aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/pyolian
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-03-11 14:28:51 +0100
committerDave Andreoli <dave@gurumeditation.it>2018-03-11 14:28:51 +0100
commit6f6557e2d0709879d2eb79eff8b84e27606a156d (patch)
tree5ab190f89af9817798b0ae89629968f4e84c0708 /src/scripts/pyolian
parentelm test - adapt to argc/v being regular argv 0 being binary name (diff)
downloadefl-6f6557e2d0709879d2eb79eff8b84e27606a156d.tar.gz
Pyolian: build the correct type from generic Object
This way all the generic Eolian_Object types are automatically converted to the correct types (Class, Variable, etc...)
Diffstat (limited to 'src/scripts/pyolian')
-rw-r--r--src/scripts/pyolian/eolian.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index 998006b54f..42468313bc 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -412,6 +412,7 @@ class Eolian_Unit(EolianBaseObject):
def namespace_get_by_name(self, name):
return Namespace(self, name)
+
class Eolian_State(Eolian_Unit):
def __init__(self):
self._obj = lib.eolian_state_new() # Eolian_State *
@@ -635,6 +636,12 @@ class Namespace(object):
### Eolian Classes ##########################################################
class Object(EolianBaseObject):
+ def __new__(cls, c_obj_pointer):
+ if cls is Object:
+ c_type = lib.eolian_object_type_get(c_obj_pointer)
+ cls = _eolian_type_class_mapping[c_type]
+ return super().__new__(cls)
+
def __repr__(self):
return "<eolian.Object '{0.name}', {0.type!s}>".format(self)
@@ -658,6 +665,7 @@ class Object(EolianBaseObject):
def type(self):
return Eolian_Object_Type(lib.eolian_object_type_get(self._obj))
+
class Class(Object):
def __repr__(self):
return "<eolian.Class '{0.full_name}', {0.type!s}>".format(self)
@@ -1548,6 +1556,26 @@ def _str_to_py(s):
print('WARNING !!!!!!!!! Unknown type: %s' % type(s))
+### internal Object type -> class mapping ###################################
+
+_eolian_type_class_mapping = {
+ Eolian_Object_Type.UNKNOWN: Object,
+ Eolian_Object_Type.CLASS: Class,
+ Eolian_Object_Type.TYPEDECL: Typedecl,
+ Eolian_Object_Type.STRUCT_FIELD: Struct_Type_Field,
+ Eolian_Object_Type.ENUM_FIELD: Enum_Type_Field,
+ Eolian_Object_Type.TYPE: Type,
+ Eolian_Object_Type.VARIABLE: Variable,
+ Eolian_Object_Type.EXPRESSION: Expression,
+ Eolian_Object_Type.FUNCTION: Function,
+ Eolian_Object_Type.FUNCTION_PARAMETER: Function_Parameter,
+ Eolian_Object_Type.EVENT: Event,
+ Eolian_Object_Type.PART: Part,
+ Eolian_Object_Type.IMPLEMENT: Implement,
+ Eolian_Object_Type.CONSTRUCTOR: Constructor,
+ Eolian_Object_Type.DOCUMENTATION: Documentation,
+}
+
### module init/shutdown ####################################################
def _cleanup():
global _already_halted