Changed inheritance to separate task/method descriptors again
authorbdemsky <bdemsky>
Tue, 16 May 2006 00:09:18 +0000 (00:09 +0000)
committerbdemsky <bdemsky>
Tue, 16 May 2006 00:09:18 +0000 (00:09 +0000)
Push task generation through flat code...

Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Flat/FlatMethod.java
Robust/src/IR/MethodDescriptor.java
Robust/src/IR/State.java
Robust/src/IR/TaskDescriptor.java
Robust/src/IR/Tree/SemanticCheck.java

index 9eaebf8d49acd567d6df16115aa139882abd3f5c..211dddc6fc28209e27b769d2f9b0463c804f460e 100644 (file)
@@ -22,8 +22,25 @@ public class BuildFlat {
            ClassDescriptor cn=(ClassDescriptor)it.next();
            flattenClass(cn);
        }
+       
+       Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator();
+       while(task_it.hasNext()) {
+           TaskDescriptor td=(TaskDescriptor)task_it.next();
+           flattenTask(td);
+       }
     }
     
+    private void flattenTask(TaskDescriptor td) {
+       BlockNode bn=state.getMethodBody(td);
+       FlatNode fn=flattenBlockNode(bn).getBegin();
+       FlatMethod fm=new FlatMethod(td, fn);
+
+       for(int i=0;i<td.numParameters();i++) {
+           fm.addParameterTemp(getTempforVar(td.getParameter(i)));
+       }
+       state.addFlatCode(td,fm);
+    }
+
     private void flattenClass(ClassDescriptor cn) {
        Iterator methodit=cn.getMethods();
        while(methodit.hasNext()) {
index 70d115126a7bb96261f6c2a599a62b8b0cc6ac73..9e6cf652dfc7d998169d5c6e272a39531d692ba3 100644 (file)
@@ -1,14 +1,24 @@
 package IR.Flat;
 import IR.MethodDescriptor;
+import IR.TaskDescriptor;
 import java.util.*;
 
 public class FlatMethod extends FlatNode {
     FlatNode method_entry;
     MethodDescriptor method;
+    TaskDescriptor task;
     Vector parameterTemps;
 
     FlatMethod(MethodDescriptor md, FlatNode entry) {
        method=md;
+       task=null;
+       method_entry=entry;
+       parameterTemps=new Vector();
+    }
+
+    FlatMethod(TaskDescriptor td, FlatNode entry) {
+       task=td;
+       method=null;
        method_entry=entry;
        parameterTemps=new Vector();
     }
index a9a366588724f10d5c8254a715a2c8b348bdc5e0..115e30736a6df7558e5c4faabb292ce48902140d 100644 (file)
@@ -21,7 +21,7 @@ public class MethodDescriptor extends Descriptor {
 
 
     public MethodDescriptor(Modifiers m, TypeDescriptor rt, String identifier) {
-       this(identifier);
+       super(identifier);
        this.modifier=m;
        this.returntype=rt;
        this.identifier=identifier;
@@ -32,10 +32,6 @@ public class MethodDescriptor extends Descriptor {
        thisvd=null;
     }
 
-    protected MethodDescriptor(String s) {
-       super(s);
-    }
-
     public Modifiers getModifiers() {
        return modifier;
     }
@@ -56,7 +52,7 @@ public class MethodDescriptor extends Descriptor {
     }
 
     public MethodDescriptor(Modifiers m, String identifier) {
-       this(identifier);
+       super(identifier);
        this.modifier=m;
        this.returntype=null;
        this.identifier=identifier;
index 06666e204123c4c1d117e082141c45283b24d120..c893c20ee70e0ceb9c1579297fe01a869074a4f0 100644 (file)
@@ -104,6 +104,10 @@ public class State {
        flatmethodmap.put(md,bn);
     }
 
+    public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
+       flatmethodmap.put(td,bn);
+    }
+
     public void addTask(TaskDescriptor td) {
        if (tasks.contains(td.getSymbol()))
            throw new Error("Task "+td.getSymbol()+" defined twice");
index 243e8fef299a7aab6de488f9ee56e4ffafea0e88..1ee16345128d38bb937051b7cf64b70dfe8d2a72 100644 (file)
@@ -10,10 +10,13 @@ import IR.Tree.Modifiers;
  *
  */
 
-public class TaskDescriptor extends MethodDescriptor {
+public class TaskDescriptor extends Descriptor {
 
     protected Hashtable flagstable;
     protected Vector vfe;
+    protected String identifier;
+    protected Vector params;
+    protected SymbolTable paramtable;
 
     public TaskDescriptor(String identifier) {
        super(identifier);
@@ -32,35 +35,8 @@ public class TaskDescriptor extends MethodDescriptor {
        return vfe;
     }
 
-    public Modifiers getModifiers() {
-       throw new Error();
-    }
-    public boolean matches(MethodDescriptor md) {
-       throw new Error();
-    }
-    public void setThis(VarDescriptor vd) {
-       throw new Error();
-    }
-    public VarDescriptor getThis() {
-       throw new Error();
-    }
-    public String getSafeMethodDescriptor() {
-       throw new Error();
-    }
-    public boolean isStatic() {
-       throw new Error();
-    }
-    public boolean isConstructor() {
-       throw new Error();
-    }
-    public TypeDescriptor getReturnType() {
-       throw new Error();
-    }
-    public void setClassDesc(ClassDescriptor cd) {
-       throw new Error();
-    }
-    public ClassDescriptor getClassDesc() {
-       throw new Error();
+    public SymbolTable getParameterTable() {
+       return paramtable;
     }
 
     public void addParameter(TypeDescriptor type, String paramname, FlagExpressionNode fen) {
@@ -75,6 +51,22 @@ public class TaskDescriptor extends MethodDescriptor {
        paramtable.add(vd);
     }
 
+    public int numParameters() {
+       return params.size();
+    }
+
+    public VarDescriptor getParameter(int i) {
+       return (VarDescriptor)params.get(i);
+    }
+
+    public String getParamName(int i) {
+       return ((VarDescriptor)params.get(i)).getName();
+    }
+
+    public TypeDescriptor getParamType(int i) {
+       return ((VarDescriptor)params.get(i)).getType();
+    }
+
     public FlagExpressionNode getFlag(VarDescriptor vd) {
        return (FlagExpressionNode) flagstable.get(vd);
     }
index c5a57f151a54609496c1a71b38f8aee281479343..9a78cb420a94aec88e3865b70d0776a2806874e0 100644 (file)
@@ -177,7 +177,7 @@ public class SemanticCheck {
        checkBlockNode(md, md.getParameterTable(),bn);
     }
     
-    public void checkBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn) {
+    public void checkBlockNode(Descriptor md, SymbolTable nametable, BlockNode bn) {
        /* Link in the naming environment */
        bn.getVarTable().setParent(nametable);
        for(int i=0;i<bn.size();i++) {
@@ -186,7 +186,7 @@ public class SemanticCheck {
        }
     }
     
-    public void checkBlockStatementNode(MethodDescriptor md, SymbolTable nametable, BlockStatementNode bsn) {
+    public void checkBlockStatementNode(Descriptor md, SymbolTable nametable, BlockStatementNode bsn) {
        switch(bsn.kind()) {
        case Kind.BlockExpressionNode:
            checkBlockExpressionNode(md, nametable,(BlockExpressionNode)bsn);
@@ -219,11 +219,11 @@ public class SemanticCheck {
        throw new Error();
     }
 
-    void checkBlockExpressionNode(MethodDescriptor md, SymbolTable nametable, BlockExpressionNode ben) {
+    void checkBlockExpressionNode(Descriptor md, SymbolTable nametable, BlockExpressionNode ben) {
        checkExpressionNode(md, nametable, ben.getExpression(), null);
     }
 
-    void checkDeclarationNode(MethodDescriptor md, SymbolTable nametable,  DeclarationNode dn) {
+    void checkDeclarationNode(Descriptor md, SymbolTable nametable,  DeclarationNode dn) {
        VarDescriptor vd=dn.getVarDescriptor();
        checkTypeDescriptor(vd.getType());
        Descriptor d=nametable.get(vd.getSymbol());
@@ -236,13 +236,14 @@ public class SemanticCheck {
            checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
     }
     
-    void checkSubBlockNode(MethodDescriptor md, SymbolTable nametable, SubBlockNode sbn) {
+    void checkSubBlockNode(Descriptor md, SymbolTable nametable, SubBlockNode sbn) {
        checkBlockNode(md, nametable, sbn.getBlockNode());
     }
 
-    void checkReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn) {
-       if (md instanceof TaskDescriptor)
-           throw new Error("Illegal return appears in Task: "+md.getSymbol());
+    void checkReturnNode(Descriptor d, SymbolTable nametable, ReturnNode rn) {
+       if (d instanceof TaskDescriptor)
+           throw new Error("Illegal return appears in Task: "+d.getSymbol());
+       MethodDescriptor md=(MethodDescriptor)d;
        if (rn.getReturnExpression()!=null)
            checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
        else
@@ -250,20 +251,20 @@ public class SemanticCheck {
                throw new Error("Need to return something for "+md);
     }
 
-    void checkTaskExitNode(MethodDescriptor md, SymbolTable nametable, TaskExitNode ten) {
-       if (!(md instanceof TaskDescriptor))
+    void checkTaskExitNode(Descriptor md, SymbolTable nametable, TaskExitNode ten) {
+       if (md instanceof MethodDescriptor)
            throw new Error("Illegal taskexit appears in Method: "+md.getSymbol());
        checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects());
     }
 
-    void checkIfStatementNode(MethodDescriptor md, SymbolTable nametable, IfStatementNode isn) {
+    void checkIfStatementNode(Descriptor md, SymbolTable nametable, IfStatementNode isn) {
        checkExpressionNode(md, nametable, isn.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
        checkBlockNode(md, nametable, isn.getTrueBlock());
        if (isn.getFalseBlock()!=null)
            checkBlockNode(md, nametable, isn.getFalseBlock());
     }
     
-    void checkExpressionNode(MethodDescriptor md, SymbolTable nametable, ExpressionNode en, TypeDescriptor td) {
+    void checkExpressionNode(Descriptor md, SymbolTable nametable, ExpressionNode en, TypeDescriptor td) {
        switch(en.kind()) {
         case Kind.AssignmentNode:
             checkAssignmentNode(md,nametable,(AssignmentNode)en,td);
@@ -296,7 +297,7 @@ public class SemanticCheck {
        throw new Error();
     }
 
-    void checkCastNode(MethodDescriptor md, SymbolTable nametable, CastNode cn, TypeDescriptor td) {
+    void checkCastNode(Descriptor md, SymbolTable nametable, CastNode cn, TypeDescriptor td) {
        /* Get type descriptor */
        if (cn.getType()==null) {
            NameDescriptor typenamed=cn.getTypeName().getName();
@@ -329,7 +330,7 @@ public class SemanticCheck {
        throw new Error("Cast will always fail\n"+cn.printNode(0));
     }
 
-    void checkFieldAccessNode(MethodDescriptor md, SymbolTable nametable, FieldAccessNode fan, TypeDescriptor td) {
+    void checkFieldAccessNode(Descriptor md, SymbolTable nametable, FieldAccessNode fan, TypeDescriptor td) {
        ExpressionNode left=fan.getExpression();
        checkExpressionNode(md,nametable,left,null);
        TypeDescriptor ltd=left.getType();
@@ -348,7 +349,7 @@ public class SemanticCheck {
                throw new Error("Field node returns "+fan.getType()+", but need "+td);
     }
 
-    void checkArrayAccessNode(MethodDescriptor md, SymbolTable nametable, ArrayAccessNode aan, TypeDescriptor td) {
+    void checkArrayAccessNode(Descriptor md, SymbolTable nametable, ArrayAccessNode aan, TypeDescriptor td) {
        ExpressionNode left=aan.getExpression();
        checkExpressionNode(md,nametable,left,null);
 
@@ -360,7 +361,7 @@ public class SemanticCheck {
                throw new Error("Field node returns "+aan.getType()+", but need "+td);
     }
 
-    void checkLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode ln, TypeDescriptor td) {
+    void checkLiteralNode(Descriptor md, SymbolTable nametable, LiteralNode ln, TypeDescriptor td) {
        /* Resolve the type */
        Object o=ln.getValue();
        if (ln.getTypeString().equals("null")) {
@@ -386,7 +387,7 @@ public class SemanticCheck {
                throw new Error("Field node returns "+ln.getType()+", but need "+td);
     }
 
-    void checkNameNode(MethodDescriptor md, SymbolTable nametable, NameNode nn, TypeDescriptor td) {
+    void checkNameNode(Descriptor md, SymbolTable nametable, NameNode nn, TypeDescriptor td) {
        NameDescriptor nd=nn.getName();
        if (nd.getBase()!=null) {
            /* Big hack */
@@ -412,7 +413,7 @@ public class SemanticCheck {
        }
     }
 
-    void checkAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
+    void checkAssignmentNode(Descriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
        checkExpressionNode(md, nametable, an.getSrc() ,td);
        //TODO: Need check on validity of operation here
        if (!((an.getDest() instanceof FieldAccessNode)||
@@ -425,7 +426,7 @@ public class SemanticCheck {
        }
     }
 
-    void checkLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln) {
+    void checkLoopNode(Descriptor md, SymbolTable nametable, LoopNode ln) {
        if (ln.getType()==LoopNode.WHILELOOP||ln.getType()==LoopNode.DOWHILELOOP) {
            checkExpressionNode(md, nametable, ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
            checkBlockNode(md, nametable, ln.getBody());
@@ -446,7 +447,7 @@ public class SemanticCheck {
     }
 
 
-    void checkCreateObjectNode(MethodDescriptor md, SymbolTable nametable, CreateObjectNode con, TypeDescriptor td) {
+    void checkCreateObjectNode(Descriptor md, SymbolTable nametable, CreateObjectNode con, TypeDescriptor td) {
        TypeDescriptor[] tdarray=new TypeDescriptor[con.numArgs()];
        for(int i=0;i<con.numArgs();i++) {
            ExpressionNode en=con.getArg(i);
@@ -524,7 +525,7 @@ public class SemanticCheck {
     }
 
 
-    void checkMethodInvokeNode(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min, TypeDescriptor td) {
+    void checkMethodInvokeNode(Descriptor md, SymbolTable nametable, MethodInvokeNode min, TypeDescriptor td) {
        /*Typecheck subexpressions
          and get types for expressions*/
 
@@ -552,8 +553,8 @@ public class SemanticCheck {
                    throw new Error(min.getBaseName()+" undefined");
                typetolookin=new TypeDescriptor(cd);
            }
-       } else if (!(md instanceof TaskDescriptor)) {
-           typetolookin=new TypeDescriptor(md.getClassDesc());
+       } else if (md instanceof MethodDescriptor) {
+           typetolookin=new TypeDescriptor(((MethodDescriptor)md).getClassDesc());
        } else {
            /* If this a task descriptor we throw an error at this point */
            throw new Error("Unknown method call to "+min.getMethodName()+"in task"+md.getSymbol());
@@ -601,7 +602,7 @@ public class SemanticCheck {
     }
 
 
-    void checkOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on, TypeDescriptor td) {
+    void checkOpNode(Descriptor md, SymbolTable nametable, OpNode on, TypeDescriptor td) {
        checkExpressionNode(md, nametable, on.getLeft(), null);
        if (on.getRight()!=null)
            checkExpressionNode(md, nametable, on.getRight(), null);