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);
}
}
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);
}
}
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;
}
}
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);
}
Aggregations