- change 'void *' arguments to 'void* ' to match style requirements.

translator:
- add support for const virtual methods. (Issue # 36)
- output const vector argument types as 'struct _class_t* const*' (cons array, non-const members) instead of 'const struct _class_t**' (non-const array, const members) (Issue # 36)
- always add the 'enum' qualifier when outputting C API enum attribute types. (Issue # 38)
- update translated files.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@31 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2009-06-25 15:59:48 +00:00
parent 8a04c0f0c1
commit 0a92d27cc1
22 changed files with 90 additions and 74 deletions

View File

@ -352,7 +352,7 @@ typedef struct _cef_handler_t
enum cef_retval_t (CEF_CALLBACK *handle_before_browse)( enum cef_retval_t (CEF_CALLBACK *handle_before_browse)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, struct _cef_request_t* request, struct _cef_frame_t* frame, struct _cef_request_t* request,
cef_handler_navtype_t navType, int isRedirect); enum cef_handler_navtype_t navType, int isRedirect);
// Event called when the browser begins loading a page. The |frame| pointer // Event called when the browser begins loading a page. The |frame| pointer
// will be NULL if the event represents the overall load status and not the // will be NULL if the event represents the overall load status and not the
@ -375,7 +375,7 @@ typedef struct _cef_handler_t
// Otherwise, return RV_CONTINUE for the default error text. // Otherwise, return RV_CONTINUE for the default error text.
enum cef_retval_t (CEF_CALLBACK *handle_load_error)( enum cef_retval_t (CEF_CALLBACK *handle_load_error)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
struct _cef_frame_t* frame, cef_handler_errorcode_t errorCode, struct _cef_frame_t* frame, enum cef_handler_errorcode_t errorCode,
const wchar_t* failedUrl, cef_string_t* errorText); const wchar_t* failedUrl, cef_string_t* errorText);
// Event called before a resource is loaded. To allow the resource to load // Event called before a resource is loaded. To allow the resource to load
@ -401,13 +401,13 @@ typedef struct _cef_handler_t
// alternate text. The return value is currently ignored. // alternate text. The return value is currently ignored.
enum cef_retval_t (CEF_CALLBACK *handle_get_menu_label)( enum cef_retval_t (CEF_CALLBACK *handle_get_menu_label)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
cef_handler_menuid_t menuId, cef_string_t* label); enum cef_handler_menuid_t menuId, cef_string_t* label);
// Event called when an option is selected from the default context menu. // Event called when an option is selected from the default context menu.
// Return RV_HANDLED to cancel default handling of the action. // Return RV_HANDLED to cancel default handling of the action.
enum cef_retval_t (CEF_CALLBACK *handle_menu_action)( enum cef_retval_t (CEF_CALLBACK *handle_menu_action)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, struct _cef_handler_t* self, struct _cef_browser_t* browser,
cef_handler_menuid_t menuId); enum cef_handler_menuid_t menuId);
// Event called to format print headers and footers. |printInfo| contains // Event called to format print headers and footers. |printInfo| contains
// platform-specific information about the printer context. |url| is the URL // platform-specific information about the printer context. |url| is the URL
@ -658,7 +658,7 @@ typedef struct _cef_v8handler_t
// if the function was handled. // if the function was handled.
int (CEF_CALLBACK *execute)(struct _cef_v8handler_t* self, int (CEF_CALLBACK *execute)(struct _cef_v8handler_t* self,
const wchar_t* name, struct _cef_v8value_t* object, size_t argumentCount, const wchar_t* name, struct _cef_v8value_t* object, size_t argumentCount,
const struct _cef_v8value_t** arguments, struct _cef_v8value_t** retval, struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval,
cef_string_t* exception); cef_string_t* exception);
} cef_v8handler_t; } cef_v8handler_t;
@ -747,7 +747,7 @@ typedef struct _cef_v8value_t
// Execute the function. // Execute the function.
int (CEF_CALLBACK *execute_function)(struct _cef_v8value_t* self, int (CEF_CALLBACK *execute_function)(struct _cef_v8value_t* self,
struct _cef_v8value_t* object, size_t argumentCount, struct _cef_v8value_t* object, size_t argumentCount,
const struct _cef_v8value_t** arguments, struct _cef_v8value_t** retval, struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval,
cef_string_t* exception); cef_string_t* exception);
} cef_v8value_t; } cef_v8value_t;

View File

@ -118,7 +118,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_title_change(
enum cef_retval_t CEF_CALLBACK handler_handle_before_browse( enum cef_retval_t CEF_CALLBACK handler_handle_before_browse(
struct _cef_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, struct _cef_handler_t* self, cef_browser_t* browser, cef_frame_t* frame,
struct _cef_request_t* request, cef_handler_navtype_t navType, struct _cef_request_t* request, enum cef_handler_navtype_t navType,
int isRedirect) int isRedirect)
{ {
DCHECK(self); DCHECK(self);
@ -167,7 +167,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_load_end(
enum cef_retval_t CEF_CALLBACK handler_handle_load_error( enum cef_retval_t CEF_CALLBACK handler_handle_load_error(
struct _cef_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, struct _cef_handler_t* self, cef_browser_t* browser, cef_frame_t* frame,
cef_handler_errorcode_t errorCode, const wchar_t* failedUrl, enum cef_handler_errorcode_t errorCode, const wchar_t* failedUrl,
cef_string_t* errorText) cef_string_t* errorText)
{ {
DCHECK(self); DCHECK(self);
@ -245,7 +245,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_menu(
enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label( enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label(
struct _cef_handler_t* self, cef_browser_t* browser, struct _cef_handler_t* self, cef_browser_t* browser,
cef_handler_menuid_t menuId, cef_string_t* label) enum cef_handler_menuid_t menuId, cef_string_t* label)
{ {
DCHECK(self); DCHECK(self);
DCHECK(browser); DCHECK(browser);
@ -267,7 +267,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_get_menu_label(
enum cef_retval_t CEF_CALLBACK handler_handle_menu_action( enum cef_retval_t CEF_CALLBACK handler_handle_menu_action(
struct _cef_handler_t* self, cef_browser_t* browser, struct _cef_handler_t* self, cef_browser_t* browser,
cef_handler_menuid_t menuId) enum cef_handler_menuid_t menuId)
{ {
DCHECK(self); DCHECK(self);
DCHECK(browser); DCHECK(browser);

View File

@ -19,7 +19,7 @@
int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* self, int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* self,
const wchar_t* name, struct _cef_v8value_t* object, size_t argumentCount, const wchar_t* name, struct _cef_v8value_t* object, size_t argumentCount,
const struct _cef_v8value_t** arguments, struct _cef_v8value_t** retval, struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval,
cef_string_t* exception) cef_string_t* exception)
{ {
DCHECK(self); DCHECK(self);
@ -36,8 +36,7 @@ int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* self,
CefV8ValueList list; CefV8ValueList list;
for(size_t i = 0; i < argumentCount; ++i) { for(size_t i = 0; i < argumentCount; ++i) {
list.push_back(CefV8ValueCToCpp::Wrap( list.push_back(CefV8ValueCToCpp::Wrap(arguments[i]));
const_cast<cef_v8value_t*>(arguments[i])));
} }
CefRefPtr<CefV8Value> retValPtr; CefRefPtr<CefV8Value> retValPtr;

View File

@ -396,7 +396,7 @@ cef_v8handler_t* CEF_CALLBACK v8value_get_function_handler(
int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self, int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self,
struct _cef_v8value_t* object, size_t argumentCount, struct _cef_v8value_t* object, size_t argumentCount,
const struct _cef_v8value_t** arguments, struct _cef_v8value_t** retval, struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval,
cef_string_t* exception) cef_string_t* exception)
{ {
DCHECK(self); DCHECK(self);
@ -407,8 +407,7 @@ int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self,
CefRefPtr<CefV8Value> objectPtr = CefV8ValueCppToC::Unwrap(object); CefRefPtr<CefV8Value> objectPtr = CefV8ValueCppToC::Unwrap(object);
CefV8ValueList argsList; CefV8ValueList argsList;
for(size_t i = 0; i < argumentCount; i++) { for(size_t i = 0; i < argumentCount; i++) {
argsList.push_back(CefV8ValueCppToC::Unwrap( argsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i]));
const_cast<cef_v8value_t*>(arguments[i])));
} }
CefRefPtr<CefV8Value> retvalPtr; CefRefPtr<CefV8Value> retvalPtr;
std::wstring exceptionStr; std::wstring exceptionStr;

View File

@ -36,8 +36,7 @@ bool CefV8HandlerCToCpp::Execute(const std::wstring& name,
cef_string_t exceptionStr = NULL; cef_string_t exceptionStr = NULL;
int rv = struct_->execute(struct_, name.c_str(), int rv = struct_->execute(struct_, name.c_str(),
CefV8ValueCppToC::Wrap(object), argsSize, CefV8ValueCppToC::Wrap(object), argsSize, argsStructPtr, &retvalStruct,
const_cast<const cef_v8value_t**>(argsStructPtr), &retvalStruct,
&exceptionStr); &exceptionStr);
if(retvalStruct) if(retvalStruct)
retval = CefV8ValueCppToC::Unwrap(retvalStruct); retval = CefV8ValueCppToC::Unwrap(retvalStruct);

View File

@ -369,8 +369,7 @@ bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr<CefV8Value> object,
cef_string_t exceptionStr = NULL; cef_string_t exceptionStr = NULL;
int rv = struct_->execute_function(struct_, CefV8ValueCToCpp::Unwrap(object), int rv = struct_->execute_function(struct_, CefV8ValueCToCpp::Unwrap(object),
argsSize, const_cast<const cef_v8value_t**>(argsStructPtr), &retvalStruct, argsSize, argsStructPtr, &retvalStruct, &exceptionStr);
&exceptionStr);
if(retvalStruct) if(retvalStruct)
retval = CefV8ValueCToCpp::Wrap(retvalStruct); retval = CefV8ValueCToCpp::Wrap(retvalStruct);
if(exceptionStr) { if(exceptionStr) {

View File

@ -341,6 +341,8 @@ _cre_cfname = '([A-Za-z0-9_]{1,})'
_cre_retval = '([A-Za-z0-9_<>:,\*\&]{1,})' _cre_retval = '([A-Za-z0-9_<>:,\*\&]{1,})'
# regex for matching function return value and name combination # regex for matching function return value and name combination
_cre_func = '([A-Za-z][A-Za-z0-9_<>:,\*\& ]{1,})' _cre_func = '([A-Za-z][A-Za-z0-9_<>:,\*\& ]{1,})'
# regex for matching virtual function modifiers
_cre_vfmod = '([A-Za-z0-9_]{0,})'
# regex for matching arbitrary whitespace # regex for matching arbitrary whitespace
_cre_space = '[\s]{1,}' _cre_space = '[\s]{1,}'
@ -351,14 +353,14 @@ def get_function_impls(content, ident):
the value. the value.
""" """
# extract the functions # extract the functions
p = re.compile('\n'+_cre_func+'\((.*?)\)' p = re.compile('\n'+_cre_func+'\((.*?)\)([A-Za-z0-9_\s]{0,})'+
+ _cre_space+'\{(.*?)\n\}', '\{(.*?)\n\}',
re.MULTILINE | re.DOTALL) re.MULTILINE | re.DOTALL)
list = p.findall(content) list = p.findall(content)
# build the function map with the function name as the key # build the function map with the function name as the key
result = [] result = []
for retval, argval, body in list: for retval, argval, vfmod, body in list:
if retval.find(ident) < 0: if retval.find(ident) < 0:
# the identifier was not found # the identifier was not found
continue continue
@ -384,6 +386,7 @@ def get_function_impls(content, ident):
'retval' : string.strip(retval), 'retval' : string.strip(retval),
'name' : name, 'name' : name,
'args' : args, 'args' : args,
'vfmod' : string.strip(vfmod),
'body' : body 'body' : body
}) })
@ -591,22 +594,23 @@ class obj_class:
# build the static function objects # build the static function objects
self.staticfuncs = [] self.staticfuncs = []
for attrib, retval, argval in list: for attrib, retval, argval in list:
comment = get_comment(body, retval+'('+argval+');') comment = get_comment(body, retval+'('+argval+')')
self.staticfuncs.append( self.staticfuncs.append(
obj_function_static(self, attrib, retval, argval, comment)) obj_function_static(self, attrib, retval, argval, comment))
# extract virtual functions # extract virtual functions
p = re.compile('\n'+_cre_space+_cre_attrib+'\n'+_cre_space+'virtual'+ p = re.compile('\n'+_cre_space+_cre_attrib+'\n'+_cre_space+'virtual'+
_cre_space+_cre_func+'\((.*?)\)', _cre_space+_cre_func+'\((.*?)\)'+_cre_space+_cre_vfmod,
re.MULTILINE | re.DOTALL) re.MULTILINE | re.DOTALL)
list = p.findall(body) list = p.findall(body)
# build the virtual function objects # build the virtual function objects
self.virtualfuncs = [] self.virtualfuncs = []
for attrib, retval, argval in list: for attrib, retval, argval, vfmod in list:
comment = get_comment(body, retval+'('+argval+') =0;') comment = get_comment(body, retval+'('+argval+')')
self.virtualfuncs.append( self.virtualfuncs.append(
obj_function_virtual(self, attrib, retval, argval, comment)) obj_function_virtual(self, attrib, retval, argval, comment,
vfmod))
def __repr__(self): def __repr__(self):
result = '/* '+dict_to_str(self.attribs)+' */ class '+self.name+"\n{" result = '/* '+dict_to_str(self.attribs)+' */ class '+self.name+"\n{"
@ -791,7 +795,11 @@ class obj_function:
if isinstance(self, obj_function_virtual): if isinstance(self, obj_function_virtual):
# virtual functions get themselves as the first argument # virtual functions get themselves as the first argument
args.append('struct _'+self.parent.get_capi_name()+'* self') str = 'struct _'+self.parent.get_capi_name()+'* self'
if isinstance(self, obj_function_virtual) and self.is_const():
# const virtual functions get const self pointers
str = 'const '+str
args.append(str)
if len(self.arguments) > 0: if len(self.arguments) > 0:
for cls in self.arguments: for cls in self.arguments:
@ -850,6 +858,8 @@ class obj_function:
if not classname is None: if not classname is None:
result += classname+'::' result += classname+'::'
result += parts['name']+'('+string.join(parts['args'], ', ')+')' result += parts['name']+'('+string.join(parts['args'], ', ')+')'
if isinstance(self, obj_function_virtual) and self.is_const():
result += ' const'
return result return result
@ -874,14 +884,22 @@ class obj_function_static(obj_function):
class obj_function_virtual(obj_function): class obj_function_virtual(obj_function):
""" Class representing a virtual function. """ """ Class representing a virtual function. """
def __init__(self, parent, attrib, retval, argval, comment): def __init__(self, parent, attrib, retval, argval, comment, vfmod):
if not isinstance(parent, obj_class): if not isinstance(parent, obj_class):
raise Exception('Invalid parent object type') raise Exception('Invalid parent object type')
obj_function.__init__(self, parent, attrib, retval, argval, comment) obj_function.__init__(self, parent, attrib, retval, argval, comment)
if vfmod == 'const':
self.isconst = True
else:
self.isconst = False
def __repr__(self): def __repr__(self):
return 'virtual '+obj_function.__repr__(self)+';' return 'virtual '+obj_function.__repr__(self)+';'
def is_const(self):
""" Returns true if the method declaration is const. """
return self.isconst
class obj_argument: class obj_argument:
""" Class representing a function argument. """ """ Class representing a function argument. """
@ -1049,6 +1067,7 @@ class obj_analysis:
'int' : 'int', 'int' : 'int',
'double' : 'double', 'double' : 'double',
'long' : 'long', 'long' : 'long',
'unsigned long' : 'unsigned long',
'size_t' : 'size_t', 'size_t' : 'size_t',
'bool' : 'int', 'bool' : 'int',
'CefWindowHandle' : 'cef_window_handle_t' 'CefWindowHandle' : 'cef_window_handle_t'
@ -1150,7 +1169,7 @@ class obj_analysis:
result += 'const ' result += 'const '
if not self.result_value in defined_structs: if not self.result_value in defined_structs:
result += 'struct _' result += 'struct _'
elif not self.has_name(): else:
result += 'enum ' result += 'enum '
result += self.result_value result += self.result_value
if self.is_byref() or self.is_byaddr(): if self.is_byref() or self.is_byaddr():
@ -1193,13 +1212,11 @@ class obj_analysis:
result['value'] = value result['value'] = value
elif type == 'refptr': elif type == 'refptr':
str = '' str = ''
if self.is_const():
str += 'const '
if not value[:-1] in defined_structs: if not value[:-1] in defined_structs:
str += 'struct _' str += 'struct _'
str += value str += value
if self.is_const(): if self.is_const():
str += '*' str += ' const*'
result['value'] = str result['value'] = str
else: else:
raise Exception('Unsupported vector type: '+type) raise Exception('Unsupported vector type: '+type)

View File

@ -6,10 +6,13 @@ from cef_parser import *
def make_ctocpp_impl_proto(clsname, name, func, parts): def make_ctocpp_impl_proto(clsname, name, func, parts):
proto = parts['retval']+' '+clsname proto = parts['retval']+' '+clsname
const = ''
if isinstance(func, obj_function_virtual): if isinstance(func, obj_function_virtual):
proto += 'CToCpp' proto += 'CToCpp'
if func.is_const():
const = ' const'
proto += '::'+name+'('+string.join(parts['args'], ', ')+')' proto += '::'+name+'('+string.join(parts['args'], ', ')+')'+const
return wrap_code(proto) return wrap_code(proto)
def make_ctocpp_impl_existing(clsname, name, func, impl): def make_ctocpp_impl_existing(clsname, name, func, impl):