import org.simantics.scl.compiler.elaboration.java.Builtins;
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.environment.LocalEnvironment;
+import org.simantics.scl.compiler.errors.CompilationError;
import org.simantics.scl.compiler.errors.ErrorLog;
import org.simantics.scl.compiler.internal.codegen.references.IVal;
import org.simantics.scl.compiler.internal.codegen.ssa.SSAModule;
private LocalStorage localStorage;
private boolean interpretIfPossible = true;
private ExpressionParseMode parseMode = ExpressionParseMode.EXPRESSION;
+ private boolean validateOnly;
public ExpressionEvaluator(RuntimeEnvironment runtimeEnvironment,
String expressionText) {
return this;
}
+ public ExpressionEvaluator validateOnly(boolean validateOnly) {
+ this.validateOnly = validateOnly;
+ return this;
+ }
+
/**
* Sets a local environment that can arbitrarily modify the resolving of the expression.
*/
return "store_" + name;
}
}
+
+ public CompilationError[] validate() {
+ try {
+ validateOnly = true;
+ eval();
+ return CompilationError.EMPTY_ARRAY;
+ } catch(SCLExpressionCompilationException e) {
+ return e.getErrors();
+ }
+ }
public Object eval() throws SCLExpressionCompilationException {
fillDefaults();
Types.functionE(type, Types.PROC, Types.UNIT)),
new EVar(variableName)
)));
+ if(validateOnly)
+ localStorage.store(variableName, null, type);
}
}
if(!(block.getStatements().getLast() instanceof GuardStatement))
{
TranslationContext context = new TranslationContext(compilationContext, localEnvironment);
expression = expression.resolve(context);
- if(!errorLog.isEmpty())
+ if(!errorLog.hasNoErrors())
throw new SCLExpressionCompilationException(errorLog.getErrors());
}
expectedType.addPolarity(Polarity.POSITIVE);
context.solveSubsumptions(expression.location);
- if(!errorLog.isEmpty())
+ if(!errorLog.hasNoErrors())
throw new SCLExpressionCompilationException(errorLog.getErrors());
if(decorateExpression && Types.canonical(expectedEffect) != Types.NO_EFFECTS) {
ExpressionDecorator decorator =
expression = context.solveConstraints(environment, expression);
expressionType = expression.getType();
- if(!errorLog.isEmpty())
+ if(!errorLog.hasNoErrors())
throw new SCLExpressionCompilationException(errorLog.getErrors());
if(localEnvironment != null)
expression = localEnvironment.postDecorateExpression(expression);
+
+ if(validateOnly)
+ return null;
Type type = expression.getType();
type = type.convertMetaVarsToVars();
new SimplificationContext(compilationContext, DummyJavaReferenceValidator.INSTANCE);
expression = expression.simplify(context);
- if(!errorLog.isEmpty())
+ if(!errorLog.hasNoErrors())
throw new SCLExpressionCompilationException(errorLog.getErrors());
if(SCLCompilerConfiguration.SHOW_EXPRESSION_BEFORE_EVALUATION)