Thursday, May 21, 2015

Log 052115 - b

Mightily pleased with myself. My first transform on the AST. Lightning speed.

class RewriteBind: public Rewrite<AstPtr> {
public:
    RewriteBind(): Rewrite(AstEmpty().clone()) {
    }

    void clear_state() {
        set_state(AstEmpty().clone());
    }

    AstPtr rewrite_decl_type(const Position& p, const AstPtr& n, const AstPtr& t) {
        set_state(n);
        auto t0 = rewrite(t);
        clear_state();
        return AstDeclType(p, n, t0).clone();
    }

    AstPtr rewrite_expr_record(const Position& p, const AstPtr& f, const AstPtr& i, const AstPtrs& aa) {
        auto i0 = get_state();
        return AstExprRecord(p, f, i0, aa).clone();
    }

    AstPtr rewrite_decl_interface(const Position& p, const AstPtr& n, const AstPtr& t) {
        set_state(n);
        auto t0 = rewrite(t);
        clear_state();
        return AstDeclInterface(p, n, t0).clone();
    }

    AstPtr rewrite_decl_instance(const Position& p, const AstPtr& pr, const AstPtr& t, const AstPtr& b) {
        set_state(t);
        auto b0 = rewrite(b);
        clear_state();
        return AstDeclInstance(p, pr, t, b0).clone();
    }

    AstPtr rewrite_decl_method(const Position& p, const AstPtr& n, const AstPtr& i, const AstPtr& t, const AstPtr& e) {
        auto i0 = get_state();
        return AstDeclMethod(p, n, i0, t, e).clone();
    }

    AstPtr rewrite_decl_definition(const Position& p, const AstPtr& n, const AstPtr& t, const AstPtr& e) {
        return AstDeclDefinition(p, n, t, e).clone(); // cut
    }
};

No comments:

Post a Comment