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