aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar laurentlb <laurentlb@google.com>2017-08-07 20:03:40 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-08-08 13:02:24 +0200
commit04b4c66dacdc84a3452db21a2a011a75fa0b7f86 (patch)
tree162627efad51b2a8c2b943484ebd36e6d7ae756c /src/main/java/com
parent59c16f6a2730a45d47546b6c69c3f4f5ba152db9 (diff)
Improve SyntaxTreeVisitor API.
RELNOTES: None. PiperOrigin-RevId: 164481927
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Parameter.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitor.java12
3 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
index 2d2b50ec60..2ba51d7234 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
@@ -301,6 +301,11 @@ public class BuildFileAST extends ASTNode {
HashCode.fromBytes(file.getDigest()).toString(), eventHandler);
}
+ public static BuildFileAST parseSkylarkFile(ParserInputSource input, EventHandler eventHandler) {
+ Parser.ParseResult result = Parser.parseFile(input, eventHandler, SKYLARK);
+ return create(ImmutableList.<Statement>of(), result, /*contentHashCode=*/ null, eventHandler);
+ }
+
/**
* Parse the specified non-build Skylark file but avoid the validation of the imports, returning
* its AST. All errors during scanning or parsing will be reported to the reporter.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parameter.java b/src/main/java/com/google/devtools/build/lib/syntax/Parameter.java
index 29e122c02d..e16fe585b0 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Parameter.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Parameter.java
@@ -199,6 +199,6 @@ public abstract class Parameter<V, T> extends Argument {
@Override
public void accept(SyntaxTreeVisitor visitor) {
- visitor.visit(this);
+ visitor.visit((Parameter<Expression, Expression>) this);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitor.java b/src/main/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitor.java
index 8229e393e5..c086fe3220 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitor.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitor.java
@@ -39,8 +39,10 @@ public class SyntaxTreeVisitor {
visit(node.getValue());
}
- public void visit(@SuppressWarnings("unused") Parameter<?, ?> node) {
- // leaf node (we need the function for overrides)
+ public void visit(Parameter<Expression, Expression> node) {
+ if (node.getDefaultValue() != null) {
+ visit(node.getDefaultValue());
+ }
}
public void visit(BuildFileAST node) {
@@ -122,7 +124,11 @@ public class SyntaxTreeVisitor {
public void visit(FunctionDefStatement node) {
visit(node.getIdentifier());
- visitAll(node.getParameters());
+ // Do not use visitAll for the parameters, because we would lose the type information.
+ // Inside the AST, we know that Parameters are using Expressions.
+ for (Parameter<Expression, Expression> param : node.getParameters()) {
+ visit(param);
+ }
visitAll(node.getStatements());
}