=== SgNode is the root of the class hierarchy for all classes Sg.... (i.e., the base class for all node types in Sage). By calling "unparseToString()", you can see what a node looks like textually. However, do NOT use this method (or the related unparseToCompleteString) in your solutions for the course projects - use it only for your own understanding, testing, and debugging. === An SgBasicBlock represents a sequence of SgStatements. Note that this has nothing to do with basic blocks in control-flow graphs (we will discuss these later in the course). If you have SgBasicBlock* bb, you can traverse the sequence with SgStatementPtrList& stmt_list = bb->get_statements(); SgStatementPtrList::const_iterator iter; for (iter=stmt_list.begin(); iter != stmt_list.end(); iter++) { SgStatement* stmt = *iter; ... } === For any SgStatement* stmt, stmt->variantT() returns a value from an enumeration type VariantT. The elements of this enumeration type are of the form V_SgXYZ (i.e., V_SgWhileStmt) and they represent the different types of AST nodes. The complete definition of this enumeration type in available in /class/cse756/rose-0.9.4a/rose/include/Cxx_Grammar.h A simple way to distinguish between different kinds of AST nodes to have switch (stmt->variantT()) { case V_SgXYZ: { SgXYZ* x = isSgXYZ(stmt); // do something with x } case V_SgPRQ: { SgPQR* y = isSgPQR(stmt); // do something with y } ... default: std::out << "Should not reach here" << std::endl; } This is not a particularly good programming style, and ROSE does provide better mechanisms (e.g., built-in AST traversals), but it may be the easiest thing for you to do. === Functions of the form "SgXYZ* isSgXYZ(SgNode* node)" check whether the node is of the corresponding type (or any subtype of it), and return either NULL (if it is not) or the pointer to the node, typecasted to the appropriate type. === SgExprStatement is just a wrapper around an SgExpression; SgExprStatement* expr_stmt = ... ; SgExpression* the_expr = expr_stmt -> get_expression(); See notes on SgExpression below === For a SgForStatement* for_stmt = ... ; you can have SgForInitStatement* init_stmt = for_stmt->get_for_init_stmt(); to get the optional initialization part of the loop. For this course, we will assume that the initialization is always present. In general, it could contain several statements: SgStatementPtrList& init_stmt_list = init_stmt->get_init_stmt(); You need to initerate over the list to get all initialization statements; however, for this course, we will assume that there is only one statement and it is an SgExprStatement; it can be obtained with SgExprStatement* the_init = isSgExprStatement(*init_stmt_list.begin()); The loop-exit test of the loop is optional, but for this class we will assume that it is always present. It can be obtained with SgExprStatement* the_test = isSgExprStatement(for_stmt->get_test()); The loop increment is optional - e.g., in "for ( ; ; )". For this class, we will assume that it is always present, and can be obtained with SgExpression* the_incr = for_stmt->get_increment(); Finally, to get the loop body SgStatement* the_body = for_stmt->get_loop_body(); This could be either a single statement - e.g., in for (...) a[i] = 0; or an SgBasicBlock - e.g., in for (...) { a[i] = 0; b[i] = 1; } We will assume that the body is always present - e.g., we do not have an empty body as in for (...) ; === a while-loop is SgWhileStmt* while_stmt = ...; SgExprStatement* the_test = isSgExprStatement(while_stmt->get_condition()); SgStatement* the_body = while_stmt->get_body(); Similarly for a do-while loop For both, we will assume that the body is always present - e.g., we do not have while (...) ; === if-statement: SgIfStmt* if_stmt = ...; SgStatement* true_body = if_stmt->get_true_body(); SgStatement* false_body = if_stmt->get_false_body(); === some interesting cases for SgExpression SgExpression *expr = ...; --- SgAddOp --- SgGreaterOrEqualOp --- expressions of the form a[i]: SgPntrArrRefExp --- SgMinusOp --- SgUnaryAddOp --- variable: SgVarRefExp --- assignment: SgAssignOp --- asignment -=: SgMinusAssignOp