import org.simantics.scl.compiler.elaboration.expressions.ETypeAnnotation;
import org.simantics.scl.compiler.elaboration.expressions.EVar;
import org.simantics.scl.compiler.elaboration.expressions.EVariable;
-import org.simantics.scl.compiler.elaboration.expressions.EWhen;
+import org.simantics.scl.compiler.elaboration.expressions.EViewPattern;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.expressions.GuardedExpression;
import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup;
import org.simantics.scl.compiler.elaboration.expressions.accessor.IdAccessor;
import org.simantics.scl.compiler.elaboration.expressions.accessor.StringAccessor;
import org.simantics.scl.compiler.elaboration.expressions.block.BindStatement;
+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;
import org.simantics.scl.compiler.elaboration.expressions.block.LetStatement;
import org.simantics.scl.compiler.elaboration.expressions.block.RuleStatement;
);
}
+ @SuppressWarnings("unchecked")
@Override
protected Object reduceClassDefinition() {
int i=1;
return fundeps;
}
+ @SuppressWarnings("unchecked")
@Override
protected Object reduceInstanceDefinition() {
int i=1;
declarations);
}
+ @SuppressWarnings("unchecked")
@Override
protected Object reduceDerivingInstanceDefinition() {
int i=2;
return get(0);
}
+ @SuppressWarnings("unchecked")
@Override
protected Object reduceImportJava() {
return new DImportJavaAst(((Token)get(2)).text, (ArrayList<DeclarationAst>)get(4));
@Override
protected Object reduceStatements() {
EBlock block = new EBlock();
- for(int i=1;i<length();i+=2)
- block.addStatement((Statement)get(i));
+ if(length() > 2)
+ for(int i=1;i<length();i+=2)
+ block.addStatement((Statement)get(i));
return block;
}
case_.setLhs(Locations.combine(patterns[0].location, patterns[patterns.length-1].location));
return new ELambda(case_);
}
+
+ @Override
+ protected Object reduceLambdaMatch() {
+ Case[] cases = new Case[length()/2-1];
+ for(int i=0;i<cases.length;++i)
+ cases[i] = (Case)get(i*2+2);
+ return new ELambda(cases);
+ }
@Override
protected Object reduceLet() {
return new EIf(
(Expression)get(1),
(Expression)get(3),
- (Expression)get(5));
+ length() == 6 ? (Expression)get(5) : null);
}
@Override
protected Object reduceSelect() {
return new ESelect(((Token)get(0)).id, (Expression)get(1), new QConjunction((Query[])get(3)));
}
-
- @Override
- protected Object reduceWhen() {
- return new EWhen(
- new QConjunction((Query[])get(1)),
- (Expression)get(3));
- }
-
+
@Override
protected Object reduceEnforce() {
return new EEnforce(new QConjunction((Query[])get(1)));
throw new UnsupportedOperationException();
}
+ @SuppressWarnings("unchecked")
@Override
protected void postReduce(Object reduced) {
if(!(reduced instanceof Symbol))
Symbol sym = (Symbol)reduced;
if(sym.location != Locations.NO_LOCATION || length() == 0)
return;
+ Object first = get(0);
+ if(!(first instanceof Symbol)) {
+ if(first instanceof List) {
+ List<Object> ll = (List<Object>)first;
+ first = ll.get(0);
+ }
+ else {
+ Object[] ll = (Object[])first;
+ if(ll.length > 0)
+ first = ll[0];
+ else
+ first = get(1);
+ }
+ }
Object last = get(length()-1);
if(!(last instanceof Symbol)) {
if(last instanceof List) {
last = get(length()-2);
}
}
- sym.location = (((Symbol)get(0)).location & 0xffffffff00000000L)
+ sym.location = (((Symbol)first).location & 0xffffffff00000000L)
| (((Symbol)last).location & 0xffffffffL);
/*for(int i=0;i<length();++i) {
Object obj = get(i);
private static final String[] EMPTY_STRING_ARRAY = new String[0];
+ @SuppressWarnings("unchecked")
@Override
protected Object reduceRuleDefinition() {
String[] extendsNames = EMPTY_STRING_ARRAY;
);
}
+ @SuppressWarnings("unchecked")
@Override
protected Object reduceRelationDefinition() {
return new DRelationAst((Expression)get(0),
protected Object reduceBasicEquation() {
return new EqBasic((Expression)get(0), (Expression)get(2));
}
+
+ @Override
+ protected Object reduceViewPattern() {
+ return new EViewPattern((Expression)get(1), (Expression)get(3));
+ }
+
+ @Override
+ protected Object reduceCHRStatement() {
+ return new CHRStatement((ListQualifier[])get(0), (ListQualifier[])get(2));
+ }
+
+ @Override
+ protected Object reduceConstraintStatement() {
+ TypeAst[] parameterTypes = new TypeAst[length()-2];
+ for(int i=0;i<parameterTypes.length;++i)
+ parameterTypes[i] = (TypeAst)get(2+i);
+ return new ConstraintStatement((Token)get(1), parameterTypes);
+ }
+
+ @Override
+ protected Object reduceCHRQuery() {
+ ListQualifier[] query = new ListQualifier[(length()+1)/2];
+ for(int i=0;i<query.length;++i)
+ query[i] = (ListQualifier)get(i*2);
+ return query;
+ }
+
+ /*
+ @Override
+ protected Object reduceWhen() {
+ return new EWhen(
+ new QConjunction((Query[])get(1)),
+ (Expression)get(3));
+ }*/
+
+ @Override
+ protected Object reduceVerboseCHRQuery() {
+ ListQualifier[] query = new ListQualifier[(length()-1)/2];
+ for(int i=0;i<query.length;++i)
+ query[i] = (ListQualifier)get(i*2+1);
+ return query;
+ }
+
+ @Override
+ protected Object reduceVerboseCHRStatement() {
+ return new CHRStatement((ListQualifier[])get(1), (ListQualifier[])get(3));
+ }
+
}