Search in sources :

Example 11 with TypeCheckException

use of boa.compiler.TypeCheckException in project compiler by boalang.

the class TypeCheckingVisitor method visit.

//
// expressions
//
/** {@inheritDoc} */
@Override
public void visit(final Expression n, final SymbolTable env) {
    n.env = env;
    n.getLhs().accept(this, env);
    final BoaType ltype = n.getLhs().type;
    n.type = ltype;
    if (n.getRhsSize() > 0) {
        if (!(ltype instanceof BoaBool))
            throw new TypeCheckException(n.getLhs(), "incompatible types for disjunction: required 'bool', found '" + ltype + "'");
        for (final Conjunction c : n.getRhs()) {
            c.accept(this, env);
            if (!(c.type instanceof BoaBool))
                throw new TypeCheckException(c, "incompatible types for disjunction: required 'bool', found '" + c.type + "'");
        }
        n.type = new BoaBool();
    }
}
Also used : TypeCheckException(boa.compiler.TypeCheckException)

Example 12 with TypeCheckException

use of boa.compiler.TypeCheckException in project compiler by boalang.

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(final Comparison n, final SymbolTable env) {
    n.env = env;
    n.getLhs().accept(this, env);
    n.type = n.getLhs().type;
    if (n.hasRhs()) {
        n.getRhs().accept(this, env);
        if (!n.getRhs().type.compares(n.type))
            throw new TypeCheckException(n.getRhs(), "incompatible types for comparison: required '" + n.type + "', found '" + n.getRhs().type + "'");
        if (n.type instanceof BoaString || n.type instanceof BoaMap || n.type instanceof BoaSet || n.type instanceof BoaStack || !(n.type instanceof BoaScalar))
            if (!n.getOp().equals("==") && !n.getOp().equals("!="))
                throw new TypeCheckException(n.getLhs(), "invalid comparison operator '" + n.getOp() + "' for type '" + n.type + "'");
        n.type = new BoaBool();
    }
}
Also used : TypeCheckException(boa.compiler.TypeCheckException)

Example 13 with TypeCheckException

use of boa.compiler.TypeCheckException in project compiler by boalang.

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(final Component n, final SymbolTable env) {
    n.env = env;
    n.getType().accept(this, env);
    if (n.hasIdentifier()) {
        final String id = n.getIdentifier().getToken();
        if (!env.getShadowing()) {
            if (env.hasGlobal(id))
                throw new TypeCheckException(n.getIdentifier(), "name conflict: constant '" + id + "' already exists");
            if (env.hasLocal(id))
                throw new TypeCheckException(n.getIdentifier(), "variable '" + id + "' already declared as '" + env.get(id) + "'");
        }
        n.type = new BoaName(n.getType().type, n.getIdentifier().getToken());
        env.set(n.getIdentifier().getToken(), n.getType().type);
        n.getIdentifier().accept(this, env);
    } else {
        n.type = n.getType().type;
    }
}
Also used : TypeCheckException(boa.compiler.TypeCheckException)

Example 14 with TypeCheckException

use of boa.compiler.TypeCheckException in project compiler by boalang.

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(Start n, SymbolTable env) {
    n.env = env;
    super.visit(n, env);
    if (!hasEmit)
        throw new TypeCheckException(n, "No emit statements detected - there will be no output generated");
}
Also used : TypeCheckException(boa.compiler.TypeCheckException)

Example 15 with TypeCheckException

use of boa.compiler.TypeCheckException in project compiler by boalang.

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(final Selector n, final SymbolTable env) {
    n.env = env;
    final String selector = n.getId().getToken();
    BoaType type = env.getOperandType();
    if (type instanceof BoaProtoMap) {
        if (!((BoaProtoMap) type).hasAttribute(selector))
            throw new TypeCheckException(n.getId(), type + " has no member named '" + selector + "'");
    } else if (type instanceof BoaTuple) {
        if (!((BoaTuple) type).hasMember(selector))
            throw new TypeCheckException(n.getId(), "'" + type + "' has no member named '" + selector + "'");
        type = ((BoaTuple) type).getMember(selector);
        if (type instanceof BoaName)
            type = ((BoaName) type).getType();
    } else if (type instanceof BoaEnum) {
        if (!((BoaEnum) type).hasMember(selector))
            throw new TypeCheckException(n.getId(), "'" + type + "' has no member named '" + selector + "'");
        type = ((BoaEnum) type).getMember(selector);
    } else {
        throw new TypeCheckException(n, "invalid operand type '" + type + "' for member selection");
    }
    n.type = type;
}
Also used : TypeCheckException(boa.compiler.TypeCheckException)

Aggregations

TypeCheckException (boa.compiler.TypeCheckException)28 IOException (java.io.IOException)7 ST (org.stringtemplate.v4.ST)5 SymbolTable (boa.compiler.SymbolTable)4 AggregatorSpec (boa.aggregators.AggregatorSpec)2 VisitorDesugar (boa.compiler.transforms.VisitorDesugar)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1