Hack the compiler to support 'abstract' keyword for mgc version. Abstract classes...
[IRC.git] / Robust / src / IR / Tree / SemanticCheck.java
1 package IR.Tree;
2
3 import java.util.*;
4
5 import IR.*;
6
7 public class SemanticCheck {
8   State state;
9   TypeUtil typeutil;
10   Stack loopstack;
11   HashSet toanalyze;
12   HashSet completed;
13
14
15   public SemanticCheck(State state, TypeUtil tu) {
16     this.state=state;
17     this.typeutil=tu;
18     this.loopstack=new Stack();
19     this.toanalyze=new HashSet();
20     this.completed=new HashSet();
21   }
22
23   public ClassDescriptor getClass(String classname) {
24     ClassDescriptor cd=typeutil.getClass(classname, toanalyze);
25     checkClass(cd);
26     return cd;
27   }
28
29   private void checkClass(ClassDescriptor cd) {
30     if (!completed.contains(cd)) {
31       completed.add(cd);
32       
33       //Set superclass link up
34       if (cd.getSuper()!=null) {
35         cd.setSuper(getClass(cd.getSuper()));
36         // Link together Field, Method, and Flag tables so classes
37         // inherit these from their superclasses
38         cd.getFieldTable().setParent(cd.getSuperDesc().getFieldTable());
39         cd.getMethodTable().setParent(cd.getSuperDesc().getMethodTable());
40         cd.getFlagTable().setParent(cd.getSuperDesc().getFlagTable());
41       }
42       
43       /* Check to see that fields are well typed */
44       for(Iterator field_it=cd.getFields(); field_it.hasNext();) {
45         FieldDescriptor fd=(FieldDescriptor)field_it.next();
46         checkField(cd,fd);
47       }
48       
49       for(Iterator method_it=cd.getMethods(); method_it.hasNext();) {
50         MethodDescriptor md=(MethodDescriptor)method_it.next();
51         checkMethod(cd,md);
52       }
53     }
54   }
55
56   public void semanticCheck() {
57     SymbolTable classtable=state.getClassSymbolTable();
58     toanalyze.addAll(classtable.getValueSet());
59     toanalyze.addAll(state.getTaskSymbolTable().getValueSet());
60
61     // Do methods next
62     while(!toanalyze.isEmpty()) {
63       Object obj=toanalyze.iterator().next();
64       if (obj instanceof TaskDescriptor) {
65         toanalyze.remove(obj);
66         TaskDescriptor td=(TaskDescriptor)obj;
67         try {
68           checkTask(td);
69         } catch( Error e ) {
70             System.out.println( "Error in "+td );
71             throw e;
72         }
73       } else {
74         ClassDescriptor cd=(ClassDescriptor)obj;
75         toanalyze.remove(cd);
76         //need to initialize typeutil object here...only place we can
77         //get class descriptors without first calling getclass
78         getClass(cd.getSymbol());
79         for(Iterator method_it=cd.getMethods(); method_it.hasNext();) {
80           MethodDescriptor md=(MethodDescriptor)method_it.next();
81           try {
82             checkMethodBody(cd,md);
83           } catch( Error e ) {
84             System.out.println( "Error in "+md );
85             throw e;
86           }
87         }
88       }
89     }
90   }
91
92   public void checkTypeDescriptor(TypeDescriptor td) {
93     if (td.isPrimitive())
94       return;       /* Done */
95     else if (td.isClass()) {
96       String name=td.toString();
97       ClassDescriptor field_cd=getClass(name);
98       if (field_cd==null)
99         throw new Error("Undefined class "+name);
100       td.setClassDescriptor(field_cd);
101       return;
102     } else if (td.isTag())
103       return;
104     else
105       throw new Error();
106   }
107
108   public void checkField(ClassDescriptor cd, FieldDescriptor fd) {
109     checkTypeDescriptor(fd.getType());
110   }
111
112   public void checkConstraintCheck(TaskDescriptor td, SymbolTable nametable, Vector ccs) {
113     if (ccs==null)
114       return;       /* No constraint checks to check */
115     for(int i=0; i<ccs.size(); i++) {
116       ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
117
118       for(int j=0; j<cc.numArgs(); j++) {
119         ExpressionNode en=cc.getArg(j);
120         checkExpressionNode(td,nametable,en,null);
121       }
122     }
123   }
124
125   public void checkFlagEffects(TaskDescriptor td, Vector vfe, SymbolTable nametable) {
126     if (vfe==null)
127       return;       /* No flag effects to check */
128     for(int i=0; i<vfe.size(); i++) {
129       FlagEffects fe=(FlagEffects) vfe.get(i);
130       String varname=fe.getName();
131       //Make sure the variable is declared as a parameter to the task
132       VarDescriptor vd=(VarDescriptor)td.getParameterTable().get(varname);
133       if (vd==null)
134         throw new Error("Parameter "+varname+" in Flag Effects not declared in "+td);
135       fe.setVar(vd);
136
137       //Make sure it correspods to a class
138       TypeDescriptor type_d=vd.getType();
139       if (!type_d.isClass())
140         throw new Error("Cannot have non-object argument for flag_effect");
141
142       ClassDescriptor cd=type_d.getClassDesc();
143       for(int j=0; j<fe.numEffects(); j++) {
144         FlagEffect flag=fe.getEffect(j);
145         String name=flag.getName();
146         FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
147         //Make sure the flag is declared
148         if (flag_d==null)
149           throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
150         if (flag_d.getExternal())
151           throw new Error("Attempting to modify external flag: "+name);
152         flag.setFlag(flag_d);
153       }
154       for(int j=0; j<fe.numTagEffects(); j++) {
155         TagEffect tag=fe.getTagEffect(j);
156         String name=tag.getName();
157
158         Descriptor d=(Descriptor)nametable.get(name);
159         if (d==null)
160           throw new Error("Tag descriptor "+name+" undeclared");
161         else if (!(d instanceof TagVarDescriptor))
162           throw new Error(name+" is not a tag descriptor");
163         tag.setTag((TagVarDescriptor)d);
164       }
165     }
166   }
167
168   public void checkTask(TaskDescriptor td) {
169     for(int i=0; i<td.numParameters(); i++) {
170       /* Check that parameter is well typed */
171       TypeDescriptor param_type=td.getParamType(i);
172       checkTypeDescriptor(param_type);
173
174       /* Check the parameter's flag expression is well formed */
175       FlagExpressionNode fen=td.getFlag(td.getParameter(i));
176       if (!param_type.isClass())
177         throw new Error("Cannot have non-object argument to a task");
178       ClassDescriptor cd=param_type.getClassDesc();
179       if (fen!=null)
180         checkFlagExpressionNode(cd, fen);
181     }
182
183     checkFlagEffects(td, td.getFlagEffects(),td.getParameterTable());
184     /* Check that the task code is valid */
185     BlockNode bn=state.getMethodBody(td);
186     checkBlockNode(td, td.getParameterTable(),bn);
187   }
188
189   public void checkFlagExpressionNode(ClassDescriptor cd, FlagExpressionNode fen) {
190     switch(fen.kind()) {
191     case Kind.FlagOpNode:
192     {
193       FlagOpNode fon=(FlagOpNode)fen;
194       checkFlagExpressionNode(cd, fon.getLeft());
195       if (fon.getRight()!=null)
196         checkFlagExpressionNode(cd, fon.getRight());
197       break;
198     }
199
200     case Kind.FlagNode:
201     {
202       FlagNode fn=(FlagNode)fen;
203       String name=fn.getFlagName();
204       FlagDescriptor fd=(FlagDescriptor)cd.getFlagTable().get(name);
205       if (fd==null)
206         throw new Error("Undeclared flag: "+name);
207       fn.setFlag(fd);
208       break;
209     }
210
211     default:
212       throw new Error("Unrecognized FlagExpressionNode");
213     }
214   }
215
216   public void checkMethod(ClassDescriptor cd, MethodDescriptor md) {
217     if(state.MGC) {
218       // TODO add version for normal Java later
219       /* Check for abstract methods */
220       if(md.isAbstract()) {
221         if(!cd.isAbstract()) {
222           throw new Error("Error! The non-abstract Class " + cd.getSymbol() + "contains an abstract method " + md.getSymbol());
223         }
224       }
225     }
226     /* Check return type */
227     if (!md.isConstructor())
228       if (!md.getReturnType().isVoid())
229         checkTypeDescriptor(md.getReturnType());
230
231     for(int i=0; i<md.numParameters(); i++) {
232       TypeDescriptor param_type=md.getParamType(i);
233       checkTypeDescriptor(param_type);
234     }
235     /* Link the naming environments */
236     if (!md.isStatic())     /* Fields aren't accessible directly in a static method, so don't link in this table */
237       md.getParameterTable().setParent(cd.getFieldTable());
238     md.setClassDesc(cd);
239     if (!md.isStatic()) {
240       VarDescriptor thisvd=new VarDescriptor(new TypeDescriptor(cd),"this");
241       md.setThis(thisvd);
242     }
243   }
244
245   public void checkMethodBody(ClassDescriptor cd, MethodDescriptor md) {
246     ClassDescriptor superdesc=cd.getSuperDesc();
247     if (superdesc!=null) {
248       Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
249       for(Iterator methodit=possiblematches.iterator(); methodit.hasNext();) {
250         MethodDescriptor matchmd=(MethodDescriptor)methodit.next();
251         if (md.matches(matchmd)) {
252           if (matchmd.getModifiers().isFinal()) {
253             throw new Error("Try to override final method in method:"+md+" declared in  "+cd);
254           }
255         }
256       }
257     }
258     BlockNode bn=state.getMethodBody(md);
259     checkBlockNode(md, md.getParameterTable(),bn);
260   }
261
262   public void checkBlockNode(Descriptor md, SymbolTable nametable, BlockNode bn) {
263     /* Link in the naming environment */
264     bn.getVarTable().setParent(nametable);
265     for(int i=0; i<bn.size(); i++) {
266       BlockStatementNode bsn=bn.get(i);
267       checkBlockStatementNode(md, bn.getVarTable(),bsn);
268     }
269   }
270
271   public void checkBlockStatementNode(Descriptor md, SymbolTable nametable, BlockStatementNode bsn) {
272     switch(bsn.kind()) {
273     case Kind.BlockExpressionNode:
274       checkBlockExpressionNode(md, nametable,(BlockExpressionNode)bsn);
275       return;
276
277     case Kind.DeclarationNode:
278       checkDeclarationNode(md, nametable, (DeclarationNode)bsn);
279       return;
280
281     case Kind.TagDeclarationNode:
282       checkTagDeclarationNode(md, nametable, (TagDeclarationNode)bsn);
283       return;
284
285     case Kind.IfStatementNode:
286       checkIfStatementNode(md, nametable, (IfStatementNode)bsn);
287       return;
288
289     case Kind.LoopNode:
290       checkLoopNode(md, nametable, (LoopNode)bsn);
291       return;
292
293     case Kind.ReturnNode:
294       checkReturnNode(md, nametable, (ReturnNode)bsn);
295       return;
296
297     case Kind.TaskExitNode:
298       checkTaskExitNode(md, nametable, (TaskExitNode)bsn);
299       return;
300
301     case Kind.SubBlockNode:
302       checkSubBlockNode(md, nametable, (SubBlockNode)bsn);
303       return;
304
305     case Kind.AtomicNode:
306       checkAtomicNode(md, nametable, (AtomicNode)bsn);
307       return;
308
309     case Kind.SynchronizedNode:
310       checkSynchronizedNode(md, nametable, (SynchronizedNode)bsn);
311       return;
312
313     case Kind.ContinueBreakNode:
314         checkContinueBreakNode(md, nametable, (ContinueBreakNode) bsn);
315         return;
316
317     case Kind.SESENode:
318     case Kind.GenReachNode:
319       // do nothing, no semantic check for SESEs
320       return;
321     }
322
323     throw new Error();
324   }
325
326   void checkBlockExpressionNode(Descriptor md, SymbolTable nametable, BlockExpressionNode ben) {
327     checkExpressionNode(md, nametable, ben.getExpression(), null);
328   }
329
330   void checkDeclarationNode(Descriptor md, SymbolTable nametable,  DeclarationNode dn) {
331     VarDescriptor vd=dn.getVarDescriptor();
332     checkTypeDescriptor(vd.getType());
333     Descriptor d=nametable.get(vd.getSymbol());
334     if ((d==null)||
335         (d instanceof FieldDescriptor)) {
336       nametable.add(vd);
337     } else
338       throw new Error(vd.getSymbol()+" in "+md+" defined a second time");
339     if (dn.getExpression()!=null)
340       checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
341   }
342
343   void checkTagDeclarationNode(Descriptor md, SymbolTable nametable,  TagDeclarationNode dn) {
344     TagVarDescriptor vd=dn.getTagVarDescriptor();
345     Descriptor d=nametable.get(vd.getSymbol());
346     if ((d==null)||
347         (d instanceof FieldDescriptor)) {
348       nametable.add(vd);
349     } else
350       throw new Error(vd.getSymbol()+" defined a second time");
351   }
352
353   void checkSubBlockNode(Descriptor md, SymbolTable nametable, SubBlockNode sbn) {
354     checkBlockNode(md, nametable, sbn.getBlockNode());
355   }
356
357   void checkAtomicNode(Descriptor md, SymbolTable nametable, AtomicNode sbn) {
358     checkBlockNode(md, nametable, sbn.getBlockNode());
359   }
360
361   void checkSynchronizedNode(Descriptor md, SymbolTable nametable, SynchronizedNode sbn) {
362     checkBlockNode(md, nametable, sbn.getBlockNode());
363     //todo this could be Object
364     checkExpressionNode(md, nametable, sbn.getExpr(), null);
365   }
366
367   void checkContinueBreakNode(Descriptor md, SymbolTable nametable, ContinueBreakNode cbn) {
368       if (loopstack.empty())
369           throw new Error("continue/break outside of loop");
370       LoopNode ln=(LoopNode)loopstack.peek();
371       cbn.setLoop(ln);
372   }
373
374   void checkReturnNode(Descriptor d, SymbolTable nametable, ReturnNode rn) {
375     if (d instanceof TaskDescriptor)
376       throw new Error("Illegal return appears in Task: "+d.getSymbol());
377     MethodDescriptor md=(MethodDescriptor)d;
378     if (rn.getReturnExpression()!=null)
379       if (md.getReturnType()==null)
380         throw new Error("Constructor can't return something.");
381       else if (md.getReturnType().isVoid())
382         throw new Error(md+" is void");
383       else
384         checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
385     else
386     if (md.getReturnType()!=null&&!md.getReturnType().isVoid())
387       throw new Error("Need to return something for "+md);
388   }
389
390   void checkTaskExitNode(Descriptor md, SymbolTable nametable, TaskExitNode ten) {
391     if (md instanceof MethodDescriptor)
392       throw new Error("Illegal taskexit appears in Method: "+md.getSymbol());
393     checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects(),nametable);
394     checkConstraintCheck((TaskDescriptor) md, nametable, ten.getChecks());
395   }
396
397   void checkIfStatementNode(Descriptor md, SymbolTable nametable, IfStatementNode isn) {
398     checkExpressionNode(md, nametable, isn.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
399     checkBlockNode(md, nametable, isn.getTrueBlock());
400     if (isn.getFalseBlock()!=null)
401       checkBlockNode(md, nametable, isn.getFalseBlock());
402   }
403
404   void checkExpressionNode(Descriptor md, SymbolTable nametable, ExpressionNode en, TypeDescriptor td) {
405     switch(en.kind()) {
406     case Kind.AssignmentNode:
407       checkAssignmentNode(md,nametable,(AssignmentNode)en,td);
408       return;
409
410     case Kind.CastNode:
411       checkCastNode(md,nametable,(CastNode)en,td);
412       return;
413
414     case Kind.CreateObjectNode:
415       checkCreateObjectNode(md,nametable,(CreateObjectNode)en,td);
416       return;
417
418     case Kind.FieldAccessNode:
419       checkFieldAccessNode(md,nametable,(FieldAccessNode)en,td);
420       return;
421
422     case Kind.ArrayAccessNode:
423       checkArrayAccessNode(md,nametable,(ArrayAccessNode)en,td);
424       return;
425
426     case Kind.LiteralNode:
427       checkLiteralNode(md,nametable,(LiteralNode)en,td);
428       return;
429
430     case Kind.MethodInvokeNode:
431       checkMethodInvokeNode(md,nametable,(MethodInvokeNode)en,td);
432       return;
433
434     case Kind.NameNode:
435       checkNameNode(md,nametable,(NameNode)en,td);
436       return;
437
438     case Kind.OpNode:
439       checkOpNode(md,nametable,(OpNode)en,td);
440       return;
441
442     case Kind.OffsetNode:
443       checkOffsetNode(md, nametable, (OffsetNode)en, td);
444       return;
445
446     case Kind.TertiaryNode:
447       checkTertiaryNode(md, nametable, (TertiaryNode)en, td);
448       return;
449       
450     case Kind.InstanceOfNode:
451       checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
452       return;
453
454     case Kind.ArrayInitializerNode:
455       checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en, td);
456       return;
457     }
458     throw new Error();
459   }
460
461   void checkCastNode(Descriptor md, SymbolTable nametable, CastNode cn, TypeDescriptor td) {
462     /* Get type descriptor */
463     if (cn.getType()==null) {
464       NameDescriptor typenamed=cn.getTypeName().getName();
465       String typename=typenamed.toString();
466       TypeDescriptor ntd=new TypeDescriptor(getClass(typename));
467       cn.setType(ntd);
468     }
469
470     /* Check the type descriptor */
471     TypeDescriptor cast_type=cn.getType();
472     checkTypeDescriptor(cast_type);
473
474     /* Type check */
475     if (td!=null) {
476       if (!typeutil.isSuperorType(td,cast_type))
477         throw new Error("Cast node returns "+cast_type+", but need "+td);
478     }
479
480     ExpressionNode en=cn.getExpression();
481     checkExpressionNode(md, nametable, en, null);
482     TypeDescriptor etd=en.getType();
483     if (typeutil.isSuperorType(cast_type,etd))     /* Cast trivially succeeds */
484       return;
485
486     if (typeutil.isSuperorType(etd,cast_type))     /* Cast may succeed */
487       return;
488     if (typeutil.isCastable(etd, cast_type))
489       return;
490
491     /* Different branches */
492     /* TODO: change if add interfaces */
493     throw new Error("Cast will always fail\n"+cn.printNode(0));
494   }
495
496   void checkFieldAccessNode(Descriptor md, SymbolTable nametable, FieldAccessNode fan, TypeDescriptor td) {
497     ExpressionNode left=fan.getExpression();
498     checkExpressionNode(md,nametable,left,null);
499     TypeDescriptor ltd=left.getType();
500     String fieldname=fan.getFieldName();
501
502     FieldDescriptor fd=null;
503     if (ltd.isArray()&&fieldname.equals("length"))
504       fd=FieldDescriptor.arrayLength;
505     else 
506       fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
507     if(state.MGC) {
508       // TODO add version for normal Java later
509     if(ltd.isStatic()) {
510       // check if this field is a static field
511       if(!fd.isStatic()) {
512         throw new Error("Dereference of the non-static field "+ fieldname + " in "+fan.printNode(0)+" in "+md);
513       }
514     } 
515     }
516     if (fd==null)
517       throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
518
519     if (fd.getType().iswrapper()) {
520       FieldAccessNode fan2=new FieldAccessNode(left, fieldname);
521       fan2.setField(fd);
522       fan.left=fan2;
523       fan.fieldname="value";
524
525       ExpressionNode leftwr=fan.getExpression();
526       TypeDescriptor ltdwr=leftwr.getType();
527       String fieldnamewr=fan.getFieldName();
528       FieldDescriptor fdwr=(FieldDescriptor) ltdwr.getClassDesc().getFieldTable().get(fieldnamewr);
529       fan.setField(fdwr);
530       if (fdwr==null)
531           throw new Error("Unknown field "+fieldnamewr + " in "+fan.printNode(0)+" in "+md);
532     } else {
533       fan.setField(fd);
534     }
535     if (td!=null) {
536       if (!typeutil.isSuperorType(td,fan.getType()))
537         throw new Error("Field node returns "+fan.getType()+", but need "+td);
538     }
539   }
540
541   void checkArrayAccessNode(Descriptor md, SymbolTable nametable, ArrayAccessNode aan, TypeDescriptor td) {
542     ExpressionNode left=aan.getExpression();
543     checkExpressionNode(md,nametable,left,null);
544
545     checkExpressionNode(md,nametable,aan.getIndex(),new TypeDescriptor(TypeDescriptor.INT));
546     TypeDescriptor ltd=left.getType();
547     if (ltd.dereference().iswrapper()) {
548       aan.wrappertype=((FieldDescriptor)ltd.dereference().getClassDesc().getFieldTable().get("value")).getType();
549     }
550
551     if (td!=null)
552       if (!typeutil.isSuperorType(td,aan.getType()))
553         throw new Error("Field node returns "+aan.getType()+", but need "+td);
554   }
555
556   void checkLiteralNode(Descriptor md, SymbolTable nametable, LiteralNode ln, TypeDescriptor td) {
557     /* Resolve the type */
558     Object o=ln.getValue();
559     if (ln.getTypeString().equals("null")) {
560       ln.setType(new TypeDescriptor(TypeDescriptor.NULL));
561     } else if (o instanceof Integer) {
562       ln.setType(new TypeDescriptor(TypeDescriptor.INT));
563     } else if (o instanceof Long) {
564       ln.setType(new TypeDescriptor(TypeDescriptor.LONG));
565     } else if (o instanceof Float) {
566       ln.setType(new TypeDescriptor(TypeDescriptor.FLOAT));
567     } else if (o instanceof Boolean) {
568       ln.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
569     } else if (o instanceof Double) {
570       ln.setType(new TypeDescriptor(TypeDescriptor.DOUBLE));
571     } else if (o instanceof Character) {
572       ln.setType(new TypeDescriptor(TypeDescriptor.CHAR));
573     } else if (o instanceof String) {
574       ln.setType(new TypeDescriptor(getClass(TypeUtil.StringClass)));
575     }
576
577     if (td!=null)
578       if (!typeutil.isSuperorType(td,ln.getType()))
579         throw new Error("Field node returns "+ln.getType()+", but need "+td+" in "+md);
580   }
581
582   void checkNameNode(Descriptor md, SymbolTable nametable, NameNode nn, TypeDescriptor td) {
583     NameDescriptor nd=nn.getName();
584     if (nd.getBase()!=null) {
585       /* Big hack */
586       /* Rewrite NameNode */
587       ExpressionNode en=translateNameDescriptorintoExpression(nd);
588       nn.setExpression(en);
589       checkExpressionNode(md,nametable,en,td);
590     } else {
591       String varname=nd.toString();
592       Descriptor d=(Descriptor)nametable.get(varname);
593       if (d==null) {
594         if(state.MGC) {
595           // TODO add version for normal Java later
596         ClassDescriptor cd = null;
597         if(((MethodDescriptor)md).isStaticBlock()) {
598           // this is a static block, all the accessed fields should be static field
599           cd = ((MethodDescriptor)md).getClassDesc();
600           SymbolTable fieldtbl = cd.getFieldTable();
601           FieldDescriptor fd=(FieldDescriptor)fieldtbl.get(varname);
602           if((fd == null) || (!fd.isStatic())){
603             // no such field in the class or it is not a static field
604             throw new Error("Name "+varname+" should not be used in static block: "+md);
605           } else {
606             // this is a static field
607             nn.setField(fd);
608             nn.setClassDesc(cd);
609             return;
610           }
611         } else {
612           cd=getClass(varname);
613           if(cd != null) {
614             // this is a class name
615             nn.setClassDesc(cd);
616             return;
617           } else {
618             throw new Error("Name "+varname+" undefined in: "+md);
619           }
620         }
621         } else {
622           throw new Error("Name "+varname+" undefined in: "+md);
623         }
624       }
625       if (d instanceof VarDescriptor) {
626         nn.setVar(d);
627       } else if (d instanceof FieldDescriptor) {
628         FieldDescriptor fd=(FieldDescriptor)d;
629         if (fd.getType().iswrapper()) {
630           String id=nd.getIdentifier();
631           NameDescriptor base=nd.getBase();
632           NameNode n=new NameNode(nn.getName());
633           n.setField(fd);
634           n.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
635           FieldAccessNode fan=new FieldAccessNode(n,"value");
636           FieldDescriptor fdval=(FieldDescriptor) fd.getType().getClassDesc().getFieldTable().get("value");
637           fan.setField(fdval);
638           nn.setExpression(fan);
639         } else {
640           nn.setField(fd);
641           nn.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
642         }
643       } else if (d instanceof TagVarDescriptor) {
644         nn.setVar(d);
645       } else throw new Error("Wrong type of descriptor");
646       if (td!=null)
647         if (!typeutil.isSuperorType(td,nn.getType()))
648           throw new Error("Field node returns "+nn.getType()+", but need "+td);
649     }
650   }
651
652   void checkOffsetNode(Descriptor md, SymbolTable nameTable, OffsetNode ofn, TypeDescriptor td) {
653     TypeDescriptor ltd=ofn.td;
654     checkTypeDescriptor(ltd);
655     
656     String fieldname = ofn.fieldname;
657     FieldDescriptor fd=null;
658     if (ltd.isArray()&&fieldname.equals("length")) {
659       fd=FieldDescriptor.arrayLength;
660     } else {
661       fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
662     }
663
664     ofn.setField(fd);
665     checkField(ltd.getClassDesc(), fd);
666
667     if (fd==null)
668       throw new Error("Unknown field "+fieldname + " in "+ofn.printNode(1)+" in "+md);
669
670     if (td!=null) {
671       if (!typeutil.isSuperorType(td, ofn.getType())) {
672         System.out.println(td);
673         System.out.println(ofn.getType());
674         throw new Error("Type of rside not compatible with type of lside"+ofn.printNode(0));
675       }
676     }
677   }
678
679
680   void checkTertiaryNode(Descriptor md, SymbolTable nametable, TertiaryNode tn, TypeDescriptor td) {
681     checkExpressionNode(md, nametable, tn.getCond(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
682     checkExpressionNode(md, nametable, tn.getTrueExpr(), td );
683     checkExpressionNode(md, nametable, tn.getFalseExpr(), td );
684   }
685
686   void checkInstanceOfNode(Descriptor md, SymbolTable nametable, InstanceOfNode tn, TypeDescriptor td) {
687     if (td!=null&&!td.isBoolean())
688       throw new Error("Expecting type "+td+"for instanceof expression");
689     
690     checkTypeDescriptor(tn.getExprType());
691     checkExpressionNode(md, nametable, tn.getExpr(), null);
692   }
693
694   void checkArrayInitializerNode(Descriptor md, SymbolTable nametable, ArrayInitializerNode ain, TypeDescriptor td) {
695     for( int i = 0; i < ain.numVarInitializers(); ++i ) {
696       checkExpressionNode(md, nametable, ain.getVarInitializer(i), td); 
697     }
698   }
699
700   void checkAssignmentNode(Descriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
701     boolean postinc=true;
702     if (an.getOperation().getBaseOp()==null||
703         (an.getOperation().getBaseOp().getOp()!=Operation.POSTINC&&
704          an.getOperation().getBaseOp().getOp()!=Operation.POSTDEC))
705       postinc=false;
706     if (!postinc)      
707       checkExpressionNode(md, nametable, an.getSrc(),td);
708     //TODO: Need check on validity of operation here
709     if (!((an.getDest() instanceof FieldAccessNode)||
710           (an.getDest() instanceof ArrayAccessNode)||
711           (an.getDest() instanceof NameNode)))
712       throw new Error("Bad lside in "+an.printNode(0));
713     checkExpressionNode(md, nametable, an.getDest(), null);
714
715     /* We want parameter variables to tasks to be immutable */
716     if (md instanceof TaskDescriptor) {
717       if (an.getDest() instanceof NameNode) {
718         NameNode nn=(NameNode)an.getDest();
719         if (nn.getVar()!=null) {
720           if (((TaskDescriptor)md).getParameterTable().contains(nn.getVar().getSymbol()))
721             throw new Error("Can't modify parameter "+nn.getVar()+ " to task "+td.getSymbol());
722         }
723       }
724     }
725
726     if (an.getDest().getType().isString()&&an.getOperation().getOp()==AssignOperation.PLUSEQ) {
727       //String add
728       ClassDescriptor stringcl=getClass(TypeUtil.StringClass);
729       TypeDescriptor stringtd=new TypeDescriptor(stringcl);
730       NameDescriptor nd=new NameDescriptor("String");
731       NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
732
733       if (!(an.getSrc().getType().isString()&&(an.getSrc() instanceof OpNode))) {
734         MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
735         rightmin.addArgument(an.getSrc());
736         an.right=rightmin;
737         checkExpressionNode(md, nametable, an.getSrc(), null);
738       }
739     }
740
741     if (!postinc&&!typeutil.isSuperorType(an.getDest().getType(),an.getSrc().getType())) {
742       throw new Error("Type of rside ("+an.getSrc().getType().toPrettyString()+") not compatible with type of lside ("+an.getDest().getType().toPrettyString()+")"+an.printNode(0));
743     }
744   }
745
746   void checkLoopNode(Descriptor md, SymbolTable nametable, LoopNode ln) {
747       loopstack.push(ln);
748     if (ln.getType()==LoopNode.WHILELOOP||ln.getType()==LoopNode.DOWHILELOOP) {
749       checkExpressionNode(md, nametable, ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
750       checkBlockNode(md, nametable, ln.getBody());
751     } else {
752       //For loop case
753       /* Link in the initializer naming environment */
754       BlockNode bn=ln.getInitializer();
755       bn.getVarTable().setParent(nametable);
756       for(int i=0; i<bn.size(); i++) {
757         BlockStatementNode bsn=bn.get(i);
758         checkBlockStatementNode(md, bn.getVarTable(),bsn);
759       }
760       //check the condition
761       checkExpressionNode(md, bn.getVarTable(), ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
762       checkBlockNode(md, bn.getVarTable(), ln.getBody());
763       checkBlockNode(md, bn.getVarTable(), ln.getUpdate());
764     }
765     loopstack.pop();
766   }
767
768
769   void checkCreateObjectNode(Descriptor md, SymbolTable nametable, CreateObjectNode con, TypeDescriptor td) {
770     TypeDescriptor[] tdarray=new TypeDescriptor[con.numArgs()];
771     for(int i=0; i<con.numArgs(); i++) {
772       ExpressionNode en=con.getArg(i);
773       checkExpressionNode(md,nametable,en,null);
774       tdarray[i]=en.getType();
775     }
776
777     TypeDescriptor typetolookin=con.getType();
778     checkTypeDescriptor(typetolookin);
779
780     if (td!=null&&!typeutil.isSuperorType(td, typetolookin))
781       throw new Error(typetolookin + " isn't a "+td);
782
783     /* Check flag effects */
784     if (con.getFlagEffects()!=null) {
785       FlagEffects fe=con.getFlagEffects();
786       ClassDescriptor cd=typetolookin.getClassDesc();
787
788       for(int j=0; j<fe.numEffects(); j++) {
789         FlagEffect flag=fe.getEffect(j);
790         String name=flag.getName();
791         FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
792         //Make sure the flag is declared
793         if (flag_d==null)
794           throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
795         if (flag_d.getExternal())
796           throw new Error("Attempting to modify external flag: "+name);
797         flag.setFlag(flag_d);
798       }
799       for(int j=0; j<fe.numTagEffects(); j++) {
800         TagEffect tag=fe.getTagEffect(j);
801         String name=tag.getName();
802
803         Descriptor d=(Descriptor)nametable.get(name);
804         if (d==null)
805           throw new Error("Tag descriptor "+name+" undeclared");
806         else if (!(d instanceof TagVarDescriptor))
807           throw new Error(name+" is not a tag descriptor");
808         tag.setTag((TagVarDescriptor)d);
809       }
810     }
811
812     if ((!typetolookin.isClass())&&(!typetolookin.isArray()))
813       throw new Error("Can't allocate primitive type:"+con.printNode(0));
814
815     if (!typetolookin.isArray()) {
816       //Array's don't need constructor calls
817       ClassDescriptor classtolookin=typetolookin.getClassDesc();
818
819       Set methoddescriptorset=classtolookin.getMethodTable().getSet(typetolookin.getSymbol());
820       MethodDescriptor bestmd=null;
821 NextMethod:
822       for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext();) {
823         MethodDescriptor currmd=(MethodDescriptor)methodit.next();
824         /* Need correct number of parameters */
825         if (con.numArgs()!=currmd.numParameters())
826           continue;
827         for(int i=0; i<con.numArgs(); i++) {
828           if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
829             continue NextMethod;
830         }
831         /* Local allocations can't call global allocator */
832         if (!con.isGlobal()&&currmd.isGlobal())
833           continue;
834
835         /* Method okay so far */
836         if (bestmd==null)
837           bestmd=currmd;
838         else {
839           if (typeutil.isMoreSpecific(currmd,bestmd)) {
840             bestmd=currmd;
841           } else if (con.isGlobal()&&match(currmd, bestmd)) {
842             if (currmd.isGlobal()&&!bestmd.isGlobal())
843               bestmd=currmd;
844             else if (currmd.isGlobal()&&bestmd.isGlobal())
845               throw new Error();
846           } else if (!typeutil.isMoreSpecific(bestmd, currmd)) {
847             throw new Error("No method is most specific");
848           }
849
850           /* Is this more specific than bestmd */
851         }
852       }
853       if (bestmd==null)
854         throw new Error("No method found for "+con.printNode(0)+" in "+md);
855       con.setConstructor(bestmd);
856     }
857   }
858
859
860   /** Check to see if md1 is the same specificity as md2.*/
861
862   boolean match(MethodDescriptor md1, MethodDescriptor md2) {
863     /* Checks if md1 is more specific than md2 */
864     if (md1.numParameters()!=md2.numParameters())
865       throw new Error();
866     for(int i=0; i<md1.numParameters(); i++) {
867       if (!md2.getParamType(i).equals(md1.getParamType(i)))
868         return false;
869     }
870     if (!md2.getReturnType().equals(md1.getReturnType()))
871       return false;
872
873     if (!md2.getClassDesc().equals(md1.getClassDesc()))
874       return false;
875
876     return true;
877   }
878
879
880
881   ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd) {
882     String id=nd.getIdentifier();
883     NameDescriptor base=nd.getBase();
884     if (base==null)
885       return new NameNode(nd);
886     else
887       return new FieldAccessNode(translateNameDescriptorintoExpression(base),id);
888   }
889
890
891   void checkMethodInvokeNode(Descriptor md, SymbolTable nametable, MethodInvokeNode min, TypeDescriptor td) {
892     /*Typecheck subexpressions
893        and get types for expressions*/
894
895     TypeDescriptor[] tdarray=new TypeDescriptor[min.numArgs()];
896     for(int i=0; i<min.numArgs(); i++) {
897       ExpressionNode en=min.getArg(i);
898       checkExpressionNode(md,nametable,en,null);
899       tdarray[i]=en.getType();
900     }
901     TypeDescriptor typetolookin=null;
902     if (min.getExpression()!=null) {
903       checkExpressionNode(md,nametable,min.getExpression(),null);
904       typetolookin=min.getExpression().getType();
905       //if (typetolookin==null)
906       //throw new Error(md+" has null return type");
907
908     } else if (min.getBaseName()!=null) {
909       String rootname=min.getBaseName().getRoot();
910       if (rootname.equals("super")) {
911         ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
912         typetolookin=new TypeDescriptor(supercd);
913       } else if (nametable.get(rootname)!=null) {
914         //we have an expression
915         min.setExpression(translateNameDescriptorintoExpression(min.getBaseName()));
916         checkExpressionNode(md, nametable, min.getExpression(), null);
917         typetolookin=min.getExpression().getType();
918       } else {
919         //we have a type
920         ClassDescriptor cd;
921         if (min.getBaseName().getSymbol().equals("System.out"))
922           cd=getClass("System");
923         else
924           cd=getClass(min.getBaseName().getSymbol());
925         if (cd==null)
926           throw new Error("md = "+ md.toString()+ "  "+min.getBaseName()+" undefined");
927         typetolookin=new TypeDescriptor(cd);
928       }
929     } else if ((md instanceof MethodDescriptor)&&min.getMethodName().equals("super")) {
930       ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
931       min.methodid=supercd.getSymbol();
932       typetolookin=new TypeDescriptor(supercd);
933     } else if (md instanceof MethodDescriptor) {
934       typetolookin=new TypeDescriptor(((MethodDescriptor)md).getClassDesc());
935     } else {
936       /* If this a task descriptor we throw an error at this point */
937       throw new Error("Unknown method call to "+min.getMethodName()+"in task"+md.getSymbol());
938     }
939     if (!typetolookin.isClass())
940       throw new Error("Error with method call to "+min.getMethodName());
941     ClassDescriptor classtolookin=typetolookin.getClassDesc();
942     //System.out.println("Method name="+min.getMethodName());
943
944     Set methoddescriptorset=classtolookin.getMethodTable().getSet(min.getMethodName());
945     MethodDescriptor bestmd=null;
946 NextMethod:
947     for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext();) {
948       MethodDescriptor currmd=(MethodDescriptor)methodit.next();
949       /* Need correct number of parameters */
950       if (min.numArgs()!=currmd.numParameters())
951         continue;
952       for(int i=0; i<min.numArgs(); i++) {
953         if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
954           continue NextMethod;
955       }
956       /* Method okay so far */
957       if (bestmd==null)
958         bestmd=currmd;
959       else {
960         if (typeutil.isMoreSpecific(currmd,bestmd)) {
961           bestmd=currmd;
962         } else if (!typeutil.isMoreSpecific(bestmd, currmd))
963           throw new Error("No method is most specific");
964
965         /* Is this more specific than bestmd */
966       }
967     }
968     if (bestmd==null)
969       throw new Error("No method found for :"+min.printNode(0)+" in class: " + classtolookin+" in "+md);
970     min.setMethod(bestmd);
971
972     if ((td!=null)&&(min.getType()!=null)&&!typeutil.isSuperorType(td,  min.getType()))
973       throw new Error(min.getType()+ " is not equal to or a subclass of "+td);
974     /* Check whether we need to set this parameter to implied this */
975     if (!bestmd.isStatic()) {
976       if (min.getExpression()==null) {
977         ExpressionNode en=new NameNode(new NameDescriptor("this"));
978         min.setExpression(en);
979         checkExpressionNode(md, nametable, min.getExpression(), null);
980       }
981     }
982   }
983
984
985   void checkOpNode(Descriptor md, SymbolTable nametable, OpNode on, TypeDescriptor td) {
986     checkExpressionNode(md, nametable, on.getLeft(), null);
987     if (on.getRight()!=null)
988       checkExpressionNode(md, nametable, on.getRight(), null);
989     TypeDescriptor ltd=on.getLeft().getType();
990     TypeDescriptor rtd=on.getRight()!=null ? on.getRight().getType() : null;
991     TypeDescriptor lefttype=null;
992     TypeDescriptor righttype=null;
993     Operation op=on.getOp();
994
995     switch(op.getOp()) {
996     case Operation.LOGIC_OR:
997     case Operation.LOGIC_AND:
998       if (!(rtd.isBoolean()))
999         throw new Error();
1000       on.setRightType(rtd);
1001
1002     case Operation.LOGIC_NOT:
1003       if (!(ltd.isBoolean()))
1004         throw new Error();
1005       //no promotion
1006       on.setLeftType(ltd);
1007
1008       on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1009       break;
1010
1011     case Operation.COMP:
1012       // 5.6.2 Binary Numeric Promotion
1013       //TODO unboxing of reference objects
1014       if (ltd.isDouble())
1015         throw new Error();
1016       else if (ltd.isFloat())
1017         throw new Error();
1018       else if (ltd.isLong())
1019         lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1020       else
1021         lefttype=new TypeDescriptor(TypeDescriptor.INT);
1022       on.setLeftType(lefttype);
1023       on.setType(lefttype);
1024       break;
1025
1026     case Operation.BIT_OR:
1027     case Operation.BIT_XOR:
1028     case Operation.BIT_AND:
1029       // 5.6.2 Binary Numeric Promotion
1030       //TODO unboxing of reference objects
1031       if (ltd.isDouble()||rtd.isDouble())
1032         throw new Error();
1033       else if (ltd.isFloat()||rtd.isFloat())
1034         throw new Error();
1035       else if (ltd.isLong()||rtd.isLong())
1036         lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1037       // 090205 hack for boolean
1038       else if (ltd.isBoolean()||rtd.isBoolean())
1039         lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
1040       else
1041         lefttype=new TypeDescriptor(TypeDescriptor.INT);
1042       righttype=lefttype;
1043
1044       on.setLeftType(lefttype);
1045       on.setRightType(righttype);
1046       on.setType(lefttype);
1047       break;
1048
1049     case Operation.ISAVAILABLE:
1050       if (!(ltd.isPtr())) {
1051         throw new Error("Can't use isavailable on non-pointers/non-parameters.");
1052       }
1053       lefttype=ltd;
1054       on.setLeftType(lefttype);
1055       on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1056       break;
1057
1058     case Operation.EQUAL:
1059     case Operation.NOTEQUAL:
1060       // 5.6.2 Binary Numeric Promotion
1061       //TODO unboxing of reference objects
1062       if (ltd.isBoolean()||rtd.isBoolean()) {
1063         if (!(ltd.isBoolean()&&rtd.isBoolean()))
1064           throw new Error();
1065         righttype=lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
1066       } else if (ltd.isPtr()||rtd.isPtr()) {
1067         if (!(ltd.isPtr()&&rtd.isPtr()))
1068           throw new Error();
1069         righttype=rtd;
1070         lefttype=ltd;
1071       } else if (ltd.isDouble()||rtd.isDouble())
1072         righttype=lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
1073       else if (ltd.isFloat()||rtd.isFloat())
1074         righttype=lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
1075       else if (ltd.isLong()||rtd.isLong())
1076         righttype=lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1077       else
1078         righttype=lefttype=new TypeDescriptor(TypeDescriptor.INT);
1079
1080       on.setLeftType(lefttype);
1081       on.setRightType(righttype);
1082       on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1083       break;
1084
1085
1086
1087     case Operation.LT:
1088     case Operation.GT:
1089     case Operation.LTE:
1090     case Operation.GTE:
1091       // 5.6.2 Binary Numeric Promotion
1092       //TODO unboxing of reference objects
1093       if (!ltd.isNumber()||!rtd.isNumber()) {
1094         if (!ltd.isNumber())
1095           throw new Error("Leftside is not number"+on.printNode(0)+"type="+ltd.toPrettyString());
1096         if (!rtd.isNumber())
1097           throw new Error("Rightside is not number"+on.printNode(0));
1098       }
1099
1100       if (ltd.isDouble()||rtd.isDouble())
1101         lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
1102       else if (ltd.isFloat()||rtd.isFloat())
1103         lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
1104       else if (ltd.isLong()||rtd.isLong())
1105         lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1106       else
1107         lefttype=new TypeDescriptor(TypeDescriptor.INT);
1108       righttype=lefttype;
1109       on.setLeftType(lefttype);
1110       on.setRightType(righttype);
1111       on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1112       break;
1113
1114     case Operation.ADD:
1115       if (ltd.isString()||rtd.isString()) {
1116         ClassDescriptor stringcl=getClass(TypeUtil.StringClass);
1117         TypeDescriptor stringtd=new TypeDescriptor(stringcl);
1118         NameDescriptor nd=new NameDescriptor("String");
1119         NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
1120         if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
1121           MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
1122           leftmin.addArgument(on.getLeft());
1123           on.left=leftmin;
1124           checkExpressionNode(md, nametable, on.getLeft(), null);
1125         }
1126
1127         if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
1128           MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
1129           rightmin.addArgument(on.getRight());
1130           on.right=rightmin;
1131           checkExpressionNode(md, nametable, on.getRight(), null);
1132         }
1133
1134         on.setLeftType(stringtd);
1135         on.setRightType(stringtd);
1136         on.setType(stringtd);
1137         break;
1138       }
1139
1140     case Operation.SUB:
1141     case Operation.MULT:
1142     case Operation.DIV:
1143     case Operation.MOD:
1144       // 5.6.2 Binary Numeric Promotion
1145       //TODO unboxing of reference objects
1146       if (ltd.isArray()||rtd.isArray()||!ltd.isNumber()||!rtd.isNumber())
1147         throw new Error("Error in "+on.printNode(0));
1148
1149       if (ltd.isDouble()||rtd.isDouble())
1150         lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
1151       else if (ltd.isFloat()||rtd.isFloat())
1152         lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
1153       else if (ltd.isLong()||rtd.isLong())
1154         lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1155       else
1156         lefttype=new TypeDescriptor(TypeDescriptor.INT);
1157       righttype=lefttype;
1158       on.setLeftType(lefttype);
1159       on.setRightType(righttype);
1160       on.setType(lefttype);
1161       break;
1162
1163     case Operation.LEFTSHIFT:
1164     case Operation.RIGHTSHIFT:
1165     case Operation.URIGHTSHIFT:
1166       if (!rtd.isIntegerType())
1167         throw new Error();
1168       //5.6.1 Unary Numeric Promotion
1169       if (rtd.isByte()||rtd.isShort()||rtd.isInt())
1170         righttype=new TypeDescriptor(TypeDescriptor.INT);
1171       else
1172         righttype=rtd;
1173
1174       on.setRightType(righttype);
1175       if (!ltd.isIntegerType())
1176         throw new Error();
1177
1178     case Operation.UNARYPLUS:
1179     case Operation.UNARYMINUS:
1180       /*        case Operation.POSTINC:
1181           case Operation.POSTDEC:
1182           case Operation.PREINC:
1183           case Operation.PREDEC:*/
1184       if (!ltd.isNumber())
1185         throw new Error();
1186       //5.6.1 Unary Numeric Promotion
1187       if (ltd.isByte()||ltd.isShort()||ltd.isInt())
1188         lefttype=new TypeDescriptor(TypeDescriptor.INT);
1189       else
1190         lefttype=ltd;
1191       on.setLeftType(lefttype);
1192       on.setType(lefttype);
1193       break;
1194
1195     default:
1196       throw new Error(op.toString());
1197     }
1198
1199     if (td!=null)
1200       if (!typeutil.isSuperorType(td, on.getType())) {
1201         System.out.println(td);
1202         System.out.println(on.getType());
1203         throw new Error("Type of rside not compatible with type of lside"+on.printNode(0));
1204       }
1205   }
1206 }