bazel syntax: rename BuildFileAST -> StarlarkFile This change was 100% mechanical, thanks to the distinctive name. We do not attempt to rename local variables. Another breaking API change for copybara. PiperOrigin-RevId: 271351606
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AstParseResult.java b/src/main/java/com/google/devtools/build/lib/packages/AstParseResult.java index 08d6bb2..fc0cd9b 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/AstParseResult.java +++ b/src/main/java/com/google/devtools/build/lib/packages/AstParseResult.java
@@ -16,15 +16,15 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable; import com.google.devtools.build.lib.events.StoredEventHandler; -import com.google.devtools.build.lib.syntax.BuildFileAST; +import com.google.devtools.build.lib.syntax.StarlarkFile; /** The result of parsing a BUILD file. */ public class AstParseResult { - public final BuildFileAST ast; + public final StarlarkFile ast; public final Iterable<Event> allEvents; public final Iterable<Postable> allPosts; - public AstParseResult(BuildFileAST ast, StoredEventHandler astParsingEventHandler) { + public AstParseResult(StarlarkFile ast, StoredEventHandler astParsingEventHandler) { this.ast = ast; this.allPosts = astParsingEventHandler.getPosts(); this.allEvents = astParsingEventHandler.getEvents();
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java index 56124b8..3ea6144 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
@@ -43,7 +43,6 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.build.lib.syntax.Argument; import com.google.devtools.build.lib.syntax.BaseFunction; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.BuiltinFunction; import com.google.devtools.build.lib.syntax.CallUtils; import com.google.devtools.build.lib.syntax.ClassObject; @@ -69,6 +68,7 @@ import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor; import com.google.devtools.build.lib.syntax.SkylarkUtils; import com.google.devtools.build.lib.syntax.SkylarkUtils.Phase; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread; import com.google.devtools.build.lib.syntax.StarlarkThread.Extension; @@ -1373,12 +1373,8 @@ StoredEventHandler localReporterForParsing = new StoredEventHandler(); // Run the lexer and parser with a local reporter, so that errors from other threads do not // show up below. - BuildFileAST buildFileAST = - parseBuildFile( - packageId, - input, - preludeStatements, - localReporterForParsing); + StarlarkFile buildFileAST = + parseBuildFile(packageId, input, preludeStatements, localReporterForParsing); AstParseResult astParseResult = new AstParseResult(buildFileAST, localReporterForParsing); return createPackageFromAst( @@ -1394,15 +1390,15 @@ globber); } - public static BuildFileAST parseBuildFile( + public static StarlarkFile parseBuildFile( PackageIdentifier packageId, ParserInput input, List<Statement> preludeStatements, ExtendedEventHandler eventHandler) { // Logged messages are used as a testability hook tracing the parsing progress logger.fine("Starting to parse " + packageId); - BuildFileAST buildFileAST = - BuildFileAST.parseWithPrelude(input, preludeStatements, eventHandler); + StarlarkFile buildFileAST = + StarlarkFile.parseWithPrelude(input, preludeStatements, eventHandler); logger.fine("Finished parsing of " + packageId); return buildFileAST; } @@ -1722,7 +1718,7 @@ public Package.Builder evaluateBuildFile( String workspaceName, PackageIdentifier packageId, - BuildFileAST file, + StarlarkFile file, RootedPath buildFilePath, Globber globber, Iterable<Event> pastEvents, @@ -1925,7 +1921,7 @@ // files. // TODO(adonovan): this is the ideal place to extract string literals from glob calls for // prefetching. Combine. - public static boolean checkBuildSyntax(BuildFileAST file, final EventHandler eventHandler) { + public static boolean checkBuildSyntax(StarlarkFile file, final EventHandler eventHandler) { final boolean[] success = {true}; NodeVisitor checker = new NodeVisitor() {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java index 230abe9..dc59b49 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
@@ -29,7 +29,6 @@ import com.google.devtools.build.lib.packages.Package.NameConflictException; import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension; import com.google.devtools.build.lib.syntax.BaseFunction; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.BuiltinFunction; import com.google.devtools.build.lib.syntax.CallUtils; import com.google.devtools.build.lib.syntax.ClassObject; @@ -41,6 +40,7 @@ import com.google.devtools.build.lib.syntax.Runtime; import com.google.devtools.build.lib.syntax.SkylarkUtils; import com.google.devtools.build.lib.syntax.SkylarkUtils.Phase; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread; import com.google.devtools.build.lib.syntax.StarlarkThread.Extension; @@ -134,7 +134,7 @@ if (localReporter == null) { localReporter = new StoredEventHandler(); } - BuildFileAST buildFileAST = BuildFileAST.parse(source, localReporter); + StarlarkFile buildFileAST = StarlarkFile.parse(source, localReporter); if (buildFileAST.containsErrors()) { throw new BuildFileContainsErrorsException( LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER, "Failed to parse " + source.getPath()); @@ -153,7 +153,7 @@ * the //external package. */ public void execute( - BuildFileAST file, + StarlarkFile file, Map<String, Extension> importedExtensions, StarlarkSemantics starlarkSemantics, WorkspaceFileValue.WorkspaceFileKey workspaceFileKey) @@ -165,7 +165,7 @@ } private void execute( - BuildFileAST file, + StarlarkFile file, @Nullable Map<String, Extension> importedExtensions, StarlarkSemantics starlarkSemantics, StoredEventHandler localReporter,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/ResolvedFileFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/ResolvedFileFunction.java index f2e2f8f..ec711e8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/ResolvedFileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/ResolvedFileFunction.java
@@ -23,9 +23,9 @@ import com.google.devtools.build.lib.packages.NoSuchThingException; import com.google.devtools.build.lib.rules.repository.ResolvedFileValue.ResolvedFileKey; import com.google.devtools.build.lib.skyframe.PrecomputedValue; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.Mutability; import com.google.devtools.build.lib.syntax.ParserInput; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread; import com.google.devtools.build.lib.vfs.FileSystemUtils; @@ -63,8 +63,8 @@ byte[] bytes = FileSystemUtils.readWithKnownFileSize( key.getPath().asPath(), key.getPath().asPath().getFileSize()); - BuildFileAST ast = - BuildFileAST.parse( + StarlarkFile ast = + StarlarkFile.parse( ParserInput.create(bytes, key.getPath().asPath().asFragment()), env.getListener()); if (ast.containsErrors()) { throw new ResolvedFileFunctionException(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java index d065bfd..5cb106c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
@@ -20,9 +20,9 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.packages.RuleClassProvider; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.Mutability; import com.google.devtools.build.lib.syntax.ParserInput; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread; import com.google.devtools.build.lib.vfs.FileSystemUtils; @@ -41,10 +41,10 @@ /** * A SkyFunction for {@link ASTFileLookupValue}s. * - * <p> Given a {@link Label} referencing a Skylark file, loads it as a syntax tree - * ({@link BuildFileAST}). The Label must be absolute, and must not reference the special - * {@code external} package. If the file (or the package containing it) doesn't exist, the - * function doesn't fail, but instead returns a specific {@code NO_FILE} {@link ASTFileLookupValue}. + * <p>Given a {@link Label} referencing a Skylark file, loads it as a syntax tree ({@link + * StarlarkFile}). The Label must be absolute, and must not reference the special {@code external} + * package. If the file (or the package containing it) doesn't exist, the function doesn't fail, but + * instead returns a specific {@code NO_FILE} {@link ASTFileLookupValue}. */ public class ASTFileLookupFunction implements SkyFunction { @@ -110,7 +110,7 @@ } // Both the package and the file exist; load the file and parse it as an AST. - BuildFileAST file = null; + StarlarkFile file = null; Path path = rootedPath.asPath(); try { long astFileSize = fileValue.getSize(); @@ -127,7 +127,7 @@ /*repoMapping=*/ ImmutableMap.of()); byte[] bytes = FileSystemUtils.readWithKnownFileSize(path, astFileSize); ParserInput input = ParserInput.create(bytes, path.asFragment()); - file = BuildFileAST.parseWithDigest(input, path.getDigest(), env.getListener()); + file = StarlarkFile.parseWithDigest(input, path.getDigest(), env.getListener()); file = file.validate(thread, /*isBuildFile=*/ false, env.getListener()); } } catch (IOException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java index 7f38607..7104882 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupValue.java
@@ -19,7 +19,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.syntax.BuildFileAST; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.NotComparableSkyValue; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -33,23 +33,25 @@ // almost certainly be unequal to the previous value. This is because of (i) the change-pruning // semantics of the PackageLookupValue dep and the FileValue dep; consider the latter: if the // FileValue for the bzl file has changed, then the contents of the bzl file probably changed and -// (ii) we don't currently have skylark-semantic-equality in BuildFileAST, so two BuildFileAST +// (ii) we don't currently have skylark-semantic-equality in StarlarkFile, so two StarlarkFile // instances representing two different contents of a bzl file will be different. // TODO(bazel-team): Consider doing better here. As a pre-req, we would need -// skylark-semantic-equality in BuildFileAST, rather than equality naively based on the contents of +// skylark-semantic-equality in StarlarkFile, rather than equality naively based on the contents of // the bzl file. For a concrete example, the contents of comment lines do not currently impact // skylark semantics. public abstract class ASTFileLookupValue implements NotComparableSkyValue { public abstract boolean lookupSuccessful(); - public abstract BuildFileAST getAST(); + + public abstract StarlarkFile getAST(); + public abstract String getErrorMsg(); /** If the file is found, this class encapsulates the parsed AST. */ @AutoCodec.VisibleForSerialization public static class ASTLookupWithFile extends ASTFileLookupValue { - private final BuildFileAST ast; + private final StarlarkFile ast; - private ASTLookupWithFile(BuildFileAST ast) { + private ASTLookupWithFile(StarlarkFile ast) { Preconditions.checkNotNull(ast); this.ast = ast; } @@ -60,7 +62,7 @@ } @Override - public BuildFileAST getAST() { + public StarlarkFile getAST() { return this.ast; } @@ -86,7 +88,7 @@ } @Override - public BuildFileAST getAST() { + public StarlarkFile getAST() { throw new IllegalStateException("attempted to retrieve AST from an unsuccessful lookup"); } @@ -111,7 +113,7 @@ String.format("Unable to load file '%s': it isn't a regular file", fileLabel)); } - public static ASTFileLookupValue withFile(BuildFileAST ast) { + public static ASTFileLookupValue withFile(StarlarkFile ast) { return new ASTLookupWithFile(ast); }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java index dbbbf39..6b8ede8 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -56,9 +56,9 @@ import com.google.devtools.build.lib.skyframe.GlobValue.InvalidGlobPatternException; import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException; import com.google.devtools.build.lib.skyframe.SkylarkImportLookupValue.SkylarkImportLookupKey; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.ParserInput; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread.Extension; import com.google.devtools.build.lib.syntax.Statement; @@ -548,7 +548,7 @@ RootedPath buildFilePath, PackageIdentifier packageId, ImmutableMap<RepositoryName, RepositoryName> repoMapping, - BuildFileAST file, + StarlarkFile file, int workspaceChunk, Environment env, SkylarkImportLookupFunction skylarkImportLookupFunctionForInlining) @@ -1167,7 +1167,7 @@ } input = ParserInput.create(buildFileBytes, inputFile.asFragment()); StoredEventHandler astParsingEventHandler = new StoredEventHandler(); - BuildFileAST ast = + StarlarkFile ast = PackageFactory.parseBuildFile( packageId, input, preludeStatements, astParsingEventHandler); astParseResult = new AstParseResult(ast, astParsingEventHandler);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java index db9176f..b4d8881 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
@@ -44,11 +44,11 @@ import com.google.devtools.build.lib.packages.WorkspaceFileValue; import com.google.devtools.build.lib.skyframe.SkylarkImportLookupValue.SkylarkImportLookupKey; import com.google.devtools.build.lib.syntax.AssignmentStatement; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Identifier; import com.google.devtools.build.lib.syntax.LoadStatement; import com.google.devtools.build.lib.syntax.Mutability; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread; import com.google.devtools.build.lib.syntax.StarlarkThread.Extension; @@ -319,7 +319,7 @@ // Skylark import files have to exist. throw new SkylarkImportFailedException(astLookupValue.getErrorMsg()); } - BuildFileAST file = astLookupValue.getAST(); + StarlarkFile file = astLookupValue.getAST(); if (file.containsErrors()) { throw SkylarkImportFailedException.skylarkErrors(filePath); } @@ -443,7 +443,7 @@ @Nullable static Map<String, Label> getLoadMap( EventHandler handler, - BuildFileAST file, + StarlarkFile file, PackageIdentifier base, ImmutableMap<RepositoryName, RepositoryName> repoMapping) { Preconditions.checkArgument(!base.getRepository().isDefault()); @@ -577,7 +577,7 @@ /** Creates the Extension to be imported. */ private Extension createExtension( - BuildFileAST ast, + StarlarkFile ast, Label extensionLabel, Map<String, Extension> importMap, StarlarkSemantics starlarkSemantics, @@ -616,7 +616,7 @@ } public static void execAndExport( - BuildFileAST ast, + StarlarkFile ast, Label extensionLabel, EventHandler eventHandler, StarlarkThread extensionThread)
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java index 55b14b4..e33ade1 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunction.java
@@ -27,10 +27,10 @@ import com.google.devtools.build.lib.packages.RuleClassProvider; import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction; import com.google.devtools.build.lib.rules.repository.ResolvedFileValue; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.LoadStatement; import com.google.devtools.build.lib.syntax.ParserInput; import com.google.devtools.build.lib.syntax.Printer; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.Statement; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -45,9 +45,7 @@ import java.util.List; import java.util.Map; -/** - * A SkyFunction to parse WORKSPACE files into a BuildFileAST. - */ +/** A SkyFunction to parse WORKSPACE files into a StarlarkFile. */ public class WorkspaceASTFunction implements SkyFunction { private final RuleClassProvider ruleClassProvider; @@ -81,8 +79,8 @@ Path repoWorkspace = workspaceRoot.getRoot().getRelative(workspaceRoot.getRootRelativePath()); try { - BuildFileAST file = - BuildFileAST.parse( + StarlarkFile file = + StarlarkFile.parse( ParserInput.create( ruleClassProvider.getDefaultWorkspacePrefix(), PathFragment.create("/DEFAULT.WORKSPACE")), @@ -96,7 +94,7 @@ } if (newWorkspaceFileContents != null) { file = - BuildFileAST.parseVirtualBuildFile( + StarlarkFile.parseVirtualBuildFile( ParserInput.create( newWorkspaceFileContents, resolvedFile.get().asPath().asFragment()), file.getStatements(), @@ -105,7 +103,7 @@ byte[] bytes = FileSystemUtils.readWithKnownFileSize(repoWorkspace, repoWorkspace.getFileSize()); file = - BuildFileAST.parseWithPrelude( + StarlarkFile.parseWithPrelude( ParserInput.create(bytes, repoWorkspace.asFragment()), file.getStatements(), env.getListener()); @@ -117,7 +115,7 @@ } } file = - BuildFileAST.parseWithPrelude( + StarlarkFile.parseWithPrelude( ParserInput.create( resolvedFile.isPresent() ? "" : ruleClassProvider.getDefaultWorkspaceSuffix(), PathFragment.create("/DEFAULT.WORKSPACE.SUFFIX")), @@ -222,8 +220,8 @@ * Cut {@code ast} into a list of AST separated by load statements. We cut right before each load * statement series. */ - private static ImmutableList<BuildFileAST> splitAST(BuildFileAST ast) { - ImmutableList.Builder<BuildFileAST> asts = ImmutableList.builder(); + private static ImmutableList<StarlarkFile> splitAST(StarlarkFile ast) { + ImmutableList.Builder<StarlarkFile> asts = ImmutableList.builder(); int prevIdx = 0; boolean lastIsLoad = true; // don't cut if the first statement is a load. List<Statement> statements = ast.getStatements();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTValue.java index 7011784..6397c79 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceASTValue.java
@@ -18,7 +18,7 @@ import com.google.common.collect.Interner; import com.google.devtools.build.lib.concurrent.BlazeInterners; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.syntax.BuildFileAST; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.AbstractSkyKey; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -48,14 +48,14 @@ */ public class WorkspaceASTValue implements SkyValue { - private final ImmutableList<BuildFileAST> asts; + private final ImmutableList<StarlarkFile> asts; - public WorkspaceASTValue(List<BuildFileAST> asts) { + public WorkspaceASTValue(List<StarlarkFile> asts) { Preconditions.checkNotNull(asts); this.asts = ImmutableList.copyOf(asts); } - public ImmutableList<BuildFileAST> getASTs() { + public ImmutableList<StarlarkFile> getASTs() { return asts; }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java index 74716bd..22aadd5 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunction.java
@@ -25,8 +25,8 @@ import com.google.devtools.build.lib.packages.WorkspaceFactory; import com.google.devtools.build.lib.packages.WorkspaceFileValue; import com.google.devtools.build.lib.packages.WorkspaceFileValue.WorkspaceFileKey; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.Mutability; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread.Extension; import com.google.devtools.build.lib.vfs.RootedPath; @@ -123,7 +123,7 @@ } parser.setParent(prevValue.getPackage(), prevValue.getImportMap(), prevValue.getBindings()); } - BuildFileAST ast = workspaceASTValue.getASTs().get(key.getIndex()); + StarlarkFile ast = workspaceASTValue.getASTs().get(key.getIndex()); PackageFunction.SkylarkImportResult importResult = PackageFunction.fetchImportsFromBuildFile( repoWorkspace,
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Comment.java b/src/main/java/com/google/devtools/build/lib/syntax/Comment.java index a5924f9..9ca6728 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Comment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Comment.java
@@ -36,7 +36,7 @@ @Override public void prettyPrint(Appendable buffer, int indentLevel) throws IOException { // We can't really print comments in the right place anyway, due to how their relative order - // is lost in the representation of BuildFileAST. So don't bother word-wrapping and just print + // is lost in the representation of StarlarkFile. So don't bother word-wrapping and just print // it on a single line. printIndent(buffer, indentLevel); buffer.append("# ");
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Expression.java b/src/main/java/com/google/devtools/build/lib/syntax/Expression.java index 5368e2e..06bc54c 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Expression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Expression.java
@@ -69,7 +69,7 @@ // TODO(adonovan): remove dependency from syntax -> EventHandler. // A call to Expression.parse either succeeds or fails; there is no useful middle ground, so an // exception is appropriate. The exception would contain the list of errors. - // By contrast, a call to BuildFileAST.parse should return both a partial AST and a list of + // By contrast, a call to StarlarkFile.parse should return both a partial AST and a list of // errors, // and generally it is useful to keep both around, so if we put the errors in the root of the AST, // then client can deal with them however they like, e.g. by sending them to the event handler.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Node.java b/src/main/java/com/google/devtools/build/lib/syntax/Node.java index 1150116..d19b669 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Node.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Node.java
@@ -92,7 +92,7 @@ * * <p>Pretty printing can also be used as a proxy for comparing for equality between two ASTs. * This can be very useful in tests. However, it is still possible for two different trees to have - * the same pretty printing. In particular, {@link BuildFileAST} includes import metadata and + * the same pretty printing. In particular, {@link StarlarkFile} includes import metadata and * comment information that is not reflected in the string. */ public abstract void prettyPrint(Appendable buffer, int indentLevel) throws IOException;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/NodeVisitor.java b/src/main/java/com/google/devtools/build/lib/syntax/NodeVisitor.java index eaaa97d..a98a016 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/NodeVisitor.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/NodeVisitor.java
@@ -53,7 +53,7 @@ } } - public void visit(BuildFileAST node) { + public void visit(StarlarkFile node) { visitBlock(node.getStatements()); visitAll(node.getComments()); }
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 6834531..ff4e4d8 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
@@ -41,7 +41,7 @@ */ // TODO(adonovan): break syntax->events dependency and simplify error handling in the API. The // result of parsing is a complete, partial, or even empty, file plus a list of errors. For -// BuildFileAST.parse, we should materialize the error list within the BuildFileAST and remove all +// StarlarkFile.parse, we should materialize the error list within the StarlarkFile and remove all // mention of event handlers; let the client decide whether to throw or report errors. For // Expression.parse, throwing an exception is appropriate: expressions are typically so short that // only one error is wanted, so the result can be all-or-nothing.
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java index 83723fa..5cd12f4 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
@@ -251,7 +251,7 @@ .setEventHandler(StarlarkThread.FAIL_FAST_HANDLER) .build() .update("unbound", Runtime.UNBOUND); - defaultValue = BuildFileAST.eval(ParserInput.fromLines(paramDefaultValue), thread); + defaultValue = StarlarkFile.eval(ParserInput.fromLines(paramDefaultValue), thread); defaultValueCache.put(paramDefaultValue, defaultValue); return defaultValue; }
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkFile.java similarity index 91% rename from src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java rename to src/main/java/com/google/devtools/build/lib/syntax/StarlarkFile.java index 7f7e7b5..9a9f458 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkFile.java
@@ -24,8 +24,7 @@ import javax.annotation.Nullable; /** Syntax tree for a Starlark file, such as a Bazel BUILD or .bzl file. */ -// TODO(adonovan): rename to StarlarkFile. -public class BuildFileAST extends Node { +public class StarlarkFile extends Node { private final ImmutableList<Statement> statements; @@ -40,7 +39,7 @@ @Nullable private final String contentHashCode; - private BuildFileAST( + private StarlarkFile( ImmutableList<Statement> statements, boolean containsErrors, String contentHashCode, @@ -55,7 +54,7 @@ this.stringEscapeEvents = stringEscapeEvents; } - private static BuildFileAST create( + private static StarlarkFile create( List<Statement> preludeStatements, ParseResult result, String contentHashCode, @@ -75,7 +74,7 @@ statementsbuilder.addAll(result.statements); } ImmutableList<Statement> statements = statementsbuilder.build(); - return new BuildFileAST( + return new StarlarkFile( statements, result.containsErrors, contentHashCode, @@ -88,9 +87,9 @@ * Extract a subtree containing only statements from {@code firstStatement} (included) up to * {@code lastStatement} excluded. */ - public BuildFileAST subTree(int firstStatement, int lastStatement) { + public StarlarkFile subTree(int firstStatement, int lastStatement) { ImmutableList<Statement> statements = this.statements.subList(firstStatement, lastStatement); - return new BuildFileAST( + return new StarlarkFile( statements, containsErrors, null, @@ -207,7 +206,7 @@ @Override public String toString() { - return "<BuildFileAST with " + statements.size() + " statements>"; + return "<StarlarkFile with " + statements.size() + " statements>"; } @Override @@ -220,10 +219,8 @@ * front of its statement list. All errors during scanning or parsing will be reported to the * event handler. */ - public static BuildFileAST parseWithPrelude( - ParserInput input, - List<Statement> preludeStatements, - EventHandler eventHandler) { + public static StarlarkFile parseWithPrelude( + ParserInput input, List<Statement> preludeStatements, EventHandler eventHandler) { Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create( preludeStatements, result, /* contentHashCode= */ null, /*allowImportInternal=*/ false); @@ -234,16 +231,14 @@ * exempt from visibility restrictions. All errors during scanning or parsing will be reported to * the event handler. */ - public static BuildFileAST parseVirtualBuildFile( - ParserInput input, - List<Statement> preludeStatements, - EventHandler eventHandler) { + public static StarlarkFile parseVirtualBuildFile( + ParserInput input, List<Statement> preludeStatements, EventHandler eventHandler) { Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create( preludeStatements, result, /* contentHashCode= */ null, /*allowImportInternal=*/ true); } - public static BuildFileAST parseWithDigest( + public static StarlarkFile parseWithDigest( ParserInput input, byte[] digest, EventHandler eventHandler) throws IOException { Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create( @@ -253,7 +248,7 @@ /* allowImportInternal= */ false); } - public static BuildFileAST parse(ParserInput input, EventHandler eventHandler) { + public static StarlarkFile parse(ParserInput input, EventHandler eventHandler) { Parser.ParseResult result = Parser.parseFile(input, eventHandler); return create( /* preludeStatements= */ ImmutableList.<Statement>of(), @@ -267,9 +262,9 @@ * during scanning or parsing will be reported to the event handler. */ // TODO(adonovan): redundant; delete. - public static BuildFileAST parseWithoutImports(ParserInput input, EventHandler eventHandler) { + public static StarlarkFile parseWithoutImports(ParserInput input, EventHandler eventHandler) { ParseResult result = Parser.parseFile(input, eventHandler); - return new BuildFileAST( + return new StarlarkFile( ImmutableList.copyOf(result.statements), result.containsErrors, /* contentHashCode= */ null, @@ -286,7 +281,7 @@ // TODO(adonovan): eliminate. Most callers need validation because they intend to execute the // file, and should be made to use higher-level operations in EvalUtils. // rest should skip this step. Called from EvaluationTestCase, ParserTest, ASTFileLookupFunction. - public BuildFileAST validate( + public StarlarkFile validate( StarlarkThread thread, boolean isBuildFile, EventHandler eventHandler) { try { ValidationEnvironment.validateFile(this, thread, isBuildFile); @@ -299,7 +294,7 @@ if (containsErrors) { return this; // already marked as errant } - return new BuildFileAST( + return new StarlarkFile( statements, /*containsErrors=*/ true, contentHashCode, @@ -338,7 +333,7 @@ @Nullable public static Object eval(ParserInput input, StarlarkThread thread) throws EvalException, InterruptedException { - BuildFileAST ast = parseAndValidateSkylark(input, thread); + StarlarkFile ast = parseAndValidateSkylark(input, thread); return ast.eval(thread); } @@ -347,9 +342,9 @@ * it throws an EvalException. Uses Starlark (not BUILD) validation semantics. */ // TODO(adonovan): move to EvalUtils; see above. - public static BuildFileAST parseAndValidateSkylark(ParserInput input, StarlarkThread thread) + public static StarlarkFile parseAndValidateSkylark(ParserInput input, StarlarkThread thread) throws EvalException { - BuildFileAST file = parse(input, thread.getEventHandler()); + StarlarkFile file = parse(input, thread.getEventHandler()); file.replayLexerEvents(thread, thread.getEventHandler()); ValidationEnvironment.validateFile(file, thread, /*isBuildFile=*/ false); return file;
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java index a7732e2..a03b7de 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/StarlarkThread.java
@@ -1206,7 +1206,7 @@ // TODO(adonovan): push this up into the debugger once the exec API is finalized. public void debugExec(ParserInput input) throws EvalException, InterruptedException { EvalEventHandler handler = new EvalEventHandler(); - BuildFileAST file = BuildFileAST.parse(input, handler); + StarlarkFile file = StarlarkFile.parse(input, handler); if (!handler.messages.isEmpty()) { Event ev = handler.messages.get(0); throw new EvalException(ev.getLocation(), ev.getMessage());
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java index d3d90b5..bb61d57 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
@@ -396,7 +396,7 @@ // Public entry point, throwing variant. // TODO(adonovan): combine with variant below. - public static void validateFile(BuildFileAST file, StarlarkThread thread, boolean isBuildFile) + public static void validateFile(StarlarkFile file, StarlarkThread thread, boolean isBuildFile) throws EvalException { try { ValidationEnvironment venv = new ValidationEnvironment(thread, isBuildFile); @@ -410,7 +410,7 @@ // Public entry point, error handling variant. public static boolean validateFile( - BuildFileAST file, StarlarkThread thread, boolean isBuildFile, EventHandler eventHandler) { + StarlarkFile file, StarlarkThread thread, boolean isBuildFile, EventHandler eventHandler) { try { validateFile(file, thread, isBuildFile); return true;
diff --git a/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java b/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java index f1368e8..a960812 100644 --- a/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java +++ b/src/main/java/com/google/devtools/build/skydoc/SkydocMain.java
@@ -55,13 +55,13 @@ import com.google.devtools.build.lib.skylarkbuildapi.stubs.SkylarkAspectStub; import com.google.devtools.build.lib.skylarkbuildapi.test.TestingBootstrap; import com.google.devtools.build.lib.syntax.BaseFunction; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.LoadStatement; import com.google.devtools.build.lib.syntax.MethodLibrary; import com.google.devtools.build.lib.syntax.Mutability; import com.google.devtools.build.lib.syntax.ParserInput; import com.google.devtools.build.lib.syntax.Runtime; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkFunction; import com.google.devtools.build.lib.syntax.StarlarkSemantics; import com.google.devtools.build.lib.syntax.StarlarkThread; @@ -389,7 +389,7 @@ } } - private static String getModuleDoc(BuildFileAST buildFileAST) { + private static String getModuleDoc(StarlarkFile buildFileAST) { ImmutableList<Statement> fileStatements = buildFileAST.getStatements(); if (!fileStatements.isEmpty()) { Statement moduleComment = fileStatements.get(0); @@ -429,7 +429,7 @@ pending.add(path); ParserInput parserInputSource = getInputSource(path.toString()); - BuildFileAST file = BuildFileAST.parse(parserInputSource, eventHandler); + StarlarkFile file = StarlarkFile.parse(parserInputSource, eventHandler); moduleDocMap.put(label, getModuleDoc(file)); @@ -490,7 +490,7 @@ /** Evaluates the AST from a single skylark file, given the already-resolved imports. */ private StarlarkThread evalSkylarkBody( StarlarkSemantics semantics, - BuildFileAST buildFileAST, + StarlarkFile buildFileAST, Map<String, Extension> imports, List<RuleInfoWrapper> ruleInfoList, List<ProviderInfoWrapper> providerInfoList,
diff --git a/src/main/java/com/google/devtools/starlark/Starlark.java b/src/main/java/com/google/devtools/starlark/Starlark.java index 0da0ace..bcfc5e1 100644 --- a/src/main/java/com/google/devtools/starlark/Starlark.java +++ b/src/main/java/com/google/devtools/starlark/Starlark.java
@@ -16,11 +16,11 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.EventKind; -import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Mutability; import com.google.devtools.build.lib.syntax.ParserInput; import com.google.devtools.build.lib.syntax.Printer; +import com.google.devtools.build.lib.syntax.StarlarkFile; import com.google.devtools.build.lib.syntax.StarlarkThread; import java.io.BufferedReader; import java.io.IOException; @@ -91,7 +91,7 @@ String line; while ((line = prompt()) != null) { try { - Object result = BuildFileAST.eval(ParserInput.fromLines(line), thread); + Object result = StarlarkFile.eval(ParserInput.fromLines(line), thread); if (result != null) { System.out.println(Printer.repr(result)); } @@ -117,7 +117,7 @@ public int execute(String content) { try { ParserInput input = ParserInput.create(content, null); - BuildFileAST.eval(input, thread); + StarlarkFile.eval(input, thread); return 0; } catch (EvalException e) { System.err.println(e.print());