From db8b8672e2b7659a6ab890393cdd512049b07e80 Mon Sep 17 00:00:00 2001 From: Florian Weikert Date: Mon, 9 Nov 2015 13:26:24 +0000 Subject: Compile assignments to byte code and throw errors. Add EvalExceptions for cases in which the interpreter would throw them during evaluation of the function definition. -- MOS_MIGRATED_REVID=107376021 --- .../devtools/build/lib/syntax/UserDefinedFunction.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java') diff --git a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java index cf68aeb6f4..ededb16999 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java @@ -81,7 +81,8 @@ public class UserDefinedFunction extends BaseFunction { protected UserDefinedFunction(Identifier function, FunctionSignature.WithValues signature, - ImmutableList statements, Environment.Frame definitionGlobals) { + ImmutableList statements, Environment.Frame definitionGlobals) + throws EvalException { super(function.getName(), signature, function.getLocation()); this.statements = statements; this.definitionGlobals = definitionGlobals; @@ -174,7 +175,7 @@ public class UserDefinedFunction extends BaseFunction { * *

The "call" method contains the compiled version of this function's AST. */ - private Optional buildCompiledFunction() { + private Optional buildCompiledFunction() throws EvalException { // replace the / character in the path so we have file system compatible class names // the java specification mentions that $ should be used in generated code // see http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8 @@ -253,11 +254,14 @@ public class UserDefinedFunction extends BaseFunction { "call", parameterTypes.toArray(new Class[parameterTypes.size()])) .getLoadedMethod()); + } catch (EvalException e) { + // don't capture EvalExceptions + throw e; } catch (Throwable e) { compilerDebug("Error while compiling", e); // TODO(bazel-team) don't capture all throwables? couldn't compile this, log somewhere? - return Optional.absent(); } + return Optional.absent(); } /** @@ -280,7 +284,8 @@ public class UserDefinedFunction extends BaseFunction { /** * Builds a byte code implementation of the AST. */ - private Implementation compileBody(VariableScope scope, DebugInfo debugInfo) { + private Implementation compileBody(VariableScope scope, DebugInfo debugInfo) + throws EvalException { List code = new ArrayList<>(statements.size()); code.add(null); // reserve space for later addition of the local variable initializer -- cgit v1.2.3