(
StarlarkThread.Frame fr, List<Statement> statements, boolean indented)
| 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 { |
no test coverage detected