📄 ast_expr.cc
字号:
/* File: ast_expr.cc * ----------------- * Implementation of expression node classes. */#include "ast_expr.h"#include "ast_type.h"#include "ast_decl.h"IntConstant::IntConstant(yyltype loc, int val) : Expr(loc) { value = val;}void IntConstant::PrintChildren(int indentLevel) { printf("%d", value);}DoubleConstant::DoubleConstant(yyltype loc, double val) : Expr(loc) { value = val;}void DoubleConstant::PrintChildren(int indentLevel) { printf("%g", value);}BoolConstant::BoolConstant(yyltype loc, bool val) : Expr(loc) { value = val;}void BoolConstant::PrintChildren(int indentLevel) { printf("%s", value ? "true" : "false");}StringConstant::StringConstant(yyltype loc, const char *val) : Expr(loc) { Assert(val != NULL); value = strdup(val);}void StringConstant::PrintChildren(int indentLevel) { printf("%s",value);}Operator::Operator(yyltype loc, const char *tok) : Node(loc) { Assert(tok != NULL); strncpy(tokenString, tok, sizeof(tokenString));}void Operator::PrintChildren(int indentLevel) { printf("%s",tokenString);}CompoundExpr::CompoundExpr(Expr *l, Operator *o, Expr *r) : Expr(Join(l->GetLocation(), r->GetLocation())) { Assert(l != NULL && o != NULL && r != NULL); (op=o)->SetParent(this); (left=l)->SetParent(this); (right=r)->SetParent(this);}CompoundExpr::CompoundExpr(Operator *o, Expr *r) : Expr(Join(o->GetLocation(), r->GetLocation())) { Assert(o != NULL && r != NULL); left = NULL; (op=o)->SetParent(this); (right=r)->SetParent(this);}void CompoundExpr::PrintChildren(int indentLevel) { if (left) left->Print(indentLevel+1); op->Print(indentLevel+1); right->Print(indentLevel+1);} ArrayAccess::ArrayAccess(yyltype loc, Expr *b, Expr *s) : LValue(loc) { (base=b)->SetParent(this); (subscript=s)->SetParent(this);}void ArrayAccess::PrintChildren(int indentLevel) { base->Print(indentLevel+1); subscript->Print(indentLevel+1, "(subscript) "); } FieldAccess::FieldAccess(Expr *b, Identifier *f) : LValue(b? Join(b->GetLocation(), f->GetLocation()) : *f->GetLocation()) { Assert(f != NULL); // b can be be NULL (just means no explicit base) base = b; if (base) base->SetParent(this); (field=f)->SetParent(this);} void FieldAccess::PrintChildren(int indentLevel) { if (base) base->Print(indentLevel+1); field->Print(indentLevel+1); }Call::Call(yyltype loc, Expr *b, Identifier *f, List<Expr*> *a) : Expr(loc) { Assert(f != NULL && a != NULL); // b can be be NULL (just means no explicit base) base = b; if (base) base->SetParent(this); (field=f)->SetParent(this); (actuals=a)->SetParentAll(this);} void Call::PrintChildren(int indentLevel) { if (base) base->Print(indentLevel+1); field->Print(indentLevel+1); actuals->PrintAll(indentLevel+1, "(actuals) "); } NewExpr::NewExpr(yyltype loc, NamedType *c) : Expr(loc) { Assert(c != NULL); (cType=c)->SetParent(this);}void NewExpr::PrintChildren(int indentLevel) { cType->Print(indentLevel+1);}NewArrayExpr::NewArrayExpr(yyltype loc, Expr *sz, Type *et) : Expr(loc) { Assert(sz != NULL && et != NULL); (size=sz)->SetParent(this); (elemType=et)->SetParent(this);}void NewArrayExpr::PrintChildren(int indentLevel) { size->Print(indentLevel+1); elemType->Print(indentLevel+1);}ConditionalExpr::ConditionalExpr(Expr *e1, Operator *o1, Expr *e2, Operator *o2, Expr *e3) : Expr(Join(e1->GetLocation(),e2->GetLocation())){ Assert(e1 != NULL && e2 != NULL && e3 != NULL && o1 != NULL && o2 != NULL); (expr1=e1)->SetParent(this); (expr2=e2)->SetParent(this); (expr3=e3)->SetParent(this); (op1=o1)->SetParent(this); (op2=o2)->SetParent(this);} void ConditionalExpr::PrintChildren(int indentLevel){ expr1->Print(indentLevel+1); op1->Print(indentLevel+1); expr2->Print(indentLevel+1); op2->Print(indentLevel+1); expr3->Print(indentLevel+1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -