From: Douglas Gregor Date: Mon, 18 Jan 2010 22:13:09 +0000 (+0000) Subject: Clean up the CIndex API slightly. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c7313d96cd4a18cd8c1fcd3ddd8128c2fcbe58f;p=clang Clean up the CIndex API slightly. Renamed CXSourceFileLine to CXSourceLocation and added a CXFile, to better match Clang's SourceLocation. Teach clang_getDeclExtent to fill in the CXFile properly. Renamed CXSourceExtent to CXSourceRange, to better match Clang's SourceLocation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93783 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index c7b0a5197c..380dec7796 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -339,22 +339,34 @@ CINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl); CINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */ CINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl); -typedef struct CXSourceLineColumn { +/** + * \brief Identifies a specific source location given its file, line, and + * column. + */ +typedef struct { + CXFile file; unsigned line; unsigned column; -} CXSourceLineColumn; +} CXSourceLocation; -typedef struct CXDeclExtent { - CXSourceLineColumn begin; - CXSourceLineColumn end; -} CXSourceExtent; +/** + * \brief Identifies a range of source locations identified by the starting and + * ending locations of that range. + * + * The \c begin location points to the first character in the range and the + * \c end location points to the last character in the range. + */ +typedef struct { + CXSourceLocation begin; + CXSourceLocation end; +} CXSourceRange; /* clang_getDeclExtent() returns the physical extent of a declaration. The * beginning line/column pair points to the start of the first token in the * declaration, and the ending line/column pair points to the last character in * the last token of the declaration. */ -CINDEX_LINKAGE CXSourceExtent clang_getDeclExtent(CXDecl); +CINDEX_LINKAGE CXSourceRange clang_getDeclExtent(CXDecl); /* * CXCursor Operations. diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index c5c7409ffc..a11f54b879 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -643,7 +643,7 @@ unsigned clang_getDeclColumn(CXDecl AnonDecl) { return SourceMgr.getSpellingColumnNumber(ND->getLocation()); } -CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) { +CXSourceRange clang_getDeclExtent(CXDecl AnonDecl) { assert(AnonDecl && "Passed null CXDecl"); NamedDecl *ND = static_cast(AnonDecl); SourceManager &SM = ND->getASTContext().getSourceManager(); @@ -653,7 +653,7 @@ CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) { SourceLocation End = SM.getInstantiationLoc(R.getEnd()); if (!Begin.isValid()) { - CXDeclExtent extent = { { 0, 0 }, { 0, 0 } }; + CXSourceRange extent = { { 0, 0, 0 }, { 0, 0, 0 } }; return extent; } @@ -691,8 +691,9 @@ CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) { } // Package up the line/column data and return to the caller. - CXDeclExtent extent = { { StartLineNo, StartColNo }, - { EndLineNo, EndColNo } }; + const FileEntry *FEntry = SM.getFileEntryForID(SM.getFileID(Begin)); + CXSourceRange extent = { { (void *)FEntry, StartLineNo, StartColNo }, + { (void *)FEntry, EndLineNo, EndColNo } }; return extent; } diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index db95644c4c..e3d6ad88bb 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -74,7 +74,7 @@ static const char* GetCursorSource(CXCursor Cursor) { static const char *FileCheckPrefix = "CHECK"; static void PrintDeclExtent(CXDecl Dcl) { - CXSourceExtent extent; + CXSourceRange extent; if (!Dcl) return; extent = clang_getDeclExtent(Dcl);