blob: 5d1ee9684fd2f8b5da0fab036577423bc1813f8a [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");
197 //ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
198 //return CXXUnit->getOriginalSourceFileName().c_str();
199 return "<unimplemented>";
200}
Daniel Dunbar1eb79b52009-08-28 16:30:07 +0000201
Steve Naroffc857ea42009-09-02 13:28:54 +0000202void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
203 CXTranslationUnitIterator callback,
204 CXClientData CData)
Steve Naroff600866c2009-08-27 19:51:58 +0000205{
Steve Naroff50398192009-08-28 15:28:48 +0000206 assert(CTUnit && "Passed null CXTranslationUnit");
207 ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
208 ASTContext &Ctx = CXXUnit->getASTContext();
209
Steve Naroff2b8ee6c2009-09-01 15:55:40 +0000210 TUVisitor DVisit(CTUnit, callback, CData);
Steve Naroff50398192009-08-28 15:28:48 +0000211 DVisit.Visit(Ctx.getTranslationUnitDecl());
Steve Naroff600866c2009-08-27 19:51:58 +0000212}
213
Steve Naroffc857ea42009-09-02 13:28:54 +0000214void clang_loadDeclaration(CXDecl Dcl,
215 CXDeclIterator callback,
216 CXClientData CData)
Steve Naroff600866c2009-08-27 19:51:58 +0000217{
Steve Naroffc857ea42009-09-02 13:28:54 +0000218 assert(Dcl && "Passed null CXDecl");
219
220 CDeclVisitor DVisit(Dcl, callback, CData);
221 DVisit.Visit(static_cast<Decl *>(Dcl));
Steve Naroff600866c2009-08-27 19:51:58 +0000222}
223
Steve Naroff7e8f8182009-08-28 12:07:44 +0000224// Some notes on CXEntity:
225//
226// - Since the 'ordinary' namespace includes functions, data, typedefs,
227// ObjC interfaces, thecurrent algorithm is a bit naive (resulting in one
228// entity for 2 different types). For example:
229//
230// module1.m: @interface Foo @end Foo *x;
231// module2.m: void Foo(int);
232//
233// - Since the unique name spans translation units, static data/functions
234// within a CXTranslationUnit are *not* currently represented by entities.
235// As a result, there will be no entity for the following:
236//
237// module.m: static void Foo() { }
238//
239
240
Steve Naroff600866c2009-08-27 19:51:58 +0000241const char *clang_getDeclarationName(CXEntity)
242{
243 return "";
244}
245const char *clang_getURI(CXEntity)
246{
247 return "";
248}
249
250CXEntity clang_getEntity(const char *URI)
251{
252 return 0;
253}
254
255//
256// CXDecl Operations.
257//
258CXCursor clang_getCursorFromDecl(CXDecl)
259{
Steve Naroff89922f82009-08-31 00:59:03 +0000260 return CXCursor();
Steve Naroff600866c2009-08-27 19:51:58 +0000261}
262CXEntity clang_getEntityFromDecl(CXDecl)
263{
264 return 0;
265}
Steve Naroff89922f82009-08-31 00:59:03 +0000266const char *clang_getDeclSpelling(CXDecl AnonDecl)
Steve Naroff600866c2009-08-27 19:51:58 +0000267{
Steve Naroff89922f82009-08-31 00:59:03 +0000268 assert(AnonDecl && "Passed null CXDecl");
269 NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
Steve Naroffc857ea42009-09-02 13:28:54 +0000270
271 if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) {
272 return OMD->getSelector().getAsString().c_str();
273 }
Steve Naroff89922f82009-08-31 00:59:03 +0000274 if (ND->getIdentifier())
275 return ND->getIdentifier()->getName();
Steve Naroffc857ea42009-09-02 13:28:54 +0000276 else
Steve Naroff89922f82009-08-31 00:59:03 +0000277 return "";
Steve Naroff600866c2009-08-27 19:51:58 +0000278}
Steve Narofff334b4e2009-09-02 18:26:48 +0000279
280const char *clang_getCursorSpelling(CXCursor C)
281{
282 assert(C.decl && "CXCursor has null decl");
283 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
284
285 if (clang_isReference(C.kind)) {
286 switch (C.kind) {
Steve Naroff1164d852009-09-02 18:58:52 +0000287 case CXCursor_ObjCSuperClassRef:
288 {
Steve Narofff334b4e2009-09-02 18:26:48 +0000289 ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND);
290 assert(OID && "clang_getCursorLine(): Missing interface decl");
291 return OID->getSuperClass()->getIdentifier()->getName();
Steve Naroff1164d852009-09-02 18:58:52 +0000292 }
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000293 case CXCursor_ObjCClassRef:
294 {
295 ObjCCategoryDecl *OID = dyn_cast<ObjCCategoryDecl>(ND);
296 assert(OID && "clang_getCursorLine(): Missing category decl");
297 return OID->getClassInterface()->getIdentifier()->getName();
298 }
Steve Narofff334b4e2009-09-02 18:26:48 +0000299 default:
300 return "<not implemented>";
301 }
302 }
303 return clang_getDeclSpelling(C.decl);
304}
305
306const char *clang_getCursorKindSpelling(enum CXCursorKind Kind)
Steve Naroff600866c2009-08-27 19:51:58 +0000307{
Steve Naroff89922f82009-08-31 00:59:03 +0000308 switch (Kind) {
309 case CXCursor_FunctionDecl: return "FunctionDecl";
310 case CXCursor_TypedefDecl: return "TypedefDecl";
311 case CXCursor_EnumDecl: return "EnumDecl";
312 case CXCursor_EnumConstantDecl: return "EnumConstantDecl";
Steve Naroffc857ea42009-09-02 13:28:54 +0000313 case CXCursor_StructDecl: return "StructDecl";
314 case CXCursor_UnionDecl: return "UnionDecl";
315 case CXCursor_ClassDecl: return "ClassDecl";
Steve Naroff89922f82009-08-31 00:59:03 +0000316 case CXCursor_FieldDecl: return "FieldDecl";
317 case CXCursor_VarDecl: return "VarDecl";
318 case CXCursor_ParmDecl: return "ParmDecl";
319 case CXCursor_ObjCInterfaceDecl: return "ObjCInterfaceDecl";
320 case CXCursor_ObjCCategoryDecl: return "ObjCCategoryDecl";
321 case CXCursor_ObjCProtocolDecl: return "ObjCProtocolDecl";
322 case CXCursor_ObjCPropertyDecl: return "ObjCPropertyDecl";
323 case CXCursor_ObjCIvarDecl: return "ObjCIvarDecl";
Steve Naroffc857ea42009-09-02 13:28:54 +0000324 case CXCursor_ObjCInstanceMethodDecl: return "ObjCInstanceMethodDecl";
325 case CXCursor_ObjCClassMethodDecl: return "ObjCClassMethodDecl";
326 case CXCursor_FunctionDefn: return "FunctionDefn";
327 case CXCursor_ObjCInstanceMethodDefn: return "ObjCInstanceMethodDefn";
328 case CXCursor_ObjCClassMethodDefn: return "ObjCClassMethodDefn";
329 case CXCursor_ObjCClassDefn: return "ObjCClassDefn";
330 case CXCursor_ObjCCategoryDefn: return "ObjCCategoryDefn";
Steve Narofff334b4e2009-09-02 18:26:48 +0000331 case CXCursor_ObjCSuperClassRef: return "ObjCSuperClassRef";
Steve Naroffaf08ddc2009-09-03 15:49:00 +0000332 case CXCursor_ObjCClassRef: return "ObjCClassRef";
Steve Naroff89922f82009-08-31 00:59:03 +0000333 default: return "<not implemented>";
334 }
Steve Naroff600866c2009-08-27 19:51:58 +0000335}
Steve Naroff89922f82009-08-31 00:59:03 +0000336
Steve Naroff600866c2009-08-27 19:51:58 +0000337//
338// CXCursor Operations.
339//
340CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
341 unsigned line, unsigned column)
342{
Steve Naroff89922f82009-08-31 00:59:03 +0000343 return CXCursor();
Steve Naroff600866c2009-08-27 19:51:58 +0000344}
345
346CXCursorKind clang_getCursorKind(CXCursor)
347{
Steve Naroff89922f82009-08-31 00:59:03 +0000348 return CXCursor_Invalid;
Steve Naroff600866c2009-08-27 19:51:58 +0000349}
350
Steve Naroff89922f82009-08-31 00:59:03 +0000351unsigned clang_isDeclaration(enum CXCursorKind K)
352{
353 return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl;
354}
Steve Naroff2d4d6292009-08-31 14:26:51 +0000355
Steve Narofff334b4e2009-09-02 18:26:48 +0000356unsigned clang_isReference(enum CXCursorKind K)
357{
358 return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
359}
360
361unsigned clang_isDefinition(enum CXCursorKind K)
362{
363 return K >= CXCursor_FirstDefn && K <= CXCursor_LastDefn;
364}
365
366static SourceLocation getLocationFromCursor(CXCursor C,
367 SourceManager &SourceMgr,
368 NamedDecl *ND) {
Steve Narofff334b4e2009-09-02 18:26:48 +0000369 if (clang_isReference(C.kind)) {
370 switch (C.kind) {
371 case CXCursor_ObjCSuperClassRef:
Steve Naroff1164d852009-09-02 18:58:52 +0000372 {
Steve Narofff334b4e2009-09-02 18:26:48 +0000373 ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND);
374 assert(OID && "clang_getCursorLine(): Missing interface decl");
Steve Naroff1164d852009-09-02 18:58:52 +0000375 return OID->getSuperClassLoc();
376 }
Steve Narofff334b4e2009-09-02 18:26:48 +0000377 default:
Steve Naroff1164d852009-09-02 18:58:52 +0000378 return SourceLocation();
Steve Narofff334b4e2009-09-02 18:26:48 +0000379 }
380 } else { // We have a declaration or a definition.
Steve Naroff1164d852009-09-02 18:58:52 +0000381 SourceLocation SLoc = ND->getLocation();
Steve Narofff334b4e2009-09-02 18:26:48 +0000382 if (SLoc.isInvalid())
383 return SourceLocation();
Steve Naroff1164d852009-09-02 18:58:52 +0000384 return SourceMgr.getSpellingLoc(SLoc); // handles macro instantiations.
Steve Narofff334b4e2009-09-02 18:26:48 +0000385 }
Steve Narofff334b4e2009-09-02 18:26:48 +0000386}
387
Steve Naroff2d4d6292009-08-31 14:26:51 +0000388unsigned clang_getCursorLine(CXCursor C)
Steve Naroff600866c2009-08-27 19:51:58 +0000389{
Steve Naroff2d4d6292009-08-31 14:26:51 +0000390 assert(C.decl && "CXCursor has null decl");
391 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000392 SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
Steve Narofff334b4e2009-09-02 18:26:48 +0000393
394 SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000395 return SourceMgr.getSpellingLineNumber(SLoc);
Steve Naroff600866c2009-08-27 19:51:58 +0000396}
Steve Narofff334b4e2009-09-02 18:26:48 +0000397
Steve Naroff2d4d6292009-08-31 14:26:51 +0000398unsigned clang_getCursorColumn(CXCursor C)
Steve Naroff600866c2009-08-27 19:51:58 +0000399{
Steve Naroff2d4d6292009-08-31 14:26:51 +0000400 assert(C.decl && "CXCursor has null decl");
401 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000402 SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
Steve Narofff334b4e2009-09-02 18:26:48 +0000403
404 SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000405 return SourceMgr.getSpellingColumnNumber(SLoc);
Steve Naroff600866c2009-08-27 19:51:58 +0000406}
Steve Naroff2d4d6292009-08-31 14:26:51 +0000407const char *clang_getCursorSource(CXCursor C)
Steve Naroff600866c2009-08-27 19:51:58 +0000408{
Steve Naroff2d4d6292009-08-31 14:26:51 +0000409 assert(C.decl && "CXCursor has null decl");
410 NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000411 SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
Steve Narofff334b4e2009-09-02 18:26:48 +0000412
413 SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
Steve Naroff2d4d6292009-08-31 14:26:51 +0000414 return SourceMgr.getBufferName(SLoc);
Steve Naroff600866c2009-08-27 19:51:58 +0000415}
416
417// If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
418// If CXCursorKind == Cursor_Declaration, then this will return the declaration.
419CXDecl clang_getCursorDecl(CXCursor)
420{
421 return 0;
422}
423
424} // end extern "C"