summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2012-11-18 14:07:49 +0200
committerYakov Goldberg <yakov.g@samsung.com>2012-11-18 19:02:42 +0200
commita4593ce77b81ad8f813c5a3007330fa9645804eb (patch)
treebba0edac4ab52f9c4661b6cf4859dd763a742611
parent83a457b6c564d6c404275e79638586d446ba1eaf (diff)
py generation changed to create one pxd for all classes
Signed-off-by: Yakov Goldberg <yakov.g@samsung.com>
-rw-r--r--eoparser/xmlparser.py122
1 files changed, 70 insertions, 52 deletions
diff --git a/eoparser/xmlparser.py b/eoparser/xmlparser.py
index 6e24e44..a9611f5 100644
--- a/eoparser/xmlparser.py
+++ b/eoparser/xmlparser.py
@@ -17,7 +17,6 @@ def O_TYPE_CHECK(o, class_type):
17def class_name_get(_o): 17def class_name_get(_o):
18 return _o.__class__.__name__ 18 return _o.__class__.__name__
19 19
20
21#Wrapping class to pass Visitor object and call for visit function 20#Wrapping class to pass Visitor object and call for visit function
22class VAcceptor(object): 21class VAcceptor(object):
23 def accept(self, v): 22 def accept(self, v):
@@ -82,8 +81,6 @@ class Mod(object):
82 o.accept(self.V) 81 o.accept(self.V)
83 82
84 83
85
86
87# Visitor Design Pattern 84# Visitor Design Pattern
88# Visitor - base class for different visitors. 85# Visitor - base class for different visitors.
89# visit function implements dispatching depending on class name of object 86# visit function implements dispatching depending on class name of object
@@ -97,7 +94,6 @@ class Visitor(object):
97 else: 94 else:
98 print "%s is not callable attribute"%(method_name) 95 print "%s is not callable attribute"%(method_name)
99 96
100
101 def cast(self, _in): 97 def cast(self, _in):
102 t = _in 98 t = _in
103 99
@@ -151,8 +147,6 @@ class Abstract(object):
151 def __init__(self): 147 def __init__(self):
152 pass 148 pass
153 149
154
155
156class JsVisitor(Visitor): 150class JsVisitor(Visitor):
157 151
158 def __init__(self): 152 def __init__(self):
@@ -304,8 +298,6 @@ class JsVisitor(Visitor):
304 self.c_file.functions.append("}\n") 298 self.c_file.functions.append("}\n")
305 self.c_file.functions.append("\n") 299 self.c_file.functions.append("\n")
306 300
307
308
309 #is called by visit_Func to parse function as a property 301 #is called by visit_Func to parse function as a property
310 def visit_prop_set_get(self, _o): 302 def visit_prop_set_get(self, _o):
311 303
@@ -517,9 +509,6 @@ class JsVisitor(Visitor):
517 self.c_file.functions.append("}\n") 509 self.c_file.functions.append("}\n")
518 self.c_file.functions.append("\n") 510 self.c_file.functions.append("\n")
519 511
520
521
522
523 def visit_Init(self, _o): 512 def visit_Init(self, _o):
524 513
525 self.c_file.name = _o.cl_obj.js_cc_file 514 self.c_file.name = _o.cl_obj.js_cc_file
@@ -549,7 +538,6 @@ class JsVisitor(Visitor):
549 inherit = ", ".join(lst) 538 inherit = ", ".join(lst)
550 self.class_info.header ="class %s : %s\n"%(_o.cl_obj.kl_id, inherit) 539 self.class_info.header ="class %s : %s\n"%(_o.cl_obj.kl_id, inherit)
551 540
552
553 if _o.cl_obj.eo_type == const.CLASS_TYPE_REGULAR: 541 if _o.cl_obj.eo_type == const.CLASS_TYPE_REGULAR:
554 self.class_info.private.append(" static Persistent<FunctionTemplate> tmpl;\n") 542 self.class_info.private.append(" static Persistent<FunctionTemplate> tmpl;\n")
555 self.class_info.private.append("\n") 543 self.class_info.private.append("\n")
@@ -557,7 +545,7 @@ class JsVisitor(Visitor):
557 #implementing constructor 545 #implementing constructor
558 self.class_info.protected.append(" %s(Local<Object> _jsObject, CElmObject *parent);\n"%(_o.cl_obj.kl_id)) 546 self.class_info.protected.append(" %s(Local<Object> _jsObject, CElmObject *parent);\n"%(_o.cl_obj.kl_id))
559 self.c_file.functions.append("%s::%s(Local<Object> _jsObject, CElmObject *parent)\n"%(_o.cl_obj.kl_id, _o.cl_obj.kl_id)) 547 self.c_file.functions.append("%s::%s(Local<Object> _jsObject, CElmObject *parent)\n"%(_o.cl_obj.kl_id, _o.cl_obj.kl_id))
560 self.c_file.functions.append(" : CElmObject(_jsObject, eo_add(%s , parent ? parent->GetEo() : NULL))\n"%(_o.cl_obj.macro)) 548 self.c_file.functions.append(" : CElmObject(_jsObject, eo_add(%s, parent ? parent->GetEo() : NULL))\n"%(_o.cl_obj.macro))
561 self.c_file.functions.append("{\n jsObject->SetPointerInInternalField(0, static_cast<CElmObject*>(this));\n}\n") 549 self.c_file.functions.append("{\n jsObject->SetPointerInInternalField(0, static_cast<CElmObject*>(this));\n}\n")
562 550
563 self.class_info.protected.append(" static Handle<FunctionTemplate> GetTemplate();\n") 551 self.class_info.protected.append(" static Handle<FunctionTemplate> GetTemplate();\n")
@@ -569,7 +557,7 @@ class JsVisitor(Visitor):
569 #implementing Initialize 557 #implementing Initialize
570 self.c_file.init_f.append("void %s::Initialize(Handle<Object> target)\n"%_o.cl_obj.kl_id) 558 self.c_file.init_f.append("void %s::Initialize(Handle<Object> target)\n"%_o.cl_obj.kl_id)
571 self.c_file.init_f.append("{\n") 559 self.c_file.init_f.append("{\n")
572 self.c_file.init_f.append(" target->Set(String::NewSymbol(\"%s\") , GetTemplate()->GetFunction());\n"%_o.cl_obj.kl_id) 560 self.c_file.init_f.append(" target->Set(String::NewSymbol(\"%s\"), GetTemplate()->GetFunction());\n"%_o.cl_obj.kl_id)
573 self.c_file.init_f.append("}\n") 561 self.c_file.init_f.append("}\n")
574 562
575 self.class_info.public.insert(0, " virtual void DidRealiseElement(Local<Value> obj);\n") 563 self.class_info.public.insert(0, " virtual void DidRealiseElement(Local<Value> obj);\n")
@@ -590,9 +578,6 @@ class JsVisitor(Visitor):
590 578
591 self.class_info.protected.append(" virtual ~%s();\n"%(_o.cl_obj.kl_id)) 579 self.class_info.protected.append(" virtual ~%s();\n"%(_o.cl_obj.kl_id))
592 580
593
594
595
596 #saving data to pxi file 581 #saving data to pxi file
597 def js_cc_file_to_dir_save(self, _outdir): 582 def js_cc_file_to_dir_save(self, _outdir):
598 lines = [] 583 lines = []
@@ -684,9 +669,6 @@ class JsVisitor(Visitor):
684 f.write(line) 669 f.write(line)
685 f.close() 670 f.close()
686 671
687
688
689
690# PyVisitor 672# PyVisitor
691# Py code generation. Generates code depending on object type(input data) 673# Py code generation. Generates code depending on object type(input data)
692# Under "object type" we understand just some set of data, which has 674# Under "object type" we understand just some set of data, which has
@@ -695,10 +677,12 @@ class JsVisitor(Visitor):
695 677
696class PyVisitor(Visitor): 678class PyVisitor(Visitor):
697 679
698 def __init__(self): 680 def __init__(self, _module_name):
699 # PyVisitor generates 2 types of files: pxi and pxd 681 # PyVisitor generates 2 types of files: pxi and pxd
700 # head, ev, funcs_parsed - are hooks for different parts of source code 682 # head, ev, funcs_parsed - are hooks for different parts of source code
701 683
684 self.py_module_name = _module_name
685
702 self.visited_properties = [] 686 self.visited_properties = []
703 687
704 self.pxi = Abstract() 688 self.pxi = Abstract()
@@ -707,17 +691,21 @@ class PyVisitor(Visitor):
707 self.pxi.ev = [] 691 self.pxi.ev = []
708 self.pxi.funcs_parsed = [] 692 self.pxi.funcs_parsed = []
709 693
710
711 self.pxd = Abstract() 694 self.pxd = Abstract()
712 self.pxd.name = "" 695 self.pxd.name = ""
713 self.pxd.head = [] 696 self.pxd.head = []
714 self.pxd.ev = [] 697 self.pxd.ev = []
715 698
699 self.pxd2 = Abstract()
700 self.pxd2.name = ""
701 self.pxd2.head = []
702 self.pxd2.ev = []
703
716 self._funcs = {"instance_set2" : "_eo_instance_set2", 704 self._funcs = {"instance_set2" : "_eo_instance_set2",
717 "instance_get" : "_eo_instance_get", 705 "instance_get" : "_eo_instance_get",
718 "do" : "eo_do"} 706 "do" : "eo_do"}
719 707
720 self.basemodule = {"macro" : "EO_DEFAULT_CLASS", 708 self.eodefault = {"macro" : "EO_DEFAULT_CLASS",
721 "module" : "eodefault", 709 "module" : "eodefault",
722 "name": "EoDefault", 710 "name": "EoDefault",
723 "parentmodule": "NULL", 711 "parentmodule": "NULL",
@@ -741,13 +729,13 @@ class PyVisitor(Visitor):
741 def visit_Func(self, _o): 729 def visit_Func(self, _o):
742# print "func Func: ", _o.name, _o.op_id, _o.c_macro, _o.parameters 730# print "func Func: ", _o.name, _o.op_id, _o.c_macro, _o.parameters
743 eo_base_ops = ["EO_BASE_SUB_ID_EVENT_FREEZE", "EO_BASE_SUB_ID_EVENT_FREEZE_GET", \ 731 eo_base_ops = ["EO_BASE_SUB_ID_EVENT_FREEZE", "EO_BASE_SUB_ID_EVENT_FREEZE_GET", \
744 "EO_BASE_SUB_ID_EVENT_THAW", "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE", 732 "EO_BASE_SUB_ID_EVENT_THAW", "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE",
745 "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET",\ 733 "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET",\
746 "EO_BASE_SUB_ID_EVENT_GLOBAL_THAW", "EO_BASE_SUB_ID_DATA_SET", \ 734 "EO_BASE_SUB_ID_EVENT_GLOBAL_THAW", "EO_BASE_SUB_ID_DATA_SET", \
747 "EO_BASE_SUB_ID_DATA_GET", "EO_BASE_SUB_ID_DATA_DEL", \ 735 "EO_BASE_SUB_ID_DATA_GET", "EO_BASE_SUB_ID_DATA_DEL", \
748 "EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD", 736 "EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD",
749 "EO_BASE_SUB_ID_EVENT_CALLBACK_DEL", \ 737 "EO_BASE_SUB_ID_EVENT_CALLBACK_DEL", \
750 "EO_BASE_SUB_ID_EVENT_CALLBACK_CALL"] 738 "EO_BASE_SUB_ID_EVENT_CALLBACK_CALL"]
751 739
752 in_params = [] 740 in_params = []
753 pass_params =[] 741 pass_params =[]
@@ -914,7 +902,6 @@ class PyVisitor(Visitor):
914 function_lines.append("") 902 function_lines.append("")
915 self.pxi.funcs_parsed += function_lines 903 self.pxi.funcs_parsed += function_lines
916 904
917
918 #generating __init_function, and all header data for files 905 #generating __init_function, and all header data for files
919 def visit_Init(self, _o): 906 def visit_Init(self, _o):
920 cl_obj = _o.cl_obj 907 cl_obj = _o.cl_obj
@@ -939,26 +926,30 @@ class PyVisitor(Visitor):
939 function_lines.append(l) 926 function_lines.append(l)
940 l = " self.%s(klass, parent)"%self._funcs["instance_set2"] 927 l = " self.%s(klass, parent)"%self._funcs["instance_set2"]
941 function_lines.append(l) 928 function_lines.append(l)
942 l = " self.data_set(EoDefault.PY_EO_NAME, self)" 929# l = " self.data_set(EoDefault.PY_EO_NAME, self)"
943 function_lines.append(l) 930# function_lines.append(l)
944 function_lines.append("") 931 function_lines.append("")
945 932
946 function_lines.append("") 933 function_lines.append("")
947 934
948 self.pxi.funcs_parsed += function_lines 935 self.pxi.funcs_parsed += function_lines
949 936
950
951 self.pxi.name = cl_obj.mod_name + ".pxi" 937 self.pxi.name = cl_obj.mod_name + ".pxi"
952 self.pxd.name = cl_obj.mod_name + ".pxd" 938 self.pxd.name = cl_obj.mod_name + ".pxd"
953 939
954 pattern = "########################################################" 940 pattern = "########################################################"
955 l = '%s\n##\n## generated from from \"%s\"\n##\n%s'%(pattern, cl_obj.source_file, pattern) 941 l = '%s\n##\n## generated from from \"%s\"\n##\n%s'%(pattern, cl_obj.source_file, pattern)
956 self.pxi.head.append(l + '\n') 942 self.pxi.head.append(l + '\n')
957 self.pxd.head.append(l + '\n') 943 self.pxd.head.append(l + '\n')
958 944
959
960 #inserting cimports 945 #inserting cimports
961 l = "cimport %s"%cl_obj.mod_name 946 #l = "cimport %s"%cl_obj.mod_name
947
948 #now we have one pxd for all extern definitions
949 #so we cimport it with preper name
950 #proper name only for nice
951
952 l = "cimport %s as %s"%(self.py_module_name, cl_obj.mod_name)
962 self.pxi.head.append(l) 953 self.pxi.head.append(l)
963 l = "cimport %s"%cl_obj.basemodule 954 l = "cimport %s"%cl_obj.basemodule
964 self.pxi.head.append(l + '\n') 955 self.pxi.head.append(l + '\n')
@@ -970,15 +961,15 @@ class PyVisitor(Visitor):
970 961
971 if cl_obj.kl_id == "EoBase": 962 if cl_obj.kl_id == "EoBase":
972 parents = [] 963 parents = []
973 parents.append(self.basemodule["name"]) 964 parents.append(self.eodefault["name"])
974 l = "from %s import %s"%(self.basemodule["module"], self.basemodule["name"]) 965 l = "from %s import %s"%(self.eodefault["module"], self.eodefault["name"])
975 self.pxi.head.append(l + "\n") 966 self.pxi.head.append(l + "\n")
976 967
977 if "EoBase" in parents: 968 if "EoBase" in parents:
978 l = "from %s import %s"%("eobase", "EoBase") 969 l = "from %s import %s"%("eobase", "EoBase")
979 self.pxi.head.append(l + "\n") 970 self.pxi.head.append(l + "\n")
980 971
981 l = "from %s import %s"%(self.basemodule["module"], "pytext_to_utf8") 972 l = "from %s import %s"%(self.eodefault["module"], "pytext_to_utf8")
982 self.pxi.head.append(l + "\n") 973 self.pxi.head.append(l + "\n")
983 974
984 #defining _id function 975 #defining _id function
@@ -991,7 +982,6 @@ class PyVisitor(Visitor):
991 #defining class 982 #defining class
992 parents = ','.join(parents) 983 parents = ','.join(parents)
993 l = 'class %s(%s):'%(cl_obj.kl_id, parents) 984 l = 'class %s(%s):'%(cl_obj.kl_id, parents)
994
995 self.pxi.head.append(l) 985 self.pxi.head.append(l)
996 986
997 #inserting cimports 987 #inserting cimports
@@ -1001,11 +991,13 @@ class PyVisitor(Visitor):
1001 #inserting externs from H 991 #inserting externs from H
1002 l = "cdef extern from \"%s\":"%(cl_obj.includes[0]) 992 l = "cdef extern from \"%s\":"%(cl_obj.includes[0])
1003 self.pxd.head.append(l + '\n') 993 self.pxd.head.append(l + '\n')
994 self.pxd2.head.append(l + '\n')
1004 995
1005 996
1006 if cl_obj.extern_base_id != "": 997 if cl_obj.extern_base_id != "":
1007 l = ' %s %s'%("Eo_Op", cl_obj.extern_base_id) 998 l = ' %s %s'%("Eo_Op", cl_obj.extern_base_id)
1008 self.pxd.head.append(l + '\n') 999 self.pxd.head.append(l + '\n')
1000 self.pxd2.head.append(l + '\n')
1009 1001
1010 enum_lines = [] 1002 enum_lines = []
1011 enum_lines.append(" ctypedef enum:") 1003 enum_lines.append(" ctypedef enum:")
@@ -1018,12 +1010,14 @@ class PyVisitor(Visitor):
1018 if len(enum_lines) > 1: 1010 if len(enum_lines) > 1:
1019 for l in enum_lines: 1011 for l in enum_lines:
1020 self.pxd.head.append(l) 1012 self.pxd.head.append(l)
1013 self.pxd2.head.append(l)
1021 self.pxd.head.append('\n') 1014 self.pxd.head.append('\n')
1015 self.pxd2.head.append('\n')
1022 1016
1023 for v in cl_obj.extern_funcs: 1017 for v in cl_obj.extern_funcs:
1024 l = ' %s %s'%(v[1], v[0]) 1018 l = ' %s %s'%(v[1], v[0])
1025 self.pxd.head.append(l) 1019 self.pxd.head.append(l)
1026 1020 self.pxd2.head.append(l)
1027 1021
1028 #generating event defenitions 1022 #generating event defenitions
1029 def visit_Ev(self, _o): 1023 def visit_Ev(self, _o):
@@ -1037,7 +1031,7 @@ class PyVisitor(Visitor):
1037 self.pxi.ev.append(l) 1031 self.pxi.ev.append(l)
1038 l = ' %s %s'%("Eo_Event_Description *", v) 1032 l = ' %s %s'%("Eo_Event_Description *", v)
1039 self.pxd.ev.append(l) 1033 self.pxd.ev.append(l)
1040 1034 self.pxd2.ev.append(l)
1041 1035
1042 #saving data to pxi file 1036 #saving data to pxi file
1043 def pxi_file_to_dir_save(self, _outdir): 1037 def pxi_file_to_dir_save(self, _outdir):
@@ -1059,7 +1053,6 @@ class PyVisitor(Visitor):
1059 f.write("\n") 1053 f.write("\n")
1060 f.close() 1054 f.close()
1061 1055
1062
1063 #saving data to pxd file 1056 #saving data to pxd file
1064 def pxd_file_to_dir_save(self, _outdir): 1057 def pxd_file_to_dir_save(self, _outdir):
1065 1058
@@ -1075,7 +1068,20 @@ class PyVisitor(Visitor):
1075 f.write("\n") 1068 f.write("\n")
1076 f.close() 1069 f.close()
1077 1070
1071 #saving data to pxd file
1072 def get_pxd_lines_from_module(self):
1073
1074 ret = []
1075 lst = self.pxd2.head
1076 for l in lst:
1077 ret.append(l+'\n')
1078 ret.append('\n')
1078 1079
1080 lst = self.pxd.ev
1081 for l in lst:
1082 ret.append(l+'\n')
1083 ret.append('\n')
1084 return (ret, self.pxd.name)
1079 1085
1080class XMLparser(object): 1086class XMLparser(object):
1081 def __init__(self): 1087 def __init__(self):
@@ -1228,6 +1234,7 @@ class XMLparser(object):
1228 1234
1229 def module_parse(self, _module_name, _xml_files, _incl_dirs): 1235 def module_parse(self, _module_name, _xml_files, _incl_dirs):
1230 1236
1237 #parsing each XML
1231 for f in _xml_files: 1238 for f in _xml_files:
1232 self.parse(f) 1239 self.parse(f)
1233 1240
@@ -1282,8 +1289,6 @@ class XMLparser(object):
1282 exit(1) 1289 exit(1)
1283 1290
1284 1291
1285
1286
1287 def parents_to_find_get(self): 1292 def parents_to_find_get(self):
1288 list_of_parents = [] 1293 list_of_parents = []
1289 1294
@@ -1360,7 +1365,6 @@ class XMLparser(object):
1360 l = list(set(l + prnts)) 1365 l = list(set(l + prnts))
1361 return l 1366 return l
1362 1367
1363
1364 #normalize all names and ids, which depend in C class name. 1368 #normalize all names and ids, which depend in C class name.
1365 #T.e. Some_Class name -> SomeClassName 1369 #T.e. Some_Class name -> SomeClassName
1366 def normalize_module_names(self): 1370 def normalize_module_names(self):
@@ -1372,8 +1376,7 @@ class XMLparser(object):
1372 objects_tmp[o.kl_id] = o 1376 objects_tmp[o.kl_id] = o
1373 self.objects = objects_tmp 1377 self.objects = objects_tmp
1374 1378
1375 1379 def py_code_generate(self, module_name, outdir):
1376 def py_code_generate(self, module_name ,outdir):
1377 #normalizing names for each class object (Evas_Object Class -> EvasObjectClass) 1380 #normalizing names for each class object (Evas_Object Class -> EvasObjectClass)
1378 self.normalize_module_names() 1381 self.normalize_module_names()
1379 1382
@@ -1381,15 +1384,30 @@ class XMLparser(object):
1381 for n, o in self.objects.items(): 1384 for n, o in self.objects.items():
1382 o.parents = self.reorder_parents(o.parents) 1385 o.parents = self.reorder_parents(o.parents)
1383 1386
1384 o.V = PyVisitor() 1387 o.V = PyVisitor(module_name)
1385 o.resolve() 1388 o.resolve()
1386 1389
1390 lines = []
1391 names = []
1387 #saving files 1392 #saving files
1388 for n, o in self.objects.items(): 1393 for n, o in self.objects.items():
1389 o.V.pxi_file_to_dir_save(outdir) 1394 o.V.pxi_file_to_dir_save(outdir)
1390 o.V.pxd_file_to_dir_save(outdir) 1395 #o.V.pxd_file_to_dir_save(outdir)
1396 (l, name) = o.V.get_pxd_lines_from_module()
1397 lines += l
1398 names.append(name)
1399
1400 f = open (os.path.join(outdir, module_name + ".pxd"), 'w')
1401
1402 pattern = "########################################################"
1403 l = '%s\n##\n## generated from \"%s\"\n##\n%s'%(pattern, ", ".join(names), pattern)
1404 f.write(l + "\n")
1405 f.write("from eodefault cimport *\n\n")
1406 for l in lines:
1407 f.write(l)
1408 f.close()
1391 1409
1392 #generating "pyx" module file, 1410 #generating "pyx" module file,
1393 #which simply includes source files "pxi" of each class 1411 #which simply includes source files "pxi" of each class
1394 #building right order of including files 1412 #building right order of including files
1395 cl_parents = {} 1413 cl_parents = {}