Flatten fields in namenodes
authorbdemsky <bdemsky>
Thu, 9 Mar 2006 02:35:06 +0000 (02:35 +0000)
committerbdemsky <bdemsky>
Thu, 9 Mar 2006 02:35:06 +0000 (02:35 +0000)
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Flat/FlatCall.java
Robust/src/IR/Tree/NameNode.java
Robust/src/IR/Tree/SemanticCheck.java

index d1f35b14f8dd807ad83bf5513c40bb25214bb517..32684bc6f16c3a284b414aad06f352c6642a45d2 100644 (file)
@@ -169,15 +169,36 @@ public class BuildFlat {
            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);
index 057cb3c29b8bc3a4cc35866550599609239bd048..df88faced694681306fca51d9cd7c840bb83cd1d 100644 (file)
@@ -15,7 +15,17 @@ public class FlatCall extends FlatNode {
     }
 
     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)
index 819e8b1efe395c8e7c68515123d7eff47e39c0dd..bf7378691dbbdc6a543543215f67bb015da8cd7a 100644 (file)
@@ -8,6 +8,7 @@ public class NameNode extends ExpressionNode {
     NameDescriptor name;
     VarDescriptor vd;
     FieldDescriptor fd;
+    ExpressionNode en;
 
     public NameNode(NameDescriptor nd) {
        this.name=nd;
@@ -15,6 +16,15 @@ public class NameNode extends ExpressionNode {
        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;
     }
@@ -32,7 +42,9 @@ public class NameNode extends ExpressionNode {
     }
 
     public TypeDescriptor getType() {
-       if (fd!=null)
+       if (en!=null)
+           return en.getType();
+       else if (fd!=null)
            return fd.getType();
        else
            return vd.getType();
index eb6635e3d776de69151df1de145ba86a8cca3960..ee1968c4e2fbf2994443acd287ab590401ab9e7b 100644 (file)
@@ -266,20 +266,28 @@ public class SemanticCheck {
 
     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) {