Search in sources :

Example 1 with SymbolTable

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

the class VisitorMergingTransformer method preProcessProgram.

protected void preProcessProgram(final Program p) {
    stopTransform.start(p);
    // FIXME rdyer need to figure out how to avoid this, but anything
    // new in the transformations needs added to the environment
    typeChecker.start(p, new SymbolTable());
    varRename.start(p, p.jobName);
}
Also used : SymbolTable(boa.compiler.SymbolTable)

Example 2 with SymbolTable

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

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(final DoStatement n, final SymbolTable env) {
    SymbolTable st;
    try {
        st = env.cloneNonLocals();
    } catch (final IOException e) {
        throw new RuntimeException(e.getClass().getSimpleName() + " caught", e);
    }
    n.env = st;
    n.getCondition().accept(this, st);
    n.getBody().accept(this, st);
}
Also used : SymbolTable(boa.compiler.SymbolTable) IOException(java.io.IOException)

Example 3 with SymbolTable

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

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(final VisitStatement n, final SymbolTable env) {
    SymbolTable st;
    try {
        st = env.cloneNonLocals();
    } catch (final IOException e) {
        throw new RuntimeException(e.getClass().getSimpleName() + " caught", e);
    }
    n.env = st;
    if (n.hasComponent()) {
        st.setShadowing(true);
        n.getComponent().accept(this, st);
        if (n.getComponent().type instanceof BoaName)
            n.getComponent().type = n.getComponent().getType().type;
        st.setShadowing(false);
    } else if (!n.hasWildcard())
        for (final Identifier id : n.getIdList()) {
            if (SymbolTable.getType(id.getToken()) == null)
                throw new TypeCheckException(id, "Invalid type '" + id.getToken() + "'");
            id.accept(this, st);
        }
    st.setIsVisitor(true);
    n.getBody().accept(this, st);
    st.unsetIsVisitor();
}
Also used : SymbolTable(boa.compiler.SymbolTable) IOException(java.io.IOException) TypeCheckException(boa.compiler.TypeCheckException)

Example 4 with SymbolTable

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

the class TypeCheckingVisitor method visit.

/** {@inheritDoc} */
@Override
public void visit(final Block n, final SymbolTable env) {
    SymbolTable st;
    try {
        st = env.cloneNonLocals();
    } catch (final IOException e) {
        throw new RuntimeException(e.getClass().getSimpleName() + " caught", e);
    }
    n.env = st;
    for (final Node s : n.getStatements()) s.accept(this, st);
}
Also used : SymbolTable(boa.compiler.SymbolTable) IOException(java.io.IOException)

Example 5 with SymbolTable

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

the class TypeCheckingVisitor method checkQuantifier.

protected Expression checkQuantifier(final Node n, final Component c, Expression e, final Block b, final String kind, final SymbolTable env) {
    SymbolTable st;
    try {
        st = env.cloneNonLocals();
    } catch (final IOException ex) {
        throw new RuntimeException(e.getClass().getSimpleName() + " caught", ex);
    }
    n.env = st;
    c.accept(this, st);
    e.accept(this, st);
    if (!(e.type instanceof BoaBool)) {
        e = new Expression(new Conjunction(new Comparison(new SimpleExpr(new Term(new Factor(new Identifier("def")).addOp(new Call().addArg(e.clone())))))));
        e.accept(this, st);
    }
    if (n instanceof IfAllStatement)
        b.accept(this, env);
    else
        b.accept(this, st);
    return e;
}
Also used : SymbolTable(boa.compiler.SymbolTable) IOException(java.io.IOException)

Aggregations

SymbolTable (boa.compiler.SymbolTable)13 IOException (java.io.IOException)12 TypeCheckException (boa.compiler.TypeCheckException)4 TypeCheckingVisitor (boa.compiler.visitors.TypeCheckingVisitor)1 StartContext (boa.parser.BoaParser.StartContext)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1