Search in sources :

Example 56 with BLangPackage

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

the class EndpointDesugar method rewriteAllEndpointsInPkg.

void rewriteAllEndpointsInPkg(BLangPackage pkgNode, SymbolEnv env) {
    pkgNode.globalEndpoints.forEach(ep -> this.rewriteEndpoint(ep, env));
    pkgNode.functions.forEach(function -> {
        SymbolEnv fucEnv = SymbolEnv.createFunctionEnv(function, function.symbol.scope, env);
        function.endpoints.forEach(endpoint -> rewriteEndpoint(endpoint, fucEnv));
    });
    pkgNode.services.forEach(serviceNode -> {
        SymbolEnv serviceEnv = SymbolEnv.createServiceEnv(serviceNode, serviceNode.symbol.scope, env);
        serviceNode.endpoints.forEach(endpoint -> rewriteEndpoint(endpoint, serviceEnv));
        serviceNode.resources.forEach(resourceNode -> {
            SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceNode.symbol.scope, serviceEnv);
            resourceNode.endpoints.forEach(endpoint -> rewriteEndpoint(endpoint, resourceEnv));
        });
    });
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 57 with BLangPackage

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

the class IterableCodeDesugar method defineFunction.

private void defineFunction(BLangFunction funcNode, BLangPackage targetPkg) {
    final BPackageSymbol packageSymbol = targetPkg.symbol;
    final SymbolEnv packageEnv = this.symTable.pkgEnvMap.get(packageSymbol);
    symbolEnter.defineNode(funcNode, packageEnv);
    packageEnv.enclPkg.functions.add(funcNode);
    packageEnv.enclPkg.topLevelNodes.add(funcNode);
}
Also used : BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 58 with BLangPackage

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

the class BinaryFileWriter method writeExecutableBinary.

public void writeExecutableBinary(BLangPackage packageNode) {
    String fileName = getOutputFileName(packageNode, BLANG_EXEC_FILE_SUFFIX);
    writeExecutableBinary(packageNode, fileName);
    // Generate balo
    Path path = this.sourceDirectory.getPath();
    if (Files.isDirectory(path.resolve(ProjectDirConstants.DOT_BALLERINA_DIR_NAME))) {
        ProjectSourceRepo projectSourceRepo = new ProjectSourceRepo(path);
        Patten packageIDPattern = projectSourceRepo.calculate(packageNode.packageID);
        Stream<Path> pathStream = packageIDPattern.convert(projectSourceRepo.getConverterInstance());
        pathStream = Stream.concat(pathStream, packageIDPattern.sibling(path("Ballerina.md")).convert(projectSourceRepo.getConverterInstance()));
        String prjPath = projectSourceRepo.getConverterInstance().toString();
        ZipUtils.generateBalo(packageNode, prjPath, pathStream);
    }
}
Also used : Path(java.nio.file.Path) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)

Example 59 with BLangPackage

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

the class BinaryFileWriter method writeExecutableBinary.

public void writeExecutableBinary(BLangPackage packageNode, String fileName) {
    if (fileName == null || fileName.isEmpty()) {
        throw new IllegalArgumentException("invalid target file name");
    }
    if (!fileName.endsWith(BLANG_EXEC_FILE_SUFFIX)) {
        fileName += BLANG_EXEC_FILE_SUFFIX;
    }
    // Generate code for the given executable
    ProgramFile programFile = this.codeGenerator.generateBALX(packageNode);
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
    try {
        ProgramFileWriter.writeProgram(programFile, byteArrayOS);
    } catch (IOException e) {
        throw new BLangCompilerException("error writing program file '" + fileName + "'", e);
    }
    final Path execFilePath = this.sourceDirectory.saveCompiledProgram(new ByteArrayInputStream(byteArrayOS.toByteArray()), fileName);
    ServiceLoader<CompilerPlugin> processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
    processorServiceLoader.forEach(plugin -> {
        plugin.codeGenerated(execFilePath);
    });
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) CompilerPlugin(org.ballerinalang.compiler.plugins.CompilerPlugin) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ProgramFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile)

Example 60 with BLangPackage

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

the class CompilerDriver method loadBuiltInPackage.

private BLangPackage loadBuiltInPackage() {
    // Load built-in packages.
    BLangPackage builtInPkg = getBuiltInPackage(Names.BUILTIN_ORG, Names.BUILTIN_PACKAGE);
    symbolTable.builtInPackageSymbol = builtInPkg.symbol;
    return builtInPkg;
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage)

Aggregations

BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)78 Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)28 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)19 Page (org.ballerinalang.docgen.model.Page)18 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)15 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)15 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)14 IOException (java.io.IOException)13 List (java.util.List)13 Path (java.nio.file.Path)12 Compiler (org.wso2.ballerinalang.compiler.Compiler)12 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)12 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)11 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)10 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)10 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)9 BLangAction (org.wso2.ballerinalang.compiler.tree.BLangAction)9 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)9