forked from OSchip/llvm-project
Lot's of little changes to get the C-based indexing API going...
Work in progress. llvm-svn: 80367
This commit is contained in:
parent
4bd7875b9c
commit
a1c728438c
|
@ -108,6 +108,8 @@
|
|||
84AF36A10CB17A3B00C820A5 /* DeclObjC.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84AF36A00CB17A3B00C820A5 /* DeclObjC.h */; };
|
||||
84D9A8880C1A57E100AC7ABC /* AttributeList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */; };
|
||||
84D9A88C0C1A581300AC7ABC /* AttributeList.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84D9A88B0C1A581300AC7ABC /* AttributeList.h */; };
|
||||
9012911D1048068D0083456D /* ASTUnit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9012911C1048068D0083456D /* ASTUnit.cpp */; };
|
||||
90129121104812F90083456D /* CIndex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9012911F104812F90083456D /* CIndex.cpp */; };
|
||||
906BF4B00F83BA2E001071FA /* ConvertUTF.c in Sources */ = {isa = PBXBuildFile; fileRef = 906BF4AF0F83BA2E001071FA /* ConvertUTF.c */; };
|
||||
90FD6D7B103C3D49005F5B73 /* Analyzer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 90FD6D6D103C3D49005F5B73 /* Analyzer.cpp */; };
|
||||
90FD6D7C103C3D49005F5B73 /* ASTLocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 90FD6D6E103C3D49005F5B73 /* ASTLocation.cpp */; };
|
||||
|
@ -497,6 +499,9 @@
|
|||
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; tabWidth = 2; };
|
||||
8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
9012911510470FCE0083456D /* Index.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Index.h; path = "clang-c/Index.h"; sourceTree = "<group>"; };
|
||||
9012911C1048068D0083456D /* ASTUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTUnit.cpp; path = lib/Frontend/ASTUnit.cpp; sourceTree = "<group>"; };
|
||||
9012911F104812F90083456D /* CIndex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CIndex.cpp; path = tools/CIndex/CIndex.cpp; sourceTree = "<group>"; };
|
||||
90129120104812F90083456D /* CIndex.exports */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CIndex.exports; path = tools/CIndex/CIndex.exports; sourceTree = "<group>"; };
|
||||
9063F2210F9E8BDF002F7251 /* ExternalSemaSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExternalSemaSource.h; path = clang/Sema/ExternalSemaSource.h; sourceTree = "<group>"; };
|
||||
9063F2220F9E8BDF002F7251 /* SemaConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SemaConsumer.h; path = clang/Sema/SemaConsumer.h; sourceTree = "<group>"; };
|
||||
9063F2280F9E911F002F7251 /* OnDiskHashTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OnDiskHashTable.h; sourceTree = "<group>"; };
|
||||
|
@ -879,6 +884,7 @@
|
|||
352246E00F5C6BC000D0D279 /* Frontend */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9012911C1048068D0083456D /* ASTUnit.cpp */,
|
||||
1A2A54A40FD1DD1C00F4CE45 /* AnalysisConsumer.cpp */,
|
||||
1A2A54A50FD1DD1C00F4CE45 /* ASTConsumers.cpp */,
|
||||
1A2A54A60FD1DD1C00F4CE45 /* Backend.cpp */,
|
||||
|
@ -1027,6 +1033,15 @@
|
|||
name = "clang-c";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9012911E104812DA0083456D /* CIndex */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9012911F104812F90083456D /* CIndex.cpp */,
|
||||
90129120104812F90083456D /* CIndex.exports */,
|
||||
);
|
||||
name = CIndex;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
90FD6D5E103C3D03005F5B73 /* Index */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -1466,6 +1481,7 @@
|
|||
DEDFE61F0F7B3AE10035BD10 /* Tools */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9012911E104812DA0083456D /* CIndex */,
|
||||
90FD6DB4103D9763005F5B73 /* index-test */,
|
||||
DEDFE6200F7B3AE90035BD10 /* clang-cc */,
|
||||
DEDFE6210F7B3AF10035BD10 /* clang */,
|
||||
|
@ -1849,6 +1865,8 @@
|
|||
90FD6D84103C3D49005F5B73 /* ResolveLocation.cpp in Sources */,
|
||||
90FD6D85103C3D49005F5B73 /* SelectorMap.cpp in Sources */,
|
||||
90FD6DB6103D977E005F5B73 /* index-test.cpp in Sources */,
|
||||
9012911D1048068D0083456D /* ASTUnit.cpp in Sources */,
|
||||
90129121104812F90083456D /* CIndex.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -33,13 +33,13 @@ extern "C" {
|
|||
Naming Conventions: To avoid namespace pollution, data types are prefixed
|
||||
with "CX" and functions are prefixed with "clang_".
|
||||
*/
|
||||
typedef void *CXIndex; // An indexing instance.
|
||||
typedef void *CXIndex; /* An indexing instance. */
|
||||
|
||||
typedef void *CXTranslationUnit; // A translation unit instance.
|
||||
typedef void *CXTranslationUnit; /* A translation unit instance. */
|
||||
|
||||
typedef void *CXCursor; // An opaque cursor into the CXTranslationUnit.
|
||||
typedef void *CXCursor; /* An opaque cursor into the CXTranslationUnit. */
|
||||
|
||||
// Cursors represent declarations and references (provides line/column info).
|
||||
/* Cursors represent declarations and references (provides line/column info). */
|
||||
enum CXCursorKind {
|
||||
CXCursor_Declaration,
|
||||
CXCursor_Reference,
|
||||
|
@ -49,9 +49,9 @@ enum CXCursorKind {
|
|||
CXCursor_ObjC_SelectorRef
|
||||
};
|
||||
|
||||
typedef void *CXDecl; // A specific declaration within a translation unit.
|
||||
typedef void *CXDecl; /* A specific declaration within a translation unit. */
|
||||
|
||||
enum CXDeclKind { // The various kinds of declarations.
|
||||
enum CXDeclKind { /* The various kinds of declarations. */
|
||||
CXDecl_any,
|
||||
CXDecl_typedef,
|
||||
CXDecl_enum,
|
||||
|
@ -73,12 +73,12 @@ enum CXDeclKind { // The various kinds of declarations.
|
|||
CXDecl_ObjC_property_implementation
|
||||
};
|
||||
|
||||
// A unique token for looking up "visible" CXDecls from a CXTranslationUnit.
|
||||
/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
|
||||
typedef void *CXEntity;
|
||||
|
||||
CXIndex clang_createIndex();
|
||||
|
||||
CXTranslationUnit clang_loadTranslationUnitFromASTFile(
|
||||
CXTranslationUnit clang_createTranslationUnit(
|
||||
CXIndex, const char *ast_filename
|
||||
);
|
||||
|
||||
|
@ -130,33 +130,35 @@ void clang_loadTranslationUnit(
|
|||
*/
|
||||
void clang_loadDeclaration(CXDecl, void (*callback)(CXDecl, CXCursor));
|
||||
|
||||
//
|
||||
// CXEntity Operations.
|
||||
//
|
||||
/*
|
||||
* CXEntity Operations.
|
||||
*/
|
||||
const char *clang_getDeclarationName(CXEntity);
|
||||
const char *clang_getURI(CXEntity);
|
||||
CXEntity clang_getEntity(const char *URI);
|
||||
//
|
||||
// CXDecl Operations.
|
||||
//
|
||||
/*
|
||||
* CXDecl Operations.
|
||||
*/
|
||||
CXCursor clang_getCursorFromDecl(CXDecl);
|
||||
CXEntity clang_getEntityFromDecl(CXDecl);
|
||||
enum CXDeclKind clang_getDeclKind(CXDecl);
|
||||
const char *clang_getDeclSpelling(CXDecl);
|
||||
//
|
||||
// CXCursor Operations.
|
||||
//
|
||||
/*
|
||||
* CXCursor Operations.
|
||||
*/
|
||||
CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
|
||||
unsigned line, unsigned column);
|
||||
|
||||
CXCursorKind clang_getCursorKind(CXCursor);
|
||||
enum CXCursorKind clang_getCursorKind(CXCursor);
|
||||
|
||||
unsigned clang_getCursorLine(CXCursor);
|
||||
unsigned clang_getCursorColumn(CXCursor);
|
||||
const char *clang_getCursorSource(CXCursor);
|
||||
|
||||
// If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
|
||||
// If CXCursorKind == Cursor_Declaration, then this will return the declaration.
|
||||
/*
|
||||
* If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
|
||||
* If CXCursorKind == Cursor_Declaration, then this will return the declaration.
|
||||
*/
|
||||
CXDecl clang_getCursorDecl(CXCursor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "clang/Index/GlobalSelector.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include <map>
|
||||
|
||||
namespace clang {
|
||||
|
@ -36,10 +37,13 @@ public:
|
|||
typedef std::map<Entity, TUSetTy> MapTy;
|
||||
typedef std::map<GlobalSelector, TUSetTy> SelMapTy;
|
||||
|
||||
explicit Indexer(Program &prog) : Prog(prog) { }
|
||||
explicit Indexer(Program &prog, FileManager &FM) :
|
||||
Prog(prog), FileMgr(FM) { }
|
||||
|
||||
Program &getProgram() const { return Prog; }
|
||||
|
||||
FileManager &getFileManager() const { return FileMgr; }
|
||||
|
||||
/// \brief Find all Entities and map them to the given translation unit.
|
||||
void IndexAST(TranslationUnit *TU);
|
||||
|
||||
|
@ -50,6 +54,8 @@ public:
|
|||
|
||||
private:
|
||||
Program &Prog;
|
||||
FileManager &FileMgr;
|
||||
|
||||
MapTy Map;
|
||||
CtxTUMapTy CtxTUMap;
|
||||
SelMapTy SelMap;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -14,4 +14,4 @@ _clang_getEntityFromDecl
|
|||
_clang_getURI
|
||||
_clang_loadDeclaration
|
||||
_clang_loadTranslationUnit
|
||||
_clang_loadTranslationUnitFromASTFile
|
||||
_clang_createTranslationUnit
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue