+package IR.Flat;
+
public class FlatNode {
public String toString() {
package IR;
import IR.Tree.*;
+import java.util.*;
public class State {
public State(ParseNode parsetree) {
globals=new SymbolTable();
this.parsetree=parsetree;
+ this.set=new HashSet();
}
public SymbolTable globals;
public ParseNode parsetree;
+ public HashSet set;
public static TypeDescriptor getTypeDescriptor(int t) {
TypeDescriptor td=new TypeDescriptor(t);
TypeDescriptor td=new TypeDescriptor(n);
return td;
}
+ public void addClass(ClassNode tdn) {
+ set.add(tdn);
+ }
}
}
public void buildtree() {
ParseNode pn=state.parsetree;
- FileNode fn=parseFile(pn);
- System.out.println(fn.printNode(0));
+ parseFile(pn);
}
/** Parse the classes in this file */
- public FileNode parseFile(ParseNode pn) {
- FileNode fn=new FileNode();
+ public void parseFile(ParseNode pn) {
ParseNode tpn=pn.getChild("type_declaration_list");
if (tpn!=null) {
ParseNodeVector pnv=tpn.getChildren();
if (isEmpty(type_pn)) /* Skip the semicolon */
continue;
ClassNode cn=parseTypeDecl(type_pn);
- fn.addClass(cn);
+ state.addClass(cn);
}
}
- return fn;
}
public ClassNode parseTypeDecl(ParseNode pn) {
import IR.MethodDescriptor;
import IR.NameDescriptor;
-class ClassNode extends TreeNode {
+public class ClassNode extends TreeNode {
ClassNode() {
classname=null;
superclass=null;
+++ /dev/null
-package IR.Tree;
-import java.util.Vector;
-
-class FileNode extends TreeNode {
- private Vector type_decls;
-
- FileNode() {
- type_decls=new Vector();
- }
-
- public void addClass(ClassNode tdn) {
- type_decls.add(tdn);
- }
-
- public String printNode(int indent) {
- String st="";
- for(int i=0;i<type_decls.size();i++) {
- ClassNode cn=(ClassNode) type_decls.get(i);
- st+=cn.printNode(indent);
-
- }
- return st;
- }
-}