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