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

Method execStatements

src/main/java/net/starlark/java/eval/Eval.java:74–112  ·  view source on GitHub ↗
(
      StarlarkThread.Frame fr, List<Statement> statements, boolean indented)

Source from the content-addressed store, hash-verified

72 }
73
74 private static TokenKind execStatements(
75 StarlarkThread.Frame fr, List<Statement> statements, boolean indented)
76 throws EvalException, InterruptedException {
77 boolean isToplevelFunction = fn(fr).isToplevel();
78
79 // Hot code path, good chance of short lists which don't justify the iterator overhead.
80 for (int i = 0; i < statements.size(); i++) {
81 Statement stmt = statements.get(i);
82 TokenKind flow = exec(fr, stmt);
83 if (flow != TokenKind.PASS) {
84 return flow;
85 }
86
87 // Hack for BzlLoadFunction's "export" semantics.
88 // We enable it only for statements outside any function (isToplevelFunction)
89 // and outside any if- or for- statements (!indented).
90 if (isToplevelFunction && !indented && fr.thread.postAssignHook != null) {
91 if (stmt instanceof AssignmentStatement assign) {
92 for (Identifier id : Identifier.boundIdentifiers(assign.getLHS())) {
93 Object value = fn(fr).getGlobal(id.getBinding().getIndex());
94 // TODO(bazel-team): Instead of special casing StarlarkFunction, make it implement
95 // StarlarkExportable.
96 if (value instanceof StarlarkFunction func) {
97 // Optimization: The id token of a StarlarkFunction should be based on its global
98 // identifier when available. This enables an name-based lookup on deserialization.
99 func.export(fr.thread, id.getName());
100 } else {
101 fr.thread.postAssignHook.assign(id.getName(), id.getStartLocation(), value);
102 }
103 }
104 } else if (stmt instanceof DefStatement def) {
105 Identifier id = def.getIdentifier();
106 ((StarlarkFunction) fn(fr).getGlobal(id.getBinding().getIndex()))
107 .export(fr.thread, id.getName());
108 }
109 }
110 }
111 return TokenKind.PASS;
112 }
113
114 private static void execAssignment(StarlarkThread.Frame fr, AssignmentStatement node)
115 throws EvalException, InterruptedException {

Callers 3

execFunctionBodyMethod · 0.95
execForMethod · 0.95
execIfMethod · 0.95

Calls 15

fnMethod · 0.95
execMethod · 0.95
boundIdentifiersMethod · 0.95
getBindingMethod · 0.95
getNameMethod · 0.95
getLHSMethod · 0.80
exportMethod · 0.80
getMethod · 0.65
getIndexMethod · 0.65
assignMethod · 0.65
isToplevelMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected