Checking in updates
authorbdemsky <bdemsky>
Sat, 11 Feb 2006 08:53:52 +0000 (08:53 +0000)
committerbdemsky <bdemsky>
Sat, 11 Feb 2006 08:53:52 +0000 (08:53 +0000)
Robust/src/IR/MethodDescriptor.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/ClassNode.java
Robust/src/IR/Tree/MethodBodyNode.java [new file with mode: 0644]
Robust/src/IR/TypeDescriptor.java
Robust/src/Parse/java14.cup

index c97bc7ba3b7e45a03d262fb480ce474dd193bc58..a7df786655a68ce757c1c50c0b1b8051f9698c5e 100644 (file)
@@ -1,6 +1,7 @@
 package IR;
 import IR.Tree.Modifiers;
 import IR.Tree.ExpressionNode;
+import java.util.Vector;
 
 /**
  * Descriptor 
@@ -13,6 +14,8 @@ public class MethodDescriptor extends Descriptor {
     protected Modifiers modifier;
     protected TypeDescriptor returntype;
     protected String identifier;
+    protected Vector param_name;
+    protected Vector param_type;
     
     public MethodDescriptor(Modifiers m, TypeDescriptor rt, String identifier) {
        super(identifier);
@@ -21,9 +24,22 @@ public class MethodDescriptor extends Descriptor {
        this.identifier=identifier;
         this.safename = "__" + name + "__";
        this.uniqueid=count++;
+       param_name=new Vector();
+       param_type=new Vector();
+    }
+    public void addParameter(TypeDescriptor type, String paramname) {
+       param_name.add(paramname);
+       param_type.add(type);
     }
 
     public String toString() {
-           return modifier.toString()+td.toString()+" "+identifier+"()";
+       String st=modifier.toString()+returntype.toString()+" "+identifier+"(";
+       for(int i=0;i<param_type.size();i++) {
+           st+=param_type.get(i).toString()+" "+param_name.get(i).toString();
+           if ((i+1)!=param_type.size())
+               st+=", ";
+       }
+       st+=")";
+       return st;
     }
 }
index d4723f69a5c952fc9eaf3498e8280e725aae5d32..1e12379275f502a1e0d110a29958bd5fadbd93cd 100644 (file)
@@ -66,7 +66,7 @@ public class BuildIR {
        }
        ParseNode methodnode=pn.getChild("method");
        if (methodnode!=null) {
-           parseMethodDecl(cn,methodnode);
+           parseMethodDecl(cn,methodnode.getChild("method_declaration"));
            return;
        }
        throw new Error();
@@ -79,6 +79,8 @@ public class BuildIR {
            return state.getTypeDescriptor(TypeDescriptor.BYTE);
        } else if(type_st.equals("short")) {
            return state.getTypeDescriptor(TypeDescriptor.SHORT);
+       } else if(type_st.equals("boolean")) {
+           return state.getTypeDescriptor(TypeDescriptor.BOOLEAN);
        } else if(type_st.equals("int")) {
            return state.getTypeDescriptor(TypeDescriptor.INT);
        } else if(type_st.equals("long")) {
@@ -92,8 +94,9 @@ public class BuildIR {
        } else if(type_st.equals("class")) {
            ParseNode nn=tn.getChild("class");
            return state.getTypeDescriptor(parseName(nn));
-       } else
+       } else {
            throw new Error();
+       }
     }
 
     private NameDescriptor parseName(ParseNode pn) {
@@ -117,7 +120,7 @@ public class BuildIR {
        ParseNodeVector pnv=vn.getChildren();
        for(int i=0;i<pnv.size();i++) {
            ParseNode vardecl=pnv.elementAt(i);
-           String identifier=vardecl.getChild("identifier").getChild("single").getTerminal();
+           String identifier=vardecl.getChild("single").getTerminal();
            ParseNode epn=vardecl.getChild("initializer");
            
            ExpressionNode en=null;
@@ -170,21 +173,50 @@ public class BuildIR {
 
 
     private void parseMethodDecl(ClassNode cn, ParseNode pn) {
-       ParseNode headern=pn.getChild("header");
+       ParseNode headern=pn.getChild("method_header");
        ParseNode bodyn=pn.getChild("body");
        MethodDescriptor md=parseMethodHeader(headern);
+       MethodBodyNode mbn=parseMethodBody(bodyn);
+       cn.addMethod(md);
+    }
+
+    public MethodBodyNode parseMethodBody(ParseNode pn) {
+       
     }
 
     public MethodDescriptor parseMethodHeader(ParseNode pn) {
-       ParseNode mn=pn.getChild("modifier");
+       ParseNode mn=pn.getChild("modifiers");
        Modifiers m=parseModifiersList(mn);
        
        ParseNode tn=pn.getChild("returntype");
-       TypeDescriptor returntype=parseTypeDescriptor(tn);
-       MethodDescriptor md=new MethodDescriptor(m, returntype, null);
+       TypeDescriptor returntype;
+       if (tn!=null) 
+           returntype=parseTypeDescriptor(tn);
+       else
+           returntype=new TypeDescriptor(TypeDescriptor.VOID);
+
+       ParseNode pmd=pn.getChild("method_declarator");
+       String name=pmd.getChild("name").getTerminal();
+       MethodDescriptor md=new MethodDescriptor(m, returntype, name);
+       
+       ParseNode paramnode=pmd.getChild("parameters");
+       parseParameterList(md,paramnode);
        return md;
     }
 
+    public void parseParameterList(MethodDescriptor md, ParseNode pn) {
+       ParseNode paramlist=pn.getChild("formal_parameter_list");
+       if (paramlist==null)
+           return;
+        ParseNodeVector pnv=paramlist.getChildren();
+        for(int i=0;i<pnv.size();i++) {
+            ParseNode paramn=pnv.elementAt(i);
+            TypeDescriptor type=parseTypeDescriptor(paramn);
+            String paramname=paramn.getChild("single").getTerminal();
+            md.addParameter(type,paramname);
+        }
+    }
+
     public Modifiers parseModifiersList(ParseNode pn) {
        Modifiers m=new Modifiers();
        ParseNode modlist=pn.getChild("modifier_list");
index a38637edeac68439d9c6fb281aceb283193e47a9..ef6ffbf808ff084613b97f7c7bdbbd58b0e58aee 100644 (file)
@@ -1,6 +1,7 @@
 package IR.Tree;
 import java.util.Vector;
 import IR.FieldDescriptor;
+import IR.MethodDescriptor;
 import IR.NameDescriptor;
 
 class ClassNode extends TreeNode {
@@ -8,6 +9,7 @@ class ClassNode extends TreeNode {
        classname=null;
        superclass=null;
        fields=new Vector();
+       methods=new Vector();
     }
     String classname;
     NameDescriptor superclass;
diff --git a/Robust/src/IR/Tree/MethodBodyNode.java b/Robust/src/IR/Tree/MethodBodyNode.java
new file mode 100644 (file)
index 0000000..319e0dd
--- /dev/null
@@ -0,0 +1,8 @@
+package IR.Tree;
+
+class MethodBodyNode extends TreeNode {
+
+    public String printNode() {
+       return null;
+    }
+}
index 534067f364aae531b35f5329fcb8217d6093d30d..e7a79eef322213a61890f9160ae1aa68ecece4e0 100644 (file)
@@ -12,10 +12,11 @@ public class TypeDescriptor extends Descriptor {
     public static final int INT=3;
     public static final int LONG=4;
     public static final int CHAR=5;
-    public static final int FLOAT=6;
-    public static final int DOUBLE=7;
-    public static final int VOID=8;
-    public static final int CLASS=9;
+    public static final int BOOLEAN=6;
+    public static final int FLOAT=7;
+    public static final int DOUBLE=8;
+    public static final int VOID=9;
+    public static final int CLASS=10;
 
 
     int type;
@@ -42,6 +43,8 @@ public class TypeDescriptor extends Descriptor {
     private static String decodeInt(int type) {
        if (type==BYTE)
            return "byte";
+       else if (type==BOOLEAN)
+           return "boolean";
        else if (type==SHORT)
            return "short";
        else if (type==INT)
index 294ba59b3c23af5cdd00f5a0f990e9c3dcf0fef5..b88bd254e30aa7cd1331e6102e45121d14a18516 100644 (file)
@@ -513,12 +513,12 @@ variable_declarators ::=
 variable_declarator ::=
                variable_declarator_id:id {:
                ParseNode pn=new ParseNode("variable_declarator");
-               pn.addChild("identifier").addChild(id);
+               pn.addChild(id);
                RESULT=pn;
        :}
        |       variable_declarator_id:id EQ variable_initializer:init {: 
                ParseNode pn=new ParseNode("variable_declarator");
-               pn.addChild("identifier").addChild(id);
+               pn.addChild(id);
                pn.addChild("initializer").addChild(init);
                RESULT=pn;
        :}
@@ -538,7 +538,7 @@ variable_initializer ::=
 method_declaration ::=
                method_header:header method_body:body {:
                ParseNode pn=new ParseNode("method_declaration");
-               pn.addChild("header").addChild(header);
+               pn.addChild(header);
                pn.addChild("body").addChild(body);
                RESULT=pn;
        :}
@@ -549,14 +549,14 @@ method_header ::=
                ParseNode pn=new ParseNode("method_header");
                pn.addChild("modifiers").addChild(mo);
                pn.addChild("returntype").addChild(type);
-               pn.addChild("declarator").addChild(decl);
+               pn.addChild(decl);
                RESULT=pn;
        :}
        |       modifiers_opt:mo VOID method_declarator:decl //throws_opt
        {:
                ParseNode pn=new ParseNode("method_header");
                pn.addChild("modifiers").addChild(mo);
-               pn.addChild("declarator").addChild(decl);
+               pn.addChild(decl);
                RESULT=pn;
        :}
        ;
@@ -590,8 +590,8 @@ formal_parameter_list ::=
 formal_parameter ::=
                type:type variable_declarator_id:name {:
                ParseNode pn=new ParseNode("formal_parameter");
-               pn.addChild("type").addChild(type);
-               pn.addChild("name").addChild(name);
+               pn.addChild(type);
+               pn.addChild(name);
                RESULT=pn;
        :}
 //     |       FINAL type variable_declarator_id