com.adamcornett.cminus.tree
Class FuncTree

java.lang.Object
  extended by org.antlr.runtime.tree.BaseTree
      extended by org.antlr.runtime.tree.CommonTree
          extended by com.adamcornett.cminus.tree.CMTree
              extended by com.adamcornett.cminus.tree.ExprNode
                  extended by com.adamcornett.cminus.tree.FuncTree
All Implemented Interfaces:
FunctionNode, ScopeNode, TypeNode, org.antlr.runtime.tree.Tree

public class FuncTree
extends ExprNode
implements FunctionNode

A tree node representing a function.

Author:
Adam Cornett

Field Summary
private  Function f
          The function from the FunctionTable
private  int localVarCount
          The number of local variables to reserve space for.
private  Scope s
          The scope for this function from the scope table
private  int stackSize
          The amount of stack space to reserve
 
Fields inherited from class com.adamcornett.cminus.tree.CMTree
log
 
Fields inherited from class org.antlr.runtime.tree.CommonTree
childIndex, parent, startIndex, stopIndex, token
 
Fields inherited from class org.antlr.runtime.tree.BaseTree
children
 
Fields inherited from interface org.antlr.runtime.tree.Tree
INVALID_NODE
 
Constructor Summary
FuncTree(org.antlr.runtime.Token payload)
           
 
Method Summary
 String computeParamStr()
           
private  String computeParamStr(CMTree paramList)
          Helper function to generate the parameter list based on the Param List node
 void emitCode(ClassGenerator classGenerator)
          Emit the function declaration code, followed by the body of the function
private  void findFunction()
          Look up the function in the table based on its name.
protected  CSTree getCSTree()
          Get the compound statement node for this function
 Function getFunction()
          Get the function declaration from the FunctionTable
private  CMTree getParamList()
           
 Type getReturnType()
          Get the return type of the function
 Scope getScope()
          Get the function's scope
 int getScopeNumber()
          Get the function's scope number
private  int getVarDecs(CMTree root)
           
 void setFunction(Function f)
           
private  void setLocals()
          Calculate the number of local variables
 void setReturnType(Type t)
           
 void setScope(Scope s)
           
private  void setStackSize()
          Determine the stack size recursively by looking at all child statements and finding the one with the largest stack.
 
Methods inherited from class com.adamcornett.cminus.tree.ExprNode
getOperandType
 
Methods inherited from class com.adamcornett.cminus.tree.CMTree
emitLineInfo, getMaxTreeDepth, getNextLabelNumber, getRequiredStack
 
Methods inherited from class org.antlr.runtime.tree.CommonTree
dupNode, getCharPositionInLine, getChildIndex, getLine, getParent, getText, getToken, getTokenStartIndex, getTokenStopIndex, getType, isNil, setChildIndex, setParent, setTokenStartIndex, setTokenStopIndex, setUnknownTokenBoundaries, toString
 
Methods inherited from class org.antlr.runtime.tree.BaseTree
addChild, addChildren, createChildrenList, deleteChild, freshenParentAndChildIndexes, freshenParentAndChildIndexes, getAncestor, getAncestors, getChild, getChildCount, getChildren, getFirstChildWithType, hasAncestor, replaceChildren, sanityCheckParentAndChildIndexes, sanityCheckParentAndChildIndexes, setChild, toStringTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

f

private Function f
The function from the FunctionTable


localVarCount

private int localVarCount
The number of local variables to reserve space for.


s

private Scope s
The scope for this function from the scope table


stackSize

private int stackSize
The amount of stack space to reserve

Constructor Detail

FuncTree

public FuncTree(org.antlr.runtime.Token payload)
Method Detail

computeParamStr

public String computeParamStr()

emitCode

public void emitCode(ClassGenerator classGenerator)
Emit the function declaration code, followed by the body of the function

Overrides:
emitCode in class CMTree

getFunction

public Function getFunction()
Get the function declaration from the FunctionTable

Specified by:
getFunction in interface FunctionNode

getReturnType

public Type getReturnType()
Get the return type of the function

Specified by:
getReturnType in interface TypeNode
Returns:
The return type of the function
See Also:
Function.getReturnType()

getScope

public Scope getScope()
Get the function's scope

Specified by:
getScope in interface ScopeNode
Returns:
the function's associated scope

getScopeNumber

public int getScopeNumber()
Get the function's scope number

Specified by:
getScopeNumber in interface ScopeNode

setFunction

public void setFunction(Function f)
Specified by:
setFunction in interface FunctionNode

setReturnType

public void setReturnType(Type t)
Specified by:
setReturnType in interface TypeNode

setScope

public void setScope(Scope s)
Specified by:
setScope in interface ScopeNode

computeParamStr

private String computeParamStr(CMTree paramList)
Helper function to generate the parameter list based on the Param List node

Parameters:
paramList - The Param List node for this function
Returns:
A string to be emitted in the function definition

findFunction

private void findFunction()
Look up the function in the table based on its name.


getParamList

private CMTree getParamList()

getVarDecs

private int getVarDecs(CMTree root)

setLocals

private void setLocals()
Calculate the number of local variables


setStackSize

private void setStackSize()
Determine the stack size recursively by looking at all child statements and finding the one with the largest stack.


getCSTree

protected CSTree getCSTree()
Get the compound statement node for this function

Returns: