001package gudusoft.gsqlparser.ir.bound;
002
003import gudusoft.gsqlparser.ir.common.IRNode;
004import gudusoft.gsqlparser.ir.common.IRNodeKind;
005import gudusoft.gsqlparser.ir.common.IRVisitor;
006
007import java.util.Collections;
008import java.util.List;
009
010/**
011 * A type reference in the bound IR.
012 * Represents scalar types, %TYPE, %ROWTYPE, RECORD, TABLE OF, VARRAY, etc.
013 */
014public class BoundTypeRef extends IRNode {
015
016    private final String typeName;
017    private final ETypeCategory category;
018    private final List<BoundTypeRef> typeArguments;
019
020    /** %TYPE reference: column whose type is being referenced. */
021    private final BoundColumnRef anchorColumn;
022
023    /** %ROWTYPE reference: table/cursor whose row type is being referenced. */
024    private final BoundObjectRef anchorTable;
025
026    public BoundTypeRef(String typeName, ETypeCategory category) {
027        this(typeName, category, null, null, null);
028    }
029
030    public BoundTypeRef(String typeName, ETypeCategory category,
031                        List<BoundTypeRef> typeArguments,
032                        BoundColumnRef anchorColumn,
033                        BoundObjectRef anchorTable) {
034        this.typeName = typeName;
035        this.category = category;
036        this.typeArguments = typeArguments != null
037                ? Collections.unmodifiableList(typeArguments)
038                : Collections.<BoundTypeRef>emptyList();
039        this.anchorColumn = anchorColumn;
040        this.anchorTable = anchorTable;
041    }
042
043    public String getTypeName() { return typeName; }
044    public ETypeCategory getCategory() { return category; }
045    public List<BoundTypeRef> getTypeArguments() { return typeArguments; }
046    public BoundColumnRef getAnchorColumn() { return anchorColumn; }
047    public BoundObjectRef getAnchorTable() { return anchorTable; }
048
049    @Override
050    public IRNodeKind getKind() {
051        return IRNodeKind.BOUND_TYPE_REF;
052    }
053
054    @Override
055    public <R, C> R accept(IRVisitor<R, C> visitor, C context) {
056        return visitor.visitBoundTypeRef(this, context);
057    }
058
059    @Override
060    public String toString() {
061        return "BoundTypeRef{" + typeName + ", " + category + "}";
062    }
063}