@Override public CAstNode visitWithStatement(WithStatement node, WalkContext arg) { // TODO implement this somehow return Ast.makeNode(CAstNode.EMPTY); }
@Override public CAstNode visitEmptyExpression(EmptyExpression node, WalkContext arg) { return Ast.makeNode(CAstNode.EMPTY); }
@Override public CAstNode visitBlock(Block node, WalkContext arg) { List<CAstNode> nodes = new ArrayList<>(); for(Node child : node) { nodes.add(visit((AstNode)child, arg)); } if (nodes.isEmpty()) { return Ast.makeNode(CAstNode.EMPTY); } else { return Ast.makeNode(CAstNode.BLOCK_STMT, nodes.toArray(new CAstNode[0])); } }
protected CAstNode makeNode(WalkContext wc, CAst Ast, ASTNode n, int kind, CAstNode c1, CAstNode c2) { CAstNode cn = Ast.makeNode(kind, c1, c2); setPos(wc, cn, n); return cn; }
protected CAstNode makeNode(WalkContext wc, CAst Ast, ASTNode n, int kind, CAstNode c) { CAstNode cn = Ast.makeNode(kind, c); setPos(wc, cn, n); return cn; }
protected CAstNode makeNode(WalkContext wc, CAst Ast, ASTNode n, int kind, CAstNode c1, CAstNode c2, CAstNode c3, CAstNode c4) { CAstNode cn = Ast.makeNode(kind, c1, c2, c3, c4); setPos(wc, cn, n); return cn; }
protected CAstNode makeNode(WalkContext wc, CAst Ast, ASTNode n, int kind) { CAstNode cn = Ast.makeNode(kind); setPos(wc, cn, n); return cn; }
protected CAstNode makeNode(WalkContext wc, CAst Ast, ASTNode n, int kind, CAstNode c1, CAstNode c2, CAstNode c3) { CAstNode cn = Ast.makeNode(kind, c1, c2, c3); setPos(wc, cn, n); return cn; }
protected CAstNode makeNode(WalkContext wc, CAst Ast, ASTNode n, int kind, CAstNode c[]) { CAstNode cn = Ast.makeNode(kind, c); setPos(wc, cn, n); return cn; }
@Override public CAstNode visitSwitchCase(SwitchCase node, WalkContext arg) { if (node.getStatements() == null) { return Ast.makeNode(CAstNode.EMPTY); } else { CAstNode[] stmts = new CAstNode[ node.getStatements().size() ]; for(int i = 0; i < stmts.length; i++) { stmts[i] = visit(node.getStatements().get(i), arg); } return Ast.makeNode(CAstNode.BLOCK_STMT, stmts); } }
protected CAstNode makeNode(WalkContext wc, CAst Ast, T pos, int kind, CAstNode c[]) { CAstNode cn = Ast.makeNode(kind, c); wc.pos().setPosition(cn, pos); return cn; }
protected CAstNode makeNode(WalkContext wc, CAst Ast, T pos, int kind, CAstNode c1, CAstNode c2, CAstNode c3) { CAstNode cn = Ast.makeNode(kind, c1, c2, c3); wc.pos().setPosition(cn, pos); return cn; }
@Override public CAstNode visitAstRoot(AstRoot node, WalkContext arg) { int i = 0; CAstNode[] children = new CAstNode[ node.getStatements().size() ]; for(AstNode n : node.getStatements()) { children[i++] = this.visit(n, arg); } return Ast.makeNode(CAstNode.BLOCK_STMT, children); }
@Override public CAstNode visitVariableInitializer(VariableInitializer node, WalkContext context) { if (node.getInitializer() != null) { return visit(node.getInitializer(), context); } else { return Ast.makeNode(CAstNode.EMPTY); } }
@Override public CAstNode visitAssignment(Assignment node, WalkContext arg) { if (node.getType() == Token.ASSIGN) { return Ast.makeNode(CAstNode.ASSIGN, visit(node.getLeft(), arg), visit(node.getRight(), arg)); } else { return Ast.makeNode(CAstNode.ASSIGN_POST_OP, visit(node.getLeft(), arg), visit(node.getRight(), arg), translateOpcode(node.getOperator())); } }
@Override public CAstNode visitIfStatement(IfStatement node, WalkContext arg) { if (node.getElsePart() != null) { return Ast.makeNode(CAstNode.IF_STMT, visit(node.getCondition(), arg), visit(node.getThenPart(), arg), visit(node.getElsePart(), arg)); } else { return Ast.makeNode(CAstNode.IF_STMT, visit(node.getCondition(), arg), visit(node.getThenPart(), arg)); } }
@Override public CAstNode visitConditionalExpression(ConditionalExpression node, WalkContext arg) { return Ast.makeNode(CAstNode.IF_EXPR, visit(node.getTestExpression(), arg), visit(node.getTrueExpression(), arg), visit(node.getFalseExpression(), arg)); }
private CAstNode copyIncludeExpr(CAstNode expr) { if (expr.getValue() != null) { return Ast.makeConstant(expr.getValue()); } else if (expr instanceof CAstOperator) { return expr; } else { CAstNode nc[] = new CAstNode[expr.getChildCount()]; for (int i = 0; i < expr.getChildCount(); i++) { nc[i] = copyIncludeExpr(expr.getChild(i)); } return Ast.makeNode(expr.getKind(), nc); } }
@Override public CAstNode visitThrowStatement(ThrowStatement n, WalkContext context) { CAstNode catchNode = context.getCatchTarget(); if (catchNode != null) { context.cfg().add(n, context.getCatchTarget(), null); } else { context.cfg().add(n, CAstControlFlowMap.EXCEPTION_TO_EXIT, null); } CAstNode throwAst = Ast.makeNode(CAstNode.THROW, visit(n.getExpression(), context)); context.cfg().map(n, throwAst); return throwAst; }