Improve inheritance support in the CEF API (issue #1623).

- Support single parent inheritance in CEF API classes.
- Support non-virtual inheritance in CEF API classes.
- Support translation of CEF API sub-directories.
- Add test sub-directories for testing-only functionality that will be
  available to unit tests but not exposed via the binary distribution.
- Add unit tests for the translator tool.
- Fix parsing of template parameter types that include commas.
This commit is contained in:
Marshall Greenblatt
2015-04-26 21:40:01 +03:00
parent 4715a1644e
commit 616fdbf3ff
408 changed files with 13269 additions and 4680 deletions

View File

@ -4,21 +4,60 @@
from cef_parser import *
def make_function_body_block(cls):
impl = ' // '+cls.get_name()+' methods.\n';
funcs = cls.get_virtual_funcs()
for func in funcs:
impl += ' '+func.get_cpp_proto()
if cls.is_client_side():
impl += ' override;\n'
else:
impl += ' OVERRIDE;\n'
return impl
def make_function_body(header, cls):
impl = make_function_body_block(cls)
cur_cls = cls
while True:
parent_name = cur_cls.get_parent_name()
if parent_name == 'CefBase':
break
else:
parent_cls = header.get_class(parent_name)
if parent_cls is None:
raise Exception('Class does not exist: '+parent_name)
if len(impl) > 0:
impl += '\n'
impl += make_function_body_block(parent_cls)
cur_cls = header.get_class(parent_name)
return impl
def make_ctocpp_header(header, clsname):
cls = header.get_class(clsname)
if cls is None:
raise Exception('Class does not exist: '+clsname)
clientside = cls.is_client_side()
defname = string.upper(get_capi_name(clsname[3:], False))
directory = cls.get_file_directory()
defname = ''
if not directory is None:
defname += directory + '_'
defname += get_capi_name(clsname[3:], False)
defname = defname.upper()
capiname = cls.get_capi_name()
result = get_copyright()
result += '#ifndef CEF_LIBCEF_DLL_CTOCPP_'+defname+'_CTOCPP_H_\n'+ \
'#define CEF_LIBCEF_DLL_CTOCPP_'+defname+'_CTOCPP_H_\n' + \
'#pragma once\n'
if clientside:
result += """
#ifndef BUILDING_CEF_SHARED
@ -33,13 +72,7 @@ def make_ctocpp_header(header, clsname):
"""
# build the function body
func_body = ''
funcs = cls.get_virtual_funcs()
for func in funcs:
if clientside:
func_body += ' '+func.get_cpp_proto()+' override;\n'
else:
func_body += ' virtual '+func.get_cpp_proto()+' OVERRIDE;\n'
func_body = make_function_body(header, cls)
# include standard headers
if func_body.find('std::map') > 0 or func_body.find('std::multimap') > 0:
@ -58,7 +91,7 @@ def make_ctocpp_header(header, clsname):
if dcls.get_file_name() != cls.get_file_name():
result += '#include "include/'+dcls.get_file_name()+'"\n' \
'#include "include/capi/'+dcls.get_capi_file_name()+'"\n'
result += """#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
@ -68,57 +101,58 @@ def make_ctocpp_header(header, clsname):
result += '// This class may be instantiated and accessed DLL-side only.\n'
else:
result += '// This class may be instantiated and accessed wrapper-side only.\n'
result += 'class '+clsname+'CToCpp\n'+ \
' : public CefCToCpp<'+clsname+'CToCpp, '+clsname+', '+capiname+'> {\n'+ \
' public:\n'+ \
' explicit '+clsname+'CToCpp('+capiname+'* str)\n'+ \
' : CefCToCpp<'+clsname+'CToCpp, '+clsname+', '+capiname+'>(str) {}\n\n'+ \
' // '+clsname+' methods\n';
' '+clsname+'CToCpp();\n\n'
result += func_body
result += '};\n\n'
if clientside:
result += '#endif // BUILDING_CEF_SHARED\n'
else:
result += '#endif // USING_CEF_SHARED\n'
result += '#endif // CEF_LIBCEF_DLL_CTOCPP_'+defname+'_CTOCPP_H_\n'
result += '#endif // CEF_LIBCEF_DLL_CTOCPP_'+defname+'_CTOCPP_H_'
return wrap_code(result)
def write_ctocpp_header(header, clsname, dir, backup):
file = dir+os.sep+get_capi_name(clsname[3:], False)+'_ctocpp.h'
# give the output file the same directory offset as the input file
cls = header.get_class(clsname)
dir = os.path.dirname(os.path.join(dir, cls.get_file_name()))
file = os.path.join(dir, get_capi_name(clsname[3:], False)+'_ctocpp.h')
if path_exists(file):
oldcontents = read_file(file)
else:
oldcontents = ''
newcontents = make_ctocpp_header(header, clsname)
if newcontents != oldcontents:
if backup and oldcontents != '':
backup_file(file)
write_file(file, newcontents)
return True
return False
# test the module
if __name__ == "__main__":
import sys
# verify that the correct number of command-line arguments are provided
if len(sys.argv) < 3:
sys.stderr.write('Usage: '+sys.argv[0]+' <infile> <classname>')
sys.exit()
# create the header object
header = obj_header()
header.add_file(sys.argv[1])
# dump the result to stdout
sys.stdout.write(make_ctocpp_header(header, sys.argv[2]))