Generate C interop adapters for functions defined in headers

This commit is contained in:
Svyatoslav Scherbina
2017-03-21 18:22:27 +07:00
committed by SvyatoslavScherbina
parent edd8489f6b
commit 49f1873efd
3 changed files with 8 additions and 3 deletions
@@ -266,7 +266,10 @@ internal class NativeIndexImpl(val language: Language) : NativeIndex() {
Language.C -> clang_Cursor_getMangling(cursor).convertAndDispose() Language.C -> clang_Cursor_getMangling(cursor).convertAndDispose()
} }
functionByName[name] = FunctionDecl(name, args, returnType, binaryName) val definitionCursor = clang_getCursorDefinition(cursor)
val isDefined = (clang_Cursor_isNull(definitionCursor) == 0)
functionByName[name] = FunctionDecl(name, args, returnType, binaryName, isDefined)
} }
CXIdxEntity_Enum -> { CXIdxEntity_Enum -> {
@@ -69,7 +69,8 @@ class Parameter(val name: String?, val type: Type)
/** /**
* C function declaration. * C function declaration.
*/ */
class FunctionDecl(val name: String, val parameters: List<Parameter>, val returnType: Type, val binaryName: String) class FunctionDecl(val name: String, val parameters: List<Parameter>, val returnType: Type, val binaryName: String,
val isDefined: Boolean)
/** /**
* C typedef definition. * C typedef definition.
@@ -909,7 +909,8 @@ class StubGenerator(
return true return true
} }
return this.returnsRecord() || return this.isDefined ||
this.returnsRecord() ||
this.parameters.map { it.type }.any { it.unwrapTypedefs() is RecordType } this.parameters.map { it.type }.any { it.unwrapTypedefs() is RecordType }
} }