Search in sources :

Example 56 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class CodeGenerator method visitXMLTagName.

/**
 * Visit XML tag name and return the index of the tag name in the reference registry.
 *
 * @param tagName           Tag name expression
 * @param xmlElementEnv     Environment of the XML element of the tag
 * @param xmlElementLiteral XML element literal to which the tag name belongs to
 * @return Index of the tag name, in the reference registry
 */
private RegIndex visitXMLTagName(BLangExpression tagName, SymbolEnv xmlElementEnv, BLangXMLElementLiteral xmlElementLiteral) {
    genNode(tagName, xmlElementEnv);
    RegIndex startTagNameRegIndex = tagName.regIndex;
    // If this is a string representation of element name, generate the namespace lookup instructions
    if (tagName.getKind() != NodeKind.XML_QNAME) {
        RegIndex localNameRegIndex = getRegIndex(TypeTags.STRING);
        RegIndex uriRegIndex = getRegIndex(TypeTags.STRING);
        emit(InstructionCodes.S2QNAME, startTagNameRegIndex, localNameRegIndex, uriRegIndex);
        startTagNameRegIndex = getRegIndex(TypeTags.XML);
        generateURILookupInstructions(xmlElementLiteral.namespacesInScope, localNameRegIndex, uriRegIndex, startTagNameRegIndex, xmlElementLiteral.pos, xmlElementEnv);
        tagName.regIndex = startTagNameRegIndex;
    }
    return startTagNameRegIndex;
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 57 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangTransformer transformerNode) {
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, this.env);
    currentCallableUnitInfo = currentPkgInfo.transformerInfoMap.get(transformerNode.symbol.name.value);
    visitInvokableNode(transformerNode, currentCallableUnitInfo, transformerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 58 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class CodeGenerator method processTimeoutBlock.

/* generate code for timeout block */
private void processTimeoutBlock(BLangForkJoin forkJoin, SymbolEnv forkJoinEnv, RegIndex timeoutVarRegIndex, Operand timeoutBlockAddr) {
    /* emit a GOTO instruction to jump out of the timeout block */
    Operand gotoAddr = getOperand(-1);
    this.emit(InstructionCodes.GOTO, gotoAddr);
    timeoutBlockAddr.value = nextIP();
    if (forkJoin.timeoutVariable != null) {
        visitForkJoinParameterDefs(forkJoin.timeoutVariable, forkJoinEnv);
        timeoutVarRegIndex.value = forkJoin.timeoutVariable.symbol.varIndex.value;
    }
    if (forkJoin.timeoutBody != null) {
        this.genNode(forkJoin.timeoutBody, forkJoinEnv);
    }
    gotoAddr.value = nextIP();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Example 59 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangFunction funcNode) {
    SymbolEnv funcEnv = SymbolEnv.createFunctionEnv(funcNode, funcNode.symbol.scope, this.env);
    currentCallableUnitInfo = currentPkgInfo.functionInfoMap.get(funcNode.symbol.name.value);
    visitInvokableNode(funcNode, currentCallableUnitInfo, funcEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 60 with SymbolEnv

use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangForkJoin forkJoin) {
    SymbolEnv forkJoinEnv = SymbolEnv.createForkJoinSymbolEnv(forkJoin, this.env);
    ForkjoinInfo forkjoinInfo = new ForkjoinInfo(this.lvIndexes.toArray());
    this.populateForkJoinWorkerInfo(forkJoin, forkjoinInfo);
    int forkJoinInfoIndex = this.forkJoinCount++;
    /* was I already inside a fork/join */
    if (this.env.forkJoin != null) {
        this.currentWorkerInfo.addForkJoinInfo(forkjoinInfo);
    } else {
        this.currentCallableUnitInfo.defaultWorkerInfo.addForkJoinInfo(forkjoinInfo);
    }
    ForkJoinCPEntry forkJoinCPEntry = new ForkJoinCPEntry(forkJoinInfoIndex);
    Operand forkJoinCPIndex = getOperand(this.currentPkgInfo.addCPEntry(forkJoinCPEntry));
    forkjoinInfo.setIndexCPIndex(forkJoinCPIndex.value);
    RegIndex timeoutRegIndex = new RegIndex(-1, TypeTags.INT);
    addToRegIndexList(timeoutRegIndex);
    if (forkJoin.timeoutExpression != null) {
        forkjoinInfo.setTimeoutAvailable(true);
        this.genNode(forkJoin.timeoutExpression, forkJoinEnv);
        timeoutRegIndex.value = forkJoin.timeoutExpression.regIndex.value;
    }
    // FORKJOIN forkJoinCPIndex timeoutRegIndex joinVarRegIndex joinBlockAddr timeoutVarRegIndex timeoutBlockAddr
    RegIndex joinVarRegIndex = new RegIndex(-1, TypeTags.MAP);
    Operand joinBlockAddr = getOperand(-1);
    RegIndex timeoutVarRegIndex = new RegIndex(-1, TypeTags.MAP);
    Operand timeoutBlockAddr = getOperand(-1);
    this.emit(InstructionCodes.FORKJOIN, forkJoinCPIndex, timeoutRegIndex, joinVarRegIndex, joinBlockAddr, timeoutVarRegIndex, timeoutBlockAddr);
    this.processJoinWorkers(forkJoin, forkjoinInfo, forkJoinEnv);
    int i = 0;
    int[] joinWrkrNameCPIndexes = new int[forkJoin.joinedWorkers.size()];
    String[] joinWrkrNames = new String[joinWrkrNameCPIndexes.length];
    for (BLangIdentifier workerName : forkJoin.joinedWorkers) {
        UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(workerName.value);
        int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
        joinWrkrNameCPIndexes[i] = workerNameCPIndex;
        joinWrkrNames[i] = workerName.value;
        i++;
    }
    forkjoinInfo.setJoinWrkrNameIndexes(joinWrkrNameCPIndexes);
    forkjoinInfo.setJoinWorkerNames(joinWrkrNames);
    forkjoinInfo.setWorkerCount(forkJoin.joinedWorkerCount);
    this.processJoinBlock(forkJoin, forkjoinInfo, forkJoinEnv, joinVarRegIndex, joinBlockAddr);
    this.processTimeoutBlock(forkJoin, forkJoinEnv, timeoutVarRegIndex, timeoutBlockAddr);
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) ForkjoinInfo(org.wso2.ballerinalang.programfile.ForkjoinInfo) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)125 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)47 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)30 Name (org.wso2.ballerinalang.compiler.util.Name)26 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)25 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)24 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)22 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)20 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)20 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)20 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)19 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)18 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)17 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)17 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)17 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)17 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)17