public class ClassDescriptor extends Descriptor {
public ClassDescriptor(String classname) {
super(classname);
- this.classname=classname;
superclass=null;
+ flags=new SymbolTable();
fields=new SymbolTable();
methods=new SymbolTable();
classid=UIDCount++;
}
private static int UIDCount=0;
private final int classid;
- String classname;
String superclass;
ClassDescriptor superdesc;
public String printTree(State state) {
int indent;
- String st=modifiers.toString()+"class "+classname;
+ String st=modifiers.toString()+"class "+getSymbol();
if (superclass!=null)
st+="extends "+superclass.toString();
st+=" {\n";
this.modifiers=modifiers;
}
- public void setName(String name) {
- classname=name;
- }
-
public void setSuper(String superclass) {
this.superclass=superclass;
}
public MethodDescriptor(Modifiers m, TypeDescriptor rt, String identifier) {
- super(identifier);
+ this(identifier);
this.modifier=m;
this.returntype=rt;
this.identifier=identifier;
thisvd=null;
}
+ protected MethodDescriptor(String s) {
+ super(s);
+ }
public Modifiers getModifiers() {
return modifier;
}
public MethodDescriptor(Modifiers m, String identifier) {
- super(identifier);
+ this(identifier);
this.modifier=m;
this.returntype=null;
this.identifier=identifier;
return (BlockNode)treemethodmap.get(md);
}
+ public BlockNode getMethodBody(TaskDescriptor td) {
+ return (BlockNode)treemethodmap.get(td);
+ }
+
public SymbolTable getClassSymbolTable() {
return classes;
}
import IR.Tree.FlagEffects;
import java.util.Vector;
import java.util.Hashtable;
+import IR.Tree.Modifiers;
/**
* Descriptor
*
*/
-public class TaskDescriptor extends Descriptor {
+public class TaskDescriptor extends MethodDescriptor {
- protected String identifier;
- protected Vector params;
- protected SymbolTable paramtable;
- protected VarDescriptor thisvd;
protected Hashtable flagstable;
protected Vector vfe;
flagstable=new Hashtable();
params=new Vector();
paramtable=new SymbolTable();
- thisvd=null;
}
public void addFlagEffects(Vector vfe) {
this.vfe=vfe;
}
- public String getSafeMethodDescriptor() {
- String st="";
- for(int i=0;i<numParameters();i++) {
- st+=getParamType(i).getSafeDescriptor();
- if ((i+1)<numParameters())
- st+="_";
- }
- return st;
+ public Vector getFlagEffects() {
+ return vfe;
}
- public SymbolTable getParameterTable() {
- return paramtable;
+ 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 void addParameter(TypeDescriptor type, String paramname, FlagExpressionNode fen) {
return (FlagExpressionNode) flagstable.get(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 String toString() {
String st=identifier+"(";
for(int i=0;i<params.size();i++) {
return flag;
}
+ public String getName() {
+ return name;
+ }
+
public int kind() {
return Kind.FlagNode;
}
public class FlagEffects {
Vector effects;
String name;
+ VarDescriptor vd;
public FlagEffects(String name) {
effects=new Vector();
this.name=name;
}
+ public void setVar(VarDescriptor vd) {
+ this.vd=vd;
+ }
+
+ public VarDescriptor getVar() {
+ return vd;
+ }
+
+ public String getName() {
+ return name;
+ }
+
public void addEffect(FlagEffect fe) {
effects.add(fe);
}
+ public int numEffects() {
+ return effects.size();
+ }
+
+ public FlagEffect getEffect(int i) {
+ return (FlagEffect) effects.get(i);
+ }
+
public String printNode(int indent) {
String st=name+"(";
for(int i=0;i<effects.size();i++) {
for(Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator();task_it.hasNext();) {
TaskDescriptor td=(TaskDescriptor)task_it.next();
-
+ checkTask(td);
}
checkTypeDescriptor(fd.getType());
}
+ public void checkFlagEffects(TaskDescriptor td, Vector vfe) {
+ for(int i=0;i<vfe.size();i++) {
+ FlagEffects fe=(FlagEffects) vfe.get(i);
+ String varname=fe.getName();
+ //Make sure the variable is declared as a parameter to the task
+ VarDescriptor vd=(VarDescriptor)td.getParameterTable().get(varname);
+ if (vd==null)
+ throw new Error("Parameter "+varname+" in Flag Effects not declared");
+ fe.setVar(vd);
+
+ //Make sure it correspods to a class
+ TypeDescriptor type_d=vd.getType();
+ if (!type_d.isClass())
+ throw new Error("Cannot have non-object argument for flag_effect");
+
+ ClassDescriptor cd=type_d.getClassDesc();
+ for(int j=0;j<fe.numEffects();j++) {
+ FlagEffect flag=fe.getEffect(j);
+ String name=flag.getName();
+ FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
+ //Make sure the flag is declared
+ if (flag_d==null)
+ throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
+ flag.setFlag(flag_d);
+ }
+ }
+ }
+
public void checkTask(TaskDescriptor td) {
for(int i=0;i<td.numParameters();i++) {
/* Check that parameter is well typed */
throw new Error("Cannot have non-object argument to a task");
ClassDescriptor cd=param_type.getClassDesc();
checkFlagExpressionNode(cd, fen);
+ checkFlagEffects(td, td.getFlagEffects());
+
+ /* Check that the task code is valid */
+ BlockNode bn=state.getMethodBody(td);
+ checkBlockNode(td, td.getParameterTable(),bn);
}
}
checkReturnNode(md, nametable, (ReturnNode)bsn);
return;
+ case Kind.TaskExitNode:
+ checkTaskExitNode(md, nametable, (TaskExitNode)bsn);
+ return;
+
case Kind.SubBlockNode:
checkSubBlockNode(md, nametable, (SubBlockNode)bsn);
return;
}
void checkReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn) {
+ if (md instanceof TaskDescriptor)
+ throw new Error("Illegal return appears in Task: "+md.getSymbol());
if (rn.getReturnExpression()!=null)
checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
else
throw new Error("Need to return something for "+md);
}
+ void checkTaskExitNode(MethodDescriptor md, SymbolTable nametable, TaskExitNode ten) {
+ if (!(md instanceof TaskDescriptor))
+ throw new Error("Illegal taskexit appears in Method: "+md.getSymbol());
+ checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects());
+ }
+
void checkIfStatementNode(MethodDescriptor md, SymbolTable nametable, IfStatementNode isn) {
checkExpressionNode(md, nametable, isn.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
checkBlockNode(md, nametable, isn.getTrueBlock());
throw new Error(min.getBaseName()+" undefined");
typetolookin=new TypeDescriptor(cd);
}
- } else {
+ } else if (!(md instanceof TaskDescriptor)) {
typetolookin=new TypeDescriptor(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());
}
if (!typetolookin.isClass())
throw new Error();
return "taskexit";
}
+ public Vector getFlagEffects() {
+ return vfe;
+ }
+
public int kind() {
return Kind.TaskExitNode;
}
-CLASSFILES=Main/Main.class IR/AssignOperation.class IR/Descriptor.class \
-IR/FieldDescriptor.class IR/MethodDescriptor.class \
-IR/NameDescriptor.class IR/Operation.class IR/State.class \
-IR/SymbolTable.class IR/Tree/AssignmentNode.class \
+CLASSFILES= Main/Main.class IR/AssignOperation.class \
+IR/ClassDescriptor.class IR/Descriptor.class IR/FieldDescriptor.class \
+IR/FlagDescriptor.class IR/Flat/BuildCode.class \
+IR/Flat/BuildFlat.class IR/Flat/FKind.class IR/Flat/FlatCall.class \
+IR/Flat/FlatCastNode.class IR/Flat/FlatCondBranch.class \
+IR/Flat/FlatElementNode.class IR/Flat/FlatFieldNode.class \
+IR/Flat/FlatLiteralNode.class IR/Flat/FlatMethod.class \
+IR/Flat/FlatNew.class IR/Flat/FlatNode.class IR/Flat/FlatNop.class \
+IR/Flat/FlatOpNode.class IR/Flat/FlatReturnNode.class \
+IR/Flat/FlatSetElementNode.class IR/Flat/FlatSetFieldNode.class \
+IR/Flat/NodePair.class IR/Flat/ParamsObject.class \
+IR/Flat/TempDescriptor.class IR/Flat/TempObject.class \
+IR/MethodDescriptor.class IR/NameDescriptor.class IR/Operation.class \
+IR/State.class IR/SymbolTable.class IR/TaskDescriptor.class \
+IR/Tree/ArrayAccessNode.class IR/Tree/AssignmentNode.class \
IR/Tree/BlockExpressionNode.class IR/Tree/BlockNode.class \
IR/Tree/BlockStatementNode.class IR/Tree/BuildIR.class \
IR/Tree/CastNode.class IR/Tree/CreateObjectNode.class \
IR/Tree/DeclarationNode.class IR/Tree/ExpressionNode.class \
-IR/Tree/FieldAccessNode.class IR/Tree/IfStatementNode.class \
+IR/Tree/FieldAccessNode.class IR/Tree/FlagEffect.class \
+IR/Tree/FlagEffects.class IR/Tree/FlagExpressionNode.class \
+IR/Tree/FlagNode.class IR/Tree/FlagOpNode.class \
+IR/Tree/IfStatementNode.class IR/Tree/Kind.class \
IR/Tree/LiteralNode.class IR/Tree/LoopNode.class \
IR/Tree/MethodInvokeNode.class IR/Tree/Modifiers.class \
IR/Tree/NameNode.class IR/Tree/OpNode.class IR/Tree/ParseNode.class \
IR/Tree/ParseNodeDOTVisitor.class IR/Tree/ParseNodeVector.class \
-IR/Tree/ReturnNode.class IR/Tree/SubBlockNode.class \
+IR/Tree/ReturnNode.class IR/Tree/SemanticCheck.class \
+IR/Tree/SubBlockNode.class IR/Tree/TaskExitNode.class \
IR/Tree/TreeNode.class IR/Tree/Walkable.class IR/TypeDescriptor.class \
-IR/VarDescriptor.class Lex/BooleanLiteral.class \
-Lex/CharacterLiteral.class Lex/Comment.class \
+IR/TypeUtil.class IR/VarDescriptor.class IR/Virtual.class \
+Lex/BooleanLiteral.class Lex/CharacterLiteral.class Lex/Comment.class \
Lex/DocumentationComment.class Lex/DoubleLiteral.class \
Lex/EndOfLineComment.class Lex/EOF.class \
Lex/EscapedUnicodeReader.class Lex/FIFO.class Lex/FloatLiteral.class \