Search in sources :

Example 1 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class PositionTreeVisitor method visit.

public void visit(BLangImportPackage importPkgNode) {
    BPackageSymbol pkgSymbol = importPkgNode.symbol;
    SymbolEnv pkgEnv = this.symTable.pkgEnvMap.get(pkgSymbol);
    acceptNode(pkgEnv.node);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 2 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

// Visitor methods
@Override
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.DEFINE)) {
        return;
    }
    // Create PackageSymbol.
    BPackageSymbol pSymbol = createPackageSymbol(pkgNode);
    SymbolEnv builtinEnv = this.symTable.pkgEnvMap.get(symTable.builtInPackageSymbol);
    SymbolEnv pkgEnv = SymbolEnv.createPkgEnv(pkgNode, pSymbol.scope, builtinEnv);
    this.symTable.pkgEnvMap.put(pSymbol, pkgEnv);
    createPackageInitFunctions(pkgNode);
    // visit the package node recursively and define all package level symbols.
    // And maintain a list of created package symbols.
    pkgNode.imports.forEach(importNode -> defineNode(importNode, pkgEnv));
    // Define struct nodes.
    pkgNode.enums.forEach(enumNode -> defineNode(enumNode, pkgEnv));
    // Define struct nodes.
    pkgNode.structs.forEach(struct -> defineNode(struct, pkgEnv));
    // Define object nodes
    pkgNode.objects.forEach(object -> defineNode(object, pkgEnv));
    // Define connector nodes.
    pkgNode.connectors.forEach(con -> defineNode(con, pkgEnv));
    // Define connector params and type.
    defineConnectorParams(pkgNode.connectors, pkgEnv);
    // Define transformer nodes.
    pkgNode.transformers.forEach(tansformer -> defineNode(tansformer, pkgEnv));
    // Define service and resource nodes.
    pkgNode.services.forEach(service -> defineNode(service, pkgEnv));
    // Define struct field nodes.
    defineStructFields(pkgNode.structs, pkgEnv);
    // Define object field nodes.
    defineObjectFields(pkgNode.objects, pkgEnv);
    // Define connector action nodes.
    defineConnectorMembers(pkgNode.connectors, pkgEnv);
    // Define object functions
    defineObjectMembers(pkgNode.objects, pkgEnv);
    // Define function nodes.
    pkgNode.functions.forEach(func -> defineNode(func, pkgEnv));
    // Define transformer params
    defineTransformerMembers(pkgNode.transformers, pkgEnv);
    // Define service resource nodes.
    defineServiceMembers(pkgNode.services, pkgEnv);
    // Define annotation nodes.
    pkgNode.annotations.forEach(annot -> defineNode(annot, pkgEnv));
    resolveAnnotationAttributeTypes(pkgNode.annotations, pkgEnv);
    pkgNode.globalVars.forEach(var -> defineNode(var, pkgEnv));
    pkgNode.globalEndpoints.forEach(ep -> defineNode(ep, pkgEnv));
    definePackageInitFunctions(pkgNode, pkgEnv);
    pkgNode.completedPhases.add(CompilerPhase.DEFINE);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 3 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method createPackageSymbol.

// Private methods
private BPackageSymbol createPackageSymbol(BLangPackage pkgNode) {
    BPackageSymbol pSymbol = new BPackageSymbol(pkgNode.packageID, symTable.rootPkgSymbol);
    pkgNode.symbol = pSymbol;
    if (pSymbol.name.value.startsWith(Names.BUILTIN_PACKAGE.value)) {
        pSymbol.scope = symTable.rootScope;
    } else {
        pSymbol.scope = new Scope(pSymbol);
    }
    return pSymbol;
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope)

Example 4 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class TaintAnalyzer method visitAssignment.

private void visitAssignment(BLangExpression varRefExpr, boolean varTaintedStatus, DiagnosticPos pos) {
    // Generate error if a global variable has been assigned with a tainted value.
    if (varTaintedStatus && varRefExpr instanceof BLangVariableReference) {
        BLangVariableReference varRef = (BLangVariableReference) varRefExpr;
        if (varRef.symbol != null && varRef.symbol.owner != null) {
            if (varRef.symbol.owner instanceof BPackageSymbol || SymbolKind.SERVICE.equals(varRef.symbol.owner.kind) || SymbolKind.CONNECTOR.equals(varRef.symbol.owner.kind)) {
                addTaintError(pos, varRef.symbol.name.value, DiagnosticCode.TAINTED_VALUE_PASSED_TO_GLOBAL_VARIABLE);
                return;
            }
        }
    }
    // TODO: Re-evaluating the full data-set (array) when a change occur.
    if (varRefExpr instanceof BLangIndexBasedAccess) {
        nonOverridingAnalysis = true;
        updatedVarRefTaintedState((BLangIndexBasedAccess) varRefExpr, varTaintedStatus);
        nonOverridingAnalysis = false;
    } else if (varRefExpr instanceof BLangFieldBasedAccess) {
        BLangFieldBasedAccess fieldBasedAccessExpr = (BLangFieldBasedAccess) varRefExpr;
        // Propagate tainted status to fields, when field symbols are present (Example: structs).
        if (fieldBasedAccessExpr.symbol != null) {
            setTaintedStatus(fieldBasedAccessExpr, varTaintedStatus);
        }
        nonOverridingAnalysis = true;
        updatedVarRefTaintedState(fieldBasedAccessExpr, varTaintedStatus);
        nonOverridingAnalysis = false;
    } else {
        BLangVariableReference varRef = (BLangVariableReference) varRefExpr;
        setTaintedStatus(varRef, varTaintedStatus);
    }
}
Also used : BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference)

Example 5 with BPackageSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol in project ballerina by ballerina-lang.

the class TaintAnalyzer method visit.

public void visit(BLangImportPackage importPkgNode) {
    BPackageSymbol pkgSymbol = importPkgNode.symbol;
    SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgSymbol);
    if (pkgEnv == null) {
        return;
    }
    this.env = pkgEnv;
    pkgEnv.node.accept(this);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Aggregations

BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)24 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)11 ArrayList (java.util.ArrayList)8 SymbolInfo (org.ballerinalang.langserver.completions.SymbolInfo)6 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)6 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)5 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 PackageActionFunctionAndTypesFilter (org.ballerinalang.langserver.completions.util.filters.PackageActionFunctionAndTypesFilter)3 SymbolKind (org.ballerinalang.model.symbols.SymbolKind)3 Scope (org.wso2.ballerinalang.compiler.semantics.model.Scope)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 Name (org.wso2.ballerinalang.compiler.util.Name)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Token (org.antlr.v4.runtime.Token)2 DocumentServiceKeys (org.ballerinalang.langserver.DocumentServiceKeys)2