diff options
author | cushon <cushon@google.com> | 2017-04-07 16:41:58 -0700 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2017-11-17 20:30:34 -0800 |
commit | f1851ae7e5988e992ae643d8635439398f806247 (patch) | |
tree | 0e53f13c3e4347cac6a8c2f67e9328ef4a7fd4ec /java/com/google/turbine/parse/Parser.java | |
parent | 28fc0ccb690cad787da840572c73fd3e3311047d (diff) | |
download | turbine-f1851ae7e5988e992ae643d8635439398f806247.tar.gz |
Don't crash on duplicate field declarations
MOE_MIGRATED_REVID=173969409
Diffstat (limited to 'java/com/google/turbine/parse/Parser.java')
-rw-r--r-- | java/com/google/turbine/parse/Parser.java | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/java/com/google/turbine/parse/Parser.java b/java/com/google/turbine/parse/Parser.java index 1ec8a38..88529de 100644 --- a/java/com/google/turbine/parse/Parser.java +++ b/java/com/google/turbine/parse/Parser.java @@ -481,8 +481,9 @@ public class Parser { { result = new Tree.VoidTy(position); next(); + int pos = position; name = eatIdent(); - return memberRest(access, annos, typaram, result, name); + return memberRest(pos, access, annos, typaram, result, name); } case BOOLEAN: case BYTE: @@ -494,17 +495,19 @@ public class Parser { case FLOAT: { result = referenceType(ImmutableList.of()); + int pos = position; name = eatIdent(); - return memberRest(access, annos, typaram, result, name); + return memberRest(pos, access, annos, typaram, result, name); } case IDENT: { + int pos = position; String ident = eatIdent(); switch (token) { case LPAREN: { name = ident; - return ImmutableList.of(methodRest(access, annos, typaram, null, name)); + return ImmutableList.of(methodRest(pos, access, annos, typaram, null, name)); } case IDENT: { @@ -515,8 +518,9 @@ public class Parser { ident, ImmutableList.<Type>of(), ImmutableList.of()); + pos = position; name = eatIdent(); - return memberRest(access, annos, typaram, result, name); + return memberRest(pos, access, annos, typaram, result, name); } case AT: case LBRACK: @@ -560,10 +564,11 @@ public class Parser { result = classty((ClassTy) result); } result = maybeDims(maybeAnnos(), result); + pos = position; name = eatIdent(); switch (token) { case LPAREN: - return ImmutableList.of(methodRest(access, annos, typaram, result, name)); + return ImmutableList.of(methodRest(pos, access, annos, typaram, result, name)); case LBRACK: case SEMI: case ASSIGN: @@ -572,7 +577,7 @@ public class Parser { if (!typaram.isEmpty()) { throw error(ErrorKind.UNEXPECTED_TYPE_PARAMETER, typaram); } - return fieldRest(access, annos, result, name); + return fieldRest(pos, access, annos, result, name); } default: throw error(token); @@ -596,6 +601,7 @@ public class Parser { } private ImmutableList<Tree> memberRest( + int pos, EnumSet<TurbineModifier> access, ImmutableList<Anno> annos, ImmutableList<TyParam> typaram, @@ -610,17 +616,21 @@ public class Parser { if (!typaram.isEmpty()) { throw error(ErrorKind.UNEXPECTED_TYPE_PARAMETER, typaram); } - return fieldRest(access, annos, result, name); + return fieldRest(pos, access, annos, result, name); } case LPAREN: - return ImmutableList.of(methodRest(access, annos, typaram, result, name)); + return ImmutableList.of(methodRest(pos, access, annos, typaram, result, name)); default: throw error(token); } } private ImmutableList<Tree> fieldRest( - EnumSet<TurbineModifier> access, ImmutableList<Anno> annos, Type baseTy, String name) { + int pos, + EnumSet<TurbineModifier> access, + ImmutableList<Anno> annos, + Type baseTy, + String name) { ImmutableList.Builder<Tree> result = ImmutableList.builder(); VariableInitializerParser initializerParser = new VariableInitializerParser(token, lexer); List<List<SavedToken>> bits = initializerParser.parseInitializers(); @@ -642,13 +652,14 @@ public class Parser { if (init != null && init.kind() == Tree.Kind.ARRAY_INIT) { init = null; } - result.add(new VarDecl(position, access, annos, ty, name, Optional.fromNullable(init))); + result.add(new VarDecl(pos, access, annos, ty, name, Optional.fromNullable(init))); } eat(Token.SEMI); return result.build(); } private Tree methodRest( + int pos, EnumSet<TurbineModifier> access, ImmutableList<Anno> annos, ImmutableList<TyParam> typaram, @@ -697,7 +708,7 @@ public class Parser { name = CTOR_NAME; } return new MethDecl( - position, + pos, access, annos, typaram, |