use of mb.nabl2.solver.TypeException in project nabl by metaborg.
the class ScopeGraphComponent method solve.
private boolean solve(CGExportEdge c) {
ITerm scopeTerm = unifier().findRecursive(c.getScope());
ITerm declTerm = unifier().findRecursive(c.getDeclaration());
if (!(scopeTerm.isGround() && declTerm.isGround())) {
return false;
}
Scope scope = Scope.matcher().match(scopeTerm, unifier()).orElseThrow(() -> new TypeException("Expected a scope as third argument to " + c));
Occurrence decl = Occurrence.matcher().match(declTerm, unifier()).orElseThrow(() -> new TypeException("Expected an occurrence as first argument to " + c));
scopeGraph.addExportEdge(decl, c.getLabel(), scope);
return true;
}
use of mb.nabl2.solver.TypeException in project nabl by metaborg.
the class ScopeGraphComponent method solve.
private boolean solve(CGDirectEdge c) {
ITerm sourceScopeRep = unifier().findRecursive(c.getSourceScope());
if (!sourceScopeRep.isGround()) {
return false;
}
Scope sourceScope = Scope.matcher().match(sourceScopeRep, unifier()).orElseThrow(() -> new TypeException("Expected a scope but got " + sourceScopeRep));
return findScope(c.getTargetScope()).map(targetScope -> {
scopeGraph.addDirectEdge(sourceScope, c.getLabel(), targetScope);
return true;
}).orElseGet(() -> {
scopeGraph.addIncompleteDirectEdge(sourceScope, c.getLabel(), c.getTargetScope());
return true;
});
}
use of mb.nabl2.solver.TypeException in project nabl by metaborg.
the class NameResolutionComponent method solve.
private Optional<SolveResult> solve(CDeclProperty c) {
final ITerm declTerm = unifier().findRecursive(c.getDeclaration());
if (!declTerm.isGround()) {
return Optional.empty();
}
final Occurrence decl = Occurrence.matcher().match(declTerm, unifier()).orElseThrow(() -> new TypeException("Expected an occurrence as first argument to " + c));
final SolveResult result = putProperty(decl, c.getKey(), c.getValue(), c.getMessageInfo()).map(cc -> SolveResult.constraints(cc)).orElseGet(() -> SolveResult.empty());
return Optional.of(result);
}
use of mb.nabl2.solver.TypeException in project nabl by metaborg.
the class PolymorphismComponent method solve.
// ------------------------------------------------------------------------------------------------------//
private Optional<SolveResult> solve(CGeneralize gen) {
final ITerm declTerm = unifier().findRecursive(gen.getDeclaration());
if (!declTerm.isGround()) {
return Optional.empty();
}
final Occurrence decl = Occurrence.matcher().match(declTerm, unifier()).orElseThrow(() -> new TypeException("Expected an occurrence as first argument to " + gen));
final ITerm type = gen.getType();
if (!isGenSafe.test(type)) {
return Optional.empty();
}
// linked map to preserve key order
final Map<ITermVar, TypeVar> subst = Maps.newLinkedHashMap();
final ITerm scheme;
{
int c = 0;
for (ITermVar var : type.getVars()) {
subst.put(var, ImmutableTypeVar.of("T" + (++c)));
}
scheme = subst.isEmpty() ? type : ImmutableForall.of(subst.values(), subst(type, subst));
}
SolveResult result = SolveResult.constraints(// @formatter:off
ImmutableCDeclProperty.of(decl, DeclProperties.TYPE_KEY, scheme, 0, gen.getMessageInfo()), ImmutableCEqual.of(gen.getGenVars(), B.newList(subst.keySet()), gen.getMessageInfo()));
return Optional.of(result);
}
use of mb.nabl2.solver.TypeException in project nabl by metaborg.
the class ScopeGraphComponent method solve.
private boolean solve(CGRef c) {
final ITerm scopeTerm = unifier().findRecursive((c.getScope()));
final ITerm refTerm = unifier().findRecursive((c.getReference()));
if (!(scopeTerm.isGround() && refTerm.isGround())) {
return false;
}
Occurrence ref = Occurrence.matcher().match(refTerm, unifier()).orElseThrow(() -> new TypeException("Expected an occurrence as first argument to " + c));
Scope scope = Scope.matcher().match(scopeTerm, unifier()).orElseThrow(() -> new TypeException("Expected a scope as second argument to " + c));
scopeGraph.addRef(ref, scope);
return true;
}
Aggregations