Search in sources :

Example 31 with BVarSymbol

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;
        }
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) ArrayList(java.util.ArrayList) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 32 with BVarSymbol

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);
        }
    }
}
Also used : StreamingQueryStatementNode(org.ballerinalang.model.tree.statements.StreamingQueryStatementNode) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Example 33 with BVarSymbol

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;
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangDocumentationAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) HashSet(java.util.HashSet) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 34 with BVarSymbol

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;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 35 with BVarSymbol

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
}
Also used : LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) PackageVarInfo(org.wso2.ballerinalang.programfile.PackageVarInfo) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)29 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)16 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)15 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)13 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)12 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)12 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)11 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)10 Name (org.wso2.ballerinalang.compiler.util.Name)10 ArrayList (java.util.ArrayList)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)9 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)8 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)8 BInvokableType (org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType)7 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)7 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)7 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)6 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)6 BLangExpressionStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt)6