@@ -191,9 +191,7 @@ private void build(List<? extends Tree> trees) {
191191 private void build (Tree tree ) {
192192 switch (tree .kind ()) {
193193 case BLOCK :
194- for (StatementTree statementTree : Lists .reverse (((BlockTree ) tree ).body ())) {
195- build (statementTree );
196- }
194+ build (((BlockTree ) tree ).body ());
197195 break ;
198196 case RETURN_STATEMENT :
199197 buildReturnStatement ((ReturnStatementTree ) tree );
@@ -310,17 +308,6 @@ private void build(Tree tree) {
310308 case NEW_CLASS :
311309 buildNewClass ((NewClassTree ) tree );
312310 break ;
313- case IDENTIFIER :
314- case INT_LITERAL :
315- case LONG_LITERAL :
316- case DOUBLE_LITERAL :
317- case CHAR_LITERAL :
318- case FLOAT_LITERAL :
319- case STRING_LITERAL :
320- case BOOLEAN_LITERAL :
321- case NULL_LITERAL :
322- currentBlock .elements .add (tree );
323- break ;
324311 case TYPE_CAST :
325312 buildTypeCast (tree );
326313 break ;
@@ -330,19 +317,28 @@ private void build(Tree tree) {
330317 case NEW_ARRAY :
331318 buildNewArray ((NewArrayTree ) tree );
332319 break ;
320+ // Java 8 constructions : ignored for now.
333321 case METHOD_REFERENCE :
334- // Java 8 constructions : ignored for now.
335- break ;
322+ // assert can be ignored by VM so skip them for now.
336323 case ASSERT_STATEMENT :
337- // assert can be ignored by VM so skip them for now.
338324 break ;
325+ // store declarations as complete blocks.
339326 case EMPTY_STATEMENT :
340327 case CLASS :
341328 case ENUM :
342329 case ANNOTATION_TYPE :
343330 case INTERFACE :
344331 case LAMBDA_EXPRESSION :
345- // store declarations as complete blocks.
332+ // simple instructions
333+ case IDENTIFIER :
334+ case INT_LITERAL :
335+ case LONG_LITERAL :
336+ case DOUBLE_LITERAL :
337+ case CHAR_LITERAL :
338+ case FLOAT_LITERAL :
339+ case STRING_LITERAL :
340+ case BOOLEAN_LITERAL :
341+ case NULL_LITERAL :
346342 currentBlock .elements .add (tree );
347343 break ;
348344 default :
@@ -485,7 +481,7 @@ private void buildSwitchStatement(SwitchStatementTree tree) {
485481 for (CaseGroupTree caseGroupTree : Lists .reverse (switchStatementTree .cases ())) {
486482 build (caseGroupTree .body ());
487483 switches .getLast ().successors .add (currentBlock );
488- if (caseGroupTree != firstCase ) {
484+ if (! caseGroupTree . equals ( firstCase ) ) {
489485 // No block predecessing the first case group.
490486 currentBlock = createBlock (currentBlock );
491487 }
@@ -668,8 +664,7 @@ private void buildTypeCast(Tree tree) {
668664 build (typeCastTree .expression ());
669665 }
670666
671- private void buildInstanceOf (InstanceOfTree tree ) {
672- InstanceOfTree instanceOfTree = tree ;
667+ private void buildInstanceOf (InstanceOfTree instanceOfTree ) {
673668 currentBlock .elements .add (instanceOfTree );
674669 build (instanceOfTree .expression ());
675670 }
@@ -691,26 +686,13 @@ private Block createUnconditionalJump(Tree terminator, @Nullable Block target) {
691686
692687 private void buildCondition (Tree syntaxNode , Block trueBlock , Block falseBlock ) {
693688 switch (syntaxNode .kind ()) {
694- case CONDITIONAL_OR : {
695- BinaryExpressionTree e = (BinaryExpressionTree ) syntaxNode ;
696- // process RHS
697- buildCondition (e .rightOperand (), trueBlock , falseBlock );
698- falseBlock = currentBlock ;
699- // process LHS
700- currentBlock = createBranch (e , trueBlock , falseBlock );
701- buildCondition (e .leftOperand (), trueBlock , falseBlock );
689+ case CONDITIONAL_OR :
690+ buildConditionalOr ((BinaryExpressionTree ) syntaxNode , trueBlock , falseBlock );
702691 break ;
703- }
704- case CONDITIONAL_AND : {
692+ case CONDITIONAL_AND :
705693 // process RHS
706- BinaryExpressionTree e = (BinaryExpressionTree ) syntaxNode ;
707- buildCondition (e .rightOperand (), trueBlock , falseBlock );
708- trueBlock = currentBlock ;
709- // process LHS
710- currentBlock = createBranch (e , trueBlock , falseBlock );
711- buildCondition (e .leftOperand (), trueBlock , falseBlock );
694+ buildConditionalAnd ((BinaryExpressionTree ) syntaxNode , trueBlock , falseBlock );
712695 break ;
713- }
714696 // Skip syntactic sugar:
715697 case PARENTHESIZED_EXPRESSION :
716698 buildCondition (((ParenthesizedTree ) syntaxNode ).expression (), trueBlock , falseBlock );
@@ -721,6 +703,23 @@ private void buildCondition(Tree syntaxNode, Block trueBlock, Block falseBlock)
721703 }
722704 }
723705
706+ private void buildConditionalOr (BinaryExpressionTree conditionalOr , Block trueBlock , Block falseBlock ) {
707+ // process RHS
708+ buildCondition (conditionalOr .rightOperand (), trueBlock , falseBlock );
709+ Block newFalseBlock = currentBlock ;
710+ // process LHS
711+ currentBlock = createBranch (conditionalOr , trueBlock , newFalseBlock );
712+ buildCondition (conditionalOr .leftOperand (), trueBlock , newFalseBlock );
713+ }
714+
715+ private void buildConditionalAnd (BinaryExpressionTree conditionalAnd , Block trueBlock , Block falseBlock ) {
716+ buildCondition (conditionalAnd .rightOperand (), trueBlock , falseBlock );
717+ Block newTrueBlock = currentBlock ;
718+ // process LHS
719+ currentBlock = createBranch (conditionalAnd , newTrueBlock , falseBlock );
720+ buildCondition (conditionalAnd .leftOperand (), newTrueBlock , falseBlock );
721+ }
722+
724723 private Block createBranch (Tree terminator , Block trueBranch , Block falseBranch ) {
725724 Block result = createBlock ();
726725 result .terminator = terminator ;
@@ -768,6 +767,8 @@ private static String syntaxNodeToDebugString(Tree syntaxNode) {
768767 case INT_LITERAL :
769768 sb .append (' ' ).append (((LiteralTree ) syntaxNode ).token ().text ());
770769 break ;
770+ default :
771+ //no need to debug other syntaxNodes
771772 }
772773 return sb .toString ();
773774 }
0 commit comments