diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 51 | ||||
-rw-r--r-- | tools/CIndex/CIndex.exports | 2 | ||||
-rw-r--r-- | tools/Makefile | 2 | ||||
-rw-r--r-- | tools/c-index-test/CMakeLists.txt | 20 | ||||
-rw-r--r-- | tools/c-index-test/Makefile | 24 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 12 | ||||
-rw-r--r-- | tools/index-test/index-test.cpp | 2 |
7 files changed, 102 insertions, 11 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index ec575475ec..dc44fd2b1c 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -13,23 +13,58 @@ #include "clang-c/Index.h" +#include "clang/Index/Program.h" +#include "clang/Index/Indexer.h" + +#include "clang/Frontend/ASTUnit.h" +#include "clang/Basic/FileManager.h" + +#include "clang/AST/DeclVisitor.h" + +using namespace clang; +using namespace idx; + extern "C" { CXIndex clang_createIndex() -{ - return 0; +{ + return new Indexer(*new Program(), *new FileManager()); } -CXTranslationUnit clang_loadTranslationUnitFromASTFile( - CXIndex, const char *ast_filename) +// FIXME: need to pass back error info. +CXTranslationUnit clang_createTranslationUnit( + CXIndex CIdx, const char *ast_filename) { - return 0; + assert(CIdx && "Passed null CXIndex"); + Indexer *CXXIdx = static_cast<Indexer *>(CIdx); + std::string astName(ast_filename); + std::string ErrMsg; + + return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg); } +class IdxVisitor : public DeclVisitor<IdxVisitor> { +public: + IdxVisitor(); + + void VisitNamedDecl(NamedDecl *ND) { + printf("NamedDecl (%s:", ND->getDeclKindName()); + if (ND->getIdentifier()) + printf("%s)\n", ND->getIdentifier()->getName()); + else + printf("<no name>)\n"); + } +}; + void clang_loadTranslationUnit( - CXTranslationUnit, void (*callback)(CXTranslationUnit, CXCursor) -) -{ + CXTranslationUnit CTUnit, void (*callback)(CXTranslationUnit, CXCursor)) +{ + assert(CTUnit && "Passed null CXTranslationUnit"); + ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit); + ASTContext &Ctx = CXXUnit->getASTContext(); + + IdxVisitor DVisit; + DVisit.Visit(Ctx.getTranslationUnitDecl()); } void clang_loadDeclaration(CXDecl, void (*callback)(CXDecl, CXCursor)) diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports index 0e6cfa549a..41b67a2467 100644 --- a/tools/CIndex/CIndex.exports +++ b/tools/CIndex/CIndex.exports @@ -14,4 +14,4 @@ _clang_getEntityFromDecl _clang_getURI _clang_loadDeclaration _clang_loadTranslationUnit -_clang_loadTranslationUnitFromASTFile +_clang_createTranslationUnit diff --git a/tools/Makefile b/tools/Makefile index 3ee73ca282..d76e95606d 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -8,6 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL := ../../.. -DIRS := clang-cc driver index-test wpa CIndex +DIRS := clang-cc driver index-test wpa CIndex c-index-test include $(LEVEL)/Makefile.common diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt new file mode 100644 index 0000000000..abf3cc4400 --- /dev/null +++ b/tools/c-index-test/CMakeLists.txt @@ -0,0 +1,20 @@ +set(LLVM_NO_RTTI 1) + +set( LLVM_USED_LIBS + CIndex + clangIndex + clangFrontend + clangSema + clangAST + clangLex + clangBasic + ) + +set( LLVM_LINK_COMPONENTS + bitreader + mc + ) + +add_clang_executable(c-index-test + c-index-test.c + ) diff --git a/tools/c-index-test/Makefile b/tools/c-index-test/Makefile new file mode 100644 index 0000000000..81fee40b66 --- /dev/null +++ b/tools/c-index-test/Makefile @@ -0,0 +1,24 @@ +##===- tools/index-test/Makefile ---------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../../.. + +TOOLNAME = c-index-test +CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include +CXXFLAGS = -fno-rtti +NO_INSTALL = 1 + +# No plugins, optimize startup time. +TOOL_NO_EXPORTS = 1 + +include $(LEVEL)/Makefile.config + +LINK_COMPONENTS := bitreader mc +USEDLIBS = CIndex.a clangIndex.a clangFrontend.a clangSema.a clangAST.a clangLex.a clangBasic.a + +include $(LLVM_SRC_ROOT)/Makefile.rules diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c new file mode 100644 index 0000000000..71bdcc5c64 --- /dev/null +++ b/tools/c-index-test/c-index-test.c @@ -0,0 +1,12 @@ + +#include "clang-c/Index.h" + +/* + * First sign of life:-) + */ +int main(int argc, char **argv) { + CXIndex Idx = clang_createIndex(); + CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]); + clang_loadTranslationUnit(TU, 0); + return 1; +} diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index 02971ed782..88fd2417ac 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -214,7 +214,7 @@ int main(int argc, char **argv) { FileManager FileMgr; Program Prog; - Indexer Idxer(Prog); + Indexer Idxer(Prog, FileMgr); llvm::SmallVector<TUnit*, 4> TUnits; // If no input was specified, read from stdin. |