1
2
3
4
5
6 """
7 defines 2 important classes
8
9 This module defines:
10 * declaration_t - base class for all pygccxml defined classes, which describe
11 a C++ declaration
12 * location_t - provides information about physical location of the declaration
13 """
14
15 import algorithm
16 import templates
17 import algorithms_cache
20 """provides information about the location of the declaration within the source file"""
21
22 - def __init__(self, file_name='', line=-1 ):
25
27 if not isinstance( other, self.__class__ ):
28 return False
29 return self.line == other.line \
30 and self.file_name == other.file_name
31
33 return not self.__eq__( other )
34
39
41 return self._file_name
43 self._file_name = new_file_name
44 file_name = property( _get_file_name, _set_file_name
45 , doc="""absolute source file name, type string""" )
46
51 line = property( _get_line, _set_line, doc="""line number, type int""")
52
54 """return tuple(self.file_name, self.line)"""
55 return (self.file_name, self.line)
56
58 """base class for all classes that represent a C++ declaration"""
59
60 - def __init__( self, name='', location=None, is_artificial=False, mangled=None, demangled=None, attributes=None ):
71
73 """Default __str__ method.
74
75 This version just returns the decl_string and the class.
76 Derived classes may override this method to provide more detailed
77 information.
78
79 A __str__ method for a declaration should always provide enough
80 information so that it uniquely identifies the declaration and
81 the user is able to find the declaration in his source code.
82 """
83 name = self.decl_string
84 if name[:2]=="::":
85 name = name[2:]
86
87 cls = self.__class__.__name__
88 if cls[-2:]=="_t":
89 cls = cls[:-2]
90 cls = cls.replace( '_', ' ' )
91 return "%s [%s]"%(name, cls)
92
93 @staticmethod
95 """implementation details"""
96 some_list.sort()
97 return some_list
98
100 """implementation details"""
101
102
103
104 print '_get__cmp__items not implemented for class ', self.__class__.__name__
105 raise NotImplemented()
106
112
114 """
115 function will return true, if both declarations refers to the same object.
116 This function could be implemented in terms of _get__cmp__data, but in
117 this case it will downgrade performance. self.mangled property is not
118 compared, because it could be chaned from one compilation time to an
119 other.
120 """
121 if not isinstance( other, self.__class__ ):
122 return False
123 return self.name == other.name \
124 and self.location == other.location \
125 and algorithm.declaration_path( self.parent ) \
126 == algorithm.declaration_path( other.parent )
127
129 """return not self.__eq__( other )"""
130 return not self.__eq__( other )
131
133 """
134 C{if not isinstance( other, self.__class__ ):}
135 C{ return self.__class__.__name__ < other.__class__.__name__}
136 C{return self._get__cmp__data() < other._get__cmp__data()}
137 """
138 if not isinstance( other, self.__class__ ):
139 return self.__class__.__name__ < other.__class__.__name__
140 return self._get__cmp__data() < other._get__cmp__data()
141
144
146 return self._get_name_impl()
147
150
152 previous_name = self._name
153 self._name = new_name
154 self._partial_name = None
155 self.cache.reset_name_based()
156 if previous_name:
157 self._on_rename()
158
159 name = property( _get_name, _set_name
160 , doc="""Declaration name
161 @type: str
162 """)
163
166
167 @property
169 """declaration name, without template default arguments
170 Right now std containers is the only classes that support this functionality"""
171 if None is self._partial_name:
172 self._partial_name = self._get_partial_name_impl()
173 return self._partial_name
174
178 if new_parent:
179 assert( isinstance( new_parent, declaration_t ) )
180 self._parent = new_parent
181 parent = property( _get_parent, _set_parent
182 , doc="""Reference to parent declaration
183 @type: declaration_t
184 """)
185
195 top_parent = property( __get_top_parent,
196 doc="""reference to top parent declaration
197 @type: declaration_t
198 """ )
199
201 return self._location
203 self._location = new_location
204 location = property( _get_location, _set_location
205 , doc="""Location of the declaration within source file
206 @type: L{location_t}
207 """)
208
210 return self._is_artificial
212 self._is_artificial = new_artificial
213 is_artificial = property( _get_is_artificial, _set_is_artificial
214 , doc="""Describes whether declaration is compiler generated or not
215 @type: bool
216 """)
217
222 mangled = property( _get_mangled, _set_mangled
223 , doc="""Compiler generated declaration name
224 @type: str
225 """ )
226
228 return self._demangled
231 demangled = property( _get_demangled, _set_demangled
232 , doc="""Demangled compiler generated declaration name
233 @type: str
234 """ )
235
237 return self._attributes
240 attributes = property( _get_attributes, _set_attributes
241 , doc="""GCCXML attributes, set using __attribute__((gccxml("...")))
242 @type: str
243 """ )
244
247
248 @property
252
253 @property
257
258 @property
260 """implementation details
261
262 reference to instance of L{algorithms_cache.algorithms_cache_t} class.
263 """
264 return self._cache
265
267 """return list of all types and declarations the declaration depends on"""
268 print self
269 raise NotImplementedError()
270
272 return self._compiler
275 compiler = property( _get_compiler, _set_compiler
276 , doc="""compiler name + version
277 @type: str""" )
278