Search in sources :

Example 36 with BLangPackage

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

the class Desugar method visit.

// visitors
@Override
public void visit(BLangPackage pkgNode) {
    if (pkgNode.completedPhases.contains(CompilerPhase.DESUGAR)) {
        result = pkgNode;
        return;
    }
    SymbolEnv env = this.symTable.pkgEnvMap.get(pkgNode.symbol);
    // Adding object functions to package level.
    pkgNode.objects.forEach(o -> {
        o.functions.forEach(f -> {
            pkgNode.functions.add(f);
            pkgNode.topLevelNodes.add(f);
        });
    });
    // Rewriting Object to struct
    pkgNode.objects.forEach(o -> pkgNode.structs.add(rewriteObjectToStruct(o, env)));
    pkgNode.structs = rewrite(pkgNode.structs, env);
    // Adding struct init functions to package level.
    pkgNode.structs.forEach(struct -> {
        pkgNode.functions.add(struct.initFunction);
        pkgNode.topLevelNodes.add(struct.initFunction);
    });
    pkgNode.imports = rewrite(pkgNode.imports, env);
    pkgNode.xmlnsList = rewrite(pkgNode.xmlnsList, env);
    pkgNode.globalVars = rewrite(pkgNode.globalVars, env);
    pkgNode.globalEndpoints = rewrite(pkgNode.globalEndpoints, env);
    pkgNode.globalEndpoints.forEach(endpoint -> endpointDesugar.defineGlobalEndpoint(endpoint, env));
    annotationDesugar.rewritePackageAnnotations(pkgNode);
    endpointDesugar.rewriteAllEndpointsInPkg(pkgNode, env);
    endpointDesugar.rewriteServiceBoundToEndpointInPkg(pkgNode, env);
    pkgNode.transformers = rewrite(pkgNode.transformers, env);
    pkgNode.functions = rewrite(pkgNode.functions, env);
    pkgNode.connectors = rewrite(pkgNode.connectors, env);
    pkgNode.services = rewrite(pkgNode.services, env);
    pkgNode.initFunction = rewrite(pkgNode.initFunction, env);
    pkgNode.startFunction = rewrite(pkgNode.startFunction, env);
    pkgNode.stopFunction = rewrite(pkgNode.stopFunction, env);
    pkgNode.completedPhases.add(CompilerPhase.DESUGAR);
    result = pkgNode;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 37 with BLangPackage

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

the class BinaryFileWriter method writeLibraryPackage.

public void writeLibraryPackage(BLangPackage packageNode) {
    String fileName = getOutputFileName(packageNode, BLANG_COMPILED_PACKAGE_FILE_SUFFIX);
    CompiledBinaryFile.PackageFile packageFile = this.codeGenerator.generateBALO(packageNode);
    ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
    try {
        PackageFileWriter.writePackage(packageFile, byteArrayOS);
    } catch (IOException e) {
        throw new BLangCompilerException("error writing package file '" + fileName + "'", e);
    }
    this.sourceDirectory.saveCompiledPackage(new ByteArrayInputStream(byteArrayOS.toByteArray()), fileName);
}
Also used : CompiledBinaryFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile) ByteArrayInputStream(java.io.ByteArrayInputStream) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 38 with BLangPackage

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

the class Compiler method build.

public void build(String sourcePackage, String targetFileName) {
    BLangPackage bLangPackage = compile(sourcePackage);
    if (this.dlog.errorCount > 0) {
        return;
    }
    // Code gen and save...
    this.binaryFileWriter.writeExecutableBinary(bLangPackage, targetFileName);
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage)

Example 39 with BLangPackage

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

the class CompilerDriver method compile.

// Private methods
private BLangPackage compile(BLangPackage bLangPackage) {
    BLangPackage pkgNode = bLangPackage;
    // "ballerina/built-in" packages is only the pre-known package by the Ballerina compiler. So load it first.
    BLangPackage builtInPackage = loadBuiltInPackage();
    if (this.stopCompilation(pkgNode, CompilerPhase.DEFINE)) {
        return pkgNode;
    }
    pkgNode = define(pkgNode);
    if (this.stopCompilation(pkgNode, CompilerPhase.TYPE_CHECK)) {
        return pkgNode;
    }
    pkgNode = typeCheck(pkgNode);
    if (this.stopCompilation(pkgNode, CompilerPhase.CODE_ANALYZE)) {
        return pkgNode;
    }
    pkgNode = codeAnalyze(pkgNode);
    if (this.stopCompilation(pkgNode, CompilerPhase.TAINT_ANALYZE)) {
        return pkgNode;
    }
    pkgNode = taintAnalyze(pkgNode);
    if (this.stopCompilation(pkgNode, CompilerPhase.COMPILER_PLUGIN)) {
        return pkgNode;
    }
    pkgNode = annotationProcess(pkgNode);
    if (this.stopCompilation(pkgNode, CompilerPhase.DESUGAR)) {
        return pkgNode;
    }
    // TODO : Improve this.
    desugar(builtInPackage);
    return desugar(pkgNode);
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage)

Example 40 with BLangPackage

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

the class PackageLoader method loadAndDefinePackage.

public BLangPackage loadAndDefinePackage(BLangIdentifier orgName, List<BLangIdentifier> pkgNameComps, BLangIdentifier version) {
    // TODO This method is only used by the composer. Can we refactor the composer code?
    List<Name> nameComps = pkgNameComps.stream().map(identifier -> names.fromIdNode(identifier)).collect(Collectors.toList());
    PackageID pkgID = new PackageID(names.fromIdNode(orgName), nameComps, names.fromIdNode(version));
    return loadAndDefinePackage(pkgID);
}
Also used : SystemPackageRepositoryProvider(org.ballerinalang.spi.SystemPackageRepositoryProvider) Arrays(java.util.Arrays) PackageSource(org.ballerinalang.repository.PackageSource) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) PROJECT_DIR(org.ballerinalang.compiler.CompilerOptionName.PROJECT_DIR) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter) Names(org.wso2.ballerinalang.compiler.util.Names) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) URI(java.net.URI) Path(java.nio.file.Path) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Manifest(org.ballerinalang.toml.model.Manifest) OFFLINE(org.ballerinalang.compiler.CompilerOptionName.OFFLINE) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) Optional(java.util.Optional) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) ManifestProcessor(org.ballerinalang.toml.parser.ManifestProcessor) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ArrayList(java.util.ArrayList) Dependency(org.ballerinalang.toml.model.Dependency) RepoHierarchyBuilder.node(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder.node) HomeRepoUtils(org.wso2.ballerinalang.util.HomeRepoUtils) PackageRepository(org.ballerinalang.repository.PackageRepository) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) TreeBuilder(org.ballerinalang.model.TreeBuilder) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectDirs(org.wso2.ballerinalang.compiler.util.ProjectDirs) StreamSupport(java.util.stream.StreamSupport) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Name(org.wso2.ballerinalang.compiler.util.Name) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) PackageEntity(org.ballerinalang.repository.PackageEntity) Parser(org.wso2.ballerinalang.compiler.parser.Parser) Paths(java.nio.file.Paths) GenericPackageSource(org.wso2.ballerinalang.compiler.packaging.GenericPackageSource) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) Collections(java.util.Collections) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) PackageID(org.ballerinalang.model.elements.PackageID) Name(org.wso2.ballerinalang.compiler.util.Name)

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