- 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)(
struct _cef_handler_t* self, struct _cef_browser_t* browser,
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
// 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.
enum cef_retval_t (CEF_CALLBACK *handle_load_error)(
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);
// 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.
enum cef_retval_t (CEF_CALLBACK *handle_get_menu_label)(
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.
// Return RV_HANDLED to cancel default handling of the action.
enum cef_retval_t (CEF_CALLBACK *handle_menu_action)(
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
// 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.
int (CEF_CALLBACK *execute)(struct _cef_v8handler_t* self,
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_v8handler_t;
@ -747,7 +747,7 @@ typedef struct _cef_v8value_t
// Execute the function.
int (CEF_CALLBACK *execute_function)(struct _cef_v8value_t* self,
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_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(
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)
{
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(
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)
{
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(
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(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(
struct _cef_handler_t* self, cef_browser_t* browser,
cef_handler_menuid_t menuId)
enum cef_handler_menuid_t menuId)
{
DCHECK(self);
DCHECK(browser);

View File

@ -19,7 +19,7 @@
int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* self,
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)
{
DCHECK(self);
@ -36,8 +36,7 @@ int CEF_CALLBACK v8handler_execute(struct _cef_v8handler_t* self,
CefV8ValueList list;
for(size_t i = 0; i < argumentCount; ++i) {
list.push_back(CefV8ValueCToCpp::Wrap(
const_cast<cef_v8value_t*>(arguments[i])));
list.push_back(CefV8ValueCToCpp::Wrap(arguments[i]));
}
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,
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)
{
DCHECK(self);
@ -407,8 +407,7 @@ int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self,
CefRefPtr<CefV8Value> objectPtr = CefV8ValueCppToC::Unwrap(object);
CefV8ValueList argsList;
for(size_t i = 0; i < argumentCount; i++) {
argsList.push_back(CefV8ValueCppToC::Unwrap(
const_cast<cef_v8value_t*>(arguments[i])));
argsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i]));
}
CefRefPtr<CefV8Value> retvalPtr;
std::wstring exceptionStr;

View File

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

View File

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

View File

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