-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
DeclarationOrigin
to native declarations
This update introduces `DeclarationOrigin` information in various native declarations, such as `NativeFunction`, `NativeTypeAlias`, `NativeEnumeration`, and related classes. It provides a structure for noting where specific declarations originate from - be it from a platform-specific header, a library header or an unknown origin. This improves traceability, allows for more precise logging and debugging, and could enhance code generation based on origin information.
- Loading branch information
Alexandre Mommers
committed
Feb 13, 2024
1 parent
4218797
commit 12cdc56
Showing
19 changed files
with
120 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
klang/klang/src/main/kotlin/klang/ObjectiveCDefaultDeclarations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
package klang.domain | ||
|
||
data class NativeVariable(override val name: String, val type: String): NameableDeclaration, NativeDeclaration | ||
data class NativeVariable( | ||
override val name: String, | ||
val type: String, | ||
override val source: DeclarationOrigin | ||
): NameableDeclaration, NativeDeclaration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
klang/klang/src/main/kotlin/klang/parser/libclang/panama/NativeEnumeration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
klang/klang/src/main/kotlin/klang/parser/libclang/panama/NativeFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
klang/klang/src/main/kotlin/klang/parser/libclang/panama/NativeStructure.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
klang/klang/src/main/kotlin/klang/parser/libclang/panama/NativeTypeAlias.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package klang.parser.libclang.panama | ||
|
||
import klang.domain.DeclarationOrigin | ||
import klang.domain.NameableDeclaration | ||
import klang.domain.NativeTypeAlias | ||
import org.openjdk.jextract.Declaration | ||
|
||
internal fun Declaration.Typedef.toNativeTypeAlias(): NameableDeclaration? = (name() to type().toTypeRef()) | ||
.let { (name, typeRef) -> NativeTypeAlias(name, typeRef) } | ||
internal fun Declaration.Typedef.toNativeTypeAlias(origin: DeclarationOrigin): NameableDeclaration? = (name() to type().toTypeRef()) | ||
.let { (name, typeRef) -> NativeTypeAlias(name, typeRef, origin) } |
21 changes: 21 additions & 0 deletions
21
klang/klang/src/main/kotlin/klang/parser/libclang/panama/OriginProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package klang.parser.libclang.panama | ||
|
||
import klang.domain.DeclarationOrigin | ||
import org.openjdk.jextract.Position | ||
import java.nio.file.Path | ||
import kotlin.io.path.absolutePathString | ||
|
||
object OriginProcessor { | ||
|
||
internal fun Position?.toOrigin(filePath: Path?): DeclarationOrigin = when { | ||
filePath == null || this == null -> DeclarationOrigin.UnknownOrigin | ||
else -> when { | ||
isInFilePath(filePath) -> DeclarationOrigin.LibraryHeader(path().absolutePathString()) | ||
else -> DeclarationOrigin.PlatformHeader | ||
} | ||
} | ||
|
||
private fun Position.isInFilePath(filePath: Path) = | ||
path().absolutePathString().contains(filePath.absolutePathString()) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters