mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Break cef.h into multiple headers (issue #142).
- Move wrapper classes from cef_wrapper.h to wrapper/ directory. - Move C API functions/classes from cef_capi.h to capi/ directory. - Move global function implementations from cef_context.cc to *_impl.cc files. - Output auto-generated file paths in cef_paths.gypi. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@442 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -94,6 +94,10 @@ def wrap_code(code, indent = ' ', maxchars = 80, splitchars = '(=,'):
|
||||
|
||||
return output
|
||||
|
||||
def get_capi_file_name(cppname):
|
||||
""" Convert a C++ header file name to a C API header file name. """
|
||||
return cppname[:-2]+'_capi.h'
|
||||
|
||||
def get_capi_name(cppname, isclassname, prefix = None):
|
||||
""" Convert a C++ CamelCaps name to a C API underscore name. """
|
||||
result = ''
|
||||
@ -193,7 +197,7 @@ def format_comment(comment, indent, translate_map = None, maxchars = 80):
|
||||
if didremovespace:
|
||||
result += ' '+line
|
||||
else:
|
||||
result += line;
|
||||
result += line
|
||||
result += '\n'
|
||||
else:
|
||||
# add to the current paragraph
|
||||
@ -321,8 +325,12 @@ def dict_to_str(dict):
|
||||
str = []
|
||||
for name in dict.keys():
|
||||
if not isinstance(dict[name], list):
|
||||
# currently a string value
|
||||
str.append(name+'='+dict[name])
|
||||
if dict[name] is True:
|
||||
# currently a bool value
|
||||
str.append(name)
|
||||
else:
|
||||
# currently a string value
|
||||
str.append(name+'='+dict[name])
|
||||
else:
|
||||
# currently a list value
|
||||
for val in dict[name]:
|
||||
@ -420,11 +428,26 @@ def get_copyright():
|
||||
class obj_header:
|
||||
""" Class representing a C++ header file. """
|
||||
|
||||
def __init__(self, filename):
|
||||
self.filename = filename;
|
||||
def __init__(self):
|
||||
self.filenames = []
|
||||
self.typedefs = []
|
||||
self.funcs = []
|
||||
self.classes = []
|
||||
|
||||
def add_directory(self, directory):
|
||||
""" Add all header files from the specified directory. """
|
||||
files = get_files(os.path.join(directory, '*.h'))
|
||||
for file in files:
|
||||
self.add_file(file)
|
||||
|
||||
def add_file(self, filepath):
|
||||
""" Add a header file. """
|
||||
|
||||
filename = os.path.split(filepath)[1]
|
||||
added = False
|
||||
|
||||
# read the input file into memory
|
||||
data = read_file(filename)
|
||||
data = read_file(filepath)
|
||||
|
||||
# remove space from between template definition end brackets
|
||||
data = data.replace("> >", ">>")
|
||||
@ -434,23 +457,27 @@ class obj_header:
|
||||
_cre_space+_cre_cfname+';',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
|
||||
# build the global typedef objects
|
||||
self.typedefs = []
|
||||
for value, alias in list:
|
||||
self.typedefs.append(obj_typedef(self, value, alias))
|
||||
if len(list) > 0:
|
||||
# build the global typedef objects
|
||||
for value, alias in list:
|
||||
self.typedefs.append(obj_typedef(self, filename, value, alias))
|
||||
|
||||
# extract global functions
|
||||
p = re.compile('\n'+_cre_attrib+'\n'+_cre_func+'\((.*?)\)',
|
||||
re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
if len(list) > 0:
|
||||
added = True
|
||||
|
||||
# build the global function objects
|
||||
for attrib, retval, argval in list:
|
||||
comment = get_comment(data, retval+'('+argval+');')
|
||||
self.funcs.append(obj_function(self, filename, attrib, retval,
|
||||
argval, comment))
|
||||
|
||||
# build the global function objects
|
||||
self.funcs = []
|
||||
for attrib, retval, argval in list:
|
||||
comment = get_comment(data, retval+'('+argval+');')
|
||||
self.funcs.append(obj_function(self, attrib, retval, argval,
|
||||
comment))
|
||||
# extract forward declarations
|
||||
p = re.compile('\nclass'+_cre_space+_cre_cfname+';')
|
||||
forward_declares = p.findall(data)
|
||||
|
||||
# extract classes
|
||||
p = re.compile('\n'+_cre_attrib+
|
||||
@ -459,13 +486,19 @@ class obj_header:
|
||||
_cre_space+'CefBase'+
|
||||
'\n{(.*?)};', re.MULTILINE | re.DOTALL)
|
||||
list = p.findall(data)
|
||||
|
||||
# build the class objects
|
||||
self.classes = []
|
||||
for attrib, name, body in list:
|
||||
comment = get_comment(data, name+' : public virtual CefBase')
|
||||
self.classes.append(
|
||||
obj_class(self, attrib, name, body, comment))
|
||||
if len(list) > 0:
|
||||
added = True
|
||||
|
||||
# build the class objects
|
||||
for attrib, name, body in list:
|
||||
comment = get_comment(data, name+' : public virtual CefBase')
|
||||
self.classes.append(
|
||||
obj_class(self, filename, attrib, name, body, comment,
|
||||
forward_declares))
|
||||
|
||||
if added:
|
||||
# a global function or class was read from the header file
|
||||
self.filenames.append(filename)
|
||||
|
||||
def __repr__(self):
|
||||
result = ''
|
||||
@ -490,21 +523,37 @@ class obj_header:
|
||||
|
||||
return result
|
||||
|
||||
def get_file_name(self):
|
||||
""" Return the file name. """
|
||||
return self.filename
|
||||
def get_file_names(self):
|
||||
""" Return the array of header file names. """
|
||||
return self.filenames
|
||||
|
||||
def get_typedefs(self):
|
||||
""" Return the array of typedef objects. """
|
||||
return self.typedefs
|
||||
|
||||
def get_funcs(self):
|
||||
def get_funcs(self, filename = None):
|
||||
""" Return the array of function objects. """
|
||||
return self.funcs
|
||||
if filename is None:
|
||||
return self.funcs
|
||||
else:
|
||||
# only return the functions in the specified file
|
||||
res = []
|
||||
for func in self.funcs:
|
||||
if func.get_file_name() == filename:
|
||||
res.append(func)
|
||||
return res
|
||||
|
||||
def get_classes(self):
|
||||
def get_classes(self, filename = None):
|
||||
""" Return the array of class objects. """
|
||||
return self.classes
|
||||
if filename is None:
|
||||
return self.classes
|
||||
else:
|
||||
# only return the classes in the specified file
|
||||
res = []
|
||||
for cls in self.classes:
|
||||
if cls.get_file_name() == filename:
|
||||
res.append(cls)
|
||||
return res
|
||||
|
||||
def get_class(self, classname, defined_structs = None):
|
||||
""" Return the specified class or None if not found. """
|
||||
@ -544,8 +593,7 @@ class obj_header:
|
||||
|
||||
def get_defined_structs(self):
|
||||
""" Return a list of names already defined structure names. """
|
||||
return ['cef_print_info_t', 'cef_window_info_t',
|
||||
'cef_handler_menuinfo_t', 'cef_base_t']
|
||||
return ['cef_print_info_t', 'cef_window_info_t', 'cef_base_t']
|
||||
|
||||
def get_capi_translations(self):
|
||||
""" Return a dictionary that maps C++ terminology to C API terminology.
|
||||
@ -585,14 +633,17 @@ class obj_header:
|
||||
class obj_class:
|
||||
""" Class representing a C++ class. """
|
||||
|
||||
def __init__(self, parent, attrib, name, body, comment):
|
||||
def __init__(self, parent, filename, attrib, name, body, comment,
|
||||
forward_declares):
|
||||
if not isinstance(parent, obj_header):
|
||||
raise Exception('Invalid parent object type')
|
||||
|
||||
self.parent = parent
|
||||
self.filename = filename
|
||||
self.attribs = str_to_dict(attrib)
|
||||
self.name = name
|
||||
self.comment = comment
|
||||
self.forward_declares = forward_declares
|
||||
|
||||
# extract typedefs
|
||||
p = re.compile('\n'+_cre_space+'typedef'+_cre_space+_cre_retval+
|
||||
@ -603,7 +654,7 @@ class obj_class:
|
||||
# build the typedef objects
|
||||
self.typedefs = []
|
||||
for value, alias in list:
|
||||
self.typedefs.append(obj_typedef(self, value, alias))
|
||||
self.typedefs.append(obj_typedef(self, filename, value, alias))
|
||||
|
||||
# extract static functions
|
||||
p = re.compile('\n'+_cre_space+_cre_attrib+'\n'+_cre_space+'static'+
|
||||
@ -659,9 +710,17 @@ class obj_class:
|
||||
result += "\n};\n"
|
||||
return result
|
||||
|
||||
def get_file_name(self):
|
||||
""" Return the C++ header file name. """
|
||||
return self.filename
|
||||
|
||||
def get_capi_file_name(self):
|
||||
""" Return the CAPI header file name. """
|
||||
return get_capi_file_name(self.filename)
|
||||
|
||||
def get_name(self):
|
||||
""" Return the class name. """
|
||||
return self.name;
|
||||
return self.name
|
||||
|
||||
def get_capi_name(self):
|
||||
""" Return the CAPI structure name for this class. """
|
||||
@ -671,6 +730,11 @@ class obj_class:
|
||||
""" Return the class comment as an array of lines. """
|
||||
return self.comment
|
||||
|
||||
def get_forward_declares(self):
|
||||
""" Return the list of classes that are forward declared for this
|
||||
class. """
|
||||
return self.forward_declares
|
||||
|
||||
def get_attribs(self):
|
||||
""" Return all attributes as a dictionary. """
|
||||
return self.attribs
|
||||
@ -688,7 +752,7 @@ class obj_class:
|
||||
else:
|
||||
# the value is a string
|
||||
return self.attribs[name]
|
||||
return None;
|
||||
return None
|
||||
|
||||
def get_attrib_list(self, name):
|
||||
""" Return all values for specified attribute as a list. """
|
||||
@ -699,19 +763,19 @@ class obj_class:
|
||||
else:
|
||||
# convert the value to a list
|
||||
return [self.attribs[name]]
|
||||
return None;
|
||||
return None
|
||||
|
||||
def get_typedefs(self):
|
||||
""" Return the array of typedef objects. """
|
||||
return self.typedefs;
|
||||
return self.typedefs
|
||||
|
||||
def get_static_funcs(self):
|
||||
""" Return the array of static function objects. """
|
||||
return self.staticfuncs;
|
||||
return self.staticfuncs
|
||||
|
||||
def get_virtual_funcs(self):
|
||||
""" Return the array of virtual function objects. """
|
||||
return self.virtualfuncs;
|
||||
return self.virtualfuncs
|
||||
|
||||
def get_types(self, list):
|
||||
""" Return a dictionary mapping data types to analyzed values. """
|
||||
@ -748,18 +812,27 @@ class obj_class:
|
||||
class obj_typedef:
|
||||
""" Class representing a typedef statement. """
|
||||
|
||||
def __init__(self, parent, value, alias):
|
||||
def __init__(self, parent, filename, value, alias):
|
||||
if not isinstance(parent, obj_header) \
|
||||
and not isinstance(parent, obj_class):
|
||||
raise Exception('Invalid parent object type')
|
||||
|
||||
self.parent = parent
|
||||
self.filename = filename
|
||||
self.alias = alias
|
||||
self.value = self.parent.get_analysis(value, False)
|
||||
|
||||
def __repr__(self):
|
||||
return 'typedef '+self.value.get_type()+' '+self.alias+';'
|
||||
|
||||
def get_file_name(self):
|
||||
""" Return the C++ header file name. """
|
||||
return self.filename
|
||||
|
||||
def get_capi_file_name(self):
|
||||
""" Return the CAPI header file name. """
|
||||
return get_capi_file_name(self.filename)
|
||||
|
||||
def get_alias(self):
|
||||
""" Return the alias. """
|
||||
return self.alias
|
||||
@ -774,14 +847,15 @@ class obj_typedef:
|
||||
""" Return a dictionary mapping data types to analyzed values. """
|
||||
name = self.value.get_type()
|
||||
if not name in list:
|
||||
list[name] = self.value;
|
||||
list[name] = self.value
|
||||
|
||||
|
||||
class obj_function:
|
||||
""" Class representing a function. """
|
||||
|
||||
def __init__(self, parent, attrib, retval, argval, comment):
|
||||
def __init__(self, parent, filename, attrib, retval, argval, comment):
|
||||
self.parent = parent
|
||||
self.filename = filename
|
||||
self.attribs = str_to_dict(attrib)
|
||||
self.retval = obj_argument(self, retval)
|
||||
self.name = self.retval.remove_name()
|
||||
@ -809,6 +883,14 @@ class obj_function:
|
||||
def __repr__(self):
|
||||
return '/* '+dict_to_str(self.attribs)+' */ '+self.get_cpp_proto()
|
||||
|
||||
def get_file_name(self):
|
||||
""" Return the C++ header file name. """
|
||||
return self.filename
|
||||
|
||||
def get_capi_file_name(self):
|
||||
""" Return the CAPI header file name. """
|
||||
return get_capi_file_name(self.filename)
|
||||
|
||||
def get_name(self):
|
||||
""" Return the function name. """
|
||||
return self.name
|
||||
@ -849,7 +931,7 @@ class obj_function:
|
||||
else:
|
||||
# the value is a string
|
||||
return self.attribs[name]
|
||||
return None;
|
||||
return None
|
||||
|
||||
def get_attrib_list(self, name):
|
||||
""" Return all values for specified attribute as a list. """
|
||||
@ -860,7 +942,7 @@ class obj_function:
|
||||
else:
|
||||
# convert the value to a list
|
||||
return [self.attribs[name]]
|
||||
return None;
|
||||
return None
|
||||
|
||||
def get_retval(self):
|
||||
""" Return the return value object. """
|
||||
@ -977,7 +1059,8 @@ class obj_function_static(obj_function):
|
||||
def __init__(self, parent, attrib, retval, argval, comment):
|
||||
if not isinstance(parent, obj_class):
|
||||
raise Exception('Invalid parent object type')
|
||||
obj_function.__init__(self, parent, attrib, retval, argval, comment)
|
||||
obj_function.__init__(self, parent, parent.filename, attrib, retval,
|
||||
argval, comment)
|
||||
|
||||
def __repr__(self):
|
||||
return 'static '+obj_function.__repr__(self)+';'
|
||||
@ -995,7 +1078,8 @@ class obj_function_virtual(obj_function):
|
||||
def __init__(self, parent, attrib, retval, argval, comment, vfmod):
|
||||
if not isinstance(parent, obj_class):
|
||||
raise Exception('Invalid parent object type')
|
||||
obj_function.__init__(self, parent, attrib, retval, argval, comment)
|
||||
obj_function.__init__(self, parent, parent.filename, attrib, retval,
|
||||
argval, comment)
|
||||
if vfmod == 'const':
|
||||
self.isconst = True
|
||||
else:
|
||||
@ -1067,8 +1151,8 @@ class obj_argument:
|
||||
""" Returns the count function for this argument. """
|
||||
# The 'count_func' attribute value format is name:function
|
||||
if not self.parent.has_attrib('count_func'):
|
||||
return None;
|
||||
name = self.type.get_name();
|
||||
return None
|
||||
name = self.type.get_name()
|
||||
vals = self.parent.get_attrib_list('count_func')
|
||||
for val in vals:
|
||||
parts = string.split(val, ':')
|
||||
@ -1193,7 +1277,7 @@ class obj_argument:
|
||||
return 'string_map_multi_byref_const'
|
||||
return 'string_map_multi_byref'
|
||||
|
||||
return 'invalid';
|
||||
return 'invalid'
|
||||
|
||||
def get_retval_type(self):
|
||||
""" Returns the retval type as defined in translator.README.txt. """
|
||||
@ -1226,7 +1310,7 @@ class obj_argument:
|
||||
else:
|
||||
return 'refptr_diff'
|
||||
|
||||
return 'invalid';
|
||||
return 'invalid'
|
||||
|
||||
def get_retval_default(self, for_capi):
|
||||
""" Returns the default return value based on the retval type. """
|
||||
@ -1239,7 +1323,7 @@ class obj_argument:
|
||||
return '1'
|
||||
if retval == 'false':
|
||||
return '0'
|
||||
return retval;
|
||||
return retval
|
||||
|
||||
# next look at the retval type value.
|
||||
type = self.get_retval_type()
|
||||
@ -1678,7 +1762,7 @@ class obj_analysis:
|
||||
result += resdict['value']
|
||||
|
||||
if self.has_name():
|
||||
result += ' '+self.get_name();
|
||||
result += ' '+self.get_name()
|
||||
|
||||
return {'format' : format, 'value' : result}
|
||||
|
||||
@ -1690,13 +1774,14 @@ if __name__ == "__main__":
|
||||
|
||||
# verify that the correct number of command-line arguments are provided
|
||||
if len(sys.argv) != 2:
|
||||
sys.stderr.write('Usage: '+sys.argv[0]+' <infile>')
|
||||
sys.stderr.write('Usage: '+sys.argv[0]+' <directory>')
|
||||
sys.exit()
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
# create the header object
|
||||
header = obj_header(sys.argv[1])
|
||||
header = obj_header()
|
||||
header.add_directory(sys.argv[1])
|
||||
|
||||
# output the type mapping
|
||||
types = {}
|
||||
|
Reference in New Issue
Block a user