aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-03-01 15:51:59 +0100
committerDave Andreoli <dave@gurumeditation.it>2018-03-01 15:51:59 +0100
commit0a51dbf2ff20dbff7669a75704389e0a92d9b187 (patch)
treee648feb26aa78e53fa8d0b2907c7eecd2b3c0cd6
parentefl file interface - fix reyturn if no file set to return a null file (diff)
downloadefl-0a51dbf2ff20dbff7669a75704389e0a92d9b187.tar.gz
Pyolian: new APIs for class retrieval
Also updated tests, generator and gendoc accordly
-rwxr-xr-xsrc/scripts/gendoc/gendoc.py2
-rw-r--r--src/scripts/pyolian/eolian.py38
-rw-r--r--src/scripts/pyolian/eolian_lib.py28
-rwxr-xr-xsrc/scripts/pyolian/generator.py2
-rwxr-xr-xsrc/scripts/pyolian/test_eolian.py30
5 files changed, 58 insertions, 42 deletions
diff --git a/src/scripts/gendoc/gendoc.py b/src/scripts/gendoc/gendoc.py
index 210450df96..1c8effffc1 100755
--- a/src/scripts/gendoc/gendoc.py
+++ b/src/scripts/gendoc/gendoc.py
@@ -131,7 +131,7 @@ if args.step in ('start', None):
# render a page for each Class
if args.step in ('classes', None):
t = Template('doc_class.template')
- for cls in eolian_db.all_classes:
+ for cls in eolian_db.classes:
if cls.full_name.startswith(args.namespace):
output_file = page_path_for_object(cls)
t.render(output_file, args.verbose, cls=cls.full_name)
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index 0243a7f1bb..0ce750fb05 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -341,23 +341,19 @@ class Eolian_Unit(EolianBaseObject):
def file(self):
return _str_to_py(lib.eolian_unit_file_get(self._obj))
- def class_get_by_name(self, class_name):
- c_cls = lib.eolian_class_get_by_name(self._obj, _str_to_bytes(class_name))
- return Class(c_cls) if c_cls else None
+ @property
+ def classes(self):
+ return Iterator(Class, lib.eolian_unit_classes_get(self._obj))
- def class_get_by_file(self, file_name):
- c_cls = lib.eolian_class_get_by_file(self._obj, _str_to_bytes(file_name))
+ def class_by_name_get(self, class_name):
+ c_cls = lib.eolian_unit_class_by_name_get(self._obj, _str_to_bytes(class_name))
return Class(c_cls) if c_cls else None
@property
- def all_classes(self):
- return Iterator(Class, lib.eolian_all_classes_get(self._obj))
-
- @property
def all_namespaces(self):
# TODO find a better way to find namespaces (maybe inside eolian?)
nspaces = set()
- for obj in self.all_classes:
+ for obj in self.classes:
nspaces.add(Namespace(self, obj.namespace))
for obj in self.typedecl_all_aliases:
nspaces.add(Namespace(self, obj.namespace))
@@ -491,6 +487,18 @@ class Eolian_State(Eolian_Unit):
def units(self):
return Iterator(Eolian_Unit, lib.eolian_state_units_get(self._obj))
+ @property
+ def classes(self):
+ return Iterator(Class, lib.eolian_state_classes_get(self._obj))
+
+ def class_by_name_get(self, class_name):
+ c_cls = lib.eolian_state_class_by_name_get(self._obj, _str_to_bytes(class_name))
+ return Class(c_cls) if c_cls else None
+
+ def class_by_file_get(self, file_name):
+ c_cls = lib.eolian_state_class_by_file_get(self._obj, _str_to_bytes(file_name))
+ return Class(c_cls) if c_cls else None
+
### Namespace Utility Class #################################################
@@ -536,30 +544,30 @@ class Namespace(object):
@property
def classes(self):
- return sorted([ c for c in self._unit.all_classes
+ return sorted([ c for c in self._unit.classes
if c.namespace == self._name ])
@property
def regulars(self):
- return sorted([ c for c in self._unit.all_classes
+ return sorted([ c for c in self._unit.classes
if c.type == Eolian_Class_Type.REGULAR and
c.namespace == self._name])
@property
def abstracts(self):
- return sorted([ c for c in self._unit.all_classes
+ return sorted([ c for c in self._unit.classes
if c.type == Eolian_Class_Type.ABSTRACT and
c.namespace == self._name])
@property
def mixins(self):
- return sorted([ c for c in self._unit.all_classes
+ return sorted([ c for c in self._unit.classes
if c.type == Eolian_Class_Type.MIXIN and
c.namespace == self._name])
@property
def interfaces(self):
- return sorted([ c for c in self._unit.all_classes
+ return sorted([ c for c in self._unit.classes
if c.type == Eolian_Class_Type.INTERFACE and
c.namespace == self._name])
diff --git a/src/scripts/pyolian/eolian_lib.py b/src/scripts/pyolian/eolian_lib.py
index e86929e773..afd747384a 100644
--- a/src/scripts/pyolian/eolian_lib.py
+++ b/src/scripts/pyolian/eolian_lib.py
@@ -93,6 +93,18 @@ lib.eolian_state_unit_by_file_get.restype = c_void_p
lib.eolian_state_units_get.argtypes = [c_void_p,]
lib.eolian_state_units_get.restype = c_void_p
+# EAPI const Eolian_Class *eolian_state_class_by_name_get(const Eolian_State *state, const char *class_name);
+lib.eolian_state_class_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_class_by_name_get.restype = c_void_p
+
+# EAPI const Eolian_Class *eolian_state_class_by_file_get(const Eolian_State *state, const char *file_name);
+lib.eolian_state_class_by_file_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_class_by_file_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_classes_get(const Eolian_State *state);
+lib.eolian_state_classes_get.argtypes = [c_void_p,]
+lib.eolian_state_classes_get.restype = c_void_p
+
# EAPI Eina_Iterator *eolian_declarations_get_by_file(const Eolian_State *state, const char *fname);
lib.eolian_declarations_get_by_file.argtypes = [c_void_p, c_char_p]
lib.eolian_declarations_get_by_file.restype = c_void_p
@@ -107,17 +119,13 @@ lib.eolian_unit_children_get.restype = c_void_p
lib.eolian_unit_file_get.argtypes = [c_void_p,]
lib.eolian_unit_file_get.restype = c_char_p
-# EAPI const Eolian_Class *eolian_class_get_by_name(const Eolian_Unit *unit, const char *class_name);
-lib.eolian_class_get_by_name.argtypes = [c_void_p, c_char_p]
-lib.eolian_class_get_by_name.restype = c_void_p
-
-# EAPI const Eolian_Class *eolian_class_get_by_file(const Eolian_Unit *unit, const char *file_name);
-lib.eolian_class_get_by_file.argtypes = [c_void_p, c_char_p]
-lib.eolian_class_get_by_file.restype = c_void_p
+# EAPI const Eolian_Class *eolian_unit_class_by_name_get(const Eolian_Unit *unit, const char *class_name);
+lib.eolian_unit_class_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_unit_class_by_name_get.restype = c_void_p
-# EAPI Eina_Iterator *eolian_all_classes_get(const Eolian_Unit *unit);
-lib.eolian_all_classes_get.argtypes = [c_void_p,]
-lib.eolian_all_classes_get.restype = c_void_p
+# EAPI Eina_Iterator *eolian_unit_classes_get(const Eolian_Unit *unit);
+lib.eolian_unit_classes_get.argtypes = [c_void_p,]
+lib.eolian_unit_classes_get.restype = c_void_p
# EAPI const Eolian_Typedecl *eolian_typedecl_alias_get_by_name(const Eolian_Unit *unit, const char *name);
lib.eolian_typedecl_alias_get_by_name.argtypes = [c_void_p, c_char_p]
diff --git a/src/scripts/pyolian/generator.py b/src/scripts/pyolian/generator.py
index 9577fa7488..fb8b3e3d10 100755
--- a/src/scripts/pyolian/generator.py
+++ b/src/scripts/pyolian/generator.py
@@ -163,7 +163,7 @@ class Template(pyratemp.Template):
if kargs:
ctx.update(kargs)
if cls:
- ctx['cls'] = eolian_db.class_get_by_name(cls)
+ ctx['cls'] = eolian_db.class_by_name_get(cls)
if ns:
ctx['namespace'] = eolian_db.namespace_get_by_name(ns)
if struct:
diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py
index b53ae26caf..25615993df 100755
--- a/src/scripts/pyolian/test_eolian.py
+++ b/src/scripts/pyolian/test_eolian.py
@@ -25,8 +25,8 @@ eolian_db = None
class TestBaseObject(unittest.TestCase):
def test_base_object_equality(self):
- cls1 = eolian_db.class_get_by_name('Efl.Loop.Timer')
- cls2 = eolian_db.class_get_by_file('efl_loop_timer.eo')
+ cls1 = eolian_db.class_by_name_get('Efl.Loop.Timer')
+ cls2 = eolian_db.class_by_file_get('efl_loop_timer.eo')
self.assertIsInstance(cls1, eolian.Class)
self.assertIsInstance(cls2, eolian.Class)
self.assertEqual(cls1, cls2)
@@ -166,7 +166,7 @@ class TestEolianUnit(unittest.TestCase):
def test_class_listing(self):
all_count = 0
- for cls in eolian_db.all_classes:
+ for cls in eolian_db.classes:
self.assertIsInstance(cls, eolian.Class)
all_count += 1
self.assertGreater(all_count, 400)
@@ -239,10 +239,10 @@ class TestEolianNamespace(unittest.TestCase):
class TestEolianClass(unittest.TestCase):
def test_class(self):
- cls = eolian_db.class_get_by_file('efl_loop_timer.eo')
+ cls = eolian_db.class_by_file_get('efl_loop_timer.eo')
self.assertIsInstance(cls, eolian.Class)
- cls = eolian_db.class_get_by_name('Efl.Loop.Timer')
+ cls = eolian_db.class_by_name_get('Efl.Loop.Timer')
self.assertIsInstance(cls, eolian.Class)
self.assertEqual(cls.name, 'Timer')
@@ -272,7 +272,7 @@ class TestEolianClass(unittest.TestCase):
class TestEolianFunction(unittest.TestCase):
def test_function(self):
- cls = eolian_db.class_get_by_name('Efl.Loop.Timer')
+ cls = eolian_db.class_by_name_get('Efl.Loop.Timer')
f = cls.function_get_by_name('delay')
self.assertIsInstance(f, eolian.Function)
self.assertEqual(f.name, 'delay')
@@ -303,7 +303,7 @@ class TestEolianFunction(unittest.TestCase):
self.assertIsInstance(f.implement, eolian.Implement)
def test_function_parameter(self):
- cls = eolian_db.class_get_by_name('Efl.Loop.Timer')
+ cls = eolian_db.class_by_name_get('Efl.Loop.Timer')
f = cls.function_get_by_name('delay')
p = list(f.parameters)[0]
self.assertEqual(p.direction, eolian.Eolian_Parameter_Dir.IN)
@@ -318,7 +318,7 @@ class TestEolianFunction(unittest.TestCase):
class TestEolianImplement(unittest.TestCase):
def test_implement(self):
- cls = eolian_db.class_get_by_name('Efl.Loop.Timer')
+ cls = eolian_db.class_by_name_get('Efl.Loop.Timer')
f = cls.function_get_by_name('delay')
im = f.implement
self.assertIsInstance(im, eolian.Implement)
@@ -337,7 +337,7 @@ class TestEolianImplement(unittest.TestCase):
class TestEolianEvent(unittest.TestCase):
def test_event(self):
- cls = eolian_db.class_get_by_name('Efl.Loop.Timer')
+ cls = eolian_db.class_by_name_get('Efl.Loop.Timer')
self.assertEqual([e.name for e in cls.events], ['tick'])
ev = cls.event_get_by_name('tick')
self.assertIsInstance(ev, eolian.Event)
@@ -353,7 +353,7 @@ class TestEolianEvent(unittest.TestCase):
class TestEolianPart(unittest.TestCase):
def test_part(self):
- cls = eolian_db.class_get_by_name('Efl.Ui.Popup')
+ cls = eolian_db.class_by_name_get('Efl.Ui.Popup')
parts = list(cls.parts)
self.assertGreater(len(parts), 0)
@@ -366,7 +366,7 @@ class TestEolianPart(unittest.TestCase):
class TestEolianConstructor(unittest.TestCase):
def test_constructor(self):
- cls = eolian_db.class_get_by_name('Efl.Ui.Win')
+ cls = eolian_db.class_by_name_get('Efl.Ui.Win')
ctors = list(cls.constructors)
self.assertGreater(len(ctors), 0)
ctor = ctors[0]
@@ -381,7 +381,7 @@ class TestEolianConstructor(unittest.TestCase):
class TestEolianDocumentation(unittest.TestCase):
def test_documentation(self):
- td = eolian_db.class_get_by_name('Efl.Net.Control')
+ td = eolian_db.class_by_name_get('Efl.Net.Control')
doc = td.documentation
self.assertIsInstance(doc, eolian.Documentation)
self.assertIsInstance(doc.summary, str)
@@ -481,7 +481,7 @@ class TestEolianTypedecl(unittest.TestCase):
class TestEolianType(unittest.TestCase):
def test_type_regular_builtin(self):
- cls = eolian_db.class_get_by_name('Efl.Loop.Timer')
+ cls = eolian_db.class_by_name_get('Efl.Loop.Timer')
func = cls.function_get_by_name('delay')
param = list(func.parameters)[0]
t = param.type # type: double
@@ -506,7 +506,7 @@ class TestEolianType(unittest.TestCase):
self.assertEqual(t.c_type_return, 'double')
def test_type_regular(self):
- cls = eolian_db.class_get_by_name('Efl.Gfx')
+ cls = eolian_db.class_by_name_get('Efl.Gfx')
func = cls.function_get_by_name('geometry')
param = list(func.setter_values)[0]
t = param.type # type: Eina.Rect
@@ -530,7 +530,7 @@ class TestEolianType(unittest.TestCase):
self.assertEqual(td.full_name, 'Eina.Rect')
def test_type_class(self):
- cls = eolian_db.class_get_by_name('Efl.Content')
+ cls = eolian_db.class_by_name_get('Efl.Content')
func = cls.function_get_by_name('content')
param = list(func.setter_values)[0]
t = param.type # type: Efl.Gfx (class interface)