Package pygccxml :: Package declarations :: Module cpptypes

Source Code for Module pygccxml.declarations.cpptypes

  1  # Copyright 2004-2008 Roman Yakovenko.
 
  2  # Distributed under the Boost Software License, Version 1.0. (See
 
  3  # accompanying file LICENSE_1_0.txt or copy at
 
  4  # http://www.boost.org/LICENSE_1_0.txt)
 
  5  
 
  6  """
 
  7  defines classes, that describe C++ types
 
  8  """ 
  9  
 
 10  import compilers 
 11  import algorithms_cache 
12 13 -class type_t(object):
14 """base class for all types"""
15 - def __init__(self):
16 object.__init__( self ) 17 self.cache = algorithms_cache.type_algs_cache_t() 18 self._byte_size = 0 19 self._byte_align = 0 20 self.compiler = None
21
22 - def __str__(self):
23 res = self.decl_string 24 if res[:2]=="::": 25 res = res[2:] 26 return res
27
28 - def __eq__(self, other):
29 if not isinstance( other, type_t ): 30 return False 31 return self.decl_string == other.decl_string
32
33 - def __ne__( self, other):
34 return not self.__eq__( other )
35
36 - def __lt__(self, other):
37 if not isinstance( other, self.__class__ ): 38 return self.__class__.__name__ < other.__class__.__name__ 39 return self.decl_string < other.decl_string
40
41 - def build_decl_string(self, with_defaults=True):
42 raise NotImplementedError()
43 44 @property
45 - def decl_string( self ):
46 return self.build_decl_string()
47 48 @property
49 - def partial_decl_string( self ):
50 return self.build_decl_string( False )
51
52 - def _clone_impl( self ):
53 raise NotImplementedError()
54
55 - def clone( self ):
56 "returns new instance of the type" 57 answer = self._clone_impl() 58 return answer
59
60 - def _get_byte_size(self):
61 return self._byte_size
62 - def _set_byte_size( self, new_byte_size ):
63 self._byte_size = new_byte_size
64 byte_size = property( _get_byte_size, _set_byte_size 65 , doc="Size of this type in bytes @type: int") 66
67 - def _get_byte_align(self):
68 if self.compiler == compilers.MSVC_PDB_9: 69 compilers.on_missing_functionality( self.compiler, "byte align" ) 70 return self._byte_align
71 - def _set_byte_align( self, new_byte_align ):
72 self._byte_align = new_byte_align
73 byte_align = property( _get_byte_align, _set_byte_align 74 , doc="Alignment of this type in bytes @type: int")
75
76 77 #There are cases when GCC-XML reports something like this 78 #<Unimplemented id="_9482" tree_code="188" tree_code_name="template_type_parm" node="0xcc4d5b0"/> 79 #In this case I will use this as type 80 81 82 -class dummy_type_t( type_t ):
83 """provides L{type_t} interface for a string, that defines C++ type. 84 85 This class could be very useful in the code generator. 86 """
87 - def __init__( self, decl_string ):
88 type_t.__init__( self ) 89 self._decl_string = decl_string
90
91 - def build_decl_string(self, with_defaults=True):
92 return self._decl_string
93
94