diff options
author | 2016-07-28 15:01:26 +0000 | |
---|---|---|
committer | 2016-07-29 10:09:37 +0000 | |
commit | ee8b7aaff277b913d50f3083768564c1d7124c87 (patch) | |
tree | e937f445fe5bdf1d68eb4afa5cd6894abfdb51f2 /src/main/java | |
parent | 36dbde86be67d3e43e0691c772e52542a31284e3 (diff) |
Fix private symbols, clean up load parsing
--
MOS_MIGRATED_REVID=128699330
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java | 11 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Parser.java | 12 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java index 2bc348a110..b1e6c1579a 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/LoadStatement.java @@ -72,15 +72,16 @@ public final class LoadStatement extends Statement { void doExec(Environment env) throws EvalException, InterruptedException { for (Map.Entry<Identifier, String> entry : symbols.entrySet()) { try { - Identifier current = entry.getKey(); + Identifier name = entry.getKey(); + Identifier declared = new Identifier(entry.getValue()); - if (current.isPrivate()) { - throw new EvalException( - getLocation(), "symbol '" + current + "' is private and cannot be imported."); + if (declared.isPrivate()) { + throw new EvalException(getLocation(), + "symbol '" + declared.getName() + "' is private and cannot be imported."); } // The key is the original name that was used to define the symbol // in the loaded bzl file. - env.importSymbol(imp.getImportString(), current, entry.getValue()); + env.importSymbol(imp.getImportString(), name, declared.getName()); } catch (Environment.NoSuchVariableException | Environment.LoadFailedException e) { throw new EvalException(getLocation(), e.getMessage()); } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java index a5ca8bdb9a..dbc16cdfa5 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java @@ -1089,9 +1089,9 @@ public class Parser { * Parses the next symbol argument of a load statement and puts it into the output map. * * <p> The symbol is either "name" (STRING) or name = "declared" (IDENTIFIER EQUALS STRING). - * "Declared" refers to the original name in the bazel file that should be loaded. - * Moreover, it will be the key of the entry in the map. - * If no alias is used, "name" and "declared" will be identical. + * If no alias is used, "name" and "declared" will be identical. "Declared" refers to the + * original name in the Bazel file that should be loaded, while "name" will be the key of the + * entry in the map. */ private void parseLoadSymbol(Map<Identifier, String> symbols) { Token nameToken, declaredToken; @@ -1119,10 +1119,12 @@ public class Parser { if (symbols.containsKey(identifier)) { syntaxError( - nameToken, String.format("Symbol '%s' has already been loaded", identifier.getName())); + nameToken, String.format("Identifier '%s' is used more than once", + identifier.getName())); } else { symbols.put( - setLocation(identifier, nameToken.left, token.left), declaredToken.value.toString()); + setLocation(identifier, nameToken.left, nameToken.right), + declaredToken.value.toString()); } } catch (NullPointerException npe) { // This means that the value of at least one token is null. In this case, the previous |