Search in sources :

Example 1 with BLangEnumerator

use of org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator in project ballerina by ballerina-lang.

the class CodeGenerator method createEnumInfoEntry.

private void createEnumInfoEntry(BLangEnum enumNode) {
    BTypeSymbol enumSymbol = (BTypeSymbol) enumNode.symbol;
    // Add Enum name as an UTFCPEntry to the constant pool
    int enumNameCPIndex = addUTF8CPEntry(currentPkgInfo, enumSymbol.name.value);
    EnumInfo enumInfo = new EnumInfo(currentPackageRefCPIndex, enumNameCPIndex, enumSymbol.flags);
    currentPkgInfo.addEnumInfo(enumSymbol.name.value, enumInfo);
    enumInfo.enumType = (BEnumType) enumSymbol.type;
    for (int i = 0; i < enumNode.enumerators.size(); i++) {
        BLangEnumerator enumeratorNode = enumNode.enumerators.get(i);
        enumeratorNode.symbol.varIndex = new RegIndex(i, enumSymbol.type.tag);
        enumeratorNode.symbol.varIndex.isVarIndex = true;
        int enumeratorNameCPIndex = addUTF8CPEntry(currentPkgInfo, enumeratorNode.symbol.name.toString());
        EnumeratorInfo enumeratorInfo = new EnumeratorInfo(enumeratorNameCPIndex, i, enumInfo.enumType);
        enumInfo.enumeratorInfoList.add(enumeratorInfo);
    }
}
Also used : EnumInfo(org.wso2.ballerinalang.programfile.EnumInfo) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) EnumeratorInfo(org.wso2.ballerinalang.programfile.EnumeratorInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 2 with BLangEnumerator

use of org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator in project ballerina by ballerina-lang.

the class BLangPackageBuilder method addEnumerator.

public void addEnumerator(DiagnosticPos pos, Set<Whitespace> ws, String name) {
    BLangEnumerator enumerator = (BLangEnumerator) TreeBuilder.createEnumeratorNode();
    enumerator.pos = pos;
    enumerator.addWS(ws);
    enumerator.name = (BLangIdentifier) createIdentifier(name);
    enumeratorList.add(enumerator);
}
Also used : BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)

Example 3 with BLangEnumerator

use of org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangEnum enumNode) {
    BTypeSymbol enumSymbol = Symbols.createEnumSymbol(Flags.asMask(enumNode.flagSet), names.fromIdNode(enumNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    enumNode.symbol = enumSymbol;
    defineSymbol(enumNode.pos, enumSymbol);
    BEnumType enumType = new BEnumType(enumSymbol, null);
    enumSymbol.type = enumType;
    SymbolEnv enumEnv = SymbolEnv.createPkgLevelSymbolEnv(enumNode, enumSymbol.scope, this.env);
    for (int i = 0; i < enumNode.enumerators.size(); i++) {
        BLangEnumerator enumerator = enumNode.enumerators.get(i);
        BVarSymbol enumeratorSymbol = new BVarSymbol(Flags.PUBLIC, names.fromIdNode(enumerator.name), enumSymbol.pkgID, enumType, enumSymbol);
        enumeratorSymbol.docTag = DocTag.FIELD;
        enumerator.symbol = enumeratorSymbol;
        if (symResolver.checkForUniqueSymbol(enumerator.pos, enumEnv, enumeratorSymbol, enumeratorSymbol.tag)) {
            enumEnv.scope.define(enumeratorSymbol.name, enumeratorSymbol);
        }
    }
}
Also used : BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType)

Aggregations

BLangEnumerator (org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)3 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)1 BEnumType (org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType)1 EnumInfo (org.wso2.ballerinalang.programfile.EnumInfo)1 EnumeratorInfo (org.wso2.ballerinalang.programfile.EnumeratorInfo)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1