use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class CodeAnalyzer method visit.
public void visit(BLangTransformer transformerNode) {
List<BVarSymbol> inputs = new ArrayList<>();
inputs.add(transformerNode.source.symbol);
transformerNode.requiredParams.forEach(param -> inputs.add(param.symbol));
List<BVarSymbol> outputs = new ArrayList<>();
transformerNode.retParams.forEach(param -> outputs.add(param.symbol));
for (BLangStatement stmt : transformerNode.body.stmts) {
switch(stmt.getKind()) {
case VARIABLE_DEF:
BLangVariableDef variableDefStmt = (BLangVariableDef) stmt;
variableDefStmt.var.expr.accept(new TransformerVarRefValidator(outputs, DiagnosticCode.TRANSFORMER_INVALID_OUTPUT_USAGE));
inputs.add(variableDefStmt.var.symbol);
break;
case ASSIGNMENT:
BLangAssignment assignStmt = (BLangAssignment) stmt;
assignStmt.varRefs.forEach(varRef -> {
varRef.accept(new TransformerVarRefValidator(inputs, DiagnosticCode.TRANSFORMER_INVALID_INPUT_UPDATE));
// If the stmt is declared using var, all the variable refs on lhs should be treated as inputs
if (assignStmt.declaredWithVar && varRef.getKind() == NodeKind.SIMPLE_VARIABLE_REF && !inputs.contains(((BLangSimpleVarRef) varRef).symbol)) {
inputs.add(((BLangSimpleVarRef) varRef).symbol);
}
});
assignStmt.expr.accept(new TransformerVarRefValidator(outputs, DiagnosticCode.TRANSFORMER_INVALID_OUTPUT_USAGE));
break;
case EXPRESSION_STATEMENT:
// Here we have assumed that the invocation expression is the only expression-statement available.
// TODO: support other types, once they are implemented.
dlog.error(stmt.pos, DiagnosticCode.INVALID_STATEMENT_IN_TRANSFORMER, "invocation");
break;
default:
dlog.error(stmt.pos, DiagnosticCode.INVALID_STATEMENT_IN_TRANSFORMER, stmt.getKind().name().toLowerCase().replace('_', ' '));
break;
}
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol 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.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
@Override
public void visit(BLangDocumentation docNode) {
Set<BLangIdentifier> visitedAttributes = new HashSet<>();
for (BLangDocumentationAttribute attribute : docNode.attributes) {
if (!visitedAttributes.add(attribute.documentationField)) {
this.dlog.warning(attribute.pos, DiagnosticCode.DUPLICATE_DOCUMENTED_ATTRIBUTE, attribute.documentationField);
continue;
}
Name attributeName = names.fromIdNode(attribute.documentationField);
BSymbol attributeSymbol = this.env.scope.lookup(attributeName).symbol;
if (attributeSymbol == null) {
this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
continue;
}
int ownerSymTag = env.scope.owner.tag;
if ((ownerSymTag & SymTag.ANNOTATION) == SymTag.ANNOTATION) {
if (attributeSymbol.tag != SymTag.ANNOTATION_ATTRIBUTE || ((BAnnotationAttributeSymbol) attributeSymbol).docTag != attribute.docTag) {
this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
continue;
}
} else {
if (attributeSymbol.tag != SymTag.VARIABLE || ((BVarSymbol) attributeSymbol).docTag != attribute.docTag) {
this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
continue;
}
}
attribute.type = attributeSymbol.type;
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class TypeChecker method checkStructLiteralKeyExpr.
private BType checkStructLiteralKeyExpr(BLangRecordKey key, BType recordType, RecordKind recKind) {
Name fieldName;
BLangExpression keyExpr = key.expr;
if (keyExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
BLangSimpleVarRef varRef = (BLangSimpleVarRef) keyExpr;
fieldName = names.fromIdNode(varRef.variableName);
} else {
// keys of the struct literal can only be a varRef (identifier)
dlog.error(keyExpr.pos, DiagnosticCode.INVALID_STRUCT_LITERAL_KEY);
return symTable.errType;
}
// Check weather the struct field exists
BSymbol fieldSymbol = symResolver.resolveStructField(keyExpr.pos, this.env, fieldName, recordType.tsymbol);
if (fieldSymbol == symTable.notFoundSymbol) {
dlog.error(keyExpr.pos, DiagnosticCode.UNDEFINED_STRUCT_FIELD, fieldName, recordType.tsymbol);
return symTable.errType;
}
// Setting the struct field symbol for future use in Desugar and code generator.
key.fieldSymbol = (BVarSymbol) fieldSymbol;
return fieldSymbol.type;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol 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
}
Aggregations