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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations