CXCursor.cpp revision b11be041e4f05519a2eabf6a99429ba6110f1ca9
116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===//
216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//                     The LLVM Compiler Infrastructure
416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// This file is distributed under the University of Illinois Open Source
616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// License. See LICENSE.TXT for details.
716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===----------------------------------------------------------------------===//
916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
102e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// This file defines routines for manipulating CXCursors. It should be the
112e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// only file that has internal knowledge of the encoding of the data in
122e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// CXCursor.
1316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//
1416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===----------------------------------------------------------------------===//
1516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
160a90d32523bfe5fa63e11b648686c9699f786d15Ted Kremenek#include "CXTranslationUnit.h"
1716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "CXCursor.h"
18ed122735639d83c10f18c28c7fd117bfcd0f62cbTed Kremenek#include "CXString.h"
197eaa8ae8692c5cd3eed8cb334fe5346470522091Douglas Gregor#include "clang/Frontend/ASTUnit.h"
2016c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "clang/AST/Decl.h"
216931900f43cea558c6974075256c07728dbfecc6Douglas Gregor#include "clang/AST/DeclCXX.h"
22283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/DeclObjC.h"
23283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/Expr.h"
241f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor#include "clang/AST/ExprCXX.h"
25007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek#include "clang-c/Index.h"
26edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek#include "llvm/Support/ErrorHandling.h"
2716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
2816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenekusing namespace clang;
291f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorusing namespace cxcursor;
3016c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
315bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas GregorCXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) {
325bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
335bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  CXCursor C = { K, { 0, 0, 0 } };
345bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  return C;
3516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek}
3616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek
37e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenekstatic CXCursorKind GetCursorKind(const Attr *A) {
38e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  assert(A && "Invalid arguments!");
39e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  switch (A->getKind()) {
40e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek    default: break;
41387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt    case attr::IBAction: return CXCursor_IBActionAttr;
42387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt    case attr::IBOutlet: return CXCursor_IBOutletAttr;
43387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt    case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
446639e9255489ad8e10278d5658fdd4b3c0e1e4cdArgyrios Kyrtzidis    case attr::Final: return CXCursor_CXXFinalAttr;
456639e9255489ad8e10278d5658fdd4b3c0e1e4cdArgyrios Kyrtzidis    case attr::Override: return CXCursor_CXXOverrideAttr;
46e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  }
47e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
48e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  return CXCursor_UnexposedAttr;
49e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek}
50e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
51a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent,
52a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                CXTranslationUnit TU) {
53e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  assert(A && Parent && TU && "Invalid arguments!");
54e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  CXCursor C = { GetCursorKind(A), { Parent, (void*)A, TU } };
55e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek  return C;
56e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek}
57e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek
58a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU,
59007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek                                bool FirstInDeclGroup) {
6054d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(D && TU && "Invalid arguments!");
61007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek  CXCursor C = { getCursorKindForDecl(D),
62dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin                 { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }
63007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek               };
645bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor  return C;
65edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek}
66edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek
67a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent,
68a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                CXTranslationUnit TU) {
6954d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(S && TU && "Invalid arguments!");
7097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  CXCursorKind K = CXCursor_NotImplemented;
7197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
7297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  switch (S->getStmtClass()) {
7397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::NoStmtClass:
7497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
7542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
7697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CaseStmtClass:
7742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CaseStmt;
7842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
7942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
8097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::DefaultStmtClass:
8142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_DefaultStmt;
8242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
8342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
8442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::IfStmtClass:
8542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_IfStmt;
8642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
8742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
8842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::SwitchStmtClass:
8942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SwitchStmt;
9042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
9142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
9242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::WhileStmtClass:
9342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_WhileStmt;
9442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
9542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
9642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DoStmtClass:
9742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_DoStmt;
9842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
9942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
10042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ForStmtClass:
10142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ForStmt;
10242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
10342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
10442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::GotoStmtClass:
10542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_GotoStmt;
10642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
10742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
10897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::IndirectGotoStmtClass:
10942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_IndirectGotoStmt;
11042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
11142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
11242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ContinueStmtClass:
11342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ContinueStmt;
11442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
11542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
11642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BreakStmtClass:
11742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_BreakStmt;
11842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
11942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
12042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ReturnStmtClass:
12142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ReturnStmt;
12242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
12342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
12442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::AsmStmtClass:
12542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_AsmStmt;
12642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
12742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
12842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtTryStmtClass:
12942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtTryStmt;
13042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
13142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
13242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtCatchStmtClass:
13342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtCatchStmt;
13442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
13542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
13642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtFinallyStmtClass:
13742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtFinallyStmt;
13842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
13942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
14042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtThrowStmtClass:
14142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtThrowStmt;
14242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
14342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
14442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAtSynchronizedStmtClass:
14542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAtSynchronizedStmt;
14642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
14742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
14842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCAutoreleasePoolStmtClass:
14942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCAutoreleasePoolStmt;
15042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
15142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
15297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCForCollectionStmtClass:
15342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCForCollectionStmt;
15442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
15542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
15697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXCatchStmtClass:
15742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXCatchStmt;
15842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
15942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
16042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXTryStmtClass:
16142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXTryStmt;
16242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
16342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
16442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXForRangeStmtClass:
16542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXForRangeStmt;
16642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
16742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
16828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  case Stmt::SEHTryStmtClass:
16942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SEHTryStmt;
17042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
17142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
17228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  case Stmt::SEHExceptStmtClass:
17342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SEHExceptStmt;
17442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
17542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
17628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  case Stmt::SEHFinallyStmtClass:
17742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SEHFinallyStmt;
17842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
17942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
18042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ArrayTypeTraitExprClass:
18142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::AsTypeExprClass:
18242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BinaryConditionalOperatorClass:
18342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BinaryTypeTraitExprClass:
18442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXBindTemporaryExprClass:
18542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDefaultArgExprClass:
18642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXScalarValueInitExprClass:
18742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXUuidofExprClass:
18842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ChooseExprClass:
18942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DesignatedInitExprClass:
19042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ExprWithCleanupsClass:
19142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ExpressionTraitExprClass:
19242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ExtVectorElementExprClass:
19342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ImplicitCastExprClass:
19442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ImplicitValueInitExprClass:
19503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  case Stmt::MaterializeTemporaryExprClass:
19642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCIndirectCopyRestoreExprClass:
19742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::OffsetOfExprClass:
19842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::OpaqueValueExprClass:
19942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ParenListExprClass:
20042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::PredefinedExprClass:
20142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ShuffleVectorExprClass:
20242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnaryExprOrTypeTraitExprClass:
20342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnaryTypeTraitExprClass:
20442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::VAArgExprClass:
20542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_UnexposedExpr;
20642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
20742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
20842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CompoundStmtClass:
20942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CompoundStmt;
21097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
21197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
21242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::NullStmtClass:
21342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_NullStmt;
21436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor    break;
21536897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
21642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::LabelStmtClass:
21742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_LabelStmt;
21842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
21942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
22042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DeclStmtClass:
22142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_DeclStmt;
22242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
22342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
22442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::IntegerLiteralClass:
22542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_IntegerLiteral;
22642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
22742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
22842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::FloatingLiteralClass:
22942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_FloatingLiteral;
23042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
23142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
23242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ImaginaryLiteralClass:
23342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ImaginaryLiteral;
23442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
23542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
23642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::StringLiteralClass:
23742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_StringLiteral;
23842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
23942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
24042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CharacterLiteralClass:
24142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CharacterLiteral;
24242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
24342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
24442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ParenExprClass:
24542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ParenExpr;
24642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
24742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
2488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  case Stmt::UnaryOperatorClass:
24942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_UnaryOperator;
25042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
25142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
25242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXNoexceptExprClass:
25342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_UnaryExpr;
25442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
25542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
25642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ArraySubscriptExprClass:
25742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ArraySubscriptExpr;
25842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
25942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
26042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BinaryOperatorClass:
26142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_BinaryOperator;
26242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
26342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
26497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CompoundAssignOperatorClass:
26542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CompoundAssignOperator;
26642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
26742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
26842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ConditionalOperatorClass:
26942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ConditionalOperator;
27042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
27142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
27297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CStyleCastExprClass:
27342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CStyleCastExpr;
27442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
27542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
27642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CompoundLiteralExprClass:
27742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CompoundLiteralExpr;
27842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
27942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
28042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::InitListExprClass:
28142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_InitListExpr;
28242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
28342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
28442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::AddrLabelExprClass:
28542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_AddrLabelExpr;
28642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
28742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
28842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::StmtExprClass:
28942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_StmtExpr;
29042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
29142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
292f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne  case Stmt::GenericSelectionExprClass:
29342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_GenericSelectionExpr;
29442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
29542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
29642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::GNUNullExprClass:
29742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_GNUNullExpr;
29842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
29942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
30042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXStaticCastExprClass:
30142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXStaticCastExpr;
30242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
30342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
30442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDynamicCastExprClass:
30542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXDynamicCastExpr;
30642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
30742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
30842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXReinterpretCastExprClass:
30942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXReinterpretCastExpr;
31042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
31142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
31242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXConstCastExprClass:
31342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXConstCastExpr;
31442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
31542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
31697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXFunctionalCastExprClass:
31742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXFunctionalCastExpr;
31842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
31942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
32042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXTypeidExprClass:
32142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXTypeidExpr;
32242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
32342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
32442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXBoolLiteralExprClass:
32542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXBoolLiteralExpr;
32642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
32742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
32842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXNullPtrLiteralExprClass:
32942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXNullPtrLiteralExpr;
33042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
33142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
33242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXThisExprClass:
33342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXThisExpr;
33442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
33542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
33642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXThrowExprClass:
33742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXThrowExpr;
33842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
33942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
34042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXNewExprClass:
34142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXNewExpr;
34242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
34342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
34442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDeleteExprClass:
34542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_CXXDeleteExpr;
34642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
34742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
34842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCStringLiteralClass:
34942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCStringLiteral;
35042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
35142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
35242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCEncodeExprClass:
35342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCEncodeExpr;
35442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
35542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
35642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCSelectorExprClass:
35742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCSelectorExpr;
35842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
35942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
36042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCProtocolExprClass:
36142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCProtocolExpr;
36242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
36342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
364f85e193739c953358c865005855253af4f68a497John McCall  case Stmt::ObjCBridgedCastExprClass:
36542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_ObjCBridgedCastExpr;
36642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
36742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
36842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::BlockExprClass:
36942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_BlockExpr;
37042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
37142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
372be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor  case Stmt::PackExpansionExprClass:
37342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_PackExpansionExpr;
37442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    break;
37542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
376ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor  case Stmt::SizeOfPackExprClass:
37742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor    K = CXCursor_SizeOfPackExpr;
37897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
37942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor
38097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::BlockDeclRefExprClass:
38142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DeclRefExprClass:
38242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::DependentScopeDeclRefExprClass:
38391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall  case Stmt::SubstNonTypeTemplateParmExprClass:
384c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor  case Stmt::SubstNonTypeTemplateParmPackExprClass:
38542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnresolvedLookupExprClass:
38697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_DeclRefExpr;
38797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
38897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
38942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXDependentScopeMemberExprClass:
39042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXPseudoDestructorExprClass:
39197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::MemberExprClass:
39242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::ObjCIsaExprClass:
39397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCIvarRefExprClass:
39497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCPropertyRefExprClass:
39542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::UnresolvedMemberExprClass:
39697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_MemberRefExpr;
39797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
39897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
39997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CallExprClass:
40097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXOperatorCallExprClass:
40197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXMemberCallExprClass:
402e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne  case Stmt::CUDAKernelCallExprClass:
40397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXConstructExprClass:
40497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::CXXTemporaryObjectExprClass:
40542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor  case Stmt::CXXUnresolvedConstructExprClass:
40697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_CallExpr;
40797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
40897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
40997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  case Stmt::ObjCMessageExprClass:
41097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    K = CXCursor_ObjCMessageExpr;
41197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor    break;
41297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  }
41397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
414b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor  CXCursor C = { K, { Parent, S, TU } };
41597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor  return C;
41697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor}
41797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
4182e331b938b38057e333fab0ba841130ea8467794Douglas GregorCXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
419b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor                                               SourceLocation Loc,
420a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
42154d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(Super && TU && "Invalid arguments!");
4222e331b938b38057e333fab0ba841130ea8467794Douglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
423b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor  CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } };
4242e331b938b38057e333fab0ba841130ea8467794Douglas Gregor  return C;
4252e331b938b38057e333fab0ba841130ea8467794Douglas Gregor}
4262e331b938b38057e333fab0ba841130ea8467794Douglas Gregor
4272e331b938b38057e333fab0ba841130ea8467794Douglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation>
4282e331b938b38057e333fab0ba841130ea8467794Douglas Gregorcxcursor::getCursorObjCSuperClassRef(CXCursor C) {
4292e331b938b38057e333fab0ba841130ea8467794Douglas Gregor  assert(C.kind == CXCursor_ObjCSuperClassRef);
4302e331b938b38057e333fab0ba841130ea8467794Douglas Gregor  return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
4312e331b938b38057e333fab0ba841130ea8467794Douglas Gregor           SourceLocation::getFromRawEncoding(
4322e331b938b38057e333fab0ba841130ea8467794Douglas Gregor                                      reinterpret_cast<uintptr_t>(C.data[1])));
4332e331b938b38057e333fab0ba841130ea8467794Douglas Gregor}
4342e331b938b38057e333fab0ba841130ea8467794Douglas Gregor
43578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas GregorCXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super,
436b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor                                             SourceLocation Loc,
437a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                             CXTranslationUnit TU) {
43854d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(Super && TU && "Invalid arguments!");
43978db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
440b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor  CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } };
44178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  return C;
44278db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor}
44378db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor
44478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorstd::pair<ObjCProtocolDecl *, SourceLocation>
44578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorcxcursor::getCursorObjCProtocolRef(CXCursor C) {
44678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  assert(C.kind == CXCursor_ObjCProtocolRef);
44778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]),
44878db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor           SourceLocation::getFromRawEncoding(
44978db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor                                      reinterpret_cast<uintptr_t>(C.data[1])));
45078db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor}
45178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor
4521adb082a709f7b588f03672999294e061234b2cfDouglas GregorCXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class,
453b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor                                          SourceLocation Loc,
454a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                          CXTranslationUnit TU) {
455ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek  // 'Class' can be null for invalid code.
456ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek  if (!Class)
457ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek    return MakeCXCursorInvalid(CXCursor_InvalidCode);
458ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek  assert(TU && "Invalid arguments!");
4591adb082a709f7b588f03672999294e061234b2cfDouglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
460b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor  CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } };
4611adb082a709f7b588f03672999294e061234b2cfDouglas Gregor  return C;
4621adb082a709f7b588f03672999294e061234b2cfDouglas Gregor}
4631adb082a709f7b588f03672999294e061234b2cfDouglas Gregor
4641adb082a709f7b588f03672999294e061234b2cfDouglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation>
4651adb082a709f7b588f03672999294e061234b2cfDouglas Gregorcxcursor::getCursorObjCClassRef(CXCursor C) {
4661adb082a709f7b588f03672999294e061234b2cfDouglas Gregor  assert(C.kind == CXCursor_ObjCClassRef);
4671adb082a709f7b588f03672999294e061234b2cfDouglas Gregor  return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
4681adb082a709f7b588f03672999294e061234b2cfDouglas Gregor           SourceLocation::getFromRawEncoding(
4691adb082a709f7b588f03672999294e061234b2cfDouglas Gregor                                      reinterpret_cast<uintptr_t>(C.data[1])));
4701adb082a709f7b588f03672999294e061234b2cfDouglas Gregor}
4711adb082a709f7b588f03672999294e061234b2cfDouglas Gregor
4727d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas GregorCXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc,
473a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                     CXTranslationUnit TU) {
47454d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar  assert(Type && TU && "Invalid arguments!");
4757d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
4767d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } };
4777d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  return C;
4787d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor}
4797d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor
4807d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorstd::pair<TypeDecl *, SourceLocation>
4817d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorcxcursor::getCursorTypeRef(CXCursor C) {
4827d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  assert(C.kind == CXCursor_TypeRef);
4837d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor  return std::make_pair(static_cast<TypeDecl *>(C.data[0]),
4847d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor           SourceLocation::getFromRawEncoding(
4857d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor                                      reinterpret_cast<uintptr_t>(C.data[1])));
4867d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor}
4877d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor
4880b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas GregorCXCursor cxcursor::MakeCursorTemplateRef(TemplateDecl *Template,
489a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                         SourceLocation Loc,
490a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                         CXTranslationUnit TU) {
4910b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  assert(Template && TU && "Invalid arguments!");
4920b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
4930b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  CXCursor C = { CXCursor_TemplateRef, { Template, RawLoc, TU } };
4940b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  return C;
4950b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor}
4960b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor
4970b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorstd::pair<TemplateDecl *, SourceLocation>
4980b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorcxcursor::getCursorTemplateRef(CXCursor C) {
4990b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  assert(C.kind == CXCursor_TemplateRef);
5000b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor  return std::make_pair(static_cast<TemplateDecl *>(C.data[0]),
5010b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor                        SourceLocation::getFromRawEncoding(
5020b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor                                       reinterpret_cast<uintptr_t>(C.data[1])));
5030b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor}
5040b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor
5056931900f43cea558c6974075256c07728dbfecc6Douglas GregorCXCursor cxcursor::MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc,
506a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                          CXTranslationUnit TU) {
5076931900f43cea558c6974075256c07728dbfecc6Douglas Gregor
5086931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
5096931900f43cea558c6974075256c07728dbfecc6Douglas Gregor         "Invalid arguments!");
5106931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
5116931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  CXCursor C = { CXCursor_NamespaceRef, { NS, RawLoc, TU } };
5126931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  return C;
5136931900f43cea558c6974075256c07728dbfecc6Douglas Gregor}
5146931900f43cea558c6974075256c07728dbfecc6Douglas Gregor
5156931900f43cea558c6974075256c07728dbfecc6Douglas Gregorstd::pair<NamedDecl *, SourceLocation>
5166931900f43cea558c6974075256c07728dbfecc6Douglas Gregorcxcursor::getCursorNamespaceRef(CXCursor C) {
5176931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  assert(C.kind == CXCursor_NamespaceRef);
5186931900f43cea558c6974075256c07728dbfecc6Douglas Gregor  return std::make_pair(static_cast<NamedDecl *>(C.data[0]),
5196931900f43cea558c6974075256c07728dbfecc6Douglas Gregor                        SourceLocation::getFromRawEncoding(
5206931900f43cea558c6974075256c07728dbfecc6Douglas Gregor                                       reinterpret_cast<uintptr_t>(C.data[1])));
5216931900f43cea558c6974075256c07728dbfecc6Douglas Gregor}
5226931900f43cea558c6974075256c07728dbfecc6Douglas Gregor
523a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas GregorCXCursor cxcursor::MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
524a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                       CXTranslationUnit TU) {
525a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor
526a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  assert(Field && TU && "Invalid arguments!");
527a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
528a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  CXCursor C = { CXCursor_MemberRef, { Field, RawLoc, TU } };
529a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  return C;
530a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor}
531a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor
532a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorstd::pair<FieldDecl *, SourceLocation>
533a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorcxcursor::getCursorMemberRef(CXCursor C) {
534a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  assert(C.kind == CXCursor_MemberRef);
535a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor  return std::make_pair(static_cast<FieldDecl *>(C.data[0]),
536a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor                        SourceLocation::getFromRawEncoding(
537a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor                                       reinterpret_cast<uintptr_t>(C.data[1])));
538a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor}
539a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor
540a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B,
541a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                              CXTranslationUnit TU){
5423064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek  CXCursor C = { CXCursor_CXXBaseSpecifier, { B, 0, TU } };
5433064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek  return C;
5443064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek}
5453064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek
5463064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed KremenekCXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
5473064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek  assert(C.kind == CXCursor_CXXBaseSpecifier);
5483064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek  return static_cast<CXXBaseSpecifier*>(C.data[0]);
5493064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek}
5503064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek
5519f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorCXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
552a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                                    CXTranslationUnit TU) {
5539f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor  CXCursor C = { CXCursor_PreprocessingDirective,
5549f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor                 { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()),
5559f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor                   reinterpret_cast<void *>(Range.getEnd().getRawEncoding()),
5569f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor                   TU }
5579f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor               };
5589f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor  return C;
5599f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor}
5609f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor
5619f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorSourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
5629f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor  assert(C.kind == CXCursor_PreprocessingDirective);
563ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis  SourceRange Range = SourceRange(SourceLocation::getFromRawEncoding(
5649f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor                                      reinterpret_cast<uintptr_t> (C.data[0])),
5654807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor                     SourceLocation::getFromRawEncoding(
5664807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor                                      reinterpret_cast<uintptr_t> (C.data[1])));
567ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis  ASTUnit *TU = getCursorASTUnit(C);
568ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis  return TU->mapRangeFromPreamble(Range);
5694807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor}
5704807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor
571a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI,
572a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                             CXTranslationUnit TU) {
573572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor  CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } };
574572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor  return C;
575572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor}
576572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor
577572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas GregorMacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
578572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor  assert(C.kind == CXCursor_MacroDefinition);
579572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor  return static_cast<MacroDefinition *>(C.data[0]);
580572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor}
581572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor
5829e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler CarruthCXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
5839e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth                                            CXTranslationUnit TU) {
5849b2a0ac970a077bdc0bf08c6c682f80ad733c892Chandler Carruth  CXCursor C = { CXCursor_MacroExpansion, { MI, 0, TU } };
5854807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor  return C;
5864807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor}
5874807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor
5889e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler CarruthMacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) {
5899b2a0ac970a077bdc0bf08c6c682f80ad733c892Chandler Carruth  assert(C.kind == CXCursor_MacroExpansion);
5909e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth  return static_cast<MacroExpansion *>(C.data[0]);
5919f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor}
5929f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor
593ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorCXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
594a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                                CXTranslationUnit TU) {
595ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor  CXCursor C = { CXCursor_InclusionDirective, { ID, 0, TU } };
596ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor  return C;
597ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor}
598ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
599ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorInclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
600ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor  assert(C.kind == CXCursor_InclusionDirective);
601ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor  return static_cast<InclusionDirective *>(C.data[0]);
602ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor}
603ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor
60436897b05ca2886e287f01802614bc10cbadcec22Douglas GregorCXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
605a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                      CXTranslationUnit TU) {
60636897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
60736897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  assert(Label && TU && "Invalid arguments!");
60836897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
60936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  CXCursor C = { CXCursor_LabelRef, { Label, RawLoc, TU } };
61036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  return C;
61136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor}
61236897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
61336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorstd::pair<LabelStmt*, SourceLocation>
61436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorcxcursor::getCursorLabelRef(CXCursor C) {
61536897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  assert(C.kind == CXCursor_LabelRef);
61636897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor  return std::make_pair(static_cast<LabelStmt *>(C.data[0]),
61736897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor                        SourceLocation::getFromRawEncoding(
61836897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor                                       reinterpret_cast<uintptr_t>(C.data[1])));
61936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor}
62036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor
6211f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E,
622a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
6231f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(E && TU && "Invalid arguments!");
6241f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  OverloadedDeclRefStorage Storage(E);
6251f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding());
6261f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  CXCursor C = {
6271f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                 CXCursor_OverloadedDeclRef,
6281f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                 { Storage.getOpaqueValue(), RawLoc, TU }
6291f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor               };
6301f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return C;
6311f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
6321f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
6331f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D,
6341f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                                               SourceLocation Loc,
635a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
6361f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(D && TU && "Invalid arguments!");
6371f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
6381f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  OverloadedDeclRefStorage Storage(D);
6391f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  CXCursor C = {
6401f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor    CXCursor_OverloadedDeclRef,
6411f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor    { Storage.getOpaqueValue(), RawLoc, TU }
6421f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  };
6431f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return C;
6441f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
6451f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
6461f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
6471f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                                               SourceLocation Loc,
648a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                               CXTranslationUnit TU) {
6491f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
6501f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
6511f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
6521f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  CXCursor C = {
6531f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor    CXCursor_OverloadedDeclRef,
6541f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor    { Storage.getOpaqueValue(), RawLoc, TU }
6551f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  };
6561f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return C;
6571f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
6581f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
6591f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorstd::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
6601f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorcxcursor::getCursorOverloadedDeclRef(CXCursor C) {
6611f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  assert(C.kind == CXCursor_OverloadedDeclRef);
6621f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor  return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]),
6631f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                        SourceLocation::getFromRawEncoding(
6641f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor                                       reinterpret_cast<uintptr_t>(C.data[1])));
6651f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor}
6661f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor
667283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorDecl *cxcursor::getCursorDecl(CXCursor Cursor) {
668283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor  return (Decl *)Cursor.data[0];
669283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
670283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
671283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorExpr *cxcursor::getCursorExpr(CXCursor Cursor) {
672283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor  return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
673283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
674283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
675283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorStmt *cxcursor::getCursorStmt(CXCursor Cursor) {
67678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor  if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
6771adb082a709f7b588f03672999294e061234b2cfDouglas Gregor      Cursor.kind == CXCursor_ObjCProtocolRef ||
6781adb082a709f7b588f03672999294e061234b2cfDouglas Gregor      Cursor.kind == CXCursor_ObjCClassRef)
6792e331b938b38057e333fab0ba841130ea8467794Douglas Gregor    return 0;
6802e331b938b38057e333fab0ba841130ea8467794Douglas Gregor
681283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor  return (Stmt *)Cursor.data[1];
682283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
683283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
68495f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted KremenekAttr *cxcursor::getCursorAttr(CXCursor Cursor) {
68595f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek  return (Attr *)Cursor.data[1];
68695f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek}
68795f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek
6888ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios KyrtzidisDecl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
6898ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis  return (Decl *)Cursor.data[0];
6908ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis}
6918ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis
692f46034af49435a4d1a0085a4738343122aeb6521Douglas GregorASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
693b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor  return getCursorASTUnit(Cursor)->getASTContext();
694b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor}
69597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor
696b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas GregorASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
697a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek  return static_cast<ASTUnit *>(static_cast<CXTranslationUnit>(Cursor.data[2])
698a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek                                  ->TUData);
699a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek}
700a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek
701a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
702a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek  return static_cast<CXTranslationUnit>(Cursor.data[2]);
703283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor}
704283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor
705b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidisstatic void CollectOverriddenMethods(CXTranslationUnit TU,
706b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                     DeclContext *Ctx,
707b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                     ObjCMethodDecl *Method,
708b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                     SmallVectorImpl<CXCursor> &Methods) {
709b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (!Ctx)
710b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return;
711b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
712b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  // If we have a class or category implementation, jump straight to the
713b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  // interface.
714b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(Ctx))
715b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return CollectOverriddenMethods(TU, Impl->getClassInterface(),
716b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                    Method, Methods);
717b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
718b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  ObjCContainerDecl *Container = dyn_cast<ObjCContainerDecl>(Ctx);
719b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (!Container)
720b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return;
721b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
722b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  // Check whether we have a matching method at this level.
723b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (ObjCMethodDecl *Overridden = Container->getMethod(Method->getSelector(),
724b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                                    Method->isInstanceMethod()))
725b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    if (Method != Overridden) {
726b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      // We found an override at this level; there is no need to look
727b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      // into other protocols or categories.
728b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      Methods.push_back(MakeCXCursor(Overridden, TU));
729b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      return;
730b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    }
731b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
732b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
733b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
734b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                          PEnd = Protocol->protocol_end();
735b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis         P != PEnd; ++P)
736b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      CollectOverriddenMethods(TU, *P, Method, Methods);
737b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  }
738b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
739b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
740b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(),
741b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                          PEnd = Category->protocol_end();
742b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis         P != PEnd; ++P)
743b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      CollectOverriddenMethods(TU, *P, Method, Methods);
744b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  }
745b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
746b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (ObjCInterfaceDecl *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
747b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(),
748b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                           PEnd = Interface->protocol_end();
749b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis         P != PEnd; ++P)
750b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      CollectOverriddenMethods(TU, *P, Method, Methods);
751b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
752b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    for (ObjCCategoryDecl *Category = Interface->getCategoryList();
753b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis         Category; Category = Category->getNextClassCategory())
754b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      CollectOverriddenMethods(TU, Category, Method, Methods);
755b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
756b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    // We only look into the superclass if we haven't found anything yet.
757b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    if (Methods.empty())
758b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      if (ObjCInterfaceDecl *Super = Interface->getSuperClass())
759b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis        return CollectOverriddenMethods(TU, Super, Method, Methods);
760b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  }
761b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis}
762b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
763b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidisvoid cxcursor::getOverriddenCursors(CXCursor cursor,
764b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis                                    SmallVectorImpl<CXCursor> &overridden) {
765b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (!clang_isDeclaration(cursor.kind))
766b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return;
767b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
768b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  Decl *D = getCursorDecl(cursor);
769b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (!D)
770b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return;
771b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
772b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  // Handle C++ member functions.
773b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  CXTranslationUnit TU = getCursorTU(cursor);
774b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
775b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    for (CXXMethodDecl::method_iterator
776b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis              M = CXXMethod->begin_overridden_methods(),
777b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis           MEnd = CXXMethod->end_overridden_methods();
778b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis         M != MEnd; ++M)
779b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis      overridden.push_back(MakeCXCursor(const_cast<CXXMethodDecl*>(*M), TU));
780b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return;
781b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  }
782b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
783b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D);
784b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  if (!Method)
785b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis    return;
786b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
787b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  // Handle Objective-C methods.
788b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis  CollectOverriddenMethods(TU, Method->getDeclContext(), Method, overridden);
789b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis}
790b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis
791283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregorbool cxcursor::operator==(CXCursor X, CXCursor Y) {
792283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor  return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
793283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor         X.data[2] == Y.data[2];
7942e331b938b38057e333fab0ba841130ea8467794Douglas Gregor}
795007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek
796007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// FIXME: Remove once we can model DeclGroups and their appropriate ranges
797007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// properly in the ASTs.
798007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenekbool cxcursor::isFirstInDeclGroup(CXCursor C) {
799007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek  assert(clang_isDeclaration(C.kind));
800007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek  return ((uintptr_t) (C.data[1])) != 0;
801007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek}
802007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek
803eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek//===----------------------------------------------------------------------===//
804b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis// libclang CXCursor APIs
805b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis//===----------------------------------------------------------------------===//
806b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis
807fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidisextern "C" {
808fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis
809fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidisint clang_Cursor_isNull(CXCursor cursor) {
810fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis  return clang_equalCursors(cursor, clang_getNullCursor());
811fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis}
812fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis
813b0d6eaa6b646c18c49923aefc76973801f561701Argyrios KyrtzidisCXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
814b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis  return getCursorTU(cursor);
815b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis}
816b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis
817fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis} // end: extern "C"
818fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis
819b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis//===----------------------------------------------------------------------===//
820eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek// CXCursorSet.
821eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek//===----------------------------------------------------------------------===//
822eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
823eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenektypedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
824eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
825eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekstatic inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
826eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  return (CXCursorSet) setImpl;
827eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
828eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekstatic inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
829eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  return (CXCursorSet_Impl*) set;
830eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
831eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremeneknamespace llvm {
832da6fb69873079a0193ed8c9fa1d1b859d4f87b95Ted Kremenektemplate<> struct DenseMapInfo<CXCursor> {
833eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekpublic:
834eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  static inline CXCursor getEmptyKey() {
835eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return MakeCXCursorInvalid(CXCursor_InvalidFile);
836eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  }
837eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  static inline CXCursor getTombstoneKey() {
838eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return MakeCXCursorInvalid(CXCursor_NoDeclFound);
839eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  }
840eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  static inline unsigned getHashValue(const CXCursor &cursor) {
841eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return llvm::DenseMapInfo<std::pair<void*,void*> >
842eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek      ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
843eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  }
844eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
845eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return x.kind == y.kind &&
846eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek           x.data[0] == y.data[0] &&
847eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek           x.data[1] == y.data[1];
848eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  }
849eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek};
850eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
851eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
852eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekextern "C" {
853eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted KremenekCXCursorSet clang_createCXCursorSet() {
854eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  return packCXCursorSet(new CXCursorSet_Impl());
855eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
856eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
857eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekvoid clang_disposeCXCursorSet(CXCursorSet set) {
858eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  delete unpackCXCursorSet(set);
859eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
860eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
861eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekunsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
862eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
863eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  if (!setImpl)
864eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return 0;
865eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  return setImpl->find(cursor) == setImpl->end();
866eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
867eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
868e8b3de090b9de3c27c5d381e767217ddb849d5d8Anders Carlssonunsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {
869eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  // Do not insert invalid cursors into the set.
870eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  if (cursor.kind >= CXCursor_FirstInvalid &&
871eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek      cursor.kind <= CXCursor_LastInvalid)
872eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return 1;
873eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek
874eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
875eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  if (!setImpl)
876eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek    return 1;
877eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  unsigned &entry = (*setImpl)[cursor];
878eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  unsigned flag = entry == 0 ? 1 : 0;
879eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  entry = 1;
880eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek  return flag;
881eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}
8828fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor
8838fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas GregorCXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
8848fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor  enum CXCursorKind kind = clang_getCursorKind(cursor);
8858fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor  if (clang_isDeclaration(kind)) {
8868fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    Decl *decl = getCursorDecl(cursor);
8878fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    if (isa<NamedDecl>(decl)) {
8888fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      NamedDecl *namedDecl = (NamedDecl *)decl;
8898fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      ASTUnit *unit = getCursorASTUnit(cursor);
8908fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      if (unit->hasSema()) {
8918fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        Sema &S = unit->getSema();
8928fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        CodeCompletionAllocator *Allocator
8938fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor          = unit->getCursorCompletionAllocator().getPtr();
8948fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        CodeCompletionResult Result(namedDecl);
8958fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        CodeCompletionString *String
8968fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor          = Result.CreateCodeCompletionString(S, *Allocator);
8978fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        return String;
8988fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      }
8998fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    }
9008fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor  }
9018fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor  else if (kind == CXCursor_MacroDefinition) {
9028fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    MacroDefinition *definition = getCursorMacroDefinition(cursor);
9038fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    const IdentifierInfo *MacroInfo = definition->getName();
9048fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    ASTUnit *unit = getCursorASTUnit(cursor);
9058fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    if (unit->hasSema()) {
9068fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      Sema &S = unit->getSema();
9078fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      CodeCompletionAllocator *Allocator
9088fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        = unit->getCursorCompletionAllocator().getPtr();
909eaf4fbab08b2636103b2da08412e33baff15ad2aDouglas Gregor      CodeCompletionResult Result(const_cast<IdentifierInfo *>(MacroInfo));
9108fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      CodeCompletionString *String
9118fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor        = Result.CreateCodeCompletionString(S, *Allocator);
9128fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor      return String;
9138fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor    }
9148fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor  }
9158fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor  return NULL;
9168fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor}
9178fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor
918eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} // end: extern "C"
919