Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying signature checks in the SymbolResolver #1379

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,6 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {
walker.iterate(tu)
}

/*walker.registerHandler(::resolveFieldUsages)
for (tu in component.translationUnits) {
currentTU = tu
walker.iterate(tu)
}

walker.clearCallbacks()
walker.registerHandler(::resolveReference)
for (tu in component.translationUnits) {
currentTU = tu
walker.iterate(tu)
}

walker.clearCallbacks()
walker.registerHandler(::resolveCalls)
for (tu in component.translationUnits) {
walker.iterate(tu)
}*/

walker.strategy = Strategy::EOG_FORWARD
walker.clearCallbacks()
walker.registerHandler(this::handle)
Expand Down Expand Up @@ -831,23 +812,6 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {
.toSet()
}

/**
* @param signature of the ConstructExpression
* @param recordDeclaration matching the class the ConstructExpression wants to construct
* @return ConstructorDeclaration that matches the provided signature
*/
protected fun getConstructorDeclarationDirectMatch(
signature: List<Type>,
recordDeclaration: RecordDeclaration
): ConstructorDeclaration? {
for (constructor in recordDeclaration.constructors) {
if (constructor.hasSignature(signature)) {
return constructor
}
}
return null
}

/**
* @param constructExpression we want to find an invocation target for
* @param recordDeclaration associated with the Object the ConstructExpression constructs
Expand All @@ -861,7 +825,8 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {
): ConstructorDeclaration {
val signature = constructExpression.signature
var constructorCandidate =
getConstructorDeclarationDirectMatch(signature, recordDeclaration)
recordDeclaration.constructors.firstOrNull { it.hasSignature(signature) }

if (constructorCandidate == null && constructExpression.language is HasDefaultArguments) {
// Check for usage of default args
constructorCandidate =
Expand Down
Loading