blob: dc44fd2b1cc5b5d36dba23255d0b0cd173dd9388 [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"
15
Steve Naroff50398192009-08-28 15:28:48 +000016#include "clang/Index/Program.h"
17#include "clang/Index/Indexer.h"
18
19#include "clang/Frontend/ASTUnit.h"
20#include "clang/Basic/FileManager.h"
21
22#include "clang/AST/DeclVisitor.h"
23
24using namespace clang;
25using namespace idx;
26
Steve Naroff600866c2009-08-27 19:51:58 +000027extern "C" {
Ted Kremenekd2fa5662009-08-26 22:36:44 +000028
Steve Naroff600866c2009-08-27 19:51:58 +000029CXIndex clang_createIndex()
Steve Naroff50398192009-08-28 15:28:48 +000030{
31 return new Indexer(*new Program(), *new FileManager());
Steve Naroff600866c2009-08-27 19:51:58 +000032}
33
Steve Naroff50398192009-08-28 15:28:48 +000034// FIXME: need to pass back error info.
35CXTranslationUnit clang_createTranslationUnit(
36 CXIndex CIdx, const char *ast_filename)
Steve Naroff600866c2009-08-27 19:51:58 +000037{
Steve Naroff50398192009-08-28 15:28:48 +000038 assert(CIdx && "Passed null CXIndex");
39 Indexer *CXXIdx = static_cast<Indexer *>(CIdx);
40 std::string astName(ast_filename);
41 std::string ErrMsg;
42
43 return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg);
Steve Naroff600866c2009-08-27 19:51:58 +000044}
45
Steve Naroff50398192009-08-28 15:28:48 +000046class IdxVisitor : public DeclVisitor<IdxVisitor> {
47public:
48 IdxVisitor();
49
50 void VisitNamedDecl(NamedDecl *ND) {
51 printf("NamedDecl (%s:", ND->getDeclKindName());
52 if (ND->getIdentifier())
53 printf("%s)\n", ND->getIdentifier()->getName());
54 else
55 printf("<no name>)\n");
56 }
57};
58
Steve Naroff600866c2009-08-27 19:51:58 +000059void clang_loadTranslationUnit(
Steve Naroff50398192009-08-28 15:28:48 +000060 CXTranslationUnit CTUnit, void (*callback)(CXTranslationUnit, CXCursor))
Steve Naroff600866c2009-08-27 19:51:58 +000061{
Steve Naroff50398192009-08-28 15:28:48 +000062 assert(CTUnit && "Passed null CXTranslationUnit");
63 ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
64 ASTContext &Ctx = CXXUnit->getASTContext();
65
66 IdxVisitor DVisit;
67 DVisit.Visit(Ctx.getTranslationUnitDecl());
Steve Naroff600866c2009-08-27 19:51:58 +000068}
69
70void clang_loadDeclaration(CXDecl, void (*callback)(CXDecl, CXCursor))
71{
72}
73
Steve Naroff7e8f8182009-08-28 12:07:44 +000074// Some notes on CXEntity:
75//
76// - Since the 'ordinary' namespace includes functions, data, typedefs,
77// ObjC interfaces, thecurrent algorithm is a bit naive (resulting in one
78// entity for 2 different types). For example:
79//
80// module1.m: @interface Foo @end Foo *x;
81// module2.m: void Foo(int);
82//
83// - Since the unique name spans translation units, static data/functions
84// within a CXTranslationUnit are *not* currently represented by entities.
85// As a result, there will be no entity for the following:
86//
87// module.m: static void Foo() { }
88//
89
90
Steve Naroff600866c2009-08-27 19:51:58 +000091const char *clang_getDeclarationName(CXEntity)
92{
93 return "";
94}
95const char *clang_getURI(CXEntity)
96{
97 return "";
98}
99
100CXEntity clang_getEntity(const char *URI)
101{
102 return 0;
103}
104
105//
106// CXDecl Operations.
107//
108CXCursor clang_getCursorFromDecl(CXDecl)
109{
110 return 0;
111}
112CXEntity clang_getEntityFromDecl(CXDecl)
113{
114 return 0;
115}
116enum CXDeclKind clang_getDeclKind(CXDecl)
117{
118 return CXDecl_any;
119}
120const char *clang_getDeclSpelling(CXDecl)
121{
122 return "";
123}
124//
125// CXCursor Operations.
126//
127CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
128 unsigned line, unsigned column)
129{
130 return 0;
131}
132
133CXCursorKind clang_getCursorKind(CXCursor)
134{
Steve Naroff7e8f8182009-08-28 12:07:44 +0000135 return CXCursor_Declaration;
Steve Naroff600866c2009-08-27 19:51:58 +0000136}
137
138unsigned clang_getCursorLine(CXCursor)
139{
140 return 0;
141}
142unsigned clang_getCursorColumn(CXCursor)
143{
144 return 0;
145}
146const char *clang_getCursorSource(CXCursor)
147{
148 return "";
149}
150
151// If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
152// If CXCursorKind == Cursor_Declaration, then this will return the declaration.
153CXDecl clang_getCursorDecl(CXCursor)
154{
155 return 0;
156}
157
158} // end extern "C"