Refactor emitter and code templates to use defined template variables.
Also switched from "${...}" to $..., which is swig's common notation
of typemap variables.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13787 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cdd450fbe4
commit
8d72616e65
2 changed files with 175 additions and 157 deletions
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
%fragment ("JS_getproperty", "templates")
|
||||
%{
|
||||
JSValueRef ${getname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
|
||||
JSValueRef $jsgetter(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
$jslocals
|
||||
JSValueRef jsresult;
|
||||
|
||||
$jscode
|
||||
return jsresult;
|
||||
|
||||
goto fail;
|
||||
|
|
@ -26,10 +28,10 @@ JSValueRef ${getname}(JSContextRef context, JSObjectRef thisObject, JSStringRef
|
|||
|
||||
%fragment ("JS_setproperty", "templates")
|
||||
%{
|
||||
bool ${setname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
|
||||
bool $jssetter(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
$jslocals
|
||||
$jscode
|
||||
|
||||
return true;
|
||||
|
||||
|
|
@ -46,10 +48,12 @@ bool ${setname}(JSContextRef context, JSObjectRef thisObject, JSStringRef proper
|
|||
************************************************************************************/
|
||||
%fragment ("JS_functionwrapper", "templates")
|
||||
%{
|
||||
JSValueRef ${functionname}(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
$jslocals
|
||||
JSValueRef jsresult;
|
||||
|
||||
$jscode
|
||||
return jsresult;
|
||||
|
||||
goto fail;
|
||||
|
|
@ -60,10 +64,12 @@ JSValueRef ${functionname}(JSContextRef context, JSObjectRef function, JSObjectR
|
|||
|
||||
%fragment ("JS_functionwrapper_overload", "templates")
|
||||
%{
|
||||
int ${functionname}(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception, JSValueRef* result)
|
||||
int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception, JSValueRef* result)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
$jslocals
|
||||
JSValueRef jsresult;
|
||||
|
||||
$jscode
|
||||
*result = jsresult;
|
||||
return SWIG_OK;
|
||||
|
||||
|
|
@ -80,83 +86,81 @@ int ${functionname}(JSContextRef context, JSObjectRef function, JSObjectRef this
|
|||
***********************************************************************/
|
||||
|
||||
%fragment ("JS_function_dispatch_case", "templates")
|
||||
%{if(argc == ${argcount}) {
|
||||
res = ${functionwrapper}(context, function, thisObject, argc, argv, exception, &jsresult);
|
||||
%{if(argc == $jsargcount) {
|
||||
res = $jswrapper(context, function, thisObject, argc, argv, exception, &jsresult);
|
||||
if(res == SWIG_OK) { *exception = 0; return jsresult; }
|
||||
}
|
||||
%}
|
||||
|
||||
%fragment ("JS_function_dispatch_case_default", "templates")
|
||||
%{
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function ${functionname}.");
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function $jsname.");
|
||||
%}
|
||||
|
||||
/* Added template for function declaration */
|
||||
|
||||
%fragment ("JS_variabledecl", "templates")
|
||||
%{{"${propertyname}",${getname}, ${setname},kJSPropertyAttributeNone},%}
|
||||
%{{"$jsname", $jsgetter, $jssetter, kJSPropertyAttributeNone},%}
|
||||
|
||||
|
||||
/* Added template for function declaration */
|
||||
|
||||
%fragment ("JS_functiondecl", "templates")
|
||||
%{{"${functionname}",${functionwrapper}, kJSPropertyAttributeNone},%}
|
||||
%{{"$jsname",$jswrapper, kJSPropertyAttributeNone},%}
|
||||
|
||||
%fragment ("JS_globaldefn", "templates")
|
||||
%{
|
||||
JSStaticValue ${namespace}_values[] = {
|
||||
${jsglobalvariables}
|
||||
JSStaticValue $jsnspace_values[] = {
|
||||
$jsglobalvariables
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticFunction ${namespace}_functions[] = {
|
||||
${jsglobalfunctions}
|
||||
JSStaticFunction $jsnspace_functions[] = {
|
||||
$jsglobalfunctions
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSClassDefinition ${namespace}_classDefinition;
|
||||
JSClassDefinition $jsnspace_classDefinition;
|
||||
%}
|
||||
|
||||
/******************************************************************************************
|
||||
* class_definition:
|
||||
* This code template is used for wrapper of classes definition.
|
||||
* ${classname_mangled}:the mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
*****************************************************************************************/
|
||||
/***********************************************************************
|
||||
* class_definition:
|
||||
* declarations of javascript class definition objects.
|
||||
***********************************************************************/
|
||||
|
||||
%fragment ("JS_class_definition", "templates")
|
||||
%{
|
||||
JSClassDefinition ${classname_mangled}_classDefinition;
|
||||
JSClassDefinition $jsmangledname_classDefinition;
|
||||
|
||||
JSClassDefinition ${classname_mangled}_objectDefinition;
|
||||
JSClassDefinition $jsmangledname_objectDefinition;
|
||||
|
||||
JSClassRef ${classname_mangled}_classRef;
|
||||
JSClassRef $jsmangledname_classRef;
|
||||
%}
|
||||
|
||||
/*********************************************************************
|
||||
* class_table:
|
||||
* This code template is used to add the wrapper for class declaration
|
||||
* ${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
/***********************************************************************
|
||||
* class_table:
|
||||
* function and variable tables for class and object creation.
|
||||
***********************************************************************/
|
||||
|
||||
%fragment ("JS_class_tables", "templates")
|
||||
%{
|
||||
JSStaticValue ${classname_mangled}_staticValues[] = {
|
||||
${jsstaticclassvariables}
|
||||
JSStaticValue $jsmangledname_staticValues[] = {
|
||||
$jsstaticclassvariables
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticFunction ${classname_mangled}_staticFunctions[] = {
|
||||
${jsstaticclassfunctions}
|
||||
JSStaticFunction $jsmangledname_staticFunctions[] = {
|
||||
$jsstaticclassfunctions
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticValue ${classname_mangled}_values[] = {
|
||||
${jsclassvariables}
|
||||
JSStaticValue $jsmangledname_values[] = {
|
||||
$jsclassvariables
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
JSStaticFunction ${classname_mangled}_functions[] = {
|
||||
${jsclassfunctions}
|
||||
JSStaticFunction $jsmangledname_functions[] = {
|
||||
$jsclassfunctions
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
%}
|
||||
|
|
@ -164,15 +168,14 @@ JSStaticFunction ${classname_mangled}_functions[] = {
|
|||
/*********************************************************************
|
||||
* destructordefn:
|
||||
* This code template is used to adds the destructor wrapper function
|
||||
* ${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
***********************************************************************/
|
||||
|
||||
%fragment ("JS_destructordefn", "templates")
|
||||
%{
|
||||
void _wrap_${classname_mangled}_finalize(JSObjectRef thisObject)
|
||||
void _wrap_$jsmangledname_finalize(JSObjectRef thisObject)
|
||||
{
|
||||
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
|
||||
if(t && t->swigCMemOwn) free ((${type}*)t->swigCObject);
|
||||
if(t && t->swigCMemOwn) free (($jstype*)t->swigCObject);
|
||||
if(t) free(t);
|
||||
}
|
||||
%}
|
||||
|
|
@ -180,22 +183,21 @@ void _wrap_${classname_mangled}_finalize(JSObjectRef thisObject)
|
|||
/*********************************************************************
|
||||
* constructor_definition:
|
||||
* This code template is used to adds the main constructor wrapper function
|
||||
* ${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
%fragment ("JS_mainctordefn", "templates")
|
||||
%{
|
||||
JSObjectRef _wrap_create_${classname_mangled}(JSContextRef context, JSObjectRef ctorObject,
|
||||
JSObjectRef _wrap_create_$jsmangledname(JSContextRef context, JSObjectRef ctorObject,
|
||||
size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
JSObjectRef thisObject = NULL;
|
||||
|
||||
// switch all cases by means of series of if-returns.
|
||||
${DISPATCH_CASES}
|
||||
$jsdispatchcases
|
||||
|
||||
// default:
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for contruction of ${classname_mangled}");
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for contruction of $jsmangledname");
|
||||
|
||||
fail:
|
||||
return thisObject;
|
||||
|
|
@ -207,8 +209,8 @@ ctor_dispatch_case: This template is used for the constructor which is overloade
|
|||
***************************************************************************************/
|
||||
|
||||
%fragment ("JS_ctor_dispatch_case", "templates")
|
||||
%{if(argc == ${argcount}) {
|
||||
thisObject = _wrap_create_${classname_mangled}${overloadext}(context, NULL, argc, argv, exception);
|
||||
%{if(argc == $jsargcount) {
|
||||
thisObject = _wrap_create_$jsmangledname$jsoverloadext(context, NULL, argc, argv, exception);
|
||||
if(thisObject != NULL) { *exception=0; return thisObject; } /* reset exception and return */
|
||||
}
|
||||
%}
|
||||
|
|
@ -216,12 +218,12 @@ ctor_dispatch_case: This template is used for the constructor which is overloade
|
|||
|
||||
%fragment ("JS_ctordefn", "templates")
|
||||
%{
|
||||
JSObjectRef _wrap_create_${classname_mangled}${overloadext}(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
JSObjectRef _wrap_create_$jsmangledname$jsoverloadext(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
|
||||
{
|
||||
${LOCALS}
|
||||
${CODE}
|
||||
$jslocals
|
||||
$jscode
|
||||
|
||||
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_${type_mangled}, SWIG_POINTER_OWN);
|
||||
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
|
||||
|
||||
goto fail;
|
||||
fail:
|
||||
|
|
@ -237,7 +239,7 @@ initializer:This template is dynamic growing and aggregates everything
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool ${modulename}_initialize(JSGlobalContextRef context) {
|
||||
bool $jsname_initialize(JSGlobalContextRef context) {
|
||||
SWIG_InitializeModule(0);
|
||||
|
||||
JSObjectRef global_object = JSContextGetGlobalObject(context);
|
||||
|
|
@ -248,13 +250,13 @@ bool ${modulename}_initialize(JSGlobalContextRef context) {
|
|||
_SwigObject_classRef = JSClassCreate(&_SwigObject_objectDefinition);
|
||||
|
||||
/* Create objects for namespaces */
|
||||
${create_namespaces}
|
||||
$jscreatenamespaces
|
||||
|
||||
/* Create classes */
|
||||
${initializercode}
|
||||
$jsinitializercode
|
||||
|
||||
/* Register namespaces */
|
||||
${register_namespaces}
|
||||
$jsregisternamespaces
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -268,41 +270,35 @@ bool ${modulename}_initialize(JSGlobalContextRef context) {
|
|||
/*****************************************************************************************
|
||||
*create_class_template:
|
||||
*This template is used to add a Static references to class templates.
|
||||
*${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
*****************************************************************************************/
|
||||
|
||||
%fragment ("JS_create_class_template", "templates")
|
||||
%{ ${classname_mangled}_classDefinition.staticFunctions = ${classname_mangled}_staticFunctions;
|
||||
${classname_mangled}_classDefinition.staticValues = ${classname_mangled}_staticValues;
|
||||
${classname_mangled}_classDefinition.callAsConstructor = _wrap_create_${classname_mangled};
|
||||
${classname_mangled}_objectDefinition.staticValues = ${classname_mangled}_values;
|
||||
${classname_mangled}_objectDefinition.staticFunctions = ${classname_mangled}_functions;
|
||||
${classname_mangled}_objectDefinition.parentClass = ${base_classname}_classRef;
|
||||
JSClassRef ${classname_mangled}_classRef = JSClassCreate(&${classname_mangled}_objectDefinition);
|
||||
SWIGTYPE_${classtype_mangled}->clientdata = ${classname_mangled}_classRef;%}
|
||||
%{ $jsmangledname_classDefinition.staticFunctions = $jsmangledname_staticFunctions;
|
||||
$jsmangledname_classDefinition.staticValues = $jsmangledname_staticValues;
|
||||
$jsmangledname_classDefinition.callAsConstructor = _wrap_create_$jsmangledname;
|
||||
$jsmangledname_objectDefinition.staticValues = $jsmangledname_values;
|
||||
$jsmangledname_objectDefinition.staticFunctions = $jsmangledname_functions;
|
||||
$jsmangledname_objectDefinition.parentClass = $jsbaseclass_classRef;
|
||||
JSClassRef $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition);
|
||||
SWIGTYPE_$jsmangledtype->clientdata = $jsmangledname_classRef;%}
|
||||
|
||||
/*****************************************************************************************
|
||||
*register_class:
|
||||
*This template is used to adds a class registration statement to initializer function
|
||||
*${classname_mangled}: The mangled name of the qualified class name, e.g., foo::A -> foo_A
|
||||
* This template is used to adds a class registration statement to initializer function
|
||||
*****************************************************************************************/
|
||||
|
||||
%fragment ("JS_register_class", "templates")
|
||||
%{JS_registerClass(context, ${namespace_mangled}_object, "${classname}", &${classname_mangled}_classDefinition);%}
|
||||
|
||||
/* register global function */
|
||||
%fragment ("JS_register_global_function", "templates")
|
||||
%{JS_registerFunction(${context}, ${context_object}, "${functionname}", ${functionwrapper});%}
|
||||
%{JS_registerClass(context, $jsnspace_object, "$jsname", &$jsmangledname_classDefinition);%}
|
||||
|
||||
|
||||
/* create and register namespaces */
|
||||
|
||||
%fragment ("JS_create_namespace", "templates")
|
||||
%{ ${namespace}_classDefinition.staticFunctions = ${namespace}_functions;
|
||||
${namespace}_classDefinition.staticValues = ${namespace}_values;
|
||||
JSObjectRef ${namespace}_object = JSObjectMake(context, JSClassCreate(&${namespace}_classDefinition), NULL);
|
||||
%{ $jsmangledname_classDefinition.staticFunctions = $jsmangledname_functions;
|
||||
$jsmangledname_classDefinition.staticValues = $jsmangledname_values;
|
||||
JSObjectRef $jsmangledname_object = JSObjectMake(context, JSClassCreate(&$jsmangledname_classDefinition), NULL);
|
||||
%}
|
||||
|
||||
%fragment ("JS_register_namespace", "templates")
|
||||
%{
|
||||
JS_registerNamespace(context, ${namespace_mangled}_object, ${parent_namespace}_object, "${namespace}"); %}
|
||||
JS_registerNamespace(context, $jsmangledname_object, $jsparent_object, "$jsname"); %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue