summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2012-12-17 17:00:29 +0200
committerYakov Goldberg <yakov.g@samsung.com>2012-12-17 17:00:29 +0200
commit27f48694bf3e54d822e3283d608f70462ec3beae (patch)
tree39f8eb1535ae148f0eff2014f5cd5f7888aabd4a
parente48f50f43fea588337116a195fb8a709e1fcd885 (diff)
parent0f1e177277bcc61a123bfa58e77eeb19a573aee6 (diff)
Release 0.0.2HEADmaster
'eoparser' package, with tools 'eorepo' is provided with base classes
-rw-r--r--DEV_README295
-rw-r--r--README246
-rwxr-xr-xbin/eo_graph_gen.py (renamed from eo_parser/eo_graph_gen.py)135
-rwxr-xr-xbin/eo_js_gen.py167
-rwxr-xr-xbin/eo_py_gen.py204
-rwxr-xr-xbin/eo_xml_gen.py (renamed from eo_parser/eo_xml_gen.py)42
-rw-r--r--eo_js/README36
-rw-r--r--eo_js/elm.h20
-rwxr-xr-xeo_js/eo_js_gen.py80
-rw-r--r--eo_parser/tests.py77
-rw-r--r--eo_parser/types.xml16
-rw-r--r--eo_py/README55
-rw-r--r--eo_py/elm_add.pxd4
-rw-r--r--eo_py/elm_add.pxi20
-rwxr-xr-xeo_py/eo_py_gen.py149
-rw-r--r--eo_py/eodefault.pxd8
-rw-r--r--eo_py/eodefault.pyx48
-rw-r--r--eoparser/__init__.py (renamed from eo_parser/__init__.py)0
-rw-r--r--eoparser/cparser.py (renamed from eo_parser/Cparser.py)228
-rw-r--r--eoparser/data/types.xml82
-rw-r--r--eoparser/helper.py (renamed from eo_parser/helper.py)54
-rw-r--r--eoparser/xmlparser.py (renamed from eo_parser/XMLparser.py)665
-rw-r--r--eorepo/EoBase.xml90
-rw-r--r--eorepo/__init__.py3
-rw-r--r--eorepo/eobase.c5268
-rw-r--r--eorepo/eobase.pxd40
-rw-r--r--eorepo/eobase.pxi108
-rw-r--r--eorepo/eobase.pyx1
-rw-r--r--eorepo/eodefault.c4095
-rw-r--r--eorepo/eodefault.pxd84
-rw-r--r--eorepo/eodefault.pyx149
-rw-r--r--examples/elm_elm.js201
-rw-r--r--examples/elw_button.js159
-rw-r--r--examples/elw_button_new_names.js162
-rw-r--r--examples/elw_button_old.js247
-rw-r--r--examples/elw_eoisa.js24
-rw-r--r--examples/elw_mixin.js18
-rw-r--r--examples/elw_signal.js54
-rw-r--r--examples/evas_elem_test.py66
-rw-r--r--examples/evas_lib_test.py2
-rw-r--r--examples/evas_test.py32
-rw-r--r--examples/evas_test2.py154
-rw-r--r--examples/mixin_test.py13
-rw-r--r--examples/signal_test.py62
-rw-r--r--examples/simple_test.py14
-rw-r--r--setup.py91
-rw-r--r--tests/test_data.in28
-rw-r--r--tests/tests.py98
48 files changed, 12954 insertions, 940 deletions
diff --git a/DEV_README b/DEV_README
new file mode 100644
index 0000000..7d0b7da
--- /dev/null
+++ b/DEV_README
@@ -0,0 +1,295 @@
1
2Yakov Goldberg <yakov.g@samsung.com>
3
4EO introspection is set of tools to generate high-level
5language bindings for C libraries based on Eo (E Object) library,
6 Usual workflow:
7 - parsing C-sources and generating XML
8 - generating source files, makefiles
9 < include additional modules
10 - compile module
11
12 This document describes current development issues,
13 and supposes that reader has some knowledge
14 about Eo, Elementary, Python and JS bindings
15
16#############################################################
17
18* Generating function names
19
20 Issues:
21 Names of funcs to be generated, name clashes.
22
23 In the beginning there was idea to cut func name from OP_ID.
24
25 There is OP_ID 'SOME_CLASS_SUB_ID_COLOR_GET' and public function
26 'some_class_color_get()' which connected with OP_ID,
27 so 'color_get()' will be generated.
28
29 If there is another class ANOTHER_CLASS(SOME_CLASS) with
30 'ANOTHER_CLASS_SUB_ID_COLOR_GET' and 'another_class_color_get()'
31 public function, another 'color_get()' func will be generated.
32
33 I don't check for names clash.
34 There won't be an error and function will be simply overloaded,
35 but it will be completely wrong.
36
37 There shouldn't be function overloading at all, that's all done
38 in library itself, in bindings I call only for most base func.
39
40 Conflict should be resolved in library itself. If we want single
41 'color_set()' for all classes, they need to be overloaded
42 in proper way.
43
44 At the moment full names like some_class_color_set() and
45 another_class_color_set() will be generated.
46
47#############################################################
48
49* Properties names parsing
50 If func name ends with '_set'/'_get'
51 parameters are checked on direction 'in' for 'set' prop
52 and on 'out' for 'get' prop.
53 If it's wrong, this function will be generated as a method.
54
55 Too common implementation. Need to provide descriptions(comments).
56
57
58#############################################################
59
60* Parameter's Types;
61 Basic types can be detected;
62 also "types" file can be provided which says how to cast to basic types:
63 <type from="Evas_Font_Size" to="int"/>
64 <type from="Eo_Callback_Priority" to="short"/>
65 <type from="Evas_Smart" to="Eo"/>
66
67 if some type wasn't found, function will not be generated.
68
69 Issues:
70 Types like Eina_List, arrays, structs need wrapping to Python types
71 can be done by providing descriptions(comments), but requires work.
72
73 Returning existing Object or new one.
74 Need to check returning instance with eo_base_data_get("Python instance");
75 if o != NULL:
76 return o
77 else: ( need to create one:)
78 get class name,
79 find constructor
80 create object
81
82 Requires work.
83
84#############################################################
85
86* Constructing object:
87 Now objects are constructed with default constuctor.
88 Some classes provide custom constructors and some ONLY custom constructors.
89
90 example for window:
91 eo_add_custom(eo, elm_win_constructor("my win", ELM_WIN_BASIC))
92
93 in Python:
94 can be called like this
95 win = ElmWin("my win", ELM_WIN_BASIC)
96
97 in JS??
98 in elev8 - this is hardcoded, ("main" ELM_WIN_BASIC) is created
99
100 Issues:
101 How to fetch custom constructors from source?
102 Add decorators to comments. Looks like fine.
103
104 How to call custom constructors with same signature, but with different name?
105 eo_add_custom(eo, elm_win_constructor_one("my win", ELM_WIN_BASIC))
106 eo_add_custom(eo, elm_win_constructor_two("my win", ELM_WIN_BASIC))
107
108 What to do in Python?
109 Define additional variable?
110 win = ElmWin(win.CONSTR1, "my win", ELM_WIN_BASIC)
111
112 and provide the way to parse argv[] in __init__ func?
113
114#############################################################
115
116* Callbacks in Python.
117 Issues:
118 Pass data to callback.
119 Add callback to Evas_Object
120
121 Description:
122 All callbacks are added to Eo object on registered event in this/parent class.
123 To add callback EoBase.event_callback_priority_add() is used.
124 Callback can be added for introspected events.
125
126 Adding callback:
127
128 func(obj, data)
129
130 cb_obj = (func, data)
131 py_obj.event_callback_priority_add(class.EVENT_ID, 0, cb_obj)
132 py_obj.event_callback_del(class.EVENT_ID, cb_obj)
133
134 it's also possible to add callback like this:
135
136 py_obj.event_callback_priority_add(class.EVENT_ID, 0, (func, data))
137
138 reference of (func, data) object is incremented,
139 so callback will be called properly.
140 But it won't be possible to delete it.
141
142 What's going on inside:
143 Proxy _callback() function(eo signature) is added to real C
144 object for desired event; Py cb_obj is set as data.
145 When event occurs, _callback() is called with data; Py func and data are fetched
146 and Py cb is called.
147
148 Maybe it's not the best idea to add data like this, but the idea
149 is to give Eo as much work as possible.
150 So no internal lists are managed to pass and keep
151 callback data as (*args **kwargs).
152
153
154 Adding callbacks to Evas_Object:
155 In C, callbacks are added with evas_object_event_callback_add(),
156 which is not in eo indrospection at all.
157 Evas Events are also not in introspection scope,
158 because they are not added to Eo objects.
159
160 Issue:
161 What to do with Evas events?
162 It's possible to add stuff manually:
163 - define extern evas_object_event_callback_add()
164 - define extern event's enum
165 - define public event_add/del funcs for class
166
167#############################################################
168
169* Callbacks in JS:
170 In elev8 one callback per event was implemented, without adding cb data.
171
172 There are some ideas how to put several callbacks and data if needed, but it must be checked.
173
174#############################################################
175
176* Adding elm_init() and other additional funcs
177
178 Sometimes some additional functions like elm_init(), elm_run()
179 are needed. These functions are not introspectable,
180 they must be added manually.
181
182 Example for python:
183 To do this, the user must provide definitions in *.pxd, *.pxi files,
184 include *.pxi into generated 'module_name.pyx' file and compile.
185
186 Usual workflow:
187 - generating XML
188 - generating source files, makefiles
189 < add files manually
190 - compile module
191
192#############################################################
193
194* Enums from headers.
195 Need to provide descriptions(comments), to understand how to fetch it
196
197#############################################################
198
199* Issues about elementary:
200 After parsing sources, found headers are included
201 into generated files.
202
203 All include error must be fixed manually, t.e. issues with
204 including elm_*.h and Elementary.h and compilation flags like
205 -DELM_INTERNAL_API_ARGESFSDFEFC=1
206
207#############################################################
208
209* EO repository for Python
210 initial eorepo package will be installed with eoparser package.
211 Layout:
212 eorepo /
213 eobase.so
214 eodefault.so
215 __init__.py
216 EoBase.xml
217 eobase.pxd
218 eobase.c
219 eodefault.pxd
220 eodefault.c
221
222 When generating cython files for some module:
223 - all classes are parsed
224 - EoBase will be parent for some classes,
225 so EoBase will be imported from eorepo.eobase
226 also eodeafault will be cimported from eorepo.eobase.
227 - packages will be also installed into eorepo folder.
228
229 ! but, I can't include packages different from eobase
230 ! need to provide mechanism to import any parent modules
231
232 Correct layout should be like this:
233
234 eorepo /
235 eobase /
236 c_eobase.so
237 eodefault.so
238 __init__.py
239 import eodefault
240 eodefault.eo_init()
241 from eorepo.eobase.c_eobase import EoBase
242 evas /
243 c_evas.so
244 __init__.py
245 from eorepo.evas.c_evas import EvasObj
246 elementary /
247 c_elementary.so
248 __init__.py # this can be autogenerated
249 from eorepo.elementary.c_elementary import ElmWin
250
251 if we want to create module "elementary", setup.py will be created,
252 which creates package "elementary", with "c_elementary.so" module and
253 proper __init__.py, which imports ElmWin from "c_elementary.so" into
254 elementary
255
256 Each module, being installed must provide some package desc
257 file:
258 it must content all classes of module and path to this module.
259 {EvasObj : [eorepo.evas.c_evas]}
260 {ElmWin : [eorepo.elm.c_elm]}
261 If I need to include some class, I search for this "desc file";
262 look for class name in it, and include class from package.
263
264 And so I don't need XML_INCLUDE or look for parent's XMLs.
265 And I don't need XML files at all.
266
267 Usage in users app:
268 import eorepo.elementary -
269 #this will activate __init__ in elementary folder, and will
270 # import ElmWin from c_elementary into elementary
271 # so eorepo.elementary.ElmWin can be used
272 # or like this
273 from eorepo.elementary import ElmWin
274
275#############################################################
276
277* Eorepo for js:
278 Currently there are several base files, which must be used in module compilation:
279 CElmObject.cc/h
280 elm.h
281 main.cc
282
283 eobase.cc/h - autogenerated for Eo_Base
284
285 1. Think, if this files must be copied for compilation
286 Or statically linked...
287 ...or smth else
288
289 2. elev8 looks for modules in its folder, so I have to install module into this folder
290 need to find way to solve it
291
292 3. In repo need to save module's h files, to include into childs modules
293 4. So each module must install some desc file: {class name : header}
294
295
diff --git a/README b/README
index ccf454a..a980af8 100644
--- a/README
+++ b/README
@@ -1,70 +1,238 @@
1##################################################### 1#####################################################
2 2
3EO Introspection - Scanner, Graph Generator 3EO Introspection
4 4
5##################################################### 5#####################################################
60. About
71. Compiling and installing
82. Folder Introspection and class graph
93. Generating python bindings
104. Generating JS bindings (elev8 and V8 are required)
6 11
7Scanner is a part of EObject introspection module. 12####################################################
8It analyzes source and header C files, which can contain EO-styled class definition, 130. About
9 and generates XML - description for each found class 14
15 EO introspection is a set of tools to generate high-level
16 language bindings for C libraries based on Eo (E Object) library.
17 Eo is a part of Enlightenent Foundation Libraries.
18 http://svn.enlightenment.org/svn/e/trunk/efl/
19
20 Eo library provides an opportunity
21 to use object oriented concepts in C.
22
23 EO Introspection provides easy generation
24 of Python and JS bindings for your Eo-based library.
25
26 Set of tools:
27 Scanner
28 Graph Generator
29 Python code generator
30 JS code generator
31
32 Scanner
33 analyzes source and header C files,
34 which can contain EO-styled class definition;
35 and then it generates XML-description for each found class.
36
37 Graph generator
38 builds classes diagram according to XML-descriptions.
39
40 Python code generator
41 analyzes XML files and generates Cython files that are compiled
42 into Python module.
43
44 JS code generator
45 analyzes XML files and generates C++ files that are compiled into
46 elev8 module. Elev8 is V8-based js-engine.
47
48#####################################################
49
501. Compiling and installing
51
52 1.1 Requirements:
53
54 python-dev package is required, to build extension
55 from source c files.
56 Install python-dev package:
57 > sudo apt-get install python-dev build-essential
58
59 1.2 Installing eoparser:
60
61 > python setup.py build
62 (do this as root unless you are installing in your users directories)
63 > python setup.py install
64
65 --prefix option can be used, to install package into user's dir.
66 Add install_dir into PYTHONPATH.
67
68 1.3 To compile Cython files, cython (0.17) is required.
69
70 Install pip (python installs packages):
71 > sudo apt-get install python-pip
72 Install cython:
73 > pip install cython
74 or upgrade:
75 > pip install --upgrade cython
10 76
11##################################################### 77#####################################################
12 78
131. Introspecting folder: 792. Introspecting folder and building class graph:
80
81 2.1 Folder introspection
14 Scanner runs recursively on defined folders 82 Scanner runs recursively on defined folders
15 a. > python eo_xml_gen.py --dir=IN_DIR --dir=IN_DIR2 --outdir=OUT_DIR -include=INCLUDE_DIR 83 > eo_xml_gen.py --dir IN_DIR --dir IN_DIR2 --outdir OUT_DIR
16 script searches for dependency xmlfiles in Python env paths.
17 if PYTHONPATH wasn't set explicit --include=INCLUDE_DIR can be needed
18
19 b. Building classes graph chart:
20 Graph generator runs recursively on defined folders and generates graphviz dot file,
21 which can be used to generate image
22
23 > python eo_graph_gen.py --dir=FOLDER_WITH_XML1 --dir=FOLDER_WITH_XMLS --outfile=OUTFILE.dot
24 > dot -Tpng OUTFILE.dot -o out.png
25 > eog out.png
26
272. Generating python-bindings: read /eo_py/README
28
29
301. Creating eobase module:
31 a. Creating new dir - PY_EOBASE
32 b. Introspecting base module folder - EOBASE
33 > python e_scan.py --dir=EOBASE --outdir=PY_EOBASE
34 - eobase.xml will be created in PY_EOBASE
35 c. Creating eobase python sources:
36 > python e_compile.py --dir=PY_EOBASE --outdir=PY_EOBASE --module=eobase
37 --pkg="elementary eo"
38 To create base module use option --module="eobase"
39 - eobase.pxd, eobase.pyx - will be created
40 - eodefault.pxd, eodefault.pyx - will be copied from script folder
41 - setup.py will be created.
42 setup.py can be modified in order to add include paths and libraries,
43 which weren't mentioned in --pkg option
44 d. Compiling python sources into python module.
45 > python setup.py build_ext --inplace
46 - eodefault.so, eobase.so will be created
47 e. Copy __init__.py to PY_EOBASE
48 Add PYTHONPATH = PY_EOBASE
49 84
85 Parent's classes should be found automatically in python search path.
86 --xmldir=XML_DIR can be used to add additional search paths.
50 87
88 2.2 Building classes graph chart:
89 Graph generator runs recursively on defined folders
90 and generates png image.
51 91
92# > python eo_graph_gen.py --dir=FOLDER_WITH_XML1 --dir=FOLDER_WITH_XMLS --outfile=OUTFILE.dot
93# > dot -Tpng OUTFILE.dot -o out.png
94# > eog out.png
95 > eo_graph_gen.py --dir FOLDER_WITH_XML1
96 --dir FOLDER_WITH_XMLS --outfile graph.png
97 > eog graph.png
52 98
53 99
100#####################################################
1013. Generating python bindings
102
103 3.1 Generating python module for classes defined in XMLs:
104 > eo_py_gen.py --dir XML_DIR --outdir OUTDIR --module MODULE_NAME
105 --pkg "lib1 lib2" --xmldir INCLUDE_XML_DIR
106 -lname -I/include -DSOME_VAR=1
107
108 Parent's classes should be found automatically in python search path.
109 --xmldir=XML_DIR can be used to add additional search paths.
110
111 --xmldir XML_DIR - path to search for parent classes
112 (XMLs fith parent classes descriptions)
113 --outdir OUTDIR - directory for output.
114 --module - name of module to generate
115 --pkg "lib1 lib2" - provide libraries compilation information with pkg-config
116 --xmldir - path to parent's classes XMLSw, which are not in search path
117
118 -I - to include search path for headers
119 -L - to include search path for libraries
120 -l - library to link with
121 -D - to define macros
122
123 Files to be generated:
124 - *.pxi files will be created for each *.xml
125 - *.pxd will be created one for module.
126 - MODULE_NAME.pyx (only one pyx allowed for compiling module)
127 this file includes all *.pxi
128 - setup.py
129 setup.py can be edited in order to add include paths, libraries
130 (which were not mentioned in --pkg option)
131 compile options
132
133 Addition:
134 Sometimes, additional functions, which are not introspectable,
135 must be included. User must implement and add them manually.
136 (Cython knowledge is required)
137
138 To do this, user must provide definitions in *.pxd, *.pxi files,
139 include *.pxi into generated 'module_name.pyx' file and compile.
140
141 3.2 Creating install package and installing generated module:
142 Creating installation package for module
143 > python setup.py sdist
144
145 Building module
146 > python setup.py build
147
148 Installing module (root maybe required)
149 > python setup.py install
150
151########################################################################
152
153 3.3 Creating PY base module for Eo base class:
154 Base module folder being introspected - Eo lib itself
155 > python eo_xml_gen.py --dir=(eo lib itself) --outdir=OUTDIR
156 - eobase.xml will be created in OUTDIR folder
157 Creating eobase python sources:
158 > python eo_py_gen.py --dir=OUTDIR --outdir=TMP --module=eobase
159 --pkg="eo" --xmldir=DEFAULT
160 To create base module, option --module must be "eobase".
161 DEFAULT - is a folder with cython files for eodefault module,
162 which provides infrastructure.
163
164 TMP folder will have following layout:
165 tmp\
166 setup.py
167 eorepo\
168 eodefault.pxd
169 eodefault.pyx
170 eobase.pyx
171 eobase.pxi
172 eobase.pxd
173 __init__.py
54 174
175 - eobase.pxd, eobase.pyx - will be created
176 - eodefault.pxd, eodefault.pyx - will be copied into
177 - __init__.py - will be copied
178 - setup.py will be created.
179 setup.py can be modified in order to add include paths
180 and libraries, which weren't mentioned in command line options
55 181
182 Creating installation package for module
183 > python setup.py sdist
56 184
185 Building module
186 > python setup.py build
57 187
188 Installing module (root maybe required)
189 > python setup.py install
58 190
191 According to layout, package 'eorepo' will be installed into
192 installation path.
193 It can be used as following:
194 from eorepo.eobase import EoBase
59 195
196#####################################################################
60 197
1984. Generating js module for classes defined in XMLs:
199 > eo_js_gen.py --dir=XML_FOLDER --outdir=OUTDIR
200 --module=MODULE_NAME --xmldir=INCLUDE_XML_DIR -lname -I/include
201 -DSOME_PATH=\"/path\"
61 202
203 Parent's classes should be found automatically in python search path.
204 --xmldir=XML_DIR can be used to add additional search paths.
62 205
206 --xmldir XML_DIR - path to search for parent classes
207 (XMLs fith parent classes descriptions)
208 --outdir OUTDIR - directory for output.
209 --module - name of module to generate
210 --pkg "lib1 lib2" - provide libraries compilation information with pkg-config
211 --xmldir - path to parent's classes XMLSw, which are not in search path
63 212
213 -I - to include search path for headers
214 -L - to include search path for libraries
215 -l - library to link with
216 -D - to define macros
64 217
218 Files to be generated:
219 - *.cc, *.h will be created for each *.xml
220 - _module.cc with EoRegisterModule() func
221 if you need to call any functions on module load,
222 add them in this func.
223 - Makefile
65 224
225 Compiling module:
226 You can edit generated Makefile, if you need to add some additional flags
227 > make
228 - modul_name.so will be compiled
66 229
67 230
231 /*
232 Need to copy followinf files to compile module, (or static link?)
233 main.cc, elm.h, CElmObject.cc, CElmObject.h, _eobase.h, _eobase.c"
234 */
68 235
236####################################################################
69 237
70 238
diff --git a/eo_parser/eo_graph_gen.py b/bin/eo_graph_gen.py
index 3ede4e6..d7b2342 100755
--- a/eo_parser/eo_graph_gen.py
+++ b/bin/eo_graph_gen.py
@@ -1,9 +1,9 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2 2
3from eo_parser.helper import isXML, dir_files_get, abs_path_get 3from eoparser.helper import isXML, dir_files_get, abs_path_get
4from eo_parser.XMLparser import XMLparser 4from eoparser.xmlparser import XMLparser
5from argparse import ArgumentParser 5from argparse import ArgumentParser
6import os 6import os, sys
7 7
8def verbose_true(mes): 8def verbose_true(mes):
9 print mes 9 print mes
@@ -14,23 +14,21 @@ def verbose_false(mes):
14def main(): 14def main():
15 parser = ArgumentParser() 15 parser = ArgumentParser()
16 parser.add_argument("-d", "--dir", dest="directory", 16 parser.add_argument("-d", "--dir", dest="directory",
17 action="append", help="Source files directory") 17 action="append", help="Path to XML descriptions", required=True)
18 18
19 parser.add_argument("-o", "--outfile", dest="outfile", 19 parser.add_argument("-o", "--outfile", dest="outfile",
20 action="store", help="Path for output files") 20 action="store", help="Out file in png format. Default: \"out.png\"", default="out.png")
21 21
22 parser.add_argument("-v", "--verbose", 22 parser.add_argument("-v", "--verbose",
23 action="store_true", dest="verbose", default=False, 23 action="store_true", dest="verbose", default=False,
24 help="Print status messages to stdout") 24 help="Verbose output")
25 25 """
26 parser.add_argument("--graphstyle", action="store", dest="graphstyle", default="digraph", 26 parser.add_argument("--graphstyle", action="store", dest="graphstyle", default="digraph",
27 help="Set graph style. Default: \"digraph\"") 27 help="Set graph style. Default: \"digraph\"")
28 """
28 29
29 parser.add_argument("--edge", action="store", dest="edge", default="solid", 30 parser.add_argument("--extedge", action="store", dest="extedge", default="dashed, dashed, dotted, dashed",
30 help="Set line style for parent edge. Default: \"solid\"") 31 help="Set line style for extension edges depending on extension type(REGULAR, MIXIN, INTERFACE, NO_INSTANT).[\"solid, dotted, dashed, bold\"]. Default: \"dashed, dashed, dotted, dashed\"")
31
32 parser.add_argument("--extedge", action="store", dest="extedge", default="dashed",
33 help="Set line style for extension edge. Default: \"dashed\"")
34 32
35 parser.add_argument("--rankdir", action="store", dest="rankdir", default="BT", 33 parser.add_argument("--rankdir", action="store", dest="rankdir", default="BT",
36 help="Direction of directed graph[BT, TB, LR, RL]. Default: \"BT\"") 34 help="Direction of directed graph[BT, TB, LR, RL]. Default: \"BT\"")
@@ -47,68 +45,71 @@ def main():
47 parser.add_argument("--nodeshape", action="store", dest="nodeshape", default="polygon", 45 parser.add_argument("--nodeshape", action="store", dest="nodeshape", default="polygon",
48 help="Node shape.[\"polygon\", \"circle\", \"ellipse\"] Default: \"polygon\"") 46 help="Node shape.[\"polygon\", \"circle\", \"ellipse\"] Default: \"polygon\"")
49 47
48 parser.add_argument("--long-names", action="store", dest="short_long", default="short",
49 help="Node shape.[\"short\", \"long\"] Default: \"short\"")
50 50
51 styles = {} 51 styles = {}
52 52
53 args = parser.parse_args() 53 args = parser.parse_args()
54 styles["edge"] = args.edge 54 styles["extedge"] = args.extedge.replace(" ", "").split(",")
55 styles["extedge"] = args.extedge 55 if len (styles["extedge"]) < 4:
56 styles["graphstyle"] = args.graphstyle 56 print "--extedge option is not correct"
57 exit(1)
58 styles["graphstyle"] = "digraph"# args.graphstyle
57 styles["rankdir"] = args.rankdir 59 styles["rankdir"] = args.rankdir
58 styles["graphfontsize"] = args.graphfontsize 60 styles["graphfontsize"] = args.graphfontsize
59 styles["graphlabel"] = args.graphlabel 61 styles["graphlabel"] = args.graphlabel
60 styles["nodefontsize"] = args.nodefontsize 62 styles["nodefontsize"] = args.nodefontsize
61 styles["nodeshape"] = args.nodeshape 63 styles["nodeshape"] = args.nodeshape
64 SHORT_LONG = 0 if args.short_long == "short" else 1
65
66 TYPE_REGULAR = "EO_CLASS_TYPE_REGULAR"
67 TYPE_MIXIN = "EO_CLASS_TYPE_MIXIN"
68 TYPE_INTERFACE = "EO_CLASS_TYPE_INTERFACE"
69 TYPE_NO_INSTANT = "EO_CLASS_TYPE_REGULAR_NO_INSTANT"
62 70
71 types_list = (TYPE_REGULAR, TYPE_MIXIN, TYPE_INTERFACE, TYPE_NO_INSTANT)
63 72
64 types = { 73 type_names = {
65 "REGULAR":"EO_CLASS_TYPE_REGULAR", 74 TYPE_REGULAR : ("REGULAR", "EO_CLASS_TYPE_REGULAR"),
66 "MIXIN" : "EO_CLASS_TYPE_MIXIN", 75 TYPE_MIXIN : ("MIXIN", "EO_CLASS_TYPE_MIXIN"),
67 "INTERFACE":"EO_CLASS_TYPE_INTERFACE", 76 TYPE_INTERFACE : ("INTERFACE", "EO_CLASS" ),
68 "NO_INSTANT":"EO_CLASS_TYPE_REGULAR_NO_INSTANT" 77 TYPE_NO_INSTANT : ("NO INSTANT", "EO_CLASS_TYPE_REGULAR_NO_INSTANT")
69 } 78 }
70 79
80 #node colors
71 n_color = { 81 n_color = {
72 types["REGULAR"]:"green", 82 TYPE_REGULAR :"green",
73 types["MIXIN"] : "blue", 83 TYPE_MIXIN : "blue",
74 types["INTERFACE"]:"red", 84 TYPE_INTERFACE :"red",
75 types["NO_INSTANT"]:"darkviolet" 85 TYPE_NO_INSTANT :"darkviolet"
76 } 86 }
77 87
88 #ext edge line style
89 p_edge = {}
90 p_edge[TYPE_REGULAR] = styles["extedge"][0]
91 p_edge[TYPE_MIXIN] = styles["extedge"][1]
92 p_edge[TYPE_INTERFACE] = styles["extedge"][2]
93 p_edge[TYPE_NO_INSTANT] = styles["extedge"][3]
94
78 verbose_print = None 95 verbose_print = None
79 if args.verbose is True: 96 if args.verbose is True:
80 verbose_print = verbose_true 97 verbose_print = verbose_true
81 else: 98 else:
82 verbose_print = verbose_false 99 verbose_print = verbose_false
83 100
84 verbose_print("Options: %s"%args) 101 directories = args.directory + sys.path
85 verbose_print("Args: %s"%args) 102 directories = abs_path_get(directories, False)
86 103
87 directories = [] 104 outfile = args.outfile
88 outfile = "" 105 outfile = os.path.expanduser(outfile)
106 outfile = os.path.abspath(outfile)
89 107
90 if args.directory == None: 108 outdir = os.path.split(outfile)[0]
91 print "ERROR: no source directory was provided" 109 if not os.path.exists(outdir):
92 exit(1) 110 print "ERROR: output directory %s doesn't exists... Aborting..."%outdir
93 elif args.outfile == None:
94 print "ERROR: no output file was provided"
95 exit(1) 111 exit(1)
96 112
97 else:
98 directories = abs_path_get(args.directory)
99
100 outfile = args.outfile
101 outfile = os.path.expanduser(outfile)
102 outfile = os.path.abspath(outfile)
103
104 outdir = os.path.split(outfile)[0]
105 if not os.path.exists(outdir):
106 print "ERROR: output directory %s doesn't exists... Aborting..."%outdir
107 exit(1)
108
109 verbose_print("Dirs: %s"%directories)
110 verbose_print("Outfile: %s"%outfile)
111
112 xml_files = dir_files_get(directories) 113 xml_files = dir_files_get(directories)
113 xml_files = filter(isXML, xml_files) 114 xml_files = filter(isXML, xml_files)
114 115
@@ -138,14 +139,8 @@ def main():
138 139
139 #generating dot node description for node, for each class 140 #generating dot node description for node, for each class
140 for n, o in graph.items(): 141 for n, o in graph.items():
141 if o.eo_type == types["REGULAR"]: 142 if o.eo_type in types_list:
142 line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["REGULAR"]]) 143 line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, type_names[o.eo_type][SHORT_LONG], n_color[o.eo_type])
143 elif o.eo_type == types["MIXIN"]:
144 line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["MIXIN"]])
145 elif o.eo_type == types["INTERFACE"]:
146 line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["INTERFACE"]])
147 elif o.eo_type == types["NO_INSTANT"]:
148 line = " \"%s\" [label = \"%s \\n %s\", color = \"%s\"];"%(n, o.c_name, o.eo_type, n_color[types["NO_INSTANT"]])
149 else: 144 else:
150 line = " \"%s\" [label = \"%s \\n %s\"];"%(n, o.c_name, o.eo_type) 145 line = " \"%s\" [label = \"%s \\n %s\"];"%(n, o.c_name, o.eo_type)
151 146
@@ -160,32 +155,34 @@ def main():
160 if parent in graph: 155 if parent in graph:
161 p_type = graph[parent].eo_type 156 p_type = graph[parent].eo_type
162 else: 157 else:
163 p_type = types["REGULAR"] 158 p_type = TYPE_REGULAR
164 line = " \"%s\" -> \"%s\" [style = \"%s\", color=\"%s\"];"%(n, parent, styles["edge"], n_color[p_type]) 159 line = " \"%s\" -> \"%s\" [style = \"%s\", color=\"%s\"];"%(n, parent, "solid", n_color[p_type])
165 lines.append(line) 160 lines.append(line)
166 for l in ext: 161 for l in ext:
167 if graph[l].eo_type == types["REGULAR"]: 162 eo_type_tmp = graph[l].eo_type
168 line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, "dashed", n_color[types["REGULAR"]]) 163 if eo_type_tmp in types_list:
169 elif graph[l].eo_type == types["MIXIN"]: 164 line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, p_edge[eo_type_tmp], n_color[eo_type_tmp])
170 line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, "dashed", n_color[types["MIXIN"]])
171 elif graph[l].eo_type == types["INTERFACE"]:
172# line = " \"%s\" -> \"%s\" [style=\"%s\"] ;"%(k, l, styles["extedge"])
173 line = " \"%s\" -> \"%s\" [style=\"%s\", color = \"%s\"] ;"%(n, l, "dotted", n_color[types["INTERFACE"]])
174 elif graph[l].eo_type == types["NO_INSTANT"]:
175 line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(n, l, "dashed", n_color[types["NO_INSTANT"]])
176 else: 165 else:
177 line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(k, l, "dashed", "black") 166 line = " \"%s\" -> \"%s\" [style=\"%s\", color=\"%s\"] ;"%(k, l, "dashed", "black")
178 167
179 lines.append(line) 168 lines.append(line)
180 lines.append("}") 169 lines.append("}")
181 170
182 f = open(outfile, 'w') 171 tmp_dot_file = "tmp.dot"
172 f = open(tmp_dot_file, 'w')
183 for l in lines: 173 for l in lines:
184 f.write(l+'\n') 174 f.write(l+'\n')
185 175
186 f.close() 176 f.close()
187 177
188 verbose_print("dot file: %s was generated"%(outfile)) 178 verbose_print("Dot file: '%s' was generated"%(tmp_dot_file))
179 verbose_print("Graph file: '%s was generated"%(outfile))
180 os.system("dot -Tpng %s -o %s"%(tmp_dot_file, outfile))
181 #os.system("neato -Tpng %s -o %s_neato"%(tmp_dot_file, outfile))
182 #os.system("twopi -Tpng %s -o %s_twopi"%(tmp_dot_file, outfile))
183 #os.system("circo -Tpng %s -o %s_circo"%(tmp_dot_file, outfile))
184 #os.system("fdp -Tpng %s -o %s_fdp"%(tmp_dot_file, outfile))
185 #os.system("sfdp -Tpng %s -o %s_sfdp"%(tmp_dot_file, outfile))
189 186
190if __name__ == "__main__": 187if __name__ == "__main__":
191 main() 188 main()
diff --git a/bin/eo_js_gen.py b/bin/eo_js_gen.py
new file mode 100755
index 0000000..b7d0b1f
--- /dev/null
+++ b/bin/eo_js_gen.py
@@ -0,0 +1,167 @@
1#!/usr/bin/env python
2
3from eoparser.helper import isXML, abs_path_get, dir_files_get, normalize_names
4from eoparser.helper import _const
5from eoparser.xmlparser import XMLparser
6from argparse import ArgumentParser
7import os, sys
8
9const = _const()
10
11
12def verbose_true(mes):
13 print mes
14
15def verbose_false(mes):
16 pass
17
18def makefile_file_generate(args, c_files, outdir):
19 module_name = args.module
20 pkg = args.pkg
21 incl_paths = ["."]
22 if args.include_paths is not None:
23 incl_paths += args.include_paths
24 libs = args.libraries
25 lib_paths = args.library_paths
26 cpp_defines = args.cpp_defines
27
28 #if someone wants to add -DSOME_STR=\"str\"
29 #I will add one more escape symbol, because I also generate Makefile
30 if cpp_defines is not None:
31 lst_tmp = []
32 for d in cpp_defines:
33 lst_tmp.append(d.replace("\"", "\\\""))
34 cpp_defines = list(lst_tmp)
35 del lst_tmp
36
37 makefile_file = "Makefile"
38 default_c_files = ['main.cc', 'CElmObject.cc', '_eobase.cc', '_module.cc']
39 c_files = default_c_files + c_files
40
41 lines = []
42 lines.append("CC=g++")
43 lines.append("all: lib%s.so"%module_name)
44 lines.append("\n")
45 lines.append("lib_SOURCES = \\")
46 for f in c_files:
47 lines.append("%s \\"%f)
48 lines[-1] = lines[-1][:-2]
49
50 lines.append("")
51 lines.append("lib_OBJECTS = $(lib_SOURCES:.cc=.o)")
52
53 lines.append("")
54 lines.append("lib_CFLAGS = \\")
55 # lines.append("-I. \\")
56 #lines.append("-DPACKAGE_DATA_DIR=\\\"/tmp\\\" \\")
57 #lines.append("-DPACKAGE_TMP_DIR=\\\"/tmp\\\" \\")
58
59 for i in incl_paths:
60 lines.append("-I%s \\"%i)
61
62 for l in pkg.split():
63 lines.append("`pkg-config --cflags %s` \\"%l)
64
65 if cpp_defines is not None:
66 for d in cpp_defines:
67 lines.append("-D%s \\"%d)
68 lines[-1] = lines[-1][:-2]
69
70 lines.append("")
71 lines.append("lib_LDFLAGS = \\")
72 for l in pkg.split():
73 lines.append("`pkg-config --libs %s` \\"%l)
74
75 if lib_paths is not None:
76 for l in lib_paths:
77 lines.append("-L%s \\"%l)
78
79 if libs is not None:
80 for l in libs:
81 lines.append("-l%s \\"%l)
82 lines[-1] = lines[-1][:-2]
83
84 lines.append("")
85 lines.append("lib%s.so: $(lib_OBJECTS)"%module_name)
86 lines.append("\t$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(lib_LDFLAGS)")
87
88 lines.append("")
89 lines.append("%.o : %.cc $(libjse_HEADERS)")
90 lines.append("\t$(CC) -fPIC $(lib_CFLAGS) -c $< -o $@")
91
92 lines.append("")
93 lines.append("clean:")
94 lines.append("\trm -f *~ *.o *.so")
95
96
97 f = open(os.path.join(outdir, makefile_file), 'w')
98 for l in lines:
99 f.write(l + "\n")
100 f.close()
101
102def main():
103 parser = ArgumentParser()
104 parser.add_argument("-d", "--dir", dest="directory",
105 action="append", help="Path to XML descriptions", required=True)
106
107 parser.add_argument("-o", "--outdir", dest="outdir",
108 action="store", help="Output directory", required=True)
109
110 parser.add_argument("-v", "--verbose",
111 action="store_true", dest="verbose", default=False,
112 help="Verbose output")
113
114 parser.add_argument("-X", "--xmldir", dest="xmldir", default=sys.path,
115 action="append", help="Directory to search for parent classes's XMLs")
116
117 parser.add_argument("--pkg", dest="pkg", default = "eo",
118 action="store", help="pkg-confing libraries. Default: \"eo\"")
119
120 parser.add_argument("-m", "--module", dest="module",
121 action="store", help="Name of module", required=True)
122
123 parser.add_argument("-I", "--include", dest="include_paths",
124 action="append", help="Pre-processor include path")
125
126 parser.add_argument("-l", "--library", dest="libraries",
127 action="append", help="Libraries of this unit")
128
129 parser.add_argument("-L", "--library-path", dest="library_paths",
130 action="append", help="Directories to search for libraries")
131
132 parser.add_argument("-D", "--define", dest="cpp_defines",
133 action="append", help="Pre-processor define")
134
135
136 args = parser.parse_args()
137
138 verbose_print = verbose_true if args.verbose is True else verbose_false
139
140 directories = []
141 outdir = ""
142 sourcedir = ""
143 incl_dirs = []
144
145 directories = abs_path_get(args.directory)
146 outdir = abs_path_get([args.outdir])[0]
147 if args.xmldir is not None:
148 incl_dirs = abs_path_get(args.xmldir, False)
149
150 xml_files = dir_files_get(directories, False)
151 xml_files = filter(isXML, xml_files)
152
153 xp = XMLparser()
154 xp.module_parse(args.module, xml_files, incl_dirs)
155 xp.js_code_generate(outdir)
156
157 c_files = []
158 for n, o in xp.objects.items():
159 c_files.append(o.V.c_file.name)
160
161 makefile_file_generate(args, c_files, outdir)
162
163 del xp
164
165if __name__ == "__main__":
166 main()
167
diff --git a/bin/eo_py_gen.py b/bin/eo_py_gen.py
new file mode 100755
index 0000000..1874584
--- /dev/null
+++ b/bin/eo_py_gen.py
@@ -0,0 +1,204 @@
1#!/usr/bin/env python
2
3from eoparser.helper import isXML, abs_path_get, dir_files_get, _const
4from eoparser.xmlparser import XMLparser
5from argparse import ArgumentParser
6import os, sys, shutil
7
8
9const = _const()
10
11def verbose_true(mes):
12 print mes
13
14def verbose_false(mes):
15 pass
16
17
18def setup_file_generate(args, outdir):
19 module_name = args.module
20 pkg = args.pkg
21 incl_paths = args.include_paths
22 libs = args.libraries
23 lib_paths = args.library_paths
24 cpp_defines = args.cpp_defines
25
26 #if someone wants to add -DSOME_STR=\"str\"
27 #I will add one more escape symbol, because I also generate setup.py
28 if cpp_defines is not None:
29 lst_tmp = []
30 for d in cpp_defines:
31 lst_tmp.append(d.replace("\"", "\\\""))
32 cpp_defines = list(lst_tmp)
33 del lst_tmp
34
35 module_file = module_name + ".pyx"
36
37 lines = []
38 lines.append("from distutils.core import setup")
39 lines.append("from distutils.extension import Extension")
40 lines.append("from Cython.Distutils import build_ext")
41 lines.append("import commands")
42 lines.append("")
43
44 lines.append("def pkgconfig(_libs):")
45 lines.append(" cf = commands.getoutput(\"pkg-config --cflags %s\"%_libs).split()")
46 lines.append(" ldf = commands.getoutput(\"pkg-config --libs %s\"%_libs).split()")
47 lines.append(" return (cf, ldf)")
48 lines.append("")
49
50 lines.append("(e_compile_args, e_link_args) = pkgconfig(\"%s\")"%pkg)
51 lines.append("")
52
53 if cpp_defines is not None:
54 for d in cpp_defines:
55 lines.append("e_compile_args.append(\"-D%s\")"%d)
56
57 include_dirs = ["\".\""]
58 if incl_paths is not None:
59 for i in incl_paths:
60 include_dirs.append("\"%s\""%i)
61 lines.append("e_include_dirs = [%s]"%', '.join(include_dirs))
62 del include_dirs
63
64 lib_dirs = []
65 if lib_paths is not None:
66 for i in lib_paths:
67 lib_dirs.append("\"%s\""%i)
68 lines.append("e_library_dirs = [%s]"%', '.join(lib_dirs))
69 del lib_dirs
70
71 lib_names = []
72 if libs is not None:
73 for i in libs:
74 lib_names.append("\"%s\""%i)
75 lines.append("e_libraries = [%s]"%', '.join(lib_names))
76 del lib_names
77
78 lines.append("")
79
80 lines.append("setup(")
81 lines.append(" cmdclass = {'build_ext': build_ext},")
82
83 if module_name == "eobase":
84 lines.append(" name = 'eobase_test_name',")
85 lines.append(" packages=['%s'],"%const.PREFIX)
86 lines.append(" package_data={'%s': ['EoBase.xml', 'eodefault.pxd']},"%(const.PREFIX))
87
88 lines.append(" ext_modules = [")
89 lines.append(" Extension(\"%s.%s\", ['%s/%s'], include_dirs = e_include_dirs, library_dirs = e_library_dirs, libraries = e_libraries, extra_compile_args = e_compile_args, extra_link_args = e_link_args),"%(const.PREFIX, "eodefault", const.PREFIX, "eodefault.pyx"))
90
91 lines.append(" Extension(\"%s.%s\", ['%s/%s'], include_dirs = e_include_dirs, library_dirs = e_library_dirs, libraries = e_libraries, extra_compile_args = e_compile_args, extra_link_args = e_link_args),"%(const.PREFIX, module_name, const.PREFIX, module_name + ".pyx"))
92
93 else:
94 lines.append(" name='%s',"%module_name)
95 lines.append(" ext_package='%s',"%const.PREFIX)
96 lines.append(" ext_modules = [")
97 lines.append(" Extension(\"%s\", ['%s'], include_dirs = e_include_dirs, library_dirs = e_library_dirs, libraries = e_libraries, extra_compile_args = e_compile_args, extra_link_args = e_link_args),"%(module_name, module_name + ".pyx"))
98
99 lines.append(" ])\n\n")
100
101
102 f = open(os.path.join(outdir, "setup.py"), 'w')
103 for l in lines:
104 f.write(l + "\n")
105 f.close()
106
107
108def main():
109 parser = ArgumentParser()
110 parser.add_argument("-d", "--dir", dest="directory",
111 action="append", help="Path to XML descriptions", required=True)
112
113 parser.add_argument("-o", "--outdir", dest="outdir",
114 action="store", help="Output directory", required=True)
115
116 parser.add_argument("-v", "--verbose",
117 action="store_true", dest="verbose", default=False,
118 help="Verbose output")
119
120 parser.add_argument("-X", "--xmldir", dest="xmldir", default=sys.path,
121 action="append", help="Directory to search for parent classes's XMLs")
122
123 parser.add_argument("--pkg", dest="pkg", default = "eo",
124 action="store", help="pkg-confing libraries. Default: \"eo\"")
125
126 parser.add_argument("-m", "--module", dest="module",
127 action="store", help="Name of module", required=True)
128
129 parser.add_argument("-I", "--include", dest="include_paths",
130 action="append", help="Pre-processor include path")
131
132 parser.add_argument("-l", "--library", dest="libraries",
133 action="append", help="Libraries of this unit")
134
135 parser.add_argument("-L", "--library-path", dest="library_paths",
136 action="append", help="Directories to search for libraries")
137
138 parser.add_argument("-D", "--define", dest="cpp_defines",
139 action="append", help="Pre-processor define")
140
141 args = parser.parse_args()
142
143 verbose_print = verbose_true if args.verbose is True else verbose_false
144
145 directories = []
146 outdir = ""
147 sourcedir = ""
148 incl_dirs = []
149
150 directories = abs_path_get(args.directory)
151 outdir = abs_path_get([args.outdir])[0]
152 if args.xmldir is not None:
153 incl_dirs = abs_path_get(args.xmldir, False)
154
155 xml_files = dir_files_get(directories, False)
156 xml_files = filter(isXML, xml_files)
157
158 xp = XMLparser()
159 xp.module_parse(args.module, xml_files, incl_dirs)
160
161 if args.module == "eobase":
162 outdir_tmp = os.path.join(outdir, const.PREFIX)
163 if not os.path.exists(outdir_tmp):
164 os.mkdir(outdir_tmp)
165 xp.py_code_generate(args.module ,outdir_tmp)
166 else:
167 xp.py_code_generate(args.module ,outdir)
168
169 setup_file_generate(args, outdir)
170
171 #Looking for "eodefault.pxd" module. Needed to include
172 if args.module == "eobase":
173 for d in incl_dirs:
174 d_tmp = os.path.join(d, "eodefault.pxd")
175 if os.path.exists(d_tmp):
176 sourcedir = d
177 break
178
179 if sourcedir == "":
180 print "ERROR: no include files were found... Aborting... (Use: -X(--xmldir=)XML_DIR)"
181 exit(1)
182
183 #copying eodefault module into source dir
184 f_pyx = os.path.join(sourcedir, "eodefault.pyx")
185 f_pxd = os.path.join(sourcedir, "eodefault.pxd")
186 f_init = os.path.join(sourcedir,"__init__.py")
187 try:
188 #this file is needed only to build eodefault.
189 outdir_tmp = os.path.join(outdir, const.PREFIX)
190 shutil.copy(f_pyx, outdir_tmp)
191 shutil.copy(f_pxd, outdir_tmp)
192 shutil.copy(f_init, outdir_tmp)
193 except IOError as ex:
194 print "%s"%ex
195 print "Aborting"
196 exit(1)
197 except shutil.Error as er:
198 print "Warning: %s"%er
199
200 del xp
201
202if __name__ == "__main__":
203 main()
204
diff --git a/eo_parser/eo_xml_gen.py b/bin/eo_xml_gen.py
index f87c380..cfbd298 100755
--- a/eo_parser/eo_xml_gen.py
+++ b/bin/eo_xml_gen.py
@@ -1,9 +1,9 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2 2
3from eo_parser.helper import dir_files_get, abs_path_get, isC, isH, isXML 3from eoparser.helper import dir_files_get, abs_path_get, isC, isH, isXML
4from eo_parser.helper import _const 4from eoparser.helper import _const
5from eo_parser.XMLparser import XMLparser 5from eoparser.xmlparser import XMLparser
6from eo_parser.Cparser import Cparser 6from eoparser.cparser import Cparser
7from argparse import ArgumentParser 7from argparse import ArgumentParser
8import sys 8import sys
9 9
@@ -19,20 +19,20 @@ def main():
19 19
20 parser = ArgumentParser() 20 parser = ArgumentParser()
21 parser.add_argument("-d", "--dir", dest="directory", 21 parser.add_argument("-d", "--dir", dest="directory",
22 action="append", help="source files") 22 action="append", help="Source C-files to introspect", required=True)
23 23
24 parser.add_argument("-o", "--outdir", dest="outdir", 24 parser.add_argument("-o", "--outdir", dest="outdir",
25 action="store", help="output directory") 25 action="store", help="Output directory", required=True)
26 26
27 parser.add_argument("-t", "--typedefs", dest="typedefs", 27 parser.add_argument("-t", "--typedefs", dest="typedefs",
28 action="store", help="Additional typedefs for parser") 28 action="store", help="Additional typedefs for parser")
29 29
30 parser.add_argument("-i", "--include", dest="xmldir", default = sys.path, 30 parser.add_argument("-X", "--xmldir", dest="xmldir", default = sys.path,
31 action="append", help="Include xml directory") 31 action="append", help="Directory to search for parent classes's XMLs")
32 32
33 parser.add_argument("-v", "--verbose", 33 parser.add_argument("-v", "--verbose",
34 action="store_true", dest="verbose", default=False, 34 action="store_true", dest="verbose", default=False,
35 help="print status messages to stdout") 35 help="Verbose output")
36 36
37 args = parser.parse_args() 37 args = parser.parse_args()
38 verbose_print = None 38 verbose_print = None
@@ -47,25 +47,15 @@ def main():
47 typedefs = "" 47 typedefs = ""
48 xmldir = [] 48 xmldir = []
49 49
50 if args.directory == None: 50 directories = abs_path_get(args.directory)
51 print "No source directory was provided" 51 outdir = abs_path_get([args.outdir])[0]
52 exit(1)
53 elif args.outdir == None:
54 print "No out directory was provided"
55 exit(1)
56 else:
57 directories = abs_path_get(args.directory)
58 if args.xmldir is not None:
59 xmldir = abs_path_get(args.xmldir, False)# not abort if dir doesn't exist
60 52
61 outdir = abs_path_get([args.outdir])[0] 53 if args.xmldir is not None:
54 xmldir = abs_path_get(args.xmldir, False)# not abort if dir doesn't exist
62 55
63 if args.typedefs != None: 56 if args.typedefs != None:
64 typedefs = abs_path_get([args.typedefs])[0] 57 typedefs = abs_path_get([args.typedefs])[0]
65 58
66 verbose_print("dirs %s"%directories)
67 verbose_print("outdir %s"%outdir)
68
69 files = dir_files_get(directories) 59 files = dir_files_get(directories)
70 c_files = filter(isC, files) 60 c_files = filter(isC, files)
71 h_files = filter(isH, files) 61 h_files = filter(isH, files)
@@ -86,7 +76,6 @@ def main():
86 for f in h_files: 76 for f in h_files:
87 cp.h_file_data_get(f) 77 cp.h_file_data_get(f)
88 78
89
90 #remove records, which are not class, t.e. they don't have GET_FUNCTION key 79 #remove records, which are not class, t.e. they don't have GET_FUNCTION key
91 cl_data_tmp = dict(cp.cl_data) #deep copy of dictionary 80 cl_data_tmp = dict(cp.cl_data) #deep copy of dictionary
92 for k in cl_data_tmp: 81 for k in cl_data_tmp:
@@ -109,8 +98,6 @@ def main():
109 cl_data_tmp2 = dict(cp.cl_data) 98 cl_data_tmp2 = dict(cp.cl_data)
110 parents_to_find = filter(lambda ll: True if ll not in cl_data_tmp2 else False, list_of_parents) 99 parents_to_find = filter(lambda ll: True if ll not in cl_data_tmp2 else False, list_of_parents)
111 100
112 verbose_print("parents_to_find: %s"%parents_to_find)
113
114 #if we have parents to find 101 #if we have parents to find
115 if len(parents_to_find) != 0: 102 if len(parents_to_find) != 0:
116 if len(xmldir) == 0: 103 if len(xmldir) == 0:
@@ -123,7 +110,6 @@ def main():
123 if len(xml_files) == 0: 110 if len(xml_files) == 0:
124 print "ERROR: no include files found for %s classes... Aborting..."% ",".join(parents_to_find) 111 print "ERROR: no include files found for %s classes... Aborting..."% ",".join(parents_to_find)
125 exit(1) 112 exit(1)
126 verbose_print("xml_files: %s\n"%xml_files)
127 113
128 #parsing include XMLs 114 #parsing include XMLs
129 xp = XMLparser() 115 xp = XMLparser()
@@ -139,7 +125,6 @@ def main():
139 parents_to_find.pop(i) 125 parents_to_find.pop(i)
140 del xp 126 del xp
141 127
142
143 #if there are still parents, which we need to find - exit 128 #if there are still parents, which we need to find - exit
144 if len(parents_to_find) != 0: 129 if len(parents_to_find) != 0:
145 print "ERROR: XML files weren't found for %s classes... Aborting"%(",".join(parents_to_find)) 130 print "ERROR: XML files weren't found for %s classes... Aborting"%(",".join(parents_to_find))
@@ -149,7 +134,6 @@ def main():
149 for k in cp.cl_data: 134 for k in cp.cl_data:
150 cp.build_xml(k) 135 cp.build_xml(k)
151 136
152 #cp.print_data()
153 del cp 137 del cp
154 138
155if __name__ == "__main__": 139if __name__ == "__main__":
diff --git a/eo_js/README b/eo_js/README
deleted file mode 100644
index 3a783e0..0000000
--- a/eo_js/README
+++ /dev/null
@@ -1,36 +0,0 @@
1############################################################################
2
3EO Introspection - JavaScript Bindings
4
5############################################################################
6
7It analyzes XML files generated by EO introspection scanner and generates
8module, which can be used with V8-based js-engine - elev8.
9
10############################################################################
11
121. Generating js module for classes defined in XMLs:
13 a. > python eo_js_gen.py --dir=XML_FOLDER --outdir=OUTDIR
14 --module=MODULE_NAME --include=INCLUDE_DIR
15
16 In case if some class is needed
17 (usually parent class, which is not in the tree being analyzed),
18 include XMLs are searched in python system paths.
19 If include file wasn't found, explicit --include=INCLUDE_DIR dir is needed
20
21 Files to be generated:
22 - *.cc, *.h will be created for each *.xml
23 b. Compiling module:
24 > not yet.
25 following files are needed to compile
26 elm.h
27 CElmObject.cc
28 CElmObject.h
29
30 *.so module will be compiled
31
32############################################################################
33############################################################################
34############################################################################
35
36
diff --git a/eo_js/elm.h b/eo_js/elm.h
index be88c11..0dd1507 100644
--- a/eo_js/elm.h
+++ b/eo_js/elm.h
@@ -66,30 +66,36 @@ extern int log_domain;
66#define PROPERTY(name_) \ 66#define PROPERTY(name_) \
67 #name_, Callback_## name_ ##_get, Callback_## name_ ##_set, NULL 67 #name_, Callback_## name_ ##_get, Callback_## name_ ##_set, NULL
68 68
69#define PROPERTY_RO(name_) \
70 #name_, Callback_## name_ ##_get, NULL, NULL
71
72#define PROPERTY_SO(name_) \
73 #name_, NULL, Callback_## name_ ##_set, NULL
74
69#define METHOD(name_) \ 75#define METHOD(name_) \
70 #name_, NULL, NULL, Callback_## name_ 76 #name_, NULL, NULL, Callback_## name_
71 77
72#define EO_GENERATE_PROPERTY_CALLBACKS(class_,name_) \ 78#define EO_GENERATE_PROPERTY_CALLBACKS(class_,name_) \
73 Handle<Value> Callback_## name_ ##_get(Local<String>, const AccessorInfo &info) { \ 79 Handle<Value> Callback_## name_ ##_get(Local<String>, const AccessorInfo &info) { \
74 HandleScope scope; \ 80 HandleScope scope; \
75 return scope.Close(GetObjectFromAccessorInfo<class_>(info)->name_ ##_get()); \ 81 return scope.Close(GetObjectFromAccessorInfo<class_>(info)->__## name_ ##_get()); \
76 } \ 82 } \
77 void Callback_## name_ ##_set(Local<String>, Local<Value> value, const AccessorInfo &info) { \ 83 void Callback_## name_ ##_set(Local<String>, Local<Value> value, const AccessorInfo &info) { \
78 HandleScope scope; \ 84 HandleScope scope; \
79 GetObjectFromAccessorInfo<class_>(info)->name_ ##_set(value); \ 85 GetObjectFromAccessorInfo<class_>(info)->__## name_ ##_set(value); \
80 } 86 }
81 87
82 88
83#define EO_GENERATE_PROPERTY_GET_CALLBACK(class_,name_) \ 89#define EO_GENERATE_PROPERTY_GET_CALLBACK(class_,name_) \
84 Handle<Value> Callback_## name_ ##_get(Local<String>, const AccessorInfo &info) { \ 90 Handle<Value> Callback_## name_ ##_get(Local<String>, const AccessorInfo &info) { \
85 HandleScope scope; \ 91 HandleScope scope; \
86 return scope.Close(GetObjectFromAccessorInfo<class_>(info)->name_ ##_get()); \ 92 return scope.Close(GetObjectFromAccessorInfo<class_>(info)->__## name_ ##_get()); \
87 } 93 }
88 94
89#define EO_GENERATE_PROPERTY_SET_CALLBACK(class_,name_) \ 95#define EO_GENERATE_PROPERTY_SET_CALLBACK(class_,name_) \
90 void Callback_## name_ ##_set(Local<String>, Local<Value> value, const AccessorInfo &info) { \ 96 void Callback_## name_ ##_set(Local<String>, Local<Value> value, const AccessorInfo &info) { \
91 HandleScope scope; \ 97 HandleScope scope; \
92 GetObjectFromAccessorInfo<class_>(info)->name_ ##_set(value); \ 98 GetObjectFromAccessorInfo<class_>(info)->__## name_ ##_set(value); \
93 } 99 }
94 100
95#define EO_GENERATE_PROPERTY_GET_EMPTY_CALLBACK(class_,name_) \ 101#define EO_GENERATE_PROPERTY_GET_EMPTY_CALLBACK(class_,name_) \
@@ -121,9 +127,13 @@ extern int log_domain;
121#define EO_GENERATE_METHOD_CALLBACKS(class_,name_) \ 127#define EO_GENERATE_METHOD_CALLBACKS(class_,name_) \
122 Handle<Value> Callback_## name_(const Arguments& args) { \ 128 Handle<Value> Callback_## name_(const Arguments& args) { \
123 HandleScope scope; \ 129 HandleScope scope; \
124 return scope.Close(GetObjectFromArguments<class_>(args)->name_(args)); \ 130 return scope.Close(GetObjectFromArguments<class_>(args)->__## name_(args)); \
125 } 131 }
126 132
133#define EO_GENERATE_STATIC_METHOD(class_, name_) \
134 static Handle<Value> static_## name_(const Arguments& args) { \
135 return Undefined(); \
136 }
127 137
128#define EO_REGISTER_STATIC_METHOD(_name) \ 138#define EO_REGISTER_STATIC_METHOD(_name) \
129 GetTemplate()->GetFunction()->ToObject()->Set(String::NewSymbol(#_name), FunctionTemplate::New(_name)->GetFunction()) 139 GetTemplate()->GetFunction()->ToObject()->Set(String::NewSymbol(#_name), FunctionTemplate::New(_name)->GetFunction())
diff --git a/eo_js/eo_js_gen.py b/eo_js/eo_js_gen.py
deleted file mode 100755
index 93da51b..0000000
--- a/eo_js/eo_js_gen.py
+++ /dev/null
@@ -1,80 +0,0 @@
1#!/usr/bin/env python
2
3from eo_parser.helper import isXML, abs_path_get, dir_files_get, normalize_names
4from eo_parser.helper import _const
5from eo_parser.XMLparser import XMLparser
6from argparse import ArgumentParser
7import os, sys
8
9const = _const()
10
11
12def verbose_true(mes):
13 print mes
14
15def verbose_false(mes):
16 pass
17
18def main():
19 parser = ArgumentParser()
20 parser.add_argument("-d", "--dir", dest="directory",
21 action="append", help="Source files")
22
23 parser.add_argument("-o", "--outdir", dest="outdir",
24 action="store", help="Output directory")
25
26 parser.add_argument("-v", "--verbose",
27 action="store_true", dest="verbose", default=False,
28 help="Print status messages to stdout. Default: False")
29
30 parser.add_argument("-i", "--include", dest="xmldir", default=sys.path,
31 action="append", help="Include eobase directory")
32
33 parser.add_argument("--pkg", dest="pkg", default = "elementary eo",
34 action="store", help="pkg-confing libraries. Default: \"elementary eo\"")
35
36 parser.add_argument("-m", "--module", dest="module",
37 action="store", help="Name of module to generate")
38
39 args = parser.parse_args()
40
41 verbose_print = verbose_true if args.verbose is True else verbose_false
42 verbose_print("Options: %s"%args)
43
44 directories = []
45 outdir = ""
46 sourcedir = ""
47 incl_dirs = []
48
49 if args.directory == None:
50 print "ERROR: No source directory was provided"
51 exit(1)
52 elif args.outdir == None:
53 print "ERROR: No out directory was provided"
54 exit(1)
55 elif args.module == None:
56 print "ERROR: No module name was provided"
57 exit(1)
58 else:
59 directories = abs_path_get(args.directory)
60 outdir = abs_path_get([args.outdir])[0]
61 if args.xmldir is not None:
62 incl_dirs = abs_path_get(args.xmldir, False)
63
64 verbose_print("Dirs: %s"%directories)
65 verbose_print("Outdir: %s"%outdir)
66 verbose_print("Include dirs: %s"%incl_dirs)
67
68 xml_files = dir_files_get(directories, False)
69 xml_files = filter(isXML, xml_files)
70 verbose_print("In Files: %s"%xml_files)
71
72 xp = XMLparser()
73 xp.module_parse(args.module, xml_files, incl_dirs)
74 xp.js_code_generate(outdir)
75
76 del xp
77
78if __name__ == "__main__":
79 main()
80
diff --git a/eo_parser/tests.py b/eo_parser/tests.py
deleted file mode 100644
index 2427658..0000000
--- a/eo_parser/tests.py
+++ /dev/null
@@ -1,77 +0,0 @@
1import unittest
2from XMLparser import XMLparser
3from eo_parser.Cparser import Cparser
4
5class testP(unittest.TestCase):
6
7 def setUp(self):
8 self.c_parser = Cparser(False)
9
10 def test_strip(self):
11 s = """
12 #define MY_TEST_CLASS_NAME "test_class_name"
13
14static const Eo_Op_Description _elm_pan_op_desc[] = {
15 EO_OP_DESCRIPTION(ELM_OBJ_PAN_SUB_ID_POS_SET, "description here"),
16 EO_OP_DESCRIPTION(ELM_OBJ_PAN_SUB_ID_POS_GET, "description here"),
17 EO_OP_DESCRIPTION_SENTINEL
18};
19
20static const Eo_Event_Description *event_desc[] = {
21 EO_EV_CALLBACK_ADD,
22 EO_EV_CALLBACK_DEL,
23 EO_EV_DEL,
24 NULL
25};
26
27static const Eo_Class_Description test_class_desc = {
28 EO_VERSION,
29 MY_TEST_CLASS_NAME,
30 EO_CLASS_TYPE_REGULAR,
31 EO_CLASS_DESCRIPTION_OPS(&ELM_OBJ_PAN_BASE_ID, _elm_pan_op_desc, ELM_OBJ_PAN_SUB_ID_LAST),
32 event_desc,
33 sizeof(Elm_Pan_Smart_Data),
34 _elm_pan_class_constructor,
35 NULL
36};
37
38 EO_DEFINE_CLASS(class_get, &test_class_desc, parent, brother, NULL)
39
40 """
41 class_def_answer = {"class_get" : ["parent",
42 ["brother"],
43 "test_class_name",
44 "EO_CLASS_TYPE_REGULAR",
45 ["ELM_OBJ_PAN_BASE_ID",
46 [("ELM_OBJ_PAN_SUB_ID_POS_SET", "pos_set"), ("ELM_OBJ_PAN_SUB_ID_POS_GET", "pos_get")],
47 "ELM_OBJ_PAN_SUB_ID_LAST"],
48 ["EO_EV_CALLBACK_ADD", "EO_EV_CALLBACK_DEL", "EO_EV_DEL"]
49 ]}
50 answer = class_def_answer
51
52 ret = self.c_parser.fetch_data(s)
53 self.assertEqual(ret, answer)
54# self.assertEqual(self.prs.strip_replace("{test str}", "{} "), "teststr" )
55 """
56 def test_strip2(self):
57 s = "(teststr)"
58 self.assertEqual(self.prs.strip_replace(" [te stst r] ", "[] "), "teststr")
59
60 def test_parse(self):
61 s = "EO_DEFINE_CLASS(elm_button_class_get, &desc)"
62 self.assertEqual(self.prs.parse_class_desc(s), ["elm_button_class_get", "desc"])
63 self.assertEqual(self.prs.defs, ["elm_button_class_get", "desc"])
64 self.assertEqual(self.prs.dic, {"a" : "b" , 1 :34} )
65"""
66
67def suite():
68
69 suite = unittest.TestSuite()
70 suite.addTest(unittest.makeSuite(testP))
71 return suite
72
73
74
75if __name__ == '__main__':
76
77 unittest.main()
diff --git a/eo_parser/types.xml b/eo_parser/types.xml
deleted file mode 100644
index 61f30c2..0000000
--- a/eo_parser/types.xml
+++ /dev/null
@@ -1,16 +0,0 @@
1<?xml version="1.0" ?>
2<types>
3 <type from="Evas_Object" to="Eo"/>
4 <type from="Evas_Smart" to="Eo"/>
5 <type from="Evas_Map" to="Eo"/>
6 <type from="Evas_Text_Style_Type" to="Eo"/>
7 <type from="Evas_Colorspace" to="Eo"/>
8 <type from="Evas_Render_Op" to="Eo"/>
9 <type from="Evas_Aspect_Control" to="Eo"/>
10 <type from="a" to="int"/>
11 <type from="b" to="a*"/>
12 <type from="c" to="char"/>
13 <type from="d" to="c*"/>
14
15
16</types>
diff --git a/eo_py/README b/eo_py/README
deleted file mode 100644
index 85b4e29..0000000
--- a/eo_py/README
+++ /dev/null
@@ -1,55 +0,0 @@
1############################################################################
2
3EO Introspection - Python Bindings
4
5############################################################################
6
7It analyzes XML files generated by EO introspection scanner and generates
8python module.
9
10############################################################################
11
121. Generating python module for classes defined in XMLs:
13 a. > python eo_py_gen.py --dir=XML_FOLDER --outdir=OUTDIR --pkg="lib1 lib2"
14 --module=MODULE_NAME --include=INCLUDE_DIR
15 In case if some class is needed (usually parent class, which is not in the tree being analyzed),
16 include XMLs are searched in python system paths.
17 If include file wasn't found, explicit --include=INCLUDE_DIR dir is needed
18
19 Files to be generated:
20 - MODULE_NAME.pyx
21 - *.pxi, *.pxd will be created for each *.xml
22 - setup.py
23 setup.py can be edited in order to add include paths and libraries,
24 which were not mentioned in --pkg option
25 b. Compiling module:
26 > python setup.py build_ext --inplace
27 - py_module.so will be generated.
28
29 Put module into python search path and import into your code.
30
31############################################################################
32############################################################################
33############################################################################
34
351. Creating eobase module:
36 a. Create new dir - PY_EOBASE
37 b. Base module folder being introspected - EOBASE
38 > python eo_xml_gen.py --dir=EOBASE --outdir=PY_EOBASE
39 - eobase.xml will be created in PY_EOBASE
40 c. Creating eobase python sources:
41 > python eo_py_gen.py --dir=PY_EOBASE --outdir=PY_EOBASE --module=eobase
42 --pkg="elementary eo"
43 To create base module, option --module must be "eobase"
44 - eobase.pxd, eobase.pyx - will be created
45 - eodefault.pxd, eodefault.pyx - will be copied into PY_EOBASE
46 - setup.py will be created.
47 setup.py can be modified in order to add include paths and libraries,
48 which weren't mentioned in --pkg option
49 d. Compiling python sources into python module.
50 > python setup.py build_ext --inplace
51 - eodefault.so, eobase.so will be created
52 e. Copy __init__.py to PY_EOBASE
53 Add PYTHONPATH = PY_EOBASE
54
55
diff --git a/eo_py/elm_add.pxd b/eo_py/elm_add.pxd
new file mode 100644
index 0000000..dcc5d57
--- /dev/null
+++ b/eo_py/elm_add.pxd
@@ -0,0 +1,4 @@
1
2cdef extern from "Elementary.h":
3 int elm_init(int argc, char **argv)
4 void elm_run()
diff --git a/eo_py/elm_add.pxi b/eo_py/elm_add.pxi
new file mode 100644
index 0000000..0d16713
--- /dev/null
+++ b/eo_py/elm_add.pxi
@@ -0,0 +1,20 @@
1
2
3cimport elm_add
4
5def elm_run():
6 elm_add.elm_run()
7
8
9def elm_init(argv):
10 cdef void *p
11# s = " ".join(argv)
12# cdef char *cstr
13# cdef char **p_cstr
14# cstr = <char*>s
15# print "cstr = ", cstr
16# c_csrt = <char**>cstr
17# print "p_cstr[0] = ", p_cstr[0]
18 p = NULL
19 return <int>(elm_add.elm_init(len(argv), NULL))
20
diff --git a/eo_py/eo_py_gen.py b/eo_py/eo_py_gen.py
deleted file mode 100755
index b3eac5c..0000000
--- a/eo_py/eo_py_gen.py
+++ /dev/null
@@ -1,149 +0,0 @@
1#!/usr/bin/env python
2
3from eo_parser.helper import isXML, abs_path_get, dir_files_get, normalize_names
4from eo_parser.XMLparser import XMLparser
5from argparse import ArgumentParser
6import os, sys, shutil
7
8def verbose_true(mes):
9 print mes
10
11def verbose_false(mes):
12 pass
13
14
15def setup_file_generate(module_name, pkg, outdir):
16 module_file = module_name + ".pyx"
17
18 lines = []
19 lines.append("from distutils.core import setup")
20 lines.append("from distutils.extension import Extension")
21 lines.append("from Cython.Distutils import build_ext")
22 lines.append("import commands, os")
23 lines.append("")
24
25 lines.append("def pkgconfig(_libs):")
26 lines.append(" cf = commands.getoutput(\"pkg-config --cflags %s\"%_libs).split()")
27 lines.append(" ldf = commands.getoutput(\"pkg-config --libs %s\"%_libs).split()")
28 lines.append(" return (cf, ldf)")
29 lines.append("")
30
31 lines.append("(e_compile_args, e_link_args) = pkgconfig(\"%s\")"%pkg)
32 lines.append("")
33
34 lines.append("e_include_dirs = [\".\"]")
35 lines.append("e_library_dirs = []")
36 lines.append("e_libraries = []")
37 lines.append("")
38
39 lines.append("setup(")
40 lines.append(" cmdclass = {'build_ext': build_ext},")
41 lines.append(" ext_modules = [")
42
43 if module_name == "eobase":
44 lines.append(" Extension(\"%s\", ['%s'], include_dirs = e_include_dirs, library_dirs = e_library_dirs, libraries = e_libraries, extra_compile_args = e_compile_args, extra_link_args = e_link_args),"%("eodefault", "eodefault.pyx"))
45
46 lines.append(" Extension(\"%s\", ['%s'], include_dirs = e_include_dirs, library_dirs = e_library_dirs, libraries = e_libraries, extra_compile_args = e_compile_args, extra_link_args = e_link_args),"%(module_name, module_name + ".pyx"))
47
48 lines.append(" ])\n\n")
49
50
51 f = open(os.path.join(outdir, "setup.py"), 'w')
52 for l in lines:
53 f.write(l + "\n")
54 f.close()
55
56
57def main():
58 parser = ArgumentParser()
59 parser.add_argument("-d", "--dir", dest="directory",
60 action="append", help="Source files")
61
62 parser.add_argument("-o", "--outdir", dest="outdir",
63 action="store", help="Output directory")
64
65 parser.add_argument("-v", "--verbose",
66 action="store_true", dest="verbose", default=False,
67 help="Print status messages to stdout. Default: False")
68
69 parser.add_argument("-i", "--include", dest="xmldir", default=sys.path,
70 action="append", help="Include eobase directory")
71
72 parser.add_argument("--pkg", dest="pkg", default = "elementary eo",
73 action="store", help="pkg-confing libraries. Default: \"elementary eo\"")
74
75 parser.add_argument("-m", "--module", dest="module",
76 action="store", help="Name of module to generate")
77
78 args = parser.parse_args()
79
80 verbose_print = verbose_true if args.verbose is True else verbose_false
81
82 verbose_print("Options: %s"%args)
83
84 directories = []
85 outdir = ""
86 sourcedir = ""
87 incl_dirs = []
88
89 if args.directory == None:
90 print "ERROR: No source directory was provided"
91 exit(1)
92 elif args.outdir == None:
93 print "ERROR: No out directory was provided"
94 exit(1)
95 elif args.module == None:
96 print "ERROR: No module name was provided"
97 exit(1)
98 else:
99 directories = abs_path_get(args.directory)
100 outdir = abs_path_get([args.outdir])[0]
101 if args.xmldir is not None:
102 incl_dirs = abs_path_get(args.xmldir, False)
103
104
105 verbose_print("Dirs: %s"%directories)
106 verbose_print("Outdir: %s"%outdir)
107 verbose_print("Include dirs: %s"%incl_dirs)
108
109 xml_files = dir_files_get(directories, False)
110 xml_files = filter(isXML, xml_files)
111 verbose_print("In Files: %s"%xml_files)
112
113 xp = XMLparser()
114 xp.module_parse(args.module, xml_files, incl_dirs)
115 xp.py_code_generate(args.module ,outdir)
116
117 setup_file_generate(args.module, args.pkg, outdir)
118
119 #Looking for "eodefault.pxd" module. Needed to include
120 for d in incl_dirs:
121 d_tmp = os.path.join(d, "eodefault.pxd")
122 if os.path.exists(d_tmp):
123 sourcedir = d
124 break
125
126 if sourcedir == "":
127 print "ERROR: no include files were found... Aborting... (Use: --include=INCLUDE_DIR)"
128 exit(1)
129
130 #copying eodefault module into source dir
131 f_pyx = os.path.join(sourcedir, "eodefault.pyx")
132 f_pxd = os.path.join(sourcedir, "eodefault.pxd")
133 f_init = os.path.join(sourcedir, "__init__.py")
134 try:
135 shutil.copy(f_pyx, outdir)
136 shutil.copy(f_pxd, outdir)
137 shutil.copy(f_init, outdir)
138 except IOError as ex:
139 print "%s"%ex
140 print "Aborting"
141 exit(1)
142 except shutil.Error as er:
143 print "Warning: %s"%er
144
145 del xp
146
147if __name__ == "__main__":
148 main()
149
diff --git a/eo_py/eodefault.pxd b/eo_py/eodefault.pxd
index e7c3960..2f3aadc 100644
--- a/eo_py/eodefault.pxd
+++ b/eo_py/eodefault.pxd
@@ -51,6 +51,7 @@ cdef extern from "Eo.h":
51 Eo_Class *eo_base_class_get() 51 Eo_Class *eo_base_class_get()
52 52
53 Eo* eo_add(Eo_Class *klass, Eo *parent) 53 Eo* eo_add(Eo_Class *klass, Eo *parent)
54 Eo* eo_add_custom(Eo_Class *klass, Eo *parent, ...)
54 55
55 Eo* eo_ref(Eo *obj) 56 Eo* eo_ref(Eo *obj)
56 void eo_unref(Eo *obj) 57 void eo_unref(Eo *obj)
@@ -69,17 +70,12 @@ cdef extern from "Eo.h":
69 Eina_Bool eo_class_do(Eo_Class *klass, ...) 70 Eina_Bool eo_class_do(Eo_Class *klass, ...)
70 71
71 72
72cdef extern from "Elementary.h":
73 int elm_init(int argc, char **argv)
74 void elm_run()
75
76
77cdef class EoDefault: 73cdef class EoDefault:
78 cdef Eo *eo 74 cdef Eo *eo
79 cdef object name 75 cdef object name
80 cdef int print_func_name(self, f_name) 76 cdef int print_func_name(self, f_name)
81 cdef int _eo_instance_set(self, Eo *eo) 77 cdef int _eo_instance_set(self, Eo *eo)
82 cpdef _eo_instance_set2(self, klass, EoDefault parent) 78 cpdef _eo_instance_set2(self, unsigned long long klass, EoDefault parent)
83 79
84cdef Eo* _eo_instance_get(EoDefault pyobj) 80cdef Eo* _eo_instance_get(EoDefault pyobj)
85cdef Eina_Bool _object_callback(void *data, Eo *o, Eo_Event_Description *desc, void *event_info) 81cdef Eina_Bool _object_callback(void *data, Eo *o, Eo_Event_Description *desc, void *event_info)
diff --git a/eo_py/eodefault.pyx b/eo_py/eodefault.pyx
index 67d6c9d..0842514 100644
--- a/eo_py/eodefault.pyx
+++ b/eo_py/eodefault.pyx
@@ -18,21 +18,6 @@ CALLBACK_STOP = 12345
18def init(): 18def init():
19 return bool(eodefault.eo_init()) 19 return bool(eodefault.eo_init())
20 20
21def elem_run():
22 eodefault.elm_run()
23
24def py_elm_init(argv):
25 cdef void *p
26# s = " ".join(argv)
27# cdef char *cstr
28# cdef char **p_cstr
29# cstr = <char*>s
30# print "cstr = ", cstr
31# c_csrt = <char**>cstr
32# print "p_cstr[0] = ", p_cstr[0]
33 p = NULL
34 return <int>(eodefault.elm_init(len(argv), NULL))
35
36######################################################### 21#########################################################
37 22
38cdef Eo *_eo_instance_get(EoDefault pyobj): 23cdef Eo *_eo_instance_get(EoDefault pyobj):
@@ -88,6 +73,9 @@ cdef class EoDefault:
88 eodefault.eo_ref(self.eo) 73 eodefault.eo_ref(self.eo)
89 return self 74 return self
90 75
76 def unref(self):
77 eodefault.eo_unref(self.eo)
78
91 # eo_ref_get() 79 # eo_ref_get()
92 def ref_get(self): 80 def ref_get(self):
93 ref_count = <object>eodefault.eo_ref_get(self.eo) 81 ref_count = <object>eodefault.eo_ref_get(self.eo)
@@ -109,17 +97,28 @@ cdef class EoDefault:
109 97
110 def name_get(self): 98 def name_get(self):
111 return self.name 99 return self.name
112 100 #this func can be called only from this (c-styled)module
113 cdef int _eo_instance_set(self, Eo *eo): 101 cdef int _eo_instance_set(self, Eo *eo):
114 assert self.eo == NULL, "Object must be clean" 102 assert self.eo == NULL, "Object must be clean"
115 self.eo = eo 103 self.eo = eo
116 self.name = self.__class__.__name__ 104 self.name = self.__class__.__name__
117 105
118 cpdef _eo_instance_set2(self, _kl, EoDefault p): 106 # this func is main routine to add new object
119 kl = <long>_kl 107 # using default constructor
120 cdef Eo_Class *kl2 = <Eo_Class*>kl 108 # and connect C and Py objects
121 self._eo_instance_set(eodefault.eo_add(kl2, eodefault._eo_instance_get(p))) 109 cpdef _eo_instance_set2(self, unsigned long long _kl, EoDefault p):
122 110 cdef Eo_Class *kl = <Eo_Class*>_kl
111 cdef Eo *o = eodefault.eo_add(kl, eodefault._eo_instance_get(p))
112 self._eo_instance_set(o)
113 self._data_set(EoDefault.PY_EO_NAME, self)
114
115 # this func can be called outside(this c-styled module), because receives Eo* as long.
116 # it was added to be able to call eo_add_custom with different params
117 # and connect C and Py objects after it
118 def _eo_instance_set3(self, unsigned long long _eo):
119 cdef Eo *o = <Eo*>_eo
120 self._eo_instance_set(o)
121 self._data_set(EoDefault.PY_EO_NAME, self)
123 122
124 cdef int print_func_name(self, f_name): 123 cdef int print_func_name(self, f_name):
125 print self.__class__, " :: ", f_name, " :: ", sys.getsizeof(self) 124 print self.__class__, " :: ", f_name, " :: ", sys.getsizeof(self)
@@ -136,8 +135,11 @@ cdef Eina_Bool _object_callback(void *data, Eo *o,
136 eodefault.eo_do(o, eodefault.EO_BASE_BASE_ID+eodefault.EO_BASE_SUB_ID_DATA_GET, <const_char_ptr>EoDefault.PY_EO_NAME, &c_py_obj) 135 eodefault.eo_do(o, eodefault.EO_BASE_BASE_ID+eodefault.EO_BASE_SUB_ID_DATA_GET, <const_char_ptr>EoDefault.PY_EO_NAME, &c_py_obj)
137 py_obj = <object>c_py_obj 136 py_obj = <object>c_py_obj
138 137
139 f = <object>data 138 #cb_struct is tuple: (func, data)
140 res = f(py_obj) 139 cb_struct = <object>data
140 f = cb_struct[0]
141 cb_data = cb_struct[1]
142 res = f(py_obj, cb_data)
141 143
142 if res == CALLBACK_STOP: 144 if res == CALLBACK_STOP:
143 return EINA_FALSE 145 return EINA_FALSE
diff --git a/eo_parser/__init__.py b/eoparser/__init__.py
index e69de29..e69de29 100644
--- a/eo_parser/__init__.py
+++ b/eoparser/__init__.py
diff --git a/eo_parser/Cparser.py b/eoparser/cparser.py
index 0b47d32..7f23b05 100644
--- a/eo_parser/Cparser.py
+++ b/eoparser/cparser.py
@@ -34,7 +34,80 @@ class Cparser(object):
34 self.typedefs = {"Evas_Coord" : "int", 34 self.typedefs = {"Evas_Coord" : "int",
35 "Evas_Angle":"int", 35 "Evas_Angle":"int",
36 "Evas_Font_Size" : "int", 36 "Evas_Font_Size" : "int",
37 "Evas_Object" : "Eo",
38 "Evas_Smart" : "Eo",
39 "Evas_Map" : "Eo",
40 "Evas_Text_Style_Type" : "int",#enum
41 "Evas_Colorspace" : "int",#enum
42 "Evas_Render_Op" : "int",#enum
43 "Evas_Aspect_Control" : "int",#enum
44 "Evas_Object_Pointer_Mode" : "int", #enum
45 "Evas_Image_Scale_Hint" : "int", #enum
46 "Evas_Image_Content_Hint" : "int", #enum
47 "Evas_Image_Animated_Loop_Hint" : "int", #enum
48 "Evas_Border_Fill_Mode" : "int", #enum
49 "Evas_Object_Table_Homogeneous_Mode" : "int", #enum
50 "Evas_Textgrid_Font_Style" : "int",
51 "Evas_Textgrid_Palette" : "int",
52 "Evas_Modifier_Mask" : "unsigned long long",
53 "Evas_Button_Flags" : "int",
54 "Evas_Fill_Spread" : "int",
55 "Evas_Event_Flags" : "int",
56 "Evas_Font_Hinting_Flags" : "int",
57 "Evas_Load_Error" : "int",
58 "Elm_Photocam_Zoom_Mode" : "int",
37 "Eina_Bool" : "bool", 59 "Eina_Bool" : "bool",
60 "Elm_Bg_Option" : "int",
61 "Elm_Fileselector_Mode" : "int",
62 "Elm_Object_Select_Mode" : "int",
63 "Elm_Actionslider_Pos" : "int",
64 "Elm_Web_Zoom_Mode" : "int",
65 "Elm_Icon_Type" : "int",
66 "Elm_Colorselextor_Mode" : "int",
67 "Elm_List_Mode" : "int",
68 "Elm_Image_Orient" : "int",
69 "Elm_Map_Route_Type" : "int",
70 "Elm_Map_Zoom_Mode" : "int",
71 "Elm_Map_Source_Type" : "int",
72 "Elm_Clock_Edit_Mode" : "int",
73 "Elm_Dayselector_Day" : "int",
74 "Elm_Thumb_Animation_Setting" : "int",
75 "Elm_Win_Keyboard_Mode" : "int",
76 "Elm_Toolbar_Shrink_Mode" : "int",
77 "Elm_Icon_Lookup_Order" : "int",
78 "Elm_Datetime_Field_Type" : "int",
79 "Elm_Gesture_Type" : "int",
80 "Evas_BiDi_Direction" : "int",
81 "Elm_Bubble_Pos" : "int",
82 "Ecore_X_Window" : "unsigned int",
83
84 "Elm_Flip_Interaction" : "int",
85 "Elm_Flip_Direction" : "int",
86 "Elm_Flip_Interaction" : "int",
87 "Elm_Flip_Mode" : "int",
88 "Elm_Calendar_Weekday" : "int",
89 "Elm_Calendar_Selectable" : "int",
90 "Elm_Calendar_Weekday" : "int",
91 "Elm_Calendar_Select_Mode" : "int",
92 "Elm_Illume_Command" : "int",
93 "Elm_Win_Keyboard_Mode" : "int",
94 "Elm_Win_Indicator_Opacity_Mode" : "int",
95 "Elm_Win_Indicator_Mode" : "int",
96 "Ecore_Wl_Window" : "int",
97 "Elm_GLView_Render_Policy" : "int",
98 "Elm_GLView_Mode" : "int",
99 "Elm_Panel_Orient" : "int",
100 "Elm_Popup_Orient" : "int",
101 "Elm_Wrap_Type" : "int",
102 "Elm_Cnp_Mode" : "int",
103 "Elm_Input_Panel_Lang" : "int",
104 "Elm_Text_Format" : "int",
105 "Elm_Input_Panel_Return_Key_Type" : "int",
106 "Elm_Wrap_Type" : "int",
107 "Elm_Autocapital_Type" : "int",
108 "Elm_Text_Format" : "int",
109 "Elm_Object_Select_Mode" : "int",
110 "Elm_List_Mode" : "int",
38 "Eo_Callback_Priority": "short"} 111 "Eo_Callback_Priority": "short"}
39 112
40 113
@@ -114,7 +187,7 @@ class Cparser(object):
114 #event_desc structure 187 #event_desc structure
115 # { EV_CLICKED, EV_BUTTON_DOWN, EV_BUTTON_UP, NULL } 188 # { EV_CLICKED, EV_BUTTON_DOWN, EV_BUTTON_UP, NULL }
116 # 189 #
117 reg = "Eo_Event_Description[ *]*([a-zA-Z0-9_]*)[][ =]*{([^}]*)};" 190 reg = "Eo_Event_Description[ *]*([\w]*)[][ =]*{([^}]*)};"
118 af = _in_data.replace("\n", "") 191 af = _in_data.replace("\n", "")
119 ev_list = re.findall(reg, af) 192 ev_list = re.findall(reg, af)
120 193
@@ -130,20 +203,21 @@ class Cparser(object):
130 # fetching 203 # fetching
131 # op description 204 # op description
132 # 205 #
133 reg = "Eo_Op_Description[ ]*([a-zA-Z0-9_]*)\[\][ =]*{([^}]*)};" 206 reg = "Eo_Op_Description[ ]*([\w]*)\[\][ =]*{([^}]*)};"
134 all_op_descs = re.findall(reg, af) 207 all_op_descs = re.findall(reg, af)
135 op_desc = {"NULL" : []} 208 op_desc = {"NULL" : []}
136 for tup in all_op_descs: 209 for tup in all_op_descs:
137 s_tmp = tup[1] 210 s_tmp = tup[1]
138 # fetching op_ids and descriptions 211 # fetching op_ids and descriptions
139 reg = "EO_OP_DESCRIPTION[^\)]*\([ ]*([A-Z_]*)[ ]*,[ ]*\"([^\"]*)\"[ ]*\)," 212 reg = "EO_OP_DESCRIPTION[^\)]*\([ ]*([A-Z0-9_]*)[ ]*,[ ]*\"([^\"]*)\"[ ]*\),"
140 ids_and_descs = re.findall(reg, s_tmp) 213 ids_and_descs = re.findall(reg, s_tmp)
141 214
142 op_list = [] 215 op_list = []
143 for t in ids_and_descs: 216 for t in ids_and_descs:
144 op_id = t[0] #op_id 217 op_id = t[0] #op_id
145 func_name = re.findall("SUB_ID_(.*)", op_id) 218 func_name = re.findall("SUB_ID_(.*)", op_id)
146 op_list.append((op_id, func_name[0].lower())) 219 func_name = func_name[0].lower()
220 op_list.append((op_id, func_name))
147 221
148 op_desc[tup[0]] = op_list 222 op_desc[tup[0]] = op_list
149 223
@@ -161,7 +235,7 @@ class Cparser(object):
161 #[7] NULL 235 #[7] NULL
162 # } 236 # }
163 # 237 #
164 reg = "Eo_Class_Description[ ]*([a-zA-Z0-9_]*)[ =]*{([^}]*)};" 238 reg = "Eo_Class_Description[ ]*([\w]*)[ =]*{([^}]*)};"
165 desc_list = re.findall(reg, af) 239 desc_list = re.findall(reg, af)
166 240
167 for tup in desc_list: 241 for tup in desc_list:
@@ -189,7 +263,6 @@ class Cparser(object):
189 name = ll[0] 263 name = ll[0]
190 264
191 name = name.strip("\"") 265 name = name.strip("\"")
192# l_tmp = tup[1].split(",")
193 class_desc[key] = [name, cl_type, desc_ops, ev_desc[ev_desc_var]] 266 class_desc[key] = [name, cl_type, desc_ops, ev_desc[ev_desc_var]]
194 267
195 #mapping class_desc_var_name to content 268 #mapping class_desc_var_name to content
@@ -238,12 +311,7 @@ class Cparser(object):
238 for tup in class_desc_ops[1]: 311 for tup in class_desc_ops[1]:
239 self.cl_data[cl_id][const.FUNCS][tup[1]] = {const.OP_ID : tup[0], const.C_MACRO: ""} 312 self.cl_data[cl_id][const.FUNCS][tup[1]] = {const.OP_ID : tup[0], const.C_MACRO: ""}
240 313
241 s = class_desc_ops[0] 314 self.cl_data[cl_id][const.BASE_ID] = class_desc_ops[0]
242 if s == "NULL" and cl_name == "Eo Base":
243#FIXME: hardcoded EO_BASE_BASE_ID
244 print cl_name, "Warning: hardcoded EO_BASE_BASE_ID"
245 s = "EO_BASE_BASE_ID"
246 self.cl_data[cl_id][const.BASE_ID] = s
247 315
248 316
249 # resolving parameters's types and names according to 317 # resolving parameters's types and names according to
@@ -256,37 +324,46 @@ class Cparser(object):
256 op_desc = self.cl_data[cl_id][const.OP_DESC] 324 op_desc = self.cl_data[cl_id][const.OP_DESC]
257 defines = self.cl_data[cl_id][const.DEFINES] 325 defines = self.cl_data[cl_id][const.DEFINES]
258 macros = self.cl_data[cl_id][const.OP_MACROS] 326 macros = self.cl_data[cl_id][const.OP_MACROS]
327 b_id = self.cl_data[cl_id][const.BASE_ID]
328 b_id_macro = ""
329 for d in defines:
330 o = re.match("#define ([\w]*)\(([^\)]*)\) \(%s[\W]*\\2[\W]*\)"%(b_id), d)
331 if o != None:
332 b_id_macro = o.group(1)
259 333
260 #looking for op_id in define; if found, cutting op_macro from define 334 #looking for op_id in define; if found, cutting op_macro from define
261 #and checking if it is in macros list. If not - we forgot to add comment 335 #and checking if it is in macros list. If not - we forgot to add comment
262 #if yes - cutting types from define 336 #if yes - cutting types from define
263 for op, f in op_desc: 337 for op, f in op_desc:
338 found = False
264 for d in defines: 339 for d in defines:
265 pos = d.find(op) 340 # looking for #define elm_obj_flip_get ELM_OBJ_FLIP_ID(ELM_OBJ_FLIP_SUB_ID_GET)
266 if pos != -1 and d[pos : d.find(")", pos)] == op: 341 o = re.match("#define ([\w]*)\([^\)]*\) %s\(%s\).*"%(b_id_macro, op), d)
267 s_tmp = d[d.find(' ') + 1:] 342 if o != None:
268 s_tmp = s_tmp.replace(" ", "") 343 found = True
269 s_tmp = s_tmp.split('(')[0] 344 s_tmp = o.group(1)
345
270 if s_tmp not in macros: 346 if s_tmp not in macros:
271 print "Warning: no comments for \"%s\"; file: \"%s\" "%(s_tmp, self.cl_data[cl_id][const.H_FILE]) 347 print "Warning: no comments for \"%s\"; file: \"%s\" "%(s_tmp, self.cl_data[cl_id][const.H_FILE])
272 else: 348 else:
273 349
274 params = [] 350 params = []
275 params_direction = macros[s_tmp] 351 params_direction = macros[s_tmp]
276 reg = "%s\(([^,]*),([^,]*)\)"%const.EO_TYPECHECK 352 reg = "%s\(([^,]*),([^,]*)\)"%const.EO_TYPECHECK
277 ss = re.findall(reg, d) 353 ss = re.findall(reg, d)
278 354
279 i = 0 355 i = 0
280 for tup in ss: 356 for tup in ss:
281 lst = list(tup) 357 lst = list(tup)
358 modifier = "const" if lst[0].find("const") != -1 else ""
282 lst[0] = lst[0].replace("const", "") 359 lst[0] = lst[0].replace("const", "")
283 lst[0] = " ".join(lst[0].split()) 360 lst[0] = " ".join(lst[0].split())
284 lst[0] = lst[0].replace(" *", "*") 361 lst[0] = lst[0].replace(" *", "*")
285 lst[1] = lst[1].replace(" ", "") 362 lst[1] = lst[1].replace(" ", "")
286 if len(lst) == 2: 363 if len(lst) == 2:
287 try: 364 try:
288 tok = ",".join(list(params_direction[i])) 365 tok = params_direction[i]
289 params.append((lst[1], lst[0], tok)) 366 params.append((lst[1], modifier, lst[0], tok))
290 except IndexError: 367 except IndexError:
291 print "Warning: error in description %s in %s"%(s_tmp,self.cl_data[cl_id][const.H_FILE]) 368 print "Warning: error in description %s in %s"%(s_tmp,self.cl_data[cl_id][const.H_FILE])
292 369
@@ -294,22 +371,26 @@ class Cparser(object):
294 print "ERROR: check parameters in EO_TYPECHECK" 371 print "ERROR: check parameters in EO_TYPECHECK"
295 exit(1) 372 exit(1)
296 i += 1 373 i += 1
297
298 self.cl_data[cl_id][const.FUNCS][f][const.PARAMETERS] = params 374 self.cl_data[cl_id][const.FUNCS][f][const.PARAMETERS] = params
299 self.cl_data[cl_id][const.FUNCS][f][const.C_MACRO] = s_tmp 375 self.cl_data[cl_id][const.FUNCS][f][const.C_MACRO] = s_tmp
376
377 if not found:
378 print "Warning: no API for %s in %s"%(op, self.cl_data[cl_id][const.H_FILE])
379 print "Function won't be added"
380 self.cl_data[cl_id][const.FUNCS].pop(f)
381
300 382
301 383
302 #generating XML 384 #generating XML
303 def build_xml(self, cl_id): 385 def build_xml(self, cl_id):
304 #FIXME: because i don't parse several EO_DEFINE_CLASS in file
305 #if const.C_NAME not in self.cl_data[cl_id]:
306 # return
307 self.cl_data[cl_id][const.XML_FILE] = os.path.join(self.outdir, normalize_names([self.cl_data[cl_id][const.C_NAME]])[0] + ".xml") 386 self.cl_data[cl_id][const.XML_FILE] = os.path.join(self.outdir, normalize_names([self.cl_data[cl_id][const.C_NAME]])[0] + ".xml")
308 387
309 cl_data = self.cl_data[cl_id] 388 cl_data = self.cl_data[cl_id]
310 389
311 module = Element(const.MODULE) 390 module = Element(const.MODULE)
312 module.set(const.NAME, cl_data[const.C_NAME]) 391 module.set(const.NAME, cl_data[const.C_NAME])
392
393 SubElement(module, const.PARSE_VERSION, {const.NUM : const.VER_NUM} )
313 SubElement(module, const.INCLUDE, {const.NAME: os.path.split(cl_data[const.H_FILE])[1]}) 394 SubElement(module, const.INCLUDE, {const.NAME: os.path.split(cl_data[const.H_FILE])[1]})
314 395
315 cl_parent = "" 396 cl_parent = ""
@@ -355,16 +436,19 @@ class Cparser(object):
355 for k in cl_data[const.FUNCS]: 436 for k in cl_data[const.FUNCS]:
356 SubElement(op_tag, const.XML_SUB_ID, {const.NAME:cl_data[const.FUNCS][k][const.OP_ID]}) 437 SubElement(op_tag, const.XML_SUB_ID, {const.NAME:cl_data[const.FUNCS][k][const.OP_ID]})
357 438
439 c_macro = cl_data[const.FUNCS][k][const.C_MACRO]
440 #if generating XML not for base class, change func name to avoid name clash
441 func_name = k if cl_id == "EO_BASE_CLASS" else c_macro
358 442
359 m = SubElement(m_tag, const.METHOD, {const.NAME : k, 443 m = SubElement(m_tag, const.METHOD, {const.NAME : func_name,
360 const.OP_ID:cl_data[const.FUNCS][k][const.OP_ID], 444 const.OP_ID:cl_data[const.FUNCS][k][const.OP_ID],
361 const.C_MACRO:cl_data[const.FUNCS][k][const.C_MACRO]}) 445 const.C_MACRO:c_macro})
362 446
363 #defining parameter type 447 #defining parameter type
364 if const.PARAMETERS in cl_data[const.FUNCS][k]: 448 if const.PARAMETERS in cl_data[const.FUNCS][k]:
365 params = cl_data[const.FUNCS][k][const.PARAMETERS] 449 params = cl_data[const.FUNCS][k][const.PARAMETERS]
366 for v, t, d in params: 450 for v_name, modifier, t, d in params:
367 p = SubElement(m, const.PARAMETER, {const.NAME:v, const.C_TYPENAME:t, const.PRIMARY_TYPE : self.typedef_resolve(t),const.DIRECTION:d}) 451 p = SubElement(m, const.PARAMETER, {const.NAME:v_name, const.MODIFIER:modifier, const.C_TYPENAME:t, const.PRIMARY_TYPE : self.typedef_resolve(t),const.DIRECTION:d})
368 452
369 453
370 if const.EV_DESC in cl_data: 454 if const.EV_DESC in cl_data:
@@ -383,6 +467,15 @@ class Cparser(object):
383 f.write(res) 467 f.write(res)
384 f.close() 468 f.close()
385 469
470 def get_param_dir_from_comment(self, com):
471 res = re.findall("@param.*", com)
472 l_tmp = []
473 for s in res:
474 s = s.replace(" ", "")
475 ret = re.match("@param\[([inout,]*)\]", s)
476 l_tmp.append(ret.group(1) if (ret != None and ret.group(1) in ["in", "out", "in,out"]) else "in,out");
477 return l_tmp
478
386 #parsing header file 479 #parsing header file
387 def h_file_data_get(self, filename): 480 def h_file_data_get(self, filename):
388 f = open (filename, 'r') 481 f = open (filename, 'r')
@@ -391,71 +484,28 @@ class Cparser(object):
391 484
392 #fetch all "#define" from file 485 #fetch all "#define" from file
393 matcher = re.compile(r"^[ \t]*(#define(.*\\\n)*.*$)",re.MULTILINE) 486 matcher = re.compile(r"^[ \t]*(#define(.*\\\n)*.*$)",re.MULTILINE)
394 ss = matcher.findall(allfile, re.MULTILINE) 487 ss = matcher.findall(allfile)
395 d_list = [] 488 def_list = []
396 for tup in ss: 489 for tup in ss:
397 s_tmp = tup[0].replace("\n", "").replace("\\", "") 490 s_tmp = tup[0].replace("\n", "").replace("\\", "")
398 s_tmp = " ".join(s_tmp.split()) 491 s_tmp = " ".join(s_tmp.split())
399 d_list.append(s_tmp) 492 def_list.append(s_tmp)
400
401 def_list = d_list
402 493
403 """
404 #fetch all "@def" from file 494 #fetch all "@def" from file
405 #matcher = re.compile(r"^/\*\*( \*.*\n)*.*\*/$",re.MULTILINE) 495 matcher = re.compile("(^/\*\*\n(((.(?!\*/))*\n)*).*\*/$)",re.MULTILINE)
406 matcher = re.compile("(^/\*\*\n( \*.*\n)*.* \*/$)",re.MULTILINE) 496 all_comments_list = matcher.findall(allfile)
407 ss = matcher.findall(allfile, re.MULTILINE)
408 for s in ss:
409 print "s====================", s[0]
410 """
411
412 #fetch all data from "@def" comments
413 macro = {} 497 macro = {}
414 pos = allfile.find("@def") 498 for comment in all_comments_list:
415 while pos != -1: 499 comment_tmp = comment[1]
416 pos_start = pos 500
417 pos_end = allfile.find("*/", pos_start) 501 #looking for @def token in comment
418 if pos_end != -1: 502 res = re.search("@def[ ]+([\w]*)", comment_tmp)
419 tmp = allfile[pos_start : pos_end] 503 if res == None:
420 #tmp = tmp.replace("\n", "") #deleting next string 504 continue
421 tmp = tmp.replace("*", "") #removing * 505
422 lst = tmp.split("\n") 506 macro_name = res.group(1)
423 507 #looking for parameters direction in comment
424 lst = filter(macro_filter_func, lst) 508 macro[macro_name] = self.get_param_dir_from_comment(comment_tmp)
425
426 for i in range(len(lst)):
427 lst[i] = " ".join(lst[i].split()) #removing more than one spaces
428
429 macro_name = lst[0]
430 par_lst = []
431 macro_name = macro_name.split("(")[0]
432
433 macro_name = macro_name[macro_name.find(" ")+1:].strip(" ")
434 for l in lst:
435 if l.startswith("@param"):
436 s = ""
437 s1 = re.match("@param\[(in|out|in,out)\]", l)
438 if s1:
439 s = s1.group(1)
440 s = s.replace(" ", "")
441 s_tmp = []
442 if s != "":
443 s = s.split(",")
444 if "in" in s:
445 s_tmp.append("in")
446 if "out" in s:
447 s_tmp.append("out")
448 else:
449 s_tmp.append("in")
450 s_tmp.append("out")
451 t = tuple(s_tmp)
452 if len(t) == 0:
453 print "ERROR: check parameter's description in #define %s"%(macro_name)
454 exit(1)
455 par_lst.append(t)
456 macro[macro_name] = par_lst
457
458 pos = allfile.find("@def", pos_end)
459 509
460 #looking for class_get function to get class macro 510 #looking for class_get function to get class macro
461 current_class = "" 511 current_class = ""
@@ -465,10 +515,10 @@ class Cparser(object):
465 for k in self.cl_data: 515 for k in self.cl_data:
466 pos = 0 516 pos = 0
467 get_func = "" 517 get_func = ""
468 518
469 for d in def_list: 519 for d in def_list:
470 # looking for #define SOME_CLASS some_class_get() 520 # looking for #define SOME_CLASS some_class_get()
471 reg = '#define[ ]*[a-zA-Z_]*[ ]*%s\(\)'%k 521 reg = '#define[ ]*[\w]*[ ]*%s\(\)'%k
472 res = re.findall(reg, d) 522 res = re.findall(reg, d)
473 if re.match(reg, d): 523 if re.match(reg, d):
474 lst = d.split() 524 lst = d.split()
diff --git a/eoparser/data/types.xml b/eoparser/data/types.xml
new file mode 100644
index 0000000..3336bd8
--- /dev/null
+++ b/eoparser/data/types.xml
@@ -0,0 +1,82 @@
1<?xml version="1.0" ?>
2<types>
3 <type from="Evas_Object" to="Eo"/>
4 <type from="Evas_Coord" to="int"/>
5 <type from="Evas_Angle" to="int"/>
6 <type from="Evas_Font_Size" to="int"/>
7 <type from="Evas_Bool" to="bool"/>
8 <type from="Eo_Callback_Priority" to="short"/>
9 <type from="Evas_Smart" to="Eo"/>
10 <type from="Evas_Map" to="Eo"/>
11 <type from="Evas_Text_Style_Type" to="int"/>
12 <type from="Evas_Colorspace" to="int"/>
13 <type from="Evas_Render_Op" to="int"/>
14 <type from="Evas_Aspect_Control" to="int"/>
15 <type from="Evas_Object_Ponter_Mode" to="int"/>
16 <type from="Evas_Image_Scale_Hint" to="int"/>
17 <type from="Evas_Image_Content_Hint" to="int"/>
18 <type from="Evas_Image_Animated_Loop_Hint" to="int"/>
19 <type from="Evas_Border_Fill_Mode" to="int"/>
20 <type from="Evas_Object_Table_Homogeneous_Mode" to="int"/>
21 <type from="Evas_Textgrid_Font_Style" to="int"/>
22 <type from="Evas_Textgrid_Palette" to="int"/>
23 <type from="Evas_Modifier_Mask" to="unsigned long long"/>
24 <type from="Evas_Button_Flags" to="int"/>
25 <type from="Evas_Fill_Spread" to="int"/>
26 <type from="Evas_Event_Flags" to="int"/>
27 <type from="Evas_Font_Hinting_Flags" to="int"/>
28 <type from="Evas_Load_Error" to="int"/>
29 <type from="Elm_Photocam_Zoom_Mode" to="int"/>
30 <type from="Elm_Bg_Option" to="int"/>
31 <type from="Elm_Fileselector_Mode" to="int"/>
32 <type from="Elm_Object_Select_Mode" to="int"/>
33 <type from="Elm_Actionslider_Pos" to="int"/>
34 <type from="Elm_Web_Zoom_Mode" to="int"/>
35 <type from="Elm_Icon_Type" to="int"/>
36 <type from="Elm_Colorselector_Mode" to="int"/>
37 <type from="Elm_List_Mode" to="int"/>
38 <type from="Elm_Image_Orient" to="int"/>
39 <type from="Elm_Map_Route_Type" to="int"/>
40 <type from="Elm_Map_Zoom_Mode" to="int"/>
41 <type from="Elm_Map_Source_Type" to="int"/>
42 <type from="Elm_Clock_Edit_Mode" to="int"/>
43 <type from="Elm_Dayselector_Day" to="int"/>
44 <type from="Elm_Thumb_Animation_Setting" to="int"/>
45 <type from="Elm_Win_Keyboard_Mode" to="int"/>
46 <type from="Elm_Toolbar_Shrink_Mode" to="int"/>
47 <type from="Elm_Icon_Lookup_Order" to="int"/>
48 <type from="Elm_Datetime_Field_Type" to="int"/>
49 <type from="Elm_Gesture_Type" to="int"/>
50 <type from="Evas_BiDi_Direction" to="int"/>
51 <type from="Elm_Bubble_Pos" to="int"/>
52 <type from="Ecore_X_Window" to="unsigned int"/>
53
54 <type from="Elm_Flip_Interaction" to="int"/>
55 <type from="Elm_Flip_Direction" to="int"/>
56 <type from="Elm_Flip_Interaction" to="int"/>
57 <type from="Elm_Flip_Mode" to="int"/>
58 <type from="Elm_Calendar_Weekday" to="int"/>
59 <type from="Elm_Calendar_Selectable" to="int"/>
60 <type from="Elm_Calendar_Weekday" to="int"/>
61 <type from="Elm_Calendar_Select_Mode" to="int"/>
62 <type from="Elm_Illume_Command" to="int"/>
63 <type from="Elm_Win_Keyboard_Mode" to="int"/>
64 <type from="Elm_Win_Indicator_Opacity_Mode" to="int"/>
65 <type from="Elm_Win_Indicator_Mode" to="int"/>
66 <type from="Ecore_Wl_Window" to="int"/>
67 <type from="Elm_GLView_Render_Policy" to="int"/>
68 <type from="Elm_GLView_Mode" to="int"/>
69 <type from="Elm_Panel_Orient" to="int"/>
70 <type from="Elm_Popup_Orient" to="int"/>
71 <type from="Elm_Wrap_Type" to="int"/>
72 <type from="Elm_Cnp_Mode" to="int"/>
73 <type from="Elm_Input_Panel_Lang" to="int"/>
74 <type from="Elm_Text_Format" to="int"/>
75 <type from="Elm_Input_Panel_Return_Key_Type" to="int"/>
76 <type from="Elm_Wrap_Type" to="int"/>
77 <type from="Elm_Autocapital_Type" to="int"/>
78 <type from="Elm_Text_Format" to="int"/>
79 <type from="Elm_Object_Select_Mode" to="int"/>
80 <type from="Elm_List_Mode" to="int"/>
81
82</types>
diff --git a/eo_parser/helper.py b/eoparser/helper.py
index 5e0acdc..18cf703 100644
--- a/eo_parser/helper.py
+++ b/eoparser/helper.py
@@ -13,10 +13,15 @@ class _const:
13 # most of constants are used as internal dict keys, 13 # most of constants are used as internal dict keys,
14 # but some of them are also used as tags in XML 14 # but some of them are also used as tags in XML
15 # Changing this constans will only spoil the view of XML 15 # Changing this constans will only spoil the view of XML
16 self.PREFIX = "eorepo" #used as xml-tag
16 17
17 self.NAME = "name" #used as xml-tag 18 self.NAME = "name" #used as xml-tag
18 self.C_NAME = "c_name" #used as xml-tag 19 self.C_NAME = "c_name" #used as xml-tag
20 self.MODIFIER = "modifier" #used as xml-tag
19 self.MODULE = "module" #used as xml-tag 21 self.MODULE = "module" #used as xml-tag
22 self.PARSE_VERSION = "parse_version" #used as xml-tag
23 self.NUM = "num" #used as xml-tag
24 self.VER_NUM = "1.0.1"
20 self.TYPE = "type" #used as xml-tag 25 self.TYPE = "type" #used as xml-tag
21 self.CLASS_CONSTRUCTOR = "class_constructor" 26 self.CLASS_CONSTRUCTOR = "class_constructor"
22 self.BASE_ID = "base_id" 27 self.BASE_ID = "base_id"
@@ -69,31 +74,30 @@ class _const:
69 self.DIRECTION = "direction" #used as xml-tag 74 self.DIRECTION = "direction" #used as xml-tag
70 75
71 76
72def isC(s): 77def isC(_path):
73 #FIXME when parsing eobase we can catch "eo.c" with EO_DEFINE_CLASS 78 #FIXME when parsing eobase we can catch "eo.c" with EO_DEFINE_CLASS
74 path_lst = s.split('.') 79 (d, f) = os.path.split(_path)
75 if len(path_lst) == 2: 80 f_name = f.split('.')
76 if path_lst[1] in ["c", "cc", "cpp"]: 81 if len(f_name) == 2:
77 return True 82 return True if f_name[1] in ["c", "cc", "cpp"] else False
78 else: 83 else:
79 return False 84 return False
80 85
81 86def isH(_path):
82def isH(s): 87 (d, f) = os.path.split(_path)
83 path_lst = s.split('.') 88 f_name = f.split('.')
84 if len(path_lst) == 2: 89 if len(f_name) == 2:
85 if path_lst[1] in ["h"]: 90 return True if f_name[1] in ["h"] else False
86 return True 91 else:
87 else: 92 return False
88 return False 93
89 94def isXML(_path):
90def isXML(s): 95 (d, f) = os.path.split(_path)
91 path_lst = s.split('.') 96 f_name = f.split('.')
92 if len(path_lst) == 2: 97 if len(f_name) == 2:
93 if path_lst[1] in ["xml"]: 98 return True if f_name[1] in ["xml"] else False
94 return True 99 else:
95 else: 100 return False
96 return False
97 101
98# dir_files_get(_directories, func, recursive) 102# dir_files_get(_directories, func, recursive)
99# 103#
@@ -148,6 +152,8 @@ def abs_path_get(_paths, _warning = True):
148 if _warning: 152 if _warning:
149 print "ERROR: path %s doesn't exist... Aborting..."%path_tmp 153 print "ERROR: path %s doesn't exist... Aborting..."%path_tmp
150 exit(1) 154 exit(1)
155 else:
156 print "Warning: path %s doesn't exist..."%path_tmp
151 return res 157 return res
152 158
153 159
diff --git a/eo_parser/XMLparser.py b/eoparser/xmlparser.py
index 85b2663..d3a197f 100644
--- a/eo_parser/XMLparser.py
+++ b/eoparser/xmlparser.py
@@ -1,7 +1,7 @@
1import xml.parsers.expat, os, shutil 1import xml.parsers.expat, os, shutil
2from eo_parser.helper import isXML, abs_path_get, dir_files_get 2from eoparser.helper import isXML, abs_path_get, dir_files_get
3from helper import normalize_names, _const 3from helper import normalize_names, _const
4import copy 4import copy, sys
5 5
6const = _const() 6const = _const()
7 7
@@ -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):
@@ -28,9 +27,8 @@ class VAcceptor(object):
28#Class to save data about each function 27#Class to save data about each function
29#This is one item from Mod.functions list 28#This is one item from Mod.functions list
30class Func(VAcceptor): 29class Func(VAcceptor):
31 def __init__(self, _name, _prop_name,_op_id, _c_macro, _parameters, _prop_type, _cl_obj): 30 def __init__(self, _name, _op_id, _c_macro, _parameters, _prop_type, _cl_obj):
32 self.name = _name 31 self.name = _name
33 self.prop_name = _prop_name
34 self.op_id = _op_id 32 self.op_id = _op_id
35 self.c_macro = _c_macro 33 self.c_macro = _c_macro
36 self.parameters = _parameters 34 self.parameters = _parameters
@@ -72,6 +70,8 @@ class Mod(object):
72 self.sub_id_function = "" 70 self.sub_id_function = ""
73 self.source_file = "" 71 self.source_file = ""
74 self.parents = [] 72 self.parents = []
73 self.path = ""
74 self.objects_incl = {}
75 self.V = None 75 self.V = None
76 76
77 # dictionary to save all object which have to be visited: Func, Ev, Init 77 # dictionary to save all object which have to be visited: Func, Ev, Init
@@ -82,8 +82,6 @@ class Mod(object):
82 o.accept(self.V) 82 o.accept(self.V)
83 83
84 84
85
86
87# Visitor Design Pattern 85# Visitor Design Pattern
88# Visitor - base class for different visitors. 86# Visitor - base class for different visitors.
89# visit function implements dispatching depending on class name of object 87# visit function implements dispatching depending on class name of object
@@ -97,7 +95,6 @@ class Visitor(object):
97 else: 95 else:
98 print "%s is not callable attribute"%(method_name) 96 print "%s is not callable attribute"%(method_name)
99 97
100
101 def cast(self, _in): 98 def cast(self, _in):
102 t = _in 99 t = _in
103 100
@@ -113,9 +110,10 @@ class Visitor(object):
113 "char**" : "char*"} 110 "char**" : "char*"}
114 111
115 internal_types = { 112 internal_types = {
116 "void*": ["void*", "object"], 113 # orig_type: ["how c obj will be defined and ho to cast to cobj", "how in Py objj will be defined"]
114 "void*": ["void*", "object"], #FIXME "ToObject?"
117 "char*": ["char*", "object", "ToString"], 115 "char*": ["char*", "object", "ToString"],
118 "Eo*": ["Eo*", "EoDefault", "ToObject"], 116 "Eo*": ["Eo*", "EoDefault", "ToEo"], #ToEo
119 "short" : ["int", "int", "ToInt32"], 117 "short" : ["int", "int", "ToInt32"],
120 "short*" : ["int", "int", "ToInt32"], 118 "short*" : ["int", "int", "ToInt32"],
121 "int": ["int", "int", "ToInt32"], 119 "int": ["int", "int", "ToInt32"],
@@ -130,15 +128,17 @@ class Visitor(object):
130 "bool*" : ["unsigned char","int", "ToBoolean"], 128 "bool*" : ["unsigned char","int", "ToBoolean"],
131 "unsigned int": ["unsigned int", "unsigned int", "ToUint32"], 129 "unsigned int": ["unsigned int", "unsigned int", "ToUint32"],
132 "unsigned int*": ["unsigned int", "unsigned int", "ToUint32"], 130 "unsigned int*": ["unsigned int", "unsigned int", "ToUint32"],
131 "unsigned short": ["unsigned int", "unsigned int", "ToUint32"],
132 "unsigned short*": ["unsigned int", "unsigned int", "ToUint32"],
133 "unsigned long": ["unsigned long", "unsigned long", "ToUint32"], 133 "unsigned long": ["unsigned long", "unsigned long", "ToUint32"],
134 "unsigned long*": ["unsigned long", "unsigned long", "ToNumber"], 134 "unsigned long*": ["unsigned long", "unsigned long", "ToNumber"],
135 "unsigned long long": ["unsigned long long", "unsigned long long", "ToNumber"], 135 "unsigned long long": ["unsigned long long", "unsigned long long", "ToNumber"],
136 "unsigned long long*": ["unsigned long long", "unsigned long long", "ToNumber"], 136 "unsigned long long*": ["unsigned long long", "unsigned long long", "ToNumber"],
137 "float": ["float", "float", "ToNumber"], 137 "float": ["float", "float", "ToNumber"],
138 "double": ["double", "double", "ToNumber" ],
139 "long double": ["long double", "long double", "ToNumber"],
140 "float*": ["float", "float", "ToNumber"], 138 "float*": ["float", "float", "ToNumber"],
139 "double": ["double", "double", "ToNumber" ],
141 "double*": ["double", "double", "ToNumber" ], 140 "double*": ["double", "double", "ToNumber" ],
141 "long double": ["long double", "long double", "ToNumber"],
142 "long double*": ["long double", "long double", "ToNumber"], 142 "long double*": ["long double", "long double", "ToNumber"],
143 "Eo_Event_Description*":["long","long", "ToNumber"], 143 "Eo_Event_Description*":["long","long", "ToNumber"],
144 "Eo_Event_Cb":["Eo_Event_Cb","object", "ToNumber"] 144 "Eo_Event_Cb":["Eo_Event_Cb","object", "ToNumber"]
@@ -149,12 +149,11 @@ class Abstract(object):
149 def __init__(self): 149 def __init__(self):
150 pass 150 pass
151 151
152
153
154class JsVisitor(Visitor): 152class JsVisitor(Visitor):
155 153
156 def __init__(self): 154 def __init__(self):
157 self.visited_properties = [] 155 self.visited_properties = []
156 self.func_name_prefix = "__"
158 157
159 self.c_file = Abstract() 158 self.c_file = Abstract()
160 self.c_file.name = "" 159 self.c_file.name = ""
@@ -180,13 +179,15 @@ class JsVisitor(Visitor):
180 self.class_info.public = [] 179 self.class_info.public = []
181 180
182 181
183 self.js_types = { "ToBoolean" : "Boolean", 182 self.c_to_js_constr = { "ToBoolean" : "Boolean",
184 "ToString" : "String", 183 "ToString" : "String",
185 "ToUint32" : "Number", 184 "ToUint32" : "Number",
186 "ToInt32" : "Number", 185 "ToInt32" : "Number",
187 "ToNumber" : "Number", 186 "ToNumber" : "Number",
188 "ToObject" : "Local <Object>" 187# "ToObject" : "Local <Object>",
189 } 188 "ToVoid" : "VOID",
189 "ToEo" : "#error"
190 }
190 191
191 #Func visit function, to generate code for functions 192 #Func visit function, to generate code for functions
192 def visit_Func(self, _o): 193 def visit_Func(self, _o):
@@ -200,11 +201,11 @@ class JsVisitor(Visitor):
200 self.visited_properties.append(prop_name) 201 self.visited_properties.append(prop_name)
201 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_SET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name)) 202 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_SET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name))
202 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_GET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name)) 203 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_GET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name))
203 self.class_info.public.append(" Handle<Value> %s_get() const;\n"%(prop_name)) 204 self.class_info.public.append(" Handle<Value> %s%s_get() const;\n"%(self.func_name_prefix, prop_name))
204 self.class_info.public.append(" void %s_set(Handle<Value> val);\n"%(prop_name)) 205 self.class_info.public.append(" void %s%s_set(Handle<Value> _val);\n"%(self.func_name_prefix, prop_name))
205 206
206 self.h_file.prop_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(prop_name)) 207 self.h_file.prop_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(prop_name))
207 self.h_file.prop_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> val, const AccessorInfo &info);\n"%(prop_name)) 208 self.h_file.prop_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> _val, const AccessorInfo &info);\n"%(prop_name))
208 self.c_file.tmpl.append(" PROPERTY(%s)"% prop_name) 209 self.c_file.tmpl.append(" PROPERTY(%s)"% prop_name)
209 210
210 211
@@ -212,27 +213,27 @@ class JsVisitor(Visitor):
212 self.visit_prop_set_get(_o) 213 self.visit_prop_set_get(_o)
213 prop_name = _o.name[:-4] 214 prop_name = _o.name[:-4]
214 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_SET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name)) 215 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_SET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name))
215 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_GET_EMPTY_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name)) 216 #self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_GET_EMPTY_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name))
216 217
217 self.class_info.public.append(" Handle<Value> %s_get() const;\n"%(prop_name)) 218 #self.class_info.public.append(" Handle<Value> %s%s_get() const;\n"%(self.func_name_prefix, prop_name))
218 self.class_info.public.append(" void %s_set(Handle<Value> val);\n"%(prop_name)) 219 self.class_info.public.append(" void %s%s_set(Handle<Value> _val);\n"%(self.func_name_prefix, prop_name))
219 220
220 self.c_file.tmpl.append(" PROPERTY(%s)"% prop_name) 221 self.c_file.tmpl.append(" PROPERTY_SO(%s)"% prop_name)
221 self.h_file.prop_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(prop_name)) 222 #self.h_file.prop_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(prop_name))
222 self.h_file.prop_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> val, const AccessorInfo &info);\n"%(prop_name)) 223 self.h_file.prop_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> _val, const AccessorInfo &info);\n"%(prop_name))
223 224
224 elif _o.prop_type == const.GET_ONLY: 225 elif _o.prop_type == const.GET_ONLY:
225 self.visit_prop_set_get(_o) 226 self.visit_prop_set_get(_o)
226 prop_name = _o.name[:-4] 227 prop_name = _o.name[:-4]
227 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_GET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name)) 228 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_GET_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name))
228 self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_SET_EMPTY_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name)) 229 #self.c_file.cb_generate_macros.append("EO_GENERATE_PROPERTY_SET_EMPTY_CALLBACK(%s, %s);\n"%(_o.cl_obj.kl_id, prop_name))
229 230
230 self.class_info.public.append(" Handle<Value> %s_get() const;\n"%(prop_name)) 231 self.class_info.public.append(" Handle<Value> %s%s_get() const;\n"%(self.func_name_prefix, prop_name))
231 self.class_info.public.append(" void %s_set(Handle<Value> val);\n"%(prop_name)) 232 #self.class_info.public.append(" void %s%s_set(Handle<Value> _val);\n"%(self.func_name_prefix, prop_name))
232 233
233 self.c_file.tmpl.append(" PROPERTY(%s)"% prop_name) 234 self.c_file.tmpl.append(" PROPERTY_RO(%s)"% prop_name)
234 self.h_file.prop_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(prop_name)) 235 self.h_file.prop_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(prop_name))
235 self.h_file.prop_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> val, const AccessorInfo &info);\n"%(prop_name)) 236 #self.h_file.prop_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> _val, const AccessorInfo &info);\n"%(prop_name))
236 237
237 elif _o.prop_type == const.METHOD: 238 elif _o.prop_type == const.METHOD:
238 self.visit_method(_o) 239 self.visit_method(_o)
@@ -251,16 +252,16 @@ class JsVisitor(Visitor):
251 252
252 253
253 self.class_info.public.append("\n") 254 self.class_info.public.append("\n")
254 self.class_info.public.append(" Handle<Value> %s_get() const;\n"%(ev)) 255 self.class_info.public.append(" Handle<Value> %s%s_get() const;\n"%(self.func_name_prefix, ev))
255 self.class_info.public.append(" void %s_set(Handle<Value> val);\n"%(ev)) 256 self.class_info.public.append(" void %s%s_set(Handle<Value> _val);\n"%(self.func_name_prefix,ev))
256 self.class_info.public.append(" void %s(void *event_info);\n"%(ev)) 257 self.class_info.public.append(" void %s%s(void *event_info);\n"%(self.func_name_prefix,ev))
257 self.class_info.public.append(" static Eina_Bool %s_wrapper(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n"%(ev)) 258 self.class_info.public.append(" static Eina_Bool %s%s_wrapper(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n"%(self.func_name_prefix,ev))
258 259
259 self.h_file.ev_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(ev)) 260 self.h_file.ev_cb_headers.append(" Handle<Value> Callback_%s_get(Local<String>, const AccessorInfo &info);\n"%(ev))
260 self.h_file.ev_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> val, const AccessorInfo &info);\n"%(ev)) 261 self.h_file.ev_cb_headers.append(" void Callback_%s_set(Local<String>, Local<Value> _val, const AccessorInfo &info);\n"%(ev))
261 262
262 #event function 263 #event function
263 self.c_file.functions.append("void %s::%s(void *event_info) //parse of event_info need to be added \n"%(_o.cl_obj.kl_id, ev)) 264 self.c_file.functions.append("void %s::%s%s(void *event_info) //parse of event_info need to be added \n"%(_o.cl_obj.kl_id, self.func_name_prefix, ev))
264 self.c_file.functions.append("{\n") 265 self.c_file.functions.append("{\n")
265 self.c_file.functions.append(" Handle<Function> callback(Function::Cast(*cb.%s));\n"%ev_prefix) 266 self.c_file.functions.append(" Handle<Function> callback(Function::Cast(*cb.%s));\n"%ev_prefix)
266 self.c_file.functions.append(" Handle<Value> args[1] = {jsObject};\n") 267 self.c_file.functions.append(" Handle<Value> args[1] = {jsObject};\n")
@@ -269,41 +270,39 @@ class JsVisitor(Visitor):
269 self.c_file.functions.append("\n") 270 self.c_file.functions.append("\n")
270 271
271 #event function wrapper 272 #event function wrapper
272 self.c_file.functions.append("Eina_Bool %s::%s_wrapper(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)\n"%(_o.cl_obj.kl_id, ev)) 273 self.c_file.functions.append("Eina_Bool %s::%s%s_wrapper(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)\n"%(_o.cl_obj.kl_id, self.func_name_prefix, ev))
273 self.c_file.functions.append("{\n\ 274 self.c_file.functions.append("{\n\
274 HandleScope scope;\n\ 275 HandleScope scope;\n\
275 static_cast<%s*>(data)->%s(event_info);\n\ 276 dynamic_cast<%s*>(static_cast<CElmObject*>(data))->%s%s(event_info);\n\
276 return EINA_TRUE;\n\ 277 return EINA_TRUE;\n\
277 (void) obj;\n\ 278 (void) obj;\n\
278 (void) desc;\n\ 279 (void) desc;\n\
279 }\n"%(_o.cl_obj.kl_id, ev)) 280 }\n"%(_o.cl_obj.kl_id, self.func_name_prefix, ev))
280 self.c_file.functions.append("\n") 281 self.c_file.functions.append("\n")
281 282
282 #event function get 283 #event function get
283 self.c_file.functions.append("Handle<Value> %s::%s_get() const\n"%(_o.cl_obj.kl_id, ev)) 284 self.c_file.functions.append("Handle<Value> %s::%s%s_get() const\n"%(_o.cl_obj.kl_id, self.func_name_prefix, ev))
284 self.c_file.functions.append("{\n\ 285 self.c_file.functions.append("{\n\
285 return cb.%s;\n\ 286 return cb.%s;\n\
286 }\n"%ev_prefix) 287 }\n"%ev_prefix)
287 self.c_file.functions.append("\n") 288 self.c_file.functions.append("\n")
288 289
289 #event function set 290 #event function set
290 self.c_file.functions.append("void %s::%s_set(Handle<Value> val)\n"%(_o.cl_obj.kl_id, ev)) 291 self.c_file.functions.append("void %s::%s%s_set(Handle<Value> _val)\n"%(_o.cl_obj.kl_id, self.func_name_prefix, ev))
291 self.c_file.functions.append("{\n") 292 self.c_file.functions.append("{\n")
292 self.c_file.functions.append(" if (!val->IsFunction())\n\ 293 self.c_file.functions.append(" if (!_val->IsFunction())\n\
293 return;\n") 294 return;\n")
294 self.c_file.functions.append(" if (!cb.%s.IsEmpty())\n\ 295 self.c_file.functions.append(" if (!cb.%s.IsEmpty())\n\
295 {\n\ 296 {\n\
296 cb.%s.Dispose();\n\ 297 cb.%s.Dispose();\n\
297 cb.%s.Clear();\n\ 298 cb.%s.Clear();\n\
298 eo_do(eobj, eo_event_callback_del(%s, %s_wrapper, this));\n\ 299 eo_do(eobj, eo_event_callback_del(%s, %s%s_wrapper, dynamic_cast<CElmObject*>(this)));\n\
299 }\n"%(ev_prefix, ev_prefix, ev_prefix, _o.ev_id, ev)) 300 }\n"%(ev_prefix, ev_prefix, ev_prefix, _o.ev_id, self.func_name_prefix, ev))
300 self.c_file.functions.append(" cb.%s = Persistent<Value>::New(val);\n\ 301 self.c_file.functions.append(" cb.%s = Persistent<Value>::New(_val);\n\
301 eo_do(eobj, eo_event_callback_add(%s, %s_wrapper, this));\n"%(ev_prefix, _o.ev_id, ev)) 302 eo_do(eobj, eo_event_callback_add(%s, %s%s_wrapper, dynamic_cast<CElmObject*>(this)));\n"%(ev_prefix, _o.ev_id, self.func_name_prefix, ev))
302 self.c_file.functions.append("}\n") 303 self.c_file.functions.append("}\n")
303 self.c_file.functions.append("\n") 304 self.c_file.functions.append("\n")
304 305
305
306
307 #is called by visit_Func to parse function as a property 306 #is called by visit_Func to parse function as a property
308 def visit_prop_set_get(self, _o): 307 def visit_prop_set_get(self, _o):
309 308
@@ -313,12 +312,12 @@ class JsVisitor(Visitor):
313 direction = "out" if prop_type == "_get" else "in" 312 direction = "out" if prop_type == "_get" else "in"
314 313
315 params_tmp = [] 314 params_tmp = []
316 add_this_func = True 315 add_this_func_with_error = False
317 for i, (n, c_t, d, p_t) in enumerate(_o.parameters): 316 for i, (n, modifier, c_t, d, p_t) in enumerate(_o.parameters):
318 if d != direction: 317 if d != direction:
319 print "Warning wrong direction: property: %s; parameter: %s; direction: %s"%(prop_name + "_get", n, d) 318 print "Warning wrong direction: class: \"%s\"; property: \"%s\"; parameter: \"%s\"; direction: \"%s\""%(_o.cl_obj.c_name, _o.name, n, d)
320 print "Property \"%s\" will not be defined"%(prop_name + "_get") 319 print "Property \"%s\", from class \"%s\" will be added with message error"%(_o.name, _o.cl_obj.c_name)
321 add_this_func = False 320 add_this_func_with_error = True
322 break 321 break
323 322
324 c_t_tmp = self.cast(p_t) 323 c_t_tmp = self.cast(p_t)
@@ -327,17 +326,24 @@ class JsVisitor(Visitor):
327 326
328 if c_t_tmp in self.internal_types: 327 if c_t_tmp in self.internal_types:
329 c_t_internal = self.internal_types[c_t_tmp][0] 328 c_t_internal = self.internal_types[c_t_tmp][0]
329 if len(self.internal_types[c_t_tmp]) < 3:
330 add_this_func_with_error = True
331 break
330 js_type = self.internal_types[c_t_tmp][2] 332 js_type = self.internal_types[c_t_tmp][2]
331 params_tmp.append((c_t, n, d, c_t_internal, js_type)) 333 params_tmp.append((modifier, c_t, n, d, c_t_internal, js_type))
332 else: 334 else:
333 print "Warning: type: \"%s\" wasn't found in self.internal_types. Funct ion \"%s\" will not be defined"%(c_t_tmp, prop_name + "_get") 335 print "Warning: type: \"%s\" wasn't found in self.internal_types.\n Property \"%s\", from class \"%s\" will be added with error message"%(c_t_tmp, _o.name, _o.cl_obj.c_name)
334 add_this_func = False 336 add_this_func_with_error = True
335 break 337 break
336 338
337 if not add_this_func: 339 if add_this_func_with_error:
338 return 340 if prop_type == "_get":
341 self.prop_get_err_generate(_o, params_tmp)
342 elif prop_type == "_set":
343 self.prop_set_err_generate(_o, params_tmp)
339 344
340 if prop_type == "_get": 345
346 elif prop_type == "_get":
341 self.prop_get_generate(_o, params_tmp) 347 self.prop_get_generate(_o, params_tmp)
342 348
343 elif prop_type == "_set": 349 elif prop_type == "_set":
@@ -357,31 +363,47 @@ class JsVisitor(Visitor):
357 363
358 #do not need to 364 #do not need to
359 self.c_file.cb_generate_macros.append("EO_GENERATE_METHOD_CALLBACKS(%s, %s);\n"%(_o.cl_obj.kl_id, _o.name)) 365 self.c_file.cb_generate_macros.append("EO_GENERATE_METHOD_CALLBACKS(%s, %s);\n"%(_o.cl_obj.kl_id, _o.name))
360 self.class_info.public.append(" Handle<Value> %s(const Arguments&);\n"%(_o.name)) 366 self.class_info.public.append(" Handle<Value> %s%s(const Arguments&);\n"%(self.func_name_prefix, _o.name))
361 367
362 self.c_file.tmpl.append(" METHOD(%s)"% _o.name) 368 self.c_file.tmpl.append(" METHOD(%s)"% _o.name)
363 self.h_file.meth_cb_headers.append(" Handle<Value> Callback_%s(const Arguments&);\n"%(_o.name)) 369 self.h_file.meth_cb_headers.append(" Handle<Value> Callback_%s(const Arguments&);\n"%(_o.name))
364 370
371 functions_tmp_save = list(self.c_file.functions)
372 self.c_file.functions.append("/* generated by 'visit method() ' */\n")
365 373
366 self.c_file.functions.append("Handle<Value> %s::%s(const Arguments& args)\n"%(_o.cl_obj.kl_id, _o.name)) 374 self.c_file.functions.append("Handle<Value> %s::%s%s(const Arguments& args)\n"%( _o.cl_obj.kl_id, self.func_name_prefix, _o.name))
367 self.c_file.functions.append("{\n") 375 self.c_file.functions.append("{\n")
368 self.c_file.functions.append(" HandleScope scope;\n") 376 self.c_file.functions.append(" HandleScope scope;\n")
369 377
370 pass_params = [] 378 pass_params = []
371 ret_params = [] 379 ret_params = []
372 in_param_counter = 0 380 in_param_counter = 0
373 for i, (n, c_t, d, p_t) in enumerate(_o.parameters): 381
382 add_this_func = True
383 add_end_func = []
384 args_not_used = True
385 for i, (n, modifier, c_t, d, p_t) in enumerate(_o.parameters):
386 args_not_used = False
374 c_t_tmp = self.cast(p_t) 387 c_t_tmp = self.cast(p_t)
388 casting = "(%s %s)"%(modifier, c_t)
375 389
376 js_type = "" 390 js_type = ""
377 c_t_internal = "" 391 c_t_internal = ""
378 392
379 if c_t_tmp in self.internal_types: 393 if c_t_tmp in self.internal_types:
380 c_t_internal = self.internal_types[c_t_tmp][0] 394 c_t_internal = self.internal_types[c_t_tmp][0]
381 js_type = self.internal_types[c_t_tmp][2] 395 if len(self.internal_types[c_t_tmp]) < 3:
396 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)
397 add_this_func = False
398 else:
399 js_type = self.internal_types[c_t_tmp][2]
382 else: 400 else:
383 print "Warning: type: \"%s\" wasn't found in self.internal_types. Function \"%s\" will not be defined"%(c_t_tmp, m) 401 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)
384 continue 402 add_this_func = False
403
404 if not add_this_func:
405 self.c_file.functions = list(functions_tmp_save)
406 return
385 407
386 if d == "in": 408 if d == "in":
387 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter)) 409 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter))
@@ -389,21 +411,33 @@ class JsVisitor(Visitor):
389 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 411 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
390 412
391 if js_type == "ToString": 413 if js_type == "ToString":
392 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type)) 414 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type))
393 elif js_type == "ToObject": 415 self.c_file.functions.append(" if (!strcmp(%s, \"null\")) %s = NULL;\n"%(n, n))
416 add_end_func.append(" free(%s);\n"%n)
417 pass_params.append(casting + n)
418 elif js_type == "ToEo":
394 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n)) 419 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n))
420 pass_params.append(casting + n)
395 else: 421 else:
396 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type)) 422 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type))
423
424 if c_t.find("*") != -1:
425 pass_params.append(casting + '&' + n)
426 else:
427 pass_params.append(casting + n)
428 """
397 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*": 429 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*":
398 pass_params.append('&' + n) 430 pass_params.append('&' + n)
399 else: 431 else:
400 pass_params.append(n) 432 pass_params.append(n)
433 """
434
401 elif d == "out": 435 elif d == "out":
402 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 436 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
403 pass_params.append('&' + n) 437 pass_params.append(casting + '&' + n)
404 438
405 js_type = self.js_types[js_type] 439 js_constr = self.c_to_js_constr[js_type]
406 ret_params.append((n, js_type)) 440 ret_params.append((n, js_type, js_constr))
407 441
408 elif d == "in,out": 442 elif d == "in,out":
409 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter)) 443 self.c_file.functions.append(" Local<Value> _%s = args[%d];\n"%(n, in_param_counter))
@@ -411,103 +445,152 @@ class JsVisitor(Visitor):
411 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 445 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
412 446
413 if js_type == "ToString": 447 if js_type == "ToString":
414 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type)) 448 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_%s->%s()));\n"%(n, n, js_type))
415 elif js_type == "ToObject": 449 self.c_file.functions.append(" if (!strcmp(%s, \"null\")) %s = NULL;\n"%(n, n))
450 add_end_func.append(" free(%s);\n"%n)
451 elif js_type == "ToEo":
416 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n)) 452 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_%s->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n, n))
417 else: 453 else:
418 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type)) 454 self.c_file.functions.append(" %s = _%s->%s()->Value();\n"%(n, n, js_type))
419 455
420 pass_params.append('&' + n) 456 pass_params.append(casting + '&' + n)
421 js_type = self.js_types[js_type] 457 js_constr = self.c_to_js_constr[js_type]
422 ret_params.append((n, js_type)) 458 ret_params.append((n, js_type, js_constr))
423 459
424 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%( _o.c_macro, ", ".join(pass_params))) 460 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%( _o.c_macro, ", ".join(pass_params)))
425 461
426 if len(ret_params) == 1: 462 if len(ret_params) == 1:
427 for par, t in ret_params: 463 args_not_used = False
464 for par, js_type, js_constr in ret_params:
428#FIXME: case then we work with EO 465#FIXME: case then we work with EO
429 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper values\n"%(t, par)) 466 if js_type in ["ToEo", "ToVoid"]:
467 self.c_file.functions.append(" return Undefined(); //need to fix case when returning object!\n")
468 else:
469 self.c_file.functions += add_end_func
470 add_end_func = []
471 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper values\n"%(js_constr, par))
430 elif len(ret_params) > 1: 472 elif len(ret_params) > 1:
473 args_not_used = False
431 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n") 474 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n")
432 for p, t in ret_params: 475 for par, js_type, js_constr in ret_params:
433 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"%(p, t, p)) 476 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"%(par, js_constr, par))
434 self.c_file.functions.append(" return scope.Close(obj__); //need to put proper values\n") 477 self.c_file.functions += add_end_func
478 add_end_func = []
479 self.c_file.functions.append(" return scope.Close(obj__); //should be right\n")
435 else: 480 else:
481 self.c_file.functions += add_end_func
482 add_end_func = []
436 self.c_file.functions.append(" return Undefined();\n") 483 self.c_file.functions.append(" return Undefined();\n")
484 #if no return params
485
486 if args_not_used:
487 self.c_file.functions.append(" (void)args;\n")
437 488
438 self.c_file.functions.append("}\n") 489 self.c_file.functions.append("}\n")
439 self.c_file.functions.append("\n") 490 self.c_file.functions.append("\n")
440 491
441 # is called by prop_set_get_visit, to generate body for property getter 492 # is called by prop_set_get_visit, to generate body for property getter
442 def prop_get_generate(self, _o, params_tmp): 493 def prop_get_generate(self, _o, params_tmp):
443 self.c_file.functions.append("Handle<Value> %s::%s() const\n"%(_o.cl_obj.kl_id, _o.name)) 494 self.c_file.functions.append("/* generated by 'prop_get_generate() ' */\n")
495 self.c_file.functions.append("Handle<Value> %s::%s%s() const\n"%(_o.cl_obj.kl_id, self.func_name_prefix, _o.name))
444 self.c_file.functions.append("{\n") 496 self.c_file.functions.append("{\n")
445 self.c_file.functions.append(" HandleScope scope;\n") 497 self.c_file.functions.append(" HandleScope scope;\n")
446 498
447 pass_params = [] 499 pass_params = []
448 ret_params = [] 500 ret_params = []
449 for (c_t, n, d, c_t_internal, js_type) in params_tmp: 501 for (modifier, c_t, n, d, c_t_internal, js_type) in params_tmp:
502 casting = "(%s %s)"%(modifier, c_t)
450 503
451 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 504 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
452 pass_params.append('&' + n) 505 pass_params.append(casting + '&' + n)
453 506
454 js_type = self.js_types[js_type] 507 js_constr = self.c_to_js_constr[js_type]
455 ret_params.append((n, js_type)) 508 ret_params.append((n, js_type, js_constr))
456 509
457 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%(_o.c_macro, ", ".join(pass_params))) 510 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%(_o.c_macro, ", ".join(pass_params)))
458 511
459 if len(ret_params) == 1: 512 if len(ret_params) == 1:
460 for par, t in ret_params: 513 for par, js_type, js_constr in ret_params:
461 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper val ues\n"%(t, par)) 514 self.c_file.functions.append("/* %s */\n"%js_type)
515 if js_type in ["ToEo", "ToVoid"]:
516 self.c_file.functions.append(" return Undefined(); //need to fix case when returning object!\n")
517 else:
518 self.c_file.functions.append(" return scope.Close(%s::New(%s));//need to put proper values\n"%(js_constr, par))
462 519
463 elif len(ret_params) > 1: 520 elif len(ret_params) > 1:
464 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n") 521 self.c_file.functions.append(" Local<Object> obj__ = Object::New();\n")
465 for par, t in ret_params: 522 for par, js_type, js_constr in ret_params:
466 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"% (par, t, par)) 523 self.c_file.functions.append(" obj__->Set(String::NewSymbol(\"%s\"), %s::New(%s));\n"% (par, js_constr, par))
467 self.c_file.functions.append(" return scope.Close(obj__);//need to put proper values\n") 524 self.c_file.functions.append(" return scope.Close(obj__);//need to put proper values\n")
468 else: 525 else:
469 self.c_file.functions.append(" return Undefined();\n") 526 self.c_file.functions.append(" return Undefined();\n")
470 527
471 self.c_file.functions.append("}\n\n") 528 self.c_file.functions.append("}\n\n")
472 529
473
474 # is called by prop_set_get_visit, to generate body for property setter 530 # is called by prop_set_get_visit, to generate body for property setter
475 def prop_set_generate(self, _o, params_tmp): 531 def prop_set_generate(self, _o, params_tmp):
532 self.c_file.functions.append("/* generated by 'prop_set_generate() ' */\n")
476 533
477 self.c_file.functions.append("void %s::%s(Handle<Value> val)\n"%(_o.cl_obj.kl_id, _o.name)) 534 self.c_file.functions.append("void %s::%s%s(Handle<Value> _val)\n"%(_o.cl_obj.kl_id, self.func_name_prefix, _o.name))
478 self.c_file.functions.append("{\n") 535 self.c_file.functions.append("{\n")
479 536
480 pass_params = [] 537 pass_params = []
481 add_end_func = [] 538 add_end_func = []
482 if len(params_tmp) > 1: 539 if len(params_tmp) > 1:
483 self.c_file.functions.append(" Local<Object> __o = val->ToObject();\n") 540 self.c_file.functions.append(" Local<Object> __o = _val->ToObject();\n")
484 541
485 for (c_t, n, d, c_t_internal, js_type) in params_tmp: 542 for (modifier, c_t, n, d, c_t_internal, js_type) in params_tmp:
543 casting = "(%s %s)"%(modifier, c_t)
486 544
487 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 545 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
488 if js_type == "ToString": 546 if js_type == "ToString":
489 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(__o->Get(String::NewSymbol(\"%s\"))->%s()));\n"%(n, n, js_type)) 547 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(__o->Get(String::NewSymbol(\"%s\"))->%s()));\n"%(n, n, js_type))
548 self.c_file.functions.append(" if (!strcmp(%s, \"null\")) %s = NULL;\n"%(n, n))
549 add_end_func.append(" free(%s);\n"%n)
550 pass_params.append(casting + n)
551
490 else: 552 else:
491 self.c_file.functions.append(" %s = __o->Get(String::NewSymbol(\"%s\"))->%s()->Value();\n"%(n, n, js_type)) 553 self.c_file.functions.append(" %s = __o->Get(String::NewSymbol(\"%s\"))->%s()->Value();\n"%(n, n, js_type))
492 554
555 if c_t.find("*") != -1:
556 pass_params.append(casting + '&' + n)
557 else:
558 pass_params.append(casting + n)
559 """
493 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*": 560 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*":
494 pass_params.append('&' + n) 561 pass_params.append('&' + n)
495 else: 562 else:
496 pass_params.append(n) 563 pass_params.append(n)
564 """
497 565
498 elif len(params_tmp) == 1: 566 elif len(params_tmp) == 1:
499 for (c_t, n, d, c_t_internal, js_type) in params_tmp: 567 for (modifier, c_t, n, d, c_t_internal, js_type) in params_tmp:
500 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n)) 568 casting = "(%s %s)"%(modifier, c_t)
501 if js_type == "ToString": 569 if js_type == "ToString":
502 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(val->%s()));\n"%(n, js_type)) 570 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
503 add_end_func.append(" free(%s);"%n) 571 self.c_file.functions.append(" %s = strdup(*String::Utf8Value(_val->%s()));\n"%(n, js_type))
572 self.c_file.functions.append(" if (!strcmp(%s, \"null\")) %s = NULL;\n"%(n, n))
573 add_end_func.append(" free(%s);\n"%n)
574 pass_params.append(casting + n)
575 elif js_type == "ToEo":
576 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
577 self.c_file.functions.append(" %s = static_cast<CElmObject*>(_val->ToObject()->GetPointerFromInternalField(0))->GetEo();\n"%(n))
578 pass_params.append(casting + n)
504 else: 579 else:
505 self.c_file.functions.append(" %s = val->%s()->Value();\n"%(n, js_type)) 580 self.c_file.functions.append(" %s %s;\n"%(c_t_internal, n))
581 self.c_file.functions.append(" %s = _val->%s()->Value();\n"%(n, js_type))
582
583 if c_t.find("*") != -1:
584 pass_params.append(casting + '&' + n)
585 else:
586 pass_params.append(casting + n)
506 587
588 """
507 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*": 589 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*":
508 pass_params.append('&' + n) 590 pass_params.append('&' + n)
509 else: 591 else:
510 pass_params.append(n) 592 pass_params.append(n)
593 """
511 594
512 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%(_o.c_macro, ", ".join(pass_params))) 595 self.c_file.functions.append(" eo_do(eobj, %s(%s));\n"%(_o.c_macro, ", ".join(pass_params)))
513 self.c_file.functions += add_end_func 596 self.c_file.functions += add_end_func
@@ -515,7 +598,24 @@ class JsVisitor(Visitor):
515 self.c_file.functions.append("}\n") 598 self.c_file.functions.append("}\n")
516 self.c_file.functions.append("\n") 599 self.c_file.functions.append("\n")
517 600
601 # is called by prop_set_get_visit, to generate body for property getter
602 def prop_get_err_generate(self, _o, params_tmp):
603 self.c_file.functions.append("/* generated by 'prop_get_err_generate() ' */\n")
604 self.c_file.functions.append("Handle<Value> %s::%s%s() const\n"%(_o.cl_obj.kl_id, self.func_name_prefix, _o.name))
605 self.c_file.functions.append("{\n")
606 self.c_file.functions.append(" printf(\"%s : This method wasn't implemented becase of type issue\\n\",__func__);\n")
607
608 self.c_file.functions.append(" return Undefined(); //need to fix case when returning object!\n")
609 self.c_file.functions.append("}\n\n")
518 610
611 # is called by prop_set_get_visit, to generate body for property setter
612 def prop_set_err_generate(self, _o, params_tmp):
613 self.c_file.functions.append("/* generated by 'prop_set_err_generate() ' */\n")
614 self.c_file.functions.append("void %s::%s%s(Handle<Value> _val)\n"%(_o.cl_obj.kl_id, self.func_name_prefix, _o.name))
615 self.c_file.functions.append("{\n")
616 self.c_file.functions.append(" printf(\"%s : This method wasn't implemented becase of type issue\\n\",__func__);")
617 self.c_file.functions.append("}\n")
618 self.c_file.functions.append("\n")
519 619
520 620
521 def visit_Init(self, _o): 621 def visit_Init(self, _o):
@@ -524,7 +624,7 @@ class JsVisitor(Visitor):
524 self.h_file.name = _o.cl_obj.js_h_file 624 self.h_file.name = _o.cl_obj.js_h_file
525 625
526 self.c_file.header.append("/**\n * generated from \"%s\"\n */\n"%(_o.cl_obj.source_file)) 626 self.c_file.header.append("/**\n * generated from \"%s\"\n */\n"%(_o.cl_obj.source_file))
527 self.c_file.header.append("#include \"%s\"\n"%(os.path.split(_o.cl_obj.js_h_file)[1] )) 627 self.c_file.header.append("#include \"%s\"\n"%_o.cl_obj.js_h_file)
528 self.c_file.header.append("namespace elm {\n\n") 628 self.c_file.header.append("namespace elm {\n\n")
529 self.c_file.header.append("using namespace v8;\n\n") 629 self.c_file.header.append("using namespace v8;\n\n")
530 630
@@ -547,7 +647,6 @@ class JsVisitor(Visitor):
547 inherit = ", ".join(lst) 647 inherit = ", ".join(lst)
548 self.class_info.header ="class %s : %s\n"%(_o.cl_obj.kl_id, inherit) 648 self.class_info.header ="class %s : %s\n"%(_o.cl_obj.kl_id, inherit)
549 649
550
551 if _o.cl_obj.eo_type == const.CLASS_TYPE_REGULAR: 650 if _o.cl_obj.eo_type == const.CLASS_TYPE_REGULAR:
552 self.class_info.private.append(" static Persistent<FunctionTemplate> tmpl;\n") 651 self.class_info.private.append(" static Persistent<FunctionTemplate> tmpl;\n")
553 self.class_info.private.append("\n") 652 self.class_info.private.append("\n")
@@ -555,7 +654,7 @@ class JsVisitor(Visitor):
555 #implementing constructor 654 #implementing constructor
556 self.class_info.protected.append(" %s(Local<Object> _jsObject, CElmObject *parent);\n"%(_o.cl_obj.kl_id)) 655 self.class_info.protected.append(" %s(Local<Object> _jsObject, CElmObject *parent);\n"%(_o.cl_obj.kl_id))
557 self.c_file.functions.append("%s::%s(Local<Object> _jsObject, CElmObject *parent)\n"%(_o.cl_obj.kl_id, _o.cl_obj.kl_id)) 656 self.c_file.functions.append("%s::%s(Local<Object> _jsObject, CElmObject *parent)\n"%(_o.cl_obj.kl_id, _o.cl_obj.kl_id))
558 self.c_file.functions.append(" : CElmObject(_jsObject, eo_add(%s , parent ? parent->GetEo() : NULL))\n"%(_o.cl_obj.macro)) 657 self.c_file.functions.append(" : CElmObject(_jsObject, eo_add(%s, parent ? parent->GetEo() : NULL))\n"%(_o.cl_obj.macro))
559 self.c_file.functions.append("{\n jsObject->SetPointerInInternalField(0, static_cast<CElmObject*>(this));\n}\n") 658 self.c_file.functions.append("{\n jsObject->SetPointerInInternalField(0, static_cast<CElmObject*>(this));\n}\n")
560 659
561 self.class_info.protected.append(" static Handle<FunctionTemplate> GetTemplate();\n") 660 self.class_info.protected.append(" static Handle<FunctionTemplate> GetTemplate();\n")
@@ -567,7 +666,7 @@ class JsVisitor(Visitor):
567 #implementing Initialize 666 #implementing Initialize
568 self.c_file.init_f.append("void %s::Initialize(Handle<Object> target)\n"%_o.cl_obj.kl_id) 667 self.c_file.init_f.append("void %s::Initialize(Handle<Object> target)\n"%_o.cl_obj.kl_id)
569 self.c_file.init_f.append("{\n") 668 self.c_file.init_f.append("{\n")
570 self.c_file.init_f.append(" target->Set(String::NewSymbol(\"%s\") , GetTemplate()->GetFunction());\n"%_o.cl_obj.kl_id) 669 self.c_file.init_f.append(" target->Set(String::NewSymbol(\"%s\"), GetTemplate()->GetFunction());\n"%_o.cl_obj.kl_id)
571 self.c_file.init_f.append("}\n") 670 self.c_file.init_f.append("}\n")
572 671
573 self.class_info.public.insert(0, " virtual void DidRealiseElement(Local<Value> obj);\n") 672 self.class_info.public.insert(0, " virtual void DidRealiseElement(Local<Value> obj);\n")
@@ -588,10 +687,7 @@ class JsVisitor(Visitor):
588 687
589 self.class_info.protected.append(" virtual ~%s();\n"%(_o.cl_obj.kl_id)) 688 self.class_info.protected.append(" virtual ~%s();\n"%(_o.cl_obj.kl_id))
590 689
591 690 #saving data to cc file
592
593
594 #saving data to pxi file
595 def js_cc_file_to_dir_save(self, _outdir): 691 def js_cc_file_to_dir_save(self, _outdir):
596 lines = [] 692 lines = []
597 693
@@ -618,7 +714,9 @@ class JsVisitor(Visitor):
618 lines.append(line) 714 lines.append(line)
619 715
620 lines.append("\n} //end namespace elm\n\n") 716 lines.append("\n} //end namespace elm\n\n")
621 f = open (self.c_file.name, 'w') 717
718
719 f = open(os.path.join(_outdir, self.c_file.name), 'w')
622 for line in lines: 720 for line in lines:
623 f.write(line) 721 f.write(line)
624 f.close() 722 f.close()
@@ -677,14 +775,11 @@ class JsVisitor(Visitor):
677 lines.append("\n") 775 lines.append("\n")
678 lines.append("#endif\n") 776 lines.append("#endif\n")
679 777
680 f = open (self.h_file.name, 'w') 778 f = open(os.path.join(_outdir, self.h_file.name), 'w')
681 for line in lines: 779 for line in lines:
682 f.write(line) 780 f.write(line)
683 f.close() 781 f.close()
684 782
685
686
687
688# PyVisitor 783# PyVisitor
689# Py code generation. Generates code depending on object type(input data) 784# Py code generation. Generates code depending on object type(input data)
690# Under "object type" we understand just some set of data, which has 785# Under "object type" we understand just some set of data, which has
@@ -693,10 +788,12 @@ class JsVisitor(Visitor):
693 788
694class PyVisitor(Visitor): 789class PyVisitor(Visitor):
695 790
696 def __init__(self): 791 def __init__(self, _module_name):
697 # PyVisitor generates 2 types of files: pxi and pxd 792 # PyVisitor generates 2 types of files: pxi and pxd
698 # head, ev, funcs_parsed - are hooks for different parts of source code 793 # head, ev, funcs_parsed - are hooks for different parts of source code
699 794
795 self.py_module_name = _module_name
796
700 self.visited_properties = [] 797 self.visited_properties = []
701 798
702 self.pxi = Abstract() 799 self.pxi = Abstract()
@@ -705,18 +802,25 @@ class PyVisitor(Visitor):
705 self.pxi.ev = [] 802 self.pxi.ev = []
706 self.pxi.funcs_parsed = [] 803 self.pxi.funcs_parsed = []
707 804
708 805 """
709 self.pxd = Abstract() 806 self.pxd = Abstract()
710 self.pxd.name = "" 807 self.pxd.name = ""
711 self.pxd.head = [] 808 self.pxd.head = []
712 self.pxd.ev = [] 809 self.pxd.ev = []
810 """
811
812 self.pxd2 = Abstract()
813 self.pxd2.name = ""
814 self.pxd2.head = []
815 self.pxd2.ev = []
713 816
714 self._funcs = {"instance_set2" : "_eo_instance_set2", 817 self._funcs = {"instance_set2" : "_eo_instance_set2",
715 "instance_get" : "_eo_instance_get", 818 "instance_get" : "_eo_instance_get",
716 "do" : "eo_do"} 819 "do" : "eo_do"}
717 820
718 self.basemodule = {"macro" : "EO_DEFAULT_CLASS", 821 self.eodefault = {"macro" : "EO_DEFAULT_CLASS",
719 "module" : "eodefault", 822 "module" : "eodefault",
823 "prefix" : const.PREFIX,
720 "name": "EoDefault", 824 "name": "EoDefault",
721 "parentmodule": "NULL", 825 "parentmodule": "NULL",
722 "type" :"EO_CLASS_TYPE_REGULAR_NO_INSTANCE", 826 "type" :"EO_CLASS_TYPE_REGULAR_NO_INSTANCE",
@@ -739,13 +843,13 @@ class PyVisitor(Visitor):
739 def visit_Func(self, _o): 843 def visit_Func(self, _o):
740# print "func Func: ", _o.name, _o.op_id, _o.c_macro, _o.parameters 844# print "func Func: ", _o.name, _o.op_id, _o.c_macro, _o.parameters
741 eo_base_ops = ["EO_BASE_SUB_ID_EVENT_FREEZE", "EO_BASE_SUB_ID_EVENT_FREEZE_GET", \ 845 eo_base_ops = ["EO_BASE_SUB_ID_EVENT_FREEZE", "EO_BASE_SUB_ID_EVENT_FREEZE_GET", \
742 "EO_BASE_SUB_ID_EVENT_THAW", "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE", 846 "EO_BASE_SUB_ID_EVENT_THAW", "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE",
743 "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET",\ 847 "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET",\
744 "EO_BASE_SUB_ID_EVENT_GLOBAL_THAW", "EO_BASE_SUB_ID_DATA_SET", \ 848 "EO_BASE_SUB_ID_EVENT_GLOBAL_THAW", "EO_BASE_SUB_ID_DATA_SET", \
745 "EO_BASE_SUB_ID_DATA_GET", "EO_BASE_SUB_ID_DATA_DEL", \ 849 "EO_BASE_SUB_ID_DATA_GET", "EO_BASE_SUB_ID_DATA_DEL", \
746 "EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD", 850 "EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD",
747 "EO_BASE_SUB_ID_EVENT_CALLBACK_DEL", \ 851 "EO_BASE_SUB_ID_EVENT_CALLBACK_DEL", \
748 "EO_BASE_SUB_ID_EVENT_CALLBACK_CALL"] 852 "EO_BASE_SUB_ID_EVENT_CALLBACK_CALL"]
749 853
750 in_params = [] 854 in_params = []
751 pass_params =[] 855 pass_params =[]
@@ -760,9 +864,10 @@ class PyVisitor(Visitor):
760 return 864 return
761 if _o.op_id == "EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD": 865 if _o.op_id == "EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD":
762 function_lines.append("def event_callback_priority_add(self, long _desc, int _priority, object _cb):") 866 function_lines.append("def event_callback_priority_add(self, long _desc, int _priority, object _cb):")
763 function_lines.append(" if not callable(_cb):") 867 function_lines.append(" if not callable(_cb[0]):")
764 function_lines.append(" raise TypeError(\"func must be callable\")") 868 function_lines.append(" raise TypeError(\"func must be callable\")")
765 function_lines.append(" cdef Eo_Event_Cb cb = <Eo_Event_Cb> eodefault._object_callback") 869 function_lines.append(" cdef Eo_Event_Cb cb = <Eo_Event_Cb> eodefault._object_callback")
870 function_lines.append(" Py_INCREF(_cb)")
766 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD), _desc, _priority, cb, <void*>_cb)") 871 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD), _desc, _priority, cb, <void*>_cb)")
767 if_ret = True 872 if_ret = True
768 873
@@ -770,6 +875,7 @@ class PyVisitor(Visitor):
770 function_lines.append("def event_callback_del(self, long _desc, object _func):") 875 function_lines.append("def event_callback_del(self, long _desc, object _func):")
771 function_lines.append(" cdef Eo_Event_Cb func = <Eo_Event_Cb> eodefault._object_callback") 876 function_lines.append(" cdef Eo_Event_Cb func = <Eo_Event_Cb> eodefault._object_callback")
772 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_EVENT_CALLBACK_DEL), _desc, func, <void*>_func)") 877 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_EVENT_CALLBACK_DEL), _desc, func, <void*>_func)")
878 function_lines.append(" Py_DECREF(_func)")
773 879
774 function_lines.append("\n") 880 function_lines.append("\n")
775 if_ret = True 881 if_ret = True
@@ -786,6 +892,13 @@ class PyVisitor(Visitor):
786 function_lines.append(" _key = pytext_to_utf8(_key)") 892 function_lines.append(" _key = pytext_to_utf8(_key)")
787 function_lines.append(" cdef char* key = <char*> _key") 893 function_lines.append(" cdef char* key = <char*> _key")
788 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_DATA_SET), key, <void*>_data, NULL)") 894 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_DATA_SET), key, <void*>_data, NULL)")
895
896 function_lines.append("")
897 function_lines.append("def _data_set(self, object _key, object _data):")
898 function_lines.append(" _key = pytext_to_utf8(_key)")
899 function_lines.append(" cdef char* key = <char*> _key")
900 function_lines.append(" eodefault.eo_do(eodefault._eo_instance_get(self), eobase_sub_id(eobase.EO_BASE_SUB_ID_DATA_SET), key, <void*>_data, NULL)")
901
789 if_ret = True 902 if_ret = True
790 903
791 elif _o.op_id == "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE": 904 elif _o.op_id == "EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE":
@@ -812,13 +925,13 @@ class PyVisitor(Visitor):
812 925
813 if if_ret: 926 if if_ret:
814 function_lines.append("\n") 927 function_lines.append("\n")
815 self.pxi["funcs_parsed"] += function_lines 928 self.pxi.funcs_parsed += function_lines
816 return 929 return
817 930
818 931
819 if True:#"parameters" in fparams: 932 if True:#"parameters" in fparams:
820 933
821 for i, (n, c_t, d, p_t) in enumerate(_o.parameters): 934 for i, (n, modifier, c_t, d, p_t) in enumerate(_o.parameters):
822 c_t_tmp = self.cast(p_t) 935 c_t_tmp = self.cast(p_t)
823 936
824 py_type = "" 937 py_type = ""
@@ -828,22 +941,26 @@ class PyVisitor(Visitor):
828 c_t_internal = self.internal_types[c_t_tmp][0] 941 c_t_internal = self.internal_types[c_t_tmp][0]
829 py_type = self.internal_types[c_t_tmp][1] 942 py_type = self.internal_types[c_t_tmp][1]
830 else: 943 else:
831 print "Warning: type: \"%s\" wasn't found in self.internal_types. Function \"%s\" will not be defined"%(c_t_tmp, _o.name) 944 print "Warning: type: \"%s\" wasn't found in self.internal_types.\n Function \"%s\" from class: \"%s\" will not be defined"%(c_t_tmp, _o.name, _o.cl_obj.c_name)
832 return 945 return
833 946
834 if d == "in": 947 if d == "in":
835 in_params.append(py_type + ' _' + n) 948 in_params.append(py_type + ' _' + n)
836 if c_t_internal == "Eo*": 949 if c_t_internal == "Eo*":
837 l = " cdef %s %s = <%s> _%s"%(c_t_internal, n, c_t_internal, n + ".eo") 950 l = " cdef %s %s = NULL if _%s is None else <%s> _%s"%(c_t_internal, n, n, c_t_internal, n + ".eo")
951 function_lines.append(l)
838 elif c_t_internal == "Eo_Event_Cb": 952 elif c_t_internal == "Eo_Event_Cb":
839 l = " cdef %s %s = <%s> %s"%(c_t_internal, n, c_t_internal, "eodefault._object_callback") 953 l = " cdef %s %s = <%s> %s"%(c_t_internal, n, c_t_internal, "eodefault._object_callback")
954 function_lines.append(l)
840 else: 955 else:
841 if c_t_internal == "char*" : 956 if c_t_internal == "char*" :
842 l = " _%s = pytext_to_utf8(_%s)"%(n, n) 957 l = " _%s = None if _%s is None else pytext_to_utf8(_%s)"%(n, n, n)
958 function_lines.append(l)
959 l = " cdef %s %s = NULL if _%s is None else <%s> _%s"%(c_t_internal, n, n, c_t_internal, n)
960 function_lines.append(l)
961 else:
962 l = " cdef %s %s = <%s> _%s"%(c_t_internal, n, c_t_internal, n)
843 function_lines.append(l) 963 function_lines.append(l)
844 l = " cdef %s %s = <%s> _%s"%(c_t_internal, n, c_t_internal, n)
845 function_lines.append(l)
846
847 964
848 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*": 965 if c_t.find(c_t_internal) != -1 and c_t.replace(c_t_internal, "") == "*":
849 pass_params.append('&' + n) 966 pass_params.append('&' + n)
@@ -860,7 +977,7 @@ class PyVisitor(Visitor):
860 in_params.append('_' + n) 977 in_params.append('_' + n)
861 pass_params.append('&' + n) 978 pass_params.append('&' + n)
862 if c_t_internal == "Eo*": 979 if c_t_internal == "Eo*":
863 l = " cdef %s %s = <%s> _%s"%(c_t_internal, n, c_t_internal, n + ".eo") 980 l = " cdef %s %s = NULL if _%s is None else <%s> _%s"%(c_t_internal, n, n, c_t_internal, n + ".eo")
864 else: 981 else:
865 l = " cdef %s %s = <%s> _%s"%(c_t_internal, n, c_t_internal, n) 982 l = " cdef %s %s = <%s> _%s"%(c_t_internal, n, c_t_internal, n)
866 ret_params.append((n + '_', c_t_internal)) 983 ret_params.append((n + '_', c_t_internal))
@@ -905,7 +1022,6 @@ class PyVisitor(Visitor):
905 function_lines.append("") 1022 function_lines.append("")
906 self.pxi.funcs_parsed += function_lines 1023 self.pxi.funcs_parsed += function_lines
907 1024
908
909 #generating __init_function, and all header data for files 1025 #generating __init_function, and all header data for files
910 def visit_Init(self, _o): 1026 def visit_Init(self, _o):
911 cl_obj = _o.cl_obj 1027 cl_obj = _o.cl_obj
@@ -930,29 +1046,34 @@ class PyVisitor(Visitor):
930 function_lines.append(l) 1046 function_lines.append(l)
931 l = " self.%s(klass, parent)"%self._funcs["instance_set2"] 1047 l = " self.%s(klass, parent)"%self._funcs["instance_set2"]
932 function_lines.append(l) 1048 function_lines.append(l)
933 l = " self.data_set(EoDefault.PY_EO_NAME, self)" 1049# l = " self.data_set(EoDefault.PY_EO_NAME, self)"
934 function_lines.append(l) 1050# function_lines.append(l)
935 function_lines.append("") 1051 function_lines.append("")
936 1052
937 function_lines.append("") 1053 function_lines.append("")
938 1054
939 self.pxi.funcs_parsed += function_lines 1055 self.pxi.funcs_parsed += function_lines
940 1056
941
942 self.pxi.name = cl_obj.mod_name + ".pxi" 1057 self.pxi.name = cl_obj.mod_name + ".pxi"
943 self.pxd.name = cl_obj.mod_name + ".pxd" 1058 self.pxd2.name = cl_obj.mod_name + ".pxd"
944 1059
945 pattern = "########################################################" 1060 pattern = "########################################################"
946 l = '%s\n##\n## generated from from \"%s\"\n##\n%s'%(pattern, cl_obj.source_file, pattern) 1061 l = '%s\n##\n## generated from from \"%s\"\n##\n%s'%(pattern, cl_obj.source_file, pattern)
947 self.pxi.head.append(l + '\n') 1062 self.pxi.head.append(l + '\n')
948 self.pxd.head.append(l + '\n') 1063 #REMOVEself.pxd.head.append(l + '\n')
949
950 1064
951 #inserting cimports 1065 #inserting cimports
952 l = "cimport %s"%cl_obj.mod_name 1066 #l = "cimport %s"%cl_obj.mod_name
1067
1068 #now we have one pxd for all extern definitions
1069 #so we cimport it with preper name
1070 #proper name only for nice
1071
1072 l = "cimport %s as %s"%(self.py_module_name, cl_obj.mod_name)
953 self.pxi.head.append(l) 1073 self.pxi.head.append(l)
954 l = "cimport %s"%cl_obj.basemodule 1074
955 self.pxi.head.append(l + '\n') 1075 #l = "cimport %s"%cl_obj.basemodule
1076 #self.pxi.head.append(l + '\n')
956 1077
957 #defining class 1078 #defining class
958 parents = [] 1079 parents = []
@@ -961,15 +1082,36 @@ class PyVisitor(Visitor):
961 1082
962 if cl_obj.kl_id == "EoBase": 1083 if cl_obj.kl_id == "EoBase":
963 parents = [] 1084 parents = []
964 parents.append(self.basemodule["name"]) 1085 parents.append(self.eodefault["name"])
965 l = "from %s import %s"%(self.basemodule["module"], self.basemodule["name"]) 1086 l = "from %s import %s"%(self.eodefault["module"], self.eodefault["name"])
1087 self.pxi.head.append(l + "\n")
1088 l = "from cpython cimport Py_INCREF, Py_DECREF"
966 self.pxi.head.append(l + "\n") 1089 self.pxi.head.append(l + "\n")
967 1090
968 if "EoBase" in parents: 1091 if "EoBase" in parents:
969 l = "from %s import %s"%("eobase", "EoBase") 1092 l = "from %s.%s import %s"%(self.eodefault["prefix"], "eobase", "EoBase")
970 self.pxi.head.append(l + "\n") 1093 self.pxi.head.append(l + "\n")
971 1094
972 l = "from %s import %s"%(self.basemodule["module"], "pytext_to_utf8") 1095 for p in parents:
1096 #if we have some parent obj to incl, t.e. it is not in the tree
1097 if p in cl_obj.objects_incl:
1098 path = cl_obj.objects_incl[p].path
1099 sys_path = list(sys.path)
1100 sys_path.sort(key = len, reverse = True)
1101 #this parent should be in search path
1102 for pth in sys_path:
1103 if pth in path:
1104 (d, n) = os.path.split(path)
1105 prefix = d.replace(pth, "").replace("/", ".").lstrip(".")
1106
1107 #FIXME
1108 #now prefix is like dir1.dir2
1109 #so we can make from dir1.dir2.mod_name import ParentClass
1110 # but I don't know mod_name, t.e. *.so!
1111
1112
1113
1114 l = "from %s.%s import %s"%(self.eodefault["prefix"], self.eodefault["module"], "pytext_to_utf8")
973 self.pxi.head.append(l + "\n") 1115 self.pxi.head.append(l + "\n")
974 1116
975 #defining _id function 1117 #defining _id function
@@ -982,21 +1124,22 @@ class PyVisitor(Visitor):
982 #defining class 1124 #defining class
983 parents = ','.join(parents) 1125 parents = ','.join(parents)
984 l = 'class %s(%s):'%(cl_obj.kl_id, parents) 1126 l = 'class %s(%s):'%(cl_obj.kl_id, parents)
985
986 self.pxi.head.append(l) 1127 self.pxi.head.append(l)
987 1128
988 #inserting cimports 1129 #inserting cimports
989 l = "from %s cimport *"%(cl_obj.basemodule) 1130 #REMOVEl = "from %s cimport *"%(cl_obj.basemodule)
990 self.pxd.head.append(l + '\n') 1131 #REMOVEself.pxd.head.append(l + '\n')
991 1132
992 #inserting externs from H 1133 #inserting externs from H
993 l = "cdef extern from \"%s\":"%(cl_obj.includes[0]) 1134 l = "cdef extern from \"%s\":"%(cl_obj.includes[0])
994 self.pxd.head.append(l + '\n') 1135 #REMOVEself.pxd.head.append(l + '\n')
1136 self.pxd2.head.append(l + '\n')
995 1137
996 1138
997 if cl_obj.extern_base_id != "": 1139 if cl_obj.extern_base_id != "":
998 l = ' %s %s'%("Eo_Op", cl_obj.extern_base_id) 1140 l = ' %s %s'%("Eo_Op", cl_obj.extern_base_id)
999 self.pxd.head.append(l + '\n') 1141 #REMOVEself.pxd.head.append(l + '\n')
1142 self.pxd2.head.append(l + '\n')
1000 1143
1001 enum_lines = []