package carray.ast;

import polyglot.ast.Ext;
import polyglot.ast.Ext_c;
import polyglot.ast.Node;
import polyglot.util.InternalCompilerError;
import polyglot.util.SerialVersionUID;
import carray.visit.ArrayInitRemover;

public class CArrayExt extends Ext_c implements CArrayOps {
    private static final long serialVersionUID = SerialVersionUID.generate();

    public static CArrayExt ext(Node n) {
        Ext e = n.ext();
        while (e != null && !(e instanceof CArrayExt)) {
            e = e.ext();
        }
        if (e == null) {
            throw new InternalCompilerError("No CArray extension object for node "
                                                    + n
                                                    + " ("
                                                    + n.getClass()
                                                    + ")",
                                            n.position());
        }
        return (CArrayExt) e;
    }

    @Override
    public final CArrayLang lang() {
        return CArrayLang_c.instance;
    }

    @Override
    public ArrayInitRemover removeArrayInitEnter(ArrayInitRemover v) {
        // By default, return the given visitor.
        return v;
    }

    @Override
    public Node removeArrayInit(ArrayInitRemover v) {
        // By default, do nothing.
        return node();
    }
}
