14efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#===- cindex.py - Python Indexing Library Bindings -----------*- python -*--===#
24efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
34efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#                     The LLVM Compiler Infrastructure
44efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
54efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# This file is distributed under the University of Illinois Open Source
64efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# License. See LICENSE.TXT for details.
74efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
84efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#===------------------------------------------------------------------------===#
94efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
104efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbarr"""
114efd632322731425d83d205f26bddcdfe1ac8937Daniel DunbarClang Indexing Library Bindings
124efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar===============================
134efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
144efd632322731425d83d205f26bddcdfe1ac8937Daniel DunbarThis module provides an interface to the Clang indexing library. It is a
154efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbarlow-level interface to the indexing library which attempts to match the Clang
164efd632322731425d83d205f26bddcdfe1ac8937Daniel DunbarAPI directly while also being "pythonic". Notable differences from the C API
174efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbarare:
184efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
194efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar * string results are returned as Python strings, not CXString objects.
204efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
214efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar * null cursors are translated to None.
224efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
234efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar * access to child cursors is done via iteration, not visitation.
244efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
254efd632322731425d83d205f26bddcdfe1ac8937Daniel DunbarThe major indexing objects are:
264efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
274efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar  Index
284efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
294efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar    The top-level object which manages some global library state.
304efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
314efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar  TranslationUnit
324efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
334efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar    High-level object encapsulating the AST for a single translation unit. These
344efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar    can be loaded from .ast files or parsed on the fly.
354efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
364efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar  Cursor
374efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
384efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar    Generic object for representing a node in the AST.
394efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
404efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar  SourceRange, SourceLocation, and File
414efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
424efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar    Objects representing information about the input source.
434efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
444efd632322731425d83d205f26bddcdfe1ac8937Daniel DunbarMost object information is exposed using properties, when the underlying API
454efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbarcall is efficient.
464efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar"""
474efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar
484efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# TODO
494efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# ====
504efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
51532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar# o API support for invalid translation units. Currently we can't even get the
52532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar#   diagnostics on failure because they refer to locations in an object that
53532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar#   will have been invalidated.
54532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar#
554efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# o fix memory management issues (currently client must hold on to index and
564efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#   translation unit, or risk crashes).
574efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
584efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# o expose code completion APIs.
594efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
604efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# o cleanup ctypes wrapping, would be nice to separate the ctypes details more
614efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#   clearly, and hide from the external interface (i.e., help(cindex)).
624efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar#
634efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar# o implement additional SourceLocation, SourceRange, and File methods.
6430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
6530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarfrom ctypes import *
66826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorcimport collections
6730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
68be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorcimport clang.enumerations
69be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
7030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# ctypes doesn't implicitly convert c_void_p to the appropriate wrapper
7130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# object. This is a problem, because it means that from_parameter will see an
7230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# integer and pass the wrong value on platforms where int != void*. Work around
7330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# this by marshalling object arguments as void**.
7430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarc_object_p = POINTER(c_void_p)
7530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
769537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorccallbacks = {}
7730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
78fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc### Exception Classes ###
79fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
80fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorcclass TranslationUnitLoadError(Exception):
81fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    """Represents an error that occurred when loading a TranslationUnit.
82fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
83fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    This is raised in the case where a TranslationUnit could not be
84fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    instantiated due to failure in the libclang library.
85fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
86fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    FIXME: Make libclang expose additional error information in this scenario.
87fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    """
88fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    pass
89fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
90fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorcclass TranslationUnitSaveError(Exception):
91fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    """Represents an error that occurred when saving a TranslationUnit.
92fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
93fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    Each error has associated with it an enumerated value, accessible under
94fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    e.save_error. Consumers can compare the value with one of the ERROR_
95fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    constants in this class.
96fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    """
97fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
98fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Indicates that an unknown error occurred. This typically indicates that
99fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # I/O failed during save.
100fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    ERROR_UNKNOWN = 1
101fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
102fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Indicates that errors during translation prevented saving. The errors
103fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # should be available via the TranslationUnit's diagnostics.
104fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    ERROR_TRANSLATION_ERRORS = 2
105fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
106fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Indicates that the translation unit was somehow invalid.
107fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    ERROR_INVALID_TU = 3
108fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
109fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def __init__(self, enumeration, message):
110fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        assert isinstance(enumeration, int)
111fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
112fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if enumeration < 1 or enumeration > 3:
113fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            raise Exception("Encountered undefined TranslationUnit save error "
114fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                            "constant: %d. Please file a bug to have this "
115fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                            "value supported." % enumeration)
116fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
117fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        self.save_error = enumeration
1182283b4664b004aae034b08f305ad2bc1dff9868eGregory Szorc        Exception.__init__(self, 'Error %d: %s' % (enumeration, message))
119fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
12030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar### Structures and Utility Classes ###
12130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
122b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorcclass CachedProperty(object):
123b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    """Decorator that lazy-loads the value of a property.
124b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
125b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    The first time the property is accessed, the original property function is
126b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    executed. The value it returns is set as the new value of that instance's
127b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    property, replacing the original method.
128b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    """
129b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
130b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    def __init__(self, wrapped):
131b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        self.wrapped = wrapped
132b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        try:
133b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc            self.__doc__ = wrapped.__doc__
134b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        except:
135b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc            pass
136b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
137b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc    def __get__(self, instance, instance_type=None):
138b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        if instance is None:
139b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc            return self
140b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
141b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        value = self.wrapped(instance)
142b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        setattr(instance, self.wrapped.__name__, value)
143b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
144b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc        return value
145b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
146b15b15c7f641fd7a71ad94ffe41b162f03d429b0Gregory Szorc
147a33dca490ad55c6f4bfc38a911f41a66f508a482Daniel Dunbarclass _CXString(Structure):
148a33dca490ad55c6f4bfc38a911f41a66f508a482Daniel Dunbar    """Helper for transforming CXString results."""
14930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
15030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    _fields_ = [("spelling", c_char_p), ("free", c_int)]
15130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
15230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def __del__(self):
153fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_disposeString(self)
15430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
155a33dca490ad55c6f4bfc38a911f41a66f508a482Daniel Dunbar    @staticmethod
156a33dca490ad55c6f4bfc38a911f41a66f508a482Daniel Dunbar    def from_result(res, fn, args):
157a33dca490ad55c6f4bfc38a911f41a66f508a482Daniel Dunbar        assert isinstance(res, _CXString)
158fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCString(res)
15912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
16030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass SourceLocation(Structure):
16130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
162149f38abf5e122941090bfb9d1d78dde0859024aDaniel Dunbar    A SourceLocation represents a particular location within a source file.
16330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
164e32af4213eb499fc5b6db15a9da9712148fcf8b5Daniel Dunbar    _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
165f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    _data = None
16630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
167f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    def _get_instantiation(self):
168f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        if self._data is None:
1693239a67361cc89eba2fe7c7abdb41bd2c9414207Daniel Dunbar            f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
170fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            conf.lib.clang_getInstantiationLocation(self, byref(f), byref(l),
1719537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                    byref(c), byref(o))
1728198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser            if f:
1738198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser                f = File(f)
1748198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser            else:
1758198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser                f = None
1766b04623bcc64a5091a47fb18cd40af5e93b773adArgyrios Kyrtzidis            self._data = (f, int(l.value), int(c.value), int(o.value))
177f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        return self._data
178f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar
17958ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser    @staticmethod
18058ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser    def from_position(tu, file, line, column):
18158ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser        """
18258ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser        Retrieve the source location associated with a given file/line/column in
18358ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser        a particular translation unit.
18458ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser        """
185fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getLocation(tu, file, line, column)
18658ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser
18774bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc    @staticmethod
18874bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc    def from_offset(tu, file, offset):
18974bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc        """Retrieve a SourceLocation from a given character offset.
19074bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc
19174bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc        tu -- TranslationUnit file belongs to
19274bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc        file -- File instance to obtain offset from
19374bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc        offset -- Integer character offset within file
19474bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc        """
195fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getLocationForOffset(tu, file, offset)
19674bb710e73229ce0ad3bb27c8689c0276e8ec131Gregory Szorc
197f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    @property
198f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    def file(self):
199f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        """Get the file represented by this source location."""
200f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        return self._get_instantiation()[0]
201f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar
202f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    @property
203f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    def line(self):
204f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        """Get the line represented by this source location."""
205f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        return self._get_instantiation()[1]
206f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar
207f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    @property
208f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    def column(self):
209f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        """Get the column represented by this source location."""
210f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        return self._get_instantiation()[2]
21130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2123239a67361cc89eba2fe7c7abdb41bd2c9414207Daniel Dunbar    @property
2133239a67361cc89eba2fe7c7abdb41bd2c9414207Daniel Dunbar    def offset(self):
2143239a67361cc89eba2fe7c7abdb41bd2c9414207Daniel Dunbar        """Get the file offset represented by this source location."""
2153239a67361cc89eba2fe7c7abdb41bd2c9414207Daniel Dunbar        return self._get_instantiation()[3]
2163239a67361cc89eba2fe7c7abdb41bd2c9414207Daniel Dunbar
21774858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser    def __eq__(self, other):
218fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_equalLocations(self, other)
21974858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser
22074858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser    def __ne__(self, other):
22174858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser        return not self.__eq__(other)
22274858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser
2237b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar    def __repr__(self):
2248198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser        if self.file:
2258198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser            filename = self.file.name
2268198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser        else:
2278198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser            filename = None
2287b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar        return "<SourceLocation file %r, line %r, column %r>" % (
2298198288f4e5dfe1743abeed1aee780fe1ddcdf07Tobias Grosser            filename, self.line, self.column)
2307b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar
23130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass SourceRange(Structure):
23230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
23330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    A SourceRange describes a range of source locations within the source
23430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    code.
23530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
23630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    _fields_ = [
237e32af4213eb499fc5b6db15a9da9712148fcf8b5Daniel Dunbar        ("ptr_data", c_void_p * 2),
23830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        ("begin_int_data", c_uint),
23930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        ("end_int_data", c_uint)]
24030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
241532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    # FIXME: Eliminate this and make normal constructor? Requires hiding ctypes
242532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    # object.
243532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    @staticmethod
244532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    def from_locations(start, end):
245fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getRange(start, end)
246532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
2477b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar    @property
24830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def start(self):
24930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
25030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Return a SourceLocation representing the first character within a
25130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        source range.
25230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
253fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getRangeStart(self)
25430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2557b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar    @property
25630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def end(self):
25730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
25830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Return a SourceLocation representing the last character within a
25930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        source range.
26030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
261fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getRangeEnd(self)
262f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar
26374858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser    def __eq__(self, other):
264fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_equalRanges(self, other)
26574858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser
26674858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser    def __ne__(self, other):
26774858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser        return not self.__eq__(other)
26874858335a1a5205b3e1c89ecf9221cea839c0b0bTobias Grosser
2698c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis    def __contains__(self, other):
2708c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        """Useful to detect the Token/Lexer bug"""
2718c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        if not isinstance(other, SourceLocation):
2728c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            return False
2738c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        if other.file is None and self.start.file is None:
2748c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            pass
275c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        elif ( self.start.file.name != other.file.name or
2768c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis               other.file.name != self.end.file.name):
2778c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            # same file name
2788c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            return False
2798c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        # same file, in between lines
2808c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        if self.start.line < other.line < self.end.line:
2818c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            return True
2828c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        elif self.start.line == other.line:
2838c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            # same file first line
2848c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            if self.start.column <= other.column:
2858c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis                return True
2868c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        elif other.line == self.end.line:
2878c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            # same file last line
2888c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis            if other.column <= self.end.column:
2898c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis                return True
2908c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis        return False
2918c099d9b04f0b3025e713f76b42a50f3a67d404fArgyrios Kyrtzidis
292f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar    def __repr__(self):
293f869083cbfea538d6b7baf4ece30066b11984e12Daniel Dunbar        return "<SourceRange start %r, end %r>" % (self.start, self.end)
29430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
295532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbarclass Diagnostic(object):
296532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    """
297532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    A Diagnostic is a single instance of a Clang diagnostic. It includes the
298532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    diagnostic severity, the message, the location the diagnostic occurred, as
299532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    well as additional source ranges and associated fix-it hints.
300532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    """
301532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
302532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    Ignored = 0
303532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    Note    = 1
304532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    Warning = 2
305532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    Error   = 3
306532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    Fatal   = 4
307532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
3083b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def __init__(self, ptr):
3093b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer        self.ptr = ptr
3103b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3113b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def __del__(self):
312fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_disposeDiagnostic(self)
3133b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3143b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    @property
3153b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def severity(self):
316fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getDiagnosticSeverity(self)
3173b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3183b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    @property
3193b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def location(self):
320fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getDiagnosticLocation(self)
3213b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3223b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    @property
3233b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def spelling(self):
324fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getDiagnosticSpelling(self)
3253b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3263b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    @property
3273b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def ranges(self):
3281d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer        class RangeIterator:
3293b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __init__(self, diag):
3303b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer                self.diag = diag
3313b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3323b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __len__(self):
333fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                return int(conf.lib.clang_getDiagnosticNumRanges(self.diag))
3343b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3353b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __getitem__(self, key):
336ba5d10b82b3cc00b4d71b273a18c051a1f38f22fTobias Grosser                if (key >= len(self)):
337ba5d10b82b3cc00b4d71b273a18c051a1f38f22fTobias Grosser                    raise IndexError
338fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                return conf.lib.clang_getDiagnosticRange(self.diag, key)
3393b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
340ff090ca42aa319e1bbdde38b3940219ea11e07b3Tobias Grosser        return RangeIterator(self)
3413b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3423b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    @property
3433b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def fixits(self):
3441d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer        class FixItIterator:
3453b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __init__(self, diag):
3463b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer                self.diag = diag
3473b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3483b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __len__(self):
349fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                return int(conf.lib.clang_getDiagnosticNumFixIts(self.diag))
3503b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3513b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __getitem__(self, key):
3523b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer                range = SourceRange()
353fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                value = conf.lib.clang_getDiagnosticFixIt(self.diag, key,
3549537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                        byref(range))
3551d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer                if len(value) == 0:
3561d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer                    raise IndexError
3573b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
3583b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer                return FixIt(range, value)
3593b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
360ff090ca42aa319e1bbdde38b3940219ea11e07b3Tobias Grosser        return FixItIterator(self)
361532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
362ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    @property
363ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    def category_number(self):
3646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        """The category number for this diagnostic or 0 if unavailable."""
365fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getDiagnosticCategory(self)
366ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser
367ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    @property
368ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    def category_name(self):
369ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser        """The string name of the category for this diagnostic."""
3706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        return conf.lib.clang_getDiagnosticCategoryText(self)
371ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser
372ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    @property
373ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    def option(self):
374ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser        """The command-line option that enables this diagnostic."""
375fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getDiagnosticOption(self, None)
376ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser
377ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    @property
378ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser    def disable_option(self):
379ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser        """The command-line option that disables this diagnostic."""
380ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser        disable = _CXString()
381fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_getDiagnosticOption(self, byref(disable))
382ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser
383fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCString(disable)
384ea403825faa5b8780a9b44277e6a2c68d7849146Tobias Grosser
385532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    def __repr__(self):
386532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar        return "<Diagnostic severity %r, location %r, spelling %r>" % (
387532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar            self.severity, self.location, self.spelling)
388532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
389ff090ca42aa319e1bbdde38b3940219ea11e07b3Tobias Grosser    def from_param(self):
390ff090ca42aa319e1bbdde38b3940219ea11e07b3Tobias Grosser      return self.ptr
391ff090ca42aa319e1bbdde38b3940219ea11e07b3Tobias Grosser
392532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbarclass FixIt(object):
393532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    """
394532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    A FixIt represents a transformation to be applied to the source to
395532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    "fix-it". The fix-it shouldbe applied by replacing the given source range
396532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    with the given value.
397532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    """
398532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
399532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    def __init__(self, range, value):
400532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar        self.range = range
401532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar        self.value = value
402532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
403532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar    def __repr__(self):
404532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar        return "<FixIt range %r, value %r>" % (self.range, self.value)
405532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
406be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorcclass TokenGroup(object):
407be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    """Helper class to facilitate token management.
408be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
409be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    Tokens are allocated from libclang in chunks. They must be disposed of as a
410be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    collective group.
411be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
412be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    One purpose of this class is for instances to represent groups of allocated
413be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    tokens. Each token in a group contains a reference back to an instance of
414be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    this class. When all tokens from a group are garbage collected, it allows
415be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    this class to be garbage collected. When this class is garbage collected,
416be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    it calls the libclang destructor which invalidates all tokens in the group.
417be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
418be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    You should not instantiate this class outside of this module.
419be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    """
420be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def __init__(self, tu, memory, count):
421be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        self._tu = tu
422be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        self._memory = memory
423be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        self._count = count
424be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
425be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def __del__(self):
426fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_disposeTokens(self._tu, self._memory, self._count)
427be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
428be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @staticmethod
429be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def get_tokens(tu, extent):
430be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Helper method to return all tokens in an extent.
431be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
432be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        This functionality is needed multiple places in this module. We define
433be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        it here because it seems like a logical place.
434be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """
435be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        tokens_memory = POINTER(Token)()
436be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        tokens_count = c_uint()
437be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
438fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_tokenize(tu, extent, byref(tokens_memory),
439be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc                byref(tokens_count))
440be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
441be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        count = int(tokens_count.value)
442be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
443be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        # If we get no tokens, no memory was allocated. Be sure not to return
444be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        # anything and potentially call a destructor on nothing.
445be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        if count < 1:
446be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            return
447be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
448be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        tokens_array = cast(tokens_memory, POINTER(Token * count)).contents
449be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
450be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        token_group = TokenGroup(tu, tokens_memory, tokens_count)
451be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
452be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        for i in xrange(0, count):
453be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            token = Token()
454be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            token.int_data = tokens_array[i].int_data
455be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            token.ptr_data = tokens_array[i].ptr_data
456be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            token._tu = tu
457be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            token._group = token_group
458be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
459be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            yield token
460be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
461be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorcclass TokenKind(object):
462be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    """Describes a specific type of a Token."""
463be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
464be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    _value_map = {} # int -> TokenKind
465be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
466be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def __init__(self, value, name):
467be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Create a new TokenKind instance from a numeric value and a name."""
468be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        self.value = value
469be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        self.name = name
470be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
471be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def __repr__(self):
472be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        return 'TokenKind.%s' % (self.name,)
473be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
474be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @staticmethod
475be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def from_value(value):
476be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Obtain a registered TokenKind instance from its value."""
477be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        result = TokenKind._value_map.get(value, None)
478be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
479be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        if result is None:
480be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            raise ValueError('Unknown TokenKind: %d' % value)
481be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
482be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        return result
483be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
484be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @staticmethod
485be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def register(value, name):
486be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Register a new TokenKind enumeration.
487be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
488be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        This should only be called at module load time by code within this
489be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        package.
490be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """
491be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        if value in TokenKind._value_map:
492be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            raise ValueError('TokenKind already registered: %d' % value)
493be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
494be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        kind = TokenKind(value, name)
495be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        TokenKind._value_map[value] = kind
496be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        setattr(TokenKind, name, kind)
497be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
49812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar### Cursor Kinds ###
499176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass BaseEnumeration(object):
50012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    """
501176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    Common base class for named enumerations held in sync with Index.h values.
50212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
503176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    Subclasses must define their own _kinds and _name_map members, as:
50412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    _kinds = []
50512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    _name_map = None
506176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    These values hold the per-subclass instances and value-to-name mappings,
507176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    respectively.
508176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
509176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
51012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
51112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    def __init__(self, value):
512176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if value >= len(self.__class__._kinds):
513176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            self.__class__._kinds += [None] * (value - len(self.__class__._kinds) + 1)
514176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if self.__class__._kinds[value] is not None:
515176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            raise ValueError,'{0} value {1} already loaded'.format(
516176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                str(self.__class__), value)
51712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        self.value = value
518176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        self.__class__._kinds[value] = self
519176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        self.__class__._name_map = None
520176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
52112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
52212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    def from_param(self):
52312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        return self.value
52412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
52512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    @property
52612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    def name(self):
52712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        """Get the enumeration name of this cursor kind."""
52812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        if self._name_map is None:
52912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar            self._name_map = {}
530176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            for key, value in self.__class__.__dict__.items():
531176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                if isinstance(value, self.__class__):
53212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar                    self._name_map[value] = key
53312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        return self._name_map[self]
53412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
535176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    @classmethod
536176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def from_id(cls, id):
537176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if id >= len(cls._kinds) or cls._kinds[id] is None:
538176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            raise ValueError,'Unknown template argument kind %d' % id
539176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return cls._kinds[id]
540176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
541176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def __repr__(self):
542176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return '%s.%s' % (self.__class__, self.name,)
543176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
544176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
545176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass CursorKind(BaseEnumeration):
546176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
547176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    A CursorKind describes the kind of entity that a cursor points to.
548176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
549176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
550176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    # The required BaseEnumeration declarations.
551176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    _kinds = []
552176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    _name_map = None
55312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
554a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    @staticmethod
555a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    def get_all_kinds():
5564efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar        """Return all CursorKind enumeration instances."""
557a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar        return filter(None, CursorKind._kinds)
558a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
559a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    def is_declaration(self):
560a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar        """Test if this is a declaration kind."""
561fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isDeclaration(self)
562a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
563a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    def is_reference(self):
564a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar        """Test if this is a reference kind."""
565fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isReference(self)
566a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
567a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    def is_expression(self):
568a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar        """Test if this is an expression kind."""
569fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isExpression(self)
570a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
571a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    def is_statement(self):
572a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar        """Test if this is a statement kind."""
573fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isStatement(self)
574a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
5758be80e1e6effd5a333bc70e7f030dc9397d0554eDouglas Gregor    def is_attribute(self):
5768be80e1e6effd5a333bc70e7f030dc9397d0554eDouglas Gregor        """Test if this is an attribute kind."""
577fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isAttribute(self)
5788be80e1e6effd5a333bc70e7f030dc9397d0554eDouglas Gregor
579a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar    def is_invalid(self):
580a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar        """Test if this is an invalid kind."""
581fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isInvalid(self)
582a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
583eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser    def is_translation_unit(self):
584eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser        """Test if this is a translation unit kind."""
585fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isTranslationUnit(self)
586eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser
587eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser    def is_preprocessing(self):
588eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser        """Test if this is a preprocessing kind."""
589fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isPreprocessing(self)
590eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser
591eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser    def is_unexposed(self):
592eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser        """Test if this is an unexposed kind."""
593fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isUnexposed(self)
594eb13634e3914ce997f7e2ea5d3e585c79e9e9b4cTobias Grosser
59512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    def __repr__(self):
59612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        return 'CursorKind.%s' % (self.name,)
59712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
598a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar###
599a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar# Declaration Kinds
600a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
60112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A declaration whose specific kind is not exposed via this interface.
60212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#
60312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# Unexposed declarations have the same operations as any other kind of
60412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# declaration; one can extract their location information, spelling, find their
60512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# definitions, etc. However, the specific kind of the declaration is not
60612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# reported.
60712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.UNEXPOSED_DECL = CursorKind(1)
60812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
60912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A C or C++ struct.
61012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.STRUCT_DECL = CursorKind(2)
61112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
61212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A C or C++ union.
61312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.UNION_DECL = CursorKind(3)
61412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
61512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A C++ class.
61612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.CLASS_DECL = CursorKind(4)
61712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
61812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An enumeration.
61912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.ENUM_DECL = CursorKind(5)
62012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
62112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A field (in C) or non-static data member (in C++) in a struct, union, or C++
62212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# class.
62312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.FIELD_DECL = CursorKind(6)
62412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
62512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An enumerator constant.
62612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.ENUM_CONSTANT_DECL = CursorKind(7)
62712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
62812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A function.
62912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.FUNCTION_DECL = CursorKind(8)
63012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
63112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A variable.
63212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.VAR_DECL = CursorKind(9)
63312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
63412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A function or method parameter.
63512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.PARM_DECL = CursorKind(10)
63612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
63712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C @interface.
63812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_INTERFACE_DECL = CursorKind(11)
63912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
64012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C @interface for a category.
64112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_CATEGORY_DECL = CursorKind(12)
64212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
64312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C @protocol declaration.
64412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_PROTOCOL_DECL = CursorKind(13)
64512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
64612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C @property declaration.
64712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_PROPERTY_DECL = CursorKind(14)
64812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
64912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C instance variable.
65012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_IVAR_DECL = CursorKind(15)
65112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
65212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C instance method.
65312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_INSTANCE_METHOD_DECL = CursorKind(16)
65412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
65512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C class method.
65612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_CLASS_METHOD_DECL = CursorKind(17)
65712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
65812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C @implementation.
65912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_IMPLEMENTATION_DECL = CursorKind(18)
66012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
66112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An Objective-C @implementation for a category.
66212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_CATEGORY_IMPL_DECL = CursorKind(19)
66312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
664a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar# A typedef.
66512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.TYPEDEF_DECL = CursorKind(20)
66612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
6674ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ class method.
6684ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.CXX_METHOD = CursorKind(21)
6694ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6704ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ namespace.
6714ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.NAMESPACE = CursorKind(22)
6724ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6734ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A linkage specification, e.g. 'extern "C"'.
6744ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.LINKAGE_SPEC = CursorKind(23)
6754ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6764ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ constructor.
6774ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.CONSTRUCTOR = CursorKind(24)
6784ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6794ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ destructor.
6804ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.DESTRUCTOR = CursorKind(25)
6814ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6824ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ conversion function.
6834ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.CONVERSION_FUNCTION = CursorKind(26)
6844ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6854ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ template type parameter
6864ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.TEMPLATE_TYPE_PARAMETER = CursorKind(27)
6874ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6884ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ non-type template paramater.
6894ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.TEMPLATE_NON_TYPE_PARAMETER = CursorKind(28)
6904ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6914ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ template template parameter.
6926988666289cdbe432c226868438d3005ba1f0312Benjamin KramerCursorKind.TEMPLATE_TEMPLATE_PARAMETER = CursorKind(29)
6934ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6944ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ function template.
6954ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.FUNCTION_TEMPLATE = CursorKind(30)
6964ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
6974ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ class template.
6984ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.CLASS_TEMPLATE = CursorKind(31)
6994ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7004ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ class template partial specialization.
7014ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.CLASS_TEMPLATE_PARTIAL_SPECIALIZATION = CursorKind(32)
7024ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7034ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ namespace alias declaration.
7044ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.NAMESPACE_ALIAS = CursorKind(33)
7054ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7064ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ using directive
7074ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.USING_DIRECTIVE = CursorKind(34)
7084ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7094ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A C++ using declaration
7104ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.USING_DECLARATION = CursorKind(35)
7114ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
71242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A Type alias decl.
71342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.TYPE_ALIAS_DECL = CursorKind(36)
71442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
71542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A Objective-C synthesize decl
71642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_SYNTHESIZE_DECL = CursorKind(37)
71742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
71842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A Objective-C dynamic decl
71942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_DYNAMIC_DECL = CursorKind(38)
72042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
72142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A C++ access specifier decl.
72242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_ACCESS_SPEC_DECL = CursorKind(39)
72342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
72442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
725a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar###
726a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar# Reference Kinds
72712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
72812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_SUPER_CLASS_REF = CursorKind(40)
72912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_PROTOCOL_REF = CursorKind(41)
73012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_CLASS_REF = CursorKind(42)
73112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
73212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A reference to a type declaration.
73312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#
73412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A type reference occurs anywhere where a type is named but not
73512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# declared. For example, given:
73612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#   typedef unsigned size_type;
73712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#   size_type size;
73812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#
73912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# The typedef is a declaration of size_type (CXCursor_TypedefDecl),
74012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# while the type of the variable "size" is referenced. The cursor
74112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# referenced by the type of size is the typedef for size_type.
74212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.TYPE_REF = CursorKind(43)
7434ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.CXX_BASE_SPECIFIER = CursorKind(44)
7444ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7454ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A reference to a class template, function template, template
7464ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# template parameter, or class template partial specialization.
7474ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.TEMPLATE_REF = CursorKind(45)
7484ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7494ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A reference to a namespace or namepsace alias.
7504ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.NAMESPACE_REF = CursorKind(46)
7514ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7524ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A reference to a member of a struct, union, or class that occurs in
7534ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# some non-expression context, e.g., a designated initializer.
7544ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.MEMBER_REF = CursorKind(47)
7554ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
7564ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A reference to a labeled statement.
7574ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.LABEL_REF = CursorKind(48)
7584ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
759da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# A reference to a set of overloaded functions or function templates
7604ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# that has not yet been resolved to a specific function or function template.
7614ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.OVERLOADED_DECL_REF = CursorKind(49)
76212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
763c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines# A reference to a variable that occurs in some non-expression
764da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# context, e.g., a C++ lambda capture list.
765da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios KyrtzidisCursorKind.VARIABLE_REF = CursorKind(50)
766da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
767a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar###
768a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar# Invalid/Error Kinds
76912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
77012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.INVALID_FILE = CursorKind(70)
77112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.NO_DECL_FOUND = CursorKind(71)
77212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.NOT_IMPLEMENTED = CursorKind(72)
7734ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.INVALID_CODE = CursorKind(73)
77412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
775a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar###
776a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar# Expression Kinds
777a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
77812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An expression whose specific kind is not exposed via this interface.
77912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#
78012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# Unexposed expressions have the same operations as any other kind of
78112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# expression; one can extract their location information, spelling, children,
78212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# etc. However, the specific kind of the expression is not reported.
78312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.UNEXPOSED_EXPR = CursorKind(100)
78412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
78512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An expression that refers to some value declaration, such as a function,
78612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# varible, or enumerator.
78712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.DECL_REF_EXPR = CursorKind(101)
78812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
78912bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An expression that refers to a member of a struct, union, class, Objective-C
79012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# class, etc.
79112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.MEMBER_REF_EXPR = CursorKind(102)
79212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
79312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An expression that calls a function.
79412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.CALL_EXPR = CursorKind(103)
79512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
79612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# An expression that sends a message to an Objective-C object or class.
79712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.OBJC_MESSAGE_EXPR = CursorKind(104)
79812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
7994ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# An expression that represents a block literal.
8004ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.BLOCK_EXPR = CursorKind(105)
8014ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
80242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# An integer literal.
80342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.INTEGER_LITERAL = CursorKind(106)
80442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
80542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A floating point number literal.
80642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.FLOATING_LITERAL = CursorKind(107)
80742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
80842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# An imaginary number literal.
80942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.IMAGINARY_LITERAL = CursorKind(108)
81042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
81142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A string literal.
81242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.STRING_LITERAL = CursorKind(109)
81342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
81442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A character literal.
81542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CHARACTER_LITERAL = CursorKind(110)
81642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
81742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A parenthesized expression, e.g. "(1)".
81842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
81942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# This AST node is only formed if full location information is requested.
82042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.PAREN_EXPR = CursorKind(111)
82142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
82242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# This represents the unary-expression's (except sizeof and
82342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# alignof).
82442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.UNARY_OPERATOR = CursorKind(112)
82542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
82642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# [C99 6.5.2.1] Array Subscripting.
82742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.ARRAY_SUBSCRIPT_EXPR = CursorKind(113)
82842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
82942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A builtin binary operation expression such as "x + y" or
83042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# "x <= y".
83142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.BINARY_OPERATOR = CursorKind(114)
83242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
83342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Compound assignment such as "+=".
83442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.COMPOUND_ASSIGNMENT_OPERATOR = CursorKind(115)
83542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
83642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# The ?: ternary operator.
83739a03d1015c9413226e8af20d7c00b48e7463c00Douglas GregorCursorKind.CONDITIONAL_OPERATOR = CursorKind(116)
83842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
83942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# An explicit cast in C (C99 6.5.4) or a C-style cast in C++
84042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# (C++ [expr.cast]), which uses the syntax (Type)expr.
84142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
84242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# For example: (int)f.
84342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CSTYLE_CAST_EXPR = CursorKind(117)
84442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
84542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# [C99 6.5.2.5]
84642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.COMPOUND_LITERAL_EXPR = CursorKind(118)
84742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
84842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Describes an C or C++ initializer list.
84942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.INIT_LIST_EXPR = CursorKind(119)
85042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
85142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# The GNU address of label extension, representing &&label.
85242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.ADDR_LABEL_EXPR = CursorKind(120)
85342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
85442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# This is the GNU Statement Expression extension: ({int X=4; X;})
85542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.StmtExpr = CursorKind(121)
85642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
857ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer# Represents a C11 generic selection.
85842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.GENERIC_SELECTION_EXPR = CursorKind(122)
85942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
86042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Implements the GNU __null extension, which is a name for a null
86142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# pointer constant that has integral type (e.g., int or long) and is the same
86242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# size and alignment as a pointer.
86342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
86442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# The __null extension is typically only used by system headers, which define
86542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# NULL as __null in C++ rather than using 0 (which is an integer that may not
86642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# match the size of a pointer).
86742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.GNU_NULL_EXPR = CursorKind(123)
86842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
86942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s static_cast<> expression.
87042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_STATIC_CAST_EXPR = CursorKind(124)
87142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
87242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s dynamic_cast<> expression.
87342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_DYNAMIC_CAST_EXPR = CursorKind(125)
87442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
87542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s reinterpret_cast<> expression.
87642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_REINTERPRET_CAST_EXPR = CursorKind(126)
87742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
87842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s const_cast<> expression.
87942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_CONST_CAST_EXPR = CursorKind(127)
88042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
88142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Represents an explicit C++ type conversion that uses "functional"
88242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# notion (C++ [expr.type.conv]).
88342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
88442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Example:
88542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# \code
88642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#   x = int(0.5);
88742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# \endcode
88842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_FUNCTIONAL_CAST_EXPR = CursorKind(128)
88942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
89042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A C++ typeid expression (C++ [expr.typeid]).
89142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_TYPEID_EXPR = CursorKind(129)
89242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
89342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# [C++ 2.13.5] C++ Boolean Literal.
89442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_BOOL_LITERAL_EXPR = CursorKind(130)
89542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
89642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# [C++0x 2.14.7] C++ Pointer Literal.
89742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_NULL_PTR_LITERAL_EXPR = CursorKind(131)
89842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
89942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Represents the "this" expression in C++
90042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_THIS_EXPR = CursorKind(132)
90142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
90242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# [C++ 15] C++ Throw Expression.
90342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
90442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# This handles 'throw' and 'throw' assignment-expression. When
90542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# assignment-expression isn't present, Op will be null.
90642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_THROW_EXPR = CursorKind(133)
90742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
90842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A new expression for memory allocation and constructor calls, e.g:
90942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# "new CXXNewExpr(foo)".
91042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_NEW_EXPR = CursorKind(134)
91142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
91242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A delete expression for memory deallocation and destructor calls,
91342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# e.g. "delete[] pArray".
91442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_DELETE_EXPR = CursorKind(135)
91542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
91642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Represents a unary expression.
91742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_UNARY_EXPR = CursorKind(136)
91842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
91942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# ObjCStringLiteral, used for Objective-C string literals i.e. "foo".
92042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_STRING_LITERAL = CursorKind(137)
92142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
92242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# ObjCEncodeExpr, used for in Objective-C.
92342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_ENCODE_EXPR = CursorKind(138)
92442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
92542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# ObjCSelectorExpr used for in Objective-C.
92642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_SELECTOR_EXPR = CursorKind(139)
92742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
92842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's protocol expression.
92942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_PROTOCOL_EXPR = CursorKind(140)
93042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
93142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# An Objective-C "bridged" cast expression, which casts between
93242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C pointers and C pointers, transferring ownership in the process.
93342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
93442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# \code
93542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#   NSString *str = (__bridge_transfer NSString *)CFCreateString();
93642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# \endcode
93742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_BRIDGE_CAST_EXPR = CursorKind(141)
93842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
93942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Represents a C++0x pack expansion that produces a sequence of
94042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# expressions.
94142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor#
94242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A pack expansion expression contains a pattern (which itself is an
94342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# expression) followed by an ellipsis. For example:
94442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.PACK_EXPANSION_EXPR = CursorKind(142)
94542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
94642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Represents an expression that computes the length of a parameter
94742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# pack.
94842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.SIZE_OF_PACK_EXPR = CursorKind(143)
94942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
950da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# Represents a C++ lambda expression that produces a local function
951da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# object.
952c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines#
953da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#  \code
954da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#  void abssort(float *x, unsigned N) {
955da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#    std::sort(x, x + N,
956da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#              [](float a, float b) {
957da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#                return std::abs(a) < std::abs(b);
958da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#              });
959da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#  }
960da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis#  \endcode
961da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios KyrtzidisCursorKind.LAMBDA_EXPR = CursorKind(144)
962c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
963da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# Objective-c Boolean Literal.
964da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios KyrtzidisCursorKind.OBJ_BOOL_LITERAL_EXPR = CursorKind(145)
965da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
966da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# Represents the "self" expression in a ObjC method.
967da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios KyrtzidisCursorKind.OBJ_SELF_EXPR = CursorKind(146)
968da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
969da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
97012bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# A statement whose specific kind is not exposed via this interface.
97112bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#
97212bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# Unexposed statements have the same operations as any other kind of statement;
97312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# one can extract their location information, spelling, children, etc. However,
97412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# the specific kind of the statement is not reported.
97512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.UNEXPOSED_STMT = CursorKind(200)
97612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
9774ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# A labelled statement in a function.
9784ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.LABEL_STMT = CursorKind(201)
9794ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
98042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A compound statement
98142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.COMPOUND_STMT = CursorKind(202)
98242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
98342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A case statement.
98442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CASE_STMT = CursorKind(203)
98542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
98642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A default statement.
98742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.DEFAULT_STMT = CursorKind(204)
98842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
98942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# An if statement.
99042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.IF_STMT = CursorKind(205)
99142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
99242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A switch statement.
99342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.SWITCH_STMT = CursorKind(206)
99442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
99542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A while statement.
99642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.WHILE_STMT = CursorKind(207)
99742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
99842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A do statement.
99942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.DO_STMT = CursorKind(208)
100042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
100142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A for statement.
100242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.FOR_STMT = CursorKind(209)
100342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
100442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A goto statement.
100542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.GOTO_STMT = CursorKind(210)
100642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
100742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# An indirect goto statement.
100842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.INDIRECT_GOTO_STMT = CursorKind(211)
100942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
101042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A continue statement.
101142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CONTINUE_STMT = CursorKind(212)
101242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
101342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A break statement.
101442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.BREAK_STMT = CursorKind(213)
101542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
101642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A return statement.
101742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.RETURN_STMT = CursorKind(214)
101842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
101942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# A GNU-style inline assembler statement.
102042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.ASM_STMT = CursorKind(215)
102142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
102242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's overall @try-@catch-@finally statement.
102342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_AT_TRY_STMT = CursorKind(216)
102442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
102542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's @catch statement.
102642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_AT_CATCH_STMT = CursorKind(217)
102742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
102842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's @finally statement.
102942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_AT_FINALLY_STMT = CursorKind(218)
103042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
103142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's @throw statement.
103242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_AT_THROW_STMT = CursorKind(219)
103342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
103442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's @synchronized statement.
103542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_AT_SYNCHRONIZED_STMT = CursorKind(220)
103642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
103742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's autorealease pool statement.
103842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_AUTORELEASE_POOL_STMT = CursorKind(221)
103942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
104042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Objective-C's for collection statement.
104142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.OBJC_FOR_COLLECTION_STMT = CursorKind(222)
104242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
104342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s catch statement.
104442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_CATCH_STMT = CursorKind(223)
104542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
104642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s try statement.
104742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_TRY_STMT = CursorKind(224)
104842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
104942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# C++'s for (* : *) statement.
105042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.CXX_FOR_RANGE_STMT = CursorKind(225)
105142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
105242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Windows Structured Exception Handling's try statement.
105342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.SEH_TRY_STMT = CursorKind(226)
105442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
105542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Windows Structured Exception Handling's except statement.
105642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.SEH_EXCEPT_STMT = CursorKind(227)
105742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
105842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Windows Structured Exception Handling's finally statement.
105942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.SEH_FINALLY_STMT = CursorKind(228)
106042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
1061da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# A MS inline assembly statement extension.
1062da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios KyrtzidisCursorKind.MS_ASM_STMT = CursorKind(229)
1063da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
106442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# The null statement.
106542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.NULL_STMT = CursorKind(230)
106642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
106742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor# Adaptor class for mixing declarations with statements and expressions.
106842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas GregorCursorKind.DECL_STMT = CursorKind(231)
10694ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
1070a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar###
1071a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar# Other Kinds
1072a6a6499a904441fc9e82ba9dd4155b8bc33f38f9Daniel Dunbar
107312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# Cursor that represents the translation unit itself.
107412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar#
107512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# The translation unit cursor exists primarily to act as the root cursor for
107612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar# traversing the contents of a translation unit.
107712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel DunbarCursorKind.TRANSLATION_UNIT = CursorKind(300)
107812bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
10794ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser###
10804ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# Attributes
10814ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
10824ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# An attribute whoe specific kind is note exposed via this interface
10834ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.UNEXPOSED_ATTR = CursorKind(400)
10844ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
10854ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.IB_ACTION_ATTR = CursorKind(401)
10864ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.IB_OUTLET_ATTR = CursorKind(402)
10874ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.IB_OUTLET_COLLECTION_ATTR = CursorKind(403)
10884ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
1089bf3cc73db94f2fbeb57929887bd05d5a0e077f0cRafael EspindolaCursorKind.CXX_FINAL_ATTR = CursorKind(404)
1090bf3cc73db94f2fbeb57929887bd05d5a0e077f0cRafael EspindolaCursorKind.CXX_OVERRIDE_ATTR = CursorKind(405)
1091bf3cc73db94f2fbeb57929887bd05d5a0e077f0cRafael EspindolaCursorKind.ANNOTATE_ATTR = CursorKind(406)
1092bf3cc73db94f2fbeb57929887bd05d5a0e077f0cRafael EspindolaCursorKind.ASM_LABEL_ATTR = CursorKind(407)
1093513371129c834c143a50c3ca09bb581b7f0f6344Argyrios KyrtzidisCursorKind.PACKED_ATTR = CursorKind(408)
10946bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesCursorKind.PURE_ATTR = CursorKind(409)
10956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesCursorKind.CONST_ATTR = CursorKind(410)
10966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesCursorKind.NODUPLICATE_ATTR = CursorKind(411)
1097c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen HinesCursorKind.CUDACONSTANT_ATTR = CursorKind(412)
1098c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen HinesCursorKind.CUDADEVICE_ATTR = CursorKind(413)
1099c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen HinesCursorKind.CUDAGLOBAL_ATTR = CursorKind(414)
1100c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen HinesCursorKind.CUDAHOST_ATTR = CursorKind(415)
1101176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesCursorKind.CUDASHARED_ATTR = CursorKind(416)
1102bf3cc73db94f2fbeb57929887bd05d5a0e077f0cRafael Espindola
11034ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser###
11044ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser# Preprocessing
11054ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.PREPROCESSING_DIRECTIVE = CursorKind(500)
11064ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.MACRO_DEFINITION = CursorKind(501)
11074ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.MACRO_INSTANTIATION = CursorKind(502)
11084ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias GrosserCursorKind.INCLUSION_DIRECTIVE = CursorKind(503)
11094ed73ce03bbdc56692f3bc232cb64632dc9dbc0fTobias Grosser
1110da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis###
1111da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# Extra declaration
1112da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
1113da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis# A module import declaration.
1114da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios KyrtzidisCursorKind.MODULE_IMPORT_DECL = CursorKind(600)
1115da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis
1116176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1117176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines### Template Argument Kinds ###
1118176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass TemplateArgumentKind(BaseEnumeration):
1119176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
1120176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    A TemplateArgumentKind describes the kind of entity that a template argument
1121176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    represents.
1122176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
1123176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1124176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    # The required BaseEnumeration declarations.
1125176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    _kinds = []
1126176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    _name_map = None
1127176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1128176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesTemplateArgumentKind.NULL = TemplateArgumentKind(0)
1129176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesTemplateArgumentKind.TYPE = TemplateArgumentKind(1)
1130176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesTemplateArgumentKind.DECLARATION = TemplateArgumentKind(2)
1131176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesTemplateArgumentKind.NULLPTR = TemplateArgumentKind(3)
1132176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesTemplateArgumentKind.INTEGRAL = TemplateArgumentKind(4)
1133176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
113412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar### Cursors ###
113512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
113630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass Cursor(Structure):
113730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
113830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    The Cursor class represents a reference to an element within the AST. It
113930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    acts as a kind of iterator.
114030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
11412abfec3240e8f2dafc9b62a71c69a6380aa5509aDouglas Gregor    _fields_ = [("_kind_id", c_int), ("xdata", c_int), ("data", c_void_p * 3)]
114230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
114358ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser    @staticmethod
114458ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser    def from_location(tu, location):
1145a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # We store a reference to the TU in the instance so the TU won't get
1146a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # collected before the cursor.
1147fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        cursor = conf.lib.clang_getCursor(tu, location)
1148a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        cursor._tu = tu
1149a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1150a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        return cursor
115158ba8c9f182c94553c8871086bf68e336a14a527Tobias Grosser
115230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def __eq__(self, other):
1153fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_equalCursors(self, other)
115430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
115530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def __ne__(self, other):
11569d008fd572fa3411e93084d51f12ea12a998786cGregory Szorc        return not self.__eq__(other)
115730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
115830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def is_definition(self):
115930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
116030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Returns true if the declaration pointed at by the cursor is also a
116130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        definition of that entity.
116230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
1163fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isCursorDefinition(self)
116430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
1165e65b34deb1f8f7c80765f1c00476e7609bb9eadaGregory Szorc    def is_static_method(self):
1166e65b34deb1f8f7c80765f1c00476e7609bb9eadaGregory Szorc        """Returns True if the cursor refers to a C++ member function or member
1167e65b34deb1f8f7c80765f1c00476e7609bb9eadaGregory Szorc        function template that is declared 'static'.
1168e65b34deb1f8f7c80765f1c00476e7609bb9eadaGregory Szorc        """
1169fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_CXXMethod_isStatic(self)
1170e65b34deb1f8f7c80765f1c00476e7609bb9eadaGregory Szorc
117130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def get_definition(self):
117230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
117330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        If the cursor is a reference to a declaration or a declaration of
117430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        some entity, return a cursor that points to the definition of that
117530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        entity.
117630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
117730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        # TODO: Should probably check that this is either a reference or
117830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        # declaration prior to issuing the lookup.
1179fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCursorDefinition(self)
118030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
11813d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar    def get_usr(self):
11823d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        """Return the Unified Symbol Resultion (USR) for the entity referenced
11833d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        by the given cursor (or None).
11843d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar
11853d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        A Unified Symbol Resolution (USR) is a string that identifies a
11863d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        particular entity (function, class, variable, etc.) within a
11873d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        program. USRs can be compared across translation units to determine,
11883d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        e.g., when references in one translation refer to an entity defined in
11893d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar        another translation unit."""
1190fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCursorUSR(self)
11913d855f8d48b235eb2beb45216cced24efd3c08faDaniel Dunbar
119230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @property
119312bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    def kind(self):
119412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        """Return the kind of this cursor."""
119512bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        return CursorKind.from_id(self._kind_id)
119612bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar
119712bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar    @property
119830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def spelling(self):
119930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """Return the spelling of the entity pointed at by the cursor."""
120042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        if not hasattr(self, '_spelling'):
1201fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._spelling = conf.lib.clang_getCursorSpelling(self)
12029537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
120342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        return self._spelling
120430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
120530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @property
1206b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor    def displayname(self):
1207b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor        """
1208b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor        Return the display name for the entity referenced by this cursor.
1209b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor
1210176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        The display name contains extra information that helps identify the
1211176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        cursor, such as the parameters of a function or template or the
1212176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        arguments of a class template specialization.
1213b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor        """
121442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        if not hasattr(self, '_displayname'):
1215fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._displayname = conf.lib.clang_getCursorDisplayName(self)
12169537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
121742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        return self._displayname
1218b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor
1219b60a2bebb5f3048f6c53d4f3997ebd84493a2d98Douglas Gregor    @property
1220176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def mangled_name(self):
1221176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Return the mangled name for the entity referenced by this cursor."""
1222176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if not hasattr(self, '_mangled_name'):
1223176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            self._mangled_name = conf.lib.clang_Cursor_getMangling(self)
1224176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1225176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return self._mangled_name
1226176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1227176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    @property
122830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def location(self):
122930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
123030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Return the source location (the starting character) of the entity
123130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        pointed at by the cursor.
123230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
123342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        if not hasattr(self, '_loc'):
1234fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._loc = conf.lib.clang_getCursorLocation(self)
12359537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
123642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        return self._loc
123730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
123830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @property
123930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def extent(self):
124030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
124130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Return the source range (the range of text) occupied by the entity
124230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        pointed at by the cursor.
124330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
124442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        if not hasattr(self, '_extent'):
1245fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._extent = conf.lib.clang_getCursorExtent(self)
12469537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
124742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        return self._extent
124830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
1249d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    @property
1250176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def storage_class(self):
1251176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """
1252176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        Retrieves the storage class (if any) of the entity pointed at by the
1253176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        cursor.
1254176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """
1255176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if not hasattr(self, '_storage_class'):
1256176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            self._storage_class = conf.lib.clang_Cursor_getStorageClass(self)
1257176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1258176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return StorageClass.from_id(self._storage_class)
1259176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1260176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    @property
12616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    def access_specifier(self):
12626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        """
12636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        Retrieves the access specifier (if any) of the entity pointed at by the
12646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        cursor.
12656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        """
12666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        if not hasattr(self, '_access_specifier'):
12676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines            self._access_specifier = conf.lib.clang_getCXXAccessSpecifier(self)
12686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
12696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        return AccessSpecifier.from_id(self._access_specifier)
12706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
12716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    @property
1272d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def type(self):
1273d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
12742d10680fe173c21c33367a04bb0969f65a43434cTobias Grosser        Retrieve the Type (if any) of the entity pointed at by the cursor.
1275d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
127642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        if not hasattr(self, '_type'):
1277fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._type = conf.lib.clang_getCursorType(self)
12789537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
127942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor        return self._type
1280d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
128164e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser    @property
12822c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc    def canonical(self):
12832c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        """Return the canonical Cursor corresponding to this Cursor.
12842c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc
12852c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        The canonical cursor is the cursor which is representative for the
12862c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        underlying entity. For example, if you have multiple forward
12872c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        declarations for the same class, the canonical cursor for the forward
12882c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        declarations will be identical.
12892c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        """
12902c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        if not hasattr(self, '_canonical'):
1291fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._canonical = conf.lib.clang_getCanonicalCursor(self)
12922c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc
12932c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc        return self._canonical
12942c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc
12952c40835c21cd435f183da3d4754aff6beeaef9f6Gregory Szorc    @property
12961e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc    def result_type(self):
12971e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc        """Retrieve the Type of the result for this Cursor."""
12981e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc        if not hasattr(self, '_result_type'):
1299fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._result_type = conf.lib.clang_getResultType(self.type)
13001e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc
13011e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc        return self._result_type
13021e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc
13031e370ab68e5b69fc40a782ee5ce01ec2c6857879Gregory Szorc    @property
130428d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser    def underlying_typedef_type(self):
130528d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser        """Return the underlying type of a typedef declaration.
130628d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser
13072d10680fe173c21c33367a04bb0969f65a43434cTobias Grosser        Returns a Type for the typedef this cursor is a declaration for. If
130828d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser        the current cursor is not a typedef, this raises.
130928d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser        """
131028d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser        if not hasattr(self, '_underlying_type'):
131128d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser            assert self.kind.is_declaration()
1312fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._underlying_type = \
1313fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser              conf.lib.clang_getTypedefDeclUnderlyingType(self)
131428d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser
131528d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser        return self._underlying_type
131628d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser
131728d939ffd6877f8a2c6a5b6704df792319f3878eTobias Grosser    @property
1318eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser    def enum_type(self):
1319eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser        """Return the integer type of an enum declaration.
1320eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser
13212d10680fe173c21c33367a04bb0969f65a43434cTobias Grosser        Returns a Type corresponding to an integer. If the cursor is not for an
1322eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser        enum, this raises.
1323eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser        """
1324eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser        if not hasattr(self, '_enum_type'):
1325eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser            assert self.kind == CursorKind.ENUM_DECL
1326fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._enum_type = conf.lib.clang_getEnumDeclIntegerType(self)
1327eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser
1328eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser        return self._enum_type
1329eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser
1330eb9ff2ea9ed829809cb177e74238301cfc2750caTobias Grosser    @property
1331bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg    def enum_value(self):
1332bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg        """Return the value of an enum constant."""
1333bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg        if not hasattr(self, '_enum_value'):
1334bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            assert self.kind == CursorKind.ENUM_CONSTANT_DECL
1335bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            # Figure out the underlying type of the enum to know if it
1336bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            # is a signed or unsigned quantity.
1337bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            underlying_type = self.type
1338bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            if underlying_type.kind == TypeKind.ENUM:
1339bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                underlying_type = underlying_type.get_declaration().enum_type
1340bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            if underlying_type.kind in (TypeKind.CHAR_U,
1341bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.UCHAR,
1342bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.CHAR16,
1343bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.CHAR32,
1344bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.USHORT,
1345bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.UINT,
1346bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.ULONG,
1347bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.ULONGLONG,
1348bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg                                        TypeKind.UINT128):
1349fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                self._enum_value = \
1350fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                  conf.lib.clang_getEnumConstantDeclUnsignedValue(self)
1351bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg            else:
1352fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                self._enum_value = conf.lib.clang_getEnumConstantDeclValue(self)
1353bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg        return self._enum_value
1354bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg
1355bbc2e090996cdf51f0e7a4235f6e0ca65c95d514Anders Waldenborg    @property
13565cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc    def objc_type_encoding(self):
13575cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc        """Return the Objective-C type encoding as a str."""
13585cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc        if not hasattr(self, '_objc_type_encoding'):
1359fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._objc_type_encoding = \
1360fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser              conf.lib.clang_getDeclObjCTypeEncoding(self)
13615cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc
13625cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc        return self._objc_type_encoding
13635cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc
13645cc6787b1ce76fc3b6e5fc6c2729f0dbfaf6c749Gregory Szorc    @property
136564e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser    def hash(self):
136664e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser        """Returns a hash of the cursor as an int."""
136764e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser        if not hasattr(self, '_hash'):
1368fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._hash = conf.lib.clang_hashCursor(self)
136964e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser
137064e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser        return self._hash
137164e7bdc1d4c8c2f40f32e699014e85fbe1be57f7Tobias Grosser
1372667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek    @property
1373667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek    def semantic_parent(self):
1374667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek        """Return the semantic parent for this cursor."""
1375667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek        if not hasattr(self, '_semantic_parent'):
1376fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._semantic_parent = conf.lib.clang_getCursorSemanticParent(self)
1377fd04a6a88255ce3a90e5f73aef69c08bb5a35677Gregory Szorc
1378667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek        return self._semantic_parent
1379667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek
1380667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek    @property
1381667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek    def lexical_parent(self):
1382667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek        """Return the lexical parent for this cursor."""
1383667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek        if not hasattr(self, '_lexical_parent'):
1384fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            self._lexical_parent = conf.lib.clang_getCursorLexicalParent(self)
1385fd04a6a88255ce3a90e5f73aef69c08bb5a35677Gregory Szorc
1386667fd80de4c3b7b143ba98a3b73e9b9b200f6af0Manuel Klimek        return self._lexical_parent
1387fd04a6a88255ce3a90e5f73aef69c08bb5a35677Gregory Szorc
1388a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc    @property
1389a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc    def translation_unit(self):
1390a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        """Returns the TranslationUnit to which this Cursor belongs."""
1391a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # If this triggers an AttributeError, the instance was not properly
1392a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # created.
1393a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        return self._tu
1394a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1395d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis    @property
1396d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis    def referenced(self):
1397d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis        """
1398c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        For a cursor that is a reference, returns a cursor
1399d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis        representing the entity that it references.
1400d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis        """
1401d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis        if not hasattr(self, '_referenced'):
1402d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis            self._referenced = conf.lib.clang_getCursorReferenced(self)
1403d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis
1404d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis        return self._referenced
1405d829379ed95cdce29497118c6c6c39bd7f62f307Argyrios Kyrtzidis
1406c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis    @property
1407c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis    def brief_comment(self):
1408c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis        """Returns the brief comment text associated with that Cursor"""
1409c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis        return conf.lib.clang_Cursor_getBriefCommentText(self)
1410c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
1411c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis    @property
1412c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis    def raw_comment(self):
1413c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis        """Returns the raw comment text associated with that Cursor"""
1414c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis        return conf.lib.clang_Cursor_getRawCommentText(self)
1415c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis
1416b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc    def get_arguments(self):
1417b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc        """Return an iterator for accessing the arguments of this cursor."""
1418b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc        num_args = conf.lib.clang_Cursor_getNumArguments(self)
1419b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc        for i in range(0, num_args):
1420b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc            yield conf.lib.clang_Cursor_getArgument(self, i)
1421b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc
1422176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def get_num_template_arguments(self):
1423176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Returns the number of template args associated with this cursor."""
1424176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return conf.lib.clang_Cursor_getNumTemplateArguments(self)
1425176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1426176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def get_template_argument_kind(self, num):
1427176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Returns the TemplateArgumentKind for the indicated template
1428176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        argument."""
1429176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return conf.lib.clang_Cursor_getTemplateArgumentKind(self, num)
1430176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1431176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def get_template_argument_type(self, num):
1432176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Returns the CXType for the indicated template argument."""
1433176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return conf.lib.clang_Cursor_getTemplateArgumentType(self, num)
1434176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1435176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def get_template_argument_value(self, num):
1436176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Returns the value of the indicated arg as a signed 64b integer."""
1437176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return conf.lib.clang_Cursor_getTemplateArgumentValue(self, num)
1438176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1439176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def get_template_argument_unsigned_value(self, num):
1440176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Returns the value of the indicated arg as an unsigned 64b integer."""
1441176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return conf.lib.clang_Cursor_getTemplateArgumentUnsignedValue(self, num)
1442176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1443de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar    def get_children(self):
144412bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886Daniel Dunbar        """Return an iterator for accessing the children of this cursor."""
1445de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar
1446de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar        # FIXME: Expose iteration from CIndex, PR6125.
1447de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar        def visitor(child, parent, children):
1448fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar            # FIXME: Document this assertion in API.
1449fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar            # FIXME: There should just be an isNull method.
1450fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            assert child != conf.lib.clang_getNullCursor()
1451a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1452a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc            # Create reference to TU so it isn't GC'd before Cursor.
1453a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc            child._tu = self._tu
1454de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar            children.append(child)
1455de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar            return 1 # continue
1456de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar        children = []
1457fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_visitChildren(self, callbacks['cursor_visit'](visitor),
14589537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc            children)
1459de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar        return iter(children)
1460de3b8e525a876d6c25554aeb782c368afec00db1Daniel Dunbar
1461c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines    def walk_preorder(self):
1462c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        """Depth-first preorder walk over the cursor and its descendants.
1463c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
1464c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        Yields cursors.
1465c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        """
1466c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        yield self
1467c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines        for child in self.get_children():
1468c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines            for descendant in child.walk_preorder():
1469c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                yield descendant
1470c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
1471be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def get_tokens(self):
1472be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Obtain Token instances formulating that compose this Cursor.
1473be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
1474be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        This is a generator for Token instances. It returns all tokens which
1475be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        occupy the extent this cursor occupies.
1476be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """
1477be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        return TokenGroup.get_tokens(self._tu, self.extent)
1478be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
147933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar    def get_field_offsetof(self):
148033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        """Returns the offsetof the FIELD_DECL pointed by this Cursor."""
148133337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        return conf.lib.clang_Cursor_getOffsetOfField(self)
148233337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
148333337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar    def is_anonymous(self):
148433337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        """
148533337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        Check if the record is anonymous.
148633337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        """
148733337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        if self.kind == CursorKind.FIELD_DECL:
148833337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar            return self.type.get_declaration().is_anonymous()
148933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        return conf.lib.clang_Cursor_isAnonymous(self)
149033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
1491411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis    def is_bitfield(self):
1492411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1493411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        Check if the field is a bitfield.
1494411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1495411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        return conf.lib.clang_Cursor_isBitField(self)
1496411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
1497411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis    def get_bitfield_width(self):
1498411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1499411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        Retrieve the width of a bitfield.
1500411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1501411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        return conf.lib.clang_getFieldDeclBitWidth(self)
1502411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
1503fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar    @staticmethod
1504fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar    def from_result(res, fn, args):
1505fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar        assert isinstance(res, Cursor)
1506fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar        # FIXME: There should just be an isNull method.
1507fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if res == conf.lib.clang_getNullCursor():
1508fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar            return None
1509a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1510a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # Store a reference to the TU in the Python object so it won't get GC'd
1511a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # before the Cursor.
1512a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        tu = None
1513a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        for arg in args:
1514a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc            if isinstance(arg, TranslationUnit):
1515a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc                tu = arg
1516a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc                break
1517a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1518a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc            if hasattr(arg, 'translation_unit'):
1519a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc                tu = arg.translation_unit
1520a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc                break
1521a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1522a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        assert tu is not None
1523a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1524a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        res._tu = tu
1525fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar        return res
1526fb8ae1796e7209b6dcd9ab08bae7cac55e1cec39Daniel Dunbar
15279537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc    @staticmethod
15289537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc    def from_cursor_result(res, fn, args):
15299537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        assert isinstance(res, Cursor)
1530fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if res == conf.lib.clang_getNullCursor():
15319537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc            return None
15329537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
15339537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        res._tu = args[0]._tu
15349537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        return res
1535d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1536176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass StorageClass(object):
15376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    """
1538176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    Describes the storage class of a declaration
15396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    """
15406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
15416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    # The unique kind objects, index by id.
15426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    _kinds = []
15436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    _name_map = None
15446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
15456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    def __init__(self, value):
1546176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if value >= len(StorageClass._kinds):
1547176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            StorageClass._kinds += [None] * (value - len(StorageClass._kinds) + 1)
1548176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if StorageClass._kinds[value] is not None:
1549176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            raise ValueError,'StorageClass already loaded'
15506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        self.value = value
1551176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        StorageClass._kinds[value] = self
1552176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        StorageClass._name_map = None
15536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
15546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    def from_param(self):
15556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        return self.value
15566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
15576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    @property
15586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    def name(self):
1559176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        """Get the enumeration name of this storage class."""
15606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        if self._name_map is None:
15616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines            self._name_map = {}
1562176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            for key,value in StorageClass.__dict__.items():
1563176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                if isinstance(value,StorageClass):
15646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                    self._name_map[value] = key
15656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        return self._name_map[self]
15666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
15676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    @staticmethod
15686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    def from_id(id):
1569176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if id >= len(StorageClass._kinds) or not StorageClass._kinds[id]:
1570176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            raise ValueError,'Unknown storage class %d' % id
1571176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return StorageClass._kinds[id]
1572176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1573176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def __repr__(self):
1574176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return 'StorageClass.%s' % (self.name,)
1575176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1576176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.INVALID = StorageClass(0)
1577176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.NONE = StorageClass(1)
1578176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.EXTERN = StorageClass(2)
1579176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.STATIC = StorageClass(3)
1580176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.PRIVATEEXTERN = StorageClass(4)
1581176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.OPENCLWORKGROUPLOCAL = StorageClass(5)
1582176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.AUTO = StorageClass(6)
1583176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesStorageClass.REGISTER = StorageClass(7)
1584176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1585176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1586176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines### C++ access specifiers ###
1587176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1588176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass AccessSpecifier(BaseEnumeration):
1589176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
1590176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    Describes the access of a C++ class member
1591176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    """
1592176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1593176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    # The unique kind objects, index by id.
1594176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    _kinds = []
1595176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    _name_map = None
1596176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1597176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    def from_param(self):
1598176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        return self.value
15996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
16006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    def __repr__(self):
16016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        return 'AccessSpecifier.%s' % (self.name,)
16026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
16036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesAccessSpecifier.INVALID = AccessSpecifier(0)
16046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesAccessSpecifier.PUBLIC = AccessSpecifier(1)
16056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesAccessSpecifier.PROTECTED = AccessSpecifier(2)
16066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesAccessSpecifier.PRIVATE = AccessSpecifier(3)
16076bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesAccessSpecifier.NONE = AccessSpecifier(4)
16086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
1609d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis### Type Kinds ###
1610d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1611176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass TypeKind(BaseEnumeration):
1612d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    """
1613d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    Describes the kind of type.
1614d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    """
1615d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1616d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    # The unique kind objects, indexed by id.
1617d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    _kinds = []
1618d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    _name_map = None
1619d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
16206e67eed3276f16edac4ab4ef5a36d2b896e18288Gregory Szorc    @property
16216e67eed3276f16edac4ab4ef5a36d2b896e18288Gregory Szorc    def spelling(self):
16226e67eed3276f16edac4ab4ef5a36d2b896e18288Gregory Szorc        """Retrieve the spelling of this TypeKind."""
1623fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTypeKindSpelling(self.value)
16246e67eed3276f16edac4ab4ef5a36d2b896e18288Gregory Szorc
1625d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def __repr__(self):
1626d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        return 'TypeKind.%s' % (self.name,)
1627d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1628d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.INVALID = TypeKind(0)
1629d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.UNEXPOSED = TypeKind(1)
1630d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.VOID = TypeKind(2)
1631d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.BOOL = TypeKind(3)
1632d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.CHAR_U = TypeKind(4)
1633d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.UCHAR = TypeKind(5)
1634d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.CHAR16 = TypeKind(6)
1635d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.CHAR32 = TypeKind(7)
1636d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.USHORT = TypeKind(8)
1637d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.UINT = TypeKind(9)
1638d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.ULONG = TypeKind(10)
1639d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.ULONGLONG = TypeKind(11)
1640d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.UINT128 = TypeKind(12)
1641d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.CHAR_S = TypeKind(13)
1642d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.SCHAR = TypeKind(14)
1643d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.WCHAR = TypeKind(15)
1644d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.SHORT = TypeKind(16)
1645d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.INT = TypeKind(17)
1646d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.LONG = TypeKind(18)
1647d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.LONGLONG = TypeKind(19)
1648d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.INT128 = TypeKind(20)
1649d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.FLOAT = TypeKind(21)
1650d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.DOUBLE = TypeKind(22)
1651d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.LONGDOUBLE = TypeKind(23)
1652d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.NULLPTR = TypeKind(24)
1653d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.OVERLOAD = TypeKind(25)
1654d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.DEPENDENT = TypeKind(26)
1655d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.OBJCID = TypeKind(27)
1656d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.OBJCCLASS = TypeKind(28)
1657d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.OBJCSEL = TypeKind(29)
1658d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.COMPLEX = TypeKind(100)
1659d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.POINTER = TypeKind(101)
1660d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.BLOCKPOINTER = TypeKind(102)
1661d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.LVALUEREFERENCE = TypeKind(103)
1662d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.RVALUEREFERENCE = TypeKind(104)
1663d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.RECORD = TypeKind(105)
1664d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.ENUM = TypeKind(106)
1665d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.TYPEDEF = TypeKind(107)
1666d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.OBJCINTERFACE = TypeKind(108)
1667d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.OBJCOBJECTPOINTER = TypeKind(109)
1668d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.FUNCTIONNOPROTO = TypeKind(110)
1669d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios KyrtzidisTypeKind.FUNCTIONPROTO = TypeKind(111)
167038d2d5539e72ce3d92c4746b632f3a7c2e48b4a2Douglas GregorTypeKind.CONSTANTARRAY = TypeKind(112)
1671250d217586b0dafcb0be343a80da31c956258e2eTobias GrosserTypeKind.VECTOR = TypeKind(113)
16724c4f6fe2a6d6b3ffd0ce114cb8099366662b67f7Argyrios KyrtzidisTypeKind.INCOMPLETEARRAY = TypeKind(114)
16734c4f6fe2a6d6b3ffd0ce114cb8099366662b67f7Argyrios KyrtzidisTypeKind.VARIABLEARRAY = TypeKind(115)
16744c4f6fe2a6d6b3ffd0ce114cb8099366662b67f7Argyrios KyrtzidisTypeKind.DEPENDENTSIZEDARRAY = TypeKind(116)
1675367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios KyrtzidisTypeKind.MEMBERPOINTER = TypeKind(117)
1676d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1677176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass RefQualifierKind(BaseEnumeration):
1678659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    """Describes a specific ref-qualifier of a type."""
1679659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
1680659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    # The unique kind objects, indexed by id.
1681659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    _kinds = []
1682659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    _name_map = None
1683659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
1684659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    def from_param(self):
1685659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis        return self.value
1686659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
1687659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    def __repr__(self):
1688659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis        return 'RefQualifierKind.%s' % (self.name,)
1689659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
1690659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios KyrtzidisRefQualifierKind.NONE = RefQualifierKind(0)
1691659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios KyrtzidisRefQualifierKind.LVALUE = RefQualifierKind(1)
1692659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios KyrtzidisRefQualifierKind.RVALUE = RefQualifierKind(2)
1693659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
1694d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidisclass Type(Structure):
1695d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    """
1696d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    The type of an element in the abstract syntax tree.
1697d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    """
1698d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    _fields_ = [("_kind_id", c_int), ("data", c_void_p * 2)]
1699d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1700d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    @property
1701d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def kind(self):
1702d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """Return the kind of this type."""
1703d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        return TypeKind.from_id(self._kind_id)
1704d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1705826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc    def argument_types(self):
1706826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        """Retrieve a container for the non-variadic arguments for this type.
1707826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1708826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        The returned object is iterable and indexable. Each item in the
1709826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        container is a Type instance.
1710826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        """
1711826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        class ArgumentsIterator(collections.Sequence):
1712826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc            def __init__(self, parent):
1713826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                self.parent = parent
1714826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                self.length = None
1715826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1716826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc            def __len__(self):
1717826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                if self.length is None:
1718fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                    self.length = conf.lib.clang_getNumArgTypes(self.parent)
1719826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1720826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                return self.length
1721826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1722826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc            def __getitem__(self, key):
1723826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                # FIXME Support slice objects.
1724826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                if not isinstance(key, int):
1725826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                    raise TypeError("Must supply a non-negative int.")
1726826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1727826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                if key < 0:
1728826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                    raise IndexError("Only non-negative indexes are accepted.")
1729826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1730826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                if key >= len(self):
1731826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                    raise IndexError("Index greater than container length: "
1732826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                                     "%d > %d" % ( key, len(self) ))
1733826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1734fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                result = conf.lib.clang_getArgType(self.parent, key)
1735826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                if result.kind == TypeKind.INVALID:
1736826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                    raise IndexError("Argument could not be retrieved.")
1737826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1738826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc                return result
1739826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1740826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        assert self.kind == TypeKind.FUNCTIONPROTO
1741826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc        return ArgumentsIterator(self)
1742826fce53d64e0ca8fdcfdd11f4e9aab6c8be224fGregory Szorc
1743860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc    @property
1744860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc    def element_type(self):
1745860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc        """Retrieve the Type of elements within this Type.
1746860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc
1747860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc        If accessed on a type that is not an array, complex, or vector type, an
1748860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc        exception will be raised.
1749860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc        """
1750fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        result = conf.lib.clang_getElementType(self)
1751860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc        if result.kind == TypeKind.INVALID:
1752860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc            raise Exception('Element type not available on this type.')
1753860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc
1754860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc        return result
1755860576050b4d163a2f182cfdd67d8c5a48e32c08Gregory Szorc
1756bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc    @property
1757bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc    def element_count(self):
1758bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc        """Retrieve the number of elements in this type.
1759bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc
1760bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc        Returns an int.
1761bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc
1762bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc        If the Type is not an array or vector, this raises.
1763bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc        """
1764fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        result = conf.lib.clang_getNumElements(self)
1765bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc        if result < 0:
1766bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc            raise Exception('Type does not have elements.')
1767bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc
1768bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc        return result
1769bf8ca0049ea4faa7b089001e837e0ebbaec2ac6dGregory Szorc
1770a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc    @property
1771a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc    def translation_unit(self):
1772a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        """The TranslationUnit to which this Type is associated."""
1773a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # If this triggers an AttributeError, the instance was not properly
1774a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        # instantiated.
1775a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        return self._tu
1776a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1777d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    @staticmethod
1778d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def from_result(res, fn, args):
1779d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        assert isinstance(res, Type)
1780a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1781a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        tu = None
1782a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        for arg in args:
1783a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc            if hasattr(arg, 'translation_unit'):
1784a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc                tu = arg.translation_unit
1785a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc                break
1786a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1787a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        assert tu is not None
1788a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc        res._tu = tu
1789a63ef1f63f9c2ae847fac25534c9e1a214efabbcGregory Szorc
1790d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        return res
1791d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1792d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def get_canonical(self):
1793d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1794d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        Return the canonical type for a Type.
1795d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1796d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        Clang's type system explicitly models typedefs and all the
1797d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        ways a specific type can be represented.  The canonical type
1798d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        is the underlying type with all the "sugar" removed.  For
1799d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        example, if 'T' is a typedef for 'int', the canonical type for
1800d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        'T' would be 'int'.
1801d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1802fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCanonicalType(self)
1803d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1804d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def is_const_qualified(self):
18058261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        """Determine whether a Type has the "const" qualifier set.
18068261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc
18078261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        This does not look through typedefs that may have added "const"
1808d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        at a different level.
1809d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1810fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isConstQualifiedType(self)
1811d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1812d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def is_volatile_qualified(self):
18138261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        """Determine whether a Type has the "volatile" qualifier set.
18148261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc
18158261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        This does not look through typedefs that may have added "volatile"
18168261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        at a different level.
1817d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1818fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isVolatileQualifiedType(self)
1819d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1820d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def is_restrict_qualified(self):
18218261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        """Determine whether a Type has the "restrict" qualifier set.
18228261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc
18238261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        This does not look through typedefs that may have added "restrict" at
18248261345a32e58dfb5f4269ed92e1608a4ec3379aGregory Szorc        a different level.
1825d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1826fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isRestrictQualifiedType(self)
1827d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
182831cc38cb76317bfe50aadbc625d6ff67f727607aGregory Szorc    def is_function_variadic(self):
182931cc38cb76317bfe50aadbc625d6ff67f727607aGregory Szorc        """Determine whether this function Type is a variadic function type."""
183031cc38cb76317bfe50aadbc625d6ff67f727607aGregory Szorc        assert self.kind == TypeKind.FUNCTIONPROTO
183131cc38cb76317bfe50aadbc625d6ff67f727607aGregory Szorc
1832fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isFunctionTypeVariadic(self)
183331cc38cb76317bfe50aadbc625d6ff67f727607aGregory Szorc
183496ad633771182c54b5b62fa4be23f866ed0beb15Gregory Szorc    def is_pod(self):
183596ad633771182c54b5b62fa4be23f866ed0beb15Gregory Szorc        """Determine whether this Type represents plain old data (POD)."""
1836fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_isPODType(self)
183796ad633771182c54b5b62fa4be23f866ed0beb15Gregory Szorc
1838d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def get_pointee(self):
1839d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1840d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        For pointer types, returns the type of the pointee.
1841d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1842fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getPointeeType(self)
1843d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1844d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def get_declaration(self):
1845d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1846d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        Return the cursor for the declaration of the given type.
1847d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1848fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTypeDeclaration(self)
1849d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
1850d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis    def get_result(self):
1851d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1852d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        Retrieve the result type associated with a function type.
1853d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis        """
1854fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getResultType(self)
1855d7933e6f29b4c93df8263df21ff5e2e1dd0cecb8Argyrios Kyrtzidis
185613102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor    def get_array_element_type(self):
185713102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor        """
185813102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor        Retrieve the type of the elements of the array type.
185913102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor        """
1860fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getArrayElementType(self)
186113102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor
186213102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor    def get_array_size(self):
186313102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor        """
186413102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor        Retrieve the size of the constant array.
186513102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor        """
1866fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getArraySize(self)
186713102ffbb00f1397fa02950e0cbc82d17be21792Douglas Gregor
1868367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios Kyrtzidis    def get_class_type(self):
1869367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios Kyrtzidis        """
1870367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios Kyrtzidis        Retrieve the class type of the member pointer type.
1871367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios Kyrtzidis        """
1872367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios Kyrtzidis        return conf.lib.clang_Type_getClassType(self)
1873367e8fe3ef5bcf5e3c9855364560b89f7a1e9145Argyrios Kyrtzidis
1874411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis    def get_align(self):
1875411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1876411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        Retrieve the alignment of the record.
1877411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1878411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        return conf.lib.clang_Type_getAlignOf(self)
1879411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
1880411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis    def get_size(self):
1881411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1882411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        Retrieve the size of the record.
1883411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1884411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        return conf.lib.clang_Type_getSizeOf(self)
1885411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
1886411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis    def get_offset(self, fieldname):
1887411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1888411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        Retrieve the offset of a field in the record.
1889411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        """
1890411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis        return conf.lib.clang_Type_getOffsetOf(self, c_char_p(fieldname))
1891411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
1892659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis    def get_ref_qualifier(self):
1893659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis        """
1894659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis        Retrieve the ref-qualifier of the type.
1895659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis        """
1896659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis        return RefQualifierKind.from_id(
1897659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis                conf.lib.clang_Type_getCXXRefQualifier(self))
1898659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
189933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar    def get_fields(self):
190033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        """Return an iterator for accessing the fields of this type."""
190133337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
190233337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        def visitor(field, children):
190333337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar            assert field != conf.lib.clang_getNullCursor()
190433337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
190533337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar            # Create reference to TU so it isn't GC'd before Cursor.
190633337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar            field._tu = self._tu
190733337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar            fields.append(field)
190833337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar            return 1 # continue
190933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        fields = []
191033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        conf.lib.clang_Type_visitFields(self,
191133337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar                            callbacks['fields_visit'](visitor), fields)
191233337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar        return iter(fields)
191333337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
1914c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis    @property
1915c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis    def spelling(self):
1916c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis        """Retrieve the spelling of this Type."""
1917c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis        return conf.lib.clang_getTypeSpelling(self)
1918c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis
19197eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc    def __eq__(self, other):
19207eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc        if type(other) != type(self):
19217eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc            return False
19227eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc
1923fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_equalTypes(self, other)
19247eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc
19257eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc    def __ne__(self, other):
19267eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc        return not self.__eq__(other)
19277eb691a7b61ba895695bbbf92e944d98ef49390dGregory Szorc
192830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar## CIndex Objects ##
192930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
193030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# CIndex objects (derived from ClangObject) are essentially lightweight
193130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# wrappers attached to some underlying object, which is exposed via CIndex as
193230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar# a void*.
193330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
193430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass ClangObject(object):
193530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
193630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    A helper for Clang objects. This class helps act as an intermediary for
193730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    the ctypes library and the Clang CIndex library.
193830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
193930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def __init__(self, obj):
194030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        assert isinstance(obj, c_object_p) and obj
194130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        self.obj = self._as_parameter_ = obj
194230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
194330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def from_param(self):
194430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        return self._as_parameter_
194530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
19465b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar
19475b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbarclass _CXUnsavedFile(Structure):
19485b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar    """Helper for passing unsaved file arguments."""
19495b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar    _fields_ = [("name", c_char_p), ("contents", c_char_p), ('length', c_ulong)]
19505b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar
195169a8552f85c1b926320418cb98fe02988c79578fTobias Grosser# Functions calls through the python interface are rather slow. Fortunately,
195269a8552f85c1b926320418cb98fe02988c79578fTobias Grosser# for most symboles, we do not need to perform a function call. Their spelling
195369a8552f85c1b926320418cb98fe02988c79578fTobias Grosser# never changes and is consequently provided by this spelling cache.
195469a8552f85c1b926320418cb98fe02988c79578fTobias GrosserSpellingCache = {
195569a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 0: CompletionChunk.Kind("Optional"),
195669a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 1: CompletionChunk.Kind("TypedText"),
195769a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 2: CompletionChunk.Kind("Text"),
195869a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 3: CompletionChunk.Kind("Placeholder"),
195969a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 4: CompletionChunk.Kind("Informative"),
196069a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 5 : CompletionChunk.Kind("CurrentParameter"),
196169a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            6: '(',   # CompletionChunk.Kind("LeftParen"),
196269a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            7: ')',   # CompletionChunk.Kind("RightParen"),
1963651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines            8: '[',   # CompletionChunk.Kind("LeftBracket"),
196469a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            9: ']',   # CompletionChunk.Kind("RightBracket"),
196569a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            10: '{',  # CompletionChunk.Kind("LeftBrace"),
196669a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            11: '}',  # CompletionChunk.Kind("RightBrace"),
196769a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            12: '<',  # CompletionChunk.Kind("LeftAngle"),
196869a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            13: '>',  # CompletionChunk.Kind("RightAngle"),
196969a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            14: ', ', # CompletionChunk.Kind("Comma"),
197069a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 15: CompletionChunk.Kind("ResultType"),
197169a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            16: ':',  # CompletionChunk.Kind("Colon"),
197269a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            17: ';',  # CompletionChunk.Kind("SemiColon"),
197369a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            18: '=',  # CompletionChunk.Kind("Equal"),
197469a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            19: ' ',  # CompletionChunk.Kind("HorizontalSpace"),
197569a8552f85c1b926320418cb98fe02988c79578fTobias Grosser            # 20: CompletionChunk.Kind("VerticalSpace")
197669a8552f85c1b926320418cb98fe02988c79578fTobias Grosser}
197769a8552f85c1b926320418cb98fe02988c79578fTobias Grosser
1978a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosserclass CompletionChunk:
1979a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    class Kind:
1980a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        def __init__(self, name):
1981a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            self.name = name
1982a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
1983a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        def __str__(self):
1984a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            return self.name
1985a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
1986a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        def __repr__(self):
1987a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            return "<ChunkKind: %s>" % self
1988a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
19896d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __init__(self, completionString, key):
19906d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        self.cs = completionString
19916d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        self.key = key
1992eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser        self.__kindNumberCache = -1
19936d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
19946d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __repr__(self):
1995a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        return "{'" + self.spelling + "', " + str(self.kind) + "}"
19966d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
1997d9ee06b2faddf9382af9fa20d1c34b8d05126417Tobias Grosser    @CachedProperty
19986d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def spelling(self):
1999bba99ad6e28e0a91bbfb1137d52a5d7cb94c72d3Tobias Grosser        if self.__kindNumber in SpellingCache:
2000bba99ad6e28e0a91bbfb1137d52a5d7cb94c72d3Tobias Grosser                return SpellingCache[self.__kindNumber]
2001fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCompletionChunkText(self.cs, self.key).spelling
20026d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
2003eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser    # We do not use @CachedProperty here, as the manual implementation is
2004eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser    # apparently still significantly faster. Please profile carefully if you
2005eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser    # would like to add CachedProperty back.
2006eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser    @property
2007e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser    def __kindNumber(self):
2008eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser        if self.__kindNumberCache == -1:
2009eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser            self.__kindNumberCache = \
2010bba99ad6e28e0a91bbfb1137d52a5d7cb94c72d3Tobias Grosser                conf.lib.clang_getCompletionChunkKind(self.cs, self.key)
2011eca36d1ae23d0e4c46a3c2c2b91a19f4a2f8055dTobias Grosser        return self.__kindNumberCache
2012e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser
2013e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser    @CachedProperty
2014e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser    def kind(self):
2015e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser        return completionChunkKindMap[self.__kindNumber]
20166d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
2017d9ee06b2faddf9382af9fa20d1c34b8d05126417Tobias Grosser    @CachedProperty
20186d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def string(self):
2019fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        res = conf.lib.clang_getCompletionChunkCompletionString(self.cs,
2020fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                                                                self.key)
20216d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
20226d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        if (res):
20236d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser          return CompletionString(res)
20246d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        else:
20256d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser          None
20266d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
2027a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    def isKindOptional(self):
2028e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser      return self.__kindNumber == 0
2029a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2030a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    def isKindTypedText(self):
2031e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser      return self.__kindNumber == 1
2032a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2033a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    def isKindPlaceHolder(self):
2034e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser      return self.__kindNumber == 3
2035a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2036a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    def isKindInformative(self):
2037e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser      return self.__kindNumber == 4
2038a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2039a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    def isKindResultType(self):
2040e43d3861d969ad583e10ef7e46c5e08e866dfaa5Tobias Grosser      return self.__kindNumber == 15
2041a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2042a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias GrossercompletionChunkKindMap = {
2043a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            0: CompletionChunk.Kind("Optional"),
2044a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            1: CompletionChunk.Kind("TypedText"),
2045a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            2: CompletionChunk.Kind("Text"),
2046a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            3: CompletionChunk.Kind("Placeholder"),
2047a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            4: CompletionChunk.Kind("Informative"),
2048a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            5: CompletionChunk.Kind("CurrentParameter"),
2049a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            6: CompletionChunk.Kind("LeftParen"),
2050a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            7: CompletionChunk.Kind("RightParen"),
2051a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            8: CompletionChunk.Kind("LeftBracket"),
2052a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            9: CompletionChunk.Kind("RightBracket"),
2053a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            10: CompletionChunk.Kind("LeftBrace"),
2054a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            11: CompletionChunk.Kind("RightBrace"),
2055a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            12: CompletionChunk.Kind("LeftAngle"),
2056a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            13: CompletionChunk.Kind("RightAngle"),
2057a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            14: CompletionChunk.Kind("Comma"),
2058a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            15: CompletionChunk.Kind("ResultType"),
2059a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            16: CompletionChunk.Kind("Colon"),
2060a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            17: CompletionChunk.Kind("SemiColon"),
2061a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            18: CompletionChunk.Kind("Equal"),
2062a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            19: CompletionChunk.Kind("HorizontalSpace"),
2063a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            20: CompletionChunk.Kind("VerticalSpace")}
2064a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
20656d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosserclass CompletionString(ClangObject):
2066a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser    class Availability:
2067a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        def __init__(self, name):
2068a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            self.name = name
2069a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2070a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        def __str__(self):
2071a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            return self.name
2072a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2073a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        def __repr__(self):
2074a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            return "<Availability: %s>" % self
2075a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
20766d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __len__(self):
20776bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        return self.num_chunks
2078147785b852ed247ebfd568a92579f7bc1fe347c8Tobias Grosser
2079147785b852ed247ebfd568a92579f7bc1fe347c8Tobias Grosser    @CachedProperty
2080147785b852ed247ebfd568a92579f7bc1fe347c8Tobias Grosser    def num_chunks(self):
2081fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getNumCompletionChunks(self.obj)
20826d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
20836d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __getitem__(self, key):
2084147785b852ed247ebfd568a92579f7bc1fe347c8Tobias Grosser        if self.num_chunks <= key:
20856d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser            raise IndexError
2086a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        return CompletionChunk(self.obj, key)
20876d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
20886d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    @property
20896d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def priority(self):
2090fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCompletionPriority(self.obj)
20916d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
20926d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    @property
20936d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def availability(self):
2094fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        res = conf.lib.clang_getCompletionAvailability(self.obj)
2095a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        return availabilityKinds[res]
20966d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
2097c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko    @property
2098c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko    def briefComment(self):
2099c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko        if conf.function_exists("clang_getCompletionBriefComment"):
2100c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko            return conf.lib.clang_getCompletionBriefComment(self.obj)
2101c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko        return _CXString()
2102c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
21036d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __repr__(self):
2104a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser        return " | ".join([str(a) for a in self]) \
2105a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser               + " || Priority: " + str(self.priority) \
2106c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko               + " || Availability: " + str(self.availability) \
2107c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko               + " || Brief comment: " + str(self.briefComment.spelling)
2108a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser
2109a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias GrosseravailabilityKinds = {
2110a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            0: CompletionChunk.Kind("Available"),
2111a87dbcc04987ebf91adec3e00ac5e1548af6d865Tobias Grosser            1: CompletionChunk.Kind("Deprecated"),
2112724d0dcc4d3765591b4586e7d064b2cba92ba43eBenjamin Kramer            2: CompletionChunk.Kind("NotAvailable"),
2113724d0dcc4d3765591b4586e7d064b2cba92ba43eBenjamin Kramer            3: CompletionChunk.Kind("NotAccessible")}
21146d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21150a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosserclass CodeCompletionResult(Structure):
21166d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    _fields_ = [('cursorKind', c_int), ('completionString', c_object_p)]
21176d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21186d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __repr__(self):
21196d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        return str(CompletionString(self.completionString))
21206d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21216d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    @property
21226d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def kind(self):
21236d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        return CursorKind.from_id(self.cursorKind)
21246d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21256d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    @property
21266d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def string(self):
21276d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        return CompletionString(self.completionString)
21280a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21290a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosserclass CCRStructure(Structure):
21300a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    _fields_ = [('results', POINTER(CodeCompletionResult)),
21310a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                ('numResults', c_int)]
21320a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21336d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __len__(self):
21346d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        return self.numResults
21356d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21366d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser    def __getitem__(self, key):
21376d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        if len(self) <= key:
21386d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser            raise IndexError
21396d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21406d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        return self.results[key]
21416d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
21420a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosserclass CodeCompletionResults(ClangObject):
21430a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    def __init__(self, ptr):
21440a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        assert isinstance(ptr, POINTER(CCRStructure)) and ptr
21450a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        self.ptr = self._as_parameter_ = ptr
21460a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21470a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    def from_param(self):
21480a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        return self._as_parameter_
21490a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21500a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    def __del__(self):
2151fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_disposeCodeCompleteResults(self)
21520a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21530a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    @property
21540a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    def results(self):
21556d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser        return self.ptr.contents
21560a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21570a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    @property
21580a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser    def diagnostics(self):
21590a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        class DiagnosticsItr:
21600a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser            def __init__(self, ccr):
21610a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                self.ccr= ccr
21620a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21630a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser            def __len__(self):
2164fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                return int(\
2165fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                  conf.lib.clang_codeCompleteGetNumDiagnostics(self.ccr))
21660a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21670a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser            def __getitem__(self, key):
2168fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                return conf.lib.clang_codeCompleteGetDiagnostic(self.ccr, key)
21690a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21700a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        return DiagnosticsItr(self)
21710a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
21720a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
217330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass Index(ClangObject):
217430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
217530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    The Index type provides the primary interface to the Clang CIndex library,
217630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    primarily by providing an interface for reading and parsing translation
217730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    units.
217830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
217930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
218030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @staticmethod
21812791dfc0fcbff64dbdaccde433b75c7226528b8dDaniel Dunbar    def create(excludeDecls=False):
218230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
218330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Create a new Index.
218430c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        Parameters:
218530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        excludeDecls -- Exclude local declarations from translation units.
218630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        """
2187fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return Index(conf.lib.clang_createIndex(excludeDecls, 0))
218830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
218930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def __del__(self):
2190fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_disposeIndex(self)
219130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
219230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def read(self, path):
2193fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """Load a TranslationUnit from the given AST file."""
2194da6a6f087b70cdac18c37028f8cff707f10f91cfArgyrios Kyrtzidis        return TranslationUnit.from_ast_file(path, self)
219530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2196fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def parse(self, path, args=None, unsaved_files=None, options = 0):
2197fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """Load the translation unit from the given source code file by running
219830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        clang and generating the AST before loading. Additional command line
219930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar        parameters can be passed to clang via the args parameter.
22005b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar
22015b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar        In-memory contents for files can be provided by passing a list of pairs
22025b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar        to as unsaved_files, the first item should be the filenames to be mapped
22035b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar        and the second should be the contents to be substituted for the
22045b534f67946eeb2cb29076288bfee9707f055f82Daniel Dunbar        file. The contents may be passed as strings or file objects.
220530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2206fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        If an error was encountered during parsing, a TranslationUnitLoadError
2207fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        will be raised.
2208fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """
2209fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        return TranslationUnit.from_source(path, args, unsaved_files, options,
2210fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                                           self)
221130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
221230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass TranslationUnit(ClangObject):
2213fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    """Represents a source code translation unit.
2214fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2215fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    This is one of the main types in the API. Any time you wish to interact
2216fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    with Clang's representation of a source file, you typically start with a
2217fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    translation unit.
221830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
221930c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2220fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Default parsing mode.
2221fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    PARSE_NONE = 0
2222fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2223fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Instruct the parser to create a detailed processing record containing
2224fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # metadata not normally retained.
2225fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    PARSE_DETAILED_PROCESSING_RECORD = 1
2226fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2227fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Indicates that the translation unit is incomplete. This is typically used
2228fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # when parsing headers.
2229fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    PARSE_INCOMPLETE = 2
2230fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2231fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Instruct the parser to create a pre-compiled preamble for the translation
2232fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # unit. This caches the preamble (included files at top of source file).
2233fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # This is useful if the translation unit will be reparsed and you don't
2234fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # want to incur the overhead of reparsing the preamble.
2235fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    PARSE_PRECOMPILED_PREAMBLE = 4
2236fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2237fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Cache code completion information on parse. This adds time to parsing but
2238fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # speeds up code completion.
2239fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    PARSE_CACHE_COMPLETION_RESULTS = 8
2240fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2241fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Flags with values 16 and 32 are deprecated and intentionally omitted.
2242fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2243fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # Do not parse function bodies. This is useful if you only care about
2244fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    # searching for declarations/definitions.
2245fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    PARSE_SKIP_FUNCTION_BODIES = 64
2246fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2247c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko    # Used to indicate that brief documentation comments should be included
2248c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko    # into the set of code completions returned from this translation unit.
2249c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko    PARSE_INCLUDE_BRIEF_COMMENTS_IN_CODE_COMPLETION = 128
2250c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
2251fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    @classmethod
2252fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def from_source(cls, filename, args=None, unsaved_files=None, options=0,
2253fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                    index=None):
2254fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """Create a TranslationUnit by parsing source.
2255fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2256fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        This is capable of processing source code both from files on the
2257fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        filesystem as well as in-memory contents.
2258fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2259fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        Command-line arguments that would be passed to clang are specified as
2260fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        a list via args. These can be used to specify include paths, warnings,
2261fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        etc. e.g. ["-Wall", "-I/path/to/include"].
2262fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2263fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        In-memory file content can be provided via unsaved_files. This is an
2264fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        iterable of 2-tuples. The first element is the str filename. The
2265fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        second element defines the content. Content can be provided as str
2266fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        source code or as file objects (anything with a read() method). If
2267fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        a file object is being used, content will be read until EOF and the
2268fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        read cursor will not be reset to its original position.
2269fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2270fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        options is a bitwise or of TranslationUnit.PARSE_XXX flags which will
2271fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        control parsing behavior.
2272fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
22732283b4664b004aae034b08f305ad2bc1dff9868eGregory Szorc        index is an Index instance to utilize. If not provided, a new Index
22742283b4664b004aae034b08f305ad2bc1dff9868eGregory Szorc        will be created for this TranslationUnit.
22752283b4664b004aae034b08f305ad2bc1dff9868eGregory Szorc
2276fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        To parse source from the filesystem, the filename of the file to parse
2277fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        is specified by the filename argument. Or, filename could be None and
2278fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        the args list would contain the filename(s) to parse.
2279fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2280fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        To parse source from an in-memory buffer, set filename to the virtual
2281fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        filename you wish to associate with this source (e.g. "test.c"). The
2282fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        contents of that file are then provided in unsaved_files.
2283fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2284fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        If an error occurs, a TranslationUnitLoadError is raised.
2285fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2286fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        Please note that a TranslationUnit with parser errors may be returned.
2287fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        It is the caller's responsibility to check tu.diagnostics for errors.
2288fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2289fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        Also note that Clang infers the source language from the extension of
2290fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        the input filename. If you pass in source code containing a C++ class
2291fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        declaration with the filename "test.c" parsing will fail.
2292fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """
2293fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if args is None:
2294fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            args = []
2295fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2296fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if unsaved_files is None:
2297fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            unsaved_files = []
2298fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2299fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if index is None:
2300fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            index = Index.create()
2301fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2302fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        args_array = None
2303fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if len(args) > 0:
2304fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            args_array = (c_char_p * len(args))(* args)
2305fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2306fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        unsaved_array = None
2307fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if len(unsaved_files) > 0:
2308fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            unsaved_array = (_CXUnsavedFile * len(unsaved_files))()
2309fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            for i, (name, contents) in enumerate(unsaved_files):
2310fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                if hasattr(contents, "read"):
2311fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                    contents = contents.read()
2312fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2313fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                unsaved_array[i].name = name
2314fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                unsaved_array[i].contents = contents
2315fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                unsaved_array[i].length = len(contents)
2316fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2317fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        ptr = conf.lib.clang_parseTranslationUnit(index, filename, args_array,
23189537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                                    len(args), unsaved_array,
23199537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                                    len(unsaved_files), options)
2320fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
232111d6cd318df1459ed57b26912d5c7a5cf2c2f091Tobias Grosser        if not ptr:
2322fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            raise TranslationUnitLoadError("Error parsing translation unit.")
2323fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2324fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        return cls(ptr, index=index)
2325fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2326fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    @classmethod
2327fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def from_ast_file(cls, filename, index=None):
2328fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """Create a TranslationUnit instance from a saved AST file.
2329fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2330fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        A previously-saved AST file (provided with -emit-ast or
2331fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        TranslationUnit.save()) is loaded from the filename specified.
2332fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2333fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        If the file cannot be loaded, a TranslationUnitLoadError will be
2334fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        raised.
2335fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2336fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        index is optional and is the Index instance to use. If not provided,
2337fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        a default Index will be created.
2338fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """
2339fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if index is None:
2340fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            index = Index.create()
2341fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2342fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        ptr = conf.lib.clang_createTranslationUnit(index, filename)
234311d6cd318df1459ed57b26912d5c7a5cf2c2f091Tobias Grosser        if not ptr:
2344fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            raise TranslationUnitLoadError(filename)
2345fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2346fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        return cls(ptr=ptr, index=index)
2347fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2348fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def __init__(self, ptr, index):
2349fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """Create a TranslationUnit instance.
2350fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2351fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        TranslationUnits should be created using one of the from_* @classmethod
2352fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        functions above. __init__ is only called internally.
2353fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """
2354fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        assert isinstance(index, Index)
2355fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2356532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar        ClangObject.__init__(self, ptr)
2357532fc63b51cd0eb795df36d3fe306645b8b980e4Daniel Dunbar
235830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def __del__(self):
2359fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_disposeTranslationUnit(self)
236030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
23611b945a7455e17fd792ef3bd3790dc88beea5faadDaniel Dunbar    @property
23621b945a7455e17fd792ef3bd3790dc88beea5faadDaniel Dunbar    def cursor(self):
23631b945a7455e17fd792ef3bd3790dc88beea5faadDaniel Dunbar        """Retrieve the cursor that represents the given translation unit."""
2364fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTranslationUnitCursor(self)
236530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
236630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @property
236730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def spelling(self):
23681b945a7455e17fd792ef3bd3790dc88beea5faadDaniel Dunbar        """Get the original translation unit source file name."""
2369fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTranslationUnitSpelling(self)
237030c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2371ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    def get_includes(self):
2372ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        """
2373ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        Return an iterable sequence of FileInclusion objects that describe the
2374ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        sequence of inclusions in a translation unit. The first object in
2375ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        this sequence is always the input file. Note that this method will not
2376ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        recursively iterate over header files included through precompiled
2377ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        headers.
2378ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        """
2379ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        def visitor(fobj, lptr, depth, includes):
23808be80e1e6effd5a333bc70e7f030dc9397d0554eDouglas Gregor            if depth > 0:
23818be80e1e6effd5a333bc70e7f030dc9397d0554eDouglas Gregor                loc = lptr.contents
23828be80e1e6effd5a333bc70e7f030dc9397d0554eDouglas Gregor                includes.append(FileInclusion(loc.file, File(fobj), loc, depth))
2383ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar
2384ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        # Automatically adapt CIndex/ctype pointers to python objects
2385ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        includes = []
2386fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_getInclusions(self,
23879537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                callbacks['translation_unit_includes'](visitor), includes)
23889537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2389ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        return iter(includes)
2390ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar
23910f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc    def get_file(self, filename):
23920f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        """Obtain a File from this translation unit."""
23930f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
23940f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        return File.from_name(self, filename)
23950f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
23960f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc    def get_location(self, filename, position):
23970f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        """Obtain a SourceLocation for a file in this translation unit.
23980f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
23990f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        The position can be specified by passing:
24000f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24010f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc          - Integer file offset. Initial file offset is 0.
24020f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc          - 2-tuple of (line number, column number). Initial file position is
24030f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            (0, 0)
24040f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        """
24050f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        f = self.get_file(filename)
24060f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24070f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        if isinstance(position, int):
24080f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            return SourceLocation.from_offset(self, f, position)
24090f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24100f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        return SourceLocation.from_position(self, f, position[0], position[1])
24110f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24120f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc    def get_extent(self, filename, locations):
24130f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        """Obtain a SourceRange from this translation unit.
24140f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24150f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        The bounds of the SourceRange must ultimately be defined by a start and
24160f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        end SourceLocation. For the locations argument, you can pass:
24170f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24180f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc          - 2 SourceLocation instances in a 2-tuple or list.
24190f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc          - 2 int file offsets via a 2-tuple or list.
24200f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc          - 2 2-tuple or lists of (line, column) pairs in a 2-tuple or list.
24210f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24220f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        e.g.
24230f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24240f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        get_extent('foo.c', (5, 10))
24250f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        get_extent('foo.c', ((1, 1), (1, 15)))
24260f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        """
24270f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        f = self.get_file(filename)
24280f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24290f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        if len(locations) < 2:
24300f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            raise Exception('Must pass object with at least 2 elements')
24310f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24320f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        start_location, end_location = locations
24330f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24340f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        if hasattr(start_location, '__len__'):
24350f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            start_location = SourceLocation.from_position(self, f,
24360f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc                start_location[0], start_location[1])
24370f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        elif isinstance(start_location, int):
24380f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            start_location = SourceLocation.from_offset(self, f,
24390f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc                start_location)
24400f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24410f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        if hasattr(end_location, '__len__'):
24420f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            end_location = SourceLocation.from_position(self, f,
24430f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc                end_location[0], end_location[1])
24440f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        elif isinstance(end_location, int):
24450f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc            end_location = SourceLocation.from_offset(self, f, end_location)
24460f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24470f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        assert isinstance(start_location, SourceLocation)
24480f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        assert isinstance(end_location, SourceLocation)
24490f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24500f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc        return SourceRange.from_locations(start_location, end_location)
24510f1964a5c1627bcc3fd658cdd1f139e30b0ad612Gregory Szorc
24523b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    @property
24533b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer    def diagnostics(self):
24543b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer        """
24553b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer        Return an iterable (and indexable) object containing the diagnostics.
24563b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer        """
24571d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer        class DiagIterator:
24583b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __init__(self, tu):
24593b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer                self.tu = tu
24603b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
24613b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __len__(self):
2462fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                return int(conf.lib.clang_getNumDiagnostics(self.tu))
24633b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
24643b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer            def __getitem__(self, key):
2465fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                diag = conf.lib.clang_getDiagnostic(self.tu, key)
24661d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer                if not diag:
24671d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer                    raise IndexError
24681d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer                return Diagnostic(diag)
24693b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
24701d02ccd1aa9bab97d0c0869d54df05a4e5f57b1bBenjamin Kramer        return DiagIterator(self)
24713b0cf09f9c84e75881b261eb4a7a69d99aa0335aBenjamin Kramer
2472fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def reparse(self, unsaved_files=None, options=0):
2473265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        """
2474265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        Reparse an already parsed translation unit.
2475265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser
2476265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        In-memory contents for files can be provided by passing a list of pairs
2477265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        as unsaved_files, the first items should be the filenames to be mapped
2478265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        and the second should be the contents to be substituted for the
2479265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        file. The contents may be passed as strings or file objects.
2480265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        """
2481fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if unsaved_files is None:
2482fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            unsaved_files = []
2483fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2484265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        unsaved_files_array = 0
2485265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser        if len(unsaved_files):
2486265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser            unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
2487265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser            for i,(name,value) in enumerate(unsaved_files):
2488265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                if not isinstance(value, str):
2489265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                    # FIXME: It would be great to support an efficient version
2490265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                    # of this, one day.
2491265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                    value = value.read()
2492265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                    print value
2493265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                if not isinstance(value, str):
2494265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                    raise TypeError,'Unexpected unsaved file contents.'
2495265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                unsaved_files_array[i].name = name
2496265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                unsaved_files_array[i].contents = value
2497265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser                unsaved_files_array[i].length = len(value)
2498fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        ptr = conf.lib.clang_reparseTranslationUnit(self, len(unsaved_files),
24999537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                unsaved_files_array, options)
2500fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2501fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    def save(self, filename):
2502fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """Saves the TranslationUnit to a file.
2503fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2504fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        This is equivalent to passing -emit-ast to the clang frontend. The
2505fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        saved file can be loaded back into a TranslationUnit. Or, if it
2506fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        corresponds to a header, it can be used as a pre-compiled header file.
2507fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2508fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        If an error occurs while saving, a TranslationUnitSaveError is raised.
2509fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        If the error was TranslationUnitSaveError.ERROR_INVALID_TU, this means
2510fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        the constructed TranslationUnit was not valid at time of save. In this
2511fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        case, the reason(s) why should be available via
2512fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        TranslationUnit.diagnostics().
2513fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2514fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        filename -- The path to save the translation unit to.
2515fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        """
2516fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        options = conf.lib.clang_defaultSaveOptions(self)
2517fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        result = int(conf.lib.clang_saveTranslationUnit(self, filename,
2518fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                                                        options))
2519fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if result != 0:
2520fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            raise TranslationUnitSaveError(result,
2521fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc                'Error saving TranslationUnit.')
2522fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
2523c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko    def codeComplete(self, path, line, column, unsaved_files=None,
2524c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko                     include_macros=False, include_code_patterns=False,
2525c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko                     include_brief_comments=False):
25260a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        """
25270a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        Code complete in this translation unit.
25280a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser
25290a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        In-memory contents for files can be provided by passing a list of pairs
25300a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        as unsaved_files, the first items should be the filenames to be mapped
25310a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        and the second should be the contents to be substituted for the
25320a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        file. The contents may be passed as strings or file objects.
25330a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        """
2534c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko        options = 0
2535c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
2536c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko        if include_macros:
2537c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko            options += 1
2538c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
2539c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko        if include_code_patterns:
2540c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko            options += 2
2541c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
2542c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko        if include_brief_comments:
2543c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko            options += 4
2544c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
2545fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc        if unsaved_files is None:
2546fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc            unsaved_files = []
2547fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc
25480a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        unsaved_files_array = 0
25490a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser        if len(unsaved_files):
25500a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser            unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
25510a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser            for i,(name,value) in enumerate(unsaved_files):
25520a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                if not isinstance(value, str):
25530a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                    # FIXME: It would be great to support an efficient version
25540a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                    # of this, one day.
25550a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                    value = value.read()
25560a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                    print value
25570a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                if not isinstance(value, str):
25580a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                    raise TypeError,'Unexpected unsaved file contents.'
25590a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                unsaved_files_array[i].name = name
25600a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                unsaved_files_array[i].contents = value
25610a16680067df298affe5da21dc7ea10c235f6e8dTobias Grosser                unsaved_files_array[i].length = len(value)
2562fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        ptr = conf.lib.clang_codeCompleteAt(self, path, line, column,
25639537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                unsaved_files_array, len(unsaved_files), options)
2564ba5d10b82b3cc00b4d71b273a18c051a1f38f22fTobias Grosser        if ptr:
2565ba5d10b82b3cc00b4d71b273a18c051a1f38f22fTobias Grosser            return CodeCompletionResults(ptr)
2566ba5d10b82b3cc00b4d71b273a18c051a1f38f22fTobias Grosser        return None
2567265e6b2d17ae348ce73961866979f574c65b56f4Tobias Grosser
2568be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def get_tokens(self, locations=None, extent=None):
2569be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Obtain tokens in this translation unit.
2570be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2571be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        This is a generator for Token instances. The caller specifies a range
2572be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        of source code to obtain tokens for. The range can be specified as a
2573be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        2-tuple of SourceLocation or as a SourceRange. If both are defined,
2574be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        behavior is undefined.
2575be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """
2576be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        if locations is not None:
2577be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc            extent = SourceRange(start=locations[0], end=locations[1])
2578be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2579be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        return TokenGroup.get_tokens(self, extent)
2580be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
258130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbarclass File(ClangObject):
258230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
25837b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar    The File class represents a particular source file that is part of a
25847b48b3519a792c010da104f0c4e554b47bf774daDaniel Dunbar    translation unit.
258530c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    """
258630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2587a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser    @staticmethod
2588a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser    def from_name(translation_unit, file_name):
2589a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser        """Retrieve a file handle within the given translation unit."""
2590fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return File(conf.lib.clang_getFile(translation_unit, file_name))
2591a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser
259230c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @property
259330c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def name(self):
25944efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar        """Return the complete file and path name of the file."""
2595fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getCString(conf.lib.clang_getFileName(self))
259630c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
259730c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    @property
259830c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar    def time(self):
25994efd632322731425d83d205f26bddcdfe1ac8937Daniel Dunbar        """Return the last modification time of the file."""
2600fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getFileTime(self)
260130c0f2637c4ba5d8764ff6e1ee6cbc89b89c63dbDaniel Dunbar
2602a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser    def __str__(self):
2603a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser        return self.name
2604a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser
2605a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser    def __repr__(self):
2606a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser        return "<File: %s>" % (self.name)
2607a9ea5df14abb807eb0173e2737c5a1d61e86975bTobias Grosser
26089537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc    @staticmethod
26099537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc    def from_cursor_result(res, fn, args):
26109537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        assert isinstance(res, File)
26119537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
26129537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        # Copy a reference to the TranslationUnit to prevent premature GC.
26139537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        res._tu = args[0]._tu
26149537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        return res
26159537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2616ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbarclass FileInclusion(object):
2617ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    """
2618ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    The FileInclusion class represents the inclusion of one source file by
2619ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    another via a '#include' directive or as the input file for the translation
2620ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    unit. This class provides information about the included file, the including
2621ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    file, the location of the '#include' directive and the depth of the included
2622ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    file in the stack. Note that the input file has depth 0.
2623ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    """
2624ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar
2625ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    def __init__(self, src, tgt, loc, depth):
2626ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        self.source = src
2627ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        self.include = tgt
2628ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        self.location = loc
2629ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        self.depth = depth
2630ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar
2631ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    @property
2632ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar    def is_input_file(self):
2633ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        """True if the included file is the input file."""
2634ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar        return self.depth == 0
2635ef7f798c0921cde7e665935a5630578cc1065e0fDaniel Dunbar
2636910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaisonclass CompilationDatabaseError(Exception):
2637910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """Represents an error that occurred when working with a CompilationDatabase
2638910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2639910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    Each error is associated to an enumerated value, accessible under
2640910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    e.cdb_error. Consumers can compare the value with one of the ERROR_
2641910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    constants in this class.
2642910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """
2643910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2644651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    # An unknown error occurred
2645910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    ERROR_UNKNOWN = 0
2646910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2647910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    # The database could not be loaded
2648910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    ERROR_CANNOTLOADDATABASE = 1
2649910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2650910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __init__(self, enumeration, message):
2651910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        assert isinstance(enumeration, int)
2652910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2653910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        if enumeration > 1:
2654910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison            raise Exception("Encountered undefined CompilationDatabase error "
2655910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison                            "constant: %d. Please file a bug to have this "
2656910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison                            "value supported." % enumeration)
2657910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2658910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        self.cdb_error = enumeration
2659910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        Exception.__init__(self, 'Error %d: %s' % (enumeration, message))
2660910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2661910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaisonclass CompileCommand(object):
2662910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """Represents the compile command used to build a file"""
2663910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __init__(self, cmd, ccmds):
2664910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        self.cmd = cmd
2665910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        # Keep a reference to the originating CompileCommands
2666910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        # to prevent garbage collection
2667910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        self.ccmds = ccmds
2668910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2669910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    @property
2670910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def directory(self):
2671910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        """Get the working directory for this CompileCommand"""
2672fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_CompileCommand_getDirectory(self.cmd)
2673910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2674910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    @property
2675910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def arguments(self):
2676910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        """
2677910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        Get an iterable object providing each argument in the
2678910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        command line for the compiler invocation as a _CXString.
2679910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2680577c530fe29b6fc8f65ef0ff5b9f194a51a68d82Arnaud A. de Grandmaison        Invariant : the first argument is the compiler executable
2681910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        """
2682fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        length = conf.lib.clang_CompileCommand_getNumArgs(self.cmd)
2683910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        for i in xrange(length):
2684fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            yield conf.lib.clang_CompileCommand_getArg(self.cmd, i)
2685910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2686910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaisonclass CompileCommands(object):
2687910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """
2688910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    CompileCommands is an iterable object containing all CompileCommand
2689910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    that can be used for building a specific file.
2690910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """
2691910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __init__(self, ccmds):
2692910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        self.ccmds = ccmds
2693910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2694910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __del__(self):
2695fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_CompileCommands_dispose(self.ccmds)
2696910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2697910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __len__(self):
2698fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return int(conf.lib.clang_CompileCommands_getSize(self.ccmds))
2699910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2700910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __getitem__(self, i):
2701fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        cc = conf.lib.clang_CompileCommands_getCommand(self.ccmds, i)
2702b1614041ac297f2e1fca359e9b77291ae5006832Arnaud A. de Grandmaison        if not cc:
2703910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison            raise IndexError
2704910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        return CompileCommand(cc, self)
2705910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2706910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    @staticmethod
2707910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def from_result(res, fn, args):
2708910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        if not res:
2709910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison            return None
2710910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        return CompileCommands(res)
2711910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2712910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaisonclass CompilationDatabase(ClangObject):
2713910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """
2714910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    The CompilationDatabase is a wrapper class around
2715910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    clang::tooling::CompilationDatabase
2716910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2717910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    It enables querying how a specific source file can be built.
2718910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    """
2719910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2720910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def __del__(self):
2721fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_CompilationDatabase_dispose(self)
2722910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2723910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    @staticmethod
2724910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def from_result(res, fn, args):
2725910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        if not res:
2726910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison            raise CompilationDatabaseError(0,
2727910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison                                           "CompilationDatabase loading failed")
2728910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        return CompilationDatabase(res)
2729910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2730910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    @staticmethod
2731910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def fromDirectory(buildDir):
2732910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        """Builds a CompilationDatabase from the database found in buildDir"""
2733910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        errorCode = c_uint()
2734910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        try:
2735fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            cdb = conf.lib.clang_CompilationDatabase_fromDirectory(buildDir,
27369537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                byref(errorCode))
2737910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        except CompilationDatabaseError as e:
27389537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc            raise CompilationDatabaseError(int(errorCode.value),
27399537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc                                           "CompilationDatabase loading failed")
2740910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        return cdb
2741910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
2742910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    def getCompileCommands(self, filename):
2743910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        """
2744910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        Get an iterable object providing all the CompileCommands available to
27454439478c38222bb56d42a9afe4c6c51cb8b593d2Arnaud A. de Grandmaison        build filename. Returns None if filename is not found in the database.
2746910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison        """
2747fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_CompilationDatabase_getCompileCommands(self,
2748fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                                                                     filename)
27499537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2750651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    def getAllCompileCommands(self):
2751651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        """
2752651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        Get an iterable object providing all the CompileCommands available from
2753651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        the database.
2754651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        """
2755651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        return conf.lib.clang_CompilationDatabase_getAllCompileCommands(self)
2756651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
2757651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
2758be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorcclass Token(Structure):
2759be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    """Represents a single token from the preprocessor.
2760be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2761be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    Tokens are effectively segments of source code. Source code is first parsed
2762be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    into tokens before being converted into the AST and Cursors.
2763be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2764be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    Tokens are obtained from parsed TranslationUnit instances. You currently
2765be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    can't create tokens manually.
2766be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    """
2767be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    _fields_ = [
2768be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        ('int_data', c_uint * 4),
2769be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        ('ptr_data', c_void_p)
2770be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    ]
2771be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2772be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @property
2773be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def spelling(self):
2774be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """The spelling of this token.
2775be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2776be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        This is the textual representation of the token in source.
2777be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """
2778fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTokenSpelling(self._tu, self)
2779be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2780be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @property
2781be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def kind(self):
2782be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """Obtain the TokenKind of the current token."""
2783fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return TokenKind.from_value(conf.lib.clang_getTokenKind(self))
2784be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2785be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @property
2786be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def location(self):
2787be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """The SourceLocation this Token occurs at."""
2788fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTokenLocation(self._tu, self)
2789be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2790be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @property
2791be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def extent(self):
2792be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """The SourceRange this Token occupies."""
2793fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return conf.lib.clang_getTokenExtent(self._tu, self)
2794be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2795be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    @property
2796be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    def cursor(self):
2797be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        """The Cursor this Token corresponds to."""
2798be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        cursor = Cursor()
2799be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2800fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        conf.lib.clang_annotateTokens(self._tu, byref(self), 1, byref(cursor))
2801be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
2802be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        return cursor
2803be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
28049537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc# Now comes the plumbing to hook up the C library.
28059537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
28069537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc# Register callback types in common container.
28079537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorccallbacks['translation_unit_includes'] = CFUNCTYPE(None, c_object_p,
28089537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc        POINTER(SourceLocation), c_uint, py_object)
28099537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorccallbacks['cursor_visit'] = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
281033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainarcallbacks['fields_visit'] = CFUNCTYPE(c_int, Cursor, py_object)
28119537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2812010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser# Functions strictly alphabetical order.
2813010556ef87db723780ee52cf6c0348ca304e20dcTobias GrosserfunctionList = [
2814010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_annotateTokens",
2815010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, POINTER(Token), c_uint, POINTER(Cursor)]),
28169537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2817010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompilationDatabase_dispose",
2818010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p]),
28199537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2820010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompilationDatabase_fromDirectory",
2821010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_char_p, POINTER(c_uint)],
2822010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p,
2823010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   CompilationDatabase.from_result),
28249537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2825651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ("clang_CompilationDatabase_getAllCompileCommands",
2826651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   [c_object_p],
2827651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   c_object_p,
2828651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines   CompileCommands.from_result),
2829651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
2830010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompilationDatabase_getCompileCommands",
2831010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p, c_char_p],
2832010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p,
2833010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   CompileCommands.from_result),
28349537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2835010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompileCommands_dispose",
2836010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p]),
28379537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2838010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompileCommands_getCommand",
2839010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p, c_uint],
2840010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
28419537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2842010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompileCommands_getSize",
2843010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p],
2844010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
28459537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2846010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompileCommand_getArg",
2847010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p, c_uint],
2848010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
2849010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
28509537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2851010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompileCommand_getDirectory",
2852010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p],
2853010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
2854010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
28559537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2856010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CompileCommand_getNumArgs",
2857010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p],
2858010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
28599537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2860010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_codeCompleteAt",
2861010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, c_char_p, c_int, c_int, c_void_p, c_int, c_int],
2862010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   POINTER(CCRStructure)),
28639537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2864010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_codeCompleteGetDiagnostic",
2865010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CodeCompletionResults, c_int],
2866010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Diagnostic),
28679537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2868010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_codeCompleteGetNumDiagnostics",
2869010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CodeCompletionResults],
2870010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
28719537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2872010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_createIndex",
2873010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_int, c_int],
2874010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
28759537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2876010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_createTranslationUnit",
2877010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Index, c_char_p],
2878010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
28799537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2880c965f76e02d536d875b1e9e3ea96f39452c6bfa2Dmitri Gribenko  ("clang_CXXMethod_isPureVirtual",
2881c965f76e02d536d875b1e9e3ea96f39452c6bfa2Dmitri Gribenko   [Cursor],
2882c965f76e02d536d875b1e9e3ea96f39452c6bfa2Dmitri Gribenko   bool),
2883c965f76e02d536d875b1e9e3ea96f39452c6bfa2Dmitri Gribenko
2884010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CXXMethod_isStatic",
2885010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
2886010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
28879537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2888010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_CXXMethod_isVirtual",
2889010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
2890010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
28919537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2892010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_defaultSaveOptions",
2893010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit],
2894010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
28959537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2896010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_disposeCodeCompleteResults",
2897010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CodeCompletionResults]),
28989537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2899010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser# ("clang_disposeCXTUResourceUsage",
2900010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser#  [CXTUResourceUsage]),
2901010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2902010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_disposeDiagnostic",
2903010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic]),
2904010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2905010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_disposeIndex",
2906010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Index]),
29079537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
2908010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_disposeString",
2909010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [_CXString]),
2910010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2911010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_disposeTokens",
2912010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, POINTER(Token), c_uint]),
2913010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2914010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_disposeTranslationUnit",
2915010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit]),
2916010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2917010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_equalCursors",
2918010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor, Cursor],
2919010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
2920010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2921010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_equalLocations",
2922010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [SourceLocation, SourceLocation],
2923010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
2924010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2925010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_equalRanges",
2926010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [SourceRange, SourceRange],
2927010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
2928010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2929010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_equalTypes",
2930010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type, Type],
2931010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
2932010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2933010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getArgType",
2934010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type, c_uint],
2935010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
2936010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
2937010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2938010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getArrayElementType",
2939010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
2940010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
2941010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
2942010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2943010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getArraySize",
2944010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
2945010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_longlong),
2946010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2947411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis  ("clang_getFieldDeclBitWidth",
2948411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   [Cursor],
2949411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   c_int),
2950411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
2951010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCanonicalCursor",
2952010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
2953010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
2954010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_cursor_result),
2955010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2956010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCanonicalType",
2957010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
2958010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
2959010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
2960010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2961010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCompletionAvailability",
2962010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_void_p],
2963010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
2964010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2965c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko  ("clang_getCompletionBriefComment",
2966c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko   [c_void_p],
2967c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko   _CXString),
2968c69e067f24aa64a277ca4d6048a3165cbb23dbe7Dmitri Gribenko
2969010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCompletionChunkCompletionString",
2970010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_void_p, c_int],
2971010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
2972010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2973010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCompletionChunkKind",
2974010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_void_p, c_int],
2975010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
2976010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2977010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCompletionChunkText",
2978010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_void_p, c_int],
2979010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString),
2980010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2981010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCompletionPriority",
2982010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_void_p],
2983010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
2984010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2985010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCString",
2986010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [_CXString],
2987010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_char_p),
2988010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2989010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursor",
2990010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, SourceLocation],
2991010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor),
2992010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2993010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorDefinition",
2994010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
2995010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
2996010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_result),
2997010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
2998010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorDisplayName",
2999010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3000010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3001010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3002010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3003010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorExtent",
3004010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3005010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceRange),
3006010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3007010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorLexicalParent",
3008010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3009010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3010010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_cursor_result),
3011010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3012010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorLocation",
3013010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3014010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3015010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3016010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorReferenced",
3017010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3018010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3019010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_result),
3020010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3021010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorReferenceNameRange",
3022010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor, c_uint, c_uint],
3023010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceRange),
3024010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3025010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorSemanticParent",
3026010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3027010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3028010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_cursor_result),
3029010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3030010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorSpelling",
3031010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3032010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3033010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3034010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3035010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorType",
3036010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3037010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3038010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3039010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3040010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCursorUSR",
3041010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3042010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3043010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3044010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3045176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ("clang_Cursor_getMangling",
3046176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   [Cursor],
3047176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   _CXString,
3048176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   _CXString.from_result),
3049176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
3050010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser# ("clang_getCXTUResourceUsage",
3051010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser#  [TranslationUnit],
3052010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser#  CXTUResourceUsage),
3053010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3054010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getCXXAccessSpecifier",
3055010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3056010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3057010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3058010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDeclObjCTypeEncoding",
3059010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3060010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3061010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3062010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3063010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnostic",
3064010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p, c_uint],
3065010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
3066010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3067010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticCategory",
3068010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic],
3069010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3070010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
30716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  ("clang_getDiagnosticCategoryText",
30726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines   [Diagnostic],
3073010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3074010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3075010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3076010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticFixIt",
3077010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic, c_uint, POINTER(SourceRange)],
3078010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3079010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3080010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3081010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticLocation",
3082010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic],
3083010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3084010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3085010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticNumFixIts",
3086010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic],
3087010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3088010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3089010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticNumRanges",
3090010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic],
3091010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3092010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3093010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticOption",
3094010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic, POINTER(_CXString)],
3095010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3096010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3097010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3098010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticRange",
3099010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic, c_uint],
3100010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceRange),
3101010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3102010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticSeverity",
3103010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic],
3104010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
3105010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3106010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getDiagnosticSpelling",
3107010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Diagnostic],
3108010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3109010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3110010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3111010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getElementType",
3112010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3113010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3114010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3115010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3116010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getEnumConstantDeclUnsignedValue",
3117010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3118010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_ulonglong),
3119010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3120010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getEnumConstantDeclValue",
3121010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3122010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_longlong),
3123010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3124010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getEnumDeclIntegerType",
3125010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3126010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3127010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3128010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3129010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getFile",
3130010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, c_char_p],
3131010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
3132010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3133010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getFileName",
3134010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [File],
3135010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString), # TODO go through _CXString.from_result?
3136010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3137010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getFileTime",
3138010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [File],
3139010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3140010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3141010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getIBOutletCollectionType",
3142010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3143010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3144010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3145010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3146010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getIncludedFile",
3147010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3148010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   File,
3149010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   File.from_cursor_result),
3150010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3151010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getInclusions",
3152010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, callbacks['translation_unit_includes'], py_object]),
3153010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3154010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getInstantiationLocation",
3155010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [SourceLocation, POINTER(c_object_p), POINTER(c_uint), POINTER(c_uint),
3156010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    POINTER(c_uint)]),
3157010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3158010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getLocation",
3159010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, File, c_uint, c_uint],
3160010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3161010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3162010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getLocationForOffset",
3163010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, File, c_uint],
3164010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3165010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3166010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getNullCursor",
3167010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   None,
3168010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor),
3169010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3170010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getNumArgTypes",
3171010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3172010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3173010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3174010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getNumCompletionChunks",
3175010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_void_p],
3176010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
3177010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3178010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getNumDiagnostics",
3179010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_object_p],
3180010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3181010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3182010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getNumElements",
3183010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3184010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_longlong),
3185010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3186010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getNumOverloadedDecls",
3187010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3188010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3189010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3190010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getOverloadedDecl",
3191010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor, c_uint],
3192010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3193010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_cursor_result),
3194010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3195010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getPointeeType",
3196010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3197010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3198010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3199010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3200010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getRange",
3201010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [SourceLocation, SourceLocation],
3202010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceRange),
3203010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3204010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getRangeEnd",
3205010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [SourceRange],
3206010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3207010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3208010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getRangeStart",
3209010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [SourceRange],
3210010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3211010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3212010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getResultType",
3213010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3214010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3215010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3216010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3217010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getSpecializedCursorTemplate",
3218010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3219010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3220010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_cursor_result),
3221010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3222010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTemplateCursorKind",
3223010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3224010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3225010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3226010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTokenExtent",
3227010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, Token],
3228010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceRange),
3229010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3230010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTokenKind",
3231010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Token],
3232010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3233010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3234010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTokenLocation",
3235010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, Token],
3236010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   SourceLocation),
3237010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3238010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTokenSpelling",
3239010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, Token],
3240010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3241010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3242010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3243010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTranslationUnitCursor",
3244010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit],
3245010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3246010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_result),
3247010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3248010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTranslationUnitSpelling",
3249010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit],
3250010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3251010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3252010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3253010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTUResourceUsageName",
3254010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_uint],
3255010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_char_p),
3256010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3257010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTypeDeclaration",
3258010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3259010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor,
3260010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Cursor.from_result),
3261010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3262010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTypedefDeclUnderlyingType",
3263010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3264010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type,
3265010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   Type.from_result),
3266010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3267010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_getTypeKindSpelling",
3268010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [c_uint],
3269010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString,
3270010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   _CXString.from_result),
3271010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3272c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis  ("clang_getTypeSpelling",
3273c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   [Type],
3274c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   _CXString,
3275c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   _CXString.from_result),
3276c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis
3277010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_hashCursor",
3278010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3279010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3280010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3281010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isAttribute",
3282010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3283010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3284010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3285010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isConstQualifiedType",
3286010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3287010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3288010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3289010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isCursorDefinition",
3290010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3291010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3292010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3293010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isDeclaration",
3294010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3295010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3296010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3297010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isExpression",
3298010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3299010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3300010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3301010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isFileMultipleIncludeGuarded",
3302010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, File],
3303010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3304010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3305010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isFunctionTypeVariadic",
3306010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3307010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3308010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3309010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isInvalid",
3310010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3311010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3312010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3313010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isPODType",
3314010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3315010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3316010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3317010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isPreprocessing",
3318010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3319010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3320010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3321010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isReference",
3322010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3323010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3324010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3325010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isRestrictQualifiedType",
3326010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3327010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3328010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3329010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isStatement",
3330010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3331010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3332010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3333010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isTranslationUnit",
3334010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3335010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3336010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3337010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isUnexposed",
3338010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [CursorKind],
3339010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3340010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3341010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isVirtualBase",
3342010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor],
3343010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3344010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3345010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_isVolatileQualifiedType",
3346010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Type],
3347010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   bool),
3348010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3349010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_parseTranslationUnit",
3350010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Index, c_char_p, c_void_p, c_int, c_void_p, c_int, c_int],
3351010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_object_p),
33529537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3353010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_reparseTranslationUnit",
3354010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, c_int, c_void_p, c_int],
3355010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
33569537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3357010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_saveTranslationUnit",
3358010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, c_char_p, c_uint],
3359010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_int),
33609537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3361010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_tokenize",
3362010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [TranslationUnit, SourceRange, POINTER(POINTER(Token)), POINTER(c_uint)]),
3363010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser
3364010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser  ("clang_visitChildren",
3365010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   [Cursor, callbacks['cursor_visit'], py_object],
3366010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser   c_uint),
3367b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc
3368b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc  ("clang_Cursor_getNumArguments",
3369b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc   [Cursor],
3370b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc   c_int),
3371b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc
3372b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc  ("clang_Cursor_getArgument",
3373b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc   [Cursor, c_uint],
3374b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc   Cursor,
3375b03b57d14983f90adb85f662812ba5742cfe45f2Gregory Szorc   Cursor.from_result),
3376411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
3377176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ("clang_Cursor_getNumTemplateArguments",
3378176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   [Cursor],
3379176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   c_int),
3380176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
3381176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ("clang_Cursor_getTemplateArgumentKind",
3382176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   [Cursor, c_uint],
3383176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   TemplateArgumentKind.from_id),
3384176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
3385176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ("clang_Cursor_getTemplateArgumentType",
3386176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   [Cursor, c_uint],
3387176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   Type,
3388176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   Type.from_result),
3389176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
3390176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ("clang_Cursor_getTemplateArgumentValue",
3391176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   [Cursor, c_uint],
3392176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   c_longlong),
3393176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
3394176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ("clang_Cursor_getTemplateArgumentUnsignedValue",
3395176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   [Cursor, c_uint],
3396176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines   c_ulonglong),
3397176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
339833337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar  ("clang_Cursor_isAnonymous",
339933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar   [Cursor],
340033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar   bool),
340133337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
3402411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis  ("clang_Cursor_isBitField",
3403411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   [Cursor],
340452bb2a06361d1d0d51809a2ac06e270e8cf05a9eDmitri Gribenko   bool),
3405411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
3406c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis  ("clang_Cursor_getBriefCommentText",
3407c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   [Cursor],
3408c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   _CXString,
3409c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   _CXString.from_result),
3410c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis
3411c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis  ("clang_Cursor_getRawCommentText",
3412c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   [Cursor],
3413c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   _CXString,
3414c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis   _CXString.from_result),
3415c23cb2d3e8af8354d43517283d3efb2cb0681f49Argyrios Kyrtzidis
341633337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar  ("clang_Cursor_getOffsetOfField",
341733337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar   [Cursor],
341833337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar   c_longlong),
341933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
3420411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis  ("clang_Type_getAlignOf",
3421411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   [Type],
3422411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   c_longlong),
3423411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
3424659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis  ("clang_Type_getClassType",
3425659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis   [Type],
3426659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis   Type,
3427659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis   Type.from_result),
3428659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
3429411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis  ("clang_Type_getOffsetOf",
3430411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   [Type, c_char_p],
3431411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   c_longlong),
3432411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis
3433411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis  ("clang_Type_getSizeOf",
3434411d33aa0b0d3bc9b2faec40cd821bdd836094abArgyrios Kyrtzidis   [Type],
3435dd9e2cb92274c8fea6b2d2acdd153c046d0a3888Argyrios Kyrtzidis   c_longlong),
3436659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis
3437659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis  ("clang_Type_getCXXRefQualifier",
3438659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis   [Type],
3439659837e0ce0f73c7fdd5941854be3500db2f4013Argyrios Kyrtzidis   c_uint),
344033337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar
344133337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar  ("clang_Type_visitFields",
344233337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar   [Type, callbacks['fields_visit'], py_object],
344333337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar   c_uint),
3444010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser]
34459537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3446010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosserclass LibclangError(Exception):
3447010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    def __init__(self, message):
3448010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser        self.m = message
34499537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3450010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    def __str__(self):
3451fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return self.m
34529537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3453857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosserdef register_function(lib, item, ignore_errors):
3454010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    # A function may not exist, if these bindings are used with an older or
3455010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    # incompatible version of libclang.so.
3456010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    try:
3457010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser        func = getattr(lib, item[0])
3458010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    except AttributeError as e:
3459fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        msg = str(e) + ". Please ensure that your python bindings are "\
3460fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                       "compatible with your libclang.so version."
3461857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        if ignore_errors:
3462857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser            return
3463fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        raise LibclangError(msg)
34649537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3465010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    if len(item) >= 2:
3466010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser        func.argtypes = item[1]
34679537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3468010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    if len(item) >= 3:
3469010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser        func.restype = item[2]
34709537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3471010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    if len(item) == 4:
3472010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser        func.errcheck = item[3]
34739537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3474857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosserdef register_functions(lib, ignore_errors):
3475010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    """Register function prototypes with a libclang library instance.
34769537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3477010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    This must be called as part of library instantiation so Python knows how
3478010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    to call out to the shared library.
3479010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    """
34809537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3481010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    def register(item):
3482857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        return register_function(lib, item, ignore_errors)
34839537e209be50c9af93e5e32c7d4d39af23de9c2dGregory Szorc
3484010556ef87db723780ee52cf6c0348ca304e20dcTobias Grosser    map(register, functionList)
3485910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison
3486fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosserclass Config:
3487fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    library_path = None
3488fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    library_file = None
3489857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser    compatibility_check = True
3490fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    loaded = False
3491fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3492fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    @staticmethod
3493fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    def set_library_path(path):
3494fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        """Set the path in which to search for libclang"""
3495fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if Config.loaded:
3496fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            raise Exception("library path must be set before before using " \
3497fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                            "any other functionalities in libclang.")
3498fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3499fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        Config.library_path = path
3500fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3501fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    @staticmethod
3502379ffe444f0a98f16f96470e0983bad50f282bc7Matt Beaumont-Gay    def set_library_file(filename):
3503379ffe444f0a98f16f96470e0983bad50f282bc7Matt Beaumont-Gay        """Set the exact location of libclang"""
3504fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if Config.loaded:
3505fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            raise Exception("library file must be set before before using " \
3506fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                            "any other functionalities in libclang.")
3507fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3508379ffe444f0a98f16f96470e0983bad50f282bc7Matt Beaumont-Gay        Config.library_file = filename
3509fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3510857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser    @staticmethod
3511857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser    def set_compatibility_check(check_status):
3512857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        """ Perform compatibility check when loading libclang
3513857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser
3514857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        The python bindings are only tested and evaluated with the version of
3515857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        libclang they are provided with. To ensure correct behavior a (limited)
3516857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        compatibility check is performed when loading the bindings. This check
3517857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        will throw an exception, as soon as it fails.
3518857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser
3519857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        In case these bindings are used with an older version of libclang, parts
3520857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        that have been stable between releases may still work. Users of the
3521857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        python bindings can disable the compatibility check. This will cause
3522857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        the python bindings to load, even though they are written for a newer
3523857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        version of libclang. Failures now arise if unsupported or incompatible
35246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        features are accessed. The user is required to test themselves if the
35256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines        features they are using are available and compatible between different
3526857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        libclang versions.
3527857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        """
3528857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        if Config.loaded:
3529857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser            raise Exception("compatibility_check must be set before before " \
3530857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser                            "using any other functionalities in libclang.")
3531857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser
3532857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        Config.compatibility_check = check_status
3533857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser
3534fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    @CachedProperty
3535fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    def lib(self):
3536fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        lib = self.get_cindex_library()
3537857134ed8412eab7aeb95c56eb8ddcd29c10c612Tobias Grosser        register_functions(lib, not Config.compatibility_check)
3538fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        Config.loaded = True
3539fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return lib
3540fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3541fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    def get_filename(self):
3542fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if Config.library_file:
3543fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            return Config.library_file
3544fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3545fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        import platform
3546fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        name = platform.system()
3547fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3548fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if name == 'Darwin':
3549fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            file = 'libclang.dylib'
3550fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        elif name == 'Windows':
3551fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            file = 'libclang.dll'
3552fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        else:
3553fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            file = 'libclang.so'
3554fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3555fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        if Config.library_path:
3556fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            file = Config.library_path + '/' + file
3557fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3558fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return file
3559fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3560fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    def get_cindex_library(self):
3561fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        try:
3562fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            library = cdll.LoadLibrary(self.get_filename())
3563fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        except OSError as e:
3564fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            msg = str(e) + ". To provide a path to libclang use " \
3565fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                           "Config.set_library_path() or " \
3566fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser                           "Config.set_library_file()."
3567fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser            raise LibclangError(msg)
3568fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3569fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser        return library
3570fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser
3571c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko    def function_exists(self, name):
3572c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko        try:
3573c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko            getattr(self.lib, name)
3574c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko        except AttributeError:
3575c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko            return False
3576c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko
3577c12d6a027662c978fc418c6fb584222fb3638483Dmitri Gribenko        return True
35786d2a40c191f6029dd95f32eb355a345ffdc30352Tobias Grosser
3579be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorcdef register_enumerations():
3580be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    for name, value in clang.enumerations.TokenKinds:
3581be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc        TokenKind.register(value, name)
3582be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
3583fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosserconf = Config()
3584be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorcregister_enumerations()
3585be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc
3586fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc__all__ = [
3587fcbc0fbaa480e6707af6ef437f5c43ea9f477d3aTobias Grosser    'Config',
3588fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'CodeCompletionResults',
3589910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    'CompilationDatabase',
3590910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    'CompileCommands',
3591910ff3f7f0a781fbb88c95bc957d1dcf63af91faArnaud A. de Grandmaison    'CompileCommand',
3592fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'CursorKind',
3593fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'Cursor',
3594fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'Diagnostic',
3595fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'File',
3596fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'FixIt',
3597fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'Index',
3598fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'SourceLocation',
3599fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'SourceRange',
3600be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    'TokenKind',
3601be51e43ba2c57b8032286af4e8713485b6dc78c3Gregory Szorc    'Token',
3602fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'TranslationUnitLoadError',
3603fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'TranslationUnit',
3604fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'TypeKind',
3605fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc    'Type',
3606fbf620bc2b7812e826f04befa31d3a48a86210baGregory Szorc]
3607