00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "vcg.h"
00042
00043 class vcgASTWalker : public vcgWalker {
00044
00045 typedef pair<Node*, string> Edge;
00046 typedef list<Edge> Edges;
00047 typedef Edges::iterator Edges_p;
00048 typedef map<Node*,Edges> Edge_map;
00049
00050 node_list nodes;
00051 Edge_map edges;
00052
00053
00054 public:
00055 vcgASTWalker(ostream& ostr, const string& comment, string excludefilename)
00056 : vcgWalker(ostr, comment, excludefilename) {
00057 nodes.clear(); edges.clear();
00058
00059 print_comment();
00060 print_comment( "=== J-Breeze AST visualization ===" );
00061 print_comment();
00062 if( !comment.empty() ) {
00063 print_comment( comment );
00064 print_comment();
00065 }
00066
00067 start_graph();
00068 print_graph_attribute( "orientation", "left_to_right" );
00069 print_graph_attribute( "display_edge_labels", "yes");
00070 }
00071
00072 virtual ~vcgASTWalker(void) { finalize_graph(); }
00073
00075 private:
00076 virtual void finalize_graph() {
00077 delayed_print_edge();
00078
00079
00080
00081 }
00082
00083 void print_node(Node *n) {
00084
00085 if(find(nodes.begin(), nodes.end(), n) != nodes.end()) return;
00086 #ifndef J_BREEZE
00087 if(n->typ()!=Unit && excluded(n->coord())) return;
00088 #endif
00089
00090 nodes.push_front(n);
00091
00092 graph << endl;
00093 graph << " node: {" << endl;
00094 print_node_attribute( "title", node_title(n));
00095 print_node_attribute( "label", node_label(n));
00096 switch(n->typ()) {
00097
00098 case Const: case Id: case Binary: case Unary: case Cast: case Comma:
00099 case Ternary: case Call: case Initializer:
00100
00101 case Expr:
00102 #ifndef J_BREEZE
00103 case ThreeAddr: case Condition: case Operand:
00104 #else
00105 case QualifiedName: case Special: case New: case AccessClass:
00106 case InstanceOf:
00107 #endif
00108 print_node_value( "shape", "ellipse" ); break;
00109
00110 case Label: case Switch: case Case: case If:
00111
00112 case While: case Do: case For: case Goto: case Continue: case Break:
00113 case Return: case Block:
00114 #ifdef J_BREEZE
00115 case DeclStmt: case ForInit: case Break_Id: case Continue_Id: case Throw:
00116 case Synchronized: case Try: case Catch: case Finally:
00117 #endif
00118 print_node_value( "shape", "box" ); break;
00119
00120 case Prim: case Tdef: case Ptr: case Array: case Func: case Struct:
00121 case Union: case Enum: case sueSpec:
00122 #ifdef J_BREEZE
00123 case Class: case Interface: case TypeName:
00124 #endif
00125 print_node_value( "shape", "rhomb" );
00126 print_node_value( "textcolor", "green" );
00127 print_node_value( "bordercolor", "green" ); break;
00128
00129 case Decl: case Proc: case Unit:
00130 #ifdef J_BREEZE
00131 case FieldVar: case Method: case Constructor: case FieldInit:
00132 case MemberType: case Package: case Import:
00133 #endif
00134 print_node_value( "shape", "triangle" );
00135 print_node_value( "textcolor", "blue" );
00136 print_node_value( "bordercolor", "blue" ); break;
00137
00138 case Text: case Undeclared: case Meta: case Attrib:
00139 print_node_value( "shape", "triangle" );
00140 print_node_value( "textcolor", "red" );
00141 print_node_value( "bordercolor", "red" ); break;
00142 default: assert(false);
00143 }
00144 graph << " }" << endl;
00145 }
00146
00147 string node_title(Node *n) {
00148 ostringstream title;
00149 char hex[16];
00150 sprintf(hex, "(%x)\0", n);
00151 title << node_name(n) << '@' << n->coord() << '.' << n->coord().offset()
00152 << hex << '\0';
00153 return title.str();
00154 }
00155
00156 string node_label(Node *n) {
00157 ostringstream label;
00158 Coord coord = n->coord();
00159 label << node_name(n) << ':' << coord.line() << '.' << coord.offset()
00160 << '\0';
00161 return label.str();
00162 }
00163
00164 void print_edge(Node *from, Node *to, string name) {
00165 if(!from || !to) return;
00166 #ifndef J_BREEZE
00167 if((from->typ()!=Unit && excluded(from->coord()))
00168 || excluded(to->coord())) return;
00169 #endif
00170 Edges targets=edges[from];
00171
00172 for(Edges_p e=targets.begin(); e!=targets.end(); e++)
00173 if((*e).first == to) return;
00174 edges[from].push_front( Edge(to,name) );
00175 }
00176
00177 void delayed_print_edge(void) {
00178 for(Edge_map::iterator es=edges.begin(); es!=edges.end(); es++) {
00179 Node *from = (*es).first;
00180 for(Edges_p e=(*es).second.begin(); e!=(*es).second.end(); e++) {
00181 Node *to = (*e).first;
00182
00183 if(find(nodes.begin(), nodes.end(), to)==nodes.end()) continue;
00184
00185 graph << endl;
00186 graph << " edge: {";
00187 graph << " sourcename: \"" << node_title(from) << "\"";
00188 graph << " targetname: \"" << node_title(to) << "\"";
00189 graph << " label: \"" << (*e).second << "\"";
00190 graph << " }" << endl;
00191 }
00192 }
00193 }
00194
00195 #define STRING(s1,s2) (string(s1 + string(" `") + s2 + "'"))
00196
00197 string node_name(Node *n) {
00198 if(!n) return string("");
00199 switch(n->typ()) {
00200
00201 case Const: {
00202 constant v = ((constNode*)n)->value();
00203 string s = v.to_string();
00204 if(v.is_str()) { s.erase(0,1); s.erase(s.length()-1,1); }
00205 return STRING("Const", s);
00206 }
00207 case Id:
00208 return STRING("Id", ((idNode*)n)->name());
00209 case Binary:
00210 return STRING("Binary", ((binaryNode*)n)->op()->print());
00211 case Unary:
00212 return STRING("Unary", ((unaryNode*)n)->op()->print());
00213 case Cast:
00214 #ifdef J_BREEZE
00215 return STRING("Cast", typenameNode::type_name(((castNode*)n)->type()));
00216 #else
00217 return string("Cast");
00218 #endif
00219 case Comma: return string("Comma");
00220 case Ternary: return string("Ternary");
00221
00222
00223
00224
00225
00226
00227
00228 #ifdef J_BREEZE
00229 case Call:
00230 return STRING("Call", qnameNode::expand_name(((mcallNode*)n)->name()));
00231 #else
00232 case Call: return string("Call");
00233 #endif
00234 case Initializer: return string("Initializer");
00235
00236 #ifdef J_BREEZE
00237 case QualifiedName: return string("QualifiedName");
00238
00239 case Special: return STRING("Special", (((specialNode*)n)->text()));
00240 case New:
00241 return STRING("New", typenameNode::type_name(((newNode*)n)->type()));
00242 case AccessClass:
00243 return STRING("AccessClass",
00244 typenameNode::type_name(((classLiteralNode*)n)->type()));
00245 case InstanceOf: return string("InstanceOf");
00246 #endif
00247 case Expr: return string("Expr");
00248
00249 case Label: return STRING("Label", ((labelNode*)n)->name());
00250 case Switch: return string("Switch");
00251 case Case:
00252 #ifdef J_BREEZE
00253 return STRING("Case", qnameNode::expand_name(((caseNode*)n)->expr()));
00254 #else
00255 return string("Case");
00256 #endif
00257
00258 case If: return string("If");
00259
00260 case While: return string("While");
00261 case Do: return string("Do");
00262 case For: return string("For");
00263 #ifndef J_BREEZE
00264 case Goto: return STRING("Goto", ((gotoNode*)n)->name());
00265 #endif
00266 case Continue: return string("Continue");
00267 case Break: return string("Break");
00268 case Return: return string("Return");
00269 case Block: return string("Block");
00270 #ifdef J_BREEZE
00271 case DeclStmt: return string("DeclStmt");
00272 case ForInit: return string("ForInit");
00273 case Break_Id:
00274 return STRING("Break_Id", ((break_idNode*)n)->name());
00275 case Continue_Id:
00276 return STRING("Continue_Id", ((continue_idNode*)n)->name());
00277 case Throw: return string("Throw");
00278 case Synchronized:
00279 return STRING("Synchronized",
00280 qnameNode::expand_name(((synchNode*)n)->expr()));
00281 case Try: return string("Try");
00282 case Catch: return string("Catch");
00283
00284
00285 case Finally: return string("finally");
00286 #endif
00287
00288 case Prim: return STRING("Prim", (((primNode*)n)->basic().to_string()));
00289 case Tdef: return STRING("Tdef", ((tdefNode*)n)->name());
00290 case Ptr: return string("Ptr");
00291 case Array:
00292 #ifdef J_BREEZE
00293 return STRING("Array",typenameNode::type_name((arrayNode*)n));
00294 #else
00295 return string("Array");
00296 #endif
00297 case Func: return string("Func");
00298 #ifndef J_BREEZE
00299 case Struct: return string("Struct");
00300 case Union: return string("Union");
00301 case Enum: return string("Enum");
00302 case sueSpec: return STRING("sueSpec", (((suespecNode*)n)->name()));
00303 #else
00304 case Class: return STRING("Class", ((classNode*)n)->name());
00305 case Interface: return STRING("Interface", ((interfaceNode*)n)->name());
00306 case TypeName:
00307 return STRING("TypeName",
00308 qnameNode::expand_name(((typenameNode*)n)->name()));
00309 #endif
00310
00311 case Decl: return STRING("Decl", ((declNode*)n)->name());
00312 case Unit: return STRING("Unit", ((unitNode*)n)->input_file());
00313 #ifndef J_BREEZE
00314 case Proc: return STRING("Proc", ((procNode*)n)->decl()->name());
00315 case ThreeAddr: return string("ThreeAddr");
00316 case Condition: return string("Condition");
00317 case Operand: return string("Operand");
00318 #else
00319 case FieldVar: return string("FieldVar");
00320 case Method: return STRING("Method", ((methodNode*)n)->decl()->name());
00321 case Constructor: return string("Constructor");
00322 case FieldInit: return string("FieldInit");
00323 case MemberType: return string("MemberType");
00324 case Package: return string("Package");
00325 case Import: return string("Import");
00326 #endif
00327
00328 #ifndef J_BREEZE
00329 case Text: return string("Text");
00330 case Undeclared: return string("Undeclared");
00331 case Meta: return string("Meta");
00332 case Attrib: return STRING("Attrib", ((attribNode*)n)->name());
00333 #endif
00334 default: assert(false);
00335 }
00336 }
00337
00338 template< class S, class T >
00339 void print_edges(S parent, list< T > &children, string name) {
00340 for (typename list< T >::iterator c=children.begin(); c!=children.end();
00341 ++c)
00342 print_edge(parent, *c, name);
00343 }
00344
00345 void at_unit(unitNode * the_unit, Order ord) {
00346 if (ord == Postorder) return;
00347 print_node(the_unit);
00348 #ifndef J_BREEZE
00349 print_edges(the_unit, the_unit->undef_funcs(), "undef_funcs");
00350 print_edges(the_unit, the_unit->suespecs(), "suspecs");
00351 #endif
00352 print_edges(the_unit, the_unit->defs(), "defs");
00353 }
00354
00355 void at_decl(declNode * the_decl, Order ord) {
00356 if (ord == Postorder || currently_excluded) return;
00357 print_node(the_decl);
00358 typeNode *type = the_decl->type();
00359 #ifdef J_BREEZE
00360 if((type->typ()!=Class && type->typ()!=Interface) ||
00361 !excluded(type))
00362 #endif
00363 print_edge(the_decl, type, "type");
00364 print_edge(the_decl, the_decl->init(), "init");
00365 #ifndef J_BREEZE
00366 print_edge(the_decl, the_decl->bitsize(), "bitsize");
00367 #endif
00368 }
00369
00370 #ifndef J_BREEZE
00371 void at_proc(procNode * the_proc, Order ord) {
00372 if(ord==Postorder) currently_excluded = false;
00373 else currently_excluded = excluded(the_proc);
00374 if (ord == Postorder || currently_excluded) return;
00375 print_node(the_proc);
00376 print_edge(the_proc, the_proc->decl(), "decl");
00377 print_edge(the_proc, the_proc->body(), "body");
00378 }
00379 #endif
00380
00381 void at_prim(primNode * the_prim, Order ord) {
00382 if (ord == Postorder || currently_excluded) return;
00383 print_node(the_prim);
00384 }
00385
00386 void at_tdef(tdefNode * the_tdef, Order ord) {
00387 if (ord == Postorder || currently_excluded) return;
00388 print_node(the_tdef);
00389 }
00390
00391 #ifndef J_BREEZE
00392 void at_ptr(ptrNode * the_ptr, Order ord) {
00393 if (ord == Postorder || currently_excluded) return;
00394 print_node(the_ptr);
00395 print_edge(the_ptr, the_ptr->type(), "type");
00396 }
00397 #endif
00398
00399 void at_array(arrayNode * the_array, Order ord) {
00400 if (ord == Postorder || currently_excluded) return;
00401 print_node(the_array);
00402 print_edge(the_array, the_array->type(), "type");
00403 print_edge(the_array, the_array->dim(), "dim");
00404 }
00405
00406 void at_func(funcNode * the_func, Order ord) {
00407 if (ord == Postorder || currently_excluded) return;
00408 print_node(the_func);
00409 print_edges(the_func, the_func->args(), "args");
00410 print_edge(the_func, the_func->returns(), "returns");
00411 }
00412
00413 #ifndef J_BREEZE
00414 void at_sue(sueNode * the_sue, Order ord) {
00415 if (ord == Postorder || currently_excluded) return;
00416 print_node(the_sue);
00417 }
00418
00419 void at_suespec(suespecNode * the_suespec, Order ord) {
00420 if (ord == Postorder || currently_excluded) return;
00421 print_node(the_suespec);
00422 print_edges(the_suespec, the_suespec->fields(), "fields");
00423 }
00424 #endif
00425
00426 void at_const(constNode * the_const, Order ord) {
00427 if (ord == Postorder || currently_excluded) return;
00428 print_node(the_const);
00429 print_edge(the_const, the_const->type(), "type");
00430 }
00431
00432 void at_id(idNode * the_id, Order ord) {
00433 if (ord == Postorder || currently_excluded) return;
00434 print_node(the_id);
00435 print_edge(the_id, the_id->type(), "type");
00436 }
00437
00438 void at_binary(binaryNode * the_binary, Order ord) {
00439 if (ord == Postorder || currently_excluded) return;
00440 print_node(the_binary);
00441 print_edge(the_binary, the_binary->type(), "type");
00442 print_edge(the_binary, the_binary->left(), "left");
00443 print_edge(the_binary, the_binary->right(), "right");
00444
00445 if(the_binary->right() &&
00446 (the_binary->op()->id()=='.' ||
00447 #ifdef J_BREEZE
00448 the_binary->op()->id()==Operator::opARROW
00449 #else
00450 the_binary->op()->id()==Operator::ARROW
00451 #endif
00452 ))
00453 the_binary->right()->walk(*this);
00454 }
00455
00456 void at_unary(unaryNode * the_unary, Order ord) {
00457 if (ord == Postorder || currently_excluded) return;
00458 print_node(the_unary);
00459 print_edge(the_unary, the_unary->expr(), "expr");
00460 print_edge(the_unary, the_unary->type(), "type");
00461 #ifndef J_BREEZE
00462 print_edge(the_unary, the_unary->sizeof_type(), "sizeof_type");
00463 #endif
00464 }
00465
00466 void at_cast(castNode * the_cast, Order ord) {
00467 if (ord == Postorder || currently_excluded) return;
00468 print_node(the_cast);
00469 print_edge(the_cast, the_cast->type(), "type");
00470 print_edge(the_cast, the_cast->expr(), "expr");
00471 }
00472
00473 void at_comma(commaNode * the_comma, Order ord) {
00474 if (ord == Postorder || currently_excluded) return;
00475 print_node(the_comma);
00476 print_edges(the_comma, the_comma->exprs(), "exprs");
00477 print_edge(the_comma, the_comma->type(), "type");
00478 }
00479
00480 void at_ternary(ternaryNode * the_ternary, Order ord) {
00481 if (ord == Postorder || currently_excluded) return;
00482 print_node(the_ternary);
00483 print_edge(the_ternary, the_ternary->cond(), "cond");
00484 print_edge(the_ternary, the_ternary->true_br(), "true_br");
00485 print_edge(the_ternary, the_ternary->false_br(), "false_br");
00486 print_edge(the_ternary, the_ternary->type(), "type");
00487 }
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497 #ifndef J_BREEZE
00498 void at_call(callNode * the_call, Order ord) {
00499 if (ord == Postorder || currently_excluded) return;
00500 print_node(the_call);
00501 print_edge(the_call, the_call->name(), "name");
00502 print_edges(the_call, the_call->args(), "args");
00503 print_edge(the_call, the_call->type(), "type");
00504 }
00505 #else
00506 void at_mcall(mcallNode * the_call, Order ord) {
00507 if (ord == Postorder || currently_excluded) return;
00508 print_node(the_call);
00509 print_edge(the_call, the_call->name(), "name");
00510 print_edges(the_call, the_call->args(), "args");
00511 print_edge(the_call, the_call->type(), "type");
00512 }
00513 #endif
00514
00515 void at_initializer(initializerNode * the_initializer, Order ord) {
00516 if (ord == Postorder || currently_excluded) return;
00517 print_node(the_initializer);
00518 print_edges(the_initializer, the_initializer->exprs(), "exprs");
00519 print_edge(the_initializer, the_initializer->type(), "type");
00520 }
00521
00522
00523
00524
00525
00526
00527
00528
00529 void at_block(blockNode * the_block, Order ord) {
00530 if (ord == Postorder || currently_excluded) return;
00531 print_node(the_block);
00532 print_edges(the_block, the_block->decls(), "decls");
00533 print_edges(the_block, the_block->stmts(), "stmts");
00534 }
00535
00536 void at_exprstmt(exprstmtNode * the_exprstmt, Order ord) {
00537 if (ord == Postorder || currently_excluded) return;
00538 print_node(the_exprstmt);
00539 print_edge(the_exprstmt, the_exprstmt->expr(), "expr");
00540 }
00541
00542 void at_label(labelNode * the_label, Order ord) {
00543 if (ord == Postorder || currently_excluded) return;
00544 print_node(the_label);
00545 print_edge(the_label, the_label->stmt(), "stmt");
00546 }
00547
00548 void at_case(caseNode * the_case, Order ord) {
00549 if (ord == Postorder || currently_excluded) return;
00550 print_node(the_case);
00551 print_edge(the_case, the_case->expr(), "expr");
00552 print_edge(the_case, the_case->stmt(), "stmt");
00553 }
00554
00555
00556
00557
00558
00559
00560
00561 void at_if(ifNode * the_if, Order ord) {
00562 if (ord == Postorder || currently_excluded) return;
00563 print_node(the_if);
00564 print_edge(the_if, the_if->expr(), "expr");
00565 print_edge(the_if, the_if->true_br(), "true_br");
00566 print_edge(the_if, the_if->false_br(), "false_br");
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 void at_switch(switchNode * the_switch, Order ord) {
00578 if (ord == Postorder || currently_excluded) return;
00579 print_node(the_switch);
00580 print_edge(the_switch, the_switch->expr(), "expr");
00581 print_edge(the_switch, the_switch->stmt(), "stmt");
00582 }
00583
00584 void at_while(whileNode * the_while, Order ord) {
00585 if (ord == Postorder || currently_excluded) return;
00586 print_node(the_while);
00587 print_edge(the_while, the_while->cond(), "cond");
00588 print_edge(the_while, the_while->body(), "body");
00589 }
00590
00591 void at_do(doNode * the_do, Order ord) {
00592 if (ord == Postorder || currently_excluded) return;
00593 print_node(the_do);
00594 print_edge(the_do, the_do->body(), "body");
00595 print_edge(the_do, the_do->cond(), "cond");
00596 }
00597
00598 void at_for(forNode * the_for, Order ord) {
00599 if (ord == Postorder || currently_excluded) return;
00600 print_node(the_for);
00601 print_edge(the_for, the_for->init(), "init");
00602 print_edge(the_for, the_for->cond(), "cond");
00603 print_edge(the_for, the_for->next(), "next");
00604 print_edge(the_for, the_for->body(), "body");
00605 }
00606
00607 #ifndef J_BREEZE
00608 void at_goto(gotoNode * the_goto, Order ord) {
00609 if (ord == Postorder || currently_excluded) return;
00610 print_node(the_goto);
00611 }
00612 #endif
00613
00614 void at_continue(continueNode * the_continue, Order ord) {
00615 if (ord == Postorder || currently_excluded) return;
00616 print_node(the_continue);
00617 }
00618
00619 void at_break(breakNode * the_break, Order ord) {
00620 if (ord == Postorder || currently_excluded) return;
00621 print_node(the_break);
00622 }
00623
00624 void at_return(returnNode * the_return, Order ord) {
00625 if (ord == Postorder || currently_excluded) return;
00626 print_node(the_return);
00627 print_edge(the_return, the_return->expr(), "expr");
00628 }
00629
00630 #ifndef J_BREEZE
00631 void at_attrib(attribNode * the_attrib, Order ord) {
00632 if (ord == Postorder || currently_excluded) return;
00633 print_node(the_attrib);
00634 print_edge(the_attrib, the_attrib->arg(), "arg");
00635 }
00636
00637 void at_text(textNode * the_text, Order ord) {
00638 if (ord == Postorder || currently_excluded) return;
00639 print_node(the_text);
00640 }
00641
00642 void at_threeAddr(threeAddrNode *t, Order ord) {
00643 if (ord == Postorder || currently_excluded) return;
00644 print_node(t);
00645 print_edge(t, t->lhs(), "lhs");
00646 print_edge(t, t->rhs1(), "rhs1");
00647 print_edge(t, t->rhs2(), "rhs2");
00648 print_edges(t, t->arg_list(), "args");
00649 }
00650
00651 void at_conditiongoto(conditiongotoNode *c, Order ord) {
00652 if (ord == Postorder || currently_excluded) return;
00653 print_node(c);
00654 print_edge(c, c->left(), "left");
00655 print_edge(c, c->right(), "right");
00656 }
00657
00658 void at_operand(operandNode *o, Order ord) {
00659 if (ord == Postorder || currently_excluded) return;
00660 print_node(o);
00661 print_edge(o, o->cast(), "cast");
00662 print_edge(o, o->var(), "var");
00663 print_edge(o, o->index(), "index");
00664 print_edges(o, o->fields(), "fields");
00665 }
00666 #endif
00667
00668 #ifdef J_BREEZE
00669 void at_class(classNode * the_class, Order ord) {
00670 if(ord==Preorder) current_type.push_front(the_class);
00671 else current_type.pop_front();
00672 if(current_type.empty())
00673 currently_excluded = false;
00674 else
00675 currently_excluded = excluded(current_type.front());
00676 if (ord == Postorder || currently_excluded) return;
00677 print_node(the_class);
00678 print_edge(the_class, the_class->extend(), "extend");
00679 print_edges(the_class, the_class->interfaces(), "interfaces");
00680 print_edges(the_class, the_class->fields(), "fields");
00681 }
00682
00683 void at_interface(interfaceNode * the_interface, Order ord) {
00684 if(ord==Preorder) current_type.push_front(the_interface);
00685 else current_type.pop_front();
00686 if(current_type.empty())
00687 currently_excluded = false;
00688 else
00689 currently_excluded = excluded(current_type.front());
00690 if (ord == Postorder || currently_excluded) return;
00691 print_node(the_interface);
00692 print_edges(the_interface, the_interface->extends(), "extends");
00693 print_edges(the_interface, the_interface->fields(), "fields");
00694 }
00695
00696 void at_typename(typenameNode * the_tn, Order ord) {
00697 if (ord == Postorder || currently_excluded) return;
00698 print_node(the_tn);
00699 print_edge(the_tn, the_tn->name(), "name");
00700 }
00701
00702 void at_fieldvar(fieldvarNode * the_fieldvar, Order ord) {
00703 if (ord == Postorder || currently_excluded) return;
00704 print_node(the_fieldvar);
00705 print_edges(the_fieldvar, the_fieldvar->decls(), "decls");
00706 }
00707
00708 void at_method(methodNode * the_method, Order ord) {
00709 if (ord == Postorder || currently_excluded) return;
00710 print_node(the_method);
00711 print_edge(the_method, the_method->decl(), "decl");
00712 print_edges(the_method, the_method->throws(), "throws");
00713 print_edge(the_method, the_method->body(), "body");
00714 }
00715
00716 void at_constructor(constructorNode * the_constructor, Order ord) {
00717 if (ord == Postorder || currently_excluded) return;
00718 print_node(the_constructor);
00719 print_edge(the_constructor, the_constructor->decl(), "decl");
00720 print_edges(the_constructor, the_constructor->throws(), "throws");
00721 print_edge(the_constructor, the_constructor->body(), "body");
00722 }
00723
00724 void at_fieldinit(fieldinitNode * the_init, Order ord) {
00725 if (ord == Postorder || currently_excluded) return;
00726 print_node(the_init);
00727 print_edge(the_init, the_init->body(), "body");
00728 }
00729
00730 void at_membertype(membertypeNode * the_membertype, Order ord) {
00731 if (ord == Postorder || currently_excluded) return;
00732 print_node(the_membertype);
00733 print_edge(the_membertype, the_membertype->member(), "membertype");
00734 }
00735
00736 void at_declstmt(declstmtNode * the_declstmt, Order ord) {
00737 if (ord == Postorder || currently_excluded) return;
00738 print_node(the_declstmt);
00739 print_edges(the_declstmt, the_declstmt->decls(), "decls");
00740 }
00741
00742 void at_forinit(forinitNode * the_forinit, Order ord) {
00743 if (ord == Postorder || currently_excluded) return;
00744 print_node(the_forinit);
00745 print_edge(the_forinit, the_forinit->init(), "init");
00746 print_edge(the_forinit, the_forinit->cond(), "cond");
00747 print_edge(the_forinit, the_forinit->next(), "next");
00748 print_edge(the_forinit, the_forinit->body(), "body");
00749 }
00750
00751 void at_break_id(break_idNode * the_break_id, Order ord) {
00752 if (ord == Postorder || currently_excluded) return;
00753 print_node(the_break_id);
00754 }
00755
00756 void at_continue_id(continue_idNode * the_continue_id, Order ord) {
00757 if (ord == Postorder || currently_excluded) return;
00758 print_node(the_continue_id);
00759 }
00760
00761 void at_throw(throwNode * the_throw, Order ord) {
00762 if (ord == Postorder || currently_excluded) return;
00763 print_node(the_throw);
00764 print_edge(the_throw, the_throw->expr(), "expr");
00765 }
00766
00767 void at_synch(synchNode * the_synch, Order ord) {
00768 if (ord == Postorder || currently_excluded) return;
00769 print_node(the_synch);
00770 print_edge(the_synch, the_synch->expr(), "expr");
00771 print_edge(the_synch, the_synch->body(), "body");
00772 }
00773
00774 void at_try(tryNode * the_try, Order ord) {
00775 if (ord == Postorder || currently_excluded) return;
00776 print_node(the_try);
00777 print_edge(the_try, the_try->stmts(), "stmts");
00778 print_edges(the_try, the_try->catches(), "catches");
00779 print_edge(the_try, the_try->finally(), "finally");
00780 }
00781
00782 void at_catch(catchNode * the_catch, Order ord) {
00783 if (ord == Postorder || currently_excluded) return;
00784 print_node(the_catch);
00785 print_edge(the_catch, the_catch->to_catch(), "to_catch");
00786 print_edge(the_catch, the_catch->body(), "body");
00787 }
00788
00789 void at_finally(finallyNode * the_finally, Order ord) {
00790 if (ord == Postorder || currently_excluded) return;
00791 print_node(the_finally);
00792 print_edge(the_finally, the_finally->block(), "block");
00793 }
00794
00795 void at_qualifiedname(qnameNode * the_qname, Order ord) {
00796 if (ord == Postorder || currently_excluded) return;
00797 print_node(the_qname);
00798 print_edge(the_qname, the_qname->left(), "left");
00799 print_edge(the_qname, the_qname->right(), "right");
00800 }
00801
00802 void at_special(specialNode * the_special, Order ord) {
00803 if (ord == Postorder || currently_excluded) return;
00804 print_node(the_special);
00805 }
00806
00807 void at_new(newNode * the_new, Order ord) {
00808 if (ord == Postorder || currently_excluded) return;
00809 print_node(the_new);
00810 print_edge(the_new, the_new->type(), "type");
00811 if(the_new->newtype()==newNode::Array)
00812 print_edge(the_new, the_new->array_init(), "array_init");
00813 else {
00814 print_edges(the_new, the_new->args(), "args");
00815 print_edge(the_new, the_new->anonymous(), "anonymous");
00816 }
00817 }
00818
00819 void at_classLiteral(classLiteralNode * the_ac, Order ord) {
00820 if (ord == Postorder || currently_excluded) return;
00821 print_node(the_ac);
00822 print_edge(the_ac, the_ac->class_of(), "class_of");
00823 }
00824
00825 void at_instanceof(instanceofNode * the_instanceof, Order ord) {
00826 if (ord == Postorder || currently_excluded) return;
00827 print_node(the_instanceof);
00828 print_edge(the_instanceof, the_instanceof->left(), "left");
00829 print_edge(the_instanceof, the_instanceof->right(), "right");
00830 }
00831
00832 void at_packagestmt(packagestmtNode *p, Order ord) {
00833 if (ord == Postorder) return;
00834 print_node(p);
00835 print_edge(p, p->name(), "name");
00836 }
00837
00838 void at_import(importNode *import, Order ord) {
00839 if (ord == Postorder) return;
00840 print_node(import);
00841 print_edge(import, import->name(), "name");
00842 }
00843 #endif
00844 };
00845
00846
00847 class vcgASTPhase: public Phase {
00848 private:
00849 string excludefilename;
00850 public:
00851 void run (void) {
00852 string graph_file_name;
00853
00854 if( CBZ::Program.empty() ) return;
00855 else if( CBZ::Program.size()==1 ) {
00856
00857 unitNode* u = CBZ::Program.front();
00858 graph_file_name = u->input_file() + ".vcgast";
00859 } else {
00860 cout << "Several compilation units present. Creating combined call graph."
00861 << endl;
00862 graph_file_name = "combined.vcgast";
00863 }
00864
00865
00866 ofstream graph_file( graph_file_name.c_str() );
00867
00868 if( graph_file ) {
00869
00870 vcgASTWalker astw(graph_file, "File: " + graph_file_name,
00871 excludefilename);
00872
00873 for(unit_list_p i=CBZ::Program.begin(); i!=CBZ::Program.end(); ++i) {
00874 unitNode* u = *i;
00875 u->walk( astw );
00876 }
00877
00878 } else {
00879 cerr << "vcgASTPhase: Can not open '" << graph_file_name
00880 << "' for writing." << endl;
00881 }
00882 }
00883
00884 void get_flags(str_list_p & arg) {
00885 string opt = *arg;
00886 if(strncmp("exclude:", opt.c_str(), 8) == 0) {
00887 excludefilename = opt;
00888 excludefilename.erase(0,8);
00889 arg++;
00890 }
00891 };
00892 };
00893
00894 Phases vcgastPhase( "vcgAST", new vcgASTPhase() );