static void visit_expr(seg_expr_node *root, seg_ast_visitor visitor, void *state) { switch(root->child_kind) { case SEG_INTEGER: (*(visitor->visit_integer))(&(root->child.integer), state); break; case SEG_STRING: (*(visitor->visit_string))(&(root->child.string), state); break; case SEG_SYMBOL: (*(visitor->visit_symbol))(&(root->child.symbol), state); break; case SEG_VAR: (*(visitor->visit_var))(&(root->child.var), state); break; case SEG_METHODCALL: (*(visitor->visit_methodcall_pre))(&(root->child.methodcall), state); visit_expr(root->child.methodcall.receiver, visitor, state); seg_arg_list *current = root->child.methodcall.args; while (current != NULL) { visit_expr(current->value, visitor, state); current = current->next; } (*(visitor->visit_methodcall_post))(&(root->child.methodcall), state); break; case SEG_BLOCK: visit_block(&(root->child.block), visitor, state); break; default: fprintf(stderr, "Unexpected child_kind in expr: %d\n", root->child_kind); } }
void PSIVisitor::visit_constraint_if_stmt(IConstraintIf *c) { visit_expr(c->getCond()); visit_constraint_stmt(c->getTrue()); if (c->getFalse()) { visit_constraint_stmt(c->getFalse()); } }
static void visit_block(seg_block_node *node, seg_ast_visitor visitor, void *state) { (*(visitor->visit_block_pre))(node, state); seg_expr_node *current = node->first; while (current != NULL) { visit_expr(current, visitor, state); current = current->next; } (*(visitor->visit_block_post))(node, state); }
void PSIVisitor::visit_constraint_stmt(IConstraint *c) { switch (c->getConstraintType()) { case IConstraint::ConstraintType_Block: { visit_constraint_block(static_cast<IConstraintBlock *>(c)); } break; case IConstraint::ConstraintType_Expr: visit_constraint_expr_stmt(static_cast<IConstraintExpr *>(c)); break; case IConstraint::ConstraintType_If: { IConstraintIf *c_if = static_cast<IConstraintIf *>(c); visit_expr(c_if->getCond()); visit_constraint_stmt(c_if->getTrue()); if (c_if->getFalse()) { visit_constraint_stmt(c_if->getFalse()); } } break; } }
void PSIVisitor::visit_binary_expr(IBinaryExpr *be) { visit_expr(be->getLHS()); visit_expr(be->getRHS()); }
void PSIVisitor::visit_constraint_expr_stmt(IConstraintExpr *c) { visit_expr(c->getExpr()); }