use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
@Override
public void visit(BLangImportPackage importPkgNode) {
Name pkgAlias = names.fromIdNode(importPkgNode.alias);
if (symResolver.lookupSymbol(env, pkgAlias, SymTag.IMPORT) != symTable.notFoundSymbol) {
dlog.error(importPkgNode.pos, DiagnosticCode.REDECLARED_SYMBOL, pkgAlias);
return;
}
// TODO Clean this code up. Can we move the this to BLangPackageBuilder class
// Create import package symbol
Name orgName;
if (importPkgNode.orgName.value == null || importPkgNode.orgName.value.isEmpty()) {
// means it's in 'import <pkg-name>' style
orgName = Names.ANON_ORG;
} else {
// means it's in 'import <org-name>/<pkg-name>' style
orgName = names.fromIdNode(importPkgNode.orgName);
}
List<Name> nameComps = importPkgNode.pkgNameComps.stream().map(identifier -> names.fromIdNode(identifier)).collect(Collectors.toList());
String version = names.fromIdNode(importPkgNode.version).getValue().replaceAll("[^\\d.]", "");
PackageID pkgId = new PackageID(orgName, nameComps, new Name(version));
if (pkgId.name.getValue().startsWith(Names.BUILTIN_PACKAGE.value)) {
dlog.error(importPkgNode.pos, DiagnosticCode.PACKAGE_NOT_FOUND, importPkgNode.getQualifiedPackageName());
return;
}
// Attempt to load the imported package.
BLangPackage pkgNode = pkgLoader.loadPackage(pkgId, env.enclPkg.packageRepository);
if (pkgNode == null) {
dlog.error(importPkgNode.pos, DiagnosticCode.PACKAGE_NOT_FOUND, importPkgNode.getQualifiedPackageName());
return;
}
// This import package is not defined.
if (pkgNode.symbol == null) {
// Define import package now.
definePackage(pkgNode);
populateInitFunctionInvocation(importPkgNode, pkgNode.symbol);
}
// define the import package symbol in the current package scope
importPkgNode.symbol = pkgNode.symbol;
this.env.scope.define(pkgAlias, pkgNode.symbol);
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class TaintAnalyzer method visit.
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.TAINT_ANALYZE)) {
return;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
SymbolEnv prevPkgEnv = this.currPkgEnv;
this.currPkgEnv = pkgEnv;
this.env = pkgEnv;
pkgNode.imports.forEach(impPkgNode -> impPkgNode.accept(this));
pkgNode.topLevelNodes.forEach(e -> ((BLangNode) e).accept(this));
// Do table generation for blocked invokables after all the import packages are scanned.
if (this.mainPkgEnv.equals(pkgEnv)) {
initialAnalysisComplete = true;
resolveBlockedInvokable();
initialAnalysisComplete = false;
}
this.currPkgEnv = prevPkgEnv;
pkgNode.completedPhases.add(CompilerPhase.TAINT_ANALYZE);
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class CodeAnalyzer method visit.
@Override
public void visit(BLangPackage pkgNode) {
if (pkgNode.completedPhases.contains(CompilerPhase.CODE_ANALYZE)) {
return;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
pkgNode.imports.forEach(impPkgNode -> analyzeNode(impPkgNode, pkgEnv));
pkgNode.topLevelNodes.forEach(topLevelNode -> analyzeNode((BLangNode) topLevelNode, pkgEnv));
pkgNode.completedPhases.add(CompilerPhase.CODE_ANALYZE);
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class CompilerPluginRunner method isValidEndpoints.
private boolean isValidEndpoints(DefinitionID endpoint, CompilerPlugin plugin) {
PackageID pkdID = new PackageID(Names.ANON_ORG, names.fromString(endpoint.pkgName), Names.EMPTY);
BLangPackage pkgNode = this.packageCache.get(pkdID);
if (pkgNode == null) {
return false;
}
SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
final BSymbol bSymbol = symResolver.lookupSymbol(pkgEnv, names.fromString(endpoint.name), SymTag.VARIABLE_NAME);
return bSymbol != symTable.notFoundSymbol;
}
use of org.wso2.ballerinalang.compiler.tree.BLangPackage in project ballerina by ballerina-lang.
the class Parser method parse.
public BLangPackage parse(PackageSource pkgSource) {
BLangPackage pkgNode = (BLangPackage) TreeBuilder.createPackageNode();
pkgSource.getPackageSourceEntries().forEach(e -> pkgNode.addCompilationUnit(generateCompilationUnit(e)));
pkgNode.pos = new DiagnosticPos(new BDiagnosticSource(pkgSource.getPackageId(), pkgSource.getName()), 1, 1, 1, 1);
pkgNode.repos = pkgSource.getRepoHierarchy();
return pkgNode;
}
Aggregations