Skip to content

Commit

Permalink
Fix static method accessed via instance reference and remove referenc…
Browse files Browse the repository at this point in the history
…es to `Names` variables
  • Loading branch information
Shadow-Devil committed Sep 11, 2024
1 parent 568ee69 commit 48f0a8a
Show file tree
Hide file tree
Showing 37 changed files with 348 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public class BIRPackageSymbolEnter {
private final PackageCache packageCache;
private final SymbolResolver symbolResolver;
private final SymbolTable symTable;
private final Names names;
private final TypeParamAnalyzer typeParamAnalyzer;
private final Types types;
private BIRTypeReader typeReader;
Expand Down Expand Up @@ -167,7 +166,6 @@ private BIRPackageSymbolEnter(CompilerContext context) {
this.packageCache = PackageCache.getInstance(context);
this.symbolResolver = SymbolResolver.getInstance(context);
this.symTable = SymbolTable.getInstance(context);
this.names = Names.getInstance(context);
this.typeParamAnalyzer = TypeParamAnalyzer.getInstance(context);
this.types = Types.getInstance(context);
}
Expand Down Expand Up @@ -1945,11 +1943,11 @@ private boolean isImmutable(long flags) {
private BType getEffectiveImmutableType(BType type) {
return ImmutableTypeCloner.getEffectiveImmutableType(null, types, type,
type.tsymbol.pkgID, type.tsymbol.owner,
symTable, null, names);
symTable, null);
}

private BType getEffectiveImmutableType(BType type, PackageID pkgID, BSymbol owner) {
return ImmutableTypeCloner.getEffectiveImmutableType(null, types, type, pkgID, owner, symTable,
null, names);
null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class SourceDirectoryManager implements Project {
new CompilerContext.Key<>();

private final CompilerOptions options;
private final Names names;
private final SourceDirectory sourceDirectory;
private Manifest manifest;

Expand All @@ -71,7 +70,6 @@ private SourceDirectoryManager(CompilerContext context) {
// This has to be further refactored with ProjectAPI Implementation
context.put(PROJECT_KEY, this);

this.names = Names.getInstance(context);
this.options = CompilerOptions.getInstance(context);

// Check whether the compilation is initiated by the project API.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ int nextBBId() {
return ++currentBBId;
}

Name nextLocalVarId(Names names) {
Name nextLocalVarId() {
currentLocalVarId++;
return names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLocalVarId)));
return Names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLocalVarId)));
}

Name nextLambdaVarId(Names names) {
Name nextLambdaVarId() {
currentLambdaVarId++;
return names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLambdaVarId)));
return Names.merge(Names.BIR_LOCAL_VAR_PREFIX, Names.fromString(Integer.toString(currentLambdaVarId)));
}

void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ static void appendStatement(BLangStatement stmt, BLangBlockStmt target) {
target.stmts.add(index, stmt);
}

static void defineVariable(BLangSimpleVariable variable, BSymbol targetSymbol, Names names) {
variable.symbol = new BVarSymbol(0, names.fromIdNode(variable.name),
names.originalNameFromIdNode(variable.name),
static void defineVariable(BLangSimpleVariable variable, BSymbol targetSymbol) {
variable.symbol = new BVarSymbol(0, Names.fromIdNode(variable.name),
Names.originalNameFromIdNode(variable.name),
targetSymbol.pkgID, variable.getBType(), targetSymbol, variable.pos, VIRTUAL);
targetSymbol.scope.define(variable.symbol.name, variable.symbol);
}
Expand Down Expand Up @@ -626,7 +626,6 @@ static BLangIsAssignableExpr createIsAssignableExpr(Location pos,
BLangExpression lhsExpr,
BType targetType,
BType type,
Names names,
Location opSymPos) {
final BLangIsAssignableExpr assignableExpr = new BLangIsAssignableExpr();
assignableExpr.pos = pos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public class AnnotationDesugar {
private final Desugar desugar;
private final SymbolTable symTable;
private final Types types;
private final Names names;
private SymbolResolver symResolver;
private ConstantValueResolver constantValueResolver;
private ClosureGenerator closureGenerator;
Expand All @@ -154,7 +153,6 @@ private AnnotationDesugar(CompilerContext context) {
this.desugar = Desugar.getInstance(context);
this.symTable = SymbolTable.getInstance(context);
this.types = Types.getInstance(context);
this.names = Names.getInstance(context);
this.symResolver = SymbolResolver.getInstance(context);
this.constantValueResolver = ConstantValueResolver.getInstance(context);
this.closureGenerator = ClosureGenerator.getInstance(context);
Expand Down Expand Up @@ -926,7 +924,7 @@ private BLangSimpleVariable createGlobalAnnotationMapVar(BLangPackage pkgNode) {
symTable.mapType,
ASTBuilderUtil.createEmptyRecordLiteral(
pkgNode.pos, symTable.mapType), null);
ASTBuilderUtil.defineVariable(annotationMap, pkgNode.symbol, names);
ASTBuilderUtil.defineVariable(annotationMap, pkgNode.symbol);
pkgNode.globalVars.add(0, annotationMap); // TODO fix this
pkgNode.topLevelNodes.add(0, annotationMap);
return annotationMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public class ClassClosureDesugar extends BLangNodeVisitor {

private final SymbolTable symTable;
private final Desugar desugar;
private final Names names;
private final BLangDiagnosticLog dlog;

static {
Expand All @@ -197,7 +196,6 @@ private ClassClosureDesugar(CompilerContext context) {
context.put(CLASS_CLOSURE_DESUGAR_KEY, this);
this.symTable = SymbolTable.getInstance(context);
this.desugar = Desugar.getInstance(context);
this.names = Names.getInstance(context);
this.dlog = BLangDiagnosticLog.getInstance(context);
CLOSURE_MAP_NOT_FOUND.pos = this.symTable.builtinPos;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public class ClosureDesugar extends BLangNodeVisitor {
private BLangNode result;
private Types types;
private Desugar desugar;
private Names names;
private ClassClosureDesugar classClosureDesugar;
private int funClosureMapCount = 1;
private int blockClosureMapCount = 1;
Expand All @@ -233,7 +232,6 @@ private ClosureDesugar(CompilerContext context) {
this.symTable = SymbolTable.getInstance(context);
this.types = Types.getInstance(context);
this.desugar = Desugar.getInstance(context);
this.names = Names.getInstance(context);
this.symResolver = SymbolResolver.getInstance(context);
this.classClosureDesugar = ClassClosureDesugar.getInstance(context);
CLOSURE_MAP_NOT_FOUND.pos = this.symTable.builtinPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public class DeclarativeAuthDesugar {

private final SymbolTable symTable;
private final SymbolResolver symResolver;
private final Names names;

private static final String ORG_NAME = "ballerina";
private static final String HTTP_PACKAGE_NAME = "http";
Expand All @@ -94,7 +93,6 @@ private DeclarativeAuthDesugar(CompilerContext context) {
context.put(DECLARATIVE_AUTH_DESUGAR_KEY, this);
this.symTable = SymbolTable.getInstance(context);
this.symResolver = SymbolResolver.getInstance(context);
this.names = Names.getInstance(context);
}

void desugarFunction(BLangFunction functionNode, SymbolEnv env, List<BType> expressionTypes) {
Expand Down Expand Up @@ -181,7 +179,7 @@ void addAuthDesugarFunctionInvocation(BLangFunction functionNode, SymbolEnv env,
List<BLangStatement> statements = getFunctionBodyStatementList(functionNode);
statements.add(0, result);

BVarSymbol resultSymbol = new BVarSymbol(0, names.fromIdNode(result.var.name), env.enclPkg.packageID,
BVarSymbol resultSymbol = new BVarSymbol(0, Names.fromIdNode(result.var.name), env.enclPkg.packageID,
result.var.getBType(), functionNode.symbol, pos, VIRTUAL);
functionNode.symbol.scope.define(resultSymbol.name, resultSymbol);
result.var.symbol = resultSymbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ public class Desugar extends BLangNodeVisitor {
private Code2CloudDesugar code2CloudDesugar;
private AnnotationDesugar annotationDesugar;
private Types types;
private Names names;
private ServiceDesugar serviceDesugar;
private BLangNode result;
private NodeCloner nodeCloner;
Expand Down Expand Up @@ -464,8 +463,6 @@ private Desugar(CompilerContext context) {
this.annotationDesugar = AnnotationDesugar.getInstance(context);
this.largeMethodSplitter = LargeMethodSplitter.getInstance(context);
this.types = Types.getInstance(context);
this.names = Names.getInstance(context);
this.names = Names.getInstance(context);
this.serviceDesugar = ServiceDesugar.getInstance(context);
this.nodeCloner = NodeCloner.getInstance(context);
this.semanticAnalyzer = SemanticAnalyzer.getInstance(context);
Expand Down Expand Up @@ -1639,7 +1636,7 @@ private void createRestFieldVarDefStmts(BLangTupleVariable parentTupleVariable,

final BLangSimpleVariable foreachVariable = ASTBuilderUtil.createVariable(pos,
"$foreach$i", foreach.varType);
foreachVariable.symbol = new BVarSymbol(0, names.fromIdNode(foreachVariable.name),
foreachVariable.symbol = new BVarSymbol(0, Names.fromIdNode(foreachVariable.name),
this.env.scope.owner.pkgID, foreachVariable.getBType(),
this.env.scope.owner, pos, VIRTUAL);
BLangSimpleVarRef foreachVarRef = ASTBuilderUtil.createVariableRef(pos, foreachVariable.symbol);
Expand Down Expand Up @@ -1885,7 +1882,7 @@ private void createVarDefStmts(BLangErrorVariable parentErrorVariable, BLangBloc
parentErrorVariable.message.getBType(), convertedErrorVarSymbol,
null);

if (names.fromIdNode(parentErrorVariable.message.name) == Names.IGNORE) {
if (Names.fromIdNode(parentErrorVariable.message.name) == Names.IGNORE) {
parentErrorVariable.message = null;
} else {
BLangSimpleVariableDef messageVariableDef =
Expand Down Expand Up @@ -1932,7 +1929,7 @@ private void createVarDefStmts(BLangErrorVariable parentErrorVariable, BLangBloc
detailTempVarDef.setBType(parentErrorVariable.detailExpr.getBType());
parentBlockStmt.addStatement(detailTempVarDef);

this.env.scope.define(names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol);
this.env.scope.define(Names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol);

for (BLangErrorVariable.BLangErrorDetailEntry detailEntry : parentErrorVariable.detail) {
BLangExpression detailEntryVar = createErrorDetailVar(detailEntry, detailTempVarDef.var.symbol);
Expand Down Expand Up @@ -2464,7 +2461,7 @@ private void createSimpleVarDefStmt(BLangSimpleVariable simpleVariable, BLangBlo
BLangLiteral indexExpr, BVarSymbol tupleVarSymbol,
BLangIndexBasedAccess parentArrayAccessExpr) {

Name varName = names.fromIdNode(simpleVariable.name);
Name varName = Names.fromIdNode(simpleVariable.name);
if (varName == Names.IGNORE) {
return;
}
Expand Down Expand Up @@ -2608,7 +2605,7 @@ private void createRestFieldAssignmentStmt(BLangTupleVarRef tupleVarRef, BLangBl

final BLangSimpleVariable foreachVariable = ASTBuilderUtil.createVariable(pos,
"$foreach$i", foreach.varType);
foreachVariable.symbol = new BVarSymbol(0, names.fromIdNode(foreachVariable.name),
foreachVariable.symbol = new BVarSymbol(0, Names.fromIdNode(foreachVariable.name),
this.env.scope.owner.pkgID, foreachVariable.getBType(),
this.env.scope.owner, pos, VIRTUAL);
BLangSimpleVarRef foreachVarRef = ASTBuilderUtil.createVariableRef(pos, foreachVariable.symbol);
Expand Down Expand Up @@ -2734,7 +2731,7 @@ private void createAssignmentStmt(BLangExpression accessibleExpression, BLangBlo
BLangIndexBasedAccess parentArrayAccessExpr) {

if (accessibleExpression.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
Name varName = names.fromIdNode(((BLangSimpleVarRef) accessibleExpression).variableName);
Name varName = Names.fromIdNode(((BLangSimpleVarRef) accessibleExpression).variableName);
if (varName == Names.IGNORE) {
return;
}
Expand Down Expand Up @@ -2917,7 +2914,7 @@ private void createVarRefAssignmentStmts(BLangRecordVarRef parentRecordVarRef, B
private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLangBlockStmt parentBlockStmt,
BVarSymbol errorVarySymbol, BLangIndexBasedAccess parentIndexAccessExpr) {
if (parentErrorVarRef.message != null &&
names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.message).variableName) != Names.IGNORE) {
Names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.message).variableName) != Names.IGNORE) {
BLangAssignment message = ASTBuilderUtil.createAssignmentStmt(parentBlockStmt.pos, parentBlockStmt);
message.expr = generateErrorMessageBuiltinFunction(parentErrorVarRef.message.pos,
symTable.stringType, errorVarySymbol, parentIndexAccessExpr);
Expand All @@ -2926,7 +2923,7 @@ private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLa
}

if (parentErrorVarRef.cause != null && (parentErrorVarRef.cause.getKind() != NodeKind.SIMPLE_VARIABLE_REF ||
names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.cause).variableName) != Names.IGNORE)) {
Names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.cause).variableName) != Names.IGNORE)) {
BLangAssignment cause = ASTBuilderUtil.createAssignmentStmt(parentBlockStmt.pos, parentBlockStmt);
cause.expr = generateErrorCauseLanglibFunction(parentErrorVarRef.cause.pos,
symTable.errorType, errorVarySymbol, parentIndexAccessExpr);
Expand All @@ -2948,7 +2945,7 @@ private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLa
parentErrorVarRef.pos);
detailTempVarDef.setBType(symTable.detailType);
parentBlockStmt.addStatement(detailTempVarDef);
this.env.scope.define(names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol);
this.env.scope.define(Names.fromIdNode(detailTempVarDef.var.name), detailTempVarDef.var.symbol);

List<String> extractedKeys = new ArrayList<>();
for (BLangNamedArgsExpression detail : parentErrorVarRef.detail) {
Expand Down Expand Up @@ -4929,7 +4926,7 @@ private BType createMatchingRecordType(BLangErrorFieldMatchPatterns errorFieldMa
BRecordType detailRecordType = createAnonRecordType(errorFieldMatchPatterns.pos);
List<BLangSimpleVariable> typeDefFields = new ArrayList<>();
for (BLangNamedArgMatchPattern bindingPattern : errorFieldMatchPatterns.namedArgMatchPatterns) {
Name fieldName = names.fromIdNode(bindingPattern.argName);
Name fieldName = Names.fromIdNode(bindingPattern.argName);
BVarSymbol declaredVarSym = bindingPattern.declaredVars.get(fieldName.value);
if (declaredVarSym == null) {
// constant match pattern expr, not needed for detail record type
Expand Down Expand Up @@ -5018,7 +5015,7 @@ private BType createMatchingRecordType(BLangErrorFieldBindingPatterns errorField
BRecordType detailRecordType = createAnonRecordType(errorFieldBindingPatterns.pos);
List<BLangSimpleVariable> typeDefFields = new ArrayList<>();
for (BLangNamedArgBindingPattern bindingPattern : errorFieldBindingPatterns.namedArgBindingPatterns) {
Name fieldName = names.fromIdNode(bindingPattern.argName);
Name fieldName = Names.fromIdNode(bindingPattern.argName);
BVarSymbol declaredVarSym = bindingPattern.declaredVars.get(fieldName.value);
if (declaredVarSym == null) {
// constant match pattern expr, not needed for detail record type
Expand Down Expand Up @@ -8397,7 +8394,7 @@ private BLangClassDefinition desugarTemplateLiteralObjectTypedef(List<BLangLiter
*/
private BLangFunction createUserDefinedObjectInitFn(BLangClassDefinition classDefn, SymbolEnv env) {
BLangFunction initFunction =
TypeDefBuilderHelper.createInitFunctionForStructureType(classDefn.symbol, env, names,
TypeDefBuilderHelper.createInitFunctionForStructureType(classDefn.symbol, env,
Names.USER_DEFINED_INIT_SUFFIX, symTable, classDefn.getBType());
BObjectTypeSymbol typeSymbol = ((BObjectTypeSymbol) classDefn.getBType().tsymbol);
typeSymbol.initializerFunc = new BAttachedFunction(Names.USER_DEFINED_INIT_SUFFIX, initFunction.symbol,
Expand Down Expand Up @@ -9536,7 +9533,7 @@ private void reorderArguments(BLangInvocation iExpr) {

final BLangSimpleVariable foreachVariable = ASTBuilderUtil.createVariable(pos, "$foreach$i",
foreach.varType);
foreachVariable.symbol = new BVarSymbol(0, names.fromIdNode(foreachVariable.name),
foreachVariable.symbol = new BVarSymbol(0, Names.fromIdNode(foreachVariable.name),
this.env.scope.owner.pkgID, foreachVariable.getBType(),
this.env.scope.owner, pos, VIRTUAL);
BLangSimpleVarRef foreachVarRef = ASTBuilderUtil.createVariableRef(pos, foreachVariable.symbol);
Expand Down Expand Up @@ -9925,7 +9922,7 @@ private BType createDetailType(List<BLangErrorVariable.BLangErrorDetailEntry> de
}

for (BLangErrorVariable.BLangErrorDetailEntry detailEntry : detail) {
Name fieldName = names.fromIdNode(detailEntry.key);
Name fieldName = Names.fromIdNode(detailEntry.key);
BType fieldType = getStructuredBindingPatternType(detailEntry.valueBindingPattern);
BVarSymbol fieldSym = new BVarSymbol(Flags.PUBLIC, fieldName, detailRecordType.tsymbol.pkgID, fieldType,
detailRecordType.tsymbol, detailEntry.key.pos, VIRTUAL);
Expand Down Expand Up @@ -10453,7 +10450,7 @@ private BLangFunction createInitFunctionForClassDefn(BLangClassDefinition classD
}

BLangFunction initFunction =
TypeDefBuilderHelper.createInitFunctionForStructureType(classDefinition.symbol, env, names,
TypeDefBuilderHelper.createInitFunctionForStructureType(classDefinition.symbol, env,
GENERATED_INIT_SUFFIX, classDefinition.getBType(), returnType);
BObjectTypeSymbol typeSymbol = ((BObjectTypeSymbol) classDefinition.getBType().tsymbol);
typeSymbol.generatedInitializerFunc = new BAttachedFunction(GENERATED_INIT_SUFFIX, initFunction.symbol,
Expand Down
Loading

0 comments on commit 48f0a8a

Please sign in to comment.