use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangVariable varNode) {
int ownerSymTag = env.scope.owner.tag;
if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
// If the variable is parameter then the variable symbol is already defined
if (varNode.symbol == null) {
symbolEnter.defineNode(varNode, env);
}
}
BType lhsType = varNode.symbol.type;
varNode.type = lhsType;
// Here we validate annotation attachments for package level variables.
varNode.annAttachments.forEach(a -> {
a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.CONST);
a.accept(this);
});
// Here we validate document attachments for package level variables.
varNode.docAttachments.forEach(doc -> {
doc.accept(this);
});
// Analyze the init expression
BLangExpression rhsExpr = varNode.expr;
if (rhsExpr == null) {
return;
}
// Here we create a new symbol environment to catch self references by keep the current
// variable symbol in the symbol environment
// e.g. int a = x + a;
SymbolEnv varInitEnv = SymbolEnv.createVarInitEnv(varNode, env, varNode.symbol);
// It will we done during the init-function of the respective construct is visited.
if ((ownerSymTag & SymTag.PACKAGE) == SymTag.PACKAGE || (ownerSymTag & SymTag.SERVICE) == SymTag.SERVICE || (ownerSymTag & SymTag.CONNECTOR) == SymTag.CONNECTOR) {
return;
}
// Return if this not a safe assignment
if (!varNode.safeAssignment) {
typeChecker.checkExpr(rhsExpr, varInitEnv, Lists.of(lhsType));
return;
}
handleSafeAssignment(varNode.pos, lhsType, rhsExpr, varInitEnv);
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
// Streaming related methods.
public void visit(BLangForever foreverStatement) {
for (StreamingQueryStatementNode streamingQueryStatement : foreverStatement.gettreamingQueryStatements()) {
analyzeStmt((BLangStatement) streamingQueryStatement, env);
}
List<BLangVariable> globalVariableList = this.env.enclPkg.globalVars;
if (globalVariableList != null) {
for (BLangVariable variable : globalVariableList) {
if (((variable).type.tsymbol) != null) {
if ("stream".equals((((variable).type.tsymbol)).name.value)) {
foreverStatement.addGlobalVariable(variable);
}
}
}
}
List<BVarSymbol> functionParameterList = ((BInvokableSymbol) this.env.scope.owner).getParameters();
for (BVarSymbol varSymbol : functionParameterList) {
if ("stream".equals((((varSymbol).type.tsymbol)).name.value)) {
foreverStatement.addFunctionVariable(varSymbol);
}
}
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class SemanticAnalyzer method validateTransformerMappingType.
private void validateTransformerMappingType(BLangVariable param) {
BType type = param.type;
if (types.isValueType(type) || (type instanceof BBuiltInRefType) || type.tag == TypeTags.STRUCT) {
return;
}
dlog.error(param.pos, DiagnosticCode.TRANSFORMER_UNSUPPORTED_TYPES, type);
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class CodeGenerator method createPackageVarInfo.
// Create info entries
private void createPackageVarInfo(BLangVariable varNode) {
BVarSymbol varSymbol = varNode.symbol;
varSymbol.varIndex = getPVIndex(varSymbol.type.tag);
int varNameCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.name.value);
int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.type.getDesc());
PackageVarInfo pkgVarInfo = new PackageVarInfo(varNameCPIndex, typeSigCPIndex, varSymbol.flags, varSymbol.varIndex.value);
currentPkgInfo.pkgVarInfoMap.put(varSymbol.name.value, pkgVarInfo);
LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
LocalVariableAttributeInfo pkgVarAttrInfo = (LocalVariableAttributeInfo) currentPkgInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
pkgVarAttrInfo.localVars.add(localVarInfo);
// TODO Populate annotation attribute
}
use of org.wso2.ballerinalang.compiler.tree.BLangVariable in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangVariable varNode) {
BVarSymbol varSymbol = varNode.symbol;
int ownerSymTag = env.scope.owner.tag;
if ((ownerSymTag & SymTag.INVOKABLE) == SymTag.INVOKABLE) {
varSymbol.varIndex = getLVIndex(varSymbol.type.tag);
LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
localVarAttrInfo.localVars.add(localVarInfo);
} else {
// TODO Support other variable nodes
throw new IllegalStateException("");
}
BLangExpression rhsExpr = varNode.expr;
if (rhsExpr != null) {
rhsExpr.regIndex = varSymbol.varIndex;
genNode(rhsExpr, this.env);
}
}
Aggregations