7 public class SemanticCheck {
15 public SemanticCheck(State state, TypeUtil tu) {
18 this.loopstack=new Stack();
19 this.toanalyze=new HashSet();
20 this.completed=new HashSet();
23 public ClassDescriptor getClass(String classname) {
24 ClassDescriptor cd=typeutil.getClass(classname, toanalyze);
29 private void checkClass(ClassDescriptor cd) {
30 if (!completed.contains(cd)) {
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());
42 // TODO add version for normal Java later
43 // Link together Field, Method tables do classes inherit these from
44 // their ancestor interfaces
45 Vector<String> sifv = cd.getSuperInterface();
46 for(int i = 0; i < sifv.size(); i++) {
47 ClassDescriptor superif = getClass(sifv.elementAt(i));
48 cd.addSuperInterfaces(superif);
49 cd.getFieldTable().addParentIF(superif.getFieldTable());
50 cd.getMethodTable().addParentIF(superif.getMethodTable());
55 /* Check to see that fields are well typed */
56 for(Iterator field_it=cd.getFields(); field_it.hasNext();) {
57 FieldDescriptor fd=(FieldDescriptor)field_it.next();
61 boolean hasConstructor = false;
62 for(Iterator method_it=cd.getMethods(); method_it.hasNext();) {
63 MethodDescriptor md=(MethodDescriptor)method_it.next();
65 hasConstructor |= md.isConstructor();
68 // add a default constructor for this class
69 MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
70 cd.getSymbol(), false);
71 BlockNode bn=new BlockNode();
72 state.addTreeCode(md,bn);
79 public void semanticCheck() {
80 SymbolTable classtable=state.getClassSymbolTable();
81 toanalyze.addAll(classtable.getValueSet());
82 toanalyze.addAll(state.getTaskSymbolTable().getValueSet());
85 while(!toanalyze.isEmpty()) {
86 Object obj=toanalyze.iterator().next();
87 if (obj instanceof TaskDescriptor) {
88 toanalyze.remove(obj);
89 TaskDescriptor td=(TaskDescriptor)obj;
93 System.out.println( "Error in "+td );
97 ClassDescriptor cd=(ClassDescriptor)obj;
99 //need to initialize typeutil object here...only place we can
100 //get class descriptors without first calling getclass
101 getClass(cd.getSymbol());
102 for(Iterator method_it=cd.getMethods(); method_it.hasNext();) {
103 MethodDescriptor md=(MethodDescriptor)method_it.next();
105 checkMethodBody(cd,md);
107 System.out.println( "Error in "+md );
115 public void checkTypeDescriptor(TypeDescriptor td) {
116 if (td.isPrimitive())
118 else if (td.isClass()) {
119 String name=td.toString();
120 ClassDescriptor field_cd=getClass(name);
122 throw new Error("Undefined class "+name);
123 td.setClassDescriptor(field_cd);
125 } else if (td.isTag())
131 public void checkField(ClassDescriptor cd, FieldDescriptor fd) {
132 checkTypeDescriptor(fd.getType());
135 public void checkConstraintCheck(TaskDescriptor td, SymbolTable nametable, Vector ccs) {
137 return; /* No constraint checks to check */
138 for(int i=0; i<ccs.size(); i++) {
139 ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
141 for(int j=0; j<cc.numArgs(); j++) {
142 ExpressionNode en=cc.getArg(j);
143 checkExpressionNode(td,nametable,en,null);
148 public void checkFlagEffects(TaskDescriptor td, Vector vfe, SymbolTable nametable) {
150 return; /* No flag effects to check */
151 for(int i=0; i<vfe.size(); i++) {
152 FlagEffects fe=(FlagEffects) vfe.get(i);
153 String varname=fe.getName();
154 //Make sure the variable is declared as a parameter to the task
155 VarDescriptor vd=(VarDescriptor)td.getParameterTable().get(varname);
157 throw new Error("Parameter "+varname+" in Flag Effects not declared in "+td);
160 //Make sure it correspods to a class
161 TypeDescriptor type_d=vd.getType();
162 if (!type_d.isClass())
163 throw new Error("Cannot have non-object argument for flag_effect");
165 ClassDescriptor cd=type_d.getClassDesc();
166 for(int j=0; j<fe.numEffects(); j++) {
167 FlagEffect flag=fe.getEffect(j);
168 String name=flag.getName();
169 FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
170 //Make sure the flag is declared
172 throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
173 if (flag_d.getExternal())
174 throw new Error("Attempting to modify external flag: "+name);
175 flag.setFlag(flag_d);
177 for(int j=0; j<fe.numTagEffects(); j++) {
178 TagEffect tag=fe.getTagEffect(j);
179 String name=tag.getName();
181 Descriptor d=(Descriptor)nametable.get(name);
183 throw new Error("Tag descriptor "+name+" undeclared");
184 else if (!(d instanceof TagVarDescriptor))
185 throw new Error(name+" is not a tag descriptor");
186 tag.setTag((TagVarDescriptor)d);
191 public void checkTask(TaskDescriptor td) {
192 for(int i=0; i<td.numParameters(); i++) {
193 /* Check that parameter is well typed */
194 TypeDescriptor param_type=td.getParamType(i);
195 checkTypeDescriptor(param_type);
197 /* Check the parameter's flag expression is well formed */
198 FlagExpressionNode fen=td.getFlag(td.getParameter(i));
199 if (!param_type.isClass())
200 throw new Error("Cannot have non-object argument to a task");
201 ClassDescriptor cd=param_type.getClassDesc();
203 checkFlagExpressionNode(cd, fen);
206 checkFlagEffects(td, td.getFlagEffects(),td.getParameterTable());
207 /* Check that the task code is valid */
208 BlockNode bn=state.getMethodBody(td);
209 checkBlockNode(td, td.getParameterTable(),bn);
212 public void checkFlagExpressionNode(ClassDescriptor cd, FlagExpressionNode fen) {
214 case Kind.FlagOpNode:
216 FlagOpNode fon=(FlagOpNode)fen;
217 checkFlagExpressionNode(cd, fon.getLeft());
218 if (fon.getRight()!=null)
219 checkFlagExpressionNode(cd, fon.getRight());
225 FlagNode fn=(FlagNode)fen;
226 String name=fn.getFlagName();
227 FlagDescriptor fd=(FlagDescriptor)cd.getFlagTable().get(name);
229 throw new Error("Undeclared flag: "+name);
235 throw new Error("Unrecognized FlagExpressionNode");
239 public void checkMethod(ClassDescriptor cd, MethodDescriptor md) {
241 // TODO add version for normal Java later
242 /* Check for abstract methods */
243 if(md.isAbstract()) {
244 if(!cd.isAbstract() && !cd.isInterface()) {
245 throw new Error("Error! The non-abstract Class " + cd.getSymbol() + " contains an abstract method " + md.getSymbol());
249 /* Check return type */
250 if (!md.isConstructor())
251 if (!md.getReturnType().isVoid())
252 checkTypeDescriptor(md.getReturnType());
254 for(int i=0; i<md.numParameters(); i++) {
255 TypeDescriptor param_type=md.getParamType(i);
256 checkTypeDescriptor(param_type);
258 /* Link the naming environments */
259 if (!md.isStatic()) /* Fields aren't accessible directly in a static method, so don't link in this table */
260 md.getParameterTable().setParent(cd.getFieldTable());
262 if (!md.isStatic()) {
263 VarDescriptor thisvd=new VarDescriptor(new TypeDescriptor(cd),"this");
268 public void checkMethodBody(ClassDescriptor cd, MethodDescriptor md) {
269 ClassDescriptor superdesc=cd.getSuperDesc();
270 if (superdesc!=null) {
271 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
272 for(Iterator methodit=possiblematches.iterator(); methodit.hasNext();) {
273 MethodDescriptor matchmd=(MethodDescriptor)methodit.next();
274 if (md.matches(matchmd)) {
275 if (matchmd.getModifiers().isFinal()) {
276 throw new Error("Try to override final method in method:"+md+" declared in "+cd);
281 BlockNode bn=state.getMethodBody(md);
282 checkBlockNode(md, md.getParameterTable(),bn);
285 public void checkBlockNode(Descriptor md, SymbolTable nametable, BlockNode bn) {
286 /* Link in the naming environment */
287 bn.getVarTable().setParent(nametable);
288 for(int i=0; i<bn.size(); i++) {
289 BlockStatementNode bsn=bn.get(i);
290 checkBlockStatementNode(md, bn.getVarTable(),bsn);
294 public void checkBlockStatementNode(Descriptor md, SymbolTable nametable, BlockStatementNode bsn) {
296 case Kind.BlockExpressionNode:
297 checkBlockExpressionNode(md, nametable,(BlockExpressionNode)bsn);
300 case Kind.DeclarationNode:
301 checkDeclarationNode(md, nametable, (DeclarationNode)bsn);
304 case Kind.TagDeclarationNode:
305 checkTagDeclarationNode(md, nametable, (TagDeclarationNode)bsn);
308 case Kind.IfStatementNode:
309 checkIfStatementNode(md, nametable, (IfStatementNode)bsn);
312 case Kind.SwitchStatementNode:
313 checkSwitchStatementNode(md, nametable, (SwitchStatementNode)bsn);
317 checkLoopNode(md, nametable, (LoopNode)bsn);
320 case Kind.ReturnNode:
321 checkReturnNode(md, nametable, (ReturnNode)bsn);
324 case Kind.TaskExitNode:
325 checkTaskExitNode(md, nametable, (TaskExitNode)bsn);
328 case Kind.SubBlockNode:
329 checkSubBlockNode(md, nametable, (SubBlockNode)bsn);
332 case Kind.AtomicNode:
333 checkAtomicNode(md, nametable, (AtomicNode)bsn);
336 case Kind.SynchronizedNode:
337 checkSynchronizedNode(md, nametable, (SynchronizedNode)bsn);
340 case Kind.ContinueBreakNode:
341 checkContinueBreakNode(md, nametable, (ContinueBreakNode) bsn);
345 case Kind.GenReachNode:
346 // do nothing, no semantic check for SESEs
353 void checkBlockExpressionNode(Descriptor md, SymbolTable nametable, BlockExpressionNode ben) {
354 checkExpressionNode(md, nametable, ben.getExpression(), null);
357 void checkDeclarationNode(Descriptor md, SymbolTable nametable, DeclarationNode dn) {
358 VarDescriptor vd=dn.getVarDescriptor();
359 checkTypeDescriptor(vd.getType());
360 Descriptor d=nametable.get(vd.getSymbol());
362 (d instanceof FieldDescriptor)) {
365 throw new Error(vd.getSymbol()+" in "+md+" defined a second time");
366 if (dn.getExpression()!=null)
367 checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
370 void checkTagDeclarationNode(Descriptor md, SymbolTable nametable, TagDeclarationNode dn) {
371 TagVarDescriptor vd=dn.getTagVarDescriptor();
372 Descriptor d=nametable.get(vd.getSymbol());
374 (d instanceof FieldDescriptor)) {
377 throw new Error(vd.getSymbol()+" defined a second time");
380 void checkSubBlockNode(Descriptor md, SymbolTable nametable, SubBlockNode sbn) {
381 checkBlockNode(md, nametable, sbn.getBlockNode());
384 void checkAtomicNode(Descriptor md, SymbolTable nametable, AtomicNode sbn) {
385 checkBlockNode(md, nametable, sbn.getBlockNode());
388 void checkSynchronizedNode(Descriptor md, SymbolTable nametable, SynchronizedNode sbn) {
389 checkBlockNode(md, nametable, sbn.getBlockNode());
390 //todo this could be Object
391 checkExpressionNode(md, nametable, sbn.getExpr(), null);
394 void checkContinueBreakNode(Descriptor md, SymbolTable nametable, ContinueBreakNode cbn) {
395 if (loopstack.empty())
396 throw new Error("continue/break outside of loop");
397 LoopNode ln=(LoopNode)loopstack.peek();
401 void checkReturnNode(Descriptor d, SymbolTable nametable, ReturnNode rn) {
402 if (d instanceof TaskDescriptor)
403 throw new Error("Illegal return appears in Task: "+d.getSymbol());
404 MethodDescriptor md=(MethodDescriptor)d;
405 if (rn.getReturnExpression()!=null)
406 if (md.getReturnType()==null)
407 throw new Error("Constructor can't return something.");
408 else if (md.getReturnType().isVoid())
409 throw new Error(md+" is void");
411 checkExpressionNode(md, nametable, rn.getReturnExpression(), md.getReturnType());
413 if (md.getReturnType()!=null&&!md.getReturnType().isVoid())
414 throw new Error("Need to return something for "+md);
417 void checkTaskExitNode(Descriptor md, SymbolTable nametable, TaskExitNode ten) {
418 if (md instanceof MethodDescriptor)
419 throw new Error("Illegal taskexit appears in Method: "+md.getSymbol());
420 checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects(),nametable);
421 checkConstraintCheck((TaskDescriptor) md, nametable, ten.getChecks());
424 void checkIfStatementNode(Descriptor md, SymbolTable nametable, IfStatementNode isn) {
425 checkExpressionNode(md, nametable, isn.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
426 checkBlockNode(md, nametable, isn.getTrueBlock());
427 if (isn.getFalseBlock()!=null)
428 checkBlockNode(md, nametable, isn.getFalseBlock());
431 void checkSwitchStatementNode(Descriptor md, SymbolTable nametable, SwitchStatementNode ssn) {
432 checkExpressionNode(md, nametable, ssn.getCondition(), new TypeDescriptor(TypeDescriptor.INT));
434 BlockNode sbn = ssn.getSwitchBody();
435 boolean hasdefault = false;
436 for(int i = 0; i < sbn.size(); i++) {
437 boolean containdefault = checkSwitchBlockNode(md, nametable, (SwitchBlockNode)sbn.get(i));
438 if(hasdefault && containdefault) {
439 throw new Error("Error: duplicate default branch in switch-case statement in Method: " + md.getSymbol());
441 hasdefault = containdefault;
445 boolean checkSwitchBlockNode(Descriptor md, SymbolTable nametable, SwitchBlockNode sbn) {
446 Vector<SwitchLabelNode> slnv = sbn.getSwitchConditions();
448 for(int i = 0; i < slnv.size(); i++) {
449 if(slnv.elementAt(i).isdefault) {
452 checkConstantExpressionNode(md, nametable, slnv.elementAt(i).getCondition(), new TypeDescriptor(TypeDescriptor.INT));
456 throw new Error("Error: duplicate default branch in switch-case statement in Method: " + md.getSymbol());
458 checkBlockNode(md, nametable, sbn.getSwitchBlockStatement());
459 return (defaultb > 0);
463 void checkConstantExpressionNode(Descriptor md, SymbolTable nametable, ExpressionNode en, TypeDescriptor td) {
465 case Kind.FieldAccessNode:
466 checkFieldAccessNode(md,nametable,(FieldAccessNode)en,td);
469 case Kind.LiteralNode:
470 checkLiteralNode(md,nametable,(LiteralNode)en,td);
476 void checkExpressionNode(Descriptor md, SymbolTable nametable, ExpressionNode en, TypeDescriptor td) {
478 case Kind.AssignmentNode:
479 checkAssignmentNode(md,nametable,(AssignmentNode)en,td);
483 checkCastNode(md,nametable,(CastNode)en,td);
486 case Kind.CreateObjectNode:
487 checkCreateObjectNode(md,nametable,(CreateObjectNode)en,td);
490 case Kind.FieldAccessNode:
491 checkFieldAccessNode(md,nametable,(FieldAccessNode)en,td);
494 case Kind.ArrayAccessNode:
495 checkArrayAccessNode(md,nametable,(ArrayAccessNode)en,td);
498 case Kind.LiteralNode:
499 checkLiteralNode(md,nametable,(LiteralNode)en,td);
502 case Kind.MethodInvokeNode:
503 checkMethodInvokeNode(md,nametable,(MethodInvokeNode)en,td);
507 checkNameNode(md,nametable,(NameNode)en,td);
511 checkOpNode(md,nametable,(OpNode)en,td);
514 case Kind.OffsetNode:
515 checkOffsetNode(md, nametable, (OffsetNode)en, td);
518 case Kind.TertiaryNode:
519 checkTertiaryNode(md, nametable, (TertiaryNode)en, td);
522 case Kind.InstanceOfNode:
523 checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
526 case Kind.ArrayInitializerNode:
527 checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en, td);
530 case Kind.ClassTypeNode:
531 checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
537 void checkClassTypeNode(Descriptor md, SymbolTable nametable, ClassTypeNode tn, TypeDescriptor td) {
538 checkTypeDescriptor(tn.getType());
541 void checkCastNode(Descriptor md, SymbolTable nametable, CastNode cn, TypeDescriptor td) {
542 /* Get type descriptor */
543 if (cn.getType()==null) {
544 NameDescriptor typenamed=cn.getTypeName().getName();
545 String typename=typenamed.toString();
546 TypeDescriptor ntd=new TypeDescriptor(getClass(typename));
550 /* Check the type descriptor */
551 TypeDescriptor cast_type=cn.getType();
552 checkTypeDescriptor(cast_type);
556 if (!typeutil.isSuperorType(td,cast_type))
557 throw new Error("Cast node returns "+cast_type+", but need "+td);
560 ExpressionNode en=cn.getExpression();
561 checkExpressionNode(md, nametable, en, null);
562 TypeDescriptor etd=en.getType();
563 if (typeutil.isSuperorType(cast_type,etd)) /* Cast trivially succeeds */
566 if (typeutil.isSuperorType(etd,cast_type)) /* Cast may succeed */
568 if (typeutil.isCastable(etd, cast_type))
571 /* Different branches */
572 /* TODO: change if add interfaces */
573 throw new Error("Cast will always fail\n"+cn.printNode(0));
576 void checkFieldAccessNode(Descriptor md, SymbolTable nametable, FieldAccessNode fan, TypeDescriptor td) {
577 ExpressionNode left=fan.getExpression();
578 checkExpressionNode(md,nametable,left,null);
579 TypeDescriptor ltd=left.getType();
580 String fieldname=fan.getFieldName();
582 FieldDescriptor fd=null;
583 if (ltd.isArray()&&fieldname.equals("length"))
584 fd=FieldDescriptor.arrayLength;
586 fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
588 // TODO add version for normal Java later
590 if(ltd.getClassDesc().isEnum()) {
591 int value = ltd.getClassDesc().getEnumConstant(fieldname);
593 // check if this field is an enum constant
594 throw new Error(fieldname + " is not an enum constant in "+fan.printNode(0)+" in "+md);
596 fd = new FieldDescriptor(new Modifiers(Modifiers.PUBLIC|Modifiers.FINAL), new TypeDescriptor(TypeDescriptor.INT), fieldname, null, false);
598 fd.setEnumValue(value);
599 } else if(fd.isStatic()) {
600 // check if this field is a static field
601 if(fd.getExpressionNode() != null) {
602 checkExpressionNode(md,nametable,fd.getExpressionNode(),null);
605 throw new Error("Dereference of the non-static field "+ fieldname + " in "+fan.printNode(0)+" in "+md);
610 throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
612 if (fd.getType().iswrapper()) {
613 FieldAccessNode fan2=new FieldAccessNode(left, fieldname);
616 fan.fieldname="value";
618 ExpressionNode leftwr=fan.getExpression();
619 TypeDescriptor ltdwr=leftwr.getType();
620 String fieldnamewr=fan.getFieldName();
621 FieldDescriptor fdwr=(FieldDescriptor) ltdwr.getClassDesc().getFieldTable().get(fieldnamewr);
624 throw new Error("Unknown field "+fieldnamewr + " in "+fan.printNode(0)+" in "+md);
629 if (!typeutil.isSuperorType(td,fan.getType()))
630 throw new Error("Field node returns "+fan.getType()+", but need "+td);
634 void checkArrayAccessNode(Descriptor md, SymbolTable nametable, ArrayAccessNode aan, TypeDescriptor td) {
635 ExpressionNode left=aan.getExpression();
636 checkExpressionNode(md,nametable,left,null);
638 checkExpressionNode(md,nametable,aan.getIndex(),new TypeDescriptor(TypeDescriptor.INT));
639 TypeDescriptor ltd=left.getType();
640 if (ltd.dereference().iswrapper()) {
641 aan.wrappertype=((FieldDescriptor)ltd.dereference().getClassDesc().getFieldTable().get("value")).getType();
645 if (!typeutil.isSuperorType(td,aan.getType()))
646 throw new Error("Field node returns "+aan.getType()+", but need "+td);
649 void checkLiteralNode(Descriptor md, SymbolTable nametable, LiteralNode ln, TypeDescriptor td) {
650 /* Resolve the type */
651 Object o=ln.getValue();
652 if (ln.getTypeString().equals("null")) {
653 ln.setType(new TypeDescriptor(TypeDescriptor.NULL));
654 } else if (o instanceof Integer) {
655 ln.setType(new TypeDescriptor(TypeDescriptor.INT));
656 } else if (o instanceof Long) {
657 ln.setType(new TypeDescriptor(TypeDescriptor.LONG));
658 } else if (o instanceof Float) {
659 ln.setType(new TypeDescriptor(TypeDescriptor.FLOAT));
660 } else if (o instanceof Boolean) {
661 ln.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
662 } else if (o instanceof Double) {
663 ln.setType(new TypeDescriptor(TypeDescriptor.DOUBLE));
664 } else if (o instanceof Character) {
665 ln.setType(new TypeDescriptor(TypeDescriptor.CHAR));
666 } else if (o instanceof String) {
667 ln.setType(new TypeDescriptor(getClass(TypeUtil.StringClass)));
671 if (!typeutil.isSuperorType(td,ln.getType())) {
672 Long l = ln.evaluate();
673 if((ln.getType().isByte() || ln.getType().isShort()
674 || ln.getType().isChar() || ln.getType().isInt())
676 && (td.isByte() || td.isShort() || td.isChar()
677 || td.isInt() || td.isLong())) {
678 long lnvalue = l.longValue();
679 if((td.isByte() && ((lnvalue > 127) || (lnvalue < -128)))
680 || (td.isShort() && ((lnvalue > 32767) || (lnvalue < -32768)))
681 || (td.isChar() && ((lnvalue > 65535) || (lnvalue < 0)))
682 || (td.isInt() && ((lnvalue > 2147483647) || (lnvalue < -2147483648)))
683 || (td.isLong() && ((lnvalue > 9223372036854775807L) || (lnvalue < -9223372036854775808L)))) {
684 throw new Error("Field node returns "+ln.getType()+", but need "+td+" in "+md);
687 throw new Error("Field node returns "+ln.getType()+", but need "+td+" in "+md);
692 void checkNameNode(Descriptor md, SymbolTable nametable, NameNode nn, TypeDescriptor td) {
693 NameDescriptor nd=nn.getName();
694 if (nd.getBase()!=null) {
696 /* Rewrite NameNode */
697 ExpressionNode en=translateNameDescriptorintoExpression(nd);
698 nn.setExpression(en);
699 checkExpressionNode(md,nametable,en,td);
701 String varname=nd.toString();
702 Descriptor d=(Descriptor)nametable.get(varname);
705 // TODO add version for normal Java later
706 ClassDescriptor cd = null;
707 if(((MethodDescriptor)md).isStaticBlock()) {
708 // this is a static block, all the accessed fields should be static field
709 cd = ((MethodDescriptor)md).getClassDesc();
710 SymbolTable fieldtbl = cd.getFieldTable();
711 FieldDescriptor fd=(FieldDescriptor)fieldtbl.get(varname);
712 if((fd == null) || (!fd.isStatic())){
713 // no such field in the class or it is not a static field
714 throw new Error("Name "+varname+" should not be used in static block: "+md);
716 // this is a static field
722 cd=getClass(varname);
724 // this is a class name
728 throw new Error("Name "+varname+" undefined in: "+md);
732 throw new Error("Name "+varname+" undefined in: "+md);
735 if (d instanceof VarDescriptor) {
737 } else if (d instanceof FieldDescriptor) {
738 FieldDescriptor fd=(FieldDescriptor)d;
739 if (fd.getType().iswrapper()) {
740 String id=nd.getIdentifier();
741 NameDescriptor base=nd.getBase();
742 NameNode n=new NameNode(nn.getName());
744 n.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
745 FieldAccessNode fan=new FieldAccessNode(n,"value");
746 FieldDescriptor fdval=(FieldDescriptor) fd.getType().getClassDesc().getFieldTable().get("value");
748 nn.setExpression(fan);
751 nn.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
753 } else if (d instanceof TagVarDescriptor) {
755 } else throw new Error("Wrong type of descriptor");
757 if (!typeutil.isSuperorType(td,nn.getType()))
758 throw new Error("Field node returns "+nn.getType()+", but need "+td);
762 void checkOffsetNode(Descriptor md, SymbolTable nameTable, OffsetNode ofn, TypeDescriptor td) {
763 TypeDescriptor ltd=ofn.td;
764 checkTypeDescriptor(ltd);
766 String fieldname = ofn.fieldname;
767 FieldDescriptor fd=null;
768 if (ltd.isArray()&&fieldname.equals("length")) {
769 fd=FieldDescriptor.arrayLength;
771 fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
775 checkField(ltd.getClassDesc(), fd);
778 throw new Error("Unknown field "+fieldname + " in "+ofn.printNode(1)+" in "+md);
781 if (!typeutil.isSuperorType(td, ofn.getType())) {
782 System.out.println(td);
783 System.out.println(ofn.getType());
784 throw new Error("Type of rside not compatible with type of lside"+ofn.printNode(0));
790 void checkTertiaryNode(Descriptor md, SymbolTable nametable, TertiaryNode tn, TypeDescriptor td) {
791 checkExpressionNode(md, nametable, tn.getCond(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
792 checkExpressionNode(md, nametable, tn.getTrueExpr(), td );
793 checkExpressionNode(md, nametable, tn.getFalseExpr(), td );
796 void checkInstanceOfNode(Descriptor md, SymbolTable nametable, InstanceOfNode tn, TypeDescriptor td) {
797 if (td!=null&&!td.isBoolean())
798 throw new Error("Expecting type "+td+"for instanceof expression");
800 checkTypeDescriptor(tn.getExprType());
801 checkExpressionNode(md, nametable, tn.getExpr(), null);
804 void checkArrayInitializerNode(Descriptor md, SymbolTable nametable, ArrayInitializerNode ain, TypeDescriptor td) {
805 Vector<TypeDescriptor> vec_type = new Vector<TypeDescriptor>();
806 for( int i = 0; i < ain.numVarInitializers(); ++i ) {
807 checkExpressionNode(md, nametable, ain.getVarInitializer(i), td==null?td:td.dereference());
808 vec_type.add(ain.getVarInitializer(i).getType());
810 // descide the type of this variableInitializerNode
811 TypeDescriptor out_type = vec_type.elementAt(0);
812 for(int i = 1; i < vec_type.size(); i++) {
813 TypeDescriptor tmp_type = vec_type.elementAt(i);
814 if(out_type == null) {
815 if(tmp_type != null) {
818 } else if(out_type.isNull()) {
819 if(!tmp_type.isNull() ) {
820 if(!tmp_type.isArray()) {
821 throw new Error("Error: mixed type in var initializer list");
826 } else if(out_type.isArray()) {
827 if(tmp_type.isArray()) {
828 if(tmp_type.getArrayCount() > out_type.getArrayCount()) {
831 } else if((tmp_type != null) && (!tmp_type.isNull())) {
832 throw new Error("Error: mixed type in var initializer list");
834 } else if(out_type.isInt()) {
835 if(!tmp_type.isInt()) {
836 throw new Error("Error: mixed type in var initializer list");
838 } else if(out_type.isString()) {
839 if(!tmp_type.isString()) {
840 throw new Error("Error: mixed type in var initializer list");
844 if(out_type != null) {
845 out_type = out_type.makeArray(state);
847 ain.setType(out_type);
850 void checkAssignmentNode(Descriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
851 boolean postinc=true;
852 if (an.getOperation().getBaseOp()==null||
853 (an.getOperation().getBaseOp().getOp()!=Operation.POSTINC&&
854 an.getOperation().getBaseOp().getOp()!=Operation.POSTDEC))
857 checkExpressionNode(md, nametable, an.getSrc(),td);
858 //TODO: Need check on validity of operation here
859 if (!((an.getDest() instanceof FieldAccessNode)||
860 (an.getDest() instanceof ArrayAccessNode)||
861 (an.getDest() instanceof NameNode)))
862 throw new Error("Bad lside in "+an.printNode(0));
863 checkExpressionNode(md, nametable, an.getDest(), null);
865 /* We want parameter variables to tasks to be immutable */
866 if (md instanceof TaskDescriptor) {
867 if (an.getDest() instanceof NameNode) {
868 NameNode nn=(NameNode)an.getDest();
869 if (nn.getVar()!=null) {
870 if (((TaskDescriptor)md).getParameterTable().contains(nn.getVar().getSymbol()))
871 throw new Error("Can't modify parameter "+nn.getVar()+ " to task "+td.getSymbol());
876 if (an.getDest().getType().isString()&&an.getOperation().getOp()==AssignOperation.PLUSEQ) {
878 ClassDescriptor stringcl=getClass(TypeUtil.StringClass);
879 TypeDescriptor stringtd=new TypeDescriptor(stringcl);
880 NameDescriptor nd=new NameDescriptor("String");
881 NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
883 if (!(an.getSrc().getType().isString()&&(an.getSrc() instanceof OpNode))) {
884 MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
885 rightmin.addArgument(an.getSrc());
887 checkExpressionNode(md, nametable, an.getSrc(), null);
891 if (!postinc&&!typeutil.isSuperorType(an.getDest().getType(),an.getSrc().getType())) {
892 TypeDescriptor dt = an.getDest().getType();
893 TypeDescriptor st = an.getSrc().getType();
894 Long l = an.getSrc().evaluate();
895 if((st.isByte() || st.isShort() || st.isChar() || st.isInt())
897 && (dt.isByte() || dt.isShort() || dt.isChar() || dt.isInt() || dt.isLong())) {
898 long lnvalue = l.longValue();
899 if((dt.isByte() && ((lnvalue > 127) || (lnvalue < -128)))
900 || (dt.isShort() && ((lnvalue > 32767) || (lnvalue < -32768)))
901 || (dt.isChar() && ((lnvalue > 65535) || (lnvalue < 0)))
902 || (dt.isInt() && ((lnvalue > 2147483647) || (lnvalue < -2147483648)))
903 || (dt.isLong() && ((lnvalue > 9223372036854775807L) || (lnvalue < -9223372036854775808L)))) {
904 throw new Error("Field node returns "+st+", but need "+dt+" in "+md);
907 throw new Error("Type of rside ("+an.getSrc().getType().toPrettyString()+") not compatible with type of lside ("+an.getDest().getType().toPrettyString()+")"+an.printNode(0));
912 void checkLoopNode(Descriptor md, SymbolTable nametable, LoopNode ln) {
914 if (ln.getType()==LoopNode.WHILELOOP||ln.getType()==LoopNode.DOWHILELOOP) {
915 checkExpressionNode(md, nametable, ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
916 checkBlockNode(md, nametable, ln.getBody());
919 /* Link in the initializer naming environment */
920 BlockNode bn=ln.getInitializer();
921 bn.getVarTable().setParent(nametable);
922 for(int i=0; i<bn.size(); i++) {
923 BlockStatementNode bsn=bn.get(i);
924 checkBlockStatementNode(md, bn.getVarTable(),bsn);
926 //check the condition
927 checkExpressionNode(md, bn.getVarTable(), ln.getCondition(), new TypeDescriptor(TypeDescriptor.BOOLEAN));
928 checkBlockNode(md, bn.getVarTable(), ln.getBody());
929 checkBlockNode(md, bn.getVarTable(), ln.getUpdate());
935 void checkCreateObjectNode(Descriptor md, SymbolTable nametable, CreateObjectNode con, TypeDescriptor td) {
936 TypeDescriptor[] tdarray=new TypeDescriptor[con.numArgs()];
937 for(int i=0; i<con.numArgs(); i++) {
938 ExpressionNode en=con.getArg(i);
939 checkExpressionNode(md,nametable,en,null);
940 tdarray[i]=en.getType();
943 TypeDescriptor typetolookin=con.getType();
944 checkTypeDescriptor(typetolookin);
946 if (td!=null&&!typeutil.isSuperorType(td, typetolookin))
947 throw new Error(typetolookin + " isn't a "+td);
949 /* Check Array Initializers */
950 if(state.MGC && (con.getArrayInitializer() != null)) {
951 checkArrayInitializerNode(md, nametable, con.getArrayInitializer(), td);
954 /* Check flag effects */
955 if (con.getFlagEffects()!=null) {
956 FlagEffects fe=con.getFlagEffects();
957 ClassDescriptor cd=typetolookin.getClassDesc();
959 for(int j=0; j<fe.numEffects(); j++) {
960 FlagEffect flag=fe.getEffect(j);
961 String name=flag.getName();
962 FlagDescriptor flag_d=(FlagDescriptor)cd.getFlagTable().get(name);
963 //Make sure the flag is declared
965 throw new Error("Flag descriptor "+name+" undefined in class: "+cd.getSymbol());
966 if (flag_d.getExternal())
967 throw new Error("Attempting to modify external flag: "+name);
968 flag.setFlag(flag_d);
970 for(int j=0; j<fe.numTagEffects(); j++) {
971 TagEffect tag=fe.getTagEffect(j);
972 String name=tag.getName();
974 Descriptor d=(Descriptor)nametable.get(name);
976 throw new Error("Tag descriptor "+name+" undeclared");
977 else if (!(d instanceof TagVarDescriptor))
978 throw new Error(name+" is not a tag descriptor");
979 tag.setTag((TagVarDescriptor)d);
983 if ((!typetolookin.isClass())&&(!typetolookin.isArray()))
984 throw new Error("Can't allocate primitive type:"+con.printNode(0));
986 if (!typetolookin.isArray()) {
987 //Array's don't need constructor calls
988 ClassDescriptor classtolookin=typetolookin.getClassDesc();
990 Set methoddescriptorset=classtolookin.getMethodTable().getSet(typetolookin.getSymbol());
991 MethodDescriptor bestmd=null;
993 for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext();) {
994 MethodDescriptor currmd=(MethodDescriptor)methodit.next();
995 /* Need correct number of parameters */
996 if (con.numArgs()!=currmd.numParameters())
998 for(int i=0; i<con.numArgs(); i++) {
999 if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
1000 continue NextMethod;
1002 /* Local allocations can't call global allocator */
1003 if (!con.isGlobal()&&currmd.isGlobal())
1006 /* Method okay so far */
1010 if (typeutil.isMoreSpecific(currmd,bestmd)) {
1012 } else if (con.isGlobal()&&match(currmd, bestmd)) {
1013 if (currmd.isGlobal()&&!bestmd.isGlobal())
1015 else if (currmd.isGlobal()&&bestmd.isGlobal())
1017 } else if (!typeutil.isMoreSpecific(bestmd, currmd)) {
1018 throw new Error("No method is most specific");
1021 /* Is this more specific than bestmd */
1025 throw new Error("No method found for "+con.printNode(0)+" in "+md);
1026 con.setConstructor(bestmd);
1031 /** Check to see if md1 is the same specificity as md2.*/
1033 boolean match(MethodDescriptor md1, MethodDescriptor md2) {
1034 /* Checks if md1 is more specific than md2 */
1035 if (md1.numParameters()!=md2.numParameters())
1037 for(int i=0; i<md1.numParameters(); i++) {
1038 if (!md2.getParamType(i).equals(md1.getParamType(i)))
1041 if (!md2.getReturnType().equals(md1.getReturnType()))
1044 if (!md2.getClassDesc().equals(md1.getClassDesc()))
1052 ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd) {
1053 String id=nd.getIdentifier();
1054 NameDescriptor base=nd.getBase();
1056 return new NameNode(nd);
1058 return new FieldAccessNode(translateNameDescriptorintoExpression(base),id);
1062 void checkMethodInvokeNode(Descriptor md, SymbolTable nametable, MethodInvokeNode min, TypeDescriptor td) {
1063 /*Typecheck subexpressions
1064 and get types for expressions*/
1066 TypeDescriptor[] tdarray=new TypeDescriptor[min.numArgs()];
1067 for(int i=0; i<min.numArgs(); i++) {
1068 ExpressionNode en=min.getArg(i);
1069 checkExpressionNode(md,nametable,en,null);
1070 tdarray[i]=en.getType();
1071 if(state.MGC && en.getType().isClass() && en.getType().getClassDesc().isEnum()) {
1072 tdarray[i] = new TypeDescriptor(TypeDescriptor.INT);
1075 TypeDescriptor typetolookin=null;
1076 if (min.getExpression()!=null) {
1077 checkExpressionNode(md,nametable,min.getExpression(),null);
1078 typetolookin=min.getExpression().getType();
1079 //if (typetolookin==null)
1080 //throw new Error(md+" has null return type");
1082 } else if (min.getBaseName()!=null) {
1083 String rootname=min.getBaseName().getRoot();
1084 if (rootname.equals("super")) {
1085 ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
1086 typetolookin=new TypeDescriptor(supercd);
1087 } else if (nametable.get(rootname)!=null) {
1088 //we have an expression
1089 min.setExpression(translateNameDescriptorintoExpression(min.getBaseName()));
1090 checkExpressionNode(md, nametable, min.getExpression(), null);
1091 typetolookin=min.getExpression().getType();
1095 if (min.getBaseName().getSymbol().equals("System.out"))
1096 cd=getClass("System");
1098 cd=getClass(min.getBaseName().getSymbol());
1100 throw new Error("md = "+ md.toString()+ " "+min.getBaseName()+" undefined");
1101 typetolookin=new TypeDescriptor(cd);
1103 } else if ((md instanceof MethodDescriptor)&&min.getMethodName().equals("super")) {
1104 ClassDescriptor supercd=((MethodDescriptor)md).getClassDesc().getSuperDesc();
1105 min.methodid=supercd.getSymbol();
1106 typetolookin=new TypeDescriptor(supercd);
1107 } else if (md instanceof MethodDescriptor) {
1108 typetolookin=new TypeDescriptor(((MethodDescriptor)md).getClassDesc());
1110 /* If this a task descriptor we throw an error at this point */
1111 throw new Error("Unknown method call to "+min.getMethodName()+"in task"+md.getSymbol());
1113 if (!typetolookin.isClass())
1114 throw new Error("Error with method call to "+min.getMethodName());
1115 ClassDescriptor classtolookin=typetolookin.getClassDesc();
1116 //System.out.println("Method name="+min.getMethodName());
1118 Set methoddescriptorset=classtolookin.getMethodTable().getSet(min.getMethodName());
1119 MethodDescriptor bestmd=null;
1121 for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext();) {
1122 MethodDescriptor currmd=(MethodDescriptor)methodit.next();
1123 /* Need correct number of parameters */
1124 if (min.numArgs()!=currmd.numParameters())
1126 for(int i=0; i<min.numArgs(); i++) {
1127 if (!typeutil.isSuperorType(currmd.getParamType(i),tdarray[i]))
1128 continue NextMethod;
1130 /* Method okay so far */
1134 if (typeutil.isMoreSpecific(currmd,bestmd)) {
1136 } else if (!typeutil.isMoreSpecific(bestmd, currmd))
1137 throw new Error("No method is most specific");
1139 /* Is this more specific than bestmd */
1143 throw new Error("No method found for :"+min.printNode(0)+" in class: " + classtolookin+" in "+md);
1144 min.setMethod(bestmd);
1146 if ((td!=null)&&(min.getType()!=null)&&!typeutil.isSuperorType(td, min.getType()))
1147 throw new Error(min.getType()+ " is not equal to or a subclass of "+td);
1148 /* Check whether we need to set this parameter to implied this */
1149 if (!bestmd.isStatic()) {
1150 if (min.getExpression()==null) {
1151 ExpressionNode en=new NameNode(new NameDescriptor("this"));
1152 min.setExpression(en);
1153 checkExpressionNode(md, nametable, min.getExpression(), null);
1159 void checkOpNode(Descriptor md, SymbolTable nametable, OpNode on, TypeDescriptor td) {
1160 checkExpressionNode(md, nametable, on.getLeft(), null);
1161 if (on.getRight()!=null)
1162 checkExpressionNode(md, nametable, on.getRight(), null);
1163 TypeDescriptor ltd=on.getLeft().getType();
1164 TypeDescriptor rtd=on.getRight()!=null ? on.getRight().getType() : null;
1165 TypeDescriptor lefttype=null;
1166 TypeDescriptor righttype=null;
1167 Operation op=on.getOp();
1169 switch(op.getOp()) {
1170 case Operation.LOGIC_OR:
1171 case Operation.LOGIC_AND:
1172 if (!(rtd.isBoolean()))
1174 on.setRightType(rtd);
1176 case Operation.LOGIC_NOT:
1177 if (!(ltd.isBoolean()))
1180 on.setLeftType(ltd);
1182 on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1185 case Operation.COMP:
1186 // 5.6.2 Binary Numeric Promotion
1187 //TODO unboxing of reference objects
1190 else if (ltd.isFloat())
1192 else if (ltd.isLong())
1193 lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1195 lefttype=new TypeDescriptor(TypeDescriptor.INT);
1196 on.setLeftType(lefttype);
1197 on.setType(lefttype);
1200 case Operation.BIT_OR:
1201 case Operation.BIT_XOR:
1202 case Operation.BIT_AND:
1203 // 5.6.2 Binary Numeric Promotion
1204 //TODO unboxing of reference objects
1205 if (ltd.isDouble()||rtd.isDouble())
1207 else if (ltd.isFloat()||rtd.isFloat())
1209 else if (ltd.isLong()||rtd.isLong())
1210 lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1211 // 090205 hack for boolean
1212 else if (ltd.isBoolean()||rtd.isBoolean())
1213 lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
1215 lefttype=new TypeDescriptor(TypeDescriptor.INT);
1218 on.setLeftType(lefttype);
1219 on.setRightType(righttype);
1220 on.setType(lefttype);
1223 case Operation.ISAVAILABLE:
1224 if (!(ltd.isPtr())) {
1225 throw new Error("Can't use isavailable on non-pointers/non-parameters.");
1228 on.setLeftType(lefttype);
1229 on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1232 case Operation.EQUAL:
1233 case Operation.NOTEQUAL:
1234 // 5.6.2 Binary Numeric Promotion
1235 //TODO unboxing of reference objects
1236 if (ltd.isBoolean()||rtd.isBoolean()) {
1237 if (!(ltd.isBoolean()&&rtd.isBoolean()))
1239 righttype=lefttype=new TypeDescriptor(TypeDescriptor.BOOLEAN);
1240 } else if (ltd.isPtr()||rtd.isPtr()) {
1241 if (!(ltd.isPtr()&&rtd.isPtr()))
1245 } else if (ltd.isDouble()||rtd.isDouble())
1246 righttype=lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
1247 else if (ltd.isFloat()||rtd.isFloat())
1248 righttype=lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
1249 else if (ltd.isLong()||rtd.isLong())
1250 righttype=lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1252 righttype=lefttype=new TypeDescriptor(TypeDescriptor.INT);
1254 on.setLeftType(lefttype);
1255 on.setRightType(righttype);
1256 on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1265 // 5.6.2 Binary Numeric Promotion
1266 //TODO unboxing of reference objects
1267 if (!ltd.isNumber()||!rtd.isNumber()) {
1268 if (!ltd.isNumber())
1269 throw new Error("Leftside is not number"+on.printNode(0)+"type="+ltd.toPrettyString());
1270 if (!rtd.isNumber())
1271 throw new Error("Rightside is not number"+on.printNode(0));
1274 if (ltd.isDouble()||rtd.isDouble())
1275 lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
1276 else if (ltd.isFloat()||rtd.isFloat())
1277 lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
1278 else if (ltd.isLong()||rtd.isLong())
1279 lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1281 lefttype=new TypeDescriptor(TypeDescriptor.INT);
1283 on.setLeftType(lefttype);
1284 on.setRightType(righttype);
1285 on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
1289 if (ltd.isString()||rtd.isString()) {
1290 ClassDescriptor stringcl=getClass(TypeUtil.StringClass);
1291 TypeDescriptor stringtd=new TypeDescriptor(stringcl);
1292 NameDescriptor nd=new NameDescriptor("String");
1293 NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
1294 if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
1295 MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
1296 leftmin.addArgument(on.getLeft());
1298 checkExpressionNode(md, nametable, on.getLeft(), null);
1301 if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
1302 MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
1303 rightmin.addArgument(on.getRight());
1305 checkExpressionNode(md, nametable, on.getRight(), null);
1308 on.setLeftType(stringtd);
1309 on.setRightType(stringtd);
1310 on.setType(stringtd);
1315 case Operation.MULT:
1318 // 5.6.2 Binary Numeric Promotion
1319 //TODO unboxing of reference objects
1320 if (ltd.isArray()||rtd.isArray()||!ltd.isNumber()||!rtd.isNumber())
1321 throw new Error("Error in "+on.printNode(0));
1323 if (ltd.isDouble()||rtd.isDouble())
1324 lefttype=new TypeDescriptor(TypeDescriptor.DOUBLE);
1325 else if (ltd.isFloat()||rtd.isFloat())
1326 lefttype=new TypeDescriptor(TypeDescriptor.FLOAT);
1327 else if (ltd.isLong()||rtd.isLong())
1328 lefttype=new TypeDescriptor(TypeDescriptor.LONG);
1330 lefttype=new TypeDescriptor(TypeDescriptor.INT);
1332 on.setLeftType(lefttype);
1333 on.setRightType(righttype);
1334 on.setType(lefttype);
1337 case Operation.LEFTSHIFT:
1338 case Operation.RIGHTSHIFT:
1339 case Operation.URIGHTSHIFT:
1340 if (!rtd.isIntegerType())
1342 //5.6.1 Unary Numeric Promotion
1343 if (rtd.isByte()||rtd.isShort()||rtd.isInt())
1344 righttype=new TypeDescriptor(TypeDescriptor.INT);
1348 on.setRightType(righttype);
1349 if (!ltd.isIntegerType())
1352 case Operation.UNARYPLUS:
1353 case Operation.UNARYMINUS:
1354 /* case Operation.POSTINC:
1355 case Operation.POSTDEC:
1356 case Operation.PREINC:
1357 case Operation.PREDEC:*/
1358 if (!ltd.isNumber())
1360 //5.6.1 Unary Numeric Promotion
1361 if (ltd.isByte()||ltd.isShort()||ltd.isInt())
1362 lefttype=new TypeDescriptor(TypeDescriptor.INT);
1365 on.setLeftType(lefttype);
1366 on.setType(lefttype);
1370 throw new Error(op.toString());
1374 if (!typeutil.isSuperorType(td, on.getType())) {
1375 System.out.println(td);
1376 System.out.println(on.getType());
1377 throw new Error("Type of rside not compatible with type of lside"+on.printNode(0));