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 | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclVisitor.h" |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Benjamin Kramer | d01a0bc | 2009-08-29 12:56:35 +0000 | [diff] [blame] | 19 | #include "clang/Basic/FileManager.h" |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 20 | #include "clang/Basic/SourceManager.h" |
Benjamin Kramer | d01a0bc | 2009-08-29 12:56:35 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/ASTUnit.h" |
| 22 | #include <cstdio> |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | using namespace idx; |
| 25 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 26 | namespace { |
| 27 | |
| 28 | // Translation Unit Visitor. |
| 29 | class TUVisitor : public DeclVisitor<TUVisitor> { |
| 30 | CXTranslationUnit TUnit; |
| 31 | CXTranslationUnitIterator Callback; |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 32 | CXClientData CData; |
| 33 | |
| 34 | void Call(enum CXCursorKind CK, NamedDecl *ND) { |
| 35 | CXCursor C = { CK, ND }; |
| 36 | Callback(TUnit, C, CData); |
| 37 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 38 | public: |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 39 | TUVisitor(CXTranslationUnit CTU, |
| 40 | CXTranslationUnitIterator cback, CXClientData D) : |
| 41 | TUnit(CTU), Callback(cback), CData(D) {} |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 42 | |
| 43 | void VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 44 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 45 | } |
| 46 | void VisitDeclContext(DeclContext *DC) { |
| 47 | for (DeclContext::decl_iterator |
| 48 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) |
| 49 | Visit(*I); |
| 50 | } |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 51 | void VisitTypedefDecl(TypedefDecl *ND) { |
| 52 | Call(CXCursor_TypedefDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 53 | } |
| 54 | void VisitTagDecl(TagDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 55 | switch (ND->getTagKind()) { |
| 56 | case TagDecl::TK_struct: |
| 57 | Call(CXCursor_StructDecl, ND); |
| 58 | break; |
| 59 | case TagDecl::TK_class: |
| 60 | Call(CXCursor_ClassDecl, ND); |
| 61 | break; |
| 62 | case TagDecl::TK_union: |
| 63 | Call(CXCursor_UnionDecl, ND); |
| 64 | break; |
| 65 | case TagDecl::TK_enum: |
| 66 | Call(CXCursor_EnumDecl, ND); |
| 67 | break; |
| 68 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 69 | } |
| 70 | void VisitFunctionDecl(FunctionDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 71 | Call(ND->isThisDeclarationADefinition() ? CXCursor_FunctionDefn |
| 72 | : CXCursor_FunctionDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 73 | } |
| 74 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *ND) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 75 | Call(CXCursor_ObjCInterfaceDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 76 | } |
| 77 | void VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 78 | Call(CXCursor_ObjCCategoryDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 79 | } |
| 80 | void VisitObjCProtocolDecl(ObjCProtocolDecl *ND) { |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 81 | Call(CXCursor_ObjCProtocolDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 82 | } |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 83 | void VisitObjCImplementationDecl(ObjCImplementationDecl *ND) { |
| 84 | Call(CXCursor_ObjCClassDefn, ND); |
| 85 | } |
| 86 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *ND) { |
| 87 | Call(CXCursor_ObjCCategoryDefn, ND); |
| 88 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 91 | // Declaration visitor. |
| 92 | class CDeclVisitor : public DeclVisitor<CDeclVisitor> { |
| 93 | CXDecl CDecl; |
| 94 | CXDeclIterator Callback; |
| 95 | CXClientData CData; |
| 96 | |
| 97 | void Call(enum CXCursorKind CK, NamedDecl *ND) { |
| 98 | CXCursor C = { CK, ND }; |
| 99 | Callback(CDecl, C, CData); |
| 100 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 101 | public: |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 102 | CDeclVisitor(CXDecl C, CXDeclIterator cback, CXClientData D) : |
| 103 | CDecl(C), Callback(cback), CData(D) {} |
| 104 | |
| 105 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| 106 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 107 | } |
| 108 | void VisitTagDecl(TagDecl *D) { |
| 109 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 110 | } |
| 111 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 112 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 113 | } |
| 114 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 115 | VisitDeclContext(dyn_cast<DeclContext>(D)); |
| 116 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 117 | void VisitDeclContext(DeclContext *DC) { |
| 118 | for (DeclContext::decl_iterator |
| 119 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) |
| 120 | Visit(*I); |
| 121 | } |
| 122 | void VisitEnumConstantDecl(EnumConstantDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 123 | Call(CXCursor_EnumConstantDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 124 | } |
| 125 | void VisitFieldDecl(FieldDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 126 | Call(CXCursor_FieldDecl, ND); |
| 127 | } |
| 128 | void VisitObjCPropertyDecl(ObjCPropertyDecl *ND) { |
| 129 | Call(CXCursor_ObjCPropertyDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 130 | } |
| 131 | void VisitObjCIvarDecl(ObjCIvarDecl *ND) { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 132 | Call(CXCursor_ObjCIvarDecl, ND); |
| 133 | } |
| 134 | void VisitObjCMethodDecl(ObjCMethodDecl *ND) { |
| 135 | if (ND->getBody()) { |
| 136 | Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDefn |
| 137 | : CXCursor_ObjCClassMethodDefn, ND); |
| 138 | // FIXME: load body. |
| 139 | } else |
| 140 | Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDecl |
| 141 | : CXCursor_ObjCClassMethodDecl, ND); |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 142 | } |
| 143 | }; |
| 144 | |
| 145 | } |
| 146 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 147 | extern "C" { |
Ted Kremenek | d2fa566 | 2009-08-26 22:36:44 +0000 | [diff] [blame] | 148 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 149 | CXIndex clang_createIndex() |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 150 | { |
| 151 | return new Indexer(*new Program(), *new FileManager()); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 154 | // FIXME: need to pass back error info. |
| 155 | CXTranslationUnit clang_createTranslationUnit( |
| 156 | CXIndex CIdx, const char *ast_filename) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 157 | { |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 158 | assert(CIdx && "Passed null CXIndex"); |
| 159 | Indexer *CXXIdx = static_cast<Indexer *>(CIdx); |
| 160 | std::string astName(ast_filename); |
| 161 | std::string ErrMsg; |
| 162 | |
| 163 | return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Daniel Dunbar | 1eb79b5 | 2009-08-28 16:30:07 +0000 | [diff] [blame] | 166 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 167 | void clang_loadTranslationUnit(CXTranslationUnit CTUnit, |
| 168 | CXTranslationUnitIterator callback, |
| 169 | CXClientData CData) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 170 | { |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 171 | assert(CTUnit && "Passed null CXTranslationUnit"); |
| 172 | ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit); |
| 173 | ASTContext &Ctx = CXXUnit->getASTContext(); |
| 174 | |
Steve Naroff | 2b8ee6c | 2009-09-01 15:55:40 +0000 | [diff] [blame] | 175 | TUVisitor DVisit(CTUnit, callback, CData); |
Steve Naroff | 5039819 | 2009-08-28 15:28:48 +0000 | [diff] [blame] | 176 | DVisit.Visit(Ctx.getTranslationUnitDecl()); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 179 | void clang_loadDeclaration(CXDecl Dcl, |
| 180 | CXDeclIterator callback, |
| 181 | CXClientData CData) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 182 | { |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 183 | assert(Dcl && "Passed null CXDecl"); |
| 184 | |
| 185 | CDeclVisitor DVisit(Dcl, callback, CData); |
| 186 | DVisit.Visit(static_cast<Decl *>(Dcl)); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Steve Naroff | 7e8f818 | 2009-08-28 12:07:44 +0000 | [diff] [blame] | 189 | // Some notes on CXEntity: |
| 190 | // |
| 191 | // - Since the 'ordinary' namespace includes functions, data, typedefs, |
| 192 | // ObjC interfaces, thecurrent algorithm is a bit naive (resulting in one |
| 193 | // entity for 2 different types). For example: |
| 194 | // |
| 195 | // module1.m: @interface Foo @end Foo *x; |
| 196 | // module2.m: void Foo(int); |
| 197 | // |
| 198 | // - Since the unique name spans translation units, static data/functions |
| 199 | // within a CXTranslationUnit are *not* currently represented by entities. |
| 200 | // As a result, there will be no entity for the following: |
| 201 | // |
| 202 | // module.m: static void Foo() { } |
| 203 | // |
| 204 | |
| 205 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 206 | const char *clang_getDeclarationName(CXEntity) |
| 207 | { |
| 208 | return ""; |
| 209 | } |
| 210 | const char *clang_getURI(CXEntity) |
| 211 | { |
| 212 | return ""; |
| 213 | } |
| 214 | |
| 215 | CXEntity clang_getEntity(const char *URI) |
| 216 | { |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | // |
| 221 | // CXDecl Operations. |
| 222 | // |
| 223 | CXCursor clang_getCursorFromDecl(CXDecl) |
| 224 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 225 | return CXCursor(); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 226 | } |
| 227 | CXEntity clang_getEntityFromDecl(CXDecl) |
| 228 | { |
| 229 | return 0; |
| 230 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 231 | const char *clang_getDeclSpelling(CXDecl AnonDecl) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 232 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 233 | assert(AnonDecl && "Passed null CXDecl"); |
| 234 | NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 235 | |
| 236 | if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) { |
| 237 | return OMD->getSelector().getAsString().c_str(); |
| 238 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 239 | if (ND->getIdentifier()) |
| 240 | return ND->getIdentifier()->getName(); |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 241 | else |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 242 | return ""; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 243 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 244 | const char *clang_getKindSpelling(enum CXCursorKind Kind) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 245 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 246 | switch (Kind) { |
| 247 | case CXCursor_FunctionDecl: return "FunctionDecl"; |
| 248 | case CXCursor_TypedefDecl: return "TypedefDecl"; |
| 249 | case CXCursor_EnumDecl: return "EnumDecl"; |
| 250 | case CXCursor_EnumConstantDecl: return "EnumConstantDecl"; |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 251 | case CXCursor_StructDecl: return "StructDecl"; |
| 252 | case CXCursor_UnionDecl: return "UnionDecl"; |
| 253 | case CXCursor_ClassDecl: return "ClassDecl"; |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 254 | case CXCursor_FieldDecl: return "FieldDecl"; |
| 255 | case CXCursor_VarDecl: return "VarDecl"; |
| 256 | case CXCursor_ParmDecl: return "ParmDecl"; |
| 257 | case CXCursor_ObjCInterfaceDecl: return "ObjCInterfaceDecl"; |
| 258 | case CXCursor_ObjCCategoryDecl: return "ObjCCategoryDecl"; |
| 259 | case CXCursor_ObjCProtocolDecl: return "ObjCProtocolDecl"; |
| 260 | case CXCursor_ObjCPropertyDecl: return "ObjCPropertyDecl"; |
| 261 | case CXCursor_ObjCIvarDecl: return "ObjCIvarDecl"; |
Steve Naroff | c857ea4 | 2009-09-02 13:28:54 +0000 | [diff] [blame] | 262 | case CXCursor_ObjCInstanceMethodDecl: return "ObjCInstanceMethodDecl"; |
| 263 | case CXCursor_ObjCClassMethodDecl: return "ObjCClassMethodDecl"; |
| 264 | case CXCursor_FunctionDefn: return "FunctionDefn"; |
| 265 | case CXCursor_ObjCInstanceMethodDefn: return "ObjCInstanceMethodDefn"; |
| 266 | case CXCursor_ObjCClassMethodDefn: return "ObjCClassMethodDefn"; |
| 267 | case CXCursor_ObjCClassDefn: return "ObjCClassDefn"; |
| 268 | case CXCursor_ObjCCategoryDefn: return "ObjCCategoryDefn"; |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 269 | default: return "<not implemented>"; |
| 270 | } |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 271 | } |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 272 | |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 273 | // |
| 274 | // CXCursor Operations. |
| 275 | // |
| 276 | CXCursor clang_getCursor(CXTranslationUnit, const char *source_name, |
| 277 | unsigned line, unsigned column) |
| 278 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 279 | return CXCursor(); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | CXCursorKind clang_getCursorKind(CXCursor) |
| 283 | { |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 284 | return CXCursor_Invalid; |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Steve Naroff | 89922f8 | 2009-08-31 00:59:03 +0000 | [diff] [blame] | 287 | unsigned clang_isDeclaration(enum CXCursorKind K) |
| 288 | { |
| 289 | return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl; |
| 290 | } |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 291 | |
| 292 | unsigned clang_getCursorLine(CXCursor C) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 293 | { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 294 | assert(C.decl && "CXCursor has null decl"); |
| 295 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
| 296 | SourceLocation SLoc = ND->getLocation(); |
| 297 | if (SLoc.isInvalid()) |
| 298 | return 0; |
| 299 | SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); |
| 300 | SLoc = SourceMgr.getSpellingLoc(SLoc); // handles macro instantiations. |
| 301 | return SourceMgr.getSpellingLineNumber(SLoc); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 302 | } |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 303 | unsigned clang_getCursorColumn(CXCursor C) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 304 | { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 305 | assert(C.decl && "CXCursor has null decl"); |
| 306 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
| 307 | SourceLocation SLoc = ND->getLocation(); |
| 308 | if (SLoc.isInvalid()) |
| 309 | return 0; |
| 310 | SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); |
| 311 | SLoc = SourceMgr.getSpellingLoc(SLoc); // handles macro instantiations. |
| 312 | return SourceMgr.getSpellingColumnNumber(SLoc); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 313 | } |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 314 | const char *clang_getCursorSource(CXCursor C) |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 315 | { |
Steve Naroff | 2d4d629 | 2009-08-31 14:26:51 +0000 | [diff] [blame] | 316 | assert(C.decl && "CXCursor has null decl"); |
| 317 | NamedDecl *ND = static_cast<NamedDecl *>(C.decl); |
| 318 | SourceLocation SLoc = ND->getLocation(); |
| 319 | if (SLoc.isInvalid()) |
| 320 | return "<invalid source location>"; |
| 321 | SourceManager &SourceMgr = ND->getASTContext().getSourceManager(); |
| 322 | SLoc = SourceMgr.getSpellingLoc(SLoc); // handles macro instantiations. |
| 323 | return SourceMgr.getBufferName(SLoc); |
Steve Naroff | 600866c | 2009-08-27 19:51:58 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // If CXCursorKind == Cursor_Reference, then this will return the referenced declaration. |
| 327 | // If CXCursorKind == Cursor_Declaration, then this will return the declaration. |
| 328 | CXDecl clang_getCursorDecl(CXCursor) |
| 329 | { |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | } // end extern "C" |