Improve verbosity when clang_parseTranslationUnit fails

This commit is contained in:
Svyatoslav Scherbina
2019-03-29 10:12:11 +03:00
committed by SvyatoslavScherbina
parent d734303ddf
commit 8a1d8a29b1
@@ -82,15 +82,28 @@ internal fun parseTranslationUnit(
): CXTranslationUnit {
memScoped {
val result = clang_parseTranslationUnit(
val resultVar = alloc<CXTranslationUnitVar>()
val errorCode = clang_parseTranslationUnit2(
index,
sourceFile.absolutePath,
compilerArgs.toNativeStringArray(memScope), compilerArgs.size,
null, 0,
options
)!!
options,
resultVar.ptr
)
return result
if (errorCode != CXErrorCode.CXError_Success) {
val copiedSourceFile = sourceFile.copyTo(createTempFile(suffix = sourceFile.name), overwrite = true)
error("""
clang_parseTranslationUnit2 failed with $errorCode;
sourceFile = ${copiedSourceFile.absolutePath}
arguments = ${compilerArgs.joinToString(" ")}
""".trimIndent())
}
return resultVar.value!!
}
}