-
Notifications
You must be signed in to change notification settings - Fork 6
Description
When we use the jjtree.Main class to generate an example_jjtree.jj file and use the javacc main method to generate a Parser based on that file, the s_jjtreeGenerated boolean flag is not set correctly in JavaCCGlobals.
Because of that, the generated code based on this flag is not included in the generated Parser. The missing code is responsible for cleaning the nodes and marks of the JJTParserState (called jjtree) of the generated Parser in the ReInit methods.
If this code is missing, the state will never be reset when the ReInit method of the Parser is called, and hence leads to a memory leak.
Steps to reproduce:
- Execute the jjtree\Main.java class with the file name being any of the examples in examples/JJTreeExamples/java (although same Issue should also be reproducible with C++)
- From the output directory of the previous step, use the generated .jj file as the argument to run javacc.main()
- Verify that the JJTParserState (jjtree) is reset inside the ReInit method of the generated Parser from step 2
Fails in Step 3, the reinit method of jjtree is not called in the ReInit method.
The root cause is inside the parser\Main.java class in the mainProgram method. Here, the JavaCCGlobals.s_jjtreeGenerated flag is set based on the isGeneratedBy method. "JJTree" is being checked against the toolName included in the generated .jj file of the jjtree.Main class.
However, there is an additional space character in the String returned by getToolNames (" JJTree").
Because of that, the comparison will return false and the jjtreeGenerated flag is set to false (although it should be true).
To fix this, either the file header of the .jj file should not contain a space after "Generated by: ", the parsing of the header should be refined or during the comparison, the values should be stripped.
/*@bgen(jjtree) Generated by: JJTree: Do not edit this line. eg1.jj */