CS 536 Fall 2007, Project 5

Class SimpleExprNode

Object
  extended by ASTNode
      extended by ExprNode
          extended by SimpleExprNode

public class SimpleExprNode
extends ExprNode

An AST node representing a simple expression with syntax "id" or "id(expr,...,expr)". The expression may represent either a function call or a (possibly subscripted) variable reference depending on the declared type of "id".


Nested Class Summary
 
Nested classes/interfaces inherited from class ASTNode
ASTNode.Opcode
 
Field Summary
 
Fields inherited from class ExprNode
column, line, type
 
Constructor Summary
SimpleExprNode(IdNode id, List<ExprNode> args)
          Creates a new SimpleExprNode.
 
Method Summary
 void codeGen(int reg)
          Generates code to load the value of this expression into a register.
 void codeGenLValue(int reg)
          Generates code to load the lvalue of this expression into a register.
 boolean isLValue()
          Tests whether this SimpleExprNode represents something that may be on the left-hand-side of an assignment, or passed to an OUT or INOUT parameter of a procedure or function.
static boolean isLValue(ExprNode exp)
          Convenience function to test whether an arbitrary ExprNode is an LValue.
 void resolveNames(SymbolTable symtab)
          Resolves all applied uses of identifiers in the tree rooted at this node.
 void resolveTypes(ProcDeclNode proc)
          Fills in types for all Symbols bound to IdNodes.
 void unparse(PrintWriter p, int level)
          Prints a source representation of the tree rooted at this node on output stream p.
 
Methods inherited from class ExprNode
codeGen
 
Methods inherited from class ASTNode
indent, toString
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleExprNode

public SimpleExprNode(IdNode id,
                      List<ExprNode> args)
Creates a new SimpleExprNode.

Parameters:
id - the name of the function or variable.
args - the list of arguments or subscripts. May be a zero-length list, but must not be null.
Method Detail

isLValue

public boolean isLValue()
Tests whether this SimpleExprNode represents something that may be on the left-hand-side of an assignment, or passed to an OUT or INOUT parameter of a procedure or function. Assumes that resolveNames and resolveTypes have already been called on this SimpleExprNode.

Returns:
true if this SimpleExprNode represents an LValue.

isLValue

public static boolean isLValue(ExprNode exp)
Convenience function to test whether an arbitrary ExprNode is an LValue. Assumes that resolveNames and resolveTypes have already been called on all the variables mentioned in exp.

Parameters:
exp - an arbitrary expression.
Returns:
true if the expression represents an LValue.

unparse

public void unparse(PrintWriter p,
                    int level)
Prints a source representation of the tree rooted at this node on output stream p.

Specified by:
unparse in class ASTNode
Parameters:
p - the place to display the output.
level - the number of levels of indentation to use if the output requires more than one line.

resolveNames

public void resolveNames(SymbolTable symtab)
Resolves all applied uses of identifiers in the tree rooted at this node.

Specified by:
resolveNames in class ASTNode
Parameters:
symtab - the symbol table to be used.

resolveTypes

public void resolveTypes(ProcDeclNode proc)
Fills in types for all Symbols bound to IdNodes. Prints error messages as necessary.

Specified by:
resolveTypes in class ASTNode
Parameters:
proc - the smallest enclosing procedure or function declaration.

codeGen

public void codeGen(int reg)
Generates code to load the value of this expression into a register.

Overrides:
codeGen in class ExprNode
Parameters:
reg - the number of the s register where the result should be placed.

codeGenLValue

public void codeGenLValue(int reg)
Generates code to load the lvalue of this expression into a register.

Parameters:
reg - the number of the s register where the result should be placed.

CS 536 Fall 2007, Project 5