Search in sources :

Example 11 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project ballerina by ballerina-lang.

the class PackageInfoWriter method writeCP.

public static void writeCP(DataOutputStream dataOutStream, ConstantPoolEntry[] constPool) throws IOException {
    dataOutStream.writeInt(constPool.length);
    for (ConstantPoolEntry cpEntry : constPool) {
        // Emitting the kind of the constant pool entry.
        dataOutStream.writeByte(cpEntry.getEntryType().getValue());
        int nameCPIndex;
        switch(cpEntry.getEntryType()) {
            case CP_ENTRY_UTF8:
                String stringVal = ((UTF8CPEntry) cpEntry).getValue();
                if (stringVal != null) {
                    byte[] bytes = toUTF(stringVal);
                    dataOutStream.writeShort(bytes.length);
                    dataOutStream.write(bytes);
                } else {
                    // If the string value is null, we write the size as -1.
                    // This marks that the value followed by -1 size is a null value.
                    dataOutStream.writeShort(NULL_VALUE_FIELD_SIZE_TAG);
                }
                break;
            case CP_ENTRY_INTEGER:
                long longVal = ((IntegerCPEntry) cpEntry).getValue();
                dataOutStream.writeLong(longVal);
                break;
            case CP_ENTRY_FLOAT:
                double doubleVal = ((FloatCPEntry) cpEntry).getValue();
                dataOutStream.writeDouble(doubleVal);
                break;
            case CP_ENTRY_STRING:
                nameCPIndex = ((StringCPEntry) cpEntry).getStringCPIndex();
                dataOutStream.writeInt(nameCPIndex);
                break;
            case CP_ENTRY_PACKAGE:
                nameCPIndex = ((PackageRefCPEntry) cpEntry).nameCPIndex;
                dataOutStream.writeInt(nameCPIndex);
                break;
            case CP_ENTRY_FUNCTION_REF:
                FunctionRefCPEntry funcRefEntry = (FunctionRefCPEntry) cpEntry;
                dataOutStream.writeInt(funcRefEntry.packageCPIndex);
                dataOutStream.writeInt(funcRefEntry.nameCPIndex);
                break;
            case CP_ENTRY_ACTION_REF:
                ActionRefCPEntry actionRefEntry = (ActionRefCPEntry) cpEntry;
                dataOutStream.writeInt(actionRefEntry.getPackageCPIndex());
                dataOutStream.writeInt(actionRefEntry.getNameCPIndex());
                break;
            case CP_ENTRY_STRUCTURE_REF:
                StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) cpEntry;
                dataOutStream.writeInt(structureRefCPEntry.packageCPIndex);
                dataOutStream.writeInt(structureRefCPEntry.nameCPIndex);
                break;
            case CP_ENTRY_TYPE_REF:
                TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
                dataOutStream.writeInt(typeRefCPEntry.typeSigCPIndex);
                break;
            case CP_ENTRY_FORK_JOIN:
                ForkJoinCPEntry forkJoinCPEntry = (ForkJoinCPEntry) cpEntry;
                dataOutStream.writeInt(forkJoinCPEntry.forkJoinInfoIndex);
                break;
            case CP_ENTRY_WRKR_DATA_CHNL_REF:
                WorkerDataChannelRefCPEntry workerDataChannelCPEntry = (WorkerDataChannelRefCPEntry) cpEntry;
                dataOutStream.writeInt(workerDataChannelCPEntry.getUniqueNameCPIndex());
                break;
            case CP_ENTRY_TRANSFORMER_REF:
                TransformerRefCPEntry transformerRefEntry = (TransformerRefCPEntry) cpEntry;
                dataOutStream.writeInt(transformerRefEntry.packageCPIndex);
                dataOutStream.writeInt(transformerRefEntry.nameCPIndex);
                break;
        }
    }
}
Also used : TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) ConstantPoolEntry(org.wso2.ballerinalang.programfile.cpentries.ConstantPoolEntry) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)

Example 12 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project ballerina by ballerina-lang.

the class CodeGenerator method createServiceInfoEntry.

private void createServiceInfoEntry(BLangService serviceNode) {
    // Add service name as an UTFCPEntry to the constant pool
    int serviceNameCPIndex = addUTF8CPEntry(currentPkgInfo, serviceNode.name.value);
    // Create service info
    if (serviceNode.endpointType != null) {
        String endPointQName = serviceNode.endpointType.tsymbol.toString();
        // TODO: bvmAlias needed?
        int epNameCPIndex = addUTF8CPEntry(currentPkgInfo, endPointQName);
        ServiceInfo serviceInfo = new ServiceInfo(currentPackageRefCPIndex, serviceNameCPIndex, serviceNode.symbol.flags, epNameCPIndex);
        // Add service level variables
        int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
        LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
        serviceNode.vars.forEach(var -> visitVarSymbol(var.var.symbol, pvIndexes, localVarAttributeInfo));
        serviceInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
        // Create the init function info
        BLangFunction serviceInitFunction = (BLangFunction) serviceNode.getInitFunction();
        createFunctionInfoEntry(serviceInitFunction);
        serviceInfo.initFuncInfo = currentPkgInfo.functionInfoMap.get(serviceInitFunction.name.toString());
        currentPkgInfo.addServiceInfo(serviceNode.name.value, serviceInfo);
        // Create resource info entries for all resources
        serviceNode.resources.forEach(res -> createResourceInfoEntry(res, serviceInfo));
    }
}
Also used : ServiceInfo(org.wso2.ballerinalang.programfile.ServiceInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 13 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.CODE_GEN)) {
        if (!buildCompiledPackage) {
            programFile.packageInfoMap.put(pkgNode.symbol.pkgID.bvmAlias(), pkgNode.symbol.packageInfo);
        }
        return;
    }
    // TODO Improve this design without if/else
    PackageInfo packageInfo = new PackageInfo();
    pkgNode.symbol.packageInfo = packageInfo;
    if (buildCompiledPackage) {
        // Generating the BALO
        pkgNode.imports.forEach(impPkgNode -> {
            int impPkgNameCPIndex = addUTF8CPEntry(packageInfo, impPkgNode.symbol.name.value);
            // TODO Improve the import package version once it is available
            int impPkgVersionCPIndex = addUTF8CPEntry(packageInfo, PackageID.DEFAULT.version.value);
            ImportPackageInfo importPkgInfo = new ImportPackageInfo(impPkgNameCPIndex, impPkgVersionCPIndex);
            packageInfo.importPkgInfoSet.add(importPkgInfo);
            packageFile.packageInfo = packageInfo;
        });
    } else {
        // Generating a BALX
        // first visit all the imports
        pkgNode.imports.forEach(impPkgNode -> genNode(impPkgNode, this.env));
        // TODO We need to create identifier for both name and the version
        programFile.packageInfoMap.put(pkgNode.symbol.pkgID.bvmAlias(), packageInfo);
    }
    // Add the current package to the program file
    BPackageSymbol pkgSymbol = pkgNode.symbol;
    currentPkgID = pkgSymbol.pkgID;
    currentPkgInfo = packageInfo;
    currentPkgInfo.nameCPIndex = addUTF8CPEntry(currentPkgInfo, currentPkgID.bvmAlias());
    currentPkgInfo.versionCPIndex = addUTF8CPEntry(currentPkgInfo, currentPkgID.version.value);
    // Insert the package reference to the constant pool of the current package
    currentPackageRefCPIndex = addPackageRefCPEntry(currentPkgInfo, currentPkgID);
    // This attribute keep track of line numbers
    int lineNoAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE.value());
    lineNoAttrInfo = new LineNumberTableAttributeInfo(lineNoAttrNameIndex);
    // This attribute keep package-level variable information
    int pkgVarAttrNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
    currentPkgInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, new LocalVariableAttributeInfo(pkgVarAttrNameIndex));
    pkgNode.globalVars.forEach(this::createPackageVarInfo);
    pkgNode.structs.forEach(this::createStructInfoEntry);
    pkgNode.enums.forEach(this::createEnumInfoEntry);
    pkgNode.connectors.forEach(this::createConnectorInfoEntry);
    pkgNode.functions.forEach(this::createFunctionInfoEntry);
    pkgNode.services.forEach(this::createServiceInfoEntry);
    pkgNode.functions.forEach(this::createFunctionInfoEntry);
    pkgNode.transformers.forEach(this::createTransformerInfoEntry);
    // Visit package builtin function
    visitBuiltinFunctions(pkgNode.initFunction);
    visitBuiltinFunctions(pkgNode.startFunction);
    visitBuiltinFunctions(pkgNode.stopFunction);
    pkgNode.topLevelNodes.stream().filter(pkgLevelNode -> pkgLevelNode.getKind() != NodeKind.VARIABLE && pkgLevelNode.getKind() != NodeKind.XMLNS).forEach(pkgLevelNode -> genNode((BLangNode) pkgLevelNode, this.env));
    currentPkgInfo.addAttributeInfo(AttributeInfo.Kind.LINE_NUMBER_TABLE_ATTRIBUTE, lineNoAttrInfo);
    currentPackageRefCPIndex = -1;
    currentPkgID = null;
    pkgNode.completedPhases.add(CompilerPhase.CODE_GEN);
}
Also used : BLangMapLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangMapLiteral) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) REF_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.REF_OFFSET) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangXMLTextLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLTextLiteral) Map(java.util.Map) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex) SymbolKind(org.ballerinalang.model.symbols.SymbolKind) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) PackageVarInfo(org.wso2.ballerinalang.programfile.PackageVarInfo) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) AttributeInfo(org.wso2.ballerinalang.programfile.attributes.AttributeInfo) TypeDescriptor(org.wso2.ballerinalang.compiler.util.TypeDescriptor) PackageID(org.ballerinalang.model.elements.PackageID) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangArrayAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangArrayAccessExpr) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) BLangAnnotAttachmentAttributeValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAttachmentAttributeValue) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangXMLCommentLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLCommentLiteral) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) BLangFunctionVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFunctionVarRef) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) TreeBuilder(org.ballerinalang.model.TreeBuilder) ErrorTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ErrorTableAttributeInfo) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangUnaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangUnaryExpr) PackageFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.PackageFile) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) REG(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG) BLangPackageXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangPackageXMLNS) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) BLangStructFieldAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangStructFieldAccessExpr) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) FIELD(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD) BOOL_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.BOOL_OFFSET) BLangBracedOrTupleExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBracedOrTupleExpr) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangAttachedFunctionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangAttachedFunctionInvocation) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) ForkjoinInfo(org.wso2.ballerinalang.programfile.ForkjoinInfo) Name(org.ballerinalang.model.Name) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) PACKAGE(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.PACKAGE) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangTransformerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangTransformerInvocation) BLangIsAssignableExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIsAssignableExpr) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) ProgramFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) InstructionCodes(org.wso2.ballerinalang.programfile.InstructionCodes) BLangActionInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BLangActionInvocation) Instruction(org.wso2.ballerinalang.programfile.Instruction) Entry(java.util.Map.Entry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangXMLSequenceLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLSequenceLiteral) AttributeInfoPool(org.wso2.ballerinalang.programfile.attributes.AttributeInfoPool) TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) BLangJSONArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral.BLangJSONArrayLiteral) BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr) InstructionFactory(org.wso2.ballerinalang.programfile.InstructionFactory) BLangRecordKeyValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) BLangFieldVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangFieldVarRef) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) FieldType(org.wso2.ballerinalang.compiler.util.FieldType) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) StringCPEntry(org.wso2.ballerinalang.programfile.cpentries.StringCPEntry) Arrays(java.util.Arrays) BLangStreamLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStreamLiteral) BMapType(org.wso2.ballerinalang.compiler.semantics.model.types.BMapType) BLangTableLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangTableLiteral) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangAnnotAttachmentAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangAnnotAttachmentAttribute) StructInfo(org.wso2.ballerinalang.programfile.StructInfo) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr) BLangEnumeratorAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess.BLangEnumeratorAccessExpr) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) STRING_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.STRING_OFFSET) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) ErrorTableEntry(org.wso2.ballerinalang.programfile.ErrorTableEntry) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction) BLangStructLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangStructLiteral) ConstantPool(org.wso2.ballerinalang.programfile.cpentries.ConstantPool) ResourceInfo(org.wso2.ballerinalang.programfile.ResourceInfo) CodeAttributeInfo(org.wso2.ballerinalang.programfile.attributes.CodeAttributeInfo) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) BLangLocalXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS.BLangLocalXMLNS) ServiceInfo(org.wso2.ballerinalang.programfile.ServiceInfo) BLangPackageVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangPackageVarRef) ArrayList(java.util.ArrayList) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) StructFieldInfo(org.wso2.ballerinalang.programfile.StructFieldInfo) BArrayType(org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLProcInsLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLProcInsLiteral) EnumInfo(org.wso2.ballerinalang.programfile.EnumInfo) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangForever(org.wso2.ballerinalang.compiler.tree.statements.BLangForever) ActionInfo(org.wso2.ballerinalang.programfile.ActionInfo) BLangJSONAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangJSONAccessExpr) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) EnumeratorInfo(org.wso2.ballerinalang.programfile.EnumeratorInfo) BLangXMLAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangXMLAccessExpr) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) INT_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.INT_OFFSET) BLangTypeConversionExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) FunctionFlags(org.ballerinalang.util.FunctionFlags) BLangXMLAttributeAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttributeAccess) LineNumberInfo(org.wso2.ballerinalang.programfile.LineNumberInfo) TransactionStatus(org.ballerinalang.util.TransactionStatus) TransformerInfo(org.wso2.ballerinalang.programfile.TransformerInfo) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) OperatorKind(org.ballerinalang.model.tree.OperatorKind) BLangFail(org.wso2.ballerinalang.compiler.tree.statements.BLangFail) BLangJSONLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangJSONLiteral) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) BLangRecordKey(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKey) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) BLOB_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.BLOB_OFFSET) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) FLOAT_OFFSET(org.wso2.ballerinalang.programfile.ProgramFileConstants.FLOAT_OFFSET) DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) Optional(java.util.Optional) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) LOCAL(org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.LOCAL) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BFunctionPointerInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.BFunctionPointerInvocation) BLangTypeofExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) CallableUnitInfo(org.wso2.ballerinalang.programfile.CallableUnitInfo) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) PackageRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.PackageRefCPEntry) BLangStringTemplateLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangStringTemplateLiteral) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangIntRangeExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangIntRangeExpression) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) XMLConstants(javax.xml.XMLConstants) BLangMapAccessExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess.BLangMapAccessExpr) VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangAwaitExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangAwaitExpr) BLangXMLElementLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) LineNumberTableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LineNumberTableAttributeInfo) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) ImportPackageInfo(org.wso2.ballerinalang.programfile.ImportPackageInfo) PackageInfo(org.wso2.ballerinalang.programfile.PackageInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 14 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project ballerina by ballerina-lang.

the class CodeGenerator method createActionInfoEntry.

private void createActionInfoEntry(BLangAction actionNode, ConnectorInfo connectorInfo) {
    BInvokableSymbol actionSymbol = actionNode.symbol;
    BInvokableType actionType = (BInvokableType) actionSymbol.type;
    // Add action name as an UTFCPEntry to the constant pool
    int actionNameCPIndex = addUTF8CPEntry(currentPkgInfo, actionNode.name.value);
    ActionInfo actionInfo = new ActionInfo(currentPackageRefCPIndex, actionNameCPIndex);
    actionInfo.paramTypes = actionType.paramTypes.toArray(new BType[0]);
    actionInfo.retParamTypes = actionType.retTypes.toArray(new BType[0]);
    actionInfo.flags = actionSymbol.flags;
    // setParameterNames(actionNode, actionInfo);
    actionInfo.signatureCPIndex = addUTF8CPEntry(currentPkgInfo, generateFunctionSig(actionInfo.paramTypes, actionInfo.retParamTypes));
    // Add worker info
    this.addWorkerInfoEntries(actionInfo, actionNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(actionNode, actionInfo);
    // Add action info to the connector info
    connectorInfo.actionInfoMap.put(actionNode.name.getValue(), actionInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) ActionInfo(org.wso2.ballerinalang.programfile.ActionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 15 with Constant

use of org.wso2.siddhi.query.api.expression.constant.Constant in project ballerina by ballerina-lang.

the class CodeGenerator method createFunctionInfoEntry.

/**
 * Creates a {@code FunctionInfo} from the given function node in AST.
 *
 * @param funcNode function node in AST
 */
private void createFunctionInfoEntry(BLangFunction funcNode) {
    BInvokableSymbol funcSymbol = funcNode.symbol;
    BInvokableType funcType = (BInvokableType) funcSymbol.type;
    // Add function name as an UTFCPEntry to the constant pool
    int funcNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, funcNode.name.value);
    FunctionInfo funcInfo = new FunctionInfo(currentPackageRefCPIndex, funcNameCPIndex);
    funcInfo.paramTypes = funcType.paramTypes.toArray(new BType[0]);
    funcInfo.retParamTypes = funcType.retTypes.toArray(new BType[0]);
    funcInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(funcInfo.paramTypes, funcInfo.retParamTypes));
    funcInfo.flags = funcSymbol.flags;
    if (funcNode.receiver != null) {
        funcInfo.attachedToTypeCPIndex = getTypeCPIndex(funcNode.receiver.type).value;
    }
    this.addWorkerInfoEntries(funcInfo, funcNode.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(funcNode, funcInfo);
    this.currentPkgInfo.functionInfoMap.put(funcSymbol.name.value, funcInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) AttachedFunctionInfo(org.wso2.ballerinalang.programfile.AttachedFunctionInfo) FunctionInfo(org.wso2.ballerinalang.programfile.FunctionInfo) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)10 Test (org.testng.annotations.Test)9 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)8 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)7 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)7 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)5 ArrayList (java.util.ArrayList)4 CompileResult (org.ballerinalang.launcher.util.CompileResult)4 PackageNode (org.ballerinalang.model.tree.PackageNode)4 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)4 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)4 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)4 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)3 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)3 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)3 Variable (org.wso2.siddhi.query.api.expression.Variable)3 BoolConstant (org.wso2.siddhi.query.api.expression.constant.BoolConstant)3 Constant (org.wso2.siddhi.query.api.expression.constant.Constant)3 DoubleConstant (org.wso2.siddhi.query.api.expression.constant.DoubleConstant)3