diff --git a/pyste/src/ClassExporter.py b/pyste/src/ClassExporter.py index 8dd0e421..44be258e 100644 --- a/pyste/src/ClassExporter.py +++ b/pyste/src/ClassExporter.py @@ -366,10 +366,11 @@ class ClassExporter(Exporter): } # converters which has a special name in python - SPECIAL_CONVETERS = { + SPECIAL_CONVERTERS = { 'double' : '__float__', 'float' : '__float__', 'int' : '__int__', + 'long' : '__long__', } @@ -480,12 +481,15 @@ class ClassExporter(Exporter): # export them as simple functions with a pre-determined name converters = [x for x in self.public_members if type(x) == ConverterOperator] - + def ConverterMethodName(converter): result_fullname = converter.result.name - # extract the last name from the full name - result_name = _ID(result_fullname.split('::')[-1]) - return 'to_' + result_name + if result_fullname in self.SPECIAL_CONVERTERS: + return self.SPECIAL_CONVERTERS[result_fullname] + else: + # extract the last name from the full name + result_name = _ID(result_fullname.split('::')[-1]) + return 'to_' + result_name for converter in converters: info = self.info['operator'][converter.result.name] diff --git a/pyste/src/GCCXMLParser.py b/pyste/src/GCCXMLParser.py index 637eceb0..6c57a512 100644 --- a/pyste/src/GCCXMLParser.py +++ b/pyste/src/GCCXMLParser.py @@ -358,12 +358,13 @@ class GCCXMLParser(object): name = element.get('name') location = self.GetLocation(element.get('location')) context = self.GetDecl(element.get('context')) - if isinstance(context, Class): + if isinstance(context, str): + enum = Enumeration(name, context) + self.AddDecl(enum) # in this case, is a top level decl + else: visib = element.get('access', Scope.public) enum = ClassEnumeration(name, context.FullName(), visib) - else: - enum = Enumeration(name, context) - self.AddDecl(enum) # in this case, is a top level decl + enum.location = location for child in element: if child.tag == 'EnumValue': @@ -379,7 +380,18 @@ class GCCXMLParser(object): def ParseUnion(self, id, element): - self.Update(id, Declaration(element.get('name'), '')) + name = element.get('name') + context = self.GetDecl(element.get('context')) + location = self.GetLocation(element.get('location')) + if isinstance(context, str): + # a free union + union = Union(name, context) + self.AddDecl(union) + else: + visib = element.get('access', Scope.public) + union = ClassUnion(name, context.FullName(), visib) + union.location = location + self.Update(id, union) diff --git a/pyste/src/declarations.py b/pyste/src/declarations.py index adba6fd3..99784b12 100644 --- a/pyste/src/declarations.py +++ b/pyste/src/declarations.py @@ -445,8 +445,20 @@ class Typedef(Declaration): self.visibility = Scope.public +class Union(Declaration): + 'Shallow declaration, because Unions are not supported yet' + def __init__(self, name, namespace): + Declaration.__init__(self, name, namespace) - +class ClassUnion(Union): + + def __init__(self, name, class_, visib): + Union.__init__(self, name, None) + self.class_ = class_ + self.visibility = visib + + def FullName(self): + return '%s::%s' % (self.class_, self.name)