Class CgenClassTable

java.lang.Object
  extended bySymbolTable
      extended byCgenClassTable

class CgenClassTable
extends SymbolTable

This class is used for representing the inheritance tree during code generation. You will need to fill in some of its methods and potentially extend it in other useful ways.


Field Summary
private  int boolclasstag
           
private  int intclasstag
           
private  java.util.Vector nds
          All classes in the program, represented as CgenNode
private  java.io.PrintStream str
          This is the stream to which assembly instructions are output
private  int stringclasstag
           
 
Constructor Summary
CgenClassTable(Classes cls, java.io.PrintStream str)
          Constructs a new class table and invokes the code generator
 
Method Summary
 void addId(AbstractSymbol id, java.lang.Object info)
          Adds a new entry to the symbol table.
private  void buildInheritanceTree()
           
 void code()
          This method is the meat of the code generator.
private  void codeBools(int classtag)
          Emits code definitions for boolean constants.
private  void codeConstants()
          Emits code to reserve space for and initialize all of the constants.
private  void codeGlobalData()
          Emits code to start the .data segment and to declare the global names.
private  void codeGlobalText()
          Emits code to start the .text segment and to declare the global names.
private  void codeSelectGc()
          Generates GC choice constants (pointers to GC functions)
 void enterScope()
          Enters a new scope.
 void exitScope()
          Exits the most recently entered scope.
private  void installBasicClasses()
          Creates data structures representing basic Cool classes (Object, IO, Int, Bool, String).
private  void installClass(CgenNode nd)
           
private  void installClasses(Classes cs)
           
 java.lang.Object lookup(AbstractSymbol sym)
          Looks up an item through all scopes of the symbol table.
 java.lang.Object probe(AbstractSymbol sym)
          Probes the symbol table.
 CgenNode root()
          Gets the root of the inheritance tree
private  void setRelations(CgenNode nd)
           
 java.lang.String toString()
          Gets the string representation of the symbol table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nds

private java.util.Vector nds
All classes in the program, represented as CgenNode


str

private java.io.PrintStream str
This is the stream to which assembly instructions are output


stringclasstag

private int stringclasstag

intclasstag

private int intclasstag

boolclasstag

private int boolclasstag
Constructor Detail

CgenClassTable

public CgenClassTable(Classes cls,
                      java.io.PrintStream str)
Constructs a new class table and invokes the code generator

Method Detail

codeGlobalData

private void codeGlobalData()
Emits code to start the .data segment and to declare the global names.


codeGlobalText

private void codeGlobalText()
Emits code to start the .text segment and to declare the global names.


codeBools

private void codeBools(int classtag)
Emits code definitions for boolean constants.


codeSelectGc

private void codeSelectGc()
Generates GC choice constants (pointers to GC functions)


codeConstants

private void codeConstants()
Emits code to reserve space for and initialize all of the constants. Class names should have been added to the string table (in the supplied code, is is done during the construction of the inheritance graph), and code for emitting string constants as a side effect adds the string's length to the integer table. The constants are emmitted by running through the stringtable and inttable and producing code for each entry.


installBasicClasses

private void installBasicClasses()
Creates data structures representing basic Cool classes (Object, IO, Int, Bool, String). Please note: as is this method does not do anything useful; you will need to edit it to make if do what you want.


installClass

private void installClass(CgenNode nd)

installClasses

private void installClasses(Classes cs)

buildInheritanceTree

private void buildInheritanceTree()

setRelations

private void setRelations(CgenNode nd)

code

public void code()
This method is the meat of the code generator. It is to be filled in programming assignment 5


root

public CgenNode root()
Gets the root of the inheritance tree


enterScope

public void enterScope()
Enters a new scope. A scope must be entered before anything can be added to the table.


exitScope

public void exitScope()
Exits the most recently entered scope.


addId

public void addId(AbstractSymbol id,
                  java.lang.Object info)
Adds a new entry to the symbol table.

Parameters:
id - the symbol
info - the data asosciated with id

lookup

public java.lang.Object lookup(AbstractSymbol sym)
Looks up an item through all scopes of the symbol table. If found it returns the associated information field, if not it returns null.

Parameters:
sym - the symbol
Returns:
the info associated with sym, or null if not found

probe

public java.lang.Object probe(AbstractSymbol sym)
Probes the symbol table. Check the top scope (only) for the symbol sym. If found, return the information field. If not return null.

Parameters:
sym - the symbol
Returns:
the info associated with sym, or null if not found

toString

public java.lang.String toString()
Gets the string representation of the symbol table.

Returns:
the string rep