protected void insertCompilationUnitMessages(boolean insertErrors, IList otherMessages) { org.rascalmpl.value.type.Type args = TF.tupleType(TF.stringType(), TF.sourceLocationType()); IValueList result = new IValueList(values); if (otherMessages != null) { for (IValue message : otherMessages) { result.add(message); } } if (insertErrors) { int i; IProblem[] problems = compilUnit.getProblems(); for (i = 0; i < problems.length; i++) { int offset = problems[i].getSourceStart(); int length = problems[i].getSourceEnd() - offset + 1; int sl = problems[i].getSourceLineNumber(); ISourceLocation pos = values.sourceLocation(loc, offset, length, sl, sl, 0, 0); org.rascalmpl.value.type.Type constr; if (problems[i].isError()) { constr = typeStore.lookupConstructor( this.typeStore.lookupAbstractDataType("Message"), "error", args); } else { constr = typeStore.lookupConstructor( this.typeStore.lookupAbstractDataType("Message"), "warning", args); } result.add(values.constructor(constr, values.string(problems[i].getMessage()), pos)); } } setAnnotation("messages", result.asList()); }
@Override public Type getKeywordArgumentTypes(Environment scope) { ArrayList<String> labels = new ArrayList<>(); ArrayList<Type> types = new ArrayList<>(); // TODO: I am not sure this is what we want. Double names will end up twice in the tuple type... for (AbstractFunction c : primaryCandidates) { Type args = c.getKeywordArgumentTypes(scope); if (args != null && args.hasFieldNames()) { for (String label : args.getFieldNames()) { labels.add(label); types.add(args.getFieldType(label)); } } } for (AbstractFunction c : defaultCandidates) { Type args = c.getKeywordArgumentTypes(scope); if (args != null && args.hasFieldNames()) { for (String label : args.getFieldNames()) { labels.add(label); types.add(args.getFieldType(label)); } } } return TF.tupleType( types.toArray(new Type[types.size()]), labels.toArray(new String[labels.size()])); }
public static IList compose(IList rel1, IList rel2) { Type otherTupleType = rel2.getType().getFieldTypes(); if (rel1.getElementType() == voidType) return rel1; if (otherTupleType == voidType) return rel2; if (rel1.getElementType().getArity() != 2 || otherTupleType.getArity() != 2) throw new IllegalOperationException("compose", rel1.getElementType(), otherTupleType); // Relaxed type constraint: if (!rel1.getElementType().getFieldType(1).comparable(otherTupleType.getFieldType(0))) throw new IllegalOperationException("compose", rel1.getElementType(), otherTupleType); Type[] newTupleFieldTypes = new Type[] {rel1.getElementType().getFieldType(0), otherTupleType.getFieldType(1)}; Type tupleType = typeFactory.tupleType(newTupleFieldTypes); IListWriter w = new ListWriter(tupleType); for (IValue v1 : rel1) { ITuple tuple1 = (ITuple) v1; for (IValue t2 : rel2) { ITuple tuple2 = (ITuple) t2; if (tuple1.get(1).isEqual(tuple2.get(0))) { w.append(Tuple.newTuple(tuple1.get(0), tuple2.get(1))); } } } return w.done(); }
protected IValue constructTypeNode(String constructor, IValue... children) { org.rascalmpl.value.type.Type args = TF.tupleType(removeNulls(children)); org.rascalmpl.value.type.Type constr = typeStore.lookupConstructor(DATATYPE_RASCAL_AST_TYPE_NODE_TYPE, constructor, args); return values.constructor(constr, removeNulls(children)); }