diff options
author | 2016-08-04 10:22:16 +0000 | |
---|---|---|
committer | 2016-08-04 10:35:48 +0000 | |
commit | 8c8857d21cd9a69d9c24155a7f36d4c74c27ce56 (patch) | |
tree | a463b92f221cdf2c02c90841701772a6e4b017d8 /src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java | |
parent | 43e22c4e466c39234979e90e7897bdc63607fc06 (diff) |
Remove static checks from the parser.
--
MOS_MIGRATED_REVID=129313959
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java | 41 |
1 files changed, 27 insertions, 14 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 c544c08ef8..aa83dbc975 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 @@ -62,11 +62,12 @@ public class BuildFileAST extends ASTNode { ImmutableList<Statement> stmts, boolean containsErrors, String contentHashCode, - Location location) { + Location location, + ImmutableList<Comment> comments) { this.stmts = stmts; this.containsErrors = containsErrors; this.contentHashCode = contentHashCode; - this.comments = ImmutableList.of(); + this.comments = comments; this.setLocation(location); } @@ -79,7 +80,8 @@ public class BuildFileAST extends ASTNode { stmts.subList(firstStatement, lastStatement), containsErrors, null, - stmts.get(firstStatement).getLocation()); + stmts.get(firstStatement).getLocation(), + ImmutableList.of()); } /** Collects all load statements */ @@ -213,26 +215,37 @@ public class BuildFileAST extends ASTNode { } /** - * Parse the specified Skylark file, returning its AST. All errors during - * scanning or parsing will be reported to the reporter. + * Parse the specified Skylark file, returning its AST. All errors during scanning or parsing will + * be reported to the reporter. * * @throws IOException if the file cannot not be read. */ - public static BuildFileAST parseSkylarkFile(Path file, EventHandler eventHandler, - ValidationEnvironment validationEnvironment) throws IOException { - return parseSkylarkFile(file, file.getFileSize(), eventHandler, - validationEnvironment); + public static BuildFileAST parseSkylarkFile(Path file, EventHandler eventHandler) + throws IOException { + return parseSkylarkFile(file, file.getFileSize(), eventHandler); } - public static BuildFileAST parseSkylarkFile(Path file, long fileSize, EventHandler eventHandler, - ValidationEnvironment validationEnvironment) throws IOException { + public static BuildFileAST parseSkylarkFile(Path file, long fileSize, EventHandler eventHandler) + throws IOException { ParserInputSource input = ParserInputSource.create(file, fileSize); - Parser.ParseResult result = - Parser.parseFileForSkylark(input, eventHandler, validationEnvironment); + Parser.ParseResult result = Parser.parseFileForSkylark(input, eventHandler); return new BuildFileAST(ImmutableList.<Statement>of(), result, HashCode.fromBytes(file.getMD5Digest()).toString()); } + /** + * Run static checks on the AST. + * + * @return a new AST (or the same), with the containsErrors flag updated. + */ + public BuildFileAST validate(ValidationEnvironment validationEnv, EventHandler eventHandler) { + boolean valid = validationEnv.validateAst(stmts, eventHandler); + if (valid || containsErrors) { + return this; + } + return new BuildFileAST(stmts, true, contentHashCode, getLocation(), comments); + } + public static BuildFileAST parseBuildString(EventHandler eventHandler, String... content) { String str = Joiner.on("\n").join(content); ParserInputSource input = ParserInputSource.create(str, null); @@ -244,7 +257,7 @@ public class BuildFileAST extends ASTNode { public static BuildFileAST parseSkylarkString(EventHandler eventHandler, String... content) { String str = Joiner.on("\n").join(content); ParserInputSource input = ParserInputSource.create(str, null); - Parser.ParseResult result = Parser.parseFileForSkylark(input, eventHandler, null); + Parser.ParseResult result = Parser.parseFileForSkylark(input, eventHandler); return new BuildFileAST(ImmutableList.<Statement>of(), result, null); } |