43 import com.sun.tools.javac.util.*; |
43 import com.sun.tools.javac.util.*; |
44 |
44 |
45 import static com.sun.tools.javac.code.BoundKind.*; |
45 import static com.sun.tools.javac.code.BoundKind.*; |
46 import static com.sun.tools.javac.code.Flags.*; |
46 import static com.sun.tools.javac.code.Flags.*; |
47 import static com.sun.tools.javac.code.Kinds.*; |
47 import static com.sun.tools.javac.code.Kinds.*; |
48 import static com.sun.tools.javac.code.TypeTags.*; |
48 import static com.sun.tools.javac.code.TypeTag.*; |
49 import static com.sun.tools.javac.jvm.UninitializedType.*; |
49 import static com.sun.tools.javac.jvm.UninitializedType.*; |
50 import static com.sun.tools.javac.main.Option.*; |
50 import static com.sun.tools.javac.main.Option.*; |
51 import static javax.tools.StandardLocation.CLASS_OUTPUT; |
51 import static javax.tools.StandardLocation.CLASS_OUTPUT; |
52 |
52 |
53 |
53 |
272 ******************************************************************/ |
272 ******************************************************************/ |
273 |
273 |
274 /** Assemble signature of given type in string buffer. |
274 /** Assemble signature of given type in string buffer. |
275 */ |
275 */ |
276 void assembleSig(Type type) { |
276 void assembleSig(Type type) { |
277 switch (type.tag) { |
277 switch (type.getTag()) { |
278 case BYTE: |
278 case BYTE: |
279 sigbuf.appendByte('B'); |
279 sigbuf.appendByte('B'); |
280 break; |
280 break; |
281 case SHORT: |
281 case SHORT: |
282 sigbuf.appendByte('S'); |
282 sigbuf.appendByte('S'); |
359 // we don't yet have a spec for uninitialized types in the |
359 // we don't yet have a spec for uninitialized types in the |
360 // local variable table |
360 // local variable table |
361 assembleSig(types.erasure(((UninitializedType)type).qtype)); |
361 assembleSig(types.erasure(((UninitializedType)type).qtype)); |
362 break; |
362 break; |
363 default: |
363 default: |
364 throw new AssertionError("typeSig " + type.tag); |
364 throw new AssertionError("typeSig " + type.getTag()); |
365 } |
365 } |
366 } |
366 } |
367 |
367 |
368 boolean hasTypeVar(List<Type> l) { |
368 boolean hasTypeVar(List<Type> l) { |
369 while (l.nonEmpty()) { |
369 while (l.nonEmpty()) { |
370 if (l.head.tag == TypeTags.TYPEVAR) return true; |
370 if (l.head.hasTag(TYPEVAR)) return true; |
371 l = l.tail; |
371 l = l.tail; |
372 } |
372 } |
373 return false; |
373 return false; |
374 } |
374 } |
375 |
375 |
437 |
437 |
438 /** Given a type t, return the extended class name of its erasure in |
438 /** Given a type t, return the extended class name of its erasure in |
439 * external representation. |
439 * external representation. |
440 */ |
440 */ |
441 public Name xClassName(Type t) { |
441 public Name xClassName(Type t) { |
442 if (t.tag == CLASS) { |
442 if (t.hasTag(CLASS)) { |
443 return names.fromUtf(externalize(t.tsym.flatName())); |
443 return names.fromUtf(externalize(t.tsym.flatName())); |
444 } else if (t.tag == ARRAY) { |
444 } else if (t.hasTag(ARRAY)) { |
445 return typeSig(types.erasure(t)); |
445 return typeSig(types.erasure(t)); |
446 } else { |
446 } else { |
447 throw new AssertionError("xClassName"); |
447 throw new AssertionError("xClassName"); |
448 } |
448 } |
449 } |
449 } |
519 throw new StringOverflow(value.toString()); |
519 throw new StringOverflow(value.toString()); |
520 } else if (value instanceof ClassSymbol) { |
520 } else if (value instanceof ClassSymbol) { |
521 ClassSymbol c = (ClassSymbol)value; |
521 ClassSymbol c = (ClassSymbol)value; |
522 if (c.owner.kind == TYP) pool.put(c.owner); |
522 if (c.owner.kind == TYP) pool.put(c.owner); |
523 poolbuf.appendByte(CONSTANT_Class); |
523 poolbuf.appendByte(CONSTANT_Class); |
524 if (c.type.tag == ARRAY) { |
524 if (c.type.hasTag(ARRAY)) { |
525 poolbuf.appendChar(pool.put(typeSig(c.type))); |
525 poolbuf.appendChar(pool.put(typeSig(c.type))); |
526 } else { |
526 } else { |
527 poolbuf.appendChar(pool.put(names.fromUtf(externalize(c.flatname)))); |
527 poolbuf.appendChar(pool.put(names.fromUtf(externalize(c.flatname)))); |
528 enterInner(c); |
528 enterInner(c); |
529 } |
529 } |
553 MethodType mtype = (MethodType)value; |
553 MethodType mtype = (MethodType)value; |
554 poolbuf.appendByte(CONSTANT_MethodType); |
554 poolbuf.appendByte(CONSTANT_MethodType); |
555 poolbuf.appendChar(pool.put(typeSig(mtype))); |
555 poolbuf.appendChar(pool.put(typeSig(mtype))); |
556 } else if (value instanceof Type) { |
556 } else if (value instanceof Type) { |
557 Type type = (Type)value; |
557 Type type = (Type)value; |
558 if (type.tag == CLASS) enterInner((ClassSymbol)type.tsym); |
558 if (type.hasTag(CLASS)) enterInner((ClassSymbol)type.tsym); |
559 poolbuf.appendByte(CONSTANT_Class); |
559 poolbuf.appendByte(CONSTANT_Class); |
560 poolbuf.appendChar(pool.put(xClassName(type))); |
560 poolbuf.appendChar(pool.put(xClassName(type))); |
561 } else if (value instanceof Pool.MethodHandle) { |
561 } else if (value instanceof Pool.MethodHandle) { |
562 Pool.MethodHandle ref = (Pool.MethodHandle)value; |
562 Pool.MethodHandle ref = (Pool.MethodHandle)value; |
563 poolbuf.appendByte(CONSTANT_MethodHandle); |
563 poolbuf.appendByte(CONSTANT_MethodHandle); |
813 * single-character marker. |
813 * single-character marker. |
814 */ |
814 */ |
815 class AttributeWriter implements Attribute.Visitor { |
815 class AttributeWriter implements Attribute.Visitor { |
816 public void visitConstant(Attribute.Constant _value) { |
816 public void visitConstant(Attribute.Constant _value) { |
817 Object value = _value.value; |
817 Object value = _value.value; |
818 switch (_value.type.tag) { |
818 switch (_value.type.getTag()) { |
819 case BYTE: |
819 case BYTE: |
820 databuf.appendByte('B'); |
820 databuf.appendByte('B'); |
821 break; |
821 break; |
822 case CHAR: |
822 case CHAR: |
823 databuf.appendByte('C'); |
823 databuf.appendByte('C'); |
899 c.complete(); |
899 c.complete(); |
900 } catch (CompletionFailure ex) { |
900 } catch (CompletionFailure ex) { |
901 System.err.println("error: " + c + ": " + ex.getMessage()); |
901 System.err.println("error: " + c + ": " + ex.getMessage()); |
902 throw ex; |
902 throw ex; |
903 } |
903 } |
904 if (c.type.tag != CLASS) return; // arrays |
904 if (!c.type.hasTag(CLASS)) return; // arrays |
905 if (pool != null && // pool might be null if called from xClassName |
905 if (pool != null && // pool might be null if called from xClassName |
906 c.owner.enclClass() != null && |
906 c.owner.enclClass() != null && |
907 (innerClasses == null || !innerClasses.contains(c))) { |
907 (innerClasses == null || !innerClasses.contains(c))) { |
908 // log.errWriter.println("enter inner " + c);//DEBUG |
908 // log.errWriter.println("enter inner " + c);//DEBUG |
909 enterInner(c.owner.enclClass()); |
909 enterInner(c.owner.enclClass()); |
1428 // FULL_FRAME |
1428 // FULL_FRAME |
1429 return new FullFrame(offset_delta, locals, stack); |
1429 return new FullFrame(offset_delta, locals, stack); |
1430 } |
1430 } |
1431 |
1431 |
1432 static boolean isInt(Type t) { |
1432 static boolean isInt(Type t) { |
1433 return (t.tag < TypeTags.INT || t.tag == TypeTags.BOOLEAN); |
1433 return (t.getTag().isStrictSubRangeOf(INT) || t.hasTag(BOOLEAN)); |
1434 } |
1434 } |
1435 |
1435 |
1436 static boolean isSameType(Type t1, Type t2, Types types) { |
1436 static boolean isSameType(Type t1, Type t2, Types types) { |
1437 if (t1 == null) { return t2 == null; } |
1437 if (t1 == null) { return t2 == null; } |
1438 if (t2 == null) { return false; } |
1438 if (t2 == null) { return false; } |
1439 |
1439 |
1440 if (isInt(t1) && isInt(t2)) { return true; } |
1440 if (isInt(t1) && isInt(t2)) { return true; } |
1441 |
1441 |
1442 if (t1.tag == UNINITIALIZED_THIS) { |
1442 if (t1.hasTag(UNINITIALIZED_THIS)) { |
1443 return t2.tag == UNINITIALIZED_THIS; |
1443 return t2.hasTag(UNINITIALIZED_THIS); |
1444 } else if (t1.tag == UNINITIALIZED_OBJECT) { |
1444 } else if (t1.hasTag(UNINITIALIZED_OBJECT)) { |
1445 if (t2.tag == UNINITIALIZED_OBJECT) { |
1445 if (t2.hasTag(UNINITIALIZED_OBJECT)) { |
1446 return ((UninitializedType)t1).offset == ((UninitializedType)t2).offset; |
1446 return ((UninitializedType)t1).offset == ((UninitializedType)t2).offset; |
1447 } else { |
1447 } else { |
1448 return false; |
1448 return false; |
1449 } |
1449 } |
1450 } else if (t2.tag == UNINITIALIZED_THIS || t2.tag == UNINITIALIZED_OBJECT) { |
1450 } else if (t2.hasTag(UNINITIALIZED_THIS) || t2.hasTag(UNINITIALIZED_OBJECT)) { |
1451 return false; |
1451 return false; |
1452 } |
1452 } |
1453 |
1453 |
1454 return types.isSameType(t1, t2); |
1454 return types.isSameType(t1, t2); |
1455 } |
1455 } |
1552 pw.println("---" + flagNames(flags)); |
1552 pw.println("---" + flagNames(flags)); |
1553 } |
1553 } |
1554 databuf.appendChar(flags); |
1554 databuf.appendChar(flags); |
1555 |
1555 |
1556 databuf.appendChar(pool.put(c)); |
1556 databuf.appendChar(pool.put(c)); |
1557 databuf.appendChar(supertype.tag == CLASS ? pool.put(supertype.tsym) : 0); |
1557 databuf.appendChar(supertype.hasTag(CLASS) ? pool.put(supertype.tsym) : 0); |
1558 databuf.appendChar(interfaces.length()); |
1558 databuf.appendChar(interfaces.length()); |
1559 for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) |
1559 for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) |
1560 databuf.appendChar(pool.put(l.head.tsym)); |
1560 databuf.appendChar(pool.put(l.head.tsym)); |
1561 int fieldsCount = 0; |
1561 int fieldsCount = 0; |
1562 int methodsCount = 0; |
1562 int methodsCount = 0; |