diff options
Diffstat (limited to 'src/minijava/symboltable/MPrimaryExpr.java')
-rw-r--r-- | src/minijava/symboltable/MPrimaryExpr.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/minijava/symboltable/MPrimaryExpr.java b/src/minijava/symboltable/MPrimaryExpr.java index ce4113c..ba233b5 100644 --- a/src/minijava/symboltable/MPrimaryExpr.java +++ b/src/minijava/symboltable/MPrimaryExpr.java @@ -1,5 +1,7 @@ package minijava.symboltable; +import minijava.typecheck.PrintError; + public class MPrimaryExpr extends MType { /** * f0 -> IntegerLiteral() @@ -35,6 +37,40 @@ public class MPrimaryExpr extends MType { } } + public String primExprType(MMethod m) { + switch (e_type) { + case Int: + return MIdentifier.intType; + case Alloc: + return e_id.getName(); + case ArrayAlloc: + return MIdentifier.arrType; + case Braket: + return e_exp.exprType(m); + case True: + case False: + return MIdentifier.boolType; + case Id: + MVariable m_var = m.findVarByName(e_id.name); + if (m_var!=null) { + return m_var.typename; + } else { + return null; + } + case Not: + if (e_exp.exprType(m)==MIdentifier.boolType) { + return MIdentifier.boolType; + } else { + PrintError.print(getLine(), getColumn(), "A non boolean expr after '!' operator"); + return null; + } + case This: + return m.method_class.name; + default: + return null; + } + } + public void printPrimExpr(int spaces) { System.err.print(OutputFormat.spaces(spaces)); @@ -49,6 +85,14 @@ public class MPrimaryExpr extends MType { case Id: System.err.print(e_id.getName()); break; + case Alloc: + System.err.print("new "+e_id.getName()+"()"); + break; + case ArrayAlloc: + System.err.print("new int["); + e_exp.printExpr(0); + System.err.print("]"); + break; } } } |