void printIf (struct IF_S *i) { struct func_elem *e = (struct func_elem *) malloc (sizeof (struct func_elem)); if (i == NULL) { //fprintf (stderr, "If does not exist.\n"); return; } strcpy (e->name, "if"); e->nextCnt = 0; list_push (&funclist, e); fprintf (fp, "if("); printExpr (i->cond); fprintf (fp, "){\n"); printStmtList (i->if_); fprintf (fp, "}"); if (i->else_ != NULL) { fprintf (fp, " else{\n"); printStmtList (i->else_); fprintf (fp, "}"); } list_pop (&funclist); free (e); }
void printWhil (struct WHILE_S *w) { struct func_elem *e = (struct func_elem *) malloc (sizeof (struct func_elem)); if (w == NULL) { //fprintf (stderr, "While does not exist.\n"); return; } strcpy (e->name, "while"); e->nextCnt = 0; list_push (&funclist, e); if (w->do_while) { fprintf (fp, "do{\n"); printStmtList (w->stmt); fprintf (fp, "} while("); printExpr (w->cond); fprintf (fp, ");"); } else { fprintf (fp, "while("); printExpr (w->cond); fprintf (fp, "){\n"); printStmtList (w->stmt); fprintf (fp, "}"); } list_pop (&funclist); free (e); }
void printFor (struct FOR_S *f) { struct func_elem *e = (struct func_elem *) malloc (sizeof (struct func_elem)); if (f == NULL) { //fprintf (stderr, "For does not exist.\n"); return; } strcpy (e->name, "for"); e->nextCnt = 0; list_push (&funclist, e); fprintf (fp, "for("); printAssi (f->init); fprintf (fp, ";"); printExpr (f->cond); fprintf (fp, ";"); printAssi (f->inc); fprintf (fp, "){\n"); printStmtList (f->stmt); fprintf (fp, "}"); list_pop (&funclist); free (e); }
void printCompStmt (struct COMPOUNDSTMT *c) { if (c == NULL) { //fprintf (stderr, "Compountstmt does not exist.\n"); return; } inc_comp (&funclist); if (c->decl != NULL) { printDeclList (c->decl, 0); } printStmtList (c->stmt); dec_comp (&funclist); }
void printCaseList (struct CASE *c) { if (c == NULL) { //fprintf (stderr, "Case list does not exist.\n"); return; } if (c->prev != NULL) printCaseList (c->prev); if (c->intnum == 0) fprintf (fp, "default:\n"); else fprintf (fp, "case %d:\n", c->intnum); printStmtList (c->stmt); if (c->break_) fprintf (fp, "break;\n"); }
void printStmtList (struct STMT *st) { if (st == NULL) { //fprintf (stderr, "Statement list does not exist.\n"); return; } if (st->prev != NULL) printStmtList (st->prev); if (st->s == eAssign) { printAssi (st->stmt.assign_); fprintf (fp, ";\n"); } else if (st->s == eCall) { printCall (st->stmt.call_); fprintf (fp, ";\n"); } else if (st->s == eRet) { printRet (st->stmt.return_); fprintf (fp, ";\n"); } else if (st->s == eWhile) { printWhil (st->stmt.while_); fprintf (fp, "\n"); } else if (st->s == eFor) { printFor (st->stmt.for_); fprintf (fp, "\n"); } else if (st->s == eIf) { printIf (st->stmt.if_); fprintf (fp, "\n"); } else if (st->s == eCompound) { printCompStmt (st->stmt.cstmt_); } else if (st->s == eSwitch) { printSwit (st->stmt.switch_); fprintf (fp, "\n"); } else fprintf (fp, ";\n"); }
void ASTPrint( int lev, ASTNode node ) { if (! node) { indent( lev ); ec_stderr_printf( "NULL" ); return; } /* Simplify our lives ... */ if (currentScope) { if (currentScope->type == PackageScope) { currentPackage = currentScope->target; currentBytecode = EC_PACKAGECODE(currentScope->target); } else { currentBytecode = currentScope->target; } currentLiteral = EC_COMPILEDLFRAME(currentBytecode); } switch ( node->type ) { case nullType: indent( lev ); ec_stderr_printf( "<nullType>" ); break; case symbolType: printSymbol( lev, node ); break; case qualifiedSymbolType: printQualifiedSymbol( lev, node ); break; case constExprType: printConstant( lev, node ); break; case variableExprType: printVariable( lev, node ); break; case arrayConstructionExprType: printArrayCons( lev, node ); break; case hashConstructionExprType: printHashCons( lev, node ); break; case unaryExprType: printUnary( lev, node ); break; case binaryExprType: printBinary( lev, node ); break; case conditionalExprType: printConditional( lev, node ); break; case orExprType: printOr( lev, node ); break; case andExprType: printAnd( lev, node ); break; case assignExprType: printAssign( lev, node ); break; case simAssignExprType: printSimAssign( lev, node ); break; case arrayRefExprType: printArrayRef( lev, node ); break; case declNodeType: printDecl( lev, node ); break; case declAtomNodeType: printDeclAtom( lev, node ); break; case statementType: printStatement( lev, node ); break; case labeledStmtType: printLabeledStmt( lev, node ); break; case exprStmtType: printExprStmt( lev, node ); break; case ifStmtType: printIf( lev, node ); break; case whileStmtType: printWhile( lev, node ); break; case doStmtType: printDo( lev, node ); break; case forStmtType: printFor( lev, node ); break; case forInStmtType: printForIn( lev, node ); break; case breakStmtType: printBreak( lev, node ); break; case continueStmtType: printContinue( lev, node ); break; case gotoStmtType: printGoto( lev, node ); break; case tryStmtType: printTry( lev, node ); break; case catchStmtType: printCatch( lev, node ); break; case throwStmtType: printThrow( lev, node ); break; case importStmtType: printImport( lev, node ); break; case paramNodeType: printParam( lev, node ); break; case paramListType: printParamList( lev, node ); break; case callNodeType: printCall( lev, node ); break; case methodCallNodeType: printMethodCall( lev, node ); break; case stmtListType: printStmtList( lev, node ); break; case funcNodeType: printFunction( lev, node ); break; case returnNodeType: printReturn( lev, node ); break; case classNodeType: printClass( lev, node ); break; case methodNodeType: printMethod( lev, node ); break; case packageNodeType: printPackage( lev, node ); break; } }