summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2012-11-22 17:49:22 +0200
committerYakov Goldberg <yakov.g@samsung.com>2012-11-22 17:49:22 +0200
commitac31fd8e8db1072146582ecd01a010531d82eb67 (patch)
tree5ad128755dbe452111494804a288884bafa60db2
parentc70904fbfacb094ad2ce55f94dee29d7699df34a (diff)
xmlparser type casting fixes
Signed-off-by: Yakov Goldberg <yakov.g@samsung.com>
-rw-r--r--eoparser/xmlparser.py91
1 files changed, 61 insertions, 30 deletions
diff --git a/eoparser/xmlparser.py b/eoparser/xmlparser.py
index c0b89fb..c75497f 100644
--- a/eoparser/xmlparser.py
+++ b/eoparser/xmlparser.py
@@ -109,9 +109,10 @@ class Visitor(object):
109 "char**" : "char*"} 109 "char**" : "char*"}
110 110
111 internal_types = { 111 internal_types = {
112 "void*": ["void*", "object", "ToObject"], #FIXME "ToObject?" 112 # orig_type: ["how c obj will be defined and ho to cast to cobj", "how in Py objj will be defined"]
113 "void*": ["void*", "object"], #FIXME "ToObject?"
113 "char*": ["char*", "object", "ToString"], 114 "char*": ["char*", "object", "ToString"],
114 "Eo*": ["Eo*", "EoDefault", "ToObject"], 115 "Eo*": ["Eo*", "EoDefault", "ToEo"], #ToEo
115 "short" : ["int", "int", "ToInt32"], 116 "short" : ["int", "int", "ToInt32"],
116 "short*" : ["int", "int", "ToInt32"], 117 "short*" : ["int", "int", "ToInt32"],
117 "int": ["int", "int", "ToInt32"], 118 "int": ["int", "int", "ToInt32"],
@@ -176,13 +177,15 @@ class JsVisitor(Visitor):
176 self.class_info.public = [] 177 self.class_info.public = []
177 178
178 179
179 self.js_types = { "ToBoolean" : "Boolean", 180 self.c_to_js_constr = { "ToBoolean" : "Boolean",
180 "ToString" : "String", 181 "ToString" : "String",
181 "ToUint32" : "Number", 182 "ToUint32" : "Number",
182 "ToInt32" : "Number", 183 "ToInt32" : "Number",
183 "ToNumber" : "Number", 184 "ToNumber" : "Number",
184 "ToObject" : "Local <Object>" 185# "ToObject" : "Local <Object>",
185 } 186 "ToVoid" : "VOID",
187 "ToEo" : "#error"
188 }
186 189
187 #Func visit function, to generate code for functions 190 #Func visit function, to generate code for functions
188 def visit_Func(self, _o): 191 def visit_Func(self, _o):
@@ -321,6 +324,9 @@ class JsVisitor(Visitor):
321 324
322 if c_t_tmp in self.internal_types: 325 if c_t_tmp in self.internal_types:
323 c_t_internal = self.internal_types[c_t_tmp][0] 326 c_t_internal = self.internal_types[c_t_tmp][0]
327 if len(self.internal_types[c_t_tmp]) < 3:
328 add_this_func = False
329 break
324 js_type = self.internal_types[c_t_tmp][2] 330 js_type = self.internal_types[c_t_tmp][2]
325 params_tmp.append((c_t, n, d, c_t_internal, js_type)) 331 params_tmp.append((c_t, n, d, c_t_internal, js_type))
326 else: 332 else:
@@ -328,8 +334,8 @@ class JsVisitor(Visitor):
328 add_this_func = False 334 add_this_func = False
329 break 335 break
330 336
331 if not add_this_func: 337 if not add_this_func:
332 return 338 return
333 339
334 if prop_type == "_get": 340 if prop_type == "_get":
335 self.prop_get_generate(_o, params_tmp) 341 self.prop_get_generate(_o, params_tmp)
@@ -340,6 +346,7 @@ class JsVisitor(Visitor):
340 346
341 #is called by visit_Func to parse function as a method 347 #is called by visit_Func to parse function as a method
342 def visit_method(self, _o): 348 def visit_method(self, _o):
349 self.c_file.functions.append("/* generated by 'visit method() ' */\n")
343 350
344 if _o.name in ["event_global_freeze", "event_global_thaw"]: 351 if _o.name in ["event_global_freeze", "event_global_thaw"]:
345 self.c_file.functions.append("Handle<Value> %s(const Arguments& args)\n"%_o.name) 352 self.c_file.functions.append("Handle<Value> %s(const Arguments& args)\n"%_o.name)
@@ -356,6 +363,7 @@ class JsVisitor(Visitor):
356 self.c_file.tmpl.append(" METHOD(%s)"% _o.name) 363 self.c_file.tmpl.append(" METHOD(%s)"% _o.name)
357 self.h_file.meth_cb_headers.append(" Handle<Value> Callback_%s(const Arguments&);\n"%(_o.name)) 364 self.h_file.meth_cb_headers.append(" Handle<Value> Callback_%s(const Arguments&);\n"%(_o.name))
358 365
366 functions_tmp_save = list(self.c_file.functions)
359 367
360 self.c_file.functions.append("Handle<Value> %s::%s(const Arguments& args)\n"%(_o.cl_obj.kl_id, _o.name)) 368 self.c_file.functions.append("Handle<Value> %s::%s(const Arguments& args)\n"%(_o.cl_obj.kl_id, _o.name))
361 self.c_file.functions.append("{\n") 369 self.c_file.functions.append("{\n")
@@ -364,6 +372,8 @@ class JsVisitor(Visitor):
364 pass_params = [] 372 pass_params = []
365 ret_params = [] 373 ret_params = []
366 in_param_counter = 0 374 in_param_counter = 0
375
376 add_this_func = True
367 for i, (n, c_t, d, p_t) in enumerate(_o.parameters): 377 for i, (n, c_t, d, p_t) in enumerate(_o.parameters):
368 c_t_tmp = self.cast(p_t) 378 c_t_tmp = self.cast(p_t)
369 379
@@ -372,10 +382,19 @@ class JsVisitor(Visitor):
372 382
373 if c_t_tmp in self.internal_types: 383 if c_t_tmp in self.internal_types:
374 c_t_internal = self.internal_types[c_t_tmp][0] 384 c_t_internal = self.internal_types[c_t_tmp][0]
375 js_type = self.internal_types[c_t_tmp][2] 385 if len(self.internal_types[c_t_tmp]) < 3:
386 print "Warning: JS TYPE for type: \"%s\" wasn't found in self.internal_types. Function \"%s\" from class \"%s\" will not be defined"%(c_t_tmp, n, _o.cl_obj.c_name)
387 add_this_func = False
388 else:
389 js_type = self.internal_types[c_t_tmp][2]
376 else: 390 else:
377 print "Warning: type: \"%s\" wasn't found in self.internal_types. Function \"%s\" from class \"%s\" will not be defined"%(c_t_tmp, n, _o.cl_obj.c_name) 391 print "Warning: type: \"%s\" wasn't found in self.internal_types. Function \"%s\" from class \"%s\" will not be defined"%(c_t_tmp, n, _o.cl_obj.c_name)
378 continue 392 add_this_func = False
393
394 if not add_this_func:
395 print "putting back funcs"
396 self.c_file.functions = list(functions_tmp_save)
397 return
379 398
380 if d == "in": 399 if d == "in":
381 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter)) 400 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter))
@@ -384,7 +403,7 @@ class JsVisitor(Visitor):
384 403
385 if js_type == "ToString": 404 if js_type == "ToString":
386 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type)) 405 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type))
387 elif js_type == "ToObject": 406 elif js_type == "ToEo":
388 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n)) 407 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n))
389 else: 408 else:
390 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type)) 409 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type))
@@ -396,8 +415,8 @@ class JsVisitor(Visitor):
396 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 415 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
397 pass_params.append('&' + n) 416 pass_params.append('&' + n)
398 417
399 js_type = self.js_types[js_type] 418 js_constr = self.c_to_js_constr[js_type]
400 ret_params.append((n, js_type)) 419 ret_params.append((n, js_type, js_constr))
401 420
402 elif d == "in,out": 421 elif d == "in,out":
403 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter)) 422 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter))
@@ -406,26 +425,29 @@ class JsVisitor(Visitor):
406 425
407 if js_type == "ToString": 426 if js_type == "ToString":
408 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type)) 427 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type))
409 elif js_type == "ToObject": 428 elif js_type == "ToEo":
410 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n)) 429 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n))
411 else: 430 else:
412 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type)) 431 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type))
413 432
414 pass_params.append('&' + n) 433 pass_params.append('&' + n)
415 js_type = self.js_types[js_type] 434 js_constr = self.c_to_js_constr[js_type]
416 ret_params.append((n, js_type)) 435 ret_params.append((n, js_type, js_constr))
417 436
418 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%( _o.c_macro, ", ".join(pass_params))) 437 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%( _o.c_macro, ", ".join(pass_params)))
419 438
420 if len(ret_params) == 1: 439 if len(ret_params) == 1:
421 for par, t in ret_params: 440 for par, js_type, js_constr in ret_params:
422#FIXME: case then we work with EO 441#FIXME: case then we work with EO
423 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper values\n"%(t, par)) 442 if js_type in ["ToEo", "ToVoid"]:
443 self.c_file.functions.append(" return Undefined(); //need to fix case when returning object!\n")
444 else:
445 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper values\n"%(js_constr, par))
424 elif len(ret_params) > 1: 446 elif len(ret_params) > 1:
425 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n") 447 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n")
426 for p, t in ret_params: 448 for par, js_type, js_constr in ret_params:
427 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"%(p, t, p)) 449 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"%(par, js_constr, par))
428 self.c_file.functions.append(" return scope.Close(obj__); //need to put proper values\n") 450 self.c_file.functions.append(" return scope.Close(obj__); //should be right\n")
429 else: 451 else:
430 self.c_file.functions.append(" return Undefined();\n") 452 self.c_file.functions.append(" return Undefined();\n")
431 453
@@ -434,6 +456,7 @@ class JsVisitor(Visitor):
434 456
435 # is called by prop_set_get_visit, to generate body for property getter 457 # is called by prop_set_get_visit, to generate body for property getter
436 def prop_get_generate(self, _o, params_tmp): 458 def prop_get_generate(self, _o, params_tmp):
459 self.c_file.functions.append("/* generated by 'prop_get_generate() ' */\n")
437 self.c_file.functions.append("Handle<Value> %s::%s() const\n"%(_o.cl_obj.kl_id, _o.name)) 460 self.c_file.functions.append("Handle<Value> %s::%s() const\n"%(_o.cl_obj.kl_id, _o.name))
438 self.c_file.functions.append("{\n") 461 self.c_file.functions.append("{\n")
439 self.c_file.functions.append(" HandleScope scope;\n") 462 self.c_file.functions.append(" HandleScope scope;\n")
@@ -445,19 +468,23 @@ class JsVisitor(Visitor):
445 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 468 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
446 pass_params.append('&' + n) 469 pass_params.append('&' + n)
447 470
448 js_type = self.js_types[js_type] 471 js_constr = self.c_to_js_constr[js_type]
449 ret_params.append((n, js_type)) 472 ret_params.append((n, js_type, js_constr))
450 473
451 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%(_o.c_macro, ", ".join(pass_params))) 474 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%(_o.c_macro, ", ".join(pass_params)))
452 475
453 if len(ret_params) == 1: 476 if len(ret_params) == 1:
454 for par, t in ret_params: 477 for par, js_type, js_constr in ret_params:
455 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper val ues\n"%(t, par)) 478 self.c_file.functions.append("/* %s */\n"%js_type)
479 if js_type in ["ToEo", "ToVoid"]:
480 self.c_file.functions.append(" return Undefined(); //need to fix case when returning object!\n")
481 else:
482 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper values\n"%(js_constr, par))
456 483
457 elif len(ret_params) > 1: 484 elif len(ret_params) > 1:
458 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n") 485 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n")
459 for par, t in ret_params: 486 for par, js_type, js_constr in ret_params:
460 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"% (par, t, par)) 487 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"% (par, js_constr, par))
461 self.c_file.functions.append(" return scope.Close(obj__);//need to put proper values\n") 488 self.c_file.functions.append(" return scope.Close(obj__);//need to put proper values\n")
462 else: 489 else:
463 self.c_file.functions.append(" return Undefined();\n") 490 self.c_file.functions.append(" return Undefined();\n")
@@ -467,6 +494,7 @@ class JsVisitor(Visitor):
467 494
468 # is called by prop_set_get_visit, to generate body for property setter 495 # is called by prop_set_get_visit, to generate body for property setter
469 def prop_set_generate(self, _o, params_tmp): 496 def prop_set_generate(self, _o, params_tmp):
497 self.c_file.functions.append("/* generated by 'prop_set_generate() ' */\n")
470 498
471 self.c_file.functions.append("void %s::%s(Handle<Value> val)\n"%(_o.cl_obj.kl_id, _o.name)) 499 self.c_file.functions.append("void %s::%s(Handle<Value> val)\n"%(_o.cl_obj.kl_id, _o.name))
472 self.c_file.functions.append("{\n") 500 self.c_file.functions.append("{\n")
@@ -495,9 +523,12 @@ class JsVisitor(Visitor):
495 if js_type == "ToString": 523 if js_type == "ToString":
496 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(val->%s()));\n"%(n, js_type)) 524 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(val->%s()));\n"%(n, js_type))
497 add_end_func.append(" free(%s);"%n) 525 add_end_func.append(" free(%s);"%n)
526 elif js_type == "ToEo":
527 self.c_file.functions.append(" %s = static_cast<CElmObject*>(val->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n))
498 else: 528 else:
499 self.c_file.functions.append(" %s = val->%s()->Value();\n"%(n, js_type)) 529 self.c_file.functions.append(" %s = val->%s()->Value();\n"%(n, js_type))
500 530
531
501 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*": 532 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*":
502 pass_params.append('&' + n) 533 pass_params.append('&' + n)
503 else: 534 else: