src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/JSONWriter.java

Print this page




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.ir.debug;
  27 
  28 import static jdk.nashorn.internal.runtime.Source.sourceFor;
  29 
  30 import java.util.ArrayList;
  31 import java.util.List;
  32 import jdk.nashorn.internal.ir.AccessNode;
  33 import jdk.nashorn.internal.ir.BinaryNode;
  34 import jdk.nashorn.internal.ir.Block;
  35 import jdk.nashorn.internal.ir.BlockStatement;
  36 import jdk.nashorn.internal.ir.BreakNode;
  37 import jdk.nashorn.internal.ir.CallNode;
  38 import jdk.nashorn.internal.ir.CaseNode;
  39 import jdk.nashorn.internal.ir.CatchNode;
  40 import jdk.nashorn.internal.ir.ContinueNode;

  41 import jdk.nashorn.internal.ir.EmptyNode;
  42 import jdk.nashorn.internal.ir.Expression;
  43 import jdk.nashorn.internal.ir.ExpressionStatement;
  44 import jdk.nashorn.internal.ir.ForNode;
  45 import jdk.nashorn.internal.ir.FunctionNode;
  46 import jdk.nashorn.internal.ir.IdentNode;
  47 import jdk.nashorn.internal.ir.IfNode;
  48 import jdk.nashorn.internal.ir.IndexNode;
  49 import jdk.nashorn.internal.ir.JoinPredecessorExpression;
  50 import jdk.nashorn.internal.ir.LabelNode;
  51 import jdk.nashorn.internal.ir.LexicalContext;
  52 import jdk.nashorn.internal.ir.LiteralNode;
  53 import jdk.nashorn.internal.ir.Node;
  54 import jdk.nashorn.internal.ir.ObjectNode;
  55 import jdk.nashorn.internal.ir.PropertyNode;
  56 import jdk.nashorn.internal.ir.ReturnNode;
  57 import jdk.nashorn.internal.ir.RuntimeNode;
  58 import jdk.nashorn.internal.ir.SplitNode;
  59 import jdk.nashorn.internal.ir.Statement;
  60 import jdk.nashorn.internal.ir.SwitchNode;


 272 
 273     @Override
 274     public boolean enterContinueNode(final ContinueNode continueNode) {
 275         enterDefault(continueNode);
 276 
 277         type("ContinueStatement");
 278         comma();
 279 
 280         final String label = continueNode.getLabelName();
 281         if(label != null) {
 282             property("label", label);
 283         } else {
 284             property("label");
 285             nullValue();
 286         }
 287 
 288         return leave();
 289     }
 290 
 291     @Override







 292     public boolean enterEmptyNode(final EmptyNode emptyNode) {
 293         enterDefault(emptyNode);
 294 
 295         type("EmptyStatement");
 296 
 297         return leave();
 298     }
 299 
 300     @Override
 301     public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
 302         // handle debugger statement
 303         final Node expression = expressionStatement.getExpression();
 304         if (expression instanceof RuntimeNode) {
 305             expression.accept(this);
 306             return false;
 307         }
 308 
 309         enterDefault(expressionStatement);
 310 
 311         type("ExpressionStatement");
 312         comma();
 313 
 314         property("expression");
 315         expression.accept(this);
 316 
 317         return leave();
 318     }
 319 
 320     @Override
 321     public boolean enterBlockStatement(final BlockStatement blockStatement) {






 322         enterDefault(blockStatement);
 323 
 324         type("BlockStatement");
 325         comma();
 326 
 327         property("block");
 328         blockStatement.getBlock().accept(this);
 329 
 330         return leave();
 331     }
 332 
 333     @Override
 334     public boolean enterForNode(final ForNode forNode) {
 335         enterDefault(forNode);
 336 
 337         if (forNode.isForIn() || (forNode.isForEach() && forNode.getInit() != null)) {
 338             type("ForInStatement");
 339             comma();
 340 
 341             final Node init = forNode.getInit();
 342             assert init != null;
 343             property("left");
 344             init.accept(this);
 345             comma();
 346 
 347             final Node modify = forNode.getModify();
 348             assert modify != null;
 349             property("right");


 660     @Override
 661     public boolean enterReturnNode(final ReturnNode returnNode) {
 662         enterDefault(returnNode);
 663 
 664         type("ReturnStatement");
 665         comma();
 666 
 667         final Node arg = returnNode.getExpression();
 668         property("argument");
 669         if (arg != null) {
 670             arg.accept(this);
 671         } else {
 672             nullValue();
 673         }
 674 
 675         return leave();
 676     }
 677 
 678     @Override
 679     public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
 680         final RuntimeNode.Request req = runtimeNode.getRequest();
 681 
 682         if (req == RuntimeNode.Request.DEBUGGER) {
 683             enterDefault(runtimeNode);
 684             type("DebuggerStatement");
 685             return leave();
 686         }
 687 
 688         return false;
 689     }
 690 
 691     @Override
 692     public boolean enterSplitNode(final SplitNode splitNode) {

 693         return false;
 694     }
 695 
 696     @Override
 697     public boolean enterSwitchNode(final SwitchNode switchNode) {
 698         enterDefault(switchNode);
 699 
 700         type("SwitchStatement");
 701         comma();
 702 
 703         property("discriminant");
 704         switchNode.getExpression().accept(this);
 705         comma();
 706 
 707         array("cases", switchNode.getCases());
 708 
 709         return leave();
 710     }
 711 
 712     @Override




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.ir.debug;
  27 
  28 import static jdk.nashorn.internal.runtime.Source.sourceFor;
  29 
  30 import java.util.ArrayList;
  31 import java.util.List;
  32 import jdk.nashorn.internal.ir.AccessNode;
  33 import jdk.nashorn.internal.ir.BinaryNode;
  34 import jdk.nashorn.internal.ir.Block;
  35 import jdk.nashorn.internal.ir.BlockStatement;
  36 import jdk.nashorn.internal.ir.BreakNode;
  37 import jdk.nashorn.internal.ir.CallNode;
  38 import jdk.nashorn.internal.ir.CaseNode;
  39 import jdk.nashorn.internal.ir.CatchNode;
  40 import jdk.nashorn.internal.ir.ContinueNode;
  41 import jdk.nashorn.internal.ir.DebuggerNode;
  42 import jdk.nashorn.internal.ir.EmptyNode;
  43 import jdk.nashorn.internal.ir.Expression;
  44 import jdk.nashorn.internal.ir.ExpressionStatement;
  45 import jdk.nashorn.internal.ir.ForNode;
  46 import jdk.nashorn.internal.ir.FunctionNode;
  47 import jdk.nashorn.internal.ir.IdentNode;
  48 import jdk.nashorn.internal.ir.IfNode;
  49 import jdk.nashorn.internal.ir.IndexNode;
  50 import jdk.nashorn.internal.ir.JoinPredecessorExpression;
  51 import jdk.nashorn.internal.ir.LabelNode;
  52 import jdk.nashorn.internal.ir.LexicalContext;
  53 import jdk.nashorn.internal.ir.LiteralNode;
  54 import jdk.nashorn.internal.ir.Node;
  55 import jdk.nashorn.internal.ir.ObjectNode;
  56 import jdk.nashorn.internal.ir.PropertyNode;
  57 import jdk.nashorn.internal.ir.ReturnNode;
  58 import jdk.nashorn.internal.ir.RuntimeNode;
  59 import jdk.nashorn.internal.ir.SplitNode;
  60 import jdk.nashorn.internal.ir.Statement;
  61 import jdk.nashorn.internal.ir.SwitchNode;


 273 
 274     @Override
 275     public boolean enterContinueNode(final ContinueNode continueNode) {
 276         enterDefault(continueNode);
 277 
 278         type("ContinueStatement");
 279         comma();
 280 
 281         final String label = continueNode.getLabelName();
 282         if(label != null) {
 283             property("label", label);
 284         } else {
 285             property("label");
 286             nullValue();
 287         }
 288 
 289         return leave();
 290     }
 291 
 292     @Override
 293     public boolean enterDebuggerNode(final DebuggerNode debuggerNode) {
 294         enterDefault(debuggerNode);
 295         type("DebuggerStatement");
 296         return leave();
 297     }
 298 
 299     @Override
 300     public boolean enterEmptyNode(final EmptyNode emptyNode) {
 301         enterDefault(emptyNode);
 302 
 303         type("EmptyStatement");
 304 
 305         return leave();
 306     }
 307 
 308     @Override
 309     public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
 310         // handle debugger statement
 311         final Node expression = expressionStatement.getExpression();
 312         if (expression instanceof RuntimeNode) {
 313             assert false : "should not reach here: RuntimeNode";
 314             return false;
 315         }
 316 
 317         enterDefault(expressionStatement);
 318 
 319         type("ExpressionStatement");
 320         comma();
 321 
 322         property("expression");
 323         expression.accept(this);
 324 
 325         return leave();
 326     }
 327 
 328     @Override
 329     public boolean enterBlockStatement(final BlockStatement blockStatement) {
 330         if (blockStatement.isSynthetic()) {
 331             final Block blk = blockStatement.getBlock();
 332             blk.getStatements().get(0).accept(this);
 333             return false;
 334         }
 335 
 336         enterDefault(blockStatement);
 337 
 338         type("BlockStatement");
 339         comma();
 340 
 341         array("body", blockStatement.getBlock().getStatements());


 342         return leave();
 343     }
 344 
 345     @Override
 346     public boolean enterForNode(final ForNode forNode) {
 347         enterDefault(forNode);
 348 
 349         if (forNode.isForIn() || (forNode.isForEach() && forNode.getInit() != null)) {
 350             type("ForInStatement");
 351             comma();
 352 
 353             final Node init = forNode.getInit();
 354             assert init != null;
 355             property("left");
 356             init.accept(this);
 357             comma();
 358 
 359             final Node modify = forNode.getModify();
 360             assert modify != null;
 361             property("right");


 672     @Override
 673     public boolean enterReturnNode(final ReturnNode returnNode) {
 674         enterDefault(returnNode);
 675 
 676         type("ReturnStatement");
 677         comma();
 678 
 679         final Node arg = returnNode.getExpression();
 680         property("argument");
 681         if (arg != null) {
 682             arg.accept(this);
 683         } else {
 684             nullValue();
 685         }
 686 
 687         return leave();
 688     }
 689 
 690     @Override
 691     public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
 692         assert false : "should not reach here: RuntimeNode";







 693         return false;
 694     }
 695 
 696     @Override
 697     public boolean enterSplitNode(final SplitNode splitNode) {
 698         assert false : "should reach here: SplitNode";
 699         return false;
 700     }
 701 
 702     @Override
 703     public boolean enterSwitchNode(final SwitchNode switchNode) {
 704         enterDefault(switchNode);
 705 
 706         type("SwitchStatement");
 707         comma();
 708 
 709         property("discriminant");
 710         switchNode.getExpression().accept(this);
 711         comma();
 712 
 713         array("cases", switchNode.getCases());
 714 
 715         return leave();
 716     }
 717 
 718     @Override