Checked in code to:
authorbdemsky <bdemsky>
Mon, 15 May 2006 19:49:07 +0000 (19:49 +0000)
committerbdemsky <bdemsky>
Mon, 15 May 2006 19:49:07 +0000 (19:49 +0000)
1) Build parse tree for tasks
2) Type check flag expressions

Robust/src/IR/State.java
Robust/src/IR/TaskDescriptor.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/FlagNode.java
Robust/src/IR/Tree/SemanticCheck.java

index a811df0819de8cdc34ae82711a118cf5edf4a21d..b25453929608cfc85b7da0865a0e3e99396783b7 100644 (file)
@@ -80,6 +80,10 @@ public class State {
        return classes;
     }
 
+    public SymbolTable getTaskSymbolTable() {
+       return tasks;
+    }
+
     public FlatMethod getMethodFlat(MethodDescriptor md) {
        return (FlatMethod)flatmethodmap.get(md);
     }
index 96489bc804ad348cb42d4f90084f1f4dea34d825..47a92909fb4b6f41af38c67d40e2c1fa178845cf 100644 (file)
@@ -58,6 +58,10 @@ public class TaskDescriptor extends Descriptor {
        paramtable.add(vd);
     }
 
+    public FlagExpressionNode getFlag(VarDescriptor vd) {
+       return (FlagExpressionNode) flagstable.get(vd);
+    }
+
     public int numParameters() {
        return params.size();
     }
index 0150b12e432e42f8c7ab70a3a8f8ca637d4b3814..c9368be4d7d59b2dcf84cf08a2a47246f7e5d3c0 100644 (file)
@@ -63,13 +63,24 @@ public class BuildIR {
        if (isNode(pn,"flag_effect")) {
            String flagname=pn.getChild("name").getTerminal();
            FlagEffects fe=new FlagEffects(flagname);
-
-           
-           
+           parseFlagEffect(fe, pn.getChild("flag_list"));
            return fe;
        } else throw new Error();
     }
 
+    public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
+       ParseNodeVector pnv=pn.getChildren();
+       for(int i=0;i<pnv.size();i++) {
+           boolean status=true;
+           if (pn.getChild("not")!=null) {
+               status=false;
+               pn=pn.getChild("not");
+           }
+           String name=pn.getChild("name").getTerminal();
+           fes.addEffect(new FlagEffect(name,status));
+       }
+    }
+
     public FlagExpressionNode parseFlagExpression(ParseNode pn) {
        if (pn.getChild("or")!=null) {
            ParseNodeVector pnv=pn.getChild("or").getChildren();
@@ -156,6 +167,10 @@ public class BuildIR {
            parseMethodDecl(cn,methodnode.getChild("method_declaration"));
            return;
        }
+       ParseNode flagnode=pn.getChild("flag");
+       if (flagnode!=null) {
+           parseFlagDecl(cn, flagnode.getChild("flag_declaration"));
+       }
        throw new Error();
     }
 
@@ -202,6 +217,11 @@ public class BuildIR {
        
     }
 
+    private void parseFlagDecl(ClassDescriptor cn,ParseNode pn) {
+       String name=pn.getChild("name").getTerminal();
+       cn.addFlag(new FlagDescriptor(name));
+    }
+
     private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) {
        ParseNode mn=pn.getChild("modifier");
        Modifiers m=parseModifiersList(mn);
index 3ef4fa97a7e45ee6bf7d1a6eaf7881748d3a1f06..7b18b7f5eec1849860cc6651a856408588345614 100644 (file)
@@ -18,6 +18,10 @@ public class FlagNode extends FlagExpressionNode {
        return flag;
     }
 
+    public String getFlagName() {
+       return name;
+    }
+
     public int kind() {
        return Kind.FlagNode;
     }
index f9ef70c7c8f9138113ba11645190fe73ac3fe2cd..561c9021422524b46e6e7c0da455a4beb5223e47 100644 (file)
@@ -22,16 +22,20 @@ public class SemanticCheck {
            //Set superclass link up
            if (cd.getSuper()!=null) {
                cd.setSuper(typeutil.getClass(cd.getSuper()));
-               // Link together Field and Method tables
+               // Link together Field, Method, and Flag tables so classes
+               // inherit these from their superclasses
                cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
                cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
+               cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
            }
            
+           /* Check to see that fields are well typed */
            for(Iterator field_it=cd.getFields();field_it.hasNext();) {
                FieldDescriptor fd=(FieldDescriptor)field_it.next();
                System.out.println("Checking field: "+fd);
                checkField(cd,fd);
            }
+
            for(Iterator method_it=cd.getMethods();method_it.hasNext();) {
                MethodDescriptor md=(MethodDescriptor)method_it.next();
                checkMethod(cd,md);
@@ -47,6 +51,13 @@ public class SemanticCheck {
                checkMethodBody(cd,md);
            }
        }
+
+       for(Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator();task_it.hasNext();) {
+           TaskDescriptor td=(TaskDescriptor)task_it.next();
+           
+           
+       }
+
     }
 
     public void checkTypeDescriptor(TypeDescriptor td) {
@@ -67,6 +78,46 @@ public class SemanticCheck {
        checkTypeDescriptor(fd.getType());
     }
 
+    public void checkTask(TaskDescriptor td) {
+       for(int i=0;i<td.numParameters();i++) {
+           /* Check that parameter is well typed */
+           TypeDescriptor param_type=td.getParamType(i);
+           checkTypeDescriptor(param_type);
+
+           /* Check the parameter's flag expression is well formed */
+           FlagExpressionNode fen=td.getFlag(td.getParameter(i));
+           if (!param_type.isClass())
+               throw new Error("Cannot have non-object argument to a task");
+           ClassDescriptor cd=param_type.getClassDesc();
+           checkFlagExpressionNode(cd, fen);
+       }
+    }
+
+    public void checkFlagExpressionNode(ClassDescriptor cd, FlagExpressionNode fen) {
+       switch(fen.kind()) {
+       case Kind.FlagOpNode: 
+           {
+               FlagOpNode fon=(FlagOpNode)fen;
+               checkFlagExpressionNode(cd, fon.getLeft());
+               if (fon.getRight()!=null)
+                   checkFlagExpressionNode(cd, fon.getRight());
+               break;
+           }
+       case Kind.FlagNode:
+           {
+               FlagNode fn=(FlagNode)fen;
+               String name=fn.getFlagName();
+               FlagDescriptor fd=(FlagDescriptor)cd.getFlagTable().get(name);
+               if (fd==null)
+                   throw new Error("Undeclared flag: "+name);
+               fn.setFlag(fd);
+               break;
+           }
+       default:
+           throw new Error("Unrecognized FlagExpressionNode");
+       }
+    }
+
     public void checkMethod(ClassDescriptor cd, MethodDescriptor md) {
        /* Check return type */
        if (!md.isConstructor())