use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangCatch bLangCatch) {
SymbolEnv catchBlockEnv = SymbolEnv.createBlockEnv(bLangCatch.body, env);
analyzeNode(bLangCatch.param, catchBlockEnv);
if (!this.types.checkStructEquivalency(bLangCatch.param.type, symTable.errStructType)) {
dlog.error(bLangCatch.param.pos, DiagnosticCode.INCOMPATIBLE_TYPES, symTable.errStructType, bLangCatch.param.type);
}
analyzeStmt(bLangCatch.body, catchBlockEnv);
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangStruct structNode) {
BSymbol structSymbol = structNode.symbol;
SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, env);
structNode.fields.forEach(field -> analyzeDef(field, structEnv));
structNode.annAttachments.forEach(annotationAttachment -> {
annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.STRUCT);
annotationAttachment.accept(this);
});
analyzeDef(structNode.initFunction, structEnv);
structNode.docAttachments.forEach(doc -> analyzeDef(doc, structEnv));
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SemanticAnalyzer method defineResourceEndpoint.
private void defineResourceEndpoint(BLangResource resourceNode, SymbolEnv resourceEnv) {
if (!resourceNode.getParameters().isEmpty()) {
final BLangVariable variable = resourceNode.getParameters().get(0);
if (variable.type == symTable.endpointType) {
String actualVarName = variable.name.value.substring(1);
variable.name = new BLangIdentifier();
variable.name.value = actualVarName;
if (resourceEnv.enclService.endpointType != null) {
variable.type = resourceEnv.enclService.endpointType;
final BEndpointVarSymbol bEndpointVarSymbol = symbolEnter.defineEndpointVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
variable.symbol = bEndpointVarSymbol;
endpointSPIAnalyzer.populateEndpointSymbol((BStructSymbol) variable.type.tsymbol, bEndpointVarSymbol);
} else {
variable.type = symTable.errType;
variable.symbol = symbolEnter.defineVarSymbol(variable.pos, EnumSet.noneOf(Flag.class), variable.type, names.fromString(actualVarName), resourceEnv);
}
// Replace old symbol with new one.
resourceNode.symbol.params.remove(0);
resourceNode.symbol.params.add(0, variable.symbol);
((BInvokableType) resourceNode.symbol.type).paramTypes.remove(0);
((BInvokableType) resourceNode.symbol.type).paramTypes.add(0, variable.type);
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SemanticAnalyzer method analyzeNode.
BType analyzeNode(BLangNode node, SymbolEnv env, BType expType, DiagnosticCode diagCode) {
SymbolEnv prevEnv = this.env;
BType preExpType = this.expType;
DiagnosticCode preDiagCode = this.diagCode;
// TODO Check the possibility of using a try/finally here
this.env = env;
this.expType = expType;
this.diagCode = diagCode;
node.accept(this);
this.env = prevEnv;
this.expType = preExpType;
this.diagCode = preDiagCode;
return resType;
}
use of org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangForkJoin forkJoin) {
SymbolEnv forkJoinEnv = SymbolEnv.createFolkJoinEnv(forkJoin, this.env);
forkJoin.workers.forEach(e -> this.symbolEnter.defineNode(e, forkJoinEnv));
forkJoin.workers.forEach(e -> this.analyzeDef(e, forkJoinEnv));
if (!this.isJoinResultType(forkJoin.joinResultVar)) {
this.dlog.error(forkJoin.joinResultVar.pos, DiagnosticCode.INVALID_WORKER_JOIN_RESULT_TYPE);
}
/* create code black and environment for join result section, i.e. (map results) */
BLangBlockStmt joinResultsBlock = this.generateCodeBlock(this.createVarDef(forkJoin.joinResultVar));
SymbolEnv joinResultsEnv = SymbolEnv.createBlockEnv(joinResultsBlock, this.env);
this.analyzeNode(joinResultsBlock, joinResultsEnv);
/* create an environment for the join body, making the enclosing environment the earlier
* join result's environment */
SymbolEnv joinBodyEnv = SymbolEnv.createBlockEnv(forkJoin.joinedBody, joinResultsEnv);
this.analyzeNode(forkJoin.joinedBody, joinBodyEnv);
if (forkJoin.timeoutExpression != null) {
if (!this.isJoinResultType(forkJoin.timeoutVariable)) {
this.dlog.error(forkJoin.timeoutVariable.pos, DiagnosticCode.INVALID_WORKER_TIMEOUT_RESULT_TYPE);
}
/* create code black and environment for timeout section */
BLangBlockStmt timeoutVarBlock = this.generateCodeBlock(this.createVarDef(forkJoin.timeoutVariable));
SymbolEnv timeoutVarEnv = SymbolEnv.createBlockEnv(timeoutVarBlock, this.env);
this.typeChecker.checkExpr(forkJoin.timeoutExpression, timeoutVarEnv, Arrays.asList(symTable.intType));
this.analyzeNode(timeoutVarBlock, timeoutVarEnv);
/* create an environment for the timeout body, making the enclosing environment the earlier
* timeout var's environment */
SymbolEnv timeoutBodyEnv = SymbolEnv.createBlockEnv(forkJoin.timeoutBody, timeoutVarEnv);
this.analyzeNode(forkJoin.timeoutBody, timeoutBodyEnv);
}
this.validateJoinWorkerList(forkJoin, forkJoinEnv);
}
Aggregations