blob: ef285e0778699ecdb4187513067b3431d906671b [file] [log] [blame]
Ted Kremenekd2fa5662009-08-26 22:36:44 +00001//===- 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 Naroff50398192009-08-28 15:28:48 +000015#include "clang/Index/Program.h"
16#include "clang/Index/Indexer.h"
Steve Naroff50398192009-08-28 15:28:48 +000017#include "clang/AST/DeclVisitor.h"
Steve Naroffc857ea42009-09-02 13:28:54 +000018#include "clang/AST/Decl.h"
Benjamin Kramerd01a0bc2009-08-29 12:56:35 +000019#include "clang/Basic/FileManager.h"
Steve Naroff2d4d6292009-08-31 14:26:51 +000020#include "clang/Basic/SourceManager.h"
Benjamin Kramerd01a0bc2009-08-29 12:56:35 +000021#include "clang/Frontend/ASTUnit.h"
22#include <cstdio>
Steve Naroff50398192009-08-28 15:28:48 +000023using namespace clang;
24using namespace idx;
25
Steve Naroff89922f82009-08-31 00:59:03 +000026namespace {
27
28// Translation Unit Visitor.
29class TUVisitor : public DeclVisitor<TUVisitor> {
30 CXTranslationUnit TUnit;
31 CXTranslationUnitIterator Callback;
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000032 CXClientData CData;
33
34 void Call(enum CXCursorKind CK, NamedDecl *ND) {
35 CXCursor C = { CK, ND };
36 Callback(TUnit, C, CData);
37 }
Steve Naroff89922f82009-08-31 00:59:03 +000038public:
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000039 TUVisitor(CXTranslationUnit CTU,
40 CXTranslationUnitIterator cback, CXClientData D) :
41 TUnit(CTU), Callback(cback), CData(D) {}
Steve Naroff89922f82009-08-31 00:59:03 +000042
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 Naroff2b8ee6c2009-09-01 15:55:40 +000051 void VisitTypedefDecl(TypedefDecl *ND) {
52 Call(CXCursor_TypedefDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +000053 }
54 void VisitTagDecl(TagDecl *ND) {
Steve Naroffc857ea42009-09-02 13:28:54 +000055 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 Naroff89922f82009-08-31 00:59:03 +000069 }
Steve Naroffaf08ddc2009-09-03 15:49:00 +000070 void VisitVarDecl(VarDecl *ND) {
71 Call(CXCursor_VarDecl, ND);
72 }
Steve Naroff89922f82009-08-31 00:59:03 +000073 void VisitFunctionDecl(FunctionDecl *ND) {
Steve Naroffc857ea42009-09-02 13:28:54 +000074 Call(ND->isThisDeclarationADefinition() ? CXCursor_FunctionDefn
75 : CXCursor_FunctionDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +000076 }
77 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *ND) {
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000078 Call(CXCursor_ObjCInterfaceDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +000079 }
80 void VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000081 Call(CXCursor_ObjCCategoryDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +000082 }
83 void VisitObjCProtocolDecl(ObjCProtocolDecl *ND) {
Steve Naroff2b8ee6c2009-09-01 15:55:40 +000084 Call(CXCursor_ObjCProtocolDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +000085 }
Steve Naroffc857ea42009-09-02 13:28:54 +000086 void VisitObjCImplementationDecl(ObjCImplementationDecl *ND) {
87 Call(CXCursor_ObjCClassDefn, ND);
88 }
89 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *ND) {
90 Call(CXCursor_ObjCCategoryDefn, ND);
91 }
Steve Naroff89922f82009-08-31 00:59:03 +000092};
93
Steve Naroffc857ea42009-09-02 13:28:54 +000094// Declaration visitor.
95class CDeclVisitor : public DeclVisitor<CDeclVisitor> {
96 CXDecl CDecl;
97 CXDeclIterator Callback;
98 CXClientData CData;
99
100 void Call(enum CXCursorKind CK, NamedDecl *ND) {
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000101 // Disable the callback when the context is equal to the visiting decl.
102 if (CDecl == ND && !clang_isReference(CK))
103 return;
Steve Naroffc857ea42009-09-02 13:28:54 +0000104 CXCursor C = { CK, ND };
105 Callback(CDecl, C, CData);
106 }
Steve Naroff89922f82009-08-31 00:59:03 +0000107public:
Steve Naroffc857ea42009-09-02 13:28:54 +0000108 CDeclVisitor(CXDecl C, CXDeclIterator cback, CXClientData D) :
109 CDecl(C), Callback(cback), CData(D) {}
110
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000111 void VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
112 // Issue callbacks for the containing class.
113 Call(CXCursor_ObjCClassRef, ND);
114 // FIXME: Issue callbacks for protocol refs.
115 VisitDeclContext(dyn_cast<DeclContext>(ND));
116 }
Steve Naroffc857ea42009-09-02 13:28:54 +0000117 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000118 // Issue callbacks for super class.
Steve Narofff334b4e2009-09-02 18:26:48 +0000119 if (D->getSuperClass())
120 Call(CXCursor_ObjCSuperClassRef, D);
121
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000122 // FIXME: Issue callbacks for protocol refs.
Steve Naroffc857ea42009-09-02 13:28:54 +0000123 VisitDeclContext(dyn_cast<DeclContext>(D));
124 }
125 void VisitTagDecl(TagDecl *D) {
126 VisitDeclContext(dyn_cast<DeclContext>(D));
127 }
128 void VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
129 VisitDeclContext(dyn_cast<DeclContext>(D));
130 }
131 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
132 VisitDeclContext(dyn_cast<DeclContext>(D));
133 }
Steve Naroff89922f82009-08-31 00:59:03 +0000134 void VisitDeclContext(DeclContext *DC) {
135 for (DeclContext::decl_iterator
136 I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I)
137 Visit(*I);
138 }
139 void VisitEnumConstantDecl(EnumConstantDecl *ND) {
Steve Naroffc857ea42009-09-02 13:28:54 +0000140 Call(CXCursor_EnumConstantDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +0000141 }
142 void VisitFieldDecl(FieldDecl *ND) {
Steve Naroffc857ea42009-09-02 13:28:54 +0000143 Call(CXCursor_FieldDecl, ND);
144 }
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000145 void VisitVarDecl(VarDecl *ND) {
146 Call(CXCursor_VarDecl, ND);
147 }
148 void VisitParmVarDecl(ParmVarDecl *ND) {
149 Call(CXCursor_ParmDecl, ND);
150 }
Steve Naroffc857ea42009-09-02 13:28:54 +0000151 void VisitObjCPropertyDecl(ObjCPropertyDecl *ND) {
152 Call(CXCursor_ObjCPropertyDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +0000153 }
154 void VisitObjCIvarDecl(ObjCIvarDecl *ND) {
Steve Naroffc857ea42009-09-02 13:28:54 +0000155 Call(CXCursor_ObjCIvarDecl, ND);
156 }
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000157 void VisitFunctionDecl(FunctionDecl *ND) {
158 if (ND->isThisDeclarationADefinition()) {
159 VisitDeclContext(dyn_cast<DeclContext>(ND));
160 }
161 }
Steve Naroffc857ea42009-09-02 13:28:54 +0000162 void VisitObjCMethodDecl(ObjCMethodDecl *ND) {
163 if (ND->getBody()) {
164 Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDefn
165 : CXCursor_ObjCClassMethodDefn, ND);
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000166 VisitDeclContext(dyn_cast<DeclContext>(ND));
Steve Naroffc857ea42009-09-02 13:28:54 +0000167 } else
168 Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDecl
169 : CXCursor_ObjCClassMethodDecl, ND);
Steve Naroff89922f82009-08-31 00:59:03 +0000170 }
171};
172
173}
174
Steve Naroff600866c2009-08-27 19:51:58 +0000175extern "C" {
Ted Kremenekd2fa5662009-08-26 22:36:44 +0000176
Steve Naroff600866c2009-08-27 19:51:58 +0000177CXIndex clang_createIndex()
Steve Naroff50398192009-08-28 15:28:48 +0000178{
179 return new Indexer(*new Program(), *new FileManager());
Steve Naroff600866c2009-08-27 19:51:58 +0000180}
181
Steve Naroff50398192009-08-28 15:28:48 +0000182// FIXME: need to pass back error info.
183CXTranslationUnit clang_createTranslationUnit(
184 CXIndex CIdx, const char *ast_filename)
Steve Naroff600866c2009-08-27 19:51:58 +0000185{
Steve Naroff50398192009-08-28 15:28:48 +0000186 assert(CIdx && "Passed null CXIndex");
187 Indexer *CXXIdx = static_cast<Indexer *>(CIdx);
188 std::string astName(ast_filename);
189 std::string ErrMsg;
190
191 return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg);
Steve Naroff600866c2009-08-27 19:51:58 +0000192}
193
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000194const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit)
195{
196 assert(CTUnit && "Passed null CXTranslationUnit");
Steve Naroff77accc12009-09-03 18:19:54 +0000197 ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
198 return CXXUnit->getOriginalSourceFileName().c_str();
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000199}
Daniel Dunbar1eb79b52009-08-28 16:30:07 +0000200
Steve Naroffc857ea42009-09-02 13:28:54 +0000201void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
202 CXTranslationUnitIterator callback,
203 CXClientData CData)
Steve Naroff600866c2009-08-27 19:51:58 +0000204{
Steve Naroff50398192009-08-28 15:28:48 +0000205 assert(CTUnit && "Passed null CXTranslationUnit");
206 ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
207 ASTContext &Ctx = CXXUnit->getASTContext();
208
Steve Naroff2b8ee6c2009-09-01 15:55:40 +0000209 TUVisitor DVisit(CTUnit, callback, CData);
Steve Naroff50398192009-08-28 15:28:48 +0000210 DVisit.Visit(Ctx.getTranslationUnitDecl());
Steve Naroff600866c2009-08-27 19:51:58 +0000211}
212
Steve Naroffc857ea42009-09-02 13:28:54 +0000213void clang_loadDeclaration(CXDecl Dcl,
214 CXDeclIterator callback,
215 CXClientData CData)
Steve Naroff600866c2009-08-27 19:51:58 +0000216{
Steve Naroffc857ea42009-09-02 13:28:54 +0000217 assert(Dcl && "Passed null CXDecl");
218
219 CDeclVisitor DVisit(Dcl, callback, CData);
220 DVisit.Visit(static_cast<Decl *>(Dcl));
Steve Naroff600866c2009-08-27 19:51:58 +0000221}
222
Steve Naroff7e8f8182009-08-28 12:07:44 +0000223// Some notes on CXEntity:
224//
225// - Since the 'ordinary' namespace includes functions, data, typedefs,
226// ObjC interfaces, thecurrent algorithm is a bit naive (resulting in one
227// entity for 2 different types). For example:
228//
229// module1.m: @interface Foo @end Foo *x;
230// module2.m: void Foo(int);
231//
232// - Since the unique name spans translation units, static data/functions
233// within a CXTranslationUnit are *not* currently represented by entities.
234// As a result, there will be no entity for the following:
235//
236// module.m: static void Foo() { }
237//
238
239
Steve Naroff600866c2009-08-27 19:51:58 +0000240const char *clang_getDeclarationName(CXEntity)
241{
242 return "";
243}
244const char *clang_getURI(CXEntity)
245{
246 return "";
247}
248
249CXEntity clang_getEntity(const char *URI)
250{
251 return 0;
252}
253
254//
255// CXDecl Operations.
256//
257CXCursor clang_getCursorFromDecl(CXDecl)
258{
Steve Naroff89922f82009-08-31 00:59:03 +0000259 return CXCursor();
Steve Naroff600866c2009-08-27 19:51:58 +0000260}
261CXEntity clang_getEntityFromDecl(CXDecl)
262{
263 return 0;
264}
Steve Naroff89922f82009-08-31 00:59:03 +0000265const char *clang_getDeclSpelling(CXDecl AnonDecl)
Steve Naroff600866c2009-08-27 19:51:58 +0000266{
Steve Naroff89922f82009-08-31 00:59:03 +0000267 assert(AnonDecl && "Passed null CXDecl");
268 NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
Steve Naroffc857ea42009-09-02 13:28:54 +0000269
270 if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) {
271 return OMD->getSelector().getAsString().c_str();
272 }
Steve Naroff89922f82009-08-31 00:59:03 +0000273 if (ND->getIdentifier())
274 return ND->getIdentifier()->getName();
Steve Naroffc857ea42009-09-02 13:28:54 +0000275 else
Steve Naroff89922f82009-08-31 00:59:03 +0000276 return "";
Steve Naroff600866c2009-08-27 19:51:58 +0000277}
Steve Narofff334b4e2009-09-02 18:26:48 +0000278
279const char *clang_getCursorSpelling(CXCursor C)
280{
281 assert(C.decl && "CXCursor has null decl");
282 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
283
284 if (clang_isReference(C.kind)) {
285 switch (C.kind) {
Steve Naroff1164d852009-09-02 18:58:52 +0000286 case CXCursor_ObjCSuperClassRef:
287 {
Steve Narofff334b4e2009-09-02 18:26:48 +0000288 ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND);
289 assert(OID && "clang_getCursorLine(): Missing interface decl");
290 return OID->getSuperClass()->getIdentifier()->getName();
Steve Naroff1164d852009-09-02 18:58:52 +0000291 }
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000292 case CXCursor_ObjCClassRef:
293 {
294 ObjCCategoryDecl *OID = dyn_cast<ObjCCategoryDecl>(ND);
295 assert(OID && "clang_getCursorLine(): Missing category decl");
296 return OID->getClassInterface()->getIdentifier()->getName();
297 }
Steve Narofff334b4e2009-09-02 18:26:48 +0000298 default:
299 return "<not implemented>";
300 }
301 }
302 return clang_getDeclSpelling(C.decl);
303}
304
305const char *clang_getCursorKindSpelling(enum CXCursorKind Kind)
Steve Naroff600866c2009-08-27 19:51:58 +0000306{
Steve Naroff89922f82009-08-31 00:59:03 +0000307 switch (Kind) {
308 case CXCursor_FunctionDecl: return "FunctionDecl";
309 case CXCursor_TypedefDecl: return "TypedefDecl";
310 case CXCursor_EnumDecl: return "EnumDecl";
311 case CXCursor_EnumConstantDecl: return "EnumConstantDecl";
Steve Naroffc857ea42009-09-02 13:28:54 +0000312 case CXCursor_StructDecl: return "StructDecl";
313 case CXCursor_UnionDecl: return "UnionDecl";
314 case CXCursor_ClassDecl: return "ClassDecl";
Steve Naroff89922f82009-08-31 00:59:03 +0000315 case CXCursor_FieldDecl: return "FieldDecl";
316 case CXCursor_VarDecl: return "VarDecl";
317 case CXCursor_ParmDecl: return "ParmDecl";
318 case CXCursor_ObjCInterfaceDecl: return "ObjCInterfaceDecl";
319 case CXCursor_ObjCCategoryDecl: return "ObjCCategoryDecl";
320 case CXCursor_ObjCProtocolDecl: return "ObjCProtocolDecl";
321 case CXCursor_ObjCPropertyDecl: return "ObjCPropertyDecl";
322 case CXCursor_ObjCIvarDecl: return "ObjCIvarDecl";
Steve Naroffc857ea42009-09-02 13:28:54 +0000323 case CXCursor_ObjCInstanceMethodDecl: return "ObjCInstanceMethodDecl";
324 case CXCursor_ObjCClassMethodDecl: return "ObjCClassMethodDecl";
325 case CXCursor_FunctionDefn: return "FunctionDefn";
326 case CXCursor_ObjCInstanceMethodDefn: return "ObjCInstanceMethodDefn";
327 case CXCursor_ObjCClassMethodDefn: return "ObjCClassMethodDefn";
328 case CXCursor_ObjCClassDefn: return "ObjCClassDefn";
329 case CXCursor_ObjCCategoryDefn: return "ObjCCategoryDefn";
Steve Narofff334b4e2009-09-02 18:26:48 +0000330 case CXCursor_ObjCSuperClassRef: return "ObjCSuperClassRef";
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000331 case CXCursor_ObjCClassRef: return "ObjCClassRef";
Steve Naroff89922f82009-08-31 00:59:03 +0000332 default: return "<not implemented>";
333 }
Steve Naroff600866c2009-08-27 19:51:58 +0000334}
Steve Naroff89922f82009-08-31 00:59:03 +0000335
Steve Naroff600866c2009-08-27 19:51:58 +0000336//
337// CXCursor Operations.
338//
339CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
340 unsigned line, unsigned column)
341{
Steve Naroff89922f82009-08-31 00:59:03 +0000342 return CXCursor();
Steve Naroff600866c2009-08-27 19:51:58 +0000343}
344
345CXCursorKind clang_getCursorKind(CXCursor)
346{
Steve Naroff89922f82009-08-31 00:59:03 +0000347 return CXCursor_Invalid;
Steve Naroff600866c2009-08-27 19:51:58 +0000348}
349
Steve Naroff89922f82009-08-31 00:59:03 +0000350unsigned clang_isDeclaration(enum CXCursorKind K)
351{
352 return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl;
353}
Steve Naroff2d4d6292009-08-31 14:26:51 +0000354
Steve Narofff334b4e2009-09-02 18:26:48 +0000355unsigned clang_isReference(enum CXCursorKind K)
356{
357 return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
358}
359
360unsigned clang_isDefinition(enum CXCursorKind K)
361{
362 return K >= CXCursor_FirstDefn && K <= CXCursor_LastDefn;
363}
364
365static SourceLocation getLocationFromCursor(CXCursor C,
366 SourceManager &SourceMgr,
367 NamedDecl *ND) {
Steve Narofff334b4e2009-09-02 18:26:48 +0000368 if (clang_isReference(C.kind)) {
369 switch (C.kind) {
370 case CXCursor_ObjCSuperClassRef:
Steve Naroff1164d852009-09-02 18:58:52 +0000371 {
Steve Narofff334b4e2009-09-02 18:26:48 +0000372 ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND);
373 assert(OID && "clang_getCursorLine(): Missing interface decl");
Steve Naroff1164d852009-09-02 18:58:52 +0000374 return OID->getSuperClassLoc();
375 }
Steve Narofff334b4e2009-09-02 18:26:48 +0000376 default:
Steve Naroff1164d852009-09-02 18:58:52 +0000377 return SourceLocation();
Steve Narofff334b4e2009-09-02 18:26:48 +0000378 }
379 } else { // We have a declaration or a definition.
Steve Naroff1164d852009-09-02 18:58:52 +0000380 SourceLocation SLoc = ND->getLocation();
Steve Narofff334b4e2009-09-02 18:26:48 +0000381 if (SLoc.isInvalid())
382 return SourceLocation();
Steve Naroff1164d852009-09-02 18:58:52 +0000383 return SourceMgr.getSpellingLoc(SLoc); // handles macro instantiations.
Steve Narofff334b4e2009-09-02 18:26:48 +0000384 }
Steve Narofff334b4e2009-09-02 18:26:48 +0000385}
386
Steve Naroff2d4d6292009-08-31 14:26:51 +0000387unsigned clang_getCursorLine(CXCursor C)
Steve Naroff600866c2009-08-27 19:51:58 +0000388{
Steve Naroff2d4d6292009-08-31 14:26:51 +0000389 assert(C.decl && "CXCursor has null decl");
390 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000391 SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
Steve Narofff334b4e2009-09-02 18:26:48 +0000392
393 SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000394 return SourceMgr.getSpellingLineNumber(SLoc);
Steve Naroff600866c2009-08-27 19:51:58 +0000395}
Steve Narofff334b4e2009-09-02 18:26:48 +0000396
Steve Naroff2d4d6292009-08-31 14:26:51 +0000397unsigned clang_getCursorColumn(CXCursor C)
Steve Naroff600866c2009-08-27 19:51:58 +0000398{
Steve Naroff2d4d6292009-08-31 14:26:51 +0000399 assert(C.decl && "CXCursor has null decl");
400 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000401 SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
Steve Narofff334b4e2009-09-02 18:26:48 +0000402
403 SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000404 return SourceMgr.getSpellingColumnNumber(SLoc);
Steve Naroff600866c2009-08-27 19:51:58 +0000405}
Steve Naroff2d4d6292009-08-31 14:26:51 +0000406const char *clang_getCursorSource(CXCursor C)
Steve Naroff600866c2009-08-27 19:51:58 +0000407{
Steve Naroff2d4d6292009-08-31 14:26:51 +0000408 assert(C.decl && "CXCursor has null decl");
409 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000410 SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
Steve Narofff334b4e2009-09-02 18:26:48 +0000411
412 SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000413 return SourceMgr.getBufferName(SLoc);
Steve Naroff600866c2009-08-27 19:51:58 +0000414}
415
416// If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
417// If CXCursorKind == Cursor_Declaration, then this will return the declaration.
418CXDecl clang_getCursorDecl(CXCursor)
419{
420 return 0;
421}
422
423} // end extern "C"