Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: create junk objects #187

Open
Enyby opened this issue Apr 1, 2017 · 3 comments
Open

Java: create junk objects #187

Enyby opened this issue Apr 1, 2017 · 3 comments

Comments

@Enyby
Copy link

Enyby commented Apr 1, 2017

I translate this file https://github.com/JesusFreke/smali/blob/master/smali/src/main/antlr/smaliParser.g
And get next Java code:

	// $ANTLR start "simple_name"
	// smaliParser.g:537:1: simple_name : ( SIMPLE_NAME | ACCESS_SPEC -> SIMPLE_NAME[$ACCESS_SPEC] | VERIFICATION_ERROR_TYPE -> SIMPLE_NAME[$VERIFICATION_ERROR_TYPE] | POSITIVE_INTEGER_LITERAL -> SIMPLE_NAME[$POSITIVE_INTEGER_LITERAL] | NEGATIVE_INTEGER_LITERAL -> SIMPLE_NAME[$NEGATIVE_INTEGER_LITERAL] | FLOAT_LITERAL_OR_ID -> SIMPLE_NAME[$FLOAT_LITERAL_OR_ID] | DOUBLE_LITERAL_OR_ID -> SIMPLE_NAME[$DOUBLE_LITERAL_OR_ID] | BOOL_LITERAL -> SIMPLE_NAME[$BOOL_LITERAL] | NULL_LITERAL -> SIMPLE_NAME[$NULL_LITERAL] | REGISTER -> SIMPLE_NAME[$REGISTER] | param_list_or_id ->| PRIMITIVE_TYPE -> SIMPLE_NAME[$PRIMITIVE_TYPE] | VOID_TYPE -> SIMPLE_NAME[$VOID_TYPE] | ANNOTATION_VISIBILITY -> SIMPLE_NAME[$ANNOTATION_VISIBILITY] | INSTRUCTION_FORMAT10t -> SIMPLE_NAME[$INSTRUCTION_FORMAT10t] | INSTRUCTION_FORMAT10x -> SIMPLE_NAME[$INSTRUCTION_FORMAT10x] | INSTRUCTION_FORMAT10x_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT10x_ODEX] | INSTRUCTION_FORMAT11x -> SIMPLE_NAME[$INSTRUCTION_FORMAT11x] | INSTRUCTION_FORMAT12x_OR_ID -> SIMPLE_NAME[$INSTRUCTION_FORMAT12x_OR_ID] | INSTRUCTION_FORMAT21c_FIELD -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_FIELD] | INSTRUCTION_FORMAT21c_FIELD_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_FIELD_ODEX] | INSTRUCTION_FORMAT21c_STRING -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_STRING] | INSTRUCTION_FORMAT21c_TYPE -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_TYPE] | INSTRUCTION_FORMAT21t -> SIMPLE_NAME[$INSTRUCTION_FORMAT21t] | INSTRUCTION_FORMAT22c_FIELD -> SIMPLE_NAME[$INSTRUCTION_FORMAT22c_FIELD] | INSTRUCTION_FORMAT22c_FIELD_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT22c_FIELD_ODEX] | INSTRUCTION_FORMAT22c_TYPE -> SIMPLE_NAME[$INSTRUCTION_FORMAT22c_TYPE] | INSTRUCTION_FORMAT22cs_FIELD -> SIMPLE_NAME[$INSTRUCTION_FORMAT22cs_FIELD] | INSTRUCTION_FORMAT22s_OR_ID -> SIMPLE_NAME[$INSTRUCTION_FORMAT22s_OR_ID] | INSTRUCTION_FORMAT22t -> SIMPLE_NAME[$INSTRUCTION_FORMAT22t] | INSTRUCTION_FORMAT23x -> SIMPLE_NAME[$INSTRUCTION_FORMAT23x] | INSTRUCTION_FORMAT31i_OR_ID -> SIMPLE_NAME[$INSTRUCTION_FORMAT31i_OR_ID] | INSTRUCTION_FORMAT31t -> SIMPLE_NAME[$INSTRUCTION_FORMAT31t] | INSTRUCTION_FORMAT35c_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT35c_METHOD] | INSTRUCTION_FORMAT35c_METHOD_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT35c_METHOD_ODEX] | INSTRUCTION_FORMAT35c_TYPE -> SIMPLE_NAME[$INSTRUCTION_FORMAT35c_TYPE] | INSTRUCTION_FORMAT35mi_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT35mi_METHOD] | INSTRUCTION_FORMAT35ms_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT35ms_METHOD] | INSTRUCTION_FORMAT45cc_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT45cc_METHOD] | INSTRUCTION_FORMAT4rcc_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT4rcc_METHOD] | INSTRUCTION_FORMAT51l -> SIMPLE_NAME[$INSTRUCTION_FORMAT51l] );
	public final smaliParser.simple_name_return simple_name() throws RecognitionException {
		smaliParser.simple_name_return retval = new smaliParser.simple_name_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token SIMPLE_NAME44=null;
		Token ACCESS_SPEC45=null;
		Token VERIFICATION_ERROR_TYPE46=null;
		Token POSITIVE_INTEGER_LITERAL47=null;
		Token NEGATIVE_INTEGER_LITERAL48=null;
		Token FLOAT_LITERAL_OR_ID49=null;
		Token DOUBLE_LITERAL_OR_ID50=null;
		Token BOOL_LITERAL51=null;
		Token NULL_LITERAL52=null;
		Token REGISTER53=null;
		Token PRIMITIVE_TYPE55=null;
		Token VOID_TYPE56=null;
		Token ANNOTATION_VISIBILITY57=null;
		Token INSTRUCTION_FORMAT10t58=null;
		Token INSTRUCTION_FORMAT10x59=null;
		Token INSTRUCTION_FORMAT10x_ODEX60=null;
		Token INSTRUCTION_FORMAT11x61=null;
		Token INSTRUCTION_FORMAT12x_OR_ID62=null;
		Token INSTRUCTION_FORMAT21c_FIELD63=null;
		Token INSTRUCTION_FORMAT21c_FIELD_ODEX64=null;
		Token INSTRUCTION_FORMAT21c_STRING65=null;
		Token INSTRUCTION_FORMAT21c_TYPE66=null;
		Token INSTRUCTION_FORMAT21t67=null;
		Token INSTRUCTION_FORMAT22c_FIELD68=null;
		Token INSTRUCTION_FORMAT22c_FIELD_ODEX69=null;
		Token INSTRUCTION_FORMAT22c_TYPE70=null;
		Token INSTRUCTION_FORMAT22cs_FIELD71=null;
		Token INSTRUCTION_FORMAT22s_OR_ID72=null;
		Token INSTRUCTION_FORMAT22t73=null;
		Token INSTRUCTION_FORMAT23x74=null;
		Token INSTRUCTION_FORMAT31i_OR_ID75=null;
		Token INSTRUCTION_FORMAT31t76=null;
		Token INSTRUCTION_FORMAT35c_METHOD77=null;
		Token INSTRUCTION_FORMAT35c_METHOD_ODEX78=null;
		Token INSTRUCTION_FORMAT35c_TYPE79=null;
		Token INSTRUCTION_FORMAT35mi_METHOD80=null;
		Token INSTRUCTION_FORMAT35ms_METHOD81=null;
		Token INSTRUCTION_FORMAT45cc_METHOD82=null;
		Token INSTRUCTION_FORMAT4rcc_METHOD83=null;
		Token INSTRUCTION_FORMAT51l84=null;
		ParserRuleReturnScope param_list_or_id54 =null;

		CommonTree SIMPLE_NAME44_tree=null;
		CommonTree ACCESS_SPEC45_tree=null;
		CommonTree VERIFICATION_ERROR_TYPE46_tree=null;
		CommonTree POSITIVE_INTEGER_LITERAL47_tree=null;
		CommonTree NEGATIVE_INTEGER_LITERAL48_tree=null;
		CommonTree FLOAT_LITERAL_OR_ID49_tree=null;
		CommonTree DOUBLE_LITERAL_OR_ID50_tree=null;
		CommonTree BOOL_LITERAL51_tree=null;
		CommonTree NULL_LITERAL52_tree=null;
		CommonTree REGISTER53_tree=null;
		CommonTree PRIMITIVE_TYPE55_tree=null;
		CommonTree VOID_TYPE56_tree=null;
		CommonTree ANNOTATION_VISIBILITY57_tree=null;
		CommonTree INSTRUCTION_FORMAT10t58_tree=null;
		CommonTree INSTRUCTION_FORMAT10x59_tree=null;
		CommonTree INSTRUCTION_FORMAT10x_ODEX60_tree=null;
		CommonTree INSTRUCTION_FORMAT11x61_tree=null;
		CommonTree INSTRUCTION_FORMAT12x_OR_ID62_tree=null;
		CommonTree INSTRUCTION_FORMAT21c_FIELD63_tree=null;
		CommonTree INSTRUCTION_FORMAT21c_FIELD_ODEX64_tree=null;
		CommonTree INSTRUCTION_FORMAT21c_STRING65_tree=null;
		CommonTree INSTRUCTION_FORMAT21c_TYPE66_tree=null;
		CommonTree INSTRUCTION_FORMAT21t67_tree=null;
		CommonTree INSTRUCTION_FORMAT22c_FIELD68_tree=null;
		CommonTree INSTRUCTION_FORMAT22c_FIELD_ODEX69_tree=null;
		CommonTree INSTRUCTION_FORMAT22c_TYPE70_tree=null;
		CommonTree INSTRUCTION_FORMAT22cs_FIELD71_tree=null;
		CommonTree INSTRUCTION_FORMAT22s_OR_ID72_tree=null;
		CommonTree INSTRUCTION_FORMAT22t73_tree=null;
		CommonTree INSTRUCTION_FORMAT23x74_tree=null;
		CommonTree INSTRUCTION_FORMAT31i_OR_ID75_tree=null;
		CommonTree INSTRUCTION_FORMAT31t76_tree=null;
		CommonTree INSTRUCTION_FORMAT35c_METHOD77_tree=null;
		CommonTree INSTRUCTION_FORMAT35c_METHOD_ODEX78_tree=null;
		CommonTree INSTRUCTION_FORMAT35c_TYPE79_tree=null;
		CommonTree INSTRUCTION_FORMAT35mi_METHOD80_tree=null;
		CommonTree INSTRUCTION_FORMAT35ms_METHOD81_tree=null;
		CommonTree INSTRUCTION_FORMAT45cc_METHOD82_tree=null;
		CommonTree INSTRUCTION_FORMAT4rcc_METHOD83_tree=null;
		CommonTree INSTRUCTION_FORMAT51l84_tree=null;
		RewriteRuleTokenStream stream_ANNOTATION_VISIBILITY=new RewriteRuleTokenStream(adaptor,"token ANNOTATION_VISIBILITY");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT21c_TYPE=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT21c_TYPE");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT22t=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT22t");
		RewriteRuleTokenStream stream_VOID_TYPE=new RewriteRuleTokenStream(adaptor,"token VOID_TYPE");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT10t=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT10t");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT35mi_METHOD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT35mi_METHOD");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT22s_OR_ID=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT22s_OR_ID");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT22cs_FIELD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT22cs_FIELD");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT12x_OR_ID=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT12x_OR_ID");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT35ms_METHOD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT35ms_METHOD");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT35c_METHOD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT35c_METHOD");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT45cc_METHOD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT45cc_METHOD");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT35c_TYPE=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT35c_TYPE");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT10x=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT10x");
		RewriteRuleTokenStream stream_FLOAT_LITERAL_OR_ID=new RewriteRuleTokenStream(adaptor,"token FLOAT_LITERAL_OR_ID");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT22c_TYPE=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT22c_TYPE");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT21c_STRING=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT21c_STRING");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT35c_METHOD_ODEX=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT35c_METHOD_ODEX");
		RewriteRuleTokenStream stream_NEGATIVE_INTEGER_LITERAL=new RewriteRuleTokenStream(adaptor,"token NEGATIVE_INTEGER_LITERAL");
		RewriteRuleTokenStream stream_REGISTER=new RewriteRuleTokenStream(adaptor,"token REGISTER");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT22c_FIELD_ODEX=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT22c_FIELD_ODEX");
		RewriteRuleTokenStream stream_DOUBLE_LITERAL_OR_ID=new RewriteRuleTokenStream(adaptor,"token DOUBLE_LITERAL_OR_ID");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT31i_OR_ID=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT31i_OR_ID");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT21t=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT21t");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT31t=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT31t");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT23x=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT23x");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT51l=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT51l");
		RewriteRuleTokenStream stream_POSITIVE_INTEGER_LITERAL=new RewriteRuleTokenStream(adaptor,"token POSITIVE_INTEGER_LITERAL");
		RewriteRuleTokenStream stream_BOOL_LITERAL=new RewriteRuleTokenStream(adaptor,"token BOOL_LITERAL");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT10x_ODEX=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT10x_ODEX");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT21c_FIELD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT21c_FIELD");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT22c_FIELD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT22c_FIELD");
		RewriteRuleTokenStream stream_VERIFICATION_ERROR_TYPE=new RewriteRuleTokenStream(adaptor,"token VERIFICATION_ERROR_TYPE");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT11x=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT11x");
		RewriteRuleTokenStream stream_ACCESS_SPEC=new RewriteRuleTokenStream(adaptor,"token ACCESS_SPEC");
		RewriteRuleTokenStream stream_NULL_LITERAL=new RewriteRuleTokenStream(adaptor,"token NULL_LITERAL");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT4rcc_METHOD=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT4rcc_METHOD");
		RewriteRuleTokenStream stream_PRIMITIVE_TYPE=new RewriteRuleTokenStream(adaptor,"token PRIMITIVE_TYPE");
		RewriteRuleTokenStream stream_INSTRUCTION_FORMAT21c_FIELD_ODEX=new RewriteRuleTokenStream(adaptor,"token INSTRUCTION_FORMAT21c_FIELD_ODEX");
		RewriteRuleSubtreeStream stream_param_list_or_id=new RewriteRuleSubtreeStream(adaptor,"rule param_list_or_id");

		try {
			// smaliParser.g:538:3: ( SIMPLE_NAME | ACCESS_SPEC -> SIMPLE_NAME[$ACCESS_SPEC] | VERIFICATION_ERROR_TYPE -> SIMPLE_NAME[$VERIFICATION_ERROR_TYPE] | POSITIVE_INTEGER_LITERAL -> SIMPLE_NAME[$POSITIVE_INTEGER_LITERAL] | NEGATIVE_INTEGER_LITERAL -> SIMPLE_NAME[$NEGATIVE_INTEGER_LITERAL] | FLOAT_LITERAL_OR_ID -> SIMPLE_NAME[$FLOAT_LITERAL_OR_ID] | DOUBLE_LITERAL_OR_ID -> SIMPLE_NAME[$DOUBLE_LITERAL_OR_ID] | BOOL_LITERAL -> SIMPLE_NAME[$BOOL_LITERAL] | NULL_LITERAL -> SIMPLE_NAME[$NULL_LITERAL] | REGISTER -> SIMPLE_NAME[$REGISTER] | param_list_or_id ->| PRIMITIVE_TYPE -> SIMPLE_NAME[$PRIMITIVE_TYPE] | VOID_TYPE -> SIMPLE_NAME[$VOID_TYPE] | ANNOTATION_VISIBILITY -> SIMPLE_NAME[$ANNOTATION_VISIBILITY] | INSTRUCTION_FORMAT10t -> SIMPLE_NAME[$INSTRUCTION_FORMAT10t] | INSTRUCTION_FORMAT10x -> SIMPLE_NAME[$INSTRUCTION_FORMAT10x] | INSTRUCTION_FORMAT10x_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT10x_ODEX] | INSTRUCTION_FORMAT11x -> SIMPLE_NAME[$INSTRUCTION_FORMAT11x] | INSTRUCTION_FORMAT12x_OR_ID -> SIMPLE_NAME[$INSTRUCTION_FORMAT12x_OR_ID] | INSTRUCTION_FORMAT21c_FIELD -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_FIELD] | INSTRUCTION_FORMAT21c_FIELD_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_FIELD_ODEX] | INSTRUCTION_FORMAT21c_STRING -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_STRING] | INSTRUCTION_FORMAT21c_TYPE -> SIMPLE_NAME[$INSTRUCTION_FORMAT21c_TYPE] | INSTRUCTION_FORMAT21t -> SIMPLE_NAME[$INSTRUCTION_FORMAT21t] | INSTRUCTION_FORMAT22c_FIELD -> SIMPLE_NAME[$INSTRUCTION_FORMAT22c_FIELD] | INSTRUCTION_FORMAT22c_FIELD_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT22c_FIELD_ODEX] | INSTRUCTION_FORMAT22c_TYPE -> SIMPLE_NAME[$INSTRUCTION_FORMAT22c_TYPE] | INSTRUCTION_FORMAT22cs_FIELD -> SIMPLE_NAME[$INSTRUCTION_FORMAT22cs_FIELD] | INSTRUCTION_FORMAT22s_OR_ID -> SIMPLE_NAME[$INSTRUCTION_FORMAT22s_OR_ID] | INSTRUCTION_FORMAT22t -> SIMPLE_NAME[$INSTRUCTION_FORMAT22t] | INSTRUCTION_FORMAT23x -> SIMPLE_NAME[$INSTRUCTION_FORMAT23x] | INSTRUCTION_FORMAT31i_OR_ID -> SIMPLE_NAME[$INSTRUCTION_FORMAT31i_OR_ID] | INSTRUCTION_FORMAT31t -> SIMPLE_NAME[$INSTRUCTION_FORMAT31t] | INSTRUCTION_FORMAT35c_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT35c_METHOD] | INSTRUCTION_FORMAT35c_METHOD_ODEX -> SIMPLE_NAME[$INSTRUCTION_FORMAT35c_METHOD_ODEX] | INSTRUCTION_FORMAT35c_TYPE -> SIMPLE_NAME[$INSTRUCTION_FORMAT35c_TYPE] | INSTRUCTION_FORMAT35mi_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT35mi_METHOD] | INSTRUCTION_FORMAT35ms_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT35ms_METHOD] | INSTRUCTION_FORMAT45cc_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT45cc_METHOD] | INSTRUCTION_FORMAT4rcc_METHOD -> SIMPLE_NAME[$INSTRUCTION_FORMAT4rcc_METHOD] | INSTRUCTION_FORMAT51l -> SIMPLE_NAME[$INSTRUCTION_FORMAT51l] )
			int alt10=41;
			switch ( input.LA(1) ) {

[...]

			case ANNOTATION_VISIBILITY:
				{
				alt10=14;
				}
				break;
				
[...]

			switch (alt10) {

[...]

				case 14 :
					// smaliParser.g:551:5: ANNOTATION_VISIBILITY
					{
					ANNOTATION_VISIBILITY57=(Token)match(input,ANNOTATION_VISIBILITY,FOLLOW_ANNOTATION_VISIBILITY_in_simple_name1914);  
					stream_ANNOTATION_VISIBILITY.add(ANNOTATION_VISIBILITY57);

					// AST REWRITE
					// elements: 
					// token labels: 
					// rule labels: retval
					// token list labels: 
					// rule list labels: 
					// wildcard labels: 
					retval.tree = root_0;
					RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.getTree():null);

					root_0 = (CommonTree)adaptor.nil();
					// 551:27: -> SIMPLE_NAME[$ANNOTATION_VISIBILITY]
					{
						adaptor.addChild(root_0, (CommonTree)adaptor.create(SIMPLE_NAME, ANNOTATION_VISIBILITY57));
					}


					retval.tree = root_0;

					}
					break;
					
[...]

			}
			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
	// $ANTLR end "simple_name"

As you see it create many new object RewriteRuleTokenStream but use only one from it.
It is waste memory and cause run of garbage collector. This is slow down work parser.

For solve this issue need rewrite code to lazy init.
For example:

RewriteRuleTokenStream stream_ANNOTATION_VISIBILITY=null; // at method begin

if (stream_ANNOTATION_VISIBILITY == null) { stream_ANNOTATION_VISIBILITY = new RewriteRuleTokenStream(adaptor,"token ANNOTATION_VISIBILITY");} // before every usage stream_ANNOTATION_VISIBILITY
// in our case before line with stream_ANNOTATION_VISIBILITY.add(ANNOTATION_VISIBILITY57);
@sharwell
Copy link
Member

sharwell commented Jul 28, 2017

📝 This was fixed completely in ANTLR 4.

For ANTLR 3, you can avoid the rewrite overhead in many placed by using AST operators instead. The type terminal option was added specifically to handle this case, but it appears to only have been implemented for the C# target. If added to the templates of the Java target,

// This code:
ACCESS_SPEC -> SIMPLE_NAME[$ACCESS_SPEC]

// Is the same as this code (but this one doesn't have the rewriter overhead):
ACCESS_SPEC<type=SIMPLE_NAME>

The specific templates affected are createNodeFromToken, tokenRef, tokenRefRuleRoot, matchSet, matchSetRuleRoot, and createRewriteNodeFromElement.

@Enyby
Copy link
Author

Enyby commented Jul 28, 2017

I do not understand - If I rewrite this code as you say then this must worked in Java or not?

@sharwell
Copy link
Member

sharwell commented Jul 28, 2017

@Enyby In the current release of ANTLR 3, only the C# target will allow you to do that. The Java target would support it only if you modify the code generation templates I mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants