comp
Class Scope

java.lang.Object
  |
  +--comp.Scope

class Scope
extends java.lang.Object

Manages a lexical scope. Our language has a simple scoping model: a global scope and function scope. A scope can answer questions about offsets from the frame pointer.

See Also:
Type

Field Summary
(package private)  FuncDefNode func
           
(package private)  int localOffset
           
(package private)  int parmOffset
           
 
Constructor Summary
Scope(FuncDefNode func)
           
 
Method Summary
 void defineLocal(java.lang.String name, Type type)
          Add a local variable definition to this scope.
 void defineParm(java.lang.String name, Type type)
          Add a parameter definition to this scope.
 int getOffset(java.lang.String name)
          Get the offset of this name in the current frame.
 Type getType(java.lang.String name)
          Get the type of this variable.
 VarDef lookup(java.lang.String id)
          Lookup the variable name in this scope.
 java.lang.String lValue(java.lang.String name, Assembler asm, RegBank bank)
          Issue an lvalue.
 java.lang.String rValue(java.lang.String name, Assembler asm, RegBank bank)
          Issue an rvalue for this name.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parmOffset

int parmOffset

localOffset

int localOffset

func

FuncDefNode func
Constructor Detail

Scope

public Scope(FuncDefNode func)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

lookup

public VarDef lookup(java.lang.String id)
Lookup the variable name in this scope. This will fatal if the id is not defined!


getType

public Type getType(java.lang.String name)
Get the type of this variable.


defineParm

public void defineParm(java.lang.String name,
                       Type type)
Add a parameter definition to this scope.


defineLocal

public void defineLocal(java.lang.String name,
                        Type type)
Add a local variable definition to this scope.


rValue

public java.lang.String rValue(java.lang.String name,
                               Assembler asm,
                               RegBank bank)
Issue an rvalue for this name. An rvalue is a readable value of a variable. Exactly what it is depends on the type of the variable.


lValue

public java.lang.String lValue(java.lang.String name,
                               Assembler asm,
                               RegBank bank)
Issue an lvalue. The lvalue is generally the address of this name.


getOffset

public int getOffset(java.lang.String name)
Get the offset of this name in the current frame.