Daniel Dunbar | 4efd632 | 2010-01-25 00:43:08 +0000 | [diff] [blame] | 1 | #===- cindex.py - Python Indexing Library Bindings -----------*- python -*--===# |
| 2 | # |
| 3 | # The LLVM Compiler Infrastructure |
| 4 | # |
| 5 | # This file is distributed under the University of Illinois Open Source |
| 6 | # License. See LICENSE.TXT for details. |
| 7 | # |
| 8 | #===------------------------------------------------------------------------===# |
| 9 | |
| 10 | r""" |
| 11 | Clang Indexing Library Bindings |
| 12 | =============================== |
| 13 | |
| 14 | This module provides an interface to the Clang indexing library. It is a |
| 15 | low-level interface to the indexing library which attempts to match the Clang |
| 16 | API directly while also being "pythonic". Notable differences from the C API |
| 17 | are: |
| 18 | |
| 19 | * string results are returned as Python strings, not CXString objects. |
| 20 | |
| 21 | * null cursors are translated to None. |
| 22 | |
| 23 | * access to child cursors is done via iteration, not visitation. |
| 24 | |
| 25 | The major indexing objects are: |
| 26 | |
| 27 | Index |
| 28 | |
| 29 | The top-level object which manages some global library state. |
| 30 | |
| 31 | TranslationUnit |
| 32 | |
| 33 | High-level object encapsulating the AST for a single translation unit. These |
| 34 | can be loaded from .ast files or parsed on the fly. |
| 35 | |
| 36 | Cursor |
| 37 | |
| 38 | Generic object for representing a node in the AST. |
| 39 | |
| 40 | SourceRange, SourceLocation, and File |
| 41 | |
| 42 | Objects representing information about the input source. |
| 43 | |
| 44 | Most object information is exposed using properties, when the underlying API |
| 45 | call is efficient. |
| 46 | """ |
| 47 | |
| 48 | # TODO |
| 49 | # ==== |
| 50 | # |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 51 | # o API support for invalid translation units. Currently we can't even get the |
| 52 | # diagnostics on failure because they refer to locations in an object that |
| 53 | # will have been invalidated. |
| 54 | # |
Daniel Dunbar | 4efd632 | 2010-01-25 00:43:08 +0000 | [diff] [blame] | 55 | # o fix memory management issues (currently client must hold on to index and |
| 56 | # translation unit, or risk crashes). |
| 57 | # |
| 58 | # o expose code completion APIs. |
| 59 | # |
| 60 | # o cleanup ctypes wrapping, would be nice to separate the ctypes details more |
| 61 | # clearly, and hide from the external interface (i.e., help(cindex)). |
| 62 | # |
| 63 | # o implement additional SourceLocation, SourceRange, and File methods. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 64 | |
| 65 | from ctypes import * |
Gregory Szorc | 826fce5 | 2012-02-20 17:45:30 +0000 | [diff] [blame] | 66 | import collections |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 67 | |
| 68 | def get_cindex_library(): |
| 69 | # FIXME: It's probably not the case that the library is actually found in |
| 70 | # this location. We need a better system of identifying and loading the |
| 71 | # CIndex library. It could be on path or elsewhere, or versioned, etc. |
| 72 | import platform |
| 73 | name = platform.system() |
| 74 | if name == 'Darwin': |
Daniel Dunbar | f51f20f | 2010-04-30 21:51:10 +0000 | [diff] [blame] | 75 | return cdll.LoadLibrary('libclang.dylib') |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 76 | elif name == 'Windows': |
Daniel Dunbar | f51f20f | 2010-04-30 21:51:10 +0000 | [diff] [blame] | 77 | return cdll.LoadLibrary('libclang.dll') |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 78 | else: |
Daniel Dunbar | f51f20f | 2010-04-30 21:51:10 +0000 | [diff] [blame] | 79 | return cdll.LoadLibrary('libclang.so') |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 80 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 81 | # ctypes doesn't implicitly convert c_void_p to the appropriate wrapper |
| 82 | # object. This is a problem, because it means that from_parameter will see an |
| 83 | # integer and pass the wrong value on platforms where int != void*. Work around |
| 84 | # this by marshalling object arguments as void**. |
| 85 | c_object_p = POINTER(c_void_p) |
| 86 | |
| 87 | lib = get_cindex_library() |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 88 | callbacks = {} |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 89 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 90 | ### Exception Classes ### |
| 91 | |
| 92 | class TranslationUnitLoadError(Exception): |
| 93 | """Represents an error that occurred when loading a TranslationUnit. |
| 94 | |
| 95 | This is raised in the case where a TranslationUnit could not be |
| 96 | instantiated due to failure in the libclang library. |
| 97 | |
| 98 | FIXME: Make libclang expose additional error information in this scenario. |
| 99 | """ |
| 100 | pass |
| 101 | |
| 102 | class TranslationUnitSaveError(Exception): |
| 103 | """Represents an error that occurred when saving a TranslationUnit. |
| 104 | |
| 105 | Each error has associated with it an enumerated value, accessible under |
| 106 | e.save_error. Consumers can compare the value with one of the ERROR_ |
| 107 | constants in this class. |
| 108 | """ |
| 109 | |
| 110 | # Indicates that an unknown error occurred. This typically indicates that |
| 111 | # I/O failed during save. |
| 112 | ERROR_UNKNOWN = 1 |
| 113 | |
| 114 | # Indicates that errors during translation prevented saving. The errors |
| 115 | # should be available via the TranslationUnit's diagnostics. |
| 116 | ERROR_TRANSLATION_ERRORS = 2 |
| 117 | |
| 118 | # Indicates that the translation unit was somehow invalid. |
| 119 | ERROR_INVALID_TU = 3 |
| 120 | |
| 121 | def __init__(self, enumeration, message): |
| 122 | assert isinstance(enumeration, int) |
| 123 | |
| 124 | if enumeration < 1 or enumeration > 3: |
| 125 | raise Exception("Encountered undefined TranslationUnit save error " |
| 126 | "constant: %d. Please file a bug to have this " |
| 127 | "value supported." % enumeration) |
| 128 | |
| 129 | self.save_error = enumeration |
Gregory Szorc | 2283b46 | 2012-05-12 20:49:13 +0000 | [diff] [blame] | 130 | Exception.__init__(self, 'Error %d: %s' % (enumeration, message)) |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 131 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 132 | ### Structures and Utility Classes ### |
| 133 | |
Daniel Dunbar | a33dca4 | 2010-01-24 21:19:57 +0000 | [diff] [blame] | 134 | class _CXString(Structure): |
| 135 | """Helper for transforming CXString results.""" |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 136 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 137 | _fields_ = [("spelling", c_char_p), ("free", c_int)] |
| 138 | |
| 139 | def __del__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 140 | lib.clang_disposeString(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 141 | |
Daniel Dunbar | a33dca4 | 2010-01-24 21:19:57 +0000 | [diff] [blame] | 142 | @staticmethod |
| 143 | def from_result(res, fn, args): |
| 144 | assert isinstance(res, _CXString) |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 145 | return lib.clang_getCString(res) |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 146 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 147 | class SourceLocation(Structure): |
| 148 | """ |
Daniel Dunbar | 149f38a | 2010-01-24 04:09:58 +0000 | [diff] [blame] | 149 | A SourceLocation represents a particular location within a source file. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 150 | """ |
Daniel Dunbar | e32af42 | 2010-01-30 23:58:50 +0000 | [diff] [blame] | 151 | _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)] |
Daniel Dunbar | f869083 | 2010-01-24 21:20:21 +0000 | [diff] [blame] | 152 | _data = None |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 153 | |
Daniel Dunbar | f869083 | 2010-01-24 21:20:21 +0000 | [diff] [blame] | 154 | def _get_instantiation(self): |
| 155 | if self._data is None: |
Daniel Dunbar | 3239a67 | 2010-01-29 17:02:32 +0000 | [diff] [blame] | 156 | f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint() |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 157 | lib.clang_getInstantiationLocation(self, byref(f), byref(l), |
| 158 | byref(c), byref(o)) |
Tobias Grosser | 8198288 | 2011-10-31 00:49:07 +0000 | [diff] [blame] | 159 | if f: |
| 160 | f = File(f) |
| 161 | else: |
| 162 | f = None |
Argyrios Kyrtzidis | 6b04623 | 2011-08-17 17:20:24 +0000 | [diff] [blame] | 163 | self._data = (f, int(l.value), int(c.value), int(o.value)) |
Daniel Dunbar | f869083 | 2010-01-24 21:20:21 +0000 | [diff] [blame] | 164 | return self._data |
| 165 | |
Tobias Grosser | 58ba8c9 | 2011-10-31 00:31:32 +0000 | [diff] [blame] | 166 | @staticmethod |
| 167 | def from_position(tu, file, line, column): |
| 168 | """ |
| 169 | Retrieve the source location associated with a given file/line/column in |
| 170 | a particular translation unit. |
| 171 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 172 | return lib.clang_getLocation(tu, file, line, column) |
Tobias Grosser | 58ba8c9 | 2011-10-31 00:31:32 +0000 | [diff] [blame] | 173 | |
Gregory Szorc | 74bb710 | 2012-06-11 11:11:48 +0000 | [diff] [blame] | 174 | @staticmethod |
| 175 | def from_offset(tu, file, offset): |
| 176 | """Retrieve a SourceLocation from a given character offset. |
| 177 | |
| 178 | tu -- TranslationUnit file belongs to |
| 179 | file -- File instance to obtain offset from |
| 180 | offset -- Integer character offset within file |
| 181 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 182 | return lib.clang_getLocationForOffset(tu, file, offset) |
Gregory Szorc | 74bb710 | 2012-06-11 11:11:48 +0000 | [diff] [blame] | 183 | |
Daniel Dunbar | f869083 | 2010-01-24 21:20:21 +0000 | [diff] [blame] | 184 | @property |
| 185 | def file(self): |
| 186 | """Get the file represented by this source location.""" |
| 187 | return self._get_instantiation()[0] |
| 188 | |
| 189 | @property |
| 190 | def line(self): |
| 191 | """Get the line represented by this source location.""" |
| 192 | return self._get_instantiation()[1] |
| 193 | |
| 194 | @property |
| 195 | def column(self): |
| 196 | """Get the column represented by this source location.""" |
| 197 | return self._get_instantiation()[2] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 198 | |
Daniel Dunbar | 3239a67 | 2010-01-29 17:02:32 +0000 | [diff] [blame] | 199 | @property |
| 200 | def offset(self): |
| 201 | """Get the file offset represented by this source location.""" |
| 202 | return self._get_instantiation()[3] |
| 203 | |
Tobias Grosser | 7485833 | 2012-02-05 11:40:59 +0000 | [diff] [blame] | 204 | def __eq__(self, other): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 205 | return lib.clang_equalLocations(self, other) |
Tobias Grosser | 7485833 | 2012-02-05 11:40:59 +0000 | [diff] [blame] | 206 | |
| 207 | def __ne__(self, other): |
| 208 | return not self.__eq__(other) |
| 209 | |
Daniel Dunbar | 7b48b35 | 2010-01-24 04:09:34 +0000 | [diff] [blame] | 210 | def __repr__(self): |
Tobias Grosser | 8198288 | 2011-10-31 00:49:07 +0000 | [diff] [blame] | 211 | if self.file: |
| 212 | filename = self.file.name |
| 213 | else: |
| 214 | filename = None |
Daniel Dunbar | 7b48b35 | 2010-01-24 04:09:34 +0000 | [diff] [blame] | 215 | return "<SourceLocation file %r, line %r, column %r>" % ( |
Tobias Grosser | 8198288 | 2011-10-31 00:49:07 +0000 | [diff] [blame] | 216 | filename, self.line, self.column) |
Daniel Dunbar | 7b48b35 | 2010-01-24 04:09:34 +0000 | [diff] [blame] | 217 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 218 | class SourceRange(Structure): |
| 219 | """ |
| 220 | A SourceRange describes a range of source locations within the source |
| 221 | code. |
| 222 | """ |
| 223 | _fields_ = [ |
Daniel Dunbar | e32af42 | 2010-01-30 23:58:50 +0000 | [diff] [blame] | 224 | ("ptr_data", c_void_p * 2), |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 225 | ("begin_int_data", c_uint), |
| 226 | ("end_int_data", c_uint)] |
| 227 | |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 228 | # FIXME: Eliminate this and make normal constructor? Requires hiding ctypes |
| 229 | # object. |
| 230 | @staticmethod |
| 231 | def from_locations(start, end): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 232 | return lib.clang_getRange(start, end) |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 233 | |
Daniel Dunbar | 7b48b35 | 2010-01-24 04:09:34 +0000 | [diff] [blame] | 234 | @property |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 235 | def start(self): |
| 236 | """ |
| 237 | Return a SourceLocation representing the first character within a |
| 238 | source range. |
| 239 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 240 | return lib.clang_getRangeStart(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 241 | |
Daniel Dunbar | 7b48b35 | 2010-01-24 04:09:34 +0000 | [diff] [blame] | 242 | @property |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 243 | def end(self): |
| 244 | """ |
| 245 | Return a SourceLocation representing the last character within a |
| 246 | source range. |
| 247 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 248 | return lib.clang_getRangeEnd(self) |
Daniel Dunbar | f869083 | 2010-01-24 21:20:21 +0000 | [diff] [blame] | 249 | |
Tobias Grosser | 7485833 | 2012-02-05 11:40:59 +0000 | [diff] [blame] | 250 | def __eq__(self, other): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 251 | return lib.clang_equalRanges(self, other) |
Tobias Grosser | 7485833 | 2012-02-05 11:40:59 +0000 | [diff] [blame] | 252 | |
| 253 | def __ne__(self, other): |
| 254 | return not self.__eq__(other) |
| 255 | |
Daniel Dunbar | f869083 | 2010-01-24 21:20:21 +0000 | [diff] [blame] | 256 | def __repr__(self): |
| 257 | return "<SourceRange start %r, end %r>" % (self.start, self.end) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 258 | |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 259 | class Diagnostic(object): |
| 260 | """ |
| 261 | A Diagnostic is a single instance of a Clang diagnostic. It includes the |
| 262 | diagnostic severity, the message, the location the diagnostic occurred, as |
| 263 | well as additional source ranges and associated fix-it hints. |
| 264 | """ |
| 265 | |
| 266 | Ignored = 0 |
| 267 | Note = 1 |
| 268 | Warning = 2 |
| 269 | Error = 3 |
| 270 | Fatal = 4 |
| 271 | |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 272 | def __init__(self, ptr): |
| 273 | self.ptr = ptr |
| 274 | |
| 275 | def __del__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 276 | lib.clang_disposeDiagnostic(self) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 277 | |
| 278 | @property |
| 279 | def severity(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 280 | return lib.clang_getDiagnosticSeverity(self) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 281 | |
| 282 | @property |
| 283 | def location(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 284 | return lib.clang_getDiagnosticLocation(self) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 285 | |
| 286 | @property |
| 287 | def spelling(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 288 | return lib.clang_getDiagnosticSpelling(self) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 289 | |
| 290 | @property |
| 291 | def ranges(self): |
Benjamin Kramer | 1d02ccd | 2010-03-06 15:38:03 +0000 | [diff] [blame] | 292 | class RangeIterator: |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 293 | def __init__(self, diag): |
| 294 | self.diag = diag |
| 295 | |
| 296 | def __len__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 297 | return int(lib.clang_getDiagnosticNumRanges(self.diag)) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 298 | |
| 299 | def __getitem__(self, key): |
Tobias Grosser | ba5d10b | 2011-10-31 02:06:50 +0000 | [diff] [blame] | 300 | if (key >= len(self)): |
| 301 | raise IndexError |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 302 | return lib.clang_getDiagnosticRange(self.diag, key) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 303 | |
Tobias Grosser | ff090ca | 2011-02-05 17:53:48 +0000 | [diff] [blame] | 304 | return RangeIterator(self) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 305 | |
| 306 | @property |
| 307 | def fixits(self): |
Benjamin Kramer | 1d02ccd | 2010-03-06 15:38:03 +0000 | [diff] [blame] | 308 | class FixItIterator: |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 309 | def __init__(self, diag): |
| 310 | self.diag = diag |
| 311 | |
| 312 | def __len__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 313 | return int(lib.clang_getDiagnosticNumFixIts(self.diag)) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 314 | |
| 315 | def __getitem__(self, key): |
| 316 | range = SourceRange() |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 317 | value = lib.clang_getDiagnosticFixIt(self.diag, key, |
| 318 | byref(range)) |
Benjamin Kramer | 1d02ccd | 2010-03-06 15:38:03 +0000 | [diff] [blame] | 319 | if len(value) == 0: |
| 320 | raise IndexError |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 321 | |
| 322 | return FixIt(range, value) |
| 323 | |
Tobias Grosser | ff090ca | 2011-02-05 17:53:48 +0000 | [diff] [blame] | 324 | return FixItIterator(self) |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 325 | |
Tobias Grosser | ea40382 | 2012-02-05 11:41:58 +0000 | [diff] [blame] | 326 | @property |
| 327 | def category_number(self): |
| 328 | """The category number for this diagnostic.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 329 | return lib.clang_getDiagnosticCategory(self) |
Tobias Grosser | ea40382 | 2012-02-05 11:41:58 +0000 | [diff] [blame] | 330 | |
| 331 | @property |
| 332 | def category_name(self): |
| 333 | """The string name of the category for this diagnostic.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 334 | return lib.clang_getDiagnosticCategoryName(self.category_number) |
Tobias Grosser | ea40382 | 2012-02-05 11:41:58 +0000 | [diff] [blame] | 335 | |
| 336 | @property |
| 337 | def option(self): |
| 338 | """The command-line option that enables this diagnostic.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 339 | return lib.clang_getDiagnosticOption(self, None) |
Tobias Grosser | ea40382 | 2012-02-05 11:41:58 +0000 | [diff] [blame] | 340 | |
| 341 | @property |
| 342 | def disable_option(self): |
| 343 | """The command-line option that disables this diagnostic.""" |
| 344 | disable = _CXString() |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 345 | lib.clang_getDiagnosticOption(self, byref(disable)) |
Tobias Grosser | ea40382 | 2012-02-05 11:41:58 +0000 | [diff] [blame] | 346 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 347 | return lib.clang_getCString(disable) |
Tobias Grosser | ea40382 | 2012-02-05 11:41:58 +0000 | [diff] [blame] | 348 | |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 349 | def __repr__(self): |
| 350 | return "<Diagnostic severity %r, location %r, spelling %r>" % ( |
| 351 | self.severity, self.location, self.spelling) |
| 352 | |
Tobias Grosser | ff090ca | 2011-02-05 17:53:48 +0000 | [diff] [blame] | 353 | def from_param(self): |
| 354 | return self.ptr |
| 355 | |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 356 | class FixIt(object): |
| 357 | """ |
| 358 | A FixIt represents a transformation to be applied to the source to |
| 359 | "fix-it". The fix-it shouldbe applied by replacing the given source range |
| 360 | with the given value. |
| 361 | """ |
| 362 | |
| 363 | def __init__(self, range, value): |
| 364 | self.range = range |
| 365 | self.value = value |
| 366 | |
| 367 | def __repr__(self): |
| 368 | return "<FixIt range %r, value %r>" % (self.range, self.value) |
| 369 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 370 | ### Cursor Kinds ### |
| 371 | |
| 372 | class CursorKind(object): |
| 373 | """ |
| 374 | A CursorKind describes the kind of entity that a cursor points to. |
| 375 | """ |
| 376 | |
| 377 | # The unique kind objects, indexed by id. |
| 378 | _kinds = [] |
| 379 | _name_map = None |
| 380 | |
| 381 | def __init__(self, value): |
| 382 | if value >= len(CursorKind._kinds): |
| 383 | CursorKind._kinds += [None] * (value - len(CursorKind._kinds) + 1) |
| 384 | if CursorKind._kinds[value] is not None: |
| 385 | raise ValueError,'CursorKind already loaded' |
| 386 | self.value = value |
| 387 | CursorKind._kinds[value] = self |
| 388 | CursorKind._name_map = None |
| 389 | |
| 390 | def from_param(self): |
| 391 | return self.value |
| 392 | |
| 393 | @property |
| 394 | def name(self): |
| 395 | """Get the enumeration name of this cursor kind.""" |
| 396 | if self._name_map is None: |
| 397 | self._name_map = {} |
| 398 | for key,value in CursorKind.__dict__.items(): |
| 399 | if isinstance(value,CursorKind): |
| 400 | self._name_map[value] = key |
| 401 | return self._name_map[self] |
| 402 | |
| 403 | @staticmethod |
| 404 | def from_id(id): |
| 405 | if id >= len(CursorKind._kinds) or CursorKind._kinds[id] is None: |
| 406 | raise ValueError,'Unknown cursor kind' |
| 407 | return CursorKind._kinds[id] |
| 408 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 409 | @staticmethod |
| 410 | def get_all_kinds(): |
Daniel Dunbar | 4efd632 | 2010-01-25 00:43:08 +0000 | [diff] [blame] | 411 | """Return all CursorKind enumeration instances.""" |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 412 | return filter(None, CursorKind._kinds) |
| 413 | |
| 414 | def is_declaration(self): |
| 415 | """Test if this is a declaration kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 416 | return lib.clang_isDeclaration(self) |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 417 | |
| 418 | def is_reference(self): |
| 419 | """Test if this is a reference kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 420 | return lib.clang_isReference(self) |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 421 | |
| 422 | def is_expression(self): |
| 423 | """Test if this is an expression kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 424 | return lib.clang_isExpression(self) |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 425 | |
| 426 | def is_statement(self): |
| 427 | """Test if this is a statement kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 428 | return lib.clang_isStatement(self) |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | 8be80e1 | 2011-07-06 03:00:34 +0000 | [diff] [blame] | 430 | def is_attribute(self): |
| 431 | """Test if this is an attribute kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 432 | return lib.clang_isAttribute(self) |
Douglas Gregor | 8be80e1 | 2011-07-06 03:00:34 +0000 | [diff] [blame] | 433 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 434 | def is_invalid(self): |
| 435 | """Test if this is an invalid kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 436 | return lib.clang_isInvalid(self) |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 437 | |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 438 | def is_translation_unit(self): |
| 439 | """Test if this is a translation unit kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 440 | return lib.clang_isTranslationUnit(self) |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 441 | |
| 442 | def is_preprocessing(self): |
| 443 | """Test if this is a preprocessing kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 444 | return lib.clang_isPreprocessing(self) |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 445 | |
| 446 | def is_unexposed(self): |
| 447 | """Test if this is an unexposed kind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 448 | return lib.clang_isUnexposed(self) |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 449 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 450 | def __repr__(self): |
| 451 | return 'CursorKind.%s' % (self.name,) |
| 452 | |
| 453 | # FIXME: Is there a nicer way to expose this enumeration? We could potentially |
| 454 | # represent the nested structure, or even build a class hierarchy. The main |
| 455 | # things we want for sure are (a) simple external access to kinds, (b) a place |
| 456 | # to hang a description and name, (c) easy to keep in sync with Index.h. |
| 457 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 458 | ### |
| 459 | # Declaration Kinds |
| 460 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 461 | # A declaration whose specific kind is not exposed via this interface. |
| 462 | # |
| 463 | # Unexposed declarations have the same operations as any other kind of |
| 464 | # declaration; one can extract their location information, spelling, find their |
| 465 | # definitions, etc. However, the specific kind of the declaration is not |
| 466 | # reported. |
| 467 | CursorKind.UNEXPOSED_DECL = CursorKind(1) |
| 468 | |
| 469 | # A C or C++ struct. |
| 470 | CursorKind.STRUCT_DECL = CursorKind(2) |
| 471 | |
| 472 | # A C or C++ union. |
| 473 | CursorKind.UNION_DECL = CursorKind(3) |
| 474 | |
| 475 | # A C++ class. |
| 476 | CursorKind.CLASS_DECL = CursorKind(4) |
| 477 | |
| 478 | # An enumeration. |
| 479 | CursorKind.ENUM_DECL = CursorKind(5) |
| 480 | |
| 481 | # A field (in C) or non-static data member (in C++) in a struct, union, or C++ |
| 482 | # class. |
| 483 | CursorKind.FIELD_DECL = CursorKind(6) |
| 484 | |
| 485 | # An enumerator constant. |
| 486 | CursorKind.ENUM_CONSTANT_DECL = CursorKind(7) |
| 487 | |
| 488 | # A function. |
| 489 | CursorKind.FUNCTION_DECL = CursorKind(8) |
| 490 | |
| 491 | # A variable. |
| 492 | CursorKind.VAR_DECL = CursorKind(9) |
| 493 | |
| 494 | # A function or method parameter. |
| 495 | CursorKind.PARM_DECL = CursorKind(10) |
| 496 | |
| 497 | # An Objective-C @interface. |
| 498 | CursorKind.OBJC_INTERFACE_DECL = CursorKind(11) |
| 499 | |
| 500 | # An Objective-C @interface for a category. |
| 501 | CursorKind.OBJC_CATEGORY_DECL = CursorKind(12) |
| 502 | |
| 503 | # An Objective-C @protocol declaration. |
| 504 | CursorKind.OBJC_PROTOCOL_DECL = CursorKind(13) |
| 505 | |
| 506 | # An Objective-C @property declaration. |
| 507 | CursorKind.OBJC_PROPERTY_DECL = CursorKind(14) |
| 508 | |
| 509 | # An Objective-C instance variable. |
| 510 | CursorKind.OBJC_IVAR_DECL = CursorKind(15) |
| 511 | |
| 512 | # An Objective-C instance method. |
| 513 | CursorKind.OBJC_INSTANCE_METHOD_DECL = CursorKind(16) |
| 514 | |
| 515 | # An Objective-C class method. |
| 516 | CursorKind.OBJC_CLASS_METHOD_DECL = CursorKind(17) |
| 517 | |
| 518 | # An Objective-C @implementation. |
| 519 | CursorKind.OBJC_IMPLEMENTATION_DECL = CursorKind(18) |
| 520 | |
| 521 | # An Objective-C @implementation for a category. |
| 522 | CursorKind.OBJC_CATEGORY_IMPL_DECL = CursorKind(19) |
| 523 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 524 | # A typedef. |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 525 | CursorKind.TYPEDEF_DECL = CursorKind(20) |
| 526 | |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 527 | # A C++ class method. |
| 528 | CursorKind.CXX_METHOD = CursorKind(21) |
| 529 | |
| 530 | # A C++ namespace. |
| 531 | CursorKind.NAMESPACE = CursorKind(22) |
| 532 | |
| 533 | # A linkage specification, e.g. 'extern "C"'. |
| 534 | CursorKind.LINKAGE_SPEC = CursorKind(23) |
| 535 | |
| 536 | # A C++ constructor. |
| 537 | CursorKind.CONSTRUCTOR = CursorKind(24) |
| 538 | |
| 539 | # A C++ destructor. |
| 540 | CursorKind.DESTRUCTOR = CursorKind(25) |
| 541 | |
| 542 | # A C++ conversion function. |
| 543 | CursorKind.CONVERSION_FUNCTION = CursorKind(26) |
| 544 | |
| 545 | # A C++ template type parameter |
| 546 | CursorKind.TEMPLATE_TYPE_PARAMETER = CursorKind(27) |
| 547 | |
| 548 | # A C++ non-type template paramater. |
| 549 | CursorKind.TEMPLATE_NON_TYPE_PARAMETER = CursorKind(28) |
| 550 | |
| 551 | # A C++ template template parameter. |
| 552 | CursorKind.TEMPLATE_TEMPLATE_PARAMTER = CursorKind(29) |
| 553 | |
| 554 | # A C++ function template. |
| 555 | CursorKind.FUNCTION_TEMPLATE = CursorKind(30) |
| 556 | |
| 557 | # A C++ class template. |
| 558 | CursorKind.CLASS_TEMPLATE = CursorKind(31) |
| 559 | |
| 560 | # A C++ class template partial specialization. |
| 561 | CursorKind.CLASS_TEMPLATE_PARTIAL_SPECIALIZATION = CursorKind(32) |
| 562 | |
| 563 | # A C++ namespace alias declaration. |
| 564 | CursorKind.NAMESPACE_ALIAS = CursorKind(33) |
| 565 | |
| 566 | # A C++ using directive |
| 567 | CursorKind.USING_DIRECTIVE = CursorKind(34) |
| 568 | |
| 569 | # A C++ using declaration |
| 570 | CursorKind.USING_DECLARATION = CursorKind(35) |
| 571 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 572 | # A Type alias decl. |
| 573 | CursorKind.TYPE_ALIAS_DECL = CursorKind(36) |
| 574 | |
| 575 | # A Objective-C synthesize decl |
| 576 | CursorKind.OBJC_SYNTHESIZE_DECL = CursorKind(37) |
| 577 | |
| 578 | # A Objective-C dynamic decl |
| 579 | CursorKind.OBJC_DYNAMIC_DECL = CursorKind(38) |
| 580 | |
| 581 | # A C++ access specifier decl. |
| 582 | CursorKind.CXX_ACCESS_SPEC_DECL = CursorKind(39) |
| 583 | |
| 584 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 585 | ### |
| 586 | # Reference Kinds |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 587 | |
| 588 | CursorKind.OBJC_SUPER_CLASS_REF = CursorKind(40) |
| 589 | CursorKind.OBJC_PROTOCOL_REF = CursorKind(41) |
| 590 | CursorKind.OBJC_CLASS_REF = CursorKind(42) |
| 591 | |
| 592 | # A reference to a type declaration. |
| 593 | # |
| 594 | # A type reference occurs anywhere where a type is named but not |
| 595 | # declared. For example, given: |
| 596 | # typedef unsigned size_type; |
| 597 | # size_type size; |
| 598 | # |
| 599 | # The typedef is a declaration of size_type (CXCursor_TypedefDecl), |
| 600 | # while the type of the variable "size" is referenced. The cursor |
| 601 | # referenced by the type of size is the typedef for size_type. |
| 602 | CursorKind.TYPE_REF = CursorKind(43) |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 603 | CursorKind.CXX_BASE_SPECIFIER = CursorKind(44) |
| 604 | |
| 605 | # A reference to a class template, function template, template |
| 606 | # template parameter, or class template partial specialization. |
| 607 | CursorKind.TEMPLATE_REF = CursorKind(45) |
| 608 | |
| 609 | # A reference to a namespace or namepsace alias. |
| 610 | CursorKind.NAMESPACE_REF = CursorKind(46) |
| 611 | |
| 612 | # A reference to a member of a struct, union, or class that occurs in |
| 613 | # some non-expression context, e.g., a designated initializer. |
| 614 | CursorKind.MEMBER_REF = CursorKind(47) |
| 615 | |
| 616 | # A reference to a labeled statement. |
| 617 | CursorKind.LABEL_REF = CursorKind(48) |
| 618 | |
| 619 | # A reference toa a set of overloaded functions or function templates |
| 620 | # that has not yet been resolved to a specific function or function template. |
| 621 | CursorKind.OVERLOADED_DECL_REF = CursorKind(49) |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 622 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 623 | ### |
| 624 | # Invalid/Error Kinds |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 625 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 626 | CursorKind.INVALID_FILE = CursorKind(70) |
| 627 | CursorKind.NO_DECL_FOUND = CursorKind(71) |
| 628 | CursorKind.NOT_IMPLEMENTED = CursorKind(72) |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 629 | CursorKind.INVALID_CODE = CursorKind(73) |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 630 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 631 | ### |
| 632 | # Expression Kinds |
| 633 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 634 | # An expression whose specific kind is not exposed via this interface. |
| 635 | # |
| 636 | # Unexposed expressions have the same operations as any other kind of |
| 637 | # expression; one can extract their location information, spelling, children, |
| 638 | # etc. However, the specific kind of the expression is not reported. |
| 639 | CursorKind.UNEXPOSED_EXPR = CursorKind(100) |
| 640 | |
| 641 | # An expression that refers to some value declaration, such as a function, |
| 642 | # varible, or enumerator. |
| 643 | CursorKind.DECL_REF_EXPR = CursorKind(101) |
| 644 | |
| 645 | # An expression that refers to a member of a struct, union, class, Objective-C |
| 646 | # class, etc. |
| 647 | CursorKind.MEMBER_REF_EXPR = CursorKind(102) |
| 648 | |
| 649 | # An expression that calls a function. |
| 650 | CursorKind.CALL_EXPR = CursorKind(103) |
| 651 | |
| 652 | # An expression that sends a message to an Objective-C object or class. |
| 653 | CursorKind.OBJC_MESSAGE_EXPR = CursorKind(104) |
| 654 | |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 655 | # An expression that represents a block literal. |
| 656 | CursorKind.BLOCK_EXPR = CursorKind(105) |
| 657 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 658 | # An integer literal. |
| 659 | CursorKind.INTEGER_LITERAL = CursorKind(106) |
| 660 | |
| 661 | # A floating point number literal. |
| 662 | CursorKind.FLOATING_LITERAL = CursorKind(107) |
| 663 | |
| 664 | # An imaginary number literal. |
| 665 | CursorKind.IMAGINARY_LITERAL = CursorKind(108) |
| 666 | |
| 667 | # A string literal. |
| 668 | CursorKind.STRING_LITERAL = CursorKind(109) |
| 669 | |
| 670 | # A character literal. |
| 671 | CursorKind.CHARACTER_LITERAL = CursorKind(110) |
| 672 | |
| 673 | # A parenthesized expression, e.g. "(1)". |
| 674 | # |
| 675 | # This AST node is only formed if full location information is requested. |
| 676 | CursorKind.PAREN_EXPR = CursorKind(111) |
| 677 | |
| 678 | # This represents the unary-expression's (except sizeof and |
| 679 | # alignof). |
| 680 | CursorKind.UNARY_OPERATOR = CursorKind(112) |
| 681 | |
| 682 | # [C99 6.5.2.1] Array Subscripting. |
| 683 | CursorKind.ARRAY_SUBSCRIPT_EXPR = CursorKind(113) |
| 684 | |
| 685 | # A builtin binary operation expression such as "x + y" or |
| 686 | # "x <= y". |
| 687 | CursorKind.BINARY_OPERATOR = CursorKind(114) |
| 688 | |
| 689 | # Compound assignment such as "+=". |
| 690 | CursorKind.COMPOUND_ASSIGNMENT_OPERATOR = CursorKind(115) |
| 691 | |
| 692 | # The ?: ternary operator. |
Douglas Gregor | 39a03d1 | 2012-06-08 00:16:27 +0000 | [diff] [blame] | 693 | CursorKind.CONDITIONAL_OPERATOR = CursorKind(116) |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 694 | |
| 695 | # An explicit cast in C (C99 6.5.4) or a C-style cast in C++ |
| 696 | # (C++ [expr.cast]), which uses the syntax (Type)expr. |
| 697 | # |
| 698 | # For example: (int)f. |
| 699 | CursorKind.CSTYLE_CAST_EXPR = CursorKind(117) |
| 700 | |
| 701 | # [C99 6.5.2.5] |
| 702 | CursorKind.COMPOUND_LITERAL_EXPR = CursorKind(118) |
| 703 | |
| 704 | # Describes an C or C++ initializer list. |
| 705 | CursorKind.INIT_LIST_EXPR = CursorKind(119) |
| 706 | |
| 707 | # The GNU address of label extension, representing &&label. |
| 708 | CursorKind.ADDR_LABEL_EXPR = CursorKind(120) |
| 709 | |
| 710 | # This is the GNU Statement Expression extension: ({int X=4; X;}) |
| 711 | CursorKind.StmtExpr = CursorKind(121) |
| 712 | |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 713 | # Represents a C11 generic selection. |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 714 | CursorKind.GENERIC_SELECTION_EXPR = CursorKind(122) |
| 715 | |
| 716 | # Implements the GNU __null extension, which is a name for a null |
| 717 | # pointer constant that has integral type (e.g., int or long) and is the same |
| 718 | # size and alignment as a pointer. |
| 719 | # |
| 720 | # The __null extension is typically only used by system headers, which define |
| 721 | # NULL as __null in C++ rather than using 0 (which is an integer that may not |
| 722 | # match the size of a pointer). |
| 723 | CursorKind.GNU_NULL_EXPR = CursorKind(123) |
| 724 | |
| 725 | # C++'s static_cast<> expression. |
| 726 | CursorKind.CXX_STATIC_CAST_EXPR = CursorKind(124) |
| 727 | |
| 728 | # C++'s dynamic_cast<> expression. |
| 729 | CursorKind.CXX_DYNAMIC_CAST_EXPR = CursorKind(125) |
| 730 | |
| 731 | # C++'s reinterpret_cast<> expression. |
| 732 | CursorKind.CXX_REINTERPRET_CAST_EXPR = CursorKind(126) |
| 733 | |
| 734 | # C++'s const_cast<> expression. |
| 735 | CursorKind.CXX_CONST_CAST_EXPR = CursorKind(127) |
| 736 | |
| 737 | # Represents an explicit C++ type conversion that uses "functional" |
| 738 | # notion (C++ [expr.type.conv]). |
| 739 | # |
| 740 | # Example: |
| 741 | # \code |
| 742 | # x = int(0.5); |
| 743 | # \endcode |
| 744 | CursorKind.CXX_FUNCTIONAL_CAST_EXPR = CursorKind(128) |
| 745 | |
| 746 | # A C++ typeid expression (C++ [expr.typeid]). |
| 747 | CursorKind.CXX_TYPEID_EXPR = CursorKind(129) |
| 748 | |
| 749 | # [C++ 2.13.5] C++ Boolean Literal. |
| 750 | CursorKind.CXX_BOOL_LITERAL_EXPR = CursorKind(130) |
| 751 | |
| 752 | # [C++0x 2.14.7] C++ Pointer Literal. |
| 753 | CursorKind.CXX_NULL_PTR_LITERAL_EXPR = CursorKind(131) |
| 754 | |
| 755 | # Represents the "this" expression in C++ |
| 756 | CursorKind.CXX_THIS_EXPR = CursorKind(132) |
| 757 | |
| 758 | # [C++ 15] C++ Throw Expression. |
| 759 | # |
| 760 | # This handles 'throw' and 'throw' assignment-expression. When |
| 761 | # assignment-expression isn't present, Op will be null. |
| 762 | CursorKind.CXX_THROW_EXPR = CursorKind(133) |
| 763 | |
| 764 | # A new expression for memory allocation and constructor calls, e.g: |
| 765 | # "new CXXNewExpr(foo)". |
| 766 | CursorKind.CXX_NEW_EXPR = CursorKind(134) |
| 767 | |
| 768 | # A delete expression for memory deallocation and destructor calls, |
| 769 | # e.g. "delete[] pArray". |
| 770 | CursorKind.CXX_DELETE_EXPR = CursorKind(135) |
| 771 | |
| 772 | # Represents a unary expression. |
| 773 | CursorKind.CXX_UNARY_EXPR = CursorKind(136) |
| 774 | |
| 775 | # ObjCStringLiteral, used for Objective-C string literals i.e. "foo". |
| 776 | CursorKind.OBJC_STRING_LITERAL = CursorKind(137) |
| 777 | |
| 778 | # ObjCEncodeExpr, used for in Objective-C. |
| 779 | CursorKind.OBJC_ENCODE_EXPR = CursorKind(138) |
| 780 | |
| 781 | # ObjCSelectorExpr used for in Objective-C. |
| 782 | CursorKind.OBJC_SELECTOR_EXPR = CursorKind(139) |
| 783 | |
| 784 | # Objective-C's protocol expression. |
| 785 | CursorKind.OBJC_PROTOCOL_EXPR = CursorKind(140) |
| 786 | |
| 787 | # An Objective-C "bridged" cast expression, which casts between |
| 788 | # Objective-C pointers and C pointers, transferring ownership in the process. |
| 789 | # |
| 790 | # \code |
| 791 | # NSString *str = (__bridge_transfer NSString *)CFCreateString(); |
| 792 | # \endcode |
| 793 | CursorKind.OBJC_BRIDGE_CAST_EXPR = CursorKind(141) |
| 794 | |
| 795 | # Represents a C++0x pack expansion that produces a sequence of |
| 796 | # expressions. |
| 797 | # |
| 798 | # A pack expansion expression contains a pattern (which itself is an |
| 799 | # expression) followed by an ellipsis. For example: |
| 800 | CursorKind.PACK_EXPANSION_EXPR = CursorKind(142) |
| 801 | |
| 802 | # Represents an expression that computes the length of a parameter |
| 803 | # pack. |
| 804 | CursorKind.SIZE_OF_PACK_EXPR = CursorKind(143) |
| 805 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 806 | # A statement whose specific kind is not exposed via this interface. |
| 807 | # |
| 808 | # Unexposed statements have the same operations as any other kind of statement; |
| 809 | # one can extract their location information, spelling, children, etc. However, |
| 810 | # the specific kind of the statement is not reported. |
| 811 | CursorKind.UNEXPOSED_STMT = CursorKind(200) |
| 812 | |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 813 | # A labelled statement in a function. |
| 814 | CursorKind.LABEL_STMT = CursorKind(201) |
| 815 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 816 | # A compound statement |
| 817 | CursorKind.COMPOUND_STMT = CursorKind(202) |
| 818 | |
| 819 | # A case statement. |
| 820 | CursorKind.CASE_STMT = CursorKind(203) |
| 821 | |
| 822 | # A default statement. |
| 823 | CursorKind.DEFAULT_STMT = CursorKind(204) |
| 824 | |
| 825 | # An if statement. |
| 826 | CursorKind.IF_STMT = CursorKind(205) |
| 827 | |
| 828 | # A switch statement. |
| 829 | CursorKind.SWITCH_STMT = CursorKind(206) |
| 830 | |
| 831 | # A while statement. |
| 832 | CursorKind.WHILE_STMT = CursorKind(207) |
| 833 | |
| 834 | # A do statement. |
| 835 | CursorKind.DO_STMT = CursorKind(208) |
| 836 | |
| 837 | # A for statement. |
| 838 | CursorKind.FOR_STMT = CursorKind(209) |
| 839 | |
| 840 | # A goto statement. |
| 841 | CursorKind.GOTO_STMT = CursorKind(210) |
| 842 | |
| 843 | # An indirect goto statement. |
| 844 | CursorKind.INDIRECT_GOTO_STMT = CursorKind(211) |
| 845 | |
| 846 | # A continue statement. |
| 847 | CursorKind.CONTINUE_STMT = CursorKind(212) |
| 848 | |
| 849 | # A break statement. |
| 850 | CursorKind.BREAK_STMT = CursorKind(213) |
| 851 | |
| 852 | # A return statement. |
| 853 | CursorKind.RETURN_STMT = CursorKind(214) |
| 854 | |
| 855 | # A GNU-style inline assembler statement. |
| 856 | CursorKind.ASM_STMT = CursorKind(215) |
| 857 | |
| 858 | # Objective-C's overall @try-@catch-@finally statement. |
| 859 | CursorKind.OBJC_AT_TRY_STMT = CursorKind(216) |
| 860 | |
| 861 | # Objective-C's @catch statement. |
| 862 | CursorKind.OBJC_AT_CATCH_STMT = CursorKind(217) |
| 863 | |
| 864 | # Objective-C's @finally statement. |
| 865 | CursorKind.OBJC_AT_FINALLY_STMT = CursorKind(218) |
| 866 | |
| 867 | # Objective-C's @throw statement. |
| 868 | CursorKind.OBJC_AT_THROW_STMT = CursorKind(219) |
| 869 | |
| 870 | # Objective-C's @synchronized statement. |
| 871 | CursorKind.OBJC_AT_SYNCHRONIZED_STMT = CursorKind(220) |
| 872 | |
| 873 | # Objective-C's autorealease pool statement. |
| 874 | CursorKind.OBJC_AUTORELEASE_POOL_STMT = CursorKind(221) |
| 875 | |
| 876 | # Objective-C's for collection statement. |
| 877 | CursorKind.OBJC_FOR_COLLECTION_STMT = CursorKind(222) |
| 878 | |
| 879 | # C++'s catch statement. |
| 880 | CursorKind.CXX_CATCH_STMT = CursorKind(223) |
| 881 | |
| 882 | # C++'s try statement. |
| 883 | CursorKind.CXX_TRY_STMT = CursorKind(224) |
| 884 | |
| 885 | # C++'s for (* : *) statement. |
| 886 | CursorKind.CXX_FOR_RANGE_STMT = CursorKind(225) |
| 887 | |
| 888 | # Windows Structured Exception Handling's try statement. |
| 889 | CursorKind.SEH_TRY_STMT = CursorKind(226) |
| 890 | |
| 891 | # Windows Structured Exception Handling's except statement. |
| 892 | CursorKind.SEH_EXCEPT_STMT = CursorKind(227) |
| 893 | |
| 894 | # Windows Structured Exception Handling's finally statement. |
| 895 | CursorKind.SEH_FINALLY_STMT = CursorKind(228) |
| 896 | |
| 897 | # The null statement. |
| 898 | CursorKind.NULL_STMT = CursorKind(230) |
| 899 | |
| 900 | # Adaptor class for mixing declarations with statements and expressions. |
| 901 | CursorKind.DECL_STMT = CursorKind(231) |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 902 | |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 903 | ### |
| 904 | # Other Kinds |
| 905 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 906 | # Cursor that represents the translation unit itself. |
| 907 | # |
| 908 | # The translation unit cursor exists primarily to act as the root cursor for |
| 909 | # traversing the contents of a translation unit. |
| 910 | CursorKind.TRANSLATION_UNIT = CursorKind(300) |
| 911 | |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 912 | ### |
| 913 | # Attributes |
| 914 | |
| 915 | # An attribute whoe specific kind is note exposed via this interface |
| 916 | CursorKind.UNEXPOSED_ATTR = CursorKind(400) |
| 917 | |
| 918 | CursorKind.IB_ACTION_ATTR = CursorKind(401) |
| 919 | CursorKind.IB_OUTLET_ATTR = CursorKind(402) |
| 920 | CursorKind.IB_OUTLET_COLLECTION_ATTR = CursorKind(403) |
| 921 | |
Rafael Espindola | bf3cc73 | 2011-12-30 15:27:22 +0000 | [diff] [blame] | 922 | CursorKind.CXX_FINAL_ATTR = CursorKind(404) |
| 923 | CursorKind.CXX_OVERRIDE_ATTR = CursorKind(405) |
| 924 | CursorKind.ANNOTATE_ATTR = CursorKind(406) |
| 925 | CursorKind.ASM_LABEL_ATTR = CursorKind(407) |
| 926 | |
Tobias Grosser | 4ed73ce | 2011-02-05 17:53:47 +0000 | [diff] [blame] | 927 | ### |
| 928 | # Preprocessing |
| 929 | CursorKind.PREPROCESSING_DIRECTIVE = CursorKind(500) |
| 930 | CursorKind.MACRO_DEFINITION = CursorKind(501) |
| 931 | CursorKind.MACRO_INSTANTIATION = CursorKind(502) |
| 932 | CursorKind.INCLUSION_DIRECTIVE = CursorKind(503) |
| 933 | |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 934 | ### Cursors ### |
| 935 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 936 | class Cursor(Structure): |
| 937 | """ |
| 938 | The Cursor class represents a reference to an element within the AST. It |
| 939 | acts as a kind of iterator. |
| 940 | """ |
Douglas Gregor | 2abfec3 | 2011-10-19 05:47:46 +0000 | [diff] [blame] | 941 | _fields_ = [("_kind_id", c_int), ("xdata", c_int), ("data", c_void_p * 3)] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 942 | |
Tobias Grosser | 58ba8c9 | 2011-10-31 00:31:32 +0000 | [diff] [blame] | 943 | @staticmethod |
| 944 | def from_location(tu, location): |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 945 | # We store a reference to the TU in the instance so the TU won't get |
| 946 | # collected before the cursor. |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 947 | cursor = lib.clang_getCursor(tu, location) |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 948 | cursor._tu = tu |
| 949 | |
| 950 | return cursor |
Tobias Grosser | 58ba8c9 | 2011-10-31 00:31:32 +0000 | [diff] [blame] | 951 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 952 | def __eq__(self, other): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 953 | return lib.clang_equalCursors(self, other) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 954 | |
| 955 | def __ne__(self, other): |
Gregory Szorc | 9d008fd | 2012-03-05 00:42:15 +0000 | [diff] [blame] | 956 | return not self.__eq__(other) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 957 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 958 | def is_definition(self): |
| 959 | """ |
| 960 | Returns true if the declaration pointed at by the cursor is also a |
| 961 | definition of that entity. |
| 962 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 963 | return lib.clang_isCursorDefinition(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 964 | |
Gregory Szorc | e65b34d | 2012-06-09 16:21:34 +0000 | [diff] [blame] | 965 | def is_static_method(self): |
| 966 | """Returns True if the cursor refers to a C++ member function or member |
| 967 | function template that is declared 'static'. |
| 968 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 969 | return lib.clang_CXXMethod_isStatic(self) |
Gregory Szorc | e65b34d | 2012-06-09 16:21:34 +0000 | [diff] [blame] | 970 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 971 | def get_definition(self): |
| 972 | """ |
| 973 | If the cursor is a reference to a declaration or a declaration of |
| 974 | some entity, return a cursor that points to the definition of that |
| 975 | entity. |
| 976 | """ |
| 977 | # TODO: Should probably check that this is either a reference or |
| 978 | # declaration prior to issuing the lookup. |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 979 | return lib.clang_getCursorDefinition(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 980 | |
Daniel Dunbar | 3d855f8 | 2010-01-24 21:20:13 +0000 | [diff] [blame] | 981 | def get_usr(self): |
| 982 | """Return the Unified Symbol Resultion (USR) for the entity referenced |
| 983 | by the given cursor (or None). |
| 984 | |
| 985 | A Unified Symbol Resolution (USR) is a string that identifies a |
| 986 | particular entity (function, class, variable, etc.) within a |
| 987 | program. USRs can be compared across translation units to determine, |
| 988 | e.g., when references in one translation refer to an entity defined in |
| 989 | another translation unit.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 990 | return lib.clang_getCursorUSR(self) |
Daniel Dunbar | 3d855f8 | 2010-01-24 21:20:13 +0000 | [diff] [blame] | 991 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 992 | @property |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 993 | def kind(self): |
| 994 | """Return the kind of this cursor.""" |
| 995 | return CursorKind.from_id(self._kind_id) |
| 996 | |
| 997 | @property |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 998 | def spelling(self): |
| 999 | """Return the spelling of the entity pointed at by the cursor.""" |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 1000 | if not self.kind.is_declaration(): |
Daniel Dunbar | 3d855f8 | 2010-01-24 21:20:13 +0000 | [diff] [blame] | 1001 | # FIXME: clang_getCursorSpelling should be fixed to not assert on |
| 1002 | # this, for consistency with clang_getCursorUSR. |
| 1003 | return None |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1004 | if not hasattr(self, '_spelling'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1005 | self._spelling = lib.clang_getCursorSpelling(self) |
| 1006 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1007 | return self._spelling |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1008 | |
| 1009 | @property |
Douglas Gregor | b60a2be | 2011-08-30 00:15:34 +0000 | [diff] [blame] | 1010 | def displayname(self): |
| 1011 | """ |
| 1012 | Return the display name for the entity referenced by this cursor. |
| 1013 | |
| 1014 | The display name contains extra information that helps identify the cursor, |
| 1015 | such as the parameters of a function or template or the arguments of a |
| 1016 | class template specialization. |
| 1017 | """ |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1018 | if not hasattr(self, '_displayname'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1019 | self._displayname = lib.clang_getCursorDisplayName(self) |
| 1020 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1021 | return self._displayname |
Douglas Gregor | b60a2be | 2011-08-30 00:15:34 +0000 | [diff] [blame] | 1022 | |
| 1023 | @property |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1024 | def location(self): |
| 1025 | """ |
| 1026 | Return the source location (the starting character) of the entity |
| 1027 | pointed at by the cursor. |
| 1028 | """ |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1029 | if not hasattr(self, '_loc'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1030 | self._loc = lib.clang_getCursorLocation(self) |
| 1031 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1032 | return self._loc |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1033 | |
| 1034 | @property |
| 1035 | def extent(self): |
| 1036 | """ |
| 1037 | Return the source range (the range of text) occupied by the entity |
| 1038 | pointed at by the cursor. |
| 1039 | """ |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1040 | if not hasattr(self, '_extent'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1041 | self._extent = lib.clang_getCursorExtent(self) |
| 1042 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1043 | return self._extent |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1044 | |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1045 | @property |
| 1046 | def type(self): |
| 1047 | """ |
Tobias Grosser | 2d10680 | 2012-02-05 12:15:56 +0000 | [diff] [blame] | 1048 | Retrieve the Type (if any) of the entity pointed at by the cursor. |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1049 | """ |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1050 | if not hasattr(self, '_type'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1051 | self._type = lib.clang_getCursorType(self) |
| 1052 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 1053 | return self._type |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1054 | |
Tobias Grosser | 64e7bdc | 2012-02-05 11:42:03 +0000 | [diff] [blame] | 1055 | @property |
Gregory Szorc | 2c40835 | 2012-05-14 03:56:33 +0000 | [diff] [blame] | 1056 | def canonical(self): |
| 1057 | """Return the canonical Cursor corresponding to this Cursor. |
| 1058 | |
| 1059 | The canonical cursor is the cursor which is representative for the |
| 1060 | underlying entity. For example, if you have multiple forward |
| 1061 | declarations for the same class, the canonical cursor for the forward |
| 1062 | declarations will be identical. |
| 1063 | """ |
| 1064 | if not hasattr(self, '_canonical'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1065 | self._canonical = lib.clang_getCanonicalCursor(self) |
Gregory Szorc | 2c40835 | 2012-05-14 03:56:33 +0000 | [diff] [blame] | 1066 | |
| 1067 | return self._canonical |
| 1068 | |
| 1069 | @property |
Gregory Szorc | 1e370ab | 2012-05-14 03:53:29 +0000 | [diff] [blame] | 1070 | def result_type(self): |
| 1071 | """Retrieve the Type of the result for this Cursor.""" |
| 1072 | if not hasattr(self, '_result_type'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1073 | self._result_type = lib.clang_getResultType(self.type) |
Gregory Szorc | 1e370ab | 2012-05-14 03:53:29 +0000 | [diff] [blame] | 1074 | |
| 1075 | return self._result_type |
| 1076 | |
| 1077 | @property |
Tobias Grosser | 28d939f | 2012-02-05 11:42:20 +0000 | [diff] [blame] | 1078 | def underlying_typedef_type(self): |
| 1079 | """Return the underlying type of a typedef declaration. |
| 1080 | |
Tobias Grosser | 2d10680 | 2012-02-05 12:15:56 +0000 | [diff] [blame] | 1081 | Returns a Type for the typedef this cursor is a declaration for. If |
Tobias Grosser | 28d939f | 2012-02-05 11:42:20 +0000 | [diff] [blame] | 1082 | the current cursor is not a typedef, this raises. |
| 1083 | """ |
| 1084 | if not hasattr(self, '_underlying_type'): |
| 1085 | assert self.kind.is_declaration() |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1086 | self._underlying_type = lib.clang_getTypedefDeclUnderlyingType(self) |
Tobias Grosser | 28d939f | 2012-02-05 11:42:20 +0000 | [diff] [blame] | 1087 | |
| 1088 | return self._underlying_type |
| 1089 | |
| 1090 | @property |
Tobias Grosser | eb9ff2e | 2012-02-05 11:42:25 +0000 | [diff] [blame] | 1091 | def enum_type(self): |
| 1092 | """Return the integer type of an enum declaration. |
| 1093 | |
Tobias Grosser | 2d10680 | 2012-02-05 12:15:56 +0000 | [diff] [blame] | 1094 | Returns a Type corresponding to an integer. If the cursor is not for an |
Tobias Grosser | eb9ff2e | 2012-02-05 11:42:25 +0000 | [diff] [blame] | 1095 | enum, this raises. |
| 1096 | """ |
| 1097 | if not hasattr(self, '_enum_type'): |
| 1098 | assert self.kind == CursorKind.ENUM_DECL |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1099 | self._enum_type = lib.clang_getEnumDeclIntegerType(self) |
Tobias Grosser | eb9ff2e | 2012-02-05 11:42:25 +0000 | [diff] [blame] | 1100 | |
| 1101 | return self._enum_type |
| 1102 | |
| 1103 | @property |
Anders Waldenborg | bbc2e09 | 2012-05-02 20:57:33 +0000 | [diff] [blame] | 1104 | def enum_value(self): |
| 1105 | """Return the value of an enum constant.""" |
| 1106 | if not hasattr(self, '_enum_value'): |
| 1107 | assert self.kind == CursorKind.ENUM_CONSTANT_DECL |
| 1108 | # Figure out the underlying type of the enum to know if it |
| 1109 | # is a signed or unsigned quantity. |
| 1110 | underlying_type = self.type |
| 1111 | if underlying_type.kind == TypeKind.ENUM: |
| 1112 | underlying_type = underlying_type.get_declaration().enum_type |
| 1113 | if underlying_type.kind in (TypeKind.CHAR_U, |
| 1114 | TypeKind.UCHAR, |
| 1115 | TypeKind.CHAR16, |
| 1116 | TypeKind.CHAR32, |
| 1117 | TypeKind.USHORT, |
| 1118 | TypeKind.UINT, |
| 1119 | TypeKind.ULONG, |
| 1120 | TypeKind.ULONGLONG, |
| 1121 | TypeKind.UINT128): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1122 | self._enum_value = lib.clang_getEnumConstantDeclUnsignedValue(self) |
Anders Waldenborg | bbc2e09 | 2012-05-02 20:57:33 +0000 | [diff] [blame] | 1123 | else: |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1124 | self._enum_value = lib.clang_getEnumConstantDeclValue(self) |
Anders Waldenborg | bbc2e09 | 2012-05-02 20:57:33 +0000 | [diff] [blame] | 1125 | return self._enum_value |
| 1126 | |
| 1127 | @property |
Gregory Szorc | 5cc6787 | 2012-03-10 22:23:27 +0000 | [diff] [blame] | 1128 | def objc_type_encoding(self): |
| 1129 | """Return the Objective-C type encoding as a str.""" |
| 1130 | if not hasattr(self, '_objc_type_encoding'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1131 | self._objc_type_encoding = lib.clang_getDeclObjCTypeEncoding(self) |
Gregory Szorc | 5cc6787 | 2012-03-10 22:23:27 +0000 | [diff] [blame] | 1132 | |
| 1133 | return self._objc_type_encoding |
| 1134 | |
| 1135 | @property |
Tobias Grosser | 64e7bdc | 2012-02-05 11:42:03 +0000 | [diff] [blame] | 1136 | def hash(self): |
| 1137 | """Returns a hash of the cursor as an int.""" |
| 1138 | if not hasattr(self, '_hash'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1139 | self._hash = lib.clang_hashCursor(self) |
Tobias Grosser | 64e7bdc | 2012-02-05 11:42:03 +0000 | [diff] [blame] | 1140 | |
| 1141 | return self._hash |
| 1142 | |
Manuel Klimek | 667fd80 | 2012-05-07 05:56:03 +0000 | [diff] [blame] | 1143 | @property |
| 1144 | def semantic_parent(self): |
| 1145 | """Return the semantic parent for this cursor.""" |
| 1146 | if not hasattr(self, '_semantic_parent'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1147 | self._semantic_parent = lib.clang_getCursorSemanticParent(self) |
Gregory Szorc | fd04a6a | 2012-05-08 06:01:34 +0000 | [diff] [blame] | 1148 | |
Manuel Klimek | 667fd80 | 2012-05-07 05:56:03 +0000 | [diff] [blame] | 1149 | return self._semantic_parent |
| 1150 | |
| 1151 | @property |
| 1152 | def lexical_parent(self): |
| 1153 | """Return the lexical parent for this cursor.""" |
| 1154 | if not hasattr(self, '_lexical_parent'): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1155 | self._lexical_parent = lib.clang_getCursorLexicalParent(self) |
Gregory Szorc | fd04a6a | 2012-05-08 06:01:34 +0000 | [diff] [blame] | 1156 | |
Manuel Klimek | 667fd80 | 2012-05-07 05:56:03 +0000 | [diff] [blame] | 1157 | return self._lexical_parent |
Gregory Szorc | fd04a6a | 2012-05-08 06:01:34 +0000 | [diff] [blame] | 1158 | |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 1159 | @property |
| 1160 | def translation_unit(self): |
| 1161 | """Returns the TranslationUnit to which this Cursor belongs.""" |
| 1162 | # If this triggers an AttributeError, the instance was not properly |
| 1163 | # created. |
| 1164 | return self._tu |
| 1165 | |
Daniel Dunbar | de3b8e5 | 2010-01-24 04:10:22 +0000 | [diff] [blame] | 1166 | def get_children(self): |
Daniel Dunbar | 12bf15c | 2010-01-24 21:20:29 +0000 | [diff] [blame] | 1167 | """Return an iterator for accessing the children of this cursor.""" |
Daniel Dunbar | de3b8e5 | 2010-01-24 04:10:22 +0000 | [diff] [blame] | 1168 | |
| 1169 | # FIXME: Expose iteration from CIndex, PR6125. |
| 1170 | def visitor(child, parent, children): |
Daniel Dunbar | fb8ae17 | 2010-01-24 21:20:05 +0000 | [diff] [blame] | 1171 | # FIXME: Document this assertion in API. |
| 1172 | # FIXME: There should just be an isNull method. |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1173 | assert child != lib.clang_getNullCursor() |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 1174 | |
| 1175 | # Create reference to TU so it isn't GC'd before Cursor. |
| 1176 | child._tu = self._tu |
Daniel Dunbar | de3b8e5 | 2010-01-24 04:10:22 +0000 | [diff] [blame] | 1177 | children.append(child) |
| 1178 | return 1 # continue |
| 1179 | children = [] |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1180 | lib.clang_visitChildren(self, callbacks['cursor_visit'](visitor), |
| 1181 | children) |
Daniel Dunbar | de3b8e5 | 2010-01-24 04:10:22 +0000 | [diff] [blame] | 1182 | return iter(children) |
| 1183 | |
Daniel Dunbar | fb8ae17 | 2010-01-24 21:20:05 +0000 | [diff] [blame] | 1184 | @staticmethod |
| 1185 | def from_result(res, fn, args): |
| 1186 | assert isinstance(res, Cursor) |
| 1187 | # FIXME: There should just be an isNull method. |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1188 | if res == lib.clang_getNullCursor(): |
Daniel Dunbar | fb8ae17 | 2010-01-24 21:20:05 +0000 | [diff] [blame] | 1189 | return None |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 1190 | |
| 1191 | # Store a reference to the TU in the Python object so it won't get GC'd |
| 1192 | # before the Cursor. |
| 1193 | tu = None |
| 1194 | for arg in args: |
| 1195 | if isinstance(arg, TranslationUnit): |
| 1196 | tu = arg |
| 1197 | break |
| 1198 | |
| 1199 | if hasattr(arg, 'translation_unit'): |
| 1200 | tu = arg.translation_unit |
| 1201 | break |
| 1202 | |
| 1203 | assert tu is not None |
| 1204 | |
| 1205 | res._tu = tu |
Daniel Dunbar | fb8ae17 | 2010-01-24 21:20:05 +0000 | [diff] [blame] | 1206 | return res |
| 1207 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1208 | @staticmethod |
| 1209 | def from_cursor_result(res, fn, args): |
| 1210 | assert isinstance(res, Cursor) |
| 1211 | if res == lib.clang_getNullCursor(): |
| 1212 | return None |
| 1213 | |
| 1214 | res._tu = args[0]._tu |
| 1215 | return res |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1216 | |
| 1217 | ### Type Kinds ### |
| 1218 | |
| 1219 | class TypeKind(object): |
| 1220 | """ |
| 1221 | Describes the kind of type. |
| 1222 | """ |
| 1223 | |
| 1224 | # The unique kind objects, indexed by id. |
| 1225 | _kinds = [] |
| 1226 | _name_map = None |
| 1227 | |
| 1228 | def __init__(self, value): |
| 1229 | if value >= len(TypeKind._kinds): |
| 1230 | TypeKind._kinds += [None] * (value - len(TypeKind._kinds) + 1) |
| 1231 | if TypeKind._kinds[value] is not None: |
| 1232 | raise ValueError,'TypeKind already loaded' |
| 1233 | self.value = value |
| 1234 | TypeKind._kinds[value] = self |
| 1235 | TypeKind._name_map = None |
| 1236 | |
| 1237 | def from_param(self): |
| 1238 | return self.value |
| 1239 | |
| 1240 | @property |
| 1241 | def name(self): |
| 1242 | """Get the enumeration name of this cursor kind.""" |
| 1243 | if self._name_map is None: |
| 1244 | self._name_map = {} |
| 1245 | for key,value in TypeKind.__dict__.items(): |
| 1246 | if isinstance(value,TypeKind): |
| 1247 | self._name_map[value] = key |
| 1248 | return self._name_map[self] |
| 1249 | |
Gregory Szorc | 6e67eed | 2012-04-15 18:51:10 +0000 | [diff] [blame] | 1250 | @property |
| 1251 | def spelling(self): |
| 1252 | """Retrieve the spelling of this TypeKind.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1253 | return lib.clang_getTypeKindSpelling(self.value) |
Gregory Szorc | 6e67eed | 2012-04-15 18:51:10 +0000 | [diff] [blame] | 1254 | |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1255 | @staticmethod |
| 1256 | def from_id(id): |
| 1257 | if id >= len(TypeKind._kinds) or TypeKind._kinds[id] is None: |
Douglas Gregor | 9d342ab | 2011-10-19 05:49:29 +0000 | [diff] [blame] | 1258 | raise ValueError,'Unknown type kind %d' % id |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1259 | return TypeKind._kinds[id] |
| 1260 | |
| 1261 | def __repr__(self): |
| 1262 | return 'TypeKind.%s' % (self.name,) |
| 1263 | |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1264 | TypeKind.INVALID = TypeKind(0) |
| 1265 | TypeKind.UNEXPOSED = TypeKind(1) |
| 1266 | TypeKind.VOID = TypeKind(2) |
| 1267 | TypeKind.BOOL = TypeKind(3) |
| 1268 | TypeKind.CHAR_U = TypeKind(4) |
| 1269 | TypeKind.UCHAR = TypeKind(5) |
| 1270 | TypeKind.CHAR16 = TypeKind(6) |
| 1271 | TypeKind.CHAR32 = TypeKind(7) |
| 1272 | TypeKind.USHORT = TypeKind(8) |
| 1273 | TypeKind.UINT = TypeKind(9) |
| 1274 | TypeKind.ULONG = TypeKind(10) |
| 1275 | TypeKind.ULONGLONG = TypeKind(11) |
| 1276 | TypeKind.UINT128 = TypeKind(12) |
| 1277 | TypeKind.CHAR_S = TypeKind(13) |
| 1278 | TypeKind.SCHAR = TypeKind(14) |
| 1279 | TypeKind.WCHAR = TypeKind(15) |
| 1280 | TypeKind.SHORT = TypeKind(16) |
| 1281 | TypeKind.INT = TypeKind(17) |
| 1282 | TypeKind.LONG = TypeKind(18) |
| 1283 | TypeKind.LONGLONG = TypeKind(19) |
| 1284 | TypeKind.INT128 = TypeKind(20) |
| 1285 | TypeKind.FLOAT = TypeKind(21) |
| 1286 | TypeKind.DOUBLE = TypeKind(22) |
| 1287 | TypeKind.LONGDOUBLE = TypeKind(23) |
| 1288 | TypeKind.NULLPTR = TypeKind(24) |
| 1289 | TypeKind.OVERLOAD = TypeKind(25) |
| 1290 | TypeKind.DEPENDENT = TypeKind(26) |
| 1291 | TypeKind.OBJCID = TypeKind(27) |
| 1292 | TypeKind.OBJCCLASS = TypeKind(28) |
| 1293 | TypeKind.OBJCSEL = TypeKind(29) |
| 1294 | TypeKind.COMPLEX = TypeKind(100) |
| 1295 | TypeKind.POINTER = TypeKind(101) |
| 1296 | TypeKind.BLOCKPOINTER = TypeKind(102) |
| 1297 | TypeKind.LVALUEREFERENCE = TypeKind(103) |
| 1298 | TypeKind.RVALUEREFERENCE = TypeKind(104) |
| 1299 | TypeKind.RECORD = TypeKind(105) |
| 1300 | TypeKind.ENUM = TypeKind(106) |
| 1301 | TypeKind.TYPEDEF = TypeKind(107) |
| 1302 | TypeKind.OBJCINTERFACE = TypeKind(108) |
| 1303 | TypeKind.OBJCOBJECTPOINTER = TypeKind(109) |
| 1304 | TypeKind.FUNCTIONNOPROTO = TypeKind(110) |
| 1305 | TypeKind.FUNCTIONPROTO = TypeKind(111) |
Douglas Gregor | 38d2d55 | 2011-10-19 05:50:34 +0000 | [diff] [blame] | 1306 | TypeKind.CONSTANTARRAY = TypeKind(112) |
Tobias Grosser | 250d217 | 2012-02-05 11:42:14 +0000 | [diff] [blame] | 1307 | TypeKind.VECTOR = TypeKind(113) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1308 | |
| 1309 | class Type(Structure): |
| 1310 | """ |
| 1311 | The type of an element in the abstract syntax tree. |
| 1312 | """ |
| 1313 | _fields_ = [("_kind_id", c_int), ("data", c_void_p * 2)] |
| 1314 | |
| 1315 | @property |
| 1316 | def kind(self): |
| 1317 | """Return the kind of this type.""" |
| 1318 | return TypeKind.from_id(self._kind_id) |
| 1319 | |
Gregory Szorc | 826fce5 | 2012-02-20 17:45:30 +0000 | [diff] [blame] | 1320 | def argument_types(self): |
| 1321 | """Retrieve a container for the non-variadic arguments for this type. |
| 1322 | |
| 1323 | The returned object is iterable and indexable. Each item in the |
| 1324 | container is a Type instance. |
| 1325 | """ |
| 1326 | class ArgumentsIterator(collections.Sequence): |
| 1327 | def __init__(self, parent): |
| 1328 | self.parent = parent |
| 1329 | self.length = None |
| 1330 | |
| 1331 | def __len__(self): |
| 1332 | if self.length is None: |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1333 | self.length = lib.clang_getNumArgTypes(self.parent) |
Gregory Szorc | 826fce5 | 2012-02-20 17:45:30 +0000 | [diff] [blame] | 1334 | |
| 1335 | return self.length |
| 1336 | |
| 1337 | def __getitem__(self, key): |
| 1338 | # FIXME Support slice objects. |
| 1339 | if not isinstance(key, int): |
| 1340 | raise TypeError("Must supply a non-negative int.") |
| 1341 | |
| 1342 | if key < 0: |
| 1343 | raise IndexError("Only non-negative indexes are accepted.") |
| 1344 | |
| 1345 | if key >= len(self): |
| 1346 | raise IndexError("Index greater than container length: " |
| 1347 | "%d > %d" % ( key, len(self) )) |
| 1348 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1349 | result = lib.clang_getArgType(self.parent, key) |
Gregory Szorc | 826fce5 | 2012-02-20 17:45:30 +0000 | [diff] [blame] | 1350 | if result.kind == TypeKind.INVALID: |
| 1351 | raise IndexError("Argument could not be retrieved.") |
| 1352 | |
| 1353 | return result |
| 1354 | |
| 1355 | assert self.kind == TypeKind.FUNCTIONPROTO |
| 1356 | return ArgumentsIterator(self) |
| 1357 | |
Gregory Szorc | 8605760 | 2012-02-17 07:44:46 +0000 | [diff] [blame] | 1358 | @property |
| 1359 | def element_type(self): |
| 1360 | """Retrieve the Type of elements within this Type. |
| 1361 | |
| 1362 | If accessed on a type that is not an array, complex, or vector type, an |
| 1363 | exception will be raised. |
| 1364 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1365 | result = lib.clang_getElementType(self) |
Gregory Szorc | 8605760 | 2012-02-17 07:44:46 +0000 | [diff] [blame] | 1366 | if result.kind == TypeKind.INVALID: |
| 1367 | raise Exception('Element type not available on this type.') |
| 1368 | |
| 1369 | return result |
| 1370 | |
Gregory Szorc | bf8ca00 | 2012-02-17 07:47:38 +0000 | [diff] [blame] | 1371 | @property |
| 1372 | def element_count(self): |
| 1373 | """Retrieve the number of elements in this type. |
| 1374 | |
| 1375 | Returns an int. |
| 1376 | |
| 1377 | If the Type is not an array or vector, this raises. |
| 1378 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1379 | result = lib.clang_getNumElements(self) |
Gregory Szorc | bf8ca00 | 2012-02-17 07:47:38 +0000 | [diff] [blame] | 1380 | if result < 0: |
| 1381 | raise Exception('Type does not have elements.') |
| 1382 | |
| 1383 | return result |
| 1384 | |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 1385 | @property |
| 1386 | def translation_unit(self): |
| 1387 | """The TranslationUnit to which this Type is associated.""" |
| 1388 | # If this triggers an AttributeError, the instance was not properly |
| 1389 | # instantiated. |
| 1390 | return self._tu |
| 1391 | |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1392 | @staticmethod |
| 1393 | def from_result(res, fn, args): |
| 1394 | assert isinstance(res, Type) |
Gregory Szorc | a63ef1f | 2012-05-15 19:51:02 +0000 | [diff] [blame] | 1395 | |
| 1396 | tu = None |
| 1397 | for arg in args: |
| 1398 | if hasattr(arg, 'translation_unit'): |
| 1399 | tu = arg.translation_unit |
| 1400 | break |
| 1401 | |
| 1402 | assert tu is not None |
| 1403 | res._tu = tu |
| 1404 | |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1405 | return res |
| 1406 | |
| 1407 | def get_canonical(self): |
| 1408 | """ |
| 1409 | Return the canonical type for a Type. |
| 1410 | |
| 1411 | Clang's type system explicitly models typedefs and all the |
| 1412 | ways a specific type can be represented. The canonical type |
| 1413 | is the underlying type with all the "sugar" removed. For |
| 1414 | example, if 'T' is a typedef for 'int', the canonical type for |
| 1415 | 'T' would be 'int'. |
| 1416 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1417 | return lib.clang_getCanonicalType(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1418 | |
| 1419 | def is_const_qualified(self): |
Gregory Szorc | 8261345 | 2012-02-20 17:58:40 +0000 | [diff] [blame] | 1420 | """Determine whether a Type has the "const" qualifier set. |
| 1421 | |
| 1422 | This does not look through typedefs that may have added "const" |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1423 | at a different level. |
| 1424 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1425 | return lib.clang_isConstQualifiedType(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1426 | |
| 1427 | def is_volatile_qualified(self): |
Gregory Szorc | 8261345 | 2012-02-20 17:58:40 +0000 | [diff] [blame] | 1428 | """Determine whether a Type has the "volatile" qualifier set. |
| 1429 | |
| 1430 | This does not look through typedefs that may have added "volatile" |
| 1431 | at a different level. |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1432 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1433 | return lib.clang_isVolatileQualifiedType(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1434 | |
| 1435 | def is_restrict_qualified(self): |
Gregory Szorc | 8261345 | 2012-02-20 17:58:40 +0000 | [diff] [blame] | 1436 | """Determine whether a Type has the "restrict" qualifier set. |
| 1437 | |
| 1438 | This does not look through typedefs that may have added "restrict" at |
| 1439 | a different level. |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1440 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1441 | return lib.clang_isRestrictQualifiedType(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1442 | |
Gregory Szorc | 31cc38c | 2012-02-19 18:28:33 +0000 | [diff] [blame] | 1443 | def is_function_variadic(self): |
| 1444 | """Determine whether this function Type is a variadic function type.""" |
| 1445 | assert self.kind == TypeKind.FUNCTIONPROTO |
| 1446 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1447 | return lib.clang_isFunctionTypeVariadic(self) |
Gregory Szorc | 31cc38c | 2012-02-19 18:28:33 +0000 | [diff] [blame] | 1448 | |
Gregory Szorc | 96ad633 | 2012-02-05 19:42:06 +0000 | [diff] [blame] | 1449 | def is_pod(self): |
| 1450 | """Determine whether this Type represents plain old data (POD).""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1451 | return lib.clang_isPODType(self) |
Gregory Szorc | 96ad633 | 2012-02-05 19:42:06 +0000 | [diff] [blame] | 1452 | |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1453 | def get_pointee(self): |
| 1454 | """ |
| 1455 | For pointer types, returns the type of the pointee. |
| 1456 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1457 | return lib.clang_getPointeeType(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1458 | |
| 1459 | def get_declaration(self): |
| 1460 | """ |
| 1461 | Return the cursor for the declaration of the given type. |
| 1462 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1463 | return lib.clang_getTypeDeclaration(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1464 | |
| 1465 | def get_result(self): |
| 1466 | """ |
| 1467 | Retrieve the result type associated with a function type. |
| 1468 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1469 | return lib.clang_getResultType(self) |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 1470 | |
Douglas Gregor | 13102ff | 2011-10-19 05:51:43 +0000 | [diff] [blame] | 1471 | def get_array_element_type(self): |
| 1472 | """ |
| 1473 | Retrieve the type of the elements of the array type. |
| 1474 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1475 | return lib.clang_getArrayElementType(self) |
Douglas Gregor | 13102ff | 2011-10-19 05:51:43 +0000 | [diff] [blame] | 1476 | |
| 1477 | def get_array_size(self): |
| 1478 | """ |
| 1479 | Retrieve the size of the constant array. |
| 1480 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1481 | return lib.clang_getArraySize(self) |
Douglas Gregor | 13102ff | 2011-10-19 05:51:43 +0000 | [diff] [blame] | 1482 | |
Gregory Szorc | 7eb691a | 2012-02-20 17:44:49 +0000 | [diff] [blame] | 1483 | def __eq__(self, other): |
| 1484 | if type(other) != type(self): |
| 1485 | return False |
| 1486 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1487 | return lib.clang_equalTypes(self, other) |
Gregory Szorc | 7eb691a | 2012-02-20 17:44:49 +0000 | [diff] [blame] | 1488 | |
| 1489 | def __ne__(self, other): |
| 1490 | return not self.__eq__(other) |
| 1491 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1492 | ## CIndex Objects ## |
| 1493 | |
| 1494 | # CIndex objects (derived from ClangObject) are essentially lightweight |
| 1495 | # wrappers attached to some underlying object, which is exposed via CIndex as |
| 1496 | # a void*. |
| 1497 | |
| 1498 | class ClangObject(object): |
| 1499 | """ |
| 1500 | A helper for Clang objects. This class helps act as an intermediary for |
| 1501 | the ctypes library and the Clang CIndex library. |
| 1502 | """ |
| 1503 | def __init__(self, obj): |
| 1504 | assert isinstance(obj, c_object_p) and obj |
| 1505 | self.obj = self._as_parameter_ = obj |
| 1506 | |
| 1507 | def from_param(self): |
| 1508 | return self._as_parameter_ |
| 1509 | |
Daniel Dunbar | 5b534f6 | 2010-01-25 00:44:11 +0000 | [diff] [blame] | 1510 | |
| 1511 | class _CXUnsavedFile(Structure): |
| 1512 | """Helper for passing unsaved file arguments.""" |
| 1513 | _fields_ = [("name", c_char_p), ("contents", c_char_p), ('length', c_ulong)] |
| 1514 | |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1515 | class CompletionChunk: |
| 1516 | class Kind: |
| 1517 | def __init__(self, name): |
| 1518 | self.name = name |
| 1519 | |
| 1520 | def __str__(self): |
| 1521 | return self.name |
| 1522 | |
| 1523 | def __repr__(self): |
| 1524 | return "<ChunkKind: %s>" % self |
| 1525 | |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1526 | def __init__(self, completionString, key): |
| 1527 | self.cs = completionString |
| 1528 | self.key = key |
| 1529 | |
| 1530 | def __repr__(self): |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1531 | return "{'" + self.spelling + "', " + str(self.kind) + "}" |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1532 | |
| 1533 | @property |
| 1534 | def spelling(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1535 | return lib.clang_getCompletionChunkText(self.cs, self.key).spelling |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1536 | |
| 1537 | @property |
| 1538 | def kind(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1539 | res = lib.clang_getCompletionChunkKind(self.cs, self.key) |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1540 | return completionChunkKindMap[res] |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1541 | |
| 1542 | @property |
| 1543 | def string(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1544 | res = lib.clang_getCompletionChunkCompletionString(self.cs, self.key) |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1545 | |
| 1546 | if (res): |
| 1547 | return CompletionString(res) |
| 1548 | else: |
| 1549 | None |
| 1550 | |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1551 | def isKindOptional(self): |
| 1552 | return self.kind == completionChunkKindMap[0] |
| 1553 | |
| 1554 | def isKindTypedText(self): |
| 1555 | return self.kind == completionChunkKindMap[1] |
| 1556 | |
| 1557 | def isKindPlaceHolder(self): |
| 1558 | return self.kind == completionChunkKindMap[3] |
| 1559 | |
| 1560 | def isKindInformative(self): |
| 1561 | return self.kind == completionChunkKindMap[4] |
| 1562 | |
| 1563 | def isKindResultType(self): |
| 1564 | return self.kind == completionChunkKindMap[15] |
| 1565 | |
| 1566 | completionChunkKindMap = { |
| 1567 | 0: CompletionChunk.Kind("Optional"), |
| 1568 | 1: CompletionChunk.Kind("TypedText"), |
| 1569 | 2: CompletionChunk.Kind("Text"), |
| 1570 | 3: CompletionChunk.Kind("Placeholder"), |
| 1571 | 4: CompletionChunk.Kind("Informative"), |
| 1572 | 5: CompletionChunk.Kind("CurrentParameter"), |
| 1573 | 6: CompletionChunk.Kind("LeftParen"), |
| 1574 | 7: CompletionChunk.Kind("RightParen"), |
| 1575 | 8: CompletionChunk.Kind("LeftBracket"), |
| 1576 | 9: CompletionChunk.Kind("RightBracket"), |
| 1577 | 10: CompletionChunk.Kind("LeftBrace"), |
| 1578 | 11: CompletionChunk.Kind("RightBrace"), |
| 1579 | 12: CompletionChunk.Kind("LeftAngle"), |
| 1580 | 13: CompletionChunk.Kind("RightAngle"), |
| 1581 | 14: CompletionChunk.Kind("Comma"), |
| 1582 | 15: CompletionChunk.Kind("ResultType"), |
| 1583 | 16: CompletionChunk.Kind("Colon"), |
| 1584 | 17: CompletionChunk.Kind("SemiColon"), |
| 1585 | 18: CompletionChunk.Kind("Equal"), |
| 1586 | 19: CompletionChunk.Kind("HorizontalSpace"), |
| 1587 | 20: CompletionChunk.Kind("VerticalSpace")} |
| 1588 | |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1589 | class CompletionString(ClangObject): |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1590 | class Availability: |
| 1591 | def __init__(self, name): |
| 1592 | self.name = name |
| 1593 | |
| 1594 | def __str__(self): |
| 1595 | return self.name |
| 1596 | |
| 1597 | def __repr__(self): |
| 1598 | return "<Availability: %s>" % self |
| 1599 | |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1600 | def __len__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1601 | return lib.clang_getNumCompletionChunks(self.obj) |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1602 | |
| 1603 | def __getitem__(self, key): |
| 1604 | if len(self) <= key: |
| 1605 | raise IndexError |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1606 | return CompletionChunk(self.obj, key) |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1607 | |
| 1608 | @property |
| 1609 | def priority(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1610 | return lib.clang_getCompletionPriority(self.obj) |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1611 | |
| 1612 | @property |
| 1613 | def availability(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1614 | res = lib.clang_getCompletionAvailability(self.obj) |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1615 | return availabilityKinds[res] |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1616 | |
| 1617 | def __repr__(self): |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 1618 | return " | ".join([str(a) for a in self]) \ |
| 1619 | + " || Priority: " + str(self.priority) \ |
| 1620 | + " || Availability: " + str(self.availability) |
| 1621 | |
| 1622 | availabilityKinds = { |
| 1623 | 0: CompletionChunk.Kind("Available"), |
| 1624 | 1: CompletionChunk.Kind("Deprecated"), |
| 1625 | 2: CompletionChunk.Kind("NotAvailable")} |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1626 | |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 1627 | class CodeCompletionResult(Structure): |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1628 | _fields_ = [('cursorKind', c_int), ('completionString', c_object_p)] |
| 1629 | |
| 1630 | def __repr__(self): |
| 1631 | return str(CompletionString(self.completionString)) |
| 1632 | |
| 1633 | @property |
| 1634 | def kind(self): |
| 1635 | return CursorKind.from_id(self.cursorKind) |
| 1636 | |
| 1637 | @property |
| 1638 | def string(self): |
| 1639 | return CompletionString(self.completionString) |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 1640 | |
| 1641 | class CCRStructure(Structure): |
| 1642 | _fields_ = [('results', POINTER(CodeCompletionResult)), |
| 1643 | ('numResults', c_int)] |
| 1644 | |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1645 | def __len__(self): |
| 1646 | return self.numResults |
| 1647 | |
| 1648 | def __getitem__(self, key): |
| 1649 | if len(self) <= key: |
| 1650 | raise IndexError |
| 1651 | |
| 1652 | return self.results[key] |
| 1653 | |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 1654 | class CodeCompletionResults(ClangObject): |
| 1655 | def __init__(self, ptr): |
| 1656 | assert isinstance(ptr, POINTER(CCRStructure)) and ptr |
| 1657 | self.ptr = self._as_parameter_ = ptr |
| 1658 | |
| 1659 | def from_param(self): |
| 1660 | return self._as_parameter_ |
| 1661 | |
| 1662 | def __del__(self): |
| 1663 | CodeCompletionResults_dispose(self) |
| 1664 | |
| 1665 | @property |
| 1666 | def results(self): |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 1667 | return self.ptr.contents |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 1668 | |
| 1669 | @property |
| 1670 | def diagnostics(self): |
| 1671 | class DiagnosticsItr: |
| 1672 | def __init__(self, ccr): |
| 1673 | self.ccr= ccr |
| 1674 | |
| 1675 | def __len__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1676 | return int(lib.clang_codeCompleteGetNumDiagnostics(self.ccr)) |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 1677 | |
| 1678 | def __getitem__(self, key): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1679 | return lib.clang_codeCompleteGetDiagnostic(self.ccr, key) |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 1680 | |
| 1681 | return DiagnosticsItr(self) |
| 1682 | |
| 1683 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1684 | class Index(ClangObject): |
| 1685 | """ |
| 1686 | The Index type provides the primary interface to the Clang CIndex library, |
| 1687 | primarily by providing an interface for reading and parsing translation |
| 1688 | units. |
| 1689 | """ |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1690 | |
| 1691 | @staticmethod |
Daniel Dunbar | 2791dfc | 2010-01-30 23:58:39 +0000 | [diff] [blame] | 1692 | def create(excludeDecls=False): |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1693 | """ |
| 1694 | Create a new Index. |
| 1695 | Parameters: |
| 1696 | excludeDecls -- Exclude local declarations from translation units. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1697 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1698 | return Index(lib.clang_createIndex(excludeDecls, 0)) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1699 | |
| 1700 | def __del__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1701 | lib.clang_disposeIndex(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1702 | |
| 1703 | def read(self, path): |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1704 | """Load a TranslationUnit from the given AST file.""" |
| 1705 | return TranslationUnit.from_ast(path, self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1706 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1707 | def parse(self, path, args=None, unsaved_files=None, options = 0): |
| 1708 | """Load the translation unit from the given source code file by running |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1709 | clang and generating the AST before loading. Additional command line |
| 1710 | parameters can be passed to clang via the args parameter. |
Daniel Dunbar | 5b534f6 | 2010-01-25 00:44:11 +0000 | [diff] [blame] | 1711 | |
| 1712 | In-memory contents for files can be provided by passing a list of pairs |
| 1713 | to as unsaved_files, the first item should be the filenames to be mapped |
| 1714 | and the second should be the contents to be substituted for the |
| 1715 | file. The contents may be passed as strings or file objects. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1716 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1717 | If an error was encountered during parsing, a TranslationUnitLoadError |
| 1718 | will be raised. |
| 1719 | """ |
| 1720 | return TranslationUnit.from_source(path, args, unsaved_files, options, |
| 1721 | self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1722 | |
| 1723 | class TranslationUnit(ClangObject): |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1724 | """Represents a source code translation unit. |
| 1725 | |
| 1726 | This is one of the main types in the API. Any time you wish to interact |
| 1727 | with Clang's representation of a source file, you typically start with a |
| 1728 | translation unit. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1729 | """ |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1730 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1731 | # Default parsing mode. |
| 1732 | PARSE_NONE = 0 |
| 1733 | |
| 1734 | # Instruct the parser to create a detailed processing record containing |
| 1735 | # metadata not normally retained. |
| 1736 | PARSE_DETAILED_PROCESSING_RECORD = 1 |
| 1737 | |
| 1738 | # Indicates that the translation unit is incomplete. This is typically used |
| 1739 | # when parsing headers. |
| 1740 | PARSE_INCOMPLETE = 2 |
| 1741 | |
| 1742 | # Instruct the parser to create a pre-compiled preamble for the translation |
| 1743 | # unit. This caches the preamble (included files at top of source file). |
| 1744 | # This is useful if the translation unit will be reparsed and you don't |
| 1745 | # want to incur the overhead of reparsing the preamble. |
| 1746 | PARSE_PRECOMPILED_PREAMBLE = 4 |
| 1747 | |
| 1748 | # Cache code completion information on parse. This adds time to parsing but |
| 1749 | # speeds up code completion. |
| 1750 | PARSE_CACHE_COMPLETION_RESULTS = 8 |
| 1751 | |
| 1752 | # Flags with values 16 and 32 are deprecated and intentionally omitted. |
| 1753 | |
| 1754 | # Do not parse function bodies. This is useful if you only care about |
| 1755 | # searching for declarations/definitions. |
| 1756 | PARSE_SKIP_FUNCTION_BODIES = 64 |
| 1757 | |
| 1758 | @classmethod |
| 1759 | def from_source(cls, filename, args=None, unsaved_files=None, options=0, |
| 1760 | index=None): |
| 1761 | """Create a TranslationUnit by parsing source. |
| 1762 | |
| 1763 | This is capable of processing source code both from files on the |
| 1764 | filesystem as well as in-memory contents. |
| 1765 | |
| 1766 | Command-line arguments that would be passed to clang are specified as |
| 1767 | a list via args. These can be used to specify include paths, warnings, |
| 1768 | etc. e.g. ["-Wall", "-I/path/to/include"]. |
| 1769 | |
| 1770 | In-memory file content can be provided via unsaved_files. This is an |
| 1771 | iterable of 2-tuples. The first element is the str filename. The |
| 1772 | second element defines the content. Content can be provided as str |
| 1773 | source code or as file objects (anything with a read() method). If |
| 1774 | a file object is being used, content will be read until EOF and the |
| 1775 | read cursor will not be reset to its original position. |
| 1776 | |
| 1777 | options is a bitwise or of TranslationUnit.PARSE_XXX flags which will |
| 1778 | control parsing behavior. |
| 1779 | |
Gregory Szorc | 2283b46 | 2012-05-12 20:49:13 +0000 | [diff] [blame] | 1780 | index is an Index instance to utilize. If not provided, a new Index |
| 1781 | will be created for this TranslationUnit. |
| 1782 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1783 | To parse source from the filesystem, the filename of the file to parse |
| 1784 | is specified by the filename argument. Or, filename could be None and |
| 1785 | the args list would contain the filename(s) to parse. |
| 1786 | |
| 1787 | To parse source from an in-memory buffer, set filename to the virtual |
| 1788 | filename you wish to associate with this source (e.g. "test.c"). The |
| 1789 | contents of that file are then provided in unsaved_files. |
| 1790 | |
| 1791 | If an error occurs, a TranslationUnitLoadError is raised. |
| 1792 | |
| 1793 | Please note that a TranslationUnit with parser errors may be returned. |
| 1794 | It is the caller's responsibility to check tu.diagnostics for errors. |
| 1795 | |
| 1796 | Also note that Clang infers the source language from the extension of |
| 1797 | the input filename. If you pass in source code containing a C++ class |
| 1798 | declaration with the filename "test.c" parsing will fail. |
| 1799 | """ |
| 1800 | if args is None: |
| 1801 | args = [] |
| 1802 | |
| 1803 | if unsaved_files is None: |
| 1804 | unsaved_files = [] |
| 1805 | |
| 1806 | if index is None: |
| 1807 | index = Index.create() |
| 1808 | |
| 1809 | args_array = None |
| 1810 | if len(args) > 0: |
| 1811 | args_array = (c_char_p * len(args))(* args) |
| 1812 | |
| 1813 | unsaved_array = None |
| 1814 | if len(unsaved_files) > 0: |
| 1815 | unsaved_array = (_CXUnsavedFile * len(unsaved_files))() |
| 1816 | for i, (name, contents) in enumerate(unsaved_files): |
| 1817 | if hasattr(contents, "read"): |
| 1818 | contents = contents.read() |
| 1819 | |
| 1820 | unsaved_array[i].name = name |
| 1821 | unsaved_array[i].contents = contents |
| 1822 | unsaved_array[i].length = len(contents) |
| 1823 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1824 | ptr = lib.clang_parseTranslationUnit(index, filename, args_array, |
| 1825 | len(args), unsaved_array, |
| 1826 | len(unsaved_files), options) |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1827 | |
| 1828 | if ptr is None: |
| 1829 | raise TranslationUnitLoadError("Error parsing translation unit.") |
| 1830 | |
| 1831 | return cls(ptr, index=index) |
| 1832 | |
| 1833 | @classmethod |
| 1834 | def from_ast_file(cls, filename, index=None): |
| 1835 | """Create a TranslationUnit instance from a saved AST file. |
| 1836 | |
| 1837 | A previously-saved AST file (provided with -emit-ast or |
| 1838 | TranslationUnit.save()) is loaded from the filename specified. |
| 1839 | |
| 1840 | If the file cannot be loaded, a TranslationUnitLoadError will be |
| 1841 | raised. |
| 1842 | |
| 1843 | index is optional and is the Index instance to use. If not provided, |
| 1844 | a default Index will be created. |
| 1845 | """ |
| 1846 | if index is None: |
| 1847 | index = Index.create() |
| 1848 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1849 | ptr = lib.clang_createTranslationUnit(index, filename) |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1850 | if ptr is None: |
| 1851 | raise TranslationUnitLoadError(filename) |
| 1852 | |
| 1853 | return cls(ptr=ptr, index=index) |
| 1854 | |
| 1855 | def __init__(self, ptr, index): |
| 1856 | """Create a TranslationUnit instance. |
| 1857 | |
| 1858 | TranslationUnits should be created using one of the from_* @classmethod |
| 1859 | functions above. __init__ is only called internally. |
| 1860 | """ |
| 1861 | assert isinstance(index, Index) |
| 1862 | |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 1863 | ClangObject.__init__(self, ptr) |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 1864 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1865 | def __del__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1866 | lib.clang_disposeTranslationUnit(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1867 | |
Daniel Dunbar | 1b945a7 | 2010-01-24 04:09:43 +0000 | [diff] [blame] | 1868 | @property |
| 1869 | def cursor(self): |
| 1870 | """Retrieve the cursor that represents the given translation unit.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1871 | return lib.clang_getTranslationUnitCursor(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1872 | |
| 1873 | @property |
| 1874 | def spelling(self): |
Daniel Dunbar | 1b945a7 | 2010-01-24 04:09:43 +0000 | [diff] [blame] | 1875 | """Get the original translation unit source file name.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1876 | return lib.clang_getTranslationUnitSpelling(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 1877 | |
Daniel Dunbar | ef7f798 | 2010-02-13 18:33:18 +0000 | [diff] [blame] | 1878 | def get_includes(self): |
| 1879 | """ |
| 1880 | Return an iterable sequence of FileInclusion objects that describe the |
| 1881 | sequence of inclusions in a translation unit. The first object in |
| 1882 | this sequence is always the input file. Note that this method will not |
| 1883 | recursively iterate over header files included through precompiled |
| 1884 | headers. |
| 1885 | """ |
| 1886 | def visitor(fobj, lptr, depth, includes): |
Douglas Gregor | 8be80e1 | 2011-07-06 03:00:34 +0000 | [diff] [blame] | 1887 | if depth > 0: |
| 1888 | loc = lptr.contents |
| 1889 | includes.append(FileInclusion(loc.file, File(fobj), loc, depth)) |
Daniel Dunbar | ef7f798 | 2010-02-13 18:33:18 +0000 | [diff] [blame] | 1890 | |
| 1891 | # Automatically adapt CIndex/ctype pointers to python objects |
| 1892 | includes = [] |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1893 | lib.clang_getInclusions(self, |
| 1894 | callbacks['translation_unit_includes'](visitor), includes) |
| 1895 | |
Daniel Dunbar | ef7f798 | 2010-02-13 18:33:18 +0000 | [diff] [blame] | 1896 | return iter(includes) |
| 1897 | |
Gregory Szorc | 0f1964a | 2012-07-12 05:05:56 +0000 | [diff] [blame^] | 1898 | def get_file(self, filename): |
| 1899 | """Obtain a File from this translation unit.""" |
| 1900 | |
| 1901 | return File.from_name(self, filename) |
| 1902 | |
| 1903 | def get_location(self, filename, position): |
| 1904 | """Obtain a SourceLocation for a file in this translation unit. |
| 1905 | |
| 1906 | The position can be specified by passing: |
| 1907 | |
| 1908 | - Integer file offset. Initial file offset is 0. |
| 1909 | - 2-tuple of (line number, column number). Initial file position is |
| 1910 | (0, 0) |
| 1911 | """ |
| 1912 | f = self.get_file(filename) |
| 1913 | |
| 1914 | if isinstance(position, int): |
| 1915 | return SourceLocation.from_offset(self, f, position) |
| 1916 | |
| 1917 | return SourceLocation.from_position(self, f, position[0], position[1]) |
| 1918 | |
| 1919 | def get_extent(self, filename, locations): |
| 1920 | """Obtain a SourceRange from this translation unit. |
| 1921 | |
| 1922 | The bounds of the SourceRange must ultimately be defined by a start and |
| 1923 | end SourceLocation. For the locations argument, you can pass: |
| 1924 | |
| 1925 | - 2 SourceLocation instances in a 2-tuple or list. |
| 1926 | - 2 int file offsets via a 2-tuple or list. |
| 1927 | - 2 2-tuple or lists of (line, column) pairs in a 2-tuple or list. |
| 1928 | |
| 1929 | e.g. |
| 1930 | |
| 1931 | get_extent('foo.c', (5, 10)) |
| 1932 | get_extent('foo.c', ((1, 1), (1, 15))) |
| 1933 | """ |
| 1934 | f = self.get_file(filename) |
| 1935 | |
| 1936 | if len(locations) < 2: |
| 1937 | raise Exception('Must pass object with at least 2 elements') |
| 1938 | |
| 1939 | start_location, end_location = locations |
| 1940 | |
| 1941 | if hasattr(start_location, '__len__'): |
| 1942 | start_location = SourceLocation.from_position(self, f, |
| 1943 | start_location[0], start_location[1]) |
| 1944 | elif isinstance(start_location, int): |
| 1945 | start_location = SourceLocation.from_offset(self, f, |
| 1946 | start_location) |
| 1947 | |
| 1948 | if hasattr(end_location, '__len__'): |
| 1949 | end_location = SourceLocation.from_position(self, f, |
| 1950 | end_location[0], end_location[1]) |
| 1951 | elif isinstance(end_location, int): |
| 1952 | end_location = SourceLocation.from_offset(self, f, end_location) |
| 1953 | |
| 1954 | assert isinstance(start_location, SourceLocation) |
| 1955 | assert isinstance(end_location, SourceLocation) |
| 1956 | |
| 1957 | return SourceRange.from_locations(start_location, end_location) |
| 1958 | |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 1959 | @property |
| 1960 | def diagnostics(self): |
| 1961 | """ |
| 1962 | Return an iterable (and indexable) object containing the diagnostics. |
| 1963 | """ |
Benjamin Kramer | 1d02ccd | 2010-03-06 15:38:03 +0000 | [diff] [blame] | 1964 | class DiagIterator: |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 1965 | def __init__(self, tu): |
| 1966 | self.tu = tu |
| 1967 | |
| 1968 | def __len__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1969 | return int(lib.clang_getNumDiagnostics(self.tu)) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 1970 | |
| 1971 | def __getitem__(self, key): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 1972 | diag = lib.clang_getDiagnostic(self.tu, key) |
Benjamin Kramer | 1d02ccd | 2010-03-06 15:38:03 +0000 | [diff] [blame] | 1973 | if not diag: |
| 1974 | raise IndexError |
| 1975 | return Diagnostic(diag) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 1976 | |
Benjamin Kramer | 1d02ccd | 2010-03-06 15:38:03 +0000 | [diff] [blame] | 1977 | return DiagIterator(self) |
Benjamin Kramer | 3b0cf09 | 2010-03-06 14:53:07 +0000 | [diff] [blame] | 1978 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1979 | def reparse(self, unsaved_files=None, options=0): |
Tobias Grosser | 265e6b2 | 2011-02-05 17:54:00 +0000 | [diff] [blame] | 1980 | """ |
| 1981 | Reparse an already parsed translation unit. |
| 1982 | |
| 1983 | In-memory contents for files can be provided by passing a list of pairs |
| 1984 | as unsaved_files, the first items should be the filenames to be mapped |
| 1985 | and the second should be the contents to be substituted for the |
| 1986 | file. The contents may be passed as strings or file objects. |
| 1987 | """ |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 1988 | if unsaved_files is None: |
| 1989 | unsaved_files = [] |
| 1990 | |
Tobias Grosser | 265e6b2 | 2011-02-05 17:54:00 +0000 | [diff] [blame] | 1991 | unsaved_files_array = 0 |
| 1992 | if len(unsaved_files): |
| 1993 | unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))() |
| 1994 | for i,(name,value) in enumerate(unsaved_files): |
| 1995 | if not isinstance(value, str): |
| 1996 | # FIXME: It would be great to support an efficient version |
| 1997 | # of this, one day. |
| 1998 | value = value.read() |
| 1999 | print value |
| 2000 | if not isinstance(value, str): |
| 2001 | raise TypeError,'Unexpected unsaved file contents.' |
| 2002 | unsaved_files_array[i].name = name |
| 2003 | unsaved_files_array[i].contents = value |
| 2004 | unsaved_files_array[i].length = len(value) |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2005 | ptr = lib.clang_reparseTranslationUnit(self, len(unsaved_files), |
| 2006 | unsaved_files_array, options) |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2007 | |
| 2008 | def save(self, filename): |
| 2009 | """Saves the TranslationUnit to a file. |
| 2010 | |
| 2011 | This is equivalent to passing -emit-ast to the clang frontend. The |
| 2012 | saved file can be loaded back into a TranslationUnit. Or, if it |
| 2013 | corresponds to a header, it can be used as a pre-compiled header file. |
| 2014 | |
| 2015 | If an error occurs while saving, a TranslationUnitSaveError is raised. |
| 2016 | If the error was TranslationUnitSaveError.ERROR_INVALID_TU, this means |
| 2017 | the constructed TranslationUnit was not valid at time of save. In this |
| 2018 | case, the reason(s) why should be available via |
| 2019 | TranslationUnit.diagnostics(). |
| 2020 | |
| 2021 | filename -- The path to save the translation unit to. |
| 2022 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2023 | options = lib.clang_defaultSaveOptions(self) |
| 2024 | result = int(lib.clang_saveTranslationUnit(self, filename, options)) |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2025 | if result != 0: |
| 2026 | raise TranslationUnitSaveError(result, |
| 2027 | 'Error saving TranslationUnit.') |
| 2028 | |
Gregory Szorc | 2283b46 | 2012-05-12 20:49:13 +0000 | [diff] [blame] | 2029 | def codeComplete(self, path, line, column, unsaved_files=None, options=0): |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2030 | """ |
| 2031 | Code complete in this translation unit. |
| 2032 | |
| 2033 | In-memory contents for files can be provided by passing a list of pairs |
| 2034 | as unsaved_files, the first items should be the filenames to be mapped |
| 2035 | and the second should be the contents to be substituted for the |
| 2036 | file. The contents may be passed as strings or file objects. |
| 2037 | """ |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2038 | if unsaved_files is None: |
| 2039 | unsaved_files = [] |
| 2040 | |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2041 | unsaved_files_array = 0 |
| 2042 | if len(unsaved_files): |
| 2043 | unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))() |
| 2044 | for i,(name,value) in enumerate(unsaved_files): |
| 2045 | if not isinstance(value, str): |
| 2046 | # FIXME: It would be great to support an efficient version |
| 2047 | # of this, one day. |
| 2048 | value = value.read() |
| 2049 | print value |
| 2050 | if not isinstance(value, str): |
| 2051 | raise TypeError,'Unexpected unsaved file contents.' |
| 2052 | unsaved_files_array[i].name = name |
| 2053 | unsaved_files_array[i].contents = value |
| 2054 | unsaved_files_array[i].length = len(value) |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2055 | ptr = lib.clang_codeCompleteAt(self, path, line, column, |
| 2056 | unsaved_files_array, len(unsaved_files), options) |
Tobias Grosser | ba5d10b | 2011-10-31 02:06:50 +0000 | [diff] [blame] | 2057 | if ptr: |
| 2058 | return CodeCompletionResults(ptr) |
| 2059 | return None |
Tobias Grosser | 265e6b2 | 2011-02-05 17:54:00 +0000 | [diff] [blame] | 2060 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2061 | class File(ClangObject): |
| 2062 | """ |
Daniel Dunbar | 7b48b35 | 2010-01-24 04:09:34 +0000 | [diff] [blame] | 2063 | The File class represents a particular source file that is part of a |
| 2064 | translation unit. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2065 | """ |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2066 | |
Tobias Grosser | a9ea5df | 2011-10-31 00:07:19 +0000 | [diff] [blame] | 2067 | @staticmethod |
| 2068 | def from_name(translation_unit, file_name): |
| 2069 | """Retrieve a file handle within the given translation unit.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2070 | return File(lib.clang_getFile(translation_unit, file_name)) |
Tobias Grosser | a9ea5df | 2011-10-31 00:07:19 +0000 | [diff] [blame] | 2071 | |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2072 | @property |
| 2073 | def name(self): |
Daniel Dunbar | 4efd632 | 2010-01-25 00:43:08 +0000 | [diff] [blame] | 2074 | """Return the complete file and path name of the file.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2075 | return lib.clang_getCString(lib.clang_getFileName(self)) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2076 | |
| 2077 | @property |
| 2078 | def time(self): |
Daniel Dunbar | 4efd632 | 2010-01-25 00:43:08 +0000 | [diff] [blame] | 2079 | """Return the last modification time of the file.""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2080 | return lib.clang_getFileTime(self) |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2081 | |
Tobias Grosser | a9ea5df | 2011-10-31 00:07:19 +0000 | [diff] [blame] | 2082 | def __str__(self): |
| 2083 | return self.name |
| 2084 | |
| 2085 | def __repr__(self): |
| 2086 | return "<File: %s>" % (self.name) |
| 2087 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2088 | @staticmethod |
| 2089 | def from_cursor_result(res, fn, args): |
| 2090 | assert isinstance(res, File) |
| 2091 | |
| 2092 | # Copy a reference to the TranslationUnit to prevent premature GC. |
| 2093 | res._tu = args[0]._tu |
| 2094 | return res |
| 2095 | |
Daniel Dunbar | ef7f798 | 2010-02-13 18:33:18 +0000 | [diff] [blame] | 2096 | class FileInclusion(object): |
| 2097 | """ |
| 2098 | The FileInclusion class represents the inclusion of one source file by |
| 2099 | another via a '#include' directive or as the input file for the translation |
| 2100 | unit. This class provides information about the included file, the including |
| 2101 | file, the location of the '#include' directive and the depth of the included |
| 2102 | file in the stack. Note that the input file has depth 0. |
| 2103 | """ |
| 2104 | |
| 2105 | def __init__(self, src, tgt, loc, depth): |
| 2106 | self.source = src |
| 2107 | self.include = tgt |
| 2108 | self.location = loc |
| 2109 | self.depth = depth |
| 2110 | |
| 2111 | @property |
| 2112 | def is_input_file(self): |
| 2113 | """True if the included file is the input file.""" |
| 2114 | return self.depth == 0 |
| 2115 | |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2116 | class CompilationDatabaseError(Exception): |
| 2117 | """Represents an error that occurred when working with a CompilationDatabase |
| 2118 | |
| 2119 | Each error is associated to an enumerated value, accessible under |
| 2120 | e.cdb_error. Consumers can compare the value with one of the ERROR_ |
| 2121 | constants in this class. |
| 2122 | """ |
| 2123 | |
| 2124 | # An unknown error occured |
| 2125 | ERROR_UNKNOWN = 0 |
| 2126 | |
| 2127 | # The database could not be loaded |
| 2128 | ERROR_CANNOTLOADDATABASE = 1 |
| 2129 | |
| 2130 | def __init__(self, enumeration, message): |
| 2131 | assert isinstance(enumeration, int) |
| 2132 | |
| 2133 | if enumeration > 1: |
| 2134 | raise Exception("Encountered undefined CompilationDatabase error " |
| 2135 | "constant: %d. Please file a bug to have this " |
| 2136 | "value supported." % enumeration) |
| 2137 | |
| 2138 | self.cdb_error = enumeration |
| 2139 | Exception.__init__(self, 'Error %d: %s' % (enumeration, message)) |
| 2140 | |
| 2141 | class CompileCommand(object): |
| 2142 | """Represents the compile command used to build a file""" |
| 2143 | def __init__(self, cmd, ccmds): |
| 2144 | self.cmd = cmd |
| 2145 | # Keep a reference to the originating CompileCommands |
| 2146 | # to prevent garbage collection |
| 2147 | self.ccmds = ccmds |
| 2148 | |
| 2149 | @property |
| 2150 | def directory(self): |
| 2151 | """Get the working directory for this CompileCommand""" |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2152 | return lib.clang_CompileCommand_getDirectory(self.cmd) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2153 | |
| 2154 | @property |
| 2155 | def arguments(self): |
| 2156 | """ |
| 2157 | Get an iterable object providing each argument in the |
| 2158 | command line for the compiler invocation as a _CXString. |
| 2159 | |
Arnaud A. de Grandmaison | 577c530 | 2012-07-06 08:22:05 +0000 | [diff] [blame] | 2160 | Invariant : the first argument is the compiler executable |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2161 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2162 | length = lib.clang_CompileCommand_getNumArgs(self.cmd) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2163 | for i in xrange(length): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2164 | yield lib.clang_CompileCommand_getArg(self.cmd, i) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2165 | |
| 2166 | class CompileCommands(object): |
| 2167 | """ |
| 2168 | CompileCommands is an iterable object containing all CompileCommand |
| 2169 | that can be used for building a specific file. |
| 2170 | """ |
| 2171 | def __init__(self, ccmds): |
| 2172 | self.ccmds = ccmds |
| 2173 | |
| 2174 | def __del__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2175 | lib.clang_CompileCommands_dispose(self.ccmds) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2176 | |
| 2177 | def __len__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2178 | return int(lib.clang_CompileCommands_getSize(self.ccmds)) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2179 | |
| 2180 | def __getitem__(self, i): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2181 | cc = lib.clang_CompileCommands_getCommand(self.ccmds, i) |
Arnaud A. de Grandmaison | b161404 | 2012-07-09 11:57:30 +0000 | [diff] [blame] | 2182 | if not cc: |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2183 | raise IndexError |
| 2184 | return CompileCommand(cc, self) |
| 2185 | |
| 2186 | @staticmethod |
| 2187 | def from_result(res, fn, args): |
| 2188 | if not res: |
| 2189 | return None |
| 2190 | return CompileCommands(res) |
| 2191 | |
| 2192 | class CompilationDatabase(ClangObject): |
| 2193 | """ |
| 2194 | The CompilationDatabase is a wrapper class around |
| 2195 | clang::tooling::CompilationDatabase |
| 2196 | |
| 2197 | It enables querying how a specific source file can be built. |
| 2198 | """ |
| 2199 | |
| 2200 | def __del__(self): |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2201 | lib.clang_CompilationDatabase_dispose(self) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2202 | |
| 2203 | @staticmethod |
| 2204 | def from_result(res, fn, args): |
| 2205 | if not res: |
| 2206 | raise CompilationDatabaseError(0, |
| 2207 | "CompilationDatabase loading failed") |
| 2208 | return CompilationDatabase(res) |
| 2209 | |
| 2210 | @staticmethod |
| 2211 | def fromDirectory(buildDir): |
| 2212 | """Builds a CompilationDatabase from the database found in buildDir""" |
| 2213 | errorCode = c_uint() |
| 2214 | try: |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2215 | cdb = lib.clang_CompilationDatabase_fromDirectory(buildDir, |
| 2216 | byref(errorCode)) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2217 | except CompilationDatabaseError as e: |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2218 | raise CompilationDatabaseError(int(errorCode.value), |
| 2219 | "CompilationDatabase loading failed") |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2220 | return cdb |
| 2221 | |
| 2222 | def getCompileCommands(self, filename): |
| 2223 | """ |
| 2224 | Get an iterable object providing all the CompileCommands available to |
Arnaud A. de Grandmaison | 4439478 | 2012-06-30 20:43:37 +0000 | [diff] [blame] | 2225 | build filename. Returns None if filename is not found in the database. |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2226 | """ |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2227 | return lib.clang_CompilationDatabase_getCompileCommands(self, filename) |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2228 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2229 | # Now comes the plumbing to hook up the C library. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2230 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2231 | # Register callback types in common container. |
| 2232 | callbacks['translation_unit_includes'] = CFUNCTYPE(None, c_object_p, |
| 2233 | POINTER(SourceLocation), c_uint, py_object) |
| 2234 | callbacks['cursor_visit'] = CFUNCTYPE(c_int, Cursor, Cursor, py_object) |
Daniel Dunbar | a33dca4 | 2010-01-24 21:19:57 +0000 | [diff] [blame] | 2235 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2236 | def register_functions(lib): |
| 2237 | """Register function prototypes with a libclang library instance. |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2238 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2239 | This must be called as part of library instantiation so Python knows how |
| 2240 | to call out to the shared library. |
| 2241 | """ |
| 2242 | # Functions are registered in strictly alphabetical order. |
| 2243 | #lib.clang_annotateTokens.argtype = [TranslationUnit, POINTER(Token), |
| 2244 | # c_uint, POINTER(Cursor)] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2245 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2246 | lib.clang_CompilationDatabase_dispose.argtypes = [c_object_p] |
Tobias Grosser | 58ba8c9 | 2011-10-31 00:31:32 +0000 | [diff] [blame] | 2247 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2248 | lib.clang_CompilationDatabase_fromDirectory.argtypes = [c_char_p, |
| 2249 | POINTER(c_uint)] |
| 2250 | lib.clang_CompilationDatabase_fromDirectory.restype = c_object_p |
| 2251 | lib.clang_CompilationDatabase_fromDirectory.errcheck = CompilationDatabase.from_result |
Tobias Grosser | 7485833 | 2012-02-05 11:40:59 +0000 | [diff] [blame] | 2252 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2253 | lib.clang_CompilationDatabase_getCompileCommands.argtypes = [c_object_p, c_char_p] |
| 2254 | lib.clang_CompilationDatabase_getCompileCommands.restype = c_object_p |
| 2255 | lib.clang_CompilationDatabase_getCompileCommands.errcheck = CompileCommands.from_result |
Gregory Szorc | 74bb710 | 2012-06-11 11:11:48 +0000 | [diff] [blame] | 2256 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2257 | lib.clang_CompileCommands_dispose.argtypes = [c_object_p] |
Daniel Dunbar | 532fc63 | 2010-01-30 23:59:02 +0000 | [diff] [blame] | 2258 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2259 | lib.clang_CompileCommands_getCommand.argtypes = [c_object_p, c_uint] |
| 2260 | lib.clang_CompileCommands_getCommand.restype = c_object_p |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2261 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2262 | lib.clang_CompileCommands_getSize.argtypes = [c_object_p] |
| 2263 | lib.clang_CompileCommands_getSize.restype = c_uint |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2264 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2265 | lib.clang_CompileCommand_getArg.argtypes = [c_object_p, c_uint] |
| 2266 | lib.clang_CompileCommand_getArg.restype = _CXString |
| 2267 | lib.clang_CompileCommand_getArg.errcheck = _CXString.from_result |
Tobias Grosser | 7485833 | 2012-02-05 11:40:59 +0000 | [diff] [blame] | 2268 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2269 | lib.clang_CompileCommand_getDirectory.argtypes = [c_object_p] |
| 2270 | lib.clang_CompileCommand_getDirectory.restype = _CXString |
| 2271 | lib.clang_CompileCommand_getDirectory.errcheck = _CXString.from_result |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 2272 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2273 | lib.clang_CompileCommand_getNumArgs.argtypes = [c_object_p] |
| 2274 | lib.clang_CompileCommand_getNumArgs.restype = c_uint |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 2275 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2276 | lib.clang_codeCompleteAt.argtypes = [TranslationUnit, c_char_p, c_int, |
| 2277 | c_int, c_void_p, c_int, c_int] |
| 2278 | lib.clang_codeCompleteAt.restype = POINTER(CCRStructure) |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 2279 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2280 | lib.clang_codeCompleteGetDiagnostic.argtypes = [CodeCompletionResults, |
| 2281 | c_int] |
| 2282 | lib.clang_codeCompleteGetDiagnostic.restype = Diagnostic |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 2283 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2284 | lib.clang_codeCompleteGetNumDiagnostics.argtypes = [CodeCompletionResults] |
| 2285 | lib.clang_codeCompleteGetNumDiagnostics.restype = c_int |
Douglas Gregor | 8be80e1 | 2011-07-06 03:00:34 +0000 | [diff] [blame] | 2286 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2287 | lib.clang_createIndex.argtypes = [c_int, c_int] |
| 2288 | lib.clang_createIndex.restype = c_object_p |
Daniel Dunbar | a6a6499 | 2010-01-24 21:20:39 +0000 | [diff] [blame] | 2289 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2290 | lib.clang_createTranslationUnit.argtypes = [Index, c_char_p] |
| 2291 | lib.clang_createTranslationUnit.restype = c_object_p |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 2292 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2293 | lib.clang_CXXMethod_isStatic.argtypes = [Cursor] |
| 2294 | lib.clang_CXXMethod_isStatic.restype = bool |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 2295 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2296 | lib.clang_CXXMethod_isVirtual.argtypes = [Cursor] |
| 2297 | lib.clang_CXXMethod_isVirtual.restype = bool |
Tobias Grosser | eb13634 | 2012-02-05 11:42:09 +0000 | [diff] [blame] | 2298 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2299 | lib.clang_defaultSaveOptions.argtypes = [TranslationUnit] |
| 2300 | lib.clang_defaultSaveOptions.restype = c_uint |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2301 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2302 | lib.clang_disposeCodeCompleteResults.argtypes = [CodeCompletionResults] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2303 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2304 | #lib.clang_disposeCXTUResourceUsage.argtypes = [CXTUResourceUsage] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2305 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2306 | lib.clang_disposeDiagnostic.argtypes = [Diagnostic] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2307 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2308 | lib.clang_disposeIndex.argtypes = [Index] |
Gregory Szorc | e65b34d | 2012-06-09 16:21:34 +0000 | [diff] [blame] | 2309 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2310 | lib.clang_disposeString.argtypes = [_CXString] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2311 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2312 | #lib.clang_disposeTokens.argtype = [TranslationUnit, POINTER(Token), c_uint] |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2313 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2314 | lib.clang_disposeTranslationUnit.argtypes = [TranslationUnit] |
Tobias Grosser | 64e7bdc | 2012-02-05 11:42:03 +0000 | [diff] [blame] | 2315 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2316 | lib.clang_equalCursors.argtypes = [Cursor, Cursor] |
| 2317 | lib.clang_equalCursors.restype = bool |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2318 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2319 | lib.clang_equalLocations.argtypes = [SourceLocation, SourceLocation] |
| 2320 | lib.clang_equalLocations.restype = bool |
Douglas Gregor | 8be80e1 | 2011-07-06 03:00:34 +0000 | [diff] [blame] | 2321 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2322 | lib.clang_equalRanges.argtypes = [SourceRange, SourceRange] |
| 2323 | lib.clang_equalRanges.restype = bool |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2324 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2325 | lib.clang_equalTypes.argtypes = [Type, Type] |
| 2326 | lib.clang_equalTypes.restype = bool |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2327 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2328 | lib.clang_getArgType.argtypes = [Type, c_uint] |
| 2329 | lib.clang_getArgType.restype = Type |
| 2330 | lib.clang_getArgType.errcheck = Type.from_result |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2331 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2332 | lib.clang_getArrayElementType.argtypes = [Type] |
| 2333 | lib.clang_getArrayElementType.restype = Type |
| 2334 | lib.clang_getArrayElementType.errcheck = Type.from_result |
Gregory Szorc | 2c40835 | 2012-05-14 03:56:33 +0000 | [diff] [blame] | 2335 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2336 | lib.clang_getArraySize.argtypes = [Type] |
| 2337 | lib.clang_getArraySize.restype = c_longlong |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2338 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2339 | lib.clang_getCanonicalCursor.argtypes = [Cursor] |
| 2340 | lib.clang_getCanonicalCursor.restype = Cursor |
| 2341 | lib.clang_getCanonicalCursor.errcheck = Cursor.from_cursor_result |
| 2342 | |
| 2343 | lib.clang_getCanonicalType.argtypes = [Type] |
| 2344 | lib.clang_getCanonicalType.restype = Type |
| 2345 | lib.clang_getCanonicalType.errcheck = Type.from_result |
| 2346 | |
| 2347 | lib.clang_getCompletionAvailability.argtypes = [c_void_p] |
| 2348 | lib.clang_getCompletionAvailability.restype = c_int |
| 2349 | |
| 2350 | lib.clang_getCompletionChunkCompletionString.argtypes = [c_void_p, c_int] |
| 2351 | lib.clang_getCompletionChunkCompletionString.restype = c_object_p |
| 2352 | |
| 2353 | lib.clang_getCompletionChunkKind.argtypes = [c_void_p, c_int] |
| 2354 | lib.clang_getCompletionChunkKind.restype = c_int |
| 2355 | |
| 2356 | lib.clang_getCompletionChunkText.argtypes = [c_void_p, c_int] |
| 2357 | lib.clang_getCompletionChunkText.restype = _CXString |
| 2358 | |
| 2359 | lib.clang_getCompletionPriority.argtypes = [c_void_p] |
| 2360 | lib.clang_getCompletionPriority.restype = c_int |
| 2361 | |
| 2362 | lib.clang_getCString.argtypes = [_CXString] |
| 2363 | lib.clang_getCString.restype = c_char_p |
| 2364 | |
| 2365 | lib.clang_getCursor.argtypes = [TranslationUnit, SourceLocation] |
| 2366 | lib.clang_getCursor.restype = Cursor |
| 2367 | |
| 2368 | lib.clang_getCursorDefinition.argtypes = [Cursor] |
| 2369 | lib.clang_getCursorDefinition.restype = Cursor |
| 2370 | lib.clang_getCursorDefinition.errcheck = Cursor.from_result |
| 2371 | |
| 2372 | lib.clang_getCursorDisplayName.argtypes = [Cursor] |
| 2373 | lib.clang_getCursorDisplayName.restype = _CXString |
| 2374 | lib.clang_getCursorDisplayName.errcheck = _CXString.from_result |
| 2375 | |
| 2376 | lib.clang_getCursorExtent.argtypes = [Cursor] |
| 2377 | lib.clang_getCursorExtent.restype = SourceRange |
| 2378 | |
| 2379 | lib.clang_getCursorLexicalParent.argtypes = [Cursor] |
| 2380 | lib.clang_getCursorLexicalParent.restype = Cursor |
| 2381 | lib.clang_getCursorLexicalParent.errcheck = Cursor.from_cursor_result |
| 2382 | |
| 2383 | lib.clang_getCursorLocation.argtypes = [Cursor] |
| 2384 | lib.clang_getCursorLocation.restype = SourceLocation |
| 2385 | |
| 2386 | lib.clang_getCursorReferenced.argtypes = [Cursor] |
| 2387 | lib.clang_getCursorReferenced.restype = Cursor |
| 2388 | lib.clang_getCursorReferenced.errcheck = Cursor.from_result |
| 2389 | |
| 2390 | lib.clang_getCursorReferenceNameRange.argtypes = [Cursor, c_uint, c_uint] |
| 2391 | lib.clang_getCursorReferenceNameRange.restype = SourceRange |
| 2392 | |
| 2393 | lib.clang_getCursorSemanticParent.argtypes = [Cursor] |
| 2394 | lib.clang_getCursorSemanticParent.restype = Cursor |
| 2395 | lib.clang_getCursorSemanticParent.errcheck = Cursor.from_cursor_result |
| 2396 | |
| 2397 | lib.clang_getCursorSpelling.argtypes = [Cursor] |
| 2398 | lib.clang_getCursorSpelling.restype = _CXString |
| 2399 | lib.clang_getCursorSpelling.errcheck = _CXString.from_result |
| 2400 | |
| 2401 | lib.clang_getCursorType.argtypes = [Cursor] |
| 2402 | lib.clang_getCursorType.restype = Type |
| 2403 | lib.clang_getCursorType.errcheck = Type.from_result |
| 2404 | |
| 2405 | lib.clang_getCursorUSR.argtypes = [Cursor] |
| 2406 | lib.clang_getCursorUSR.restype = _CXString |
| 2407 | lib.clang_getCursorUSR.errcheck = _CXString.from_result |
| 2408 | |
| 2409 | #lib.clang_getCXTUResourceUsage.argtypes = [TranslationUnit] |
| 2410 | #lib.clang_getCXTUResourceUsage.restype = CXTUResourceUsage |
| 2411 | |
| 2412 | lib.clang_getCXXAccessSpecifier.argtypes = [Cursor] |
| 2413 | lib.clang_getCXXAccessSpecifier.restype = c_uint |
| 2414 | |
| 2415 | lib.clang_getDeclObjCTypeEncoding.argtypes = [Cursor] |
| 2416 | lib.clang_getDeclObjCTypeEncoding.restype = _CXString |
| 2417 | lib.clang_getDeclObjCTypeEncoding.errcheck = _CXString.from_result |
| 2418 | |
| 2419 | lib.clang_getDiagnostic.argtypes = [c_object_p, c_uint] |
| 2420 | lib.clang_getDiagnostic.restype = c_object_p |
| 2421 | |
| 2422 | lib.clang_getDiagnosticCategory.argtypes = [Diagnostic] |
| 2423 | lib.clang_getDiagnosticCategory.restype = c_uint |
| 2424 | |
| 2425 | lib.clang_getDiagnosticCategoryName.argtypes = [c_uint] |
| 2426 | lib.clang_getDiagnosticCategoryName.restype = _CXString |
| 2427 | lib.clang_getDiagnosticCategoryName.errcheck = _CXString.from_result |
| 2428 | |
| 2429 | lib.clang_getDiagnosticFixIt.argtypes = [Diagnostic, c_uint, |
| 2430 | POINTER(SourceRange)] |
| 2431 | lib.clang_getDiagnosticFixIt.restype = _CXString |
| 2432 | lib.clang_getDiagnosticFixIt.errcheck = _CXString.from_result |
| 2433 | |
| 2434 | lib.clang_getDiagnosticLocation.argtypes = [Diagnostic] |
| 2435 | lib.clang_getDiagnosticLocation.restype = SourceLocation |
| 2436 | |
| 2437 | lib.clang_getDiagnosticNumFixIts.argtypes = [Diagnostic] |
| 2438 | lib.clang_getDiagnosticNumFixIts.restype = c_uint |
| 2439 | |
| 2440 | lib.clang_getDiagnosticNumRanges.argtypes = [Diagnostic] |
| 2441 | lib.clang_getDiagnosticNumRanges.restype = c_uint |
| 2442 | |
| 2443 | lib.clang_getDiagnosticOption.argtypes = [Diagnostic, POINTER(_CXString)] |
| 2444 | lib.clang_getDiagnosticOption.restype = _CXString |
| 2445 | lib.clang_getDiagnosticOption.errcheck = _CXString.from_result |
| 2446 | |
| 2447 | lib.clang_getDiagnosticRange.argtypes = [Diagnostic, c_uint] |
| 2448 | lib.clang_getDiagnosticRange.restype = SourceRange |
| 2449 | |
| 2450 | lib.clang_getDiagnosticSeverity.argtypes = [Diagnostic] |
| 2451 | lib.clang_getDiagnosticSeverity.restype = c_int |
| 2452 | |
| 2453 | lib.clang_getDiagnosticSpelling.argtypes = [Diagnostic] |
| 2454 | lib.clang_getDiagnosticSpelling.restype = _CXString |
| 2455 | lib.clang_getDiagnosticSpelling.errcheck = _CXString.from_result |
| 2456 | |
| 2457 | lib.clang_getElementType.argtypes = [Type] |
| 2458 | lib.clang_getElementType.restype = Type |
| 2459 | lib.clang_getElementType.errcheck = Type.from_result |
| 2460 | |
| 2461 | lib.clang_getEnumConstantDeclUnsignedValue.argtypes = [Cursor] |
| 2462 | lib.clang_getEnumConstantDeclUnsignedValue.restype = c_ulonglong |
| 2463 | |
| 2464 | lib.clang_getEnumConstantDeclValue.argtypes = [Cursor] |
| 2465 | lib.clang_getEnumConstantDeclValue.restype = c_longlong |
| 2466 | |
| 2467 | lib.clang_getEnumDeclIntegerType.argtypes = [Cursor] |
| 2468 | lib.clang_getEnumDeclIntegerType.restype = Type |
| 2469 | lib.clang_getEnumDeclIntegerType.errcheck = Type.from_result |
Tobias Grosser | 28d939f | 2012-02-05 11:42:20 +0000 | [diff] [blame] | 2470 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2471 | lib.clang_getFile.argtypes = [TranslationUnit, c_char_p] |
| 2472 | lib.clang_getFile.restype = c_object_p |
Tobias Grosser | eb9ff2e | 2012-02-05 11:42:25 +0000 | [diff] [blame] | 2473 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2474 | lib.clang_getFileName.argtypes = [File] |
| 2475 | lib.clang_getFileName.restype = _CXString |
| 2476 | # TODO go through _CXString.from_result? |
Anders Waldenborg | bbc2e09 | 2012-05-02 20:57:33 +0000 | [diff] [blame] | 2477 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2478 | lib.clang_getFileTime.argtypes = [File] |
| 2479 | lib.clang_getFileTime.restype = c_uint |
Anders Waldenborg | bbc2e09 | 2012-05-02 20:57:33 +0000 | [diff] [blame] | 2480 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2481 | lib.clang_getIBOutletCollectionType.argtypes = [Cursor] |
| 2482 | lib.clang_getIBOutletCollectionType.restype = Type |
| 2483 | lib.clang_getIBOutletCollectionType.errcheck = Type.from_result |
Gregory Szorc | 5cc6787 | 2012-03-10 22:23:27 +0000 | [diff] [blame] | 2484 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2485 | lib.clang_getIncludedFile.argtypes = [Cursor] |
| 2486 | lib.clang_getIncludedFile.restype = File |
| 2487 | lib.clang_getIncludedFile.errcheck = File.from_cursor_result |
Manuel Klimek | 667fd80 | 2012-05-07 05:56:03 +0000 | [diff] [blame] | 2488 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2489 | lib.clang_getInclusions.argtypes = [TranslationUnit, |
| 2490 | callbacks['translation_unit_includes'], py_object] |
Manuel Klimek | 667fd80 | 2012-05-07 05:56:03 +0000 | [diff] [blame] | 2491 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2492 | lib.clang_getInstantiationLocation.argtypes = [SourceLocation, |
| 2493 | POINTER(c_object_p), POINTER(c_uint), POINTER(c_uint), POINTER(c_uint)] |
Daniel Dunbar | de3b8e5 | 2010-01-24 04:10:22 +0000 | [diff] [blame] | 2494 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2495 | lib.clang_getLocation.argtypes = [TranslationUnit, File, c_uint, c_uint] |
| 2496 | lib.clang_getLocation.restype = SourceLocation |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2497 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2498 | lib.clang_getLocationForOffset.argtypes = [TranslationUnit, File, c_uint] |
| 2499 | lib.clang_getLocationForOffset.restype = SourceLocation |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2500 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2501 | lib.clang_getNullCursor.restype = Cursor |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2502 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2503 | lib.clang_getNumArgTypes.argtypes = [Type] |
| 2504 | lib.clang_getNumArgTypes.restype = c_uint |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2505 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2506 | lib.clang_getNumCompletionChunks.argtypes = [c_void_p] |
| 2507 | lib.clang_getNumCompletionChunks.restype = c_int |
Gregory Szorc | 96ad633 | 2012-02-05 19:42:06 +0000 | [diff] [blame] | 2508 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2509 | lib.clang_getNumDiagnostics.argtypes = [c_object_p] |
| 2510 | lib.clang_getNumDiagnostics.restype = c_uint |
Gregory Szorc | 31cc38c | 2012-02-19 18:28:33 +0000 | [diff] [blame] | 2511 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2512 | lib.clang_getNumElements.argtypes = [Type] |
| 2513 | lib.clang_getNumElements.restype = c_longlong |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2514 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2515 | lib.clang_getNumOverloadedDecls.argtypes = [Cursor] |
| 2516 | lib.clang_getNumOverloadedDecls.restyp = c_uint |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2517 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2518 | lib.clang_getOverloadedDecl.argtypes = [Cursor, c_uint] |
| 2519 | lib.clang_getOverloadedDecl.restype = Cursor |
| 2520 | lib.clang_getOverloadedDecl.errcheck = Cursor.from_cursor_result |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2521 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2522 | lib.clang_getPointeeType.argtypes = [Type] |
| 2523 | lib.clang_getPointeeType.restype = Type |
| 2524 | lib.clang_getPointeeType.errcheck = Type.from_result |
Gregory Szorc | 826fce5 | 2012-02-20 17:45:30 +0000 | [diff] [blame] | 2525 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2526 | lib.clang_getRange.argtypes = [SourceLocation, SourceLocation] |
| 2527 | lib.clang_getRange.restype = SourceRange |
Gregory Szorc | 826fce5 | 2012-02-20 17:45:30 +0000 | [diff] [blame] | 2528 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2529 | lib.clang_getRangeEnd.argtypes = [SourceRange] |
| 2530 | lib.clang_getRangeEnd.restype = SourceLocation |
Gregory Szorc | 8605760 | 2012-02-17 07:44:46 +0000 | [diff] [blame] | 2531 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2532 | lib.clang_getRangeStart.argtypes = [SourceRange] |
| 2533 | lib.clang_getRangeStart.restype = SourceLocation |
Gregory Szorc | bf8ca00 | 2012-02-17 07:47:38 +0000 | [diff] [blame] | 2534 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2535 | lib.clang_getResultType.argtypes = [Type] |
| 2536 | lib.clang_getResultType.restype = Type |
| 2537 | lib.clang_getResultType.errcheck = Type.from_result |
Douglas Gregor | 13102ff | 2011-10-19 05:51:43 +0000 | [diff] [blame] | 2538 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2539 | lib.clang_getSpecializedCursorTemplate.argtypes = [Cursor] |
| 2540 | lib.clang_getSpecializedCursorTemplate.restype = Cursor |
| 2541 | lib.clang_getSpecializedCursorTemplate.errcheck = Cursor.from_cursor_result |
Argyrios Kyrtzidis | d7933e6 | 2011-08-17 00:43:03 +0000 | [diff] [blame] | 2542 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2543 | lib.clang_getTemplateCursorKind.argtypes = [Cursor] |
| 2544 | lib.clang_getTemplateCursorKind.restype = c_uint |
Gregory Szorc | 7eb691a | 2012-02-20 17:44:49 +0000 | [diff] [blame] | 2545 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2546 | #lib.clang_getTokenExtent.argtypes = [TranslationUnit, Token] |
| 2547 | #lib.clang_getTokenExtent.restype = SourceRange |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2548 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2549 | #lib.clang_getTokenKind.argtypes = [Token] |
| 2550 | #lib.clang_getTokenKind.restype = c_uint |
| 2551 | #lib.clang_getTokenKind.errcheck = TokenKind.from_result |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2552 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2553 | #lib.clang_getTokenLocation.argtype = [TranslationUnit, Token] |
| 2554 | #lib.clang_getTokenLocation.restype = SourceLocation |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2555 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2556 | #lib.clang_getTokenSpelling.argtype = [TranslationUnit, Token] |
| 2557 | #lib.clang_getTokenSpelling.restype = _CXString |
| 2558 | #lib.clang_getTokenSpelling.errcheck = _CXString.from_result |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2559 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2560 | lib.clang_getTranslationUnitCursor.argtypes = [TranslationUnit] |
| 2561 | lib.clang_getTranslationUnitCursor.restype = Cursor |
| 2562 | lib.clang_getTranslationUnitCursor.errcheck = Cursor.from_result |
Tobias Grosser | 265e6b2 | 2011-02-05 17:54:00 +0000 | [diff] [blame] | 2563 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2564 | lib.clang_getTranslationUnitSpelling.argtypes = [TranslationUnit] |
| 2565 | lib.clang_getTranslationUnitSpelling.restype = _CXString |
| 2566 | lib.clang_getTranslationUnitSpelling.errcheck = _CXString.from_result |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2567 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2568 | lib.clang_getTUResourceUsageName.argtypes = [c_uint] |
| 2569 | lib.clang_getTUResourceUsageName.restype = c_char_p |
Daniel Dunbar | 1b945a7 | 2010-01-24 04:09:43 +0000 | [diff] [blame] | 2570 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2571 | lib.clang_getTypeDeclaration.argtypes = [Type] |
| 2572 | lib.clang_getTypeDeclaration.restype = Cursor |
| 2573 | lib.clang_getTypeDeclaration.errcheck = Cursor.from_result |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2574 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2575 | lib.clang_getTypedefDeclUnderlyingType.argtypes = [Cursor] |
| 2576 | lib.clang_getTypedefDeclUnderlyingType.restype = Type |
| 2577 | lib.clang_getTypedefDeclUnderlyingType.errcheck = Type.from_result |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2578 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2579 | lib.clang_getTypeKindSpelling.argtypes = [c_uint] |
| 2580 | lib.clang_getTypeKindSpelling.restype = _CXString |
| 2581 | lib.clang_getTypeKindSpelling.errcheck = _CXString.from_result |
Daniel Dunbar | ef7f798 | 2010-02-13 18:33:18 +0000 | [diff] [blame] | 2582 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2583 | lib.clang_hashCursor.argtypes = [Cursor] |
| 2584 | lib.clang_hashCursor.restype = c_uint |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2585 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2586 | lib.clang_isAttribute.argtypes = [CursorKind] |
| 2587 | lib.clang_isAttribute.restype = bool |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2588 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2589 | lib.clang_isConstQualifiedType.argtypes = [Type] |
| 2590 | lib.clang_isConstQualifiedType.restype = bool |
Tobias Grosser | a9ea5df | 2011-10-31 00:07:19 +0000 | [diff] [blame] | 2591 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2592 | lib.clang_isCursorDefinition.argtypes = [Cursor] |
| 2593 | lib.clang_isCursorDefinition.restype = bool |
Daniel Dunbar | 30c0f26 | 2010-01-24 02:02:07 +0000 | [diff] [blame] | 2594 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2595 | lib.clang_isDeclaration.argtypes = [CursorKind] |
| 2596 | lib.clang_isDeclaration.restype = bool |
Daniel Dunbar | 4efd632 | 2010-01-25 00:43:08 +0000 | [diff] [blame] | 2597 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2598 | lib.clang_isExpression.argtypes = [CursorKind] |
| 2599 | lib.clang_isExpression.restype = bool |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2600 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2601 | lib.clang_isFileMultipleIncludeGuarded.argtypes = [TranslationUnit, File] |
| 2602 | lib.clang_isFileMultipleIncludeGuarded.restype = bool |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2603 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2604 | lib.clang_isFunctionTypeVariadic.argtypes = [Type] |
| 2605 | lib.clang_isFunctionTypeVariadic.restype = bool |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2606 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2607 | lib.clang_isInvalid.argtypes = [CursorKind] |
| 2608 | lib.clang_isInvalid.restype = bool |
Tobias Grosser | 0a16680 | 2011-02-05 17:54:04 +0000 | [diff] [blame] | 2609 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2610 | lib.clang_isPODType.argtypes = [Type] |
| 2611 | lib.clang_isPODType.restype = bool |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 2612 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2613 | lib.clang_isPreprocessing.argtypes = [CursorKind] |
| 2614 | lib.clang_isPreprocessing.restype = bool |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 2615 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2616 | lib.clang_isReference.argtypes = [CursorKind] |
| 2617 | lib.clang_isReference.restype = bool |
Tobias Grosser | a87dbcc | 2011-02-05 17:54:10 +0000 | [diff] [blame] | 2618 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2619 | lib.clang_isRestrictQualifiedType.argtypes = [Type] |
| 2620 | lib.clang_isRestrictQualifiedType.restype = bool |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 2621 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2622 | lib.clang_isStatement.argtypes = [CursorKind] |
| 2623 | lib.clang_isStatement.restype = bool |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 2624 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2625 | lib.clang_isTranslationUnit.argtypes = [CursorKind] |
| 2626 | lib.clang_isTranslationUnit.restype = bool |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 2627 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2628 | lib.clang_isUnexposed.argtypes = [CursorKind] |
| 2629 | lib.clang_isUnexposed.restype = bool |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2630 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2631 | lib.clang_isVirtualBase.argtypes = [Cursor] |
| 2632 | lib.clang_isVirtualBase.restype = bool |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2633 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2634 | lib.clang_isVolatileQualifiedType.argtypes = [Type] |
| 2635 | lib.clang_isVolatileQualifiedType.restype = bool |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2636 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2637 | lib.clang_parseTranslationUnit.argypes = [Index, c_char_p, c_void_p, c_int, |
| 2638 | c_void_p, c_int, c_int] |
| 2639 | lib.clang_parseTranslationUnit.restype = c_object_p |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2640 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2641 | lib.clang_reparseTranslationUnit.argtypes = [TranslationUnit, c_int, |
| 2642 | c_void_p, c_int] |
| 2643 | lib.clang_reparseTranslationUnit.restype = c_int |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2644 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2645 | lib.clang_saveTranslationUnit.argtypes = [TranslationUnit, c_char_p, |
| 2646 | c_uint] |
| 2647 | lib.clang_saveTranslationUnit.restype = c_int |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2648 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2649 | #lib.clang_tokenize.argtypes = [TranslationUnit, SourceRange, |
| 2650 | # POINTER(POINTER(Token)), POINTER(c_uint)] |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2651 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2652 | lib.clang_visitChildren.argtypes = [Cursor, callbacks['cursor_visit'], |
| 2653 | py_object] |
| 2654 | lib.clang_visitChildren.restype = c_uint |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2655 | |
Gregory Szorc | 9537e20 | 2012-07-12 04:56:46 +0000 | [diff] [blame] | 2656 | register_functions(lib) |
Tobias Grosser | 6d2a40c | 2011-02-05 17:54:07 +0000 | [diff] [blame] | 2657 | |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2658 | __all__ = [ |
| 2659 | 'CodeCompletionResults', |
Arnaud A. de Grandmaison | 910ff3f | 2012-06-30 11:28:04 +0000 | [diff] [blame] | 2660 | 'CompilationDatabase', |
| 2661 | 'CompileCommands', |
| 2662 | 'CompileCommand', |
Gregory Szorc | fbf620b | 2012-05-08 05:56:38 +0000 | [diff] [blame] | 2663 | 'CursorKind', |
| 2664 | 'Cursor', |
| 2665 | 'Diagnostic', |
| 2666 | 'File', |
| 2667 | 'FixIt', |
| 2668 | 'Index', |
| 2669 | 'SourceLocation', |
| 2670 | 'SourceRange', |
| 2671 | 'TranslationUnitLoadError', |
| 2672 | 'TranslationUnit', |
| 2673 | 'TypeKind', |
| 2674 | 'Type', |
| 2675 | ] |