diff options
author | cushon <cushon@google.com> | 2016-10-28 16:27:41 -0700 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2016-10-28 17:06:37 -0700 |
commit | 3e5b0c401c8d93182e9f0ce6f0de81f7574f5aca (patch) | |
tree | 166d0741c1cebf6929b1ea5b0fe23a388fed83dd /java/com/google/turbine/types/Canonicalize.java | |
parent | 5460a3b06da4ef3978cac89dc6d45983c8c396ef (diff) | |
download | turbine-3e5b0c401c8d93182e9f0ce6f0de81f7574f5aca.tar.gz |
Initial type annotation support
Handle binding of type annotations, evaluation of type annotation
arguments, and lowering to bytecode for all type annotations kinds that
can appears in headers.
Currently type annotations are identified syntactically, we need to read
@Target to deal with ambiguous declarations on fields and method return
types (e.g. `@A int x;` could be `TYPE_USE` or `FIELD` or both).
MOE_MIGRATED_REVID=137566512
Diffstat (limited to 'java/com/google/turbine/types/Canonicalize.java')
-rw-r--r-- | java/com/google/turbine/types/Canonicalize.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/java/com/google/turbine/types/Canonicalize.java b/java/com/google/turbine/types/Canonicalize.java index f283a06..9617c7e 100644 --- a/java/com/google/turbine/types/Canonicalize.java +++ b/java/com/google/turbine/types/Canonicalize.java @@ -74,8 +74,7 @@ public class Canonicalize { case ARRAY_TY: { Type.ArrayTy arrayTy = (Type.ArrayTy) type; - return new Type.ArrayTy( - arrayTy.dimension(), canonicalize(env, base, arrayTy.elementType())); + return new Type.ArrayTy(canonicalize(env, base, arrayTy.elementType()), arrayTy.annos()); } case CLASS_TY: return canonicalizeClassTy(env, base, (ClassTy) type); @@ -147,9 +146,9 @@ public class Canonicalize { Env<ClassSymbol, TypeBoundClass> env, ClassSymbol owner) { ImmutableList.Builder<Type> targs = ImmutableList.builder(); for (TyVarSymbol p : env.get(owner).typeParameterTypes().keySet()) { - targs.add(new Type.TyVar(p)); + targs.add(new Type.TyVar(p, ImmutableList.of())); } - return new ClassTy.SimpleClassTy(owner, targs.build()); + return new ClassTy.SimpleClassTy(owner, targs.build(), ImmutableList.of()); } // is s a subclass (not interface) of t? @@ -235,7 +234,7 @@ public class Canonicalize { List<Type> args = new ArrayList<>(); for (TyVarSymbol sym : env.get(classSymbol).typeParameterTypes().keySet()) { if (!mapping.containsKey(sym)) { - args.add(new Type.TyVar(sym)); + args.add(new Type.TyVar(sym, ImmutableList.of())); continue; } Type arg = instantiate(mapping, mapping.get(sym)); @@ -246,7 +245,7 @@ public class Canonicalize { } args.add(arg); } - return new ClassTy.SimpleClassTy(classSymbol, ImmutableList.copyOf(args)); + return new ClassTy.SimpleClassTy(classSymbol, ImmutableList.copyOf(args), ImmutableList.of()); } /** Instantiates a type argument using the given mapping. */ @@ -265,7 +264,7 @@ public class Canonicalize { case ARRAY_TY: ArrayTy arrayTy = (ArrayTy) type; Type elem = instantiate(mapping, arrayTy.elementType()); - return new ArrayTy(arrayTy.dimension(), elem); + return new ArrayTy(elem, arrayTy.annos()); case TY_VAR: TyVar tyVar = (TyVar) type; if (mapping.containsKey(tyVar.sym())) { @@ -282,9 +281,9 @@ public class Canonicalize { case NONE: return type; case UPPER: - return new Type.WildUpperBoundedTy(instantiate(mapping, type.bound())); + return new Type.WildUpperBoundedTy(instantiate(mapping, type.bound()), type.annotations()); case LOWER: - return new Type.WildLowerBoundedTy(instantiate(mapping, type.bound())); + return new Type.WildLowerBoundedTy(instantiate(mapping, type.bound()), type.annotations()); default: throw new AssertionError(type.boundKind()); } @@ -297,7 +296,7 @@ public class Canonicalize { for (Type arg : simple.targs()) { args.add(instantiate(mapping, arg)); } - simples.add(new SimpleClassTy(simple.sym(), args.build())); + simples.add(new SimpleClassTy(simple.sym(), args.build(), simple.annos())); } return new ClassTy(simples.build()); } @@ -319,7 +318,7 @@ public class Canonicalize { // canonicalize type arguments first ImmutableList.Builder<ClassTy.SimpleClassTy> args = ImmutableList.builder(); for (ClassTy.SimpleClassTy s : ty.classes) { - args.add(new ClassTy.SimpleClassTy(s.sym(), canonicalize(s.targs(), base, env))); + args.add(new ClassTy.SimpleClassTy(s.sym(), canonicalize(s.targs(), base, env), s.annos())); } ty = new ClassTy(args.build()); return canon(env, base, ty); @@ -340,9 +339,11 @@ public class Canonicalize { case NONE: return type; case LOWER: - return new Type.WildLowerBoundedTy(canonicalize(env, base, type.bound())); + return new Type.WildLowerBoundedTy( + canonicalize(env, base, type.bound()), type.annotations()); case UPPER: - return new Type.WildUpperBoundedTy(canonicalize(env, base, type.bound())); + return new Type.WildUpperBoundedTy( + canonicalize(env, base, type.bound()), type.annotations()); default: throw new AssertionError(type.boundKind()); } |