Search in sources :

Example 11 with BLangWorker

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

the class CodeGenerator method addWorkerInfoEntries.

private void addWorkerInfoEntries(CallableUnitInfo callableUnitInfo, List<BLangWorker> workers) {
    UTF8CPEntry workerNameCPEntry = new UTF8CPEntry("default");
    int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
    WorkerInfo defaultWorkerInfo = new WorkerInfo(workerNameCPIndex, "default");
    callableUnitInfo.defaultWorkerInfo = defaultWorkerInfo;
    for (BLangWorker worker : workers) {
        workerNameCPEntry = new UTF8CPEntry(worker.name.value);
        workerNameCPIndex = currentPkgInfo.addCPEntry(workerNameCPEntry);
        WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.getName().value);
        callableUnitInfo.addWorkerInfo(worker.getName().value, workerInfo);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 12 with BLangWorker

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

the class CodeGenerator method populateForkJoinWorkerInfo.

private void populateForkJoinWorkerInfo(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo) {
    for (BLangWorker worker : forkJoin.workers) {
        UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(worker.name.value);
        int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
        WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.name.value);
        forkjoinInfo.addWorkerInfo(worker.name.value, workerInfo);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 13 with BLangWorker

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

the class CodeGenerator method processJoinWorkers.

/* visit the workers within fork-join block */
private void processJoinWorkers(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv) {
    UTF8CPEntry codeUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.CODE_ATTRIBUTE.toString());
    int codeAttribNameIndex = this.currentPkgInfo.addCPEntry(codeUTF8CPEntry);
    for (BLangWorker worker : forkJoin.workers) {
        VariableIndex lvIndexesCopy = copyVarIndex(this.lvIndexes);
        this.regIndexes = new VariableIndex(REG);
        VariableIndex regIndexesCopy = this.regIndexes;
        this.regIndexes = new VariableIndex(REG);
        VariableIndex maxRegIndexesCopy = this.maxRegIndexes;
        this.maxRegIndexes = new VariableIndex(REG);
        List<RegIndex> regIndexListCopy = this.regIndexList;
        this.regIndexList = new ArrayList<>();
        WorkerInfo workerInfo = forkjoinInfo.getWorkerInfo(worker.name.value);
        workerInfo.codeAttributeInfo.attributeNameIndex = codeAttribNameIndex;
        workerInfo.codeAttributeInfo.codeAddrs = this.nextIP();
        this.currentWorkerInfo = workerInfo;
        this.genNode(worker.body, forkJoinEnv);
        this.endWorkerInfoUnit(workerInfo.codeAttributeInfo);
        this.emit(InstructionCodes.HALT);
        this.lvIndexes = lvIndexesCopy;
        this.regIndexes = regIndexesCopy;
        this.maxRegIndexes = maxRegIndexesCopy;
        this.regIndexList = regIndexListCopy;
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 14 with BLangWorker

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

the class CallableUnitBodyItemSorter method sortItems.

@Override
public void sortItems(TextDocumentServiceContext ctx, List<CompletionItem> completionItems) {
    BLangNode previousNode = ctx.get(CompletionKeys.PREVIOUS_NODE_KEY);
    TokenStream tokenStream = ctx.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
    if (ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY) != null) {
        int currentTokenStart = ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getStart().getTokenIndex();
        Token nextToken = tokenStream.get(currentTokenStart + 1);
        int cursorLine = ctx.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
        int cursorChar = ctx.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
        if (nextToken.getChannel() != Token.DEFAULT_CHANNEL && (cursorLine > nextToken.getLine() - 1 || (cursorLine == nextToken.getLine() - 1 && cursorChar > nextToken.getCharPositionInLine()))) {
            completionItems.clear();
            return;
        }
    }
    this.clearItemsIfWorkerExists(ctx, completionItems);
    if (previousNode == null) {
        this.populateWhenCursorBeforeOrAfterEp(completionItems);
    } else if (previousNode instanceof BLangVariableDef) {
        // } else
        if (ctx.get(CompletionKeys.INVOCATION_STATEMENT_KEY) == null || !ctx.get(CompletionKeys.INVOCATION_STATEMENT_KEY)) {
            CompletionItem workerItem = this.getWorkerSnippet();
            workerItem.setSortText(Priority.PRIORITY160.toString());
            completionItems.add(workerItem);
        }
    } else if (previousNode instanceof BLangWorker) {
        completionItems.add(this.getWorkerSnippet());
    }
    this.setPriorities(completionItems);
}
Also used : BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) TokenStream(org.antlr.v4.runtime.TokenStream) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) CompletionItem(org.eclipse.lsp4j.CompletionItem) Token(org.antlr.v4.runtime.Token) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)

Aggregations

BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)9 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)4 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)3 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)3 Token (org.antlr.v4.runtime.Token)1 TokenStream (org.antlr.v4.runtime.TokenStream)1 InvokableNode (org.ballerinalang.model.tree.InvokableNode)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)1 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)1 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)1 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)1 LocalVariableAttributeInfo (org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo)1