Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 1 | //===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Clang-C Source Indexing library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang-c/Index.h" |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 15 | #include "clang/Index/Program.h" |
| 16 | #include "clang/Index/Indexer.h" |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 17 | #include "clang/Index/ASTLocation.h" |
| 18 | #include "clang/Index/Utils.h" |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclVisitor.h" |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 20 | #include "clang/AST/StmtVisitor.h" |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 21 | #include "clang/AST/Decl.h" |
Benjamin Kramer | d01a0bc | 2009-08-29 12:56:35 +0000 | [diff] [blame] | 22 | #include "clang/Basic/FileManager.h" |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 23 | #include "clang/Basic/SourceManager.h" |
Benjamin Kramer | d01a0bc | 2009-08-29 12:56:35 +0000 | [diff] [blame] | 24 | #include "clang/Frontend/ASTUnit.h" |
| 25 | #include <cstdio> |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 26 | using namespace clang; |
| 27 | using namespace idx; |
| 28 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 31 | class CRefVisitor : public StmtVisitor<CRefVisitor> { |
| 32 | CXDecl CDecl; |
| 33 | CXDeclIterator Callback; |
| 34 | CXClientData CData; |
| 35 | |
| 36 | void Call(enum CXCursorKind CK, Stmt *SRef) { |
| 37 | CXCursor C = { CK, CDecl, SRef }; |
| 38 | Callback(CDecl, C, CData); |
| 39 | } |
| 40 | |
| 41 | public: |
| 42 | CRefVisitor(CXDecl C, CXDeclIterator cback, CXClientData D) : |
| 43 | CDecl(C), Callback(cback), CData(D) {} |
| 44 | |
| 45 | void VisitStmt(Stmt *S) { |
| 46 | for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end(); |
| 47 | C != CEnd; ++C) |
| 48 | Visit(*C); |
| 49 | } |
| 50 | void VisitDeclRefExpr(DeclRefExpr *Node) { |
| 51 | NamedDecl *D = Node->getDecl(); |
| 52 | if (isa<VarDecl>(D)) |
| 53 | Call(CXCursor_VarRef, Node); |
| 54 | else if (isa<FunctionDecl>(D)) |
| 55 | Call(CXCursor_FunctionRef, Node); |
| 56 | else if (isa<EnumConstantDecl>(D)) |
| 57 | Call(CXCursor_EnumConstantRef, Node); |
| 58 | } |
| 59 | void VisitMemberExpr(MemberExpr *Node) { |
| 60 | Call(CXCursor_MemberRef, Node); |
| 61 | } |
| 62 | void VisitObjCMessageExpr(ObjCMessageExpr *Node) { |
| 63 | Call(CXCursor_ObjCSelectorRef, Node); |
| 64 | } |
| 65 | void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { |
| 66 | Call(CXCursor_ObjCIvarRef, Node); |
| 67 | } |
| 68 | }; |
| 69 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 70 | // Translation Unit Visitor. |
| 71 | class TUVisitor : public DeclVisitor<TUVisitor> { |
| 72 | CXTranslationUnit TUnit; |
| 73 | CXTranslationUnitIterator Callback; |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 74 | CXClientData CData; |
| 75 | |
| 76 | void Call(enum CXCursorKind CK, NamedDecl *ND) { |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 77 | CXCursor C = { CK, ND, 0 }; |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 78 | Callback(TUnit, C, CData); |
| 79 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 80 | public: |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 81 | TUVisitor(CXTranslationUnit CTU, |
| 82 | CXTranslationUnitIterator cback, CXClientData D) : |
| 83 | TUnit(CTU), Callback(cback), CData(D) {} |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 84 | |
| 85 | void VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 86 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 87 | } |
| 88 | void VisitDeclContext(DeclContext *DC) { |
| 89 | for (DeclContext::decl_iterator |
| 90 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) |
| 91 | Visit(*I); |
| 92 | } |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 93 | void VisitTypedefDecl(TypedefDecl *ND) { |
| 94 | Call(CXCursor_TypedefDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 95 | } |
| 96 | void VisitTagDecl(TagDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 97 | switch (ND->getTagKind()) { |
| 98 | case TagDecl::TK_struct: |
| 99 | Call(CXCursor_StructDecl, ND); |
| 100 | break; |
| 101 | case TagDecl::TK_class: |
| 102 | Call(CXCursor_ClassDecl, ND); |
| 103 | break; |
| 104 | case TagDecl::TK_union: |
| 105 | Call(CXCursor_UnionDecl, ND); |
| 106 | break; |
| 107 | case TagDecl::TK_enum: |
| 108 | Call(CXCursor_EnumDecl, ND); |
| 109 | break; |
| 110 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 111 | } |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 112 | void VisitVarDecl(VarDecl *ND) { |
| 113 | Call(CXCursor_VarDecl, ND); |
| 114 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 115 | void VisitFunctionDecl(FunctionDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 116 | Call(ND->isThisDeclarationADefinition() ? CXCursor_FunctionDefn |
| 117 | : CXCursor_FunctionDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 118 | } |
| 119 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *ND) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 120 | Call(CXCursor_ObjCInterfaceDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 121 | } |
| 122 | void VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 123 | Call(CXCursor_ObjCCategoryDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 124 | } |
| 125 | void VisitObjCProtocolDecl(ObjCProtocolDecl *ND) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 126 | Call(CXCursor_ObjCProtocolDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 127 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 128 | void VisitObjCImplementationDecl(ObjCImplementationDecl *ND) { |
| 129 | Call(CXCursor_ObjCClassDefn, ND); |
| 130 | } |
| 131 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *ND) { |
| 132 | Call(CXCursor_ObjCCategoryDefn, ND); |
| 133 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 136 | // Declaration visitor. |
| 137 | class CDeclVisitor : public DeclVisitor<CDeclVisitor> { |
| 138 | CXDecl CDecl; |
| 139 | CXDeclIterator Callback; |
| 140 | CXClientData CData; |
| 141 | |
| 142 | void Call(enum CXCursorKind CK, NamedDecl *ND) { |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 143 | // Disable the callback when the context is equal to the visiting decl. |
| 144 | if (CDecl == ND && !clang_isReference(CK)) |
| 145 | return; |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 146 | CXCursor C = { CK, ND, 0 }; |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 147 | Callback(CDecl, C, CData); |
| 148 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 149 | public: |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 150 | CDeclVisitor(CXDecl C, CXDeclIterator cback, CXClientData D) : |
| 151 | CDecl(C), Callback(cback), CData(D) {} |
| 152 | |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 153 | void VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { |
| 154 | // Issue callbacks for the containing class. |
| 155 | Call(CXCursor_ObjCClassRef, ND); |
| 156 | // FIXME: Issue callbacks for protocol refs. |
| 157 | VisitDeclContext(dyn_cast<DeclContext>(ND)); |
| 158 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 159 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 160 | // Issue callbacks for super class. |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 161 | if (D->getSuperClass()) |
| 162 | Call(CXCursor_ObjCSuperClassRef, D); |
| 163 | |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 164 | for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(), |
| 165 | E = D->protocol_end(); I != E; ++I) |
| 166 | Call(CXCursor_ObjCProtocolRef, *I); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 167 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 168 | } |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 169 | void VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { |
| 170 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
| 171 | E = PID->protocol_end(); I != E; ++I) |
| 172 | Call(CXCursor_ObjCProtocolRef, *I); |
| 173 | |
| 174 | VisitDeclContext(dyn_cast<DeclContext>(PID)); |
| 175 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 176 | void VisitTagDecl(TagDecl *D) { |
| 177 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 178 | } |
| 179 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 180 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 181 | } |
| 182 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 183 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 184 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 185 | void VisitDeclContext(DeclContext *DC) { |
| 186 | for (DeclContext::decl_iterator |
| 187 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) |
| 188 | Visit(*I); |
| 189 | } |
| 190 | void VisitEnumConstantDecl(EnumConstantDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 191 | Call(CXCursor_EnumConstantDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 192 | } |
| 193 | void VisitFieldDecl(FieldDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 194 | Call(CXCursor_FieldDecl, ND); |
| 195 | } |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 196 | void VisitVarDecl(VarDecl *ND) { |
| 197 | Call(CXCursor_VarDecl, ND); |
| 198 | } |
| 199 | void VisitParmVarDecl(ParmVarDecl *ND) { |
| 200 | Call(CXCursor_ParmDecl, ND); |
| 201 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 202 | void VisitObjCPropertyDecl(ObjCPropertyDecl *ND) { |
| 203 | Call(CXCursor_ObjCPropertyDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 204 | } |
| 205 | void VisitObjCIvarDecl(ObjCIvarDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 206 | Call(CXCursor_ObjCIvarDecl, ND); |
| 207 | } |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 208 | void VisitFunctionDecl(FunctionDecl *ND) { |
| 209 | if (ND->isThisDeclarationADefinition()) { |
| 210 | VisitDeclContext(dyn_cast<DeclContext>(ND)); |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 211 | |
| 212 | CRefVisitor RVisit(CDecl, Callback, CData); |
| 213 | RVisit.Visit(ND->getBody()); |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 216 | void VisitObjCMethodDecl(ObjCMethodDecl *ND) { |
| 217 | if (ND->getBody()) { |
| 218 | Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDefn |
| 219 | : CXCursor_ObjCClassMethodDefn, ND); |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 220 | VisitDeclContext(dyn_cast<DeclContext>(ND)); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 221 | } else |
| 222 | Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDecl |
| 223 | : CXCursor_ObjCClassMethodDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 224 | } |
| 225 | }; |
| 226 | |
| 227 | } |
| 228 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 229 | extern "C" { |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 230 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 231 | CXIndex clang_createIndex() |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 232 | { |
Daniel Dunbar | a390759 | 2009-09-21 03:03:22 +0000 | [diff] [blame] | 233 | // FIXME: Program is leaked. |
| 234 | return new Indexer(*new Program()); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Steve Naroff | 2bd6b9f | 2009-09-17 18:33:27 +0000 | [diff] [blame] | 237 | void clang_disposeIndex(CXIndex CIdx) |
| 238 | { |
| 239 | assert(CIdx && "Passed null CXIndex"); |
| 240 | delete static_cast<Indexer *>(CIdx); |
| 241 | } |
| 242 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 243 | // FIXME: need to pass back error info. |
| 244 | CXTranslationUnit clang_createTranslationUnit( |
| 245 | CXIndex CIdx, const char *ast_filename) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 246 | { |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 247 | assert(CIdx && "Passed null CXIndex"); |
| 248 | Indexer *CXXIdx = static_cast<Indexer *>(CIdx); |
| 249 | std::string astName(ast_filename); |
| 250 | std::string ErrMsg; |
| 251 | |
Daniel Dunbar | 31b87d8 | 2009-09-21 03:03:39 +0000 | [diff] [blame] | 252 | return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getDiagnostics(), |
| 253 | CXXIdx->getFileManager(), &ErrMsg); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Steve Naroff | 2bd6b9f | 2009-09-17 18:33:27 +0000 | [diff] [blame] | 256 | void clang_disposeTranslationUnit( |
| 257 | CXTranslationUnit CTUnit) |
| 258 | { |
| 259 | assert(CTUnit && "Passed null CXTranslationUnit"); |
| 260 | delete static_cast<ASTUnit *>(CTUnit); |
| 261 | } |
| 262 | |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 263 | const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) |
| 264 | { |
| 265 | assert(CTUnit && "Passed null CXTranslationUnit"); |
Steve Naroff | 77accc1 | 2009-09-03 18:19:54 +0000 | [diff] [blame] | 266 | ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit); |
| 267 | return CXXUnit->getOriginalSourceFileName().c_str(); |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 268 | } |
Daniel Dunbar | 1eb79b5 | 2009-08-28 16:30:07 +0000 | [diff] [blame] | 269 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 270 | void clang_loadTranslationUnit(CXTranslationUnit CTUnit, |
| 271 | CXTranslationUnitIterator callback, |
| 272 | CXClientData CData) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 273 | { |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 274 | assert(CTUnit && "Passed null CXTranslationUnit"); |
| 275 | ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit); |
| 276 | ASTContext &Ctx = CXXUnit->getASTContext(); |
| 277 | |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 278 | TUVisitor DVisit(CTUnit, callback, CData); |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 279 | DVisit.Visit(Ctx.getTranslationUnitDecl()); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 282 | void clang_loadDeclaration(CXDecl Dcl, |
| 283 | CXDeclIterator callback, |
| 284 | CXClientData CData) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 285 | { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 286 | assert(Dcl && "Passed null CXDecl"); |
| 287 | |
| 288 | CDeclVisitor DVisit(Dcl, callback, CData); |
| 289 | DVisit.Visit(static_cast<Decl *>(Dcl)); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Steve Naroff | 7e8f818 | 2009-08-28 12:07:44 +0000 | [diff] [blame] | 292 | // Some notes on CXEntity: |
| 293 | // |
| 294 | // - Since the 'ordinary' namespace includes functions, data, typedefs, |
| 295 | // ObjC interfaces, thecurrent algorithm is a bit naive (resulting in one |
| 296 | // entity for 2 different types). For example: |
| 297 | // |
| 298 | // module1.m: @interface Foo @end Foo *x; |
| 299 | // module2.m: void Foo(int); |
| 300 | // |
| 301 | // - Since the unique name spans translation units, static data/functions |
| 302 | // within a CXTranslationUnit are *not* currently represented by entities. |
| 303 | // As a result, there will be no entity for the following: |
| 304 | // |
| 305 | // module.m: static void Foo() { } |
| 306 | // |
| 307 | |
| 308 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 309 | const char *clang_getDeclarationName(CXEntity) |
| 310 | { |
| 311 | return ""; |
| 312 | } |
| 313 | const char *clang_getURI(CXEntity) |
| 314 | { |
| 315 | return ""; |
| 316 | } |
| 317 | |
| 318 | CXEntity clang_getEntity(const char *URI) |
| 319 | { |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | // |
| 324 | // CXDecl Operations. |
| 325 | // |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 326 | CXEntity clang_getEntityFromDecl(CXDecl) |
| 327 | { |
| 328 | return 0; |
| 329 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 330 | const char *clang_getDeclSpelling(CXDecl AnonDecl) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 331 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 332 | assert(AnonDecl && "Passed null CXDecl"); |
| 333 | NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 334 | |
| 335 | if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) { |
| 336 | return OMD->getSelector().getAsString().c_str(); |
| 337 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 338 | if (ND->getIdentifier()) |
| 339 | return ND->getIdentifier()->getName(); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 340 | else |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 341 | return ""; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 342 | } |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 343 | |
| 344 | const char *clang_getCursorSpelling(CXCursor C) |
| 345 | { |
| 346 | assert(C.decl && "CXCursor has null decl"); |
| 347 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
| 348 | |
| 349 | if (clang_isReference(C.kind)) { |
| 350 | switch (C.kind) { |
Steve Naroff | 1164d85 | 2009-09-02 18:58:52 +0000 | [diff] [blame] | 351 | case CXCursor_ObjCSuperClassRef: |
| 352 | { |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 353 | ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND); |
| 354 | assert(OID && "clang_getCursorLine(): Missing interface decl"); |
| 355 | return OID->getSuperClass()->getIdentifier()->getName(); |
Steve Naroff | 1164d85 | 2009-09-02 18:58:52 +0000 | [diff] [blame] | 356 | } |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 357 | case CXCursor_ObjCClassRef: |
| 358 | { |
| 359 | ObjCCategoryDecl *OID = dyn_cast<ObjCCategoryDecl>(ND); |
| 360 | assert(OID && "clang_getCursorLine(): Missing category decl"); |
| 361 | return OID->getClassInterface()->getIdentifier()->getName(); |
| 362 | } |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 363 | case CXCursor_ObjCProtocolRef: |
| 364 | { |
| 365 | ObjCProtocolDecl *OID = dyn_cast<ObjCProtocolDecl>(ND); |
| 366 | assert(OID && "clang_getCursorLine(): Missing protocol decl"); |
| 367 | return OID->getIdentifier()->getName(); |
| 368 | } |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 369 | case CXCursor_ObjCSelectorRef: |
| 370 | { |
| 371 | ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>( |
| 372 | static_cast<Stmt *>(C.stmt)); |
| 373 | assert(OME && "clang_getCursorLine(): Missing message expr"); |
| 374 | return OME->getSelector().getAsString().c_str(); |
| 375 | } |
| 376 | case CXCursor_VarRef: |
| 377 | case CXCursor_FunctionRef: |
| 378 | case CXCursor_EnumConstantRef: |
| 379 | { |
| 380 | DeclRefExpr *DRE = dyn_cast<DeclRefExpr>( |
| 381 | static_cast<Stmt *>(C.stmt)); |
| 382 | assert(DRE && "clang_getCursorLine(): Missing decl ref expr"); |
| 383 | return DRE->getDecl()->getIdentifier()->getName(); |
| 384 | } |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 385 | default: |
| 386 | return "<not implemented>"; |
| 387 | } |
| 388 | } |
| 389 | return clang_getDeclSpelling(C.decl); |
| 390 | } |
| 391 | |
| 392 | const char *clang_getCursorKindSpelling(enum CXCursorKind Kind) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 393 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 394 | switch (Kind) { |
| 395 | case CXCursor_FunctionDecl: return "FunctionDecl"; |
| 396 | case CXCursor_TypedefDecl: return "TypedefDecl"; |
| 397 | case CXCursor_EnumDecl: return "EnumDecl"; |
| 398 | case CXCursor_EnumConstantDecl: return "EnumConstantDecl"; |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 399 | case CXCursor_StructDecl: return "StructDecl"; |
| 400 | case CXCursor_UnionDecl: return "UnionDecl"; |
| 401 | case CXCursor_ClassDecl: return "ClassDecl"; |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 402 | case CXCursor_FieldDecl: return "FieldDecl"; |
| 403 | case CXCursor_VarDecl: return "VarDecl"; |
| 404 | case CXCursor_ParmDecl: return "ParmDecl"; |
| 405 | case CXCursor_ObjCInterfaceDecl: return "ObjCInterfaceDecl"; |
| 406 | case CXCursor_ObjCCategoryDecl: return "ObjCCategoryDecl"; |
| 407 | case CXCursor_ObjCProtocolDecl: return "ObjCProtocolDecl"; |
| 408 | case CXCursor_ObjCPropertyDecl: return "ObjCPropertyDecl"; |
| 409 | case CXCursor_ObjCIvarDecl: return "ObjCIvarDecl"; |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 410 | case CXCursor_ObjCInstanceMethodDecl: return "ObjCInstanceMethodDecl"; |
| 411 | case CXCursor_ObjCClassMethodDecl: return "ObjCClassMethodDecl"; |
| 412 | case CXCursor_FunctionDefn: return "FunctionDefn"; |
| 413 | case CXCursor_ObjCInstanceMethodDefn: return "ObjCInstanceMethodDefn"; |
| 414 | case CXCursor_ObjCClassMethodDefn: return "ObjCClassMethodDefn"; |
| 415 | case CXCursor_ObjCClassDefn: return "ObjCClassDefn"; |
| 416 | case CXCursor_ObjCCategoryDefn: return "ObjCCategoryDefn"; |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 417 | case CXCursor_ObjCSuperClassRef: return "ObjCSuperClassRef"; |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 418 | case CXCursor_ObjCProtocolRef: return "ObjCProtocolRef"; |
Steve Naroff | af08ddc | 2009-09-03 15:49:00 +0000 | [diff] [blame] | 419 | case CXCursor_ObjCClassRef: return "ObjCClassRef"; |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 420 | case CXCursor_ObjCSelectorRef: return "ObjCSelectorRef"; |
| 421 | |
| 422 | case CXCursor_VarRef: return "VarRef"; |
| 423 | case CXCursor_FunctionRef: return "FunctionRef"; |
| 424 | case CXCursor_EnumConstantRef: return "EnumConstantRef"; |
| 425 | case CXCursor_MemberRef: return "MemberRef"; |
| 426 | |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 427 | case CXCursor_InvalidFile: return "InvalidFile"; |
| 428 | case CXCursor_NoDeclFound: return "NoDeclFound"; |
| 429 | case CXCursor_NotImplemented: return "NotImplemented"; |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 430 | default: return "<not implemented>"; |
| 431 | } |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 432 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 433 | |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 434 | static enum CXCursorKind TranslateKind(Decl *D) { |
| 435 | switch (D->getKind()) { |
| 436 | case Decl::Function: return CXCursor_FunctionDecl; |
| 437 | case Decl::Typedef: return CXCursor_TypedefDecl; |
| 438 | case Decl::Enum: return CXCursor_EnumDecl; |
| 439 | case Decl::EnumConstant: return CXCursor_EnumConstantDecl; |
| 440 | case Decl::Record: return CXCursor_StructDecl; // FIXME: union/class |
| 441 | case Decl::Field: return CXCursor_FieldDecl; |
| 442 | case Decl::Var: return CXCursor_VarDecl; |
| 443 | case Decl::ParmVar: return CXCursor_ParmDecl; |
| 444 | case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl; |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 445 | case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl; |
| 446 | case Decl::ObjCProtocol: return CXCursor_ObjCProtocolDecl; |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 447 | case Decl::ObjCMethod: { |
| 448 | ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D); |
| 449 | if (MD->isInstanceMethod()) |
| 450 | return CXCursor_ObjCInstanceMethodDecl; |
| 451 | return CXCursor_ObjCClassMethodDecl; |
| 452 | } |
| 453 | default: break; |
| 454 | } |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 455 | return CXCursor_NotImplemented; |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 456 | } |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 457 | // |
| 458 | // CXCursor Operations. |
| 459 | // |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 460 | CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name, |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 461 | unsigned line, unsigned column) |
| 462 | { |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 463 | assert(CTUnit && "Passed null CXTranslationUnit"); |
| 464 | ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit); |
| 465 | |
| 466 | FileManager &FMgr = CXXUnit->getFileManager(); |
| 467 | const FileEntry *File = FMgr.getFile(source_name, |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 468 | source_name+strlen(source_name)); |
| 469 | if (!File) { |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 470 | CXCursor C = { CXCursor_InvalidFile, 0, 0 }; |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 471 | return C; |
| 472 | } |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 473 | SourceLocation SLoc = |
| 474 | CXXUnit->getSourceManager().getLocation(File, line, column); |
| 475 | |
| 476 | ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc); |
| 477 | |
| 478 | Decl *Dcl = ALoc.getDecl(); |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 479 | if (Dcl) { |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 480 | CXCursor C = { TranslateKind(Dcl), Dcl, 0 }; |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 481 | return C; |
| 482 | } |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 483 | CXCursor C = { CXCursor_NoDeclFound, 0, 0 }; |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 484 | return C; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 487 | CXCursor clang_getCursorFromDecl(CXDecl AnonDecl) |
| 488 | { |
| 489 | assert(AnonDecl && "Passed null CXDecl"); |
| 490 | NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl); |
| 491 | |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 492 | CXCursor C = { TranslateKind(ND), ND, 0 }; |
Steve Naroff | 77128dd | 2009-09-15 20:25:34 +0000 | [diff] [blame] | 493 | return C; |
| 494 | } |
| 495 | |
| 496 | unsigned clang_isInvalid(enum CXCursorKind K) |
| 497 | { |
| 498 | return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid; |
| 499 | } |
| 500 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 501 | unsigned clang_isDeclaration(enum CXCursorKind K) |
| 502 | { |
| 503 | return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl; |
| 504 | } |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 505 | |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 506 | unsigned clang_isReference(enum CXCursorKind K) |
| 507 | { |
| 508 | return K >= CXCursor_FirstRef && K <= CXCursor_LastRef; |
| 509 | } |
| 510 | |
| 511 | unsigned clang_isDefinition(enum CXCursorKind K) |
| 512 | { |
| 513 | return K >= CXCursor_FirstDefn && K <= CXCursor_LastDefn; |
| 514 | } |
| 515 | |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 516 | CXCursorKind clang_getCursorKind(CXCursor C) |
| 517 | { |
| 518 | return C.kind; |
| 519 | } |
| 520 | |
| 521 | CXDecl clang_getCursorDecl(CXCursor C) |
| 522 | { |
| 523 | return C.decl; |
| 524 | } |
| 525 | |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 526 | static SourceLocation getLocationFromCursor(CXCursor C, |
| 527 | SourceManager &SourceMgr, |
| 528 | NamedDecl *ND) { |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 529 | if (clang_isReference(C.kind)) { |
| 530 | switch (C.kind) { |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 531 | case CXCursor_ObjCSuperClassRef: |
Steve Naroff | 1164d85 | 2009-09-02 18:58:52 +0000 | [diff] [blame] | 532 | { |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 533 | ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND); |
| 534 | assert(OID && "clang_getCursorLine(): Missing interface decl"); |
Steve Naroff | 1164d85 | 2009-09-02 18:58:52 +0000 | [diff] [blame] | 535 | return OID->getSuperClassLoc(); |
| 536 | } |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 537 | case CXCursor_ObjCProtocolRef: |
| 538 | { |
| 539 | ObjCProtocolDecl *OID = dyn_cast<ObjCProtocolDecl>(ND); |
| 540 | assert(OID && "clang_getCursorLine(): Missing protocol decl"); |
| 541 | return OID->getLocation(); |
| 542 | } |
Steve Naroff | fb57042 | 2009-09-22 19:25:29 +0000 | [diff] [blame] | 543 | case CXCursor_ObjCSelectorRef: |
| 544 | { |
| 545 | ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>( |
| 546 | static_cast<Stmt *>(C.stmt)); |
| 547 | assert(OME && "clang_getCursorLine(): Missing message expr"); |
| 548 | return OME->getLeftLoc(); /* FIXME: should be a range */ |
| 549 | } |
| 550 | case CXCursor_VarRef: |
| 551 | case CXCursor_FunctionRef: |
| 552 | case CXCursor_EnumConstantRef: |
| 553 | { |
| 554 | DeclRefExpr *DRE = dyn_cast<DeclRefExpr>( |
| 555 | static_cast<Stmt *>(C.stmt)); |
| 556 | assert(DRE && "clang_getCursorLine(): Missing decl ref expr"); |
| 557 | return DRE->getLocation(); |
| 558 | } |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 559 | default: |
Steve Naroff | 1164d85 | 2009-09-02 18:58:52 +0000 | [diff] [blame] | 560 | return SourceLocation(); |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 561 | } |
| 562 | } else { // We have a declaration or a definition. |
Steve Naroff | 9efa767 | 2009-09-04 15:44:05 +0000 | [diff] [blame] | 563 | SourceLocation SLoc; |
| 564 | switch (ND->getKind()) { |
| 565 | case Decl::ObjCInterface: |
| 566 | { |
| 567 | SLoc = dyn_cast<ObjCInterfaceDecl>(ND)->getClassLoc(); |
| 568 | break; |
| 569 | } |
| 570 | case Decl::ObjCProtocol: |
| 571 | { |
| 572 | SLoc = ND->getLocation(); /* FIXME: need to get the name location. */ |
| 573 | break; |
| 574 | } |
| 575 | default: |
| 576 | { |
| 577 | SLoc = ND->getLocation(); |
| 578 | break; |
| 579 | } |
| 580 | } |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 581 | if (SLoc.isInvalid()) |
| 582 | return SourceLocation(); |
Steve Naroff | 1164d85 | 2009-09-02 18:58:52 +0000 | [diff] [blame] | 583 | return SourceMgr.getSpellingLoc(SLoc); // handles macro instantiations. |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 584 | } |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 587 | unsigned clang_getCursorLine(CXCursor C) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 588 | { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 589 | assert(C.decl && "CXCursor has null decl"); |
| 590 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 591 | SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 592 | |
| 593 | SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 594 | return SourceMgr.getSpellingLineNumber(SLoc); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 595 | } |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 596 | |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 597 | unsigned clang_getCursorColumn(CXCursor C) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 598 | { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 599 | assert(C.decl && "CXCursor has null decl"); |
| 600 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 601 | SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 602 | |
| 603 | SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 604 | return SourceMgr.getSpellingColumnNumber(SLoc); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 605 | } |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 606 | const char *clang_getCursorSource(CXCursor C) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 607 | { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 608 | assert(C.decl && "CXCursor has null decl"); |
| 609 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 610 | SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); |
Steve Naroff | f334b4e | 2009-09-02 18:26:48 +0000 | [diff] [blame] | 611 | |
| 612 | SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND); |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 613 | return SourceMgr.getBufferName(SLoc); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 616 | } // end extern "C" |