3. Semantic analysis: the generated abstract structure tree is further analyzed to convert the complex syntactic structure into a simple, easy to understand and read syntactic structure. For example, converting an enhanced for loop foreach to a for loop structure. A more concrete abstract structure tree is produced after semantic analysis.
Steps in the implementation of semantic analysis.
Semantic analysis is mainly done in the Enter class, which has two main steps
(1) All symbols appearing in the class are entered into the class's own symbol table, and all class symbols, class parameter lists, superclass symbols, and inherited interface type symbols are stored in the list of unprocessed symbols (since the class has references in other classes in addition to its own symbols, they are sorted)
(2) In the list of unprocessed symbols, parsing all class symbols into their respective class symbols is done in the MemberEnter.complete() class. (Parse the syntax tree and add all symbols to the symbol table)
In the Enter class resolution step, there is a secondary operation.
Adding a default constructor. Then the next step is to process the annotations: this is done in the JavaProcessingEnvironment class. Data flow analysis, done in the Flow class.
Steps for data flow analysis implementation.
1, check whether the variables are assigned before use, in addition to the 8 basic data types, there are String types and other object references need to be assigned before use.
2. Variables modified with final will not be reassigned, and will report an error if copied repeatedly; also if the variable is a static member variable it must be assigned at the time of definition
3. Analysis of method return value types
4. All Checked Exceptions must be thrown or caught upwards.
5, all statements will be executed, this analysis is whether there are statements after the return statement, because the statements after the return will not be executed.
The final step of the semantic parser, further processing the syntax tree, solves the problem Eliminate useless code, e.g., blocks of code where the if condition is always false will not be executed Unlocking syntactic sugar: to put it bluntly, converting, for example, an enhanced foreach loop to a for loop Automatic type conversion of variables: e.g., between int and Integer types
4, byte code: after the above three steps, java source code can be converted into java virtual machine (JVM) can be other byte code files.
Converts the source code into a command form that conforms to the JVM syntax specification. All JVM operations are based on stack operations, so all operations are done on the incoming and outgoing stacks. Output the bytecode in the form of JVM file organization to a bytecode file with the class suffix
Entire business process.