CXIndex, const char *ast_filename
);
-const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
-
/*
Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
within a translation unit, issuing a 'callback' for each one.
class Preprocessor;
class ASTContext;
class Decl;
- class PCHReader;
/// \brief Utility class for loading a ASTContext from a PCH file.
///
llvm::OwningPtr<TargetInfo> Target;
llvm::OwningPtr<Preprocessor> PP;
llvm::OwningPtr<ASTContext> Ctx;
- llvm::OwningPtr<PCHReader> Reader;
ASTUnit(const ASTUnit&); // do not implement
ASTUnit &operator=(const ASTUnit &); // do not implement
const Diagnostic &getDiagnostic() const { return *Diags.get(); }
Diagnostic &getDiagnostic() { return *Diags.get(); }
- const std::string &getOriginalSourceFileName();
-
/// \brief Create a ASTUnit from a PCH file.
///
/// \param Filename PCH filename
} // anonymous namespace
-const std::string &ASTUnit::getOriginalSourceFileName() {
- return Reader->getOriginalSourceFile();
-}
ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
FileManager &FileMgr,
std::string Predefines;
unsigned Counter;
- llvm::OwningPtr<PCHReader> Reader;
+ llvm::OwningPtr<PCHReader> Reader;
llvm::OwningPtr<ExternalASTSource> Source;
Reader.reset(new PCHReader(SourceMgr, FileMgr, Diags));
- AST->Reader.reset(Reader.get());
Reader->setListener(new PCHInfoCollector(LangInfo, HeaderInfo, TargetTriple,
Predefines, Counter));
break;
}
}
- void VisitVarDecl(VarDecl *ND) {
- Call(CXCursor_VarDecl, ND);
- }
void VisitFunctionDecl(FunctionDecl *ND) {
Call(ND->isThisDeclarationADefinition() ? CXCursor_FunctionDefn
: CXCursor_FunctionDecl, ND);
CXClientData CData;
void Call(enum CXCursorKind CK, NamedDecl *ND) {
- // Disable the callback when the context is equal to the visiting decl.
- if (CDecl == ND)
- return;
CXCursor C = { CK, ND };
Callback(CDecl, C, CData);
}
void VisitFieldDecl(FieldDecl *ND) {
Call(CXCursor_FieldDecl, ND);
}
- void VisitVarDecl(VarDecl *ND) {
- Call(CXCursor_VarDecl, ND);
- }
- void VisitParmVarDecl(ParmVarDecl *ND) {
- Call(CXCursor_ParmDecl, ND);
- }
void VisitObjCPropertyDecl(ObjCPropertyDecl *ND) {
Call(CXCursor_ObjCPropertyDecl, ND);
}
void VisitObjCIvarDecl(ObjCIvarDecl *ND) {
Call(CXCursor_ObjCIvarDecl, ND);
}
- void VisitFunctionDecl(FunctionDecl *ND) {
- if (ND->isThisDeclarationADefinition()) {
- VisitDeclContext(dyn_cast<DeclContext>(ND));
- }
- }
void VisitObjCMethodDecl(ObjCMethodDecl *ND) {
if (ND->getBody()) {
Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDefn
: CXCursor_ObjCClassMethodDefn, ND);
- VisitDeclContext(dyn_cast<DeclContext>(ND));
+ // FIXME: load body.
} else
Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDecl
: CXCursor_ObjCClassMethodDecl, ND);
return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg);
}
-const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit)
-{
- assert(CTUnit && "Passed null CXTranslationUnit");
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
- return CXXUnit->getOriginalSourceFileName().c_str();
-}
void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
CXTranslationUnitIterator callback,
_clang_isDefinition
_clang_getCursorSpelling
_clang_getCursorKindSpelling
-_clang_getTranslationUnitSpelling
#include "clang-c/Index.h"
#include <stdio.h>
-static void PrintCursor(CXCursor Cursor) {
- printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
- clang_getCursorSpelling(Cursor));
- printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
- clang_getCursorLine(Cursor),
- clang_getCursorColumn(Cursor));
-}
-
static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
{
- printf("%s: ", clang_getDeclSpelling(Dcl));
- if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter))
- PrintCursor(Cursor);
+ if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
+ printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
+ clang_getCursorSpelling(Cursor));
+ printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
+ clang_getCursorLine(Cursor),
+ clang_getCursorColumn(Cursor));
+ }
}
-
static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
CXClientData Filter)
{
- printf("%s: ", clang_getTranslationUnitSpelling(Unit));
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
- PrintCursor(Cursor);
+ printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
+ clang_getCursorSpelling(Cursor));
+ printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
+ clang_getCursorLine(Cursor),
+ clang_getCursorColumn(Cursor));
clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
}