static void DumpVisitor_visitLetExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr) { DUMPER(self)->indent++; emit_string("LET ", "", "", DUMPER(self)->indent); DUMPER(self)->indent++; handleExpr(kctx, self, kExpr_at(expr, 1)); emit_string(":=", "", "", DUMPER(self)->indent); handleExpr(kctx, self, kExpr_at(expr, 2)); DUMPER(self)->indent--; DUMPER(self)->indent--; }
static void DumpVisitor_visitReturnStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt) { emit_string("Return", "", "", DUMPER(self)->indent); kExpr* expr = Stmt_getFirstExpr(kctx, stmt); if(expr != NULL && IS_Expr(expr)) { handleExpr(kctx, self, expr); } }
static void DumpVisitor_visitLoopStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt) { DUMPER(self)->indent++; emit_string("Loop", "", "", DUMPER(self)->indent - 1); handleExpr(kctx, self, Stmt_getFirstExpr(kctx, stmt)); emit_string("Body", "", "", DUMPER(self)->indent - 1); visitBlock(kctx, self, Stmt_getFirstBlock(kctx, stmt)); DUMPER(self)->indent--; }
static void DumpVisitor_visitOrExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr) { unsigned i; emit_string("OR", "", "", DUMPER(self)->indent); DUMPER(self)->indent++; for (i = 1; i < kArray_size(expr->cons); ++i) { handleExpr(kctx, self, kExpr_at(expr, i)); } DUMPER(self)->indent--; }
static void DumpVisitor_visitIfStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt) { DUMPER(self)->indent++; emit_string("If", "", "", DUMPER(self)->indent - 1); handleExpr(kctx, self, Stmt_getFirstExpr(kctx, stmt)); emit_string("Then", "", "", DUMPER(self)->indent - 1); visitBlock(kctx, self, Stmt_getFirstBlock(kctx, stmt)); emit_string("Else", "", "", DUMPER(self)->indent - 1); visitBlock(kctx, self, Stmt_getElseBlock(kctx, stmt)); DUMPER(self)->indent--; }
vector<string> CodeGenerator::expr(vector<Node>::iterator& it) // start calculation { // TODO : add value to exprCode vector<string> exprCode; int exprLayer = it->layer; // save this expr's level it++; vector<string> expression; for (; it->layer > exprLayer; it++) { string thisSymbol = it->symbol; if (thisSymbol == "+" || thisSymbol == "-" || thisSymbol == "*" || thisSymbol == "/" || thisSymbol == "==" || thisSymbol == "!=" || thisSymbol == "<" || thisSymbol == "<=" || thisSymbol == ">" || thisSymbol == ">=" || thisSymbol == "&&" || thisSymbol == "||" || thisSymbol == "=") // BinOp expression.push_back(thisSymbol); else if (thisSymbol == "id") { it++; string var = it->symbol; // it += 2; expression.push_back(it->symbol); /* if (it->symbol != "(" && it->symbol != "[") //function expression.push_back(var); */ } else if (thisSymbol == "num") { it++; expression.push_back(it->symbol); } // else if (thisSymbol == "(") { // expression.push_back(it->symbol); // } // else if (thisSymbol == ")") { // expression.push_back(it->symbol); // } } it--; // for (vector<string>::iterator x = expression.begin(); x != expression.end(); // x++) // cout << *x << " "; // cout << endl; appendVectors(exprCode, handleExpr(infixExprToPostfix(expression))); return exprCode; }
static void DumpVisitor_visitCallExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr) { KGrowingBuffer wb; KLIB Kwb_init(&(kctx->stack->cwb), &wb); kMethod *mtd = CallExpr_getMethod(expr); KLIB Kwb_printf(kctx, &wb, "CALL: '%s%s'", T_mn(mtd->mn)); DUMPER(self)->indent++; emit_string(KLIB Kwb_top(kctx, &wb, 1), "(", "", DUMPER(self)->indent); DUMPER(self)->indent++; unsigned i; for (i = 1; i < kArray_size(expr->cons); ++i) { handleExpr(kctx, self, kExpr_at(expr, i)); } DUMPER(self)->indent--; emit_string(")", "", "", DUMPER(self)->indent); DUMPER(self)->indent--; KLIB Kwb_free(&wb); }
static void DumpVisitor_visitExprStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt) { handleExpr(kctx, self, Stmt_getFirstExpr(kctx, stmt)); }