X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FEBlock.java;h=c21732557ba555f5ce950058e0eddaaab468182a;hb=82a87b8535628d47d9c381e1a3a2296fb67c7fd0;hp=a509616bbb4bf669e08e1ece55584d58355309a3;hpb=00119bc6c509134e985c11ad4f6aff37801adc3f;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java index a509616bb..c21732557 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EBlock.java @@ -3,10 +3,12 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; import java.util.List; -import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.elaboration.chr.CHRRule; import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; +import org.simantics.scl.compiler.elaboration.chr.ast.CHRQueryTranslationMode; import org.simantics.scl.compiler.elaboration.chr.translation.CHRTranslation; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; +import org.simantics.scl.compiler.elaboration.expressions.block.BlockType; import org.simantics.scl.compiler.elaboration.expressions.block.CHRStatement; import org.simantics.scl.compiler.elaboration.expressions.block.ConstraintStatement; import org.simantics.scl.compiler.elaboration.expressions.block.GuardStatement; @@ -19,20 +21,21 @@ import org.simantics.scl.compiler.errors.Locations; public class EBlock extends ASTExpression { - ArrayList statements = new ArrayList(); - boolean monadic; + public ArrayList statements = new ArrayList(); + BlockType blockType = BlockType.Normal; public EBlock() { + this.blockType = blockType; + } + + public void setBlockType(BlockType blockType) { + this.blockType = blockType; } public void addStatement(Statement statement) { statements.add(statement); } - public void setMonadic(boolean monadic) { - this.monadic = monadic; - } - public ArrayList getStatements() { return statements; } @@ -47,8 +50,10 @@ public class EBlock extends ASTExpression { @Override public Expression resolve(TranslationContext context) { - if(statements.isEmpty()) - throw new InternalCompilerError(); + if(statements.isEmpty()) { + context.getErrorLog().log(location, "Block should not be empty."); + return new EError(location); + } int i = statements.size()-1; Statement last = statements.get(i); if(!(last instanceof GuardStatement)) { @@ -61,7 +66,7 @@ public class EBlock extends ASTExpression { Statement cur = statements.get(i); StatementGroup group = cur.getStatementGroup(); if(group == null) - in = cur.toExpression(context, monadic, in); + in = cur.toExpression(context, blockType, in); else { int endId = i+1; while(i>0 && statements.get(i-1).getStatementGroup() == group) @@ -73,10 +78,14 @@ public class EBlock extends ASTExpression { case Rule: in = extractRules(i, endId, in); break; - case CHR: - in = new ECHRRuleset(extractCHRRules(context, i, endId), in); + case CHR: { + CHRRuleset ruleset = extractCHRRules(context, i, endId); + long location = Locations.combine(ruleset.location, in.location); + in = new ECHRRuleset(ruleset, in); + in.location = location; break; } + } } } return in.resolve(context); @@ -91,8 +100,12 @@ public class EBlock extends ASTExpression { ruleset.location = Locations.combine(statements.get(begin).location, statements.get(end-1).location); for(int i=begin;i