summaryrefslogtreecommitdiff
path: root/src/scripts/pyolian/eolian.py
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/eolian.py
parent44387a580310d4e5acdd89a1a4ae3b2cb29f83ac (diff)
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 '')
-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):
412 def namespace_get_by_name(self, name): 412 def namespace_get_by_name(self, name):
413 return Namespace(self, name) 413 return Namespace(self, name)
414 414
415
415class Eolian_State(Eolian_Unit): 416class Eolian_State(Eolian_Unit):
416 def __init__(self): 417 def __init__(self):
417 self._obj = lib.eolian_state_new() # Eolian_State * 418 self._obj = lib.eolian_state_new() # Eolian_State *
@@ -635,6 +636,12 @@ class Namespace(object):
635### Eolian Classes ########################################################## 636### Eolian Classes ##########################################################
636 637
637class Object(EolianBaseObject): 638class Object(EolianBaseObject):
639 def __new__(cls, c_obj_pointer):
640 if cls is Object:
641 c_type = lib.eolian_object_type_get(c_obj_pointer)
642 cls = _eolian_type_class_mapping[c_type]
643 return super().__new__(cls)
644
638 def __repr__(self): 645 def __repr__(self):
639 return "<eolian.Object '{0.name}', {0.type!s}>".format(self) 646 return "<eolian.Object '{0.name}', {0.type!s}>".format(self)
640 647
@@ -658,6 +665,7 @@ class Object(EolianBaseObject):
658 def type(self): 665 def type(self):
659 return Eolian_Object_Type(lib.eolian_object_type_get(self._obj)) 666 return Eolian_Object_Type(lib.eolian_object_type_get(self._obj))
660 667
668
661class Class(Object): 669class Class(Object):
662 def __repr__(self): 670 def __repr__(self):
663 return "<eolian.Class '{0.full_name}', {0.type!s}>".format(self) 671 return "<eolian.Class '{0.full_name}', {0.type!s}>".format(self)
@@ -1548,6 +1556,26 @@ def _str_to_py(s):
1548 print('WARNING !!!!!!!!! Unknown type: %s' % type(s)) 1556 print('WARNING !!!!!!!!! Unknown type: %s' % type(s))
1549 1557
1550 1558
1559### internal Object type -> class mapping ###################################
1560
1561_eolian_type_class_mapping = {
1562 Eolian_Object_Type.UNKNOWN: Object,
1563 Eolian_Object_Type.CLASS: Class,
1564 Eolian_Object_Type.TYPEDECL: Typedecl,
1565 Eolian_Object_Type.STRUCT_FIELD: Struct_Type_Field,
1566 Eolian_Object_Type.ENUM_FIELD: Enum_Type_Field,
1567 Eolian_Object_Type.TYPE: Type,
1568 Eolian_Object_Type.VARIABLE: Variable,
1569 Eolian_Object_Type.EXPRESSION: Expression,
1570 Eolian_Object_Type.FUNCTION: Function,
1571 Eolian_Object_Type.FUNCTION_PARAMETER: Function_Parameter,
1572 Eolian_Object_Type.EVENT: Event,
1573 Eolian_Object_Type.PART: Part,
1574 Eolian_Object_Type.IMPLEMENT: Implement,
1575 Eolian_Object_Type.CONSTRUCTOR: Constructor,
1576 Eolian_Object_Type.DOCUMENTATION: Documentation,
1577}
1578
1551### module init/shutdown #################################################### 1579### module init/shutdown ####################################################
1552def _cleanup(): 1580def _cleanup():
1553 global _already_halted 1581 global _already_halted