Menu

[r13978]: / branches / gsoc2012-javascript / Lib / javascript / jsc / javascriptcode.swg  Maximize  Restore  History

Download this file

293 lines (231 with data), 10.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*********************************************************************
*getproperty: This template gives name to generated wrapper for the getproperty
*{LOCALS}: declarations for input arguments
*{CODE}: contains input marshalling, and the action
*********************************************************************/
%fragment ("JS_getproperty", "templates")
%{
JSValueRef ${getname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
${LOCALS}
${CODE}
return jsresult;
goto fail;
fail:
return NULL;
}
%}
/**********************************************************************
*setproperty: This template gives name to generated wrapper for the setproperty
*{LOCALS}: declarations for input arguments
*{CODE}: contains input marshalling, and the action
**********************************************************************/
%fragment ("JS_setproperty", "templates")
%{
bool ${setname}(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
${LOCALS}
${CODE}
return true;
goto fail;
fail:
return false;
}
%}
/************************************************************************************
*functionwrapper: This template gives name to generated wrapper for the function
*{LOCALS}: declarations for input arguments
*{CODE} contains input marshalling, and the action
************************************************************************************/
%fragment ("JS_functionwrapper", "templates")
%{
JSValueRef ${functionname}(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
${LOCALS}
${CODE}
return jsresult;
goto fail;
fail:
return NULL;
}
%}
/**************************************************************************************
function_dispatch_case: This template is used for the function which is overloaded
***************************************************************************************/
%fragment ("JS_function_dispatch_case", "templates")
%{if(argc == ${argcount}) {
jsresult = ${functionwrapper}(context, function, thisObject, argc, argv, exception);
} else %}
%fragment ("JS_function_dispatch_case_default", "templates")
%{
{
// TODO: throw JS exception
throw "Invalid function arguments.";
}
%}
/* Added template for function declaration */
%fragment ("JS_variabledecl", "templates")
%{{"${propertyname}",${getname}, ${setname},kJSPropertyAttributeNone},%}
/* Added template for function declaration */
%fragment ("JS_functiondecl", "templates")
%{{"${functionname}",${functionwrapper}, kJSPropertyAttributeNone},%}
%fragment ("JS_globaldefn", "templates")
%{
JSStaticValue ${namespace}_values[] = {
${jsglobalvariables}
{ 0, 0, 0, 0 }
};
JSStaticFunction ${namespace}_functions[] = {
${jsglobalfunctions}
{ 0, 0, 0 }
};
JSClassDefinition ${namespace}_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
*****************************************************************************************/
%fragment ("JS_class_definition", "templates")
%{
JSClassDefinition ${classname_mangled}_classDefinition;
JSClassDefinition ${classname_mangled}_objectDefinition;
JSClassRef ${classname_mangled}_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
***********************************************************************/
%fragment ("JS_class_tables", "templates")
%{
JSStaticValue ${classname_mangled}_staticValues[] = {
${jsstaticclassvariables}
{ 0, 0, 0, 0 }
};
JSStaticFunction ${classname_mangled}_staticFunctions[] = {
${jsstaticclassfunctions}
{ 0, 0, 0 }
};
JSStaticValue ${classname_mangled}_values[] = {
${jsclassvariables}
{ 0, 0, 0, 0 }
};
JSStaticFunction ${classname_mangled}_functions[] = {
${jsclassfunctions}
{ 0, 0, 0 }
};
%}
/*********************************************************************
* 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)
{
SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
if(t && t->swigCMemOwn) free ((${type}*)t->swigCObject);
if(t) free(t);
}
%}
/*********************************************************************
* 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,
size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
JSObjectRef thisObject;
${DISPATCH_CASES}
{
// TODO: handle illegal arguments
SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for contruction of ${classname_mangled}");
}
return thisObject;
fail:
return NULL;
}
%}
/**************************************************************************************
ctor_dispatch_case: This template is used for the constructor which is overloaded
***************************************************************************************/
%fragment ("JS_ctor_dispatch_case", "templates")
%{if(argc == ${argcount}) {
thisObject = _wrap_create_${classname_mangled}${overloadext}(context, NULL, argc, argv, exception);
} else %}
%fragment ("JS_ctordefn", "templates")
%{
JSObjectRef _wrap_create_${classname_mangled}${overloadext}(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
${LOCALS}
${CODE}
return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_${type_mangled}, SWIG_POINTER_OWN);
goto fail;
fail:
return NULL;
}
%}
/**********************************************************************
initializer:This template is dynamic growing and aggregates everything
**********************************************************************/
%fragment ("JS_initializer", "templates") %{
#ifdef __cplusplus
extern "C" {
#endif
bool ${modulename}_initialize(JSGlobalContextRef context) {
SWIG_InitializeModule(0);
JSObjectRef global_object = JSContextGetGlobalObject(context);
/* Initialize the base swig type object */
_SwigObject_objectDefinition.staticFunctions = _SwigObject_functions;
_SwigObject_objectDefinition.staticValues = _SwigObject_values;
_SwigObject_classRef = JSClassCreate(&_SwigObject_objectDefinition);
/* Create objects for namespaces */
${create_namespaces}
/* Create classes */
${initializercode}
/* Register namespaces */
${register_namespaces}
return true;
}
#ifdef __cplusplus
}
#endif
%}
/*****************************************************************************************
*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;%}
/*****************************************************************************************
*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
*****************************************************************************************/
%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});%}
/* 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);
%}
%fragment ("JS_register_namespace", "templates")
%{
JS_registerNamespace(context, ${namespace_mangled}_object, ${parent_namespace}_object, "${namespace}"); %}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.