aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-03-01 17:08:56 +0100
committerDave Andreoli <dave@gurumeditation.it>2018-03-01 17:08:56 +0100
commit939cb26bd9152dfcea69f742caa343ab254a1986 (patch)
tree8fb09fee580c07cf101f00e2d2c2210abcbb68d2
parentPyolian: new variable lookup APIs (diff)
downloadefl-939cb26bd9152dfcea69f742caa343ab254a1986.tar.gz
Pyolian: new APIs for typedecl lookups
-rwxr-xr-xsrc/scripts/gendoc/gendoc.py6
-rw-r--r--src/scripts/pyolian/eolian.py108
-rw-r--r--src/scripts/pyolian/eolian_lib.py84
-rwxr-xr-xsrc/scripts/pyolian/generator.py6
-rwxr-xr-xsrc/scripts/pyolian/test_eolian.py28
5 files changed, 140 insertions, 92 deletions
diff --git a/src/scripts/gendoc/gendoc.py b/src/scripts/gendoc/gendoc.py
index 1c8effffc1..8fec32cc13 100755
--- a/src/scripts/gendoc/gendoc.py
+++ b/src/scripts/gendoc/gendoc.py
@@ -139,7 +139,7 @@ if args.step in ('classes', None):
# render a page for each Enum
if args.step in ('enums', None):
t = Template('doc_enum.template')
- for enum in eolian_db.typedecl_all_enums:
+ for enum in eolian_db.enums:
if enum.full_name.startswith(args.namespace):
output_file = page_path_for_object(enum)
t.render(output_file, args.verbose, enum=enum.full_name)
@@ -147,7 +147,7 @@ if args.step in ('enums', None):
# render a page for each Struct
if args.step in ('structs', None):
t = Template('doc_struct.template')
- for struct in eolian_db.typedecl_all_structs:
+ for struct in eolian_db.structs:
if struct.full_name.startswith(args.namespace):
output_file = page_path_for_object(struct)
t.render(output_file, args.verbose, struct=struct.full_name)
@@ -155,7 +155,7 @@ if args.step in ('structs', None):
# render a page for each Alias
if args.step in ('aliases', None):
t = Template('doc_alias.template')
- for alias in eolian_db.typedecl_all_aliases:
+ for alias in eolian_db.aliases:
if alias.full_name.startswith(args.namespace):
output_file = page_path_for_object(alias)
t.render(output_file, args.verbose, alias=alias.full_name)
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index d181a0fc60..55f4fea971 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -365,59 +365,47 @@ class Eolian_Unit(EolianBaseObject):
c_var = lib.eolian_unit_global_by_name_get(self._obj, _str_to_bytes(name))
return Variable(c_var) if c_var else None
-
@property
- def all_namespaces(self):
- # TODO find a better way to find namespaces (maybe inside eolian?)
- nspaces = set()
- for obj in self.classes:
- nspaces.add(Namespace(self, obj.namespace))
- for obj in self.typedecl_all_aliases:
- nspaces.add(Namespace(self, obj.namespace))
- for obj in self.typedecl_all_structs:
- nspaces.add(Namespace(self, obj.namespace))
- for obj in self.typedecl_all_enums:
- nspaces.add(Namespace(self, obj.namespace))
- return sorted(nspaces)
+ def enums(self):
+ return Iterator(Typedecl, lib.eolian_unit_enums_get(self._obj))
- def namespace_get_by_name(self, name):
- return Namespace(self, name)
+ def enum_by_name_get(self, name):
+ c_tdecl = lib.eolian_unit_enum_by_name_get(self._obj, _str_to_bytes(name))
+ return Typedecl(c_tdecl) if c_tdecl else None
@property
- def typedecl_all_enums(self):
- return Iterator(Typedecl, lib.eolian_typedecl_all_enums_get(self._obj))
+ def structs(self):
+ return Iterator(Typedecl, lib.eolian_unit_structs_get(self._obj))
- def typedecl_enum_get_by_name(self, name):
- c_tdecl = lib.eolian_typedecl_enum_get_by_name(self._obj, _str_to_bytes(name))
+ def struct_by_name_get(self, name):
+ c_tdecl = lib.eolian_unit_struct_by_name_get(self._obj, _str_to_bytes(name))
return Typedecl(c_tdecl) if c_tdecl else None
- def typedecl_enums_get_by_file(self, fname):
- return Iterator(Typedecl,
- lib.eolian_typedecl_enums_get_by_file(self._obj, _str_to_bytes(fname)))
-
@property
- def typedecl_all_structs(self):
- return Iterator(Typedecl, lib.eolian_typedecl_all_structs_get(self._obj))
+ def aliases(self):
+ return Iterator(Typedecl, lib.eolian_unit_aliases_get(self._obj))
- def typedecl_struct_get_by_name(self, name):
- c_tdecl = lib.eolian_typedecl_struct_get_by_name(self._obj, _str_to_bytes(name))
+ def alias_by_name_get(self, name):
+ c_tdecl = lib.eolian_unit_alias_by_name_get(self._obj, _str_to_bytes(name))
return Typedecl(c_tdecl) if c_tdecl else None
- def typedecl_structs_get_by_file(self, fname):
- return Iterator(Typedecl,
- lib.eolian_typedecl_structs_get_by_file(self._obj, _str_to_bytes(fname)))
@property
- def typedecl_all_aliases(self):
- return Iterator(Typedecl, lib.eolian_typedecl_all_aliases_get(self._obj))
-
- def typedecl_alias_get_by_name(self, name):
- c_tdecl = lib.eolian_typedecl_alias_get_by_name(self._obj, _str_to_bytes(name))
- return Typedecl(c_tdecl) if c_tdecl else None
+ def all_namespaces(self):
+ # TODO find a better way to find namespaces (maybe inside eolian?)
+ nspaces = set()
+ for obj in self.classes:
+ nspaces.add(Namespace(self, obj.namespace))
+ for obj in self.aliases:
+ nspaces.add(Namespace(self, obj.namespace))
+ for obj in self.structs:
+ nspaces.add(Namespace(self, obj.namespace))
+ for obj in self.enums:
+ nspaces.add(Namespace(self, obj.namespace))
+ return sorted(nspaces)
- def typedecl_aliases_get_by_file(self, fname):
- return Iterator(Typedecl,
- lib.eolian_typedecl_aliases_get_by_file(self._obj, _str_to_bytes(fname)))
+ def namespace_get_by_name(self, name):
+ return Namespace(self, name)
@property
def all_declarations(self):
@@ -516,6 +504,42 @@ class Eolian_State(Eolian_Unit):
return Iterator(Variable,
lib.eolian_state_globals_by_file_get(self._obj, _str_to_bytes(file_name)))
+ @property
+ def aliases(self):
+ return Iterator(Typedecl, lib.eolian_state_aliases_get(self._obj))
+
+ def alias_by_name_get(self, name):
+ c_tdecl = lib.eolian_state_alias_by_name_get(self._obj, _str_to_bytes(name))
+ return Typedecl(c_tdecl) if c_tdecl else None
+
+ def aliases_by_file_get(self, file_name):
+ return Iterator(Typedecl,
+ lib.eolian_state_aliases_by_file_get(self._obj, _str_to_bytes(file_name)))
+
+ @property
+ def structs(self):
+ return Iterator(Typedecl, lib.eolian_state_structs_get(self._obj))
+
+ def struct_by_name_get(self, name):
+ c_tdecl = lib.eolian_state_struct_by_name_get(self._obj, _str_to_bytes(name))
+ return Typedecl(c_tdecl) if c_tdecl else None
+
+ def structs_by_file_get(self, file_name):
+ return Iterator(Typedecl,
+ lib.eolian_state_structs_by_file_get(self._obj, _str_to_bytes(file_name)))
+
+ @property
+ def enums(self):
+ return Iterator(Typedecl, lib.eolian_state_enums_get(self._obj))
+
+ def enum_by_name_get(self, name):
+ c_tdecl = lib.eolian_state_enum_by_name_get(self._obj, _str_to_bytes(name))
+ return Typedecl(c_tdecl) if c_tdecl else None
+
+ def enums_by_file_get(self, file_name):
+ return Iterator(Typedecl,
+ lib.eolian_state_enums_by_file_get(self._obj, _str_to_bytes(file_name)))
+
### Namespace Utility Class #################################################
@@ -590,17 +614,17 @@ class Namespace(object):
@property
def aliases(self):
- return sorted([ td for td in self._unit.typedecl_all_aliases
+ return sorted([ td for td in self._unit.aliases
if td.namespace == self._name])
@property
def structs(self):
- return sorted([ td for td in self._unit.typedecl_all_structs
+ return sorted([ td for td in self._unit.structs
if td.namespace == self._name])
@property
def enums(self):
- return sorted([ td for td in self._unit.typedecl_all_enums
+ return sorted([ td for td in self._unit.enums
if td.namespace == self._name])
diff --git a/src/scripts/pyolian/eolian_lib.py b/src/scripts/pyolian/eolian_lib.py
index 75ab22246c..e4e1bc819e 100644
--- a/src/scripts/pyolian/eolian_lib.py
+++ b/src/scripts/pyolian/eolian_lib.py
@@ -129,6 +129,42 @@ lib.eolian_state_constants_get.restype = c_void_p
lib.eolian_state_globals_get.argtypes = [c_void_p,]
lib.eolian_state_globals_get.restype = c_void_p
+# EAPI const Eolian_Typedecl *eolian_state_alias_by_name_get(const Eolian_State *state, const char *name);
+lib.eolian_state_alias_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_alias_by_name_get.restype = c_void_p
+
+# EAPI const Eolian_Typedecl *eolian_state_struct_by_name_get(const Eolian_State *state, const char *name);
+lib.eolian_state_struct_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_struct_by_name_get.restype = c_void_p
+
+# EAPI const Eolian_Typedecl *eolian_state_enum_by_name_get(const Eolian_State *state, const char *name);
+lib.eolian_state_enum_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_enum_by_name_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_aliases_by_file_get(const Eolian_State *state, const char *file_name);
+lib.eolian_state_aliases_by_file_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_aliases_by_file_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_structs_by_file_get(const Eolian_State *state, const char *file_name);
+lib.eolian_state_structs_by_file_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_structs_by_file_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_enums_by_file_get(const Eolian_State *state, const char *file_name);
+lib.eolian_state_enums_by_file_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_state_enums_by_file_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_aliases_get(const Eolian_State *state);
+lib.eolian_state_aliases_get.argtypes = [c_void_p,]
+lib.eolian_state_aliases_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_structs_get(const Eolian_State *state);
+lib.eolian_state_structs_get.argtypes = [c_void_p,]
+lib.eolian_state_structs_get.restype = c_void_p
+
+# EAPI Eina_Iterator *eolian_state_enums_get(const Eolian_State *state);
+lib.eolian_state_enums_get.argtypes = [c_void_p,]
+lib.eolian_state_enums_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
@@ -151,41 +187,29 @@ lib.eolian_unit_class_by_name_get.restype = c_void_p
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]
-lib.eolian_typedecl_alias_get_by_name.restype = c_void_p
-
-# EAPI const Eolian_Typedecl *eolian_typedecl_struct_get_by_name(const Eolian_Unit *unit, const char *name);
-lib.eolian_typedecl_struct_get_by_name.argtypes = [c_void_p, c_char_p]
-lib.eolian_typedecl_struct_get_by_name.restype = c_void_p
-
-# EAPI const Eolian_Typedecl *eolian_typedecl_enum_get_by_name(const Eolian_Unit *unit, const char *name);
-lib.eolian_typedecl_enum_get_by_name.argtypes = [c_void_p, c_char_p]
-lib.eolian_typedecl_enum_get_by_name.restype = c_void_p
-
-# EAPI Eina_Iterator *eolian_typedecl_aliases_get_by_file(const Eolian_Unit *unit, const char *fname);
-lib.eolian_typedecl_aliases_get_by_file.argtypes = [c_void_p, c_char_p]
-lib.eolian_typedecl_aliases_get_by_file.restype = c_void_p
+# EAPI const Eolian_Typedecl *eolian_unit_alias_by_name_get(const Eolian_Unit *unit, const char *name);
+lib.eolian_unit_alias_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_unit_alias_by_name_get.restype = c_void_p
-# EAPI Eina_Iterator *eolian_typedecl_structs_get_by_file(const Eolian_Unit *unit, const char *fname);
-lib.eolian_typedecl_structs_get_by_file.argtypes = [c_void_p, c_char_p]
-lib.eolian_typedecl_structs_get_by_file.restype = c_void_p
+# EAPI const Eolian_Typedecl *eolian_unit_struct_by_name_get(const Eolian_Unit *unit, const char *name);
+lib.eolian_unit_struct_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_unit_struct_by_name_get.restype = c_void_p
-# EAPI Eina_Iterator *eolian_typedecl_enums_get_by_file(const Eolian_Unit *unit, const char *fname);
-lib.eolian_typedecl_enums_get_by_file.argtypes = [c_void_p, c_char_p]
-lib.eolian_typedecl_enums_get_by_file.restype = c_void_p
+# EAPI const Eolian_Typedecl *eolian_unit_enum_by_name_get(const Eolian_Unit *unit, const char *name);
+lib.eolian_unit_enum_by_name_get.argtypes = [c_void_p, c_char_p]
+lib.eolian_unit_enum_by_name_get.restype = c_void_p
-# EAPI Eina_Iterator *eolian_typedecl_all_aliases_get(const Eolian_Unit *unit);
-lib.eolian_typedecl_all_aliases_get.argtypes = [c_void_p,]
-lib.eolian_typedecl_all_aliases_get.restype = c_void_p
+# EAPI Eina_Iterator *eolian_unit_aliases_get(const Eolian_Unit *unit);
+lib.eolian_unit_aliases_get.argtypes = [c_void_p,]
+lib.eolian_unit_aliases_get.restype = c_void_p
-# EAPI Eina_Iterator *eolian_typedecl_all_structs_get(const Eolian_Unit *unit);
-lib.eolian_typedecl_all_structs_get.argtypes = [c_void_p,]
-lib.eolian_typedecl_all_structs_get.restype = c_void_p
+# EAPI Eina_Iterator *eolian_unit_structs_get(const Eolian_Unit *unit);
+lib.eolian_unit_structs_get.argtypes = [c_void_p,]
+lib.eolian_unit_structs_get.restype = c_void_p
-# EAPI Eina_Iterator *eolian_typedecl_all_enums_get(const Eolian_Unit *unit);
-lib.eolian_typedecl_all_enums_get.argtypes = [c_void_p,]
-lib.eolian_typedecl_all_enums_get.restype = c_void_p
+# EAPI Eina_Iterator *eolian_unit_enums_get(const Eolian_Unit *unit);
+lib.eolian_unit_enums_get.argtypes = [c_void_p,]
+lib.eolian_unit_enums_get.restype = c_void_p
# EAPI const Eolian_Variable *eolian_unit_global_by_name_get(const Eolian_Unit *unit, const char *name);
lib.eolian_unit_global_by_name_get.argtypes = [c_void_p, c_char_p]
diff --git a/src/scripts/pyolian/generator.py b/src/scripts/pyolian/generator.py
index fb8b3e3d10..067d7b52c6 100755
--- a/src/scripts/pyolian/generator.py
+++ b/src/scripts/pyolian/generator.py
@@ -167,11 +167,11 @@ class Template(pyratemp.Template):
if ns:
ctx['namespace'] = eolian_db.namespace_get_by_name(ns)
if struct:
- ctx['struct'] = eolian_db.typedecl_struct_get_by_name(struct)
+ ctx['struct'] = eolian_db.struct_by_name_get(struct)
if enum:
- ctx['enum'] = eolian_db.typedecl_enum_get_by_name(enum)
+ ctx['enum'] = eolian_db.enum_by_name_get(enum)
if alias:
- ctx['alias'] = eolian_db.typedecl_alias_get_by_name(alias)
+ ctx['alias'] = eolian_db.alias_by_name_get(alias)
if verbose and filename:
print("rendering: {} => {}".format(
diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py
index 13c7b2aaf0..606e2624fc 100755
--- a/src/scripts/pyolian/test_eolian.py
+++ b/src/scripts/pyolian/test_eolian.py
@@ -37,8 +37,8 @@ class TestBaseObject(unittest.TestCase):
self.assertNotEqual(cls1, None)
self.assertNotEqual(cls1, 0)
- enum1 = eolian_db.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction')
- enum2 = eolian_db.typedecl_enum_get_by_name('Efl.Ui.Focus.Direction')
+ enum1 = eolian_db.enum_by_name_get('Efl.Ui.Focus.Direction')
+ enum2 = eolian_db.enum_by_name_get('Efl.Ui.Focus.Direction')
self.assertIsInstance(enum1, eolian.Typedecl)
self.assertIsInstance(enum2, eolian.Typedecl)
self.assertEqual(enum1, enum2)
@@ -95,20 +95,20 @@ class TestEolianUnit(unittest.TestCase):
self.assertTrue(l[0].endswith('.eot'))
def test_enum_listing(self):
- l = list(eolian_db.typedecl_enums_get_by_file('efl_ui_win.eo'))
+ l = list(eolian_db.enums_by_file_get('efl_ui_win.eo'))
self.assertGreater(len(l), 5)
self.assertIsInstance(l[0], eolian.Typedecl)
self.assertEqual(l[0].type, eolian.Eolian_Typedecl_Type.ENUM)
all_count = 0
- for enum in eolian_db.typedecl_all_enums:
+ for enum in eolian_db.enums:
self.assertIsInstance(enum, eolian.Typedecl)
self.assertEqual(enum.type, eolian.Eolian_Typedecl_Type.ENUM)
all_count += 1
self.assertGreater(all_count, 50)
def test_struct_listing(self):
- l = list(eolian_db.typedecl_structs_get_by_file('eina_types.eot'))
+ l = list(eolian_db.structs_by_file_get('eina_types.eot'))
self.assertGreater(len(l), 10)
self.assertIsInstance(l[0], eolian.Typedecl)
self.assertIn(l[0].type, (
@@ -116,7 +116,7 @@ class TestEolianUnit(unittest.TestCase):
eolian.Eolian_Typedecl_Type.STRUCT_OPAQUE))
all_count = 0
- for struct in eolian_db.typedecl_all_structs:
+ for struct in eolian_db.structs:
self.assertIsInstance(struct, eolian.Typedecl)
self.assertIn(struct.type, (
eolian.Eolian_Typedecl_Type.STRUCT,
@@ -125,12 +125,12 @@ class TestEolianUnit(unittest.TestCase):
self.assertGreater(all_count, 50)
def test_alias_listing(self):
- l = list(eolian_db.typedecl_aliases_get_by_file('edje_types.eot'))
+ l = list(eolian_db.aliases_by_file_get('edje_types.eot'))
self.assertGreater(len(l), 5)
self.assertIsInstance(l[0], eolian.Typedecl)
all_count = 0
- for alias in eolian_db.typedecl_all_aliases:
+ for alias in eolian_db.aliases:
self.assertIsInstance(alias, eolian.Typedecl)
self.assertIn(alias.type, (
eolian.Eolian_Typedecl_Type.ALIAS,
@@ -422,7 +422,7 @@ class TestEolianVariable(unittest.TestCase):
class TestEolianTypedecl(unittest.TestCase):
def test_typedecl_enum(self):
- td = eolian_db.typedecl_enum_get_by_name('Efl.Net.Http.Version')
+ td = eolian_db.enum_by_name_get('Efl.Net.Http.Version')
self.assertIsInstance(td, eolian.Typedecl)
self.assertEqual(td.name, 'Version')
self.assertEqual(td.full_name, 'Efl.Net.Http.Version')
@@ -437,7 +437,7 @@ class TestEolianTypedecl(unittest.TestCase):
self.assertEqual(td.c_type, 'enum Efl_Net_Http_Version { v1_0 = 100, v1_1 = 101, v2_0 = 200 }')
def test_typedecl_enum_field(self):
- td = eolian_db.typedecl_enum_get_by_name('Efl.Net.Http.Version')
+ td = eolian_db.enum_by_name_get('Efl.Net.Http.Version')
field = td.enum_field_get('v1_0')
self.assertIsInstance(field, eolian.Enum_Type_Field)
self.assertEqual(field.name, 'v1_0')
@@ -446,7 +446,7 @@ class TestEolianTypedecl(unittest.TestCase):
self.assertIsInstance(field.value, eolian.Expression)
def test_typedecl_struct(self):
- td = eolian_db.typedecl_struct_get_by_name('Efl.Gfx.Color32')
+ td = eolian_db.struct_by_name_get('Efl.Gfx.Color32')
self.assertIsInstance(td, eolian.Typedecl)
self.assertEqual(td.name, 'Color32')
self.assertEqual(td.full_name, 'Efl.Gfx.Color32')
@@ -461,7 +461,7 @@ class TestEolianTypedecl(unittest.TestCase):
self.assertEqual(td.c_type, 'struct Efl_Gfx_Color32 { uint8_t r; uint8_t g; uint8_t b; uint8_t a; }')
def test_typedecl_struct_field(self):
- td = eolian_db.typedecl_struct_get_by_name('Efl.Gfx.Color32')
+ td = eolian_db.struct_by_name_get('Efl.Gfx.Color32')
field = td.struct_field_get('b')
self.assertIsInstance(field, eolian.Struct_Type_Field)
self.assertEqual(field.name, 'b')
@@ -469,7 +469,7 @@ class TestEolianTypedecl(unittest.TestCase):
self.assertIsInstance(field.documentation, eolian.Documentation)
def test_typedecl_alias(self):
- alias = eolian_db.typedecl_alias_get_by_name('Eina.Error')
+ alias = eolian_db.alias_by_name_get('Eina.Error')
self.assertIsInstance(alias, eolian.Typedecl)
self.assertEqual(alias.type, eolian.Eolian_Typedecl_Type.ALIAS)
self.assertEqual(alias.name, 'Error')
@@ -567,7 +567,7 @@ class TestEolianDeclaration(unittest.TestCase):
class TestEolianExpression(unittest.TestCase):
def test_expression_simple(self):
- td = eolian_db.typedecl_enum_get_by_name('Efl.Net.Http.Version')
+ td = eolian_db.enum_by_name_get('Efl.Net.Http.Version')
field = td.enum_field_get('v1_0')
exp = field.value
self.assertIsInstance(exp, eolian.Expression)