MCPcopy Index your code
hub / github.com/bazelbuild/bazel / compileFile

Method compileFile

src/main/java/net/starlark/java/syntax/Program.java:95–130  ·  view source on GitHub ↗

Resolves a file syntax tree in the specified environment and compiles it to a Program. This operation mutates the syntax tree, both by resolving identifiers and recording local variables, and in case of error, by appending to file.errors(). @throws SyntaxError.Exception in case of resolutio

(StarlarkFile file, Resolver.Module env)

Source from the content-addressed store, hash-verified

93 * contained syntax scan/parse errors. Resolution errors are added to {@code file.errors()}.
94 */
95 public static Program compileFile(StarlarkFile file, Resolver.Module env)
96 throws SyntaxError.Exception {
97 Resolver.resolveFile(file, env);
98 if (!file.ok()) {
99 throw new SyntaxError.Exception(file.errors());
100 }
101
102 // Extract load statements.
103 ImmutableList.Builder<String> loads = ImmutableList.builder();
104 ImmutableList.Builder<Location> loadLocations = ImmutableList.builder();
105 for (Statement stmt : file.getStatements()) {
106 if (stmt instanceof LoadStatement load) {
107 String module = load.getImport().getValue();
108 loads.add(module);
109 loadLocations.add(load.getImport().getLocation());
110 }
111 }
112
113 // Find unused doc comments.
114 ImmutableMap<String, DocComments> docCommentsMap = ImmutableMap.copyOf(file.docCommentsMap);
115 HashSet<Comment> usedDocCommentLines = new HashSet<>();
116 for (DocComments docComments : docCommentsMap.values()) {
117 usedDocCommentLines.addAll(docComments.getLines());
118 }
119 ImmutableList<Comment> unusedDocCommentLines =
120 file.getComments().stream()
121 .filter(c -> c.hasDocCommentPrefix() && !usedDocCommentLines.contains(c))
122 .collect(toImmutableList());
123
124 return new Program(
125 file.getResolvedFunction(),
126 loads.build(),
127 loadLocations.build(),
128 docCommentsMap,
129 unusedDocCommentLines);
130 }
131
132 /**
133 * Resolves an expression syntax tree in the specified environment and compiles it to a Program.

Callers 3

compileFileMethod · 0.95
compileThenExecuteMethod · 0.95
execFileMethod · 0.95

Calls 15

resolveFileMethod · 0.95
okMethod · 0.80
getStatementsMethod · 0.80
getImportMethod · 0.80
hasDocCommentPrefixMethod · 0.80
getValueMethod · 0.65
getLocationMethod · 0.65
errorsMethod · 0.45
builderMethod · 0.45
addMethod · 0.45
copyOfMethod · 0.45
valuesMethod · 0.45

Tested by 2

compileFileMethod · 0.76
compileThenExecuteMethod · 0.76