np_baseexp.getEnd().addNext(fsfn);
return new NodePair(np_src.getBegin(), fsfn);
} else if (an.getDest().kind()==Kind.NameNode) {
-
- //TODO: FIXME
- FlatNop nop=new FlatNop();
- return new NodePair(nop,nop);
- } else throw new Error();
+ NameNode nn=(NameNode)an.getDest();
+ if (nn.getExpression()!=null) {
+ FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
+ ExpressionNode en=fan.getExpression();
+ TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst");
+ NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
+ last.addNext(np_baseexp.getBegin());
+ FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
+ np_baseexp.getEnd().addNext(fsfn);
+ return new NodePair(np_src.getBegin(), fsfn);
+ } else {
+ if (nn.getField()!=null) {
+ FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
+ last.addNext(fsfn);
+ return new NodePair(np_src.getBegin(), fsfn);
+ } else {
+ FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
+ last.addNext(fon);
+ return new NodePair(np_src.getBegin(),fon);
+ }
+ }
+ }
+ throw new Error();
}
private NodePair flattenNameNode(NameNode nn,TempDescriptor out_temp) {
- if (nn.getField()!=null) {
+ if (nn.getExpression()!=null) {
+ /* Hack - use subtree instead */
+ return flattenExpressionNode(nn.getExpression(),out_temp);
+ } else if (nn.getField()!=null) {
TempDescriptor tmp=getTempforVar(nn.getVar());
FlatFieldNode ffn=new FlatFieldNode(nn.getField(), tmp, out_temp);
return new NodePair(ffn,ffn);
}
public String toString() {
- String st=dst+"="+method.toString()+"("+this_temp;
+ String st="";
+ if (dst==null)
+ st+=method.getSymbol()+"(";
+ else
+ st+=dst+"="+method.getSymbol()+"(";
+ if (this_temp!=null) {
+ st+=this_temp;
+ if (args.length!=0)
+ st+=", ";
+ }
+
for(int i=0;i<args.length;i++) {
st+=args[i].toString();
if ((i+1)<args.length)
NameDescriptor name;
VarDescriptor vd;
FieldDescriptor fd;
+ ExpressionNode en;
public NameNode(NameDescriptor nd) {
this.name=nd;
this.fd=null;
}
+ public ExpressionNode getExpression() {
+ return en;
+ }
+
+ /* Gross hack */
+ public void setExpression(ExpressionNode en) {
+ this.en=en;
+ }
+
public void setVar(VarDescriptor vd) {
this.vd=vd;
}
}
public TypeDescriptor getType() {
- if (fd!=null)
+ if (en!=null)
+ return en.getType();
+ else if (fd!=null)
return fd.getType();
else
return vd.getType();
void checkNameNode(MethodDescriptor md, SymbolTable nametable, NameNode nn, TypeDescriptor td) {
NameDescriptor nd=nn.getName();
- String varname=nd.toString();
- Descriptor d=(Descriptor)nametable.get(varname);
- if (d==null) {
- throw new Error("Name "+varname+" undefined");
- }
- if (d instanceof VarDescriptor) {
- nn.setVar((VarDescriptor)d);
- } else if (d instanceof FieldDescriptor) {
- nn.setField((FieldDescriptor)d);
- nn.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
+ if (nd.getBase()!=null) {
+ /* Big hack */
+ /* Rewrite NameNode */
+ ExpressionNode en=translateNameDescriptorintoExpression(nd);
+ nn.setExpression(en);
+ checkExpressionNode(md,nametable,en,td);
+ } else {
+ String varname=nd.toString();
+ Descriptor d=(Descriptor)nametable.get(varname);
+ if (d==null) {
+ throw new Error("Name "+varname+" undefined");
+ }
+ if (d instanceof VarDescriptor) {
+ nn.setVar((VarDescriptor)d);
+ } else if (d instanceof FieldDescriptor) {
+ nn.setField((FieldDescriptor)d);
+ nn.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
+ }
+ if (td!=null)
+ if (!typeutil.isSuperorType(td,nn.getType()))
+ throw new Error("Field node returns "+nn.getType()+", but need "+td);
}
- if (td!=null)
- if (!typeutil.isSuperorType(td,nn.getType()))
- throw new Error("Field node returns "+nn.getType()+", but need "+td);
}
void checkAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {