aboutsummaryrefslogtreecommitdiff
path: root/java/com/google/turbine
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/google/turbine')
-rw-r--r--java/com/google/turbine/binder/ConstBinder.java4
-rw-r--r--java/com/google/turbine/binder/ConstEvaluator.java19
-rw-r--r--java/com/google/turbine/binder/CtSymClassBinder.java4
-rw-r--r--java/com/google/turbine/binder/JimageClassBinder.java4
-rw-r--r--java/com/google/turbine/binder/bound/TurbineClassValue.java (renamed from java/com/google/turbine/binder/bound/ClassValue.java)8
-rw-r--r--java/com/google/turbine/binder/bytecode/BytecodeBinder.java8
-rw-r--r--java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java4
-rw-r--r--java/com/google/turbine/binder/lookup/ImportIndex.java15
-rw-r--r--java/com/google/turbine/binder/lookup/LookupResult.java4
-rw-r--r--java/com/google/turbine/binder/lookup/WildImportIndex.java12
-rw-r--r--java/com/google/turbine/bytecode/AnnotationWriter.java6
-rw-r--r--java/com/google/turbine/bytecode/ClassFile.java4
-rw-r--r--java/com/google/turbine/bytecode/ClassReader.java7
-rw-r--r--java/com/google/turbine/diag/TurbineError.java1
-rw-r--r--java/com/google/turbine/lower/Lower.java10
-rw-r--r--java/com/google/turbine/main/Main.java6
-rw-r--r--java/com/google/turbine/options/TurbineOptionsParser.java14
-rw-r--r--java/com/google/turbine/parse/Parser.java9
-rw-r--r--java/com/google/turbine/type/Type.java3
-rw-r--r--java/com/google/turbine/types/Canonicalize.java2
20 files changed, 92 insertions, 52 deletions
diff --git a/java/com/google/turbine/binder/ConstBinder.java b/java/com/google/turbine/binder/ConstBinder.java
index e5717b2..0f989dd 100644
--- a/java/com/google/turbine/binder/ConstBinder.java
+++ b/java/com/google/turbine/binder/ConstBinder.java
@@ -20,9 +20,9 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.turbine.binder.bound.AnnotationMetadata;
-import com.google.turbine.binder.bound.ClassValue;
import com.google.turbine.binder.bound.EnumConstantValue;
import com.google.turbine.binder.bound.SourceTypeBoundClass;
+import com.google.turbine.binder.bound.TurbineClassValue;
import com.google.turbine.binder.bound.TypeBoundClass;
import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo;
import com.google.turbine.binder.bound.TypeBoundClass.MethodInfo;
@@ -215,7 +215,7 @@ public class ConstBinder {
if (value.kind() != Kind.CLASS_LITERAL) {
return null;
}
- Type type = ((ClassValue) value).type();
+ Type type = ((TurbineClassValue) value).type();
if (type.tyKind() != TyKind.CLASS_TY) {
return null;
}
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java
index 2d8ce2d..0e837a4 100644
--- a/java/com/google/turbine/binder/ConstEvaluator.java
+++ b/java/com/google/turbine/binder/ConstEvaluator.java
@@ -18,12 +18,13 @@ package com.google.turbine.binder;
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.turbine.binder.bound.AnnotationValue;
-import com.google.turbine.binder.bound.ClassValue;
import com.google.turbine.binder.bound.EnumConstantValue;
+import com.google.turbine.binder.bound.TurbineClassValue;
import com.google.turbine.binder.bound.TypeBoundClass;
import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo;
import com.google.turbine.binder.bound.TypeBoundClass.MethodInfo;
@@ -35,6 +36,7 @@ import com.google.turbine.binder.lookup.MemberImportIndex;
import com.google.turbine.binder.lookup.Scope;
import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.binder.sym.FieldSymbol;
+import com.google.turbine.binder.sym.Symbol;
import com.google.turbine.diag.SourceFile;
import com.google.turbine.diag.TurbineError;
import com.google.turbine.diag.TurbineError.ErrorKind;
@@ -166,7 +168,7 @@ public strictfp class ConstEvaluator {
/** Evaluates a class literal. */
Const evalClassLiteral(ClassLiteral t) {
- return new ClassValue(evalClassLiteralType(t.type()));
+ return new TurbineClassValue(evalClassLiteralType(t.type()));
}
private Type evalClassLiteralType(Tree.Type type) {
@@ -203,6 +205,9 @@ public strictfp class ConstEvaluator {
if (result == null) {
throw error(classTy.position(), ErrorKind.CANNOT_RESOLVE, flat.peekFirst());
}
+ if (result.sym().symKind() != Symbol.Kind.CLASS) {
+ throw error(classTy.position(), ErrorKind.UNEXPECTED_TYPE_PARAMETER, flat.peekFirst());
+ }
ClassSymbol classSym = (ClassSymbol) result.sym();
for (Ident bit : result.remaining()) {
classSym = resolveNext(classTy.position(), classSym, bit);
@@ -949,9 +954,19 @@ public strictfp class ConstEvaluator {
private AnnotationValue evalAnno(Tree.Anno t) {
LookupResult result = scope.lookup(new LookupKey(t.name()));
+ if (result == null) {
+ throw error(
+ t.name().get(0).position(), ErrorKind.CANNOT_RESOLVE, Joiner.on(".").join(t.name()));
+ }
ClassSymbol sym = (ClassSymbol) result.sym();
for (Ident name : result.remaining()) {
sym = Resolve.resolve(env, sym, sym, name);
+ if (sym == null) {
+ throw error(name.position(), ErrorKind.CANNOT_RESOLVE, name.value());
+ }
+ }
+ if (sym == null) {
+ return null;
}
AnnoInfo annoInfo = evaluateAnnotation(new AnnoInfo(source, sym, t, null));
return new AnnotationValue(annoInfo.sym(), annoInfo.values());
diff --git a/java/com/google/turbine/binder/CtSymClassBinder.java b/java/com/google/turbine/binder/CtSymClassBinder.java
index fd2e544..d9d74ab 100644
--- a/java/com/google/turbine/binder/CtSymClassBinder.java
+++ b/java/com/google/turbine/binder/CtSymClassBinder.java
@@ -16,6 +16,8 @@
package com.google.turbine.binder;
+import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
+
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
@@ -42,7 +44,7 @@ public class CtSymClassBinder {
@Nullable
public static ClassPath bind(String version) throws IOException {
- Path javaHome = Paths.get(System.getProperty("java.home"));
+ Path javaHome = Paths.get(JAVA_HOME.value());
Path ctSym = javaHome.resolve("lib/ct.sym");
if (!Files.exists(ctSym)) {
throw new IllegalStateException("lib/ct.sym does not exist in " + javaHome);
diff --git a/java/com/google/turbine/binder/JimageClassBinder.java b/java/com/google/turbine/binder/JimageClassBinder.java
index 72bcb2f..b32b8ea 100644
--- a/java/com/google/turbine/binder/JimageClassBinder.java
+++ b/java/com/google/turbine/binder/JimageClassBinder.java
@@ -16,6 +16,8 @@
package com.google.turbine.binder;
+import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
+
import com.google.common.base.Joiner;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
@@ -79,7 +81,7 @@ public class JimageClassBinder {
/** Returns a platform classpath for the given JDK's jimage file. */
public static ClassPath bind(String javaHome) throws IOException {
- if (javaHome.equals(System.getProperty("java.home"))) {
+ if (javaHome.equals(JAVA_HOME.value())) {
return bindDefault();
}
FileSystem fileSystem =
diff --git a/java/com/google/turbine/binder/bound/ClassValue.java b/java/com/google/turbine/binder/bound/TurbineClassValue.java
index a75db42..df55501 100644
--- a/java/com/google/turbine/binder/bound/ClassValue.java
+++ b/java/com/google/turbine/binder/bound/TurbineClassValue.java
@@ -21,11 +21,11 @@ import com.google.turbine.type.Type;
import java.util.Objects;
/** A class literal constant. */
-public class ClassValue extends Const {
+public class TurbineClassValue extends Const {
private final Type type;
- public ClassValue(Type type) {
+ public TurbineClassValue(Type type) {
this.type = type;
}
@@ -46,11 +46,11 @@ public class ClassValue extends Const {
@Override
public int hashCode() {
- return Objects.hash(type);
+ return Objects.hashCode(type);
}
@Override
public boolean equals(Object obj) {
- return obj instanceof ClassValue && type().equals(((ClassValue) obj).type());
+ return obj instanceof TurbineClassValue && type().equals(((TurbineClassValue) obj).type());
}
}
diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBinder.java b/java/com/google/turbine/binder/bytecode/BytecodeBinder.java
index e5ba343..1d2eecb 100644
--- a/java/com/google/turbine/binder/bytecode/BytecodeBinder.java
+++ b/java/com/google/turbine/binder/bytecode/BytecodeBinder.java
@@ -19,9 +19,9 @@ package com.google.turbine.binder.bytecode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.turbine.binder.bound.AnnotationValue;
-import com.google.turbine.binder.bound.ClassValue;
import com.google.turbine.binder.bound.EnumConstantValue;
import com.google.turbine.binder.bound.ModuleInfo;
+import com.google.turbine.binder.bound.TurbineClassValue;
import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.binder.sym.FieldSymbol;
import com.google.turbine.binder.sym.TyVarSymbol;
@@ -29,7 +29,7 @@ import com.google.turbine.bytecode.ClassFile;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ArrayValue;
-import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue;
+import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue;
import com.google.turbine.bytecode.ClassReader;
@@ -118,9 +118,9 @@ public class BytecodeBinder {
case ARRAY:
return bindArrayValue(type, (ArrayValue) value);
case CLASS:
- return new ClassValue(
+ return new TurbineClassValue(
bindTy(
- new SigParser(((ConstClassValue) value).className()).parseType(),
+ new SigParser(((ConstTurbineClassValue) value).className()).parseType(),
x -> {
throw new IllegalStateException(x);
}));
diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
index f21760b..6e882e6 100644
--- a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
+++ b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
@@ -37,7 +37,7 @@ import com.google.turbine.bytecode.ClassFile;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ArrayValue;
-import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue;
+import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.Kind;
import com.google.turbine.bytecode.ClassFile.MethodInfo.ParameterInfo;
@@ -530,7 +530,7 @@ public class BytecodeBoundClass implements BoundClass, HeaderBoundClass, TypeBou
ElementValue val = annotation.elementValuePairs().get("value");
switch (val.kind()) {
case CLASS:
- String className = ((ConstClassValue) val).className();
+ String className = ((ConstTurbineClassValue) val).className();
return new ClassSymbol(className.substring(1, className.length() - 1));
default:
break;
diff --git a/java/com/google/turbine/binder/lookup/ImportIndex.java b/java/com/google/turbine/binder/lookup/ImportIndex.java
index f28d905..afa985a 100644
--- a/java/com/google/turbine/binder/lookup/ImportIndex.java
+++ b/java/com/google/turbine/binder/lookup/ImportIndex.java
@@ -105,7 +105,10 @@ public class ImportIndex implements ImportScope {
}
ClassSymbol sym = (ClassSymbol) result.sym();
for (Tree.Ident bit : result.remaining()) {
- sym = resolveNext(log, i.position(), resolve, sym, bit);
+ sym = resolveNext(log, resolve, sym, bit);
+ if (sym == null) {
+ return null;
+ }
}
ClassSymbol resolved = sym;
return new ImportScope() {
@@ -117,15 +120,13 @@ public class ImportIndex implements ImportScope {
}
private static ClassSymbol resolveNext(
- TurbineLogWithSource log,
- int position,
- CanonicalSymbolResolver resolve,
- ClassSymbol sym,
- Ident bit) {
+ TurbineLogWithSource log, CanonicalSymbolResolver resolve, ClassSymbol sym, Ident bit) {
ClassSymbol next = resolve.resolveOne(sym, bit);
if (next == null) {
log.error(
- position, ErrorKind.SYMBOL_NOT_FOUND, new ClassSymbol(sym.binaryName() + '$' + bit));
+ bit.position(),
+ ErrorKind.SYMBOL_NOT_FOUND,
+ new ClassSymbol(sym.binaryName() + '$' + bit));
}
return next;
}
diff --git a/java/com/google/turbine/binder/lookup/LookupResult.java b/java/com/google/turbine/binder/lookup/LookupResult.java
index 7e0f737..8340386 100644
--- a/java/com/google/turbine/binder/lookup/LookupResult.java
+++ b/java/com/google/turbine/binder/lookup/LookupResult.java
@@ -16,6 +16,8 @@
package com.google.turbine.binder.lookup;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.Immutable;
import com.google.turbine.binder.sym.ClassSymbol;
@@ -45,7 +47,7 @@ public class LookupResult {
private final ImmutableList<Tree.Ident> remaining;
public LookupResult(Symbol sym, LookupKey remaining) {
- this.sym = sym;
+ this.sym = requireNonNull(sym);
this.remaining = remaining.hasNext() ? remaining.rest().simpleNames() : ImmutableList.of();
}
}
diff --git a/java/com/google/turbine/binder/lookup/WildImportIndex.java b/java/com/google/turbine/binder/lookup/WildImportIndex.java
index 043ccc5..cfe58c7 100644
--- a/java/com/google/turbine/binder/lookup/WildImportIndex.java
+++ b/java/com/google/turbine/binder/lookup/WildImportIndex.java
@@ -67,9 +67,7 @@ public class WildImportIndex implements ImportScope {
/** Full resolve the type for a non-static on-demand import. */
private static ImportScope onDemandImport(
- TopLevelIndex cpi,
- ImportDecl i,
- final CanonicalSymbolResolver importResolver) {
+ TopLevelIndex cpi, ImportDecl i, final CanonicalSymbolResolver importResolver) {
ImmutableList.Builder<String> flatNames = ImmutableList.builder();
for (Tree.Ident ident : i.type()) {
flatNames.add(ident.value());
@@ -106,9 +104,7 @@ public class WildImportIndex implements ImportScope {
* deferred).
*/
private static ImportScope staticOnDemandImport(
- TopLevelIndex cpi,
- ImportDecl i,
- final CanonicalSymbolResolver importResolver) {
+ TopLevelIndex cpi, ImportDecl i, final CanonicalSymbolResolver importResolver) {
LookupResult result = cpi.scope().lookup(new LookupKey(i.type()));
if (result == null) {
return null;
@@ -141,9 +137,7 @@ public class WildImportIndex implements ImportScope {
}
static ClassSymbol resolveImportBase(
- LookupResult result,
- ResolveFunction resolve,
- CanonicalSymbolResolver importResolver) {
+ LookupResult result, ResolveFunction resolve, CanonicalSymbolResolver importResolver) {
ClassSymbol member = (ClassSymbol) result.sym();
for (Tree.Ident bit : result.remaining()) {
member = resolve.resolveOne(member, bit);
diff --git a/java/com/google/turbine/bytecode/AnnotationWriter.java b/java/com/google/turbine/bytecode/AnnotationWriter.java
index b52cc5e..868b548 100644
--- a/java/com/google/turbine/bytecode/AnnotationWriter.java
+++ b/java/com/google/turbine/bytecode/AnnotationWriter.java
@@ -22,7 +22,7 @@ import com.google.turbine.bytecode.ClassFile.AnnotationInfo;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.AnnotationValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ArrayValue;
-import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue;
+import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue;
import com.google.turbine.bytecode.ClassFile.TypeAnnotationInfo;
@@ -65,7 +65,7 @@ public class AnnotationWriter {
writeEnumElementValue((EnumConstValue) value);
break;
case CLASS:
- writeClassElementValue((ConstClassValue) value);
+ writeClassElementValue((ConstTurbineClassValue) value);
break;
case ARRAY:
writeArrayElementValue((ArrayValue) value);
@@ -123,7 +123,7 @@ public class AnnotationWriter {
output.writeShort(pool.utf8(value.constName()));
}
- private void writeClassElementValue(ConstClassValue value) {
+ private void writeClassElementValue(ConstTurbineClassValue value) {
output.writeByte('c');
output.writeShort(pool.utf8(value.className()));
}
diff --git a/java/com/google/turbine/bytecode/ClassFile.java b/java/com/google/turbine/bytecode/ClassFile.java
index 502e295..422f8c6 100644
--- a/java/com/google/turbine/bytecode/ClassFile.java
+++ b/java/com/google/turbine/bytecode/ClassFile.java
@@ -450,11 +450,11 @@ public class ClassFile {
}
/** A constant class literal value. */
- class ConstClassValue implements ElementValue {
+ class ConstTurbineClassValue implements ElementValue {
private final String className;
- public ConstClassValue(String className) {
+ public ConstTurbineClassValue(String className) {
this.className = className;
}
diff --git a/java/com/google/turbine/bytecode/ClassReader.java b/java/com/google/turbine/bytecode/ClassReader.java
index 0070527..dc5e050 100644
--- a/java/com/google/turbine/bytecode/ClassReader.java
+++ b/java/com/google/turbine/bytecode/ClassReader.java
@@ -22,7 +22,7 @@ import com.google.errorprone.annotations.CheckReturnValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.AnnotationValue;
-import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue;
+import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstValue;
import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue;
import com.google.turbine.bytecode.ClassFile.MethodInfo.ParameterInfo;
@@ -34,7 +34,6 @@ import com.google.turbine.bytecode.ClassFile.ModuleInfo.RequireInfo;
import com.google.turbine.bytecode.ClassFile.ModuleInfo.UseInfo;
import com.google.turbine.model.Const;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
@@ -101,7 +100,7 @@ public class ClassReader {
List<ClassFile.MethodInfo> methodinfos = readMethods(constantPool);
String signature = null;
- List<ClassFile.InnerClass> innerclasses = Collections.emptyList();
+ List<ClassFile.InnerClass> innerclasses = ImmutableList.of();
ImmutableList.Builder<ClassFile.AnnotationInfo> annotations = ImmutableList.builder();
ClassFile.ModuleInfo module = null;
int attributesCount = reader.u2();
@@ -346,7 +345,7 @@ public class ClassReader {
{
int classInfoIndex = reader.u2();
String className = constantPool.utf8(classInfoIndex);
- return new ConstClassValue(className);
+ return new ConstTurbineClassValue(className);
}
case '@':
return new AnnotationValue(readAnnotation(constantPool));
diff --git a/java/com/google/turbine/diag/TurbineError.java b/java/com/google/turbine/diag/TurbineError.java
index e13eb44..b8b2a54 100644
--- a/java/com/google/turbine/diag/TurbineError.java
+++ b/java/com/google/turbine/diag/TurbineError.java
@@ -30,6 +30,7 @@ public class TurbineError extends Error {
UNEXPECTED_EOF("unexpected end of input"),
UNTERMINATED_STRING("unterminated string literal"),
UNTERMINATED_CHARACTER_LITERAL("unterminated char literal"),
+ UNTERMINATED_EXPRESSION("unterminated expression, expected ';' not found"),
EMPTY_CHARACTER_LITERAL("empty char literal"),
EXPECTED_TOKEN("expected token %s"),
INVALID_LITERAL("invalid literal: %s"),
diff --git a/java/com/google/turbine/lower/Lower.java b/java/com/google/turbine/lower/Lower.java
index 99b5627..97fbd6e 100644
--- a/java/com/google/turbine/lower/Lower.java
+++ b/java/com/google/turbine/lower/Lower.java
@@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.turbine.binder.bound.AnnotationValue;
-import com.google.turbine.binder.bound.ClassValue;
import com.google.turbine.binder.bound.EnumConstantValue;
import com.google.turbine.binder.bound.ModuleInfo.ExportInfo;
import com.google.turbine.binder.bound.ModuleInfo.OpenInfo;
@@ -34,6 +33,7 @@ import com.google.turbine.binder.bound.ModuleInfo.RequireInfo;
import com.google.turbine.binder.bound.ModuleInfo.UseInfo;
import com.google.turbine.binder.bound.SourceModuleInfo;
import com.google.turbine.binder.bound.SourceTypeBoundClass;
+import com.google.turbine.binder.bound.TurbineClassValue;
import com.google.turbine.binder.bound.TypeBoundClass;
import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo;
import com.google.turbine.binder.bound.TypeBoundClass.MethodInfo;
@@ -79,7 +79,6 @@ import com.google.turbine.types.Erasure;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayDeque;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Deque;
import java.util.LinkedHashSet;
import java.util.List;
@@ -373,7 +372,7 @@ public class Lower {
private ClassFile.FieldInfo lowerField(FieldInfo f) {
final String name = f.name();
- Function<TyVarSymbol, TyVarInfo> tenv = new TyVarEnv(Collections.emptyMap());
+ Function<TyVarSymbol, TyVarInfo> tenv = new TyVarEnv(ImmutableMap.of());
String desc = SigWriter.type(sig.signature(Erasure.erase(f.type(), tenv)));
String signature = sig.fieldSignature(f.type());
@@ -543,8 +542,9 @@ public class Lower {
switch (value.kind()) {
case CLASS_LITERAL:
{
- ClassValue classValue = (ClassValue) value;
- return new ElementValue.ConstClassValue(SigWriter.type(sig.signature(classValue.type())));
+ TurbineClassValue classValue = (TurbineClassValue) value;
+ return new ElementValue.ConstTurbineClassValue(
+ SigWriter.type(sig.signature(classValue.type())));
}
case ENUM_CONSTANT:
{
diff --git a/java/com/google/turbine/main/Main.java b/java/com/google/turbine/main/Main.java
index 03a68ce..34421e1 100644
--- a/java/com/google/turbine/main/Main.java
+++ b/java/com/google/turbine/main/Main.java
@@ -16,10 +16,12 @@
package com.google.turbine.main;
+import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
+import com.google.common.io.MoreFiles;
import com.google.turbine.binder.Binder;
import com.google.turbine.binder.Binder.BindingResult;
import com.google.turbine.binder.ClassPath;
@@ -145,7 +147,7 @@ public class Main {
if (options.release().isPresent()) {
String release = options.release().get();
- if (release.equals(System.getProperty("java.specification.version"))) {
+ if (release.equals(JAVA_SPECIFICATION_VERSION.value())) {
// if --release matches the host JDK, use its jimage instead of ct.sym
return JimageClassBinder.bindDefault();
}
@@ -172,7 +174,7 @@ public class Main {
ImmutableList.Builder<CompUnit> units = ImmutableList.builder();
for (String source : options.sources()) {
Path path = Paths.get(source);
- units.add(Parser.parse(new SourceFile(source, new String(Files.readAllBytes(path), UTF_8))));
+ units.add(Parser.parse(new SourceFile(source, MoreFiles.asCharSource(path, UTF_8).read())));
}
for (String sourceJar : options.sourceJars()) {
for (Zip.Entry ze : new Zip.ZipIterable(Paths.get(sourceJar))) {
diff --git a/java/com/google/turbine/options/TurbineOptionsParser.java b/java/com/google/turbine/options/TurbineOptionsParser.java
index 2976285..5b1f326 100644
--- a/java/com/google/turbine/options/TurbineOptionsParser.java
+++ b/java/com/google/turbine/options/TurbineOptionsParser.java
@@ -16,6 +16,7 @@
package com.google.turbine.options;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.CharMatcher;
@@ -116,6 +117,12 @@ public class TurbineOptionsParser {
case "--nojavac_fallback":
builder.setJavacFallback(false);
break;
+ case "--reduce_classpath":
+ builder.setShouldReduceClassPath(true);
+ break;
+ case "--noreduce_classpath":
+ builder.setShouldReduceClassPath(false);
+ break;
case "--help":
builder.setHelp(true);
break;
@@ -138,6 +145,13 @@ public class TurbineOptionsParser {
if (arg.isEmpty()) {
continue;
}
+ if (arg.charAt(0) == '\'') {
+ // perform best-effort unescaping as a concession to ninja, see:
+ // https://android.googlesource.com/platform/external/ninja/+/6f903faaf5488dc052ffc4e3e0b12757b426e088/src/util.cc#274
+ checkArgument(arg.charAt(arg.length() - 1) == '\'', arg);
+ arg = arg.substring(1, arg.length() - 1);
+ checkArgument(!arg.contains("'"), arg);
+ }
if (arg.startsWith("@@")) {
argumentDeque.addLast(arg.substring(1));
} else if (arg.startsWith("@")) {
diff --git a/java/com/google/turbine/parse/Parser.java b/java/com/google/turbine/parse/Parser.java
index ba76659..dd45b0d 100644
--- a/java/com/google/turbine/parse/Parser.java
+++ b/java/com/google/turbine/parse/Parser.java
@@ -20,6 +20,7 @@ import static com.google.turbine.parse.Token.COMMA;
import static com.google.turbine.parse.Token.INTERFACE;
import static com.google.turbine.parse.Token.LPAREN;
import static com.google.turbine.parse.Token.RPAREN;
+import static com.google.turbine.parse.Token.SEMI;
import static com.google.turbine.tree.TurbineModifier.PROTECTED;
import static com.google.turbine.tree.TurbineModifier.PUBLIC;
@@ -812,6 +813,7 @@ public class Parser {
token = initializerParser.token;
boolean first = true;
+ int expressionStart = pos;
for (List<SavedToken> bit : bits) {
IteratorLexer lexer = new IteratorLexer(this.lexer.source(), bit.iterator());
Parser parser = new Parser(lexer);
@@ -823,12 +825,17 @@ public class Parser {
Type ty = baseTy;
ty = parser.extraDims(ty);
// TODO(cushon): skip more fields that are definitely non-const
- Expression init = new ConstExpressionParser(lexer, lexer.next()).expression();
+ ConstExpressionParser constExpressionParser = new ConstExpressionParser(lexer, lexer.next());
+ expressionStart = lexer.position();
+ Expression init = constExpressionParser.expression();
if (init != null && init.kind() == Tree.Kind.ARRAY_INIT) {
init = null;
}
result.add(new VarDecl(pos, access, annos, ty, name, Optional.ofNullable(init)));
}
+ if (token != SEMI) {
+ throw TurbineError.format(lexer.source(), expressionStart, ErrorKind.UNTERMINATED_EXPRESSION);
+ }
eat(Token.SEMI);
return result.build();
}
diff --git a/java/com/google/turbine/type/Type.java b/java/com/google/turbine/type/Type.java
index 3bf47d6..8950ec0 100644
--- a/java/com/google/turbine/type/Type.java
+++ b/java/com/google/turbine/type/Type.java
@@ -19,6 +19,7 @@ package com.google.turbine.type;
import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.binder.sym.TyVarSymbol;
import com.google.turbine.model.TurbineConstantTypeKind;
@@ -100,7 +101,7 @@ public interface Type {
/** The class symbol. */
public ClassSymbol sym() {
- return classes().get(classes().size() - 1).sym();
+ return Iterables.getLast(classes()).sym();
}
@Override
diff --git a/java/com/google/turbine/types/Canonicalize.java b/java/com/google/turbine/types/Canonicalize.java
index d3328b7..a8861da 100644
--- a/java/com/google/turbine/types/Canonicalize.java
+++ b/java/com/google/turbine/types/Canonicalize.java
@@ -157,7 +157,7 @@ public class Canonicalize {
private Collection<ClassTy.SimpleClassTy> lexicalBase(ClassSymbol first, ClassSymbol owner) {
if ((getInfo(first).access() & TurbineFlag.ACC_STATIC) == TurbineFlag.ACC_STATIC) {
- return Collections.emptyList();
+ return ImmutableList.of();
}
ClassSymbol canonOwner = getInfo(first).owner();
Deque<ClassTy.SimpleClassTy> result = new ArrayDeque<>();