Skip to content

Commit

Permalink
feat(core): replace dyncall with libffi. Close LWJGL#283
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Feb 24, 2021
1 parent 075461c commit 84db65f
Show file tree
Hide file tree
Showing 357 changed files with 4,180 additions and 2,437 deletions.
10 changes: 5 additions & 5 deletions modules/extract/src/main/kotlin/org/lwjgl/extract/Extract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ internal fun parse(
}

stackPush().use { stack ->
clang_visitChildren(clang_getTranslationUnitCursor(context.tu, CXCursor.mallocStack(stack))) { cursor, _ ->
CXCursorVisitor.create { cursor, _, _ ->
if (!header.shouldParse(cursor, options)) {
return@clang_visitChildren CXChildVisit_Continue
return@create CXChildVisit_Continue
}

stack.push().use { frame ->
Expand Down Expand Up @@ -244,7 +244,7 @@ internal fun parse(
val underlyingType = clang_getTypedefDeclUnderlyingType(cursor, CXType.mallocStack(frame))
when (underlyingType.kind()) {
CXType_Elaborated -> {
clang_visitChildren(cursor) { child, _ ->
CXCursorVisitor.create { child, _, _ ->
when (clang_getCursorKind(child)) {
CXCursor_EnumDecl -> {
if (options.parseConstants) {
Expand Down Expand Up @@ -288,7 +288,7 @@ internal fun parse(
else -> TODO()
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(cursor, it, NULL) }
}
CXType_Pointer -> {
val pointee = clang_getPointeeType(underlyingType, CXType.mallocStack(frame))
Expand Down Expand Up @@ -347,7 +347,7 @@ internal fun parse(
Unit
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(clang_getTranslationUnitCursor(context.tu, CXCursor.mallocStack(stack)), it, NULL) }
}

if (handles.isNotEmpty()) {
Expand Down
30 changes: 15 additions & 15 deletions modules/extract/src/main/kotlin/org/lwjgl/extract/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal fun parseSimpleType(name: String, nativeName: String, type: String) = "

internal fun parseTypedef(nativeName: String, type: CXType) = "val $nativeName = typedef(${type.lwjgl}, \"$nativeName\")"

@UseExperimental(ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalUnsignedTypes::class)
private fun parseConstant(header: Header, nativeName: String, value: String, doc: Documentation?): String {
val noPrefix = !nativeName.startsWith(header.prefixConstant)

Expand Down Expand Up @@ -180,15 +180,15 @@ internal class Enum(
internal fun CXCursor.parseEnum(context: ExtractionContext, name: String, typedef: Boolean): Enum {
val constants = ArrayList<EnumConstant>()

clang_visitChildren(this) { enumConstantDecl, _ ->
CXCursorVisitor.create { enumConstantDecl, _, _ ->
val constantName = enumConstantDecl.spelling

val doc = stackPush().use { stack ->
clang_Cursor_getParsedComment(enumConstantDecl, CXComment.mallocStack(stack)).parse()
}

val size = constants.size
clang_visitChildren(enumConstantDecl) { enumValue, _ ->
CXCursorVisitor.create { enumValue, _, _ ->
constants.add(
EnumConstant(
constantName,
Expand All @@ -199,7 +199,7 @@ internal fun CXCursor.parseEnum(context: ExtractionContext, name: String, typede
)
)
CXChildVisit_Continue
}
}.use { clang_visitChildren(enumConstantDecl, it, NULL) }
if (constants.size == size) {
constants.add(
EnumConstant(
Expand All @@ -211,7 +211,7 @@ internal fun CXCursor.parseEnum(context: ExtractionContext, name: String, typede
)
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(this, it, NULL) }

stackPush().use { stack ->
val doc = clang_Cursor_getParsedComment(this, CXComment.mallocStack(stack))
Expand Down Expand Up @@ -267,7 +267,7 @@ private fun CXCursor.parseStructMembers(
val attributes = ArrayList<String>()
val members = ArrayList<String>()

clang_visitChildren(this) { fieldDecl, _ ->
CXCursorVisitor.create { fieldDecl, _, _ ->
if (fieldDecl.kind() == CXCursor_UnexposedAttr) {
attributes.add(context.getSource(fieldDecl))
} else {
Expand Down Expand Up @@ -365,7 +365,7 @@ private fun CXCursor.parseStructMembers(
}
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(this, it, NULL) }

return "${attributes.joinToString("\n", postfix = if (attributes.isEmpty()) "" else "\n$indent") { "// $it" }}${members.joinToString("\n$indent")}"
}
Expand Down Expand Up @@ -414,14 +414,14 @@ private fun CXCursor.anonymousFunctionProto(
documentation: String = "Instances of this interface may be passed to the #FIXME() method."
): String {
val args = ArrayList<CXCursor>(clang_getNumArgTypes(proto))
clang_visitChildren(this) { cursor, _ ->
CXCursorVisitor.create { cursor, _, _ ->
if (clang_getCursorKind(cursor) == CXCursor_ParmDecl) {
val cp = CXCursor.mallocStack(stack)
memCopy(cursor, cp)
args.add(cp)
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(this, it, NULL) }

val doc = clang_Cursor_getParsedComment(this, CXComment.mallocStack(stack)).parse()
val docIndent = "$indent$t$t"
Expand All @@ -438,14 +438,14 @@ $indent}"""

internal fun CXCursor.parseCallback(header: Header, type: CXType, name: String): String = stackPush().use { stack ->
val args = ArrayList<CXCursor>(clang_getNumArgTypes(type))
clang_visitChildren(this) { cursor, _ ->
CXCursorVisitor.create { cursor, _, _ ->
if (clang_getCursorKind(cursor) == CXCursor_ParmDecl) {
val cp = CXCursor.mallocStack(stack)
memCopy(cursor, cp)
args.add(cp)
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(this, it, NULL) }

val doc = clang_Cursor_getParsedComment(this, CXComment.mallocStack(stack)).parse()

Expand All @@ -470,14 +470,14 @@ internal fun CXCursor.parseFunction(header: Header): String = stackPush().use {
}
val type = clang_getCursorType(this, CXType.mallocStack(stack))
val args = ArrayList<CXCursor>()
clang_visitChildren(this) { cursor, _ ->
CXCursorVisitor.create { cursor, _, _ ->
if (clang_getCursorKind(cursor) == CXCursor_ParmDecl) {
val cp = CXCursor.mallocStack(stack)
memCopy(cursor, cp)
args.add(cp)
}
CXChildVisit_Continue
}
}.use { clang_visitChildren(this, it, NULL) }

val doc = clang_Cursor_getParsedComment(this, CXComment.mallocStack(stack)).parse()

Expand Down Expand Up @@ -603,10 +603,10 @@ internal fun CXCursor.parseMacro(

private fun CXCursor.hasChild(traversal: Int = CXChildVisit_Continue, predicate: (CXCursor) -> Boolean): Boolean {
var result = false
clang_visitChildren(this) { child, _ ->
CXCursorVisitor.create { child, _, _ ->
result = predicate(child)
traversal
}
}.use { clang_visitChildren(this, it, NULL) }
return result
}

Expand Down
4 changes: 2 additions & 2 deletions modules/extract/src/main/kotlin/org/lwjgl/extract/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ internal fun dump(root: CXCursor, stream: PrintStream, depth: Int) {
clang_getCursorKindSpelling(clang_getCursorKind(root), stack.str).str
)
}
clang_visitChildren(root) { child, _ ->
CXCursorVisitor.create { child, _, _ ->
dump(child, stream, depth + 1)
CXChildVisit_Continue
}
}.use { clang_visitChildren(root, it, NULL) }
}

internal fun CXCursor.text(source: String): String {
Expand Down
Loading

0 comments on commit 84db65f

Please sign in to comment.