Search in sources :

Example 11 with BLangInvokableNode

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

the class CodeGenerator method createTransformerInfoEntry.

private void createTransformerInfoEntry(BLangInvokableNode invokable) {
    BInvokableSymbol transformerSymbol = invokable.symbol;
    BInvokableType transformerType = (BInvokableType) transformerSymbol.type;
    // Add transformer name as an UTFCPEntry to the constant pool
    int transformerNameCPIndex = this.addUTF8CPEntry(currentPkgInfo, transformerSymbol.name.value);
    TransformerInfo transformerInfo = new TransformerInfo(currentPackageRefCPIndex, transformerNameCPIndex);
    transformerInfo.paramTypes = transformerType.paramTypes.toArray(new BType[0]);
    transformerInfo.retParamTypes = transformerType.retTypes.toArray(new BType[0]);
    transformerInfo.flags = transformerSymbol.flags;
    this.addWorkerInfoEntries(transformerInfo, invokable.getWorkers());
    // Add parameter default value info
    addParameterDefaultValues(invokable, transformerInfo);
    transformerInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateFunctionSig(transformerInfo.paramTypes, transformerInfo.retParamTypes));
    this.currentPkgInfo.transformerInfoMap.put(transformerSymbol.name.value, transformerInfo);
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) TransformerInfo(org.wso2.ballerinalang.programfile.TransformerInfo)

Example 12 with BLangInvokableNode

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

the class EndpointDesugar method rewriteEndpoint.

void rewriteEndpoint(BLangEndpoint endpoint, SymbolEnv env) {
    final BSymbol encSymbol, varSymbol;
    final BLangBlockStmt initBlock, startBlock;
    BLangBlockStmt stopBlock = null;
    if (env.enclInvokable != null) {
        // Function, Action, Resource. Code generate to its body directly.
        encSymbol = varSymbol = env.enclInvokable.symbol;
        initBlock = startBlock = ((BLangInvokableNode) env.node).body;
    } else if (env.enclService != null) {
        encSymbol = env.enclService.symbol;
        varSymbol = ((BLangService) env.node).initFunction.symbol;
        initBlock = startBlock = ((BLangService) env.node).initFunction.body;
    } else {
        // Pkg level endpoint.
        encSymbol = env.enclPkg.symbol;
        varSymbol = ((BLangPackage) env.node).initFunction.symbol;
        initBlock = ((BLangPackage) env.node).initFunction.body;
        startBlock = ((BLangPackage) env.node).startFunction.body;
        stopBlock = ((BLangPackage) env.node).stopFunction.body;
    }
    BLangBlockStmt genInit, genInitCall, genStartCall, genStopCall;
    genInit = generateEndpointInit(endpoint, env, encSymbol);
    genInitCall = generateEndpointInitFunctionCall(endpoint, env, encSymbol, varSymbol);
    genStartCall = generateEndpointStartOrStop(endpoint, endpoint.symbol.startFunction, env, encSymbol);
    genStopCall = generateEndpointStartOrStop(endpoint, endpoint.symbol.stopFunction, env, encSymbol);
    if (env.enclInvokable != null) {
        ASTBuilderUtil.prependStatements(genStartCall, startBlock);
        ASTBuilderUtil.prependStatements(genInitCall, initBlock);
        // TODO : Implement stop.
        ASTBuilderUtil.prependStatements(genInit, initBlock);
    } else if (env.enclService != null) {
        ASTBuilderUtil.appendStatements(genInit, initBlock);
        ASTBuilderUtil.appendStatements(genInitCall, initBlock);
        ASTBuilderUtil.appendStatements(genStartCall, startBlock);
    // TODO : Implement stop.
    } else {
        ASTBuilderUtil.appendStatements(genInit, initBlock);
        ASTBuilderUtil.appendStatements(genInitCall, initBlock);
        ASTBuilderUtil.appendStatements(genStartCall, startBlock);
        ASTBuilderUtil.appendStatements(genStopCall, Objects.requireNonNull(stopBlock));
    }
}
Also used : BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)4 TaintRecord (org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord)3 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BLangReturn (org.wso2.ballerinalang.compiler.tree.statements.BLangReturn)2 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)2 LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)2 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 XMLConstants (javax.xml.XMLConstants)1 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)1 TreeBuilder (org.ballerinalang.model.TreeBuilder)1