Search in sources :

Example 11 with BLangConnector

use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.

the class SymbolEnter method defineConnectorMembers.

private void defineConnectorMembers(List<BLangConnector> connectors, SymbolEnv pkgEnv) {
    connectors.forEach(connector -> {
        SymbolEnv conEnv = SymbolEnv.createConnectorEnv(connector, connector.symbol.scope, pkgEnv);
        connector.varDefs.forEach(varDef -> defineNode(varDef.var, conEnv));
        defineConnectorInitFunction(connector, conEnv);
        connector.actions.stream().peek(action -> action.flagSet.add(Flag.PUBLIC)).forEach(action -> defineNode(action, conEnv));
    });
}
Also used : BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BAttachedFunction(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol.BAttachedFunction) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BTypeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) Flag(org.ballerinalang.model.elements.Flag) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) BServiceSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol) BEnumType(org.wso2.ballerinalang.compiler.semantics.model.types.BEnumType) EnumSet(java.util.EnumSet) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) BConnectorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BConnectorSymbol) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) BXMLAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLAttributeSymbol) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute) Collectors(java.util.stream.Collectors) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) List(java.util.List) IMPORT(org.ballerinalang.model.tree.NodeKind.IMPORT) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BStructField(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType.BStructField) BLangUserDefinedType(org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType) BAnnotationType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangXMLAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLAttribute) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) PackageLoader(org.wso2.ballerinalang.compiler.PackageLoader) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) BServiceType(org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType) Flags(org.wso2.ballerinalang.util.Flags) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) DocTag(org.ballerinalang.model.elements.DocTag) TreeBuilder(org.ballerinalang.model.TreeBuilder) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) XMLConstants(javax.xml.XMLConstants) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BTransformerSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BTransformerSymbol) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangEnumerator(org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 12 with BLangConnector

use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.

the class TaintAnalyzer method attachTaintTableBasedOnAnnotations.

private void attachTaintTableBasedOnAnnotations(BLangConnector connectorNode) {
    if (connectorNode.symbol.taintTable == null) {
        List<Boolean> retParamsTaintedStatus = new ArrayList<>();
        Map<Integer, TaintRecord> taintTable = new HashMap<>();
        taintTable.put(ALL_UNTAINTED_TABLE_ENTRY_INDEX, new TaintRecord(retParamsTaintedStatus, null));
        if (connectorNode.params.size() > 0) {
            // Append taint table with tainted status when each parameter is tainted.
            for (int paramIndex = 0; paramIndex < connectorNode.params.size(); paramIndex++) {
                BLangVariable param = connectorNode.params.get(paramIndex);
                // If parameter is sensitive, test for this parameter being tainted is invalid.
                if (hasAnnotation(param, ANNOTATION_SENSITIVE)) {
                    continue;
                }
                taintTable.put(paramIndex, new TaintRecord(retParamsTaintedStatus, null));
            }
        }
        connectorNode.symbol.taintTable = taintTable;
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaintRecord(org.wso2.ballerinalang.compiler.semantics.model.symbols.TaintRecord) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 13 with BLangConnector

use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.

the class SemanticAnalyzer method visit.

public void visit(BLangConnector connectorNode) {
    BSymbol connectorSymbol = connectorNode.symbol;
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, env);
    connectorNode.annAttachments.forEach(a -> {
        a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.CONNECTOR);
        this.analyzeDef(a, connectorEnv);
    });
    connectorNode.docAttachments.forEach(doc -> analyzeDef(doc, connectorEnv));
    connectorNode.params.forEach(param -> this.analyzeDef(param, connectorEnv));
    connectorNode.varDefs.forEach(varDef -> this.analyzeDef(varDef, connectorEnv));
    connectorNode.endpoints.forEach(e -> analyzeDef(e, connectorEnv));
    this.analyzeDef(connectorNode.initFunction, connectorEnv);
    connectorNode.actions.forEach(action -> this.analyzeDef(action, connectorEnv));
    this.analyzeDef(connectorNode.initAction, connectorEnv);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 14 with BLangConnector

use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangConnector connectorNode) {
    BLangFunction initFunction = (BLangFunction) connectorNode.getInitFunction();
    visit(initFunction);
    currentConnectorInfo = currentPkgInfo.getConnectorInfo(connectorNode.getName().getValue());
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorNode.symbol.scope, this.env);
    connectorNode.actions.forEach(action -> genNode(action, connectorEnv));
    genNode(connectorNode.initAction, connectorEnv);
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 15 with BLangConnector

use of org.wso2.ballerinalang.compiler.tree.BLangConnector in project ballerina by ballerina-lang.

the class CodeGenerator method createConnectorInfoEntry.

private void createConnectorInfoEntry(BLangConnector connectorNode) {
    BConnectorType connectorType = (BConnectorType) connectorNode.symbol.type;
    // Add connector name as an UTFCPEntry to the constant pool
    int connectorNameCPIndex = addUTF8CPEntry(currentPkgInfo, connectorNode.name.value);
    // Create connector info
    ConnectorInfo connectorInfo = new ConnectorInfo(currentPackageRefCPIndex, connectorNameCPIndex, connectorNode.symbol.flags);
    connectorInfo.paramTypes = connectorType.paramTypes.toArray(new BType[0]);
    connectorInfo.signatureCPIndex = addUTF8CPEntry(this.currentPkgInfo, generateConnectorSig(connectorInfo));
    // Add connector level variables
    int localVarAttNameIndex = addUTF8CPEntry(currentPkgInfo, AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE.value());
    LocalVariableAttributeInfo localVarAttributeInfo = new LocalVariableAttributeInfo(localVarAttNameIndex);
    connectorNode.params.forEach(var -> visitVarSymbol(var.symbol, fieldIndexes, localVarAttributeInfo));
    connectorNode.varDefs.forEach(var -> visitVarSymbol(var.var.symbol, fieldIndexes, localVarAttributeInfo));
    connectorInfo.addAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE, localVarAttributeInfo);
    // Create variable count attribute info
    prepareIndexes(fieldIndexes);
    int[] fieldCount = new int[] { fieldIndexes.tInt, fieldIndexes.tFloat, fieldIndexes.tString, fieldIndexes.tBoolean, fieldIndexes.tBlob, fieldIndexes.tRef };
    addVariableCountAttributeInfo(currentPkgInfo, connectorInfo, fieldCount);
    // Create the init function info
    BLangFunction connectorInitFunction = (BLangFunction) connectorNode.getInitFunction();
    createFunctionInfoEntry(connectorInitFunction);
    this.currentPkgInfo.connectorInfoMap.put(connectorNode.name.value, connectorInfo);
    // Create action info entries for all actions
    connectorNode.actions.forEach(res -> createActionInfoEntry(res, connectorInfo));
    createActionInfoEntry(connectorNode.initAction, connectorInfo);
    fieldIndexes = new VariableIndex(FIELD);
}
Also used : LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) ConnectorInfo(org.wso2.ballerinalang.programfile.ConnectorInfo) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BConnectorType(org.wso2.ballerinalang.compiler.semantics.model.types.BConnectorType) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)12 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)11 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)11 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)10 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)9 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)8 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)5 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)5 BLangObject (org.wso2.ballerinalang.compiler.tree.BLangObject)5 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)5 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)5 BLangTransformer (org.wso2.ballerinalang.compiler.tree.BLangTransformer)5 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)5 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)5 Collectors (java.util.stream.Collectors)4