return (ASTNode) new TreeVisitor(ParseDriver.adaptor).visit(targetNode, action);
/** Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. * Execute both actions even if t has no children. * If a child visit yields a new child, it can update its * parent's child list or just return the new child. The * child update code works even if the child visit alters its parent * and returns the new tree. * * Return result of applying post action to this node. */ public Object visit(Object t, TreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); boolean isNil = adaptor.isNil(t); if ( action!=null && !isNil ) { t = action.pre(t); // if rewritten, walk children of new t } for (int i=0; i<adaptor.getChildCount(t); i++) { Object child = adaptor.getChild(t, i); Object visitResult = visit(child, action); Object childAfterVisit = adaptor.getChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.setChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.post(t); return t; } }
/** Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. * Execute both actions even if t has no children. * If a child visit yields a new child, it can update its * parent's child list or just return the new child. The * child update code works even if the child visit alters its parent * and returns the new tree. * * Return result of applying post action to this node. */ public Object visit(Object t, TreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); boolean isNil = adaptor.isNil(t); if ( action!=null && !isNil ) { t = action.pre(t); // if rewritten, walk children of new t } for (int i=0; i<adaptor.getChildCount(t); i++) { Object child = adaptor.getChild(t, i); Object visitResult = visit(child, action); Object childAfterVisit = adaptor.getChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.setChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.post(t); return t; } }
new TreeVisitor(ParseDriver.adaptor).visit(havingExpr, action);
/** Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. * Execute both actions even if t has no children. * If a child visit yields a new child, it can update its * parent's child list or just return the new child. The * child update code works even if the child visit alters its parent * and returns the new tree. * * Return result of applying post action to this node. */ public Object visit(Object t, TreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); boolean isNil = adaptor.isNil(t); if ( action!=null && !isNil ) { t = action.pre(t); // if rewritten, walk children of new t } for (int i=0; i<adaptor.getChildCount(t); i++) { Object child = adaptor.getChild(t, i); Object visitResult = visit(child, action); Object childAfterVisit = adaptor.getChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.setChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.post(t); return t; } }
new TreeVisitor(ParseDriver.adaptor).visit(havingExpr, action);
/** Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. * Execute both actions even if t has no children. * If a child visit yields a new child, it can update its * parent's child list or just return the new child. The * child update code works even if the child visit alters its parent * and returns the new tree. * * Return result of applying post action to this node. */ public Object visit(Object t, TreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); boolean isNil = adaptor.isNil(t); if ( action!=null && !isNil ) { t = action.pre(t); // if rewritten, walk children of new t } for (int i=0; i<adaptor.getChildCount(t); i++) { Object child = adaptor.getChild(t, i); Object visitResult = visit(child, action); Object childAfterVisit = adaptor.getChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.setChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.post(t); return t; } }
ASTNode newTargetNode = (ASTNode) new TreeVisitor(ParseDriver.adaptor).visit(targetNode, action); if (visited.booleanValue() && !found.booleanValue()) { throw new SemanticException(ErrorMsg.HIVE_GROUPING_FUNCTION_EXPR_NOT_IN_GROUPBY.getMsg());
/** Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. * Execute both actions even if t has no children. * If a child visit yields a new child, it can update its * parent's child list or just return the new child. The * child update code works even if the child visit alters its parent * and returns the new tree. * * Return result of applying post action to this node. */ public Object visit(Object t, TreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); boolean isNil = adaptor.isNil(t); if ( action!=null && !isNil ) { t = action.pre(t); // if rewritten, walk children of new t } for (int i=0; i<adaptor.getChildCount(t); i++) { Object child = adaptor.getChild(t, i); Object visitResult = visit(child, action); Object childAfterVisit = adaptor.getChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.setChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.post(t); return t; } }
TreeVisitor tv = new TreeVisitor(ParseDriver.adaptor); tv.visit(child, action);
/** Visit every node in tree t and trigger an action for each node * before/after having visited all of its children. * Execute both actions even if t has no children. * If a child visit yields a new child, it can update its * parent's child list or just return the new child. The * child update code works even if the child visit alters its parent * and returns the new tree. * * Return result of applying post action to this node. */ public Object visit(Object t, TreeVisitorAction action) { // System.out.println("visit "+((Tree)t).toStringTree()); boolean isNil = adaptor.isNil(t); if ( action!=null && !isNil ) { t = action.pre(t); // if rewritten, walk children of new t } for (int i=0; i<adaptor.getChildCount(t); i++) { Object child = adaptor.getChild(t, i); Object visitResult = visit(child, action); Object childAfterVisit = adaptor.getChild(t, i); if ( visitResult != childAfterVisit ) { // result & child differ? adaptor.setChild(t, i, visitResult); } } if ( action!=null && !isNil ) t = action.post(t); return t; } }
TreeVisitor tv = new TreeVisitor(ParseDriver.adaptor); tv.visit(child, action);
public <T extends TreeVisitorAction> T visit(T visitor) { new TreeVisitor().visit(tree, visitor); return visitor; }
/** Utility visitor that sets grammar ptr in each node */ public static void setGrammarPtr(final Grammar g, GrammarAST tree) { if ( tree==null ) return; // ensure each node has pointer to surrounding grammar TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor()); v.visit(tree, new TreeVisitorAction() { @Override public Object pre(Object t) { ((GrammarAST)t).g = g; return t; } @Override public Object post(Object t) { return t; } }); }
public Object downup(Object t, boolean showTransformations) { this.showTransformations = showTransformations; TreeVisitor v = new TreeVisitor(new CommonTreeAdaptor()); TreeVisitorAction actions = new TreeVisitorAction() { @Override public Object pre(Object t) { return applyOnce(t, topdown_fptr); } @Override public Object post(Object t) { return applyRepeatedly(t, bottomup_ftpr); } }; t = v.visit(t, actions); return t; }
public void downup(Object t) { TreeVisitor v = new TreeVisitor(new CommonTreeAdaptor()); TreeVisitorAction actions = new TreeVisitorAction() { @Override public Object pre(Object t) { applyOnce(t, topdown_fptr); return t; } @Override public Object post(Object t) { applyOnce(t, bottomup_fptr); return t; } }; v.visit(t, actions); }
public void downup(Object t) { TreeVisitor v = new TreeVisitor(new CommonTreeAdaptor()); TreeVisitorAction actions = new TreeVisitorAction() { @Override public Object pre(Object t) { applyOnce(t, topdown_fptr); return t; } @Override public Object post(Object t) { applyOnce(t, bottomup_fptr); return t; } }; v.visit(t, actions); }
public Object downup(Object t, boolean showTransformations) { this.showTransformations = showTransformations; TreeVisitor v = new TreeVisitor(new CommonTreeAdaptor()); TreeVisitorAction actions = new TreeVisitorAction() { @Override public Object pre(Object t) { return applyOnce(t, topdown_fptr); } @Override public Object post(Object t) { return applyRepeatedly(t, bottomup_ftpr); } }; t = v.visit(t, actions); return t; }
/** Utility visitor that sets grammar ptr in each node */ public static void setGrammarPtr(final Grammar g, GrammarAST tree) { if ( tree==null ) return; // ensure each node has pointer to surrounding grammar TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor()); v.visit(tree, new TreeVisitorAction() { @Override public Object pre(Object t) { ((GrammarAST)t).g = g; return t; } @Override public Object post(Object t) { return t; } }); }
public Object downup(Object t, boolean showTransformations) { this.showTransformations = showTransformations; TreeVisitor v = new TreeVisitor(new CommonTreeAdaptor()); TreeVisitorAction actions = new TreeVisitorAction() { @Override public Object pre(Object t) { return applyOnce(t, topdown_fptr); } @Override public Object post(Object t) { return applyRepeatedly(t, bottomup_ftpr); } }; t = v.visit(t, actions); return t; }