fix: yaml generator for clang 15 and up (#4076)

* fix(yaml): use find_clang as for datacopy

* fix: use library path provided by clang python package first

* fix: anonymous structs and unions

* fix: typedefd struct attributes
This commit is contained in:
Raphael Coeffic
2023-09-21 15:17:42 +02:00
committed by GitHub
parent 22a4e67117
commit ce03cbf651
2 changed files with 21 additions and 26 deletions
+10 -9
View File
@@ -4,6 +4,7 @@
#
import os
import sys
from clang.cindex import *
# Check if libclang is able to find the builtin include files.
@@ -28,6 +29,9 @@ def canFindBuiltinHeaders(index, args = []):
# for all manual installations (the ones where the builtin header path problem
# is very common) as well as a set of very common distributions.
def getBuiltinHeaderPath(library_path):
if not library_path:
return None
if os.path.isfile(library_path):
library_path = os.path.dirname(library_path)
@@ -56,10 +60,11 @@ def getBuiltinHeaderPath(library_path):
def findLibClang():
if sys.platform == "darwin":
knownPaths = [
"/usr/local/Cellar/llvm/6.0.0/lib",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib",
"/Library/Developer/CommandLineTools/usr/lib"
]
if Config.library_path:
knownPaths.insert(0, Config.library_path)
libSuffix = ".dylib"
elif sys.platform.startswith("linux"):
knownPaths = [
@@ -90,17 +95,14 @@ def initLibClang():
library_path = findLibClang()
if library_path:
#print("libclang found: " + library_path)
print("libclang found: " + library_path, file=sys.stderr)
if os.path.isdir(library_path):
Config.set_library_path(library_path)
else:
Config.set_library_file(library_path)
else:
print("ERROR: libclang not found!", file=sys.stderr)
return False
Config.set_compatibility_check(False)
try:
index = Index.create()
except Exception as e:
@@ -109,9 +111,8 @@ def initLibClang():
global builtin_hdr_path
builtin_hdr_path = getBuiltinHeaderPath(library_path)
if not builtin_hdr_path:
print("ERROR: builtin header path not found", file=sys.stderr)
return False
if builtin_hdr_path:
print("builtin header path found: " + builtin_hdr_path, file=sys.stderr)
# Everything is OK, libclang can be used
return True
+11 -17
View File
@@ -1,6 +1,8 @@
#!/usr/bin/python
import os
import sys
import find_clang
from clang.cindex import *
# debug
@@ -145,7 +147,7 @@ class FieldAST(AST_Element):
if self.type == 'char':
self.type = 'string'
else:
self.type = map_type(t.spelling)
self.type = map_type(t.get_canonical().spelling)
class StructAST(AST_Element):
@@ -158,7 +160,7 @@ class StructAST(AST_Element):
if len(alt_name) > 0:
name = alt_name
if name == '':
if name == '' or (isinstance(cursor,Cursor) and cursor.is_anonymous()):
name = self.name_prefix() + 'anonymous_' + get_next_anon()
else:
name = self.name_prefix() + name
@@ -491,23 +493,15 @@ def print_ast_node(ast_node):
if len(sys.argv) < 2:
bail_out(f"usage: {sys.argv[0]} [header file name] [template] [node name] [additional compile args]")
CLANG_LIB_LOCATIONS = [
'/usr/local/Cellar/llvm/6.0.0/lib/libclang.dylib',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib',
'/Library/Developer/CommandLineTools/usr/lib/libclang.dylib',
'/usr/lib/x86_64-linux-gnu/libclang-6.0.so.1',
'/usr/lib/aarch64-linux-gnu/libclang-6.0.so.1'
]
if not find_clang.initLibClang():
sys.exit(-1)
# set clang lib file
for lib in CLANG_LIB_LOCATIONS:
if os.path.exists(lib):
Config.set_library_file(lib)
break
index = find_clang.index
args = ['-x', 'c++', '-std=c++11', '-Wno-deprecated-register'] + sys.argv[4:]
if find_clang.builtin_hdr_path:
args.append("-I" + find_clang.builtin_hdr_path)
# compile source file
index = Index.create()
translation_unit = index.parse(sys.argv[1], ['-x', 'c++', '-std=c++11', '-Wno-deprecated-register'] + sys.argv[4:])
translation_unit = index.parse(sys.argv[1], args)
def show_tu_diags(diags, prefix=''):
tu_errors = 0