[cfe-commits] r138860 - in /cfe/trunk: include/clang-c/Index.h tools/libclang/CIndex.cpp

Argyrios Kyrtzidis kyrtzidis at apple.com
Wed Aug 31 10:15:21 PDT 2011


On Aug 31, 2011, at 9:53 AM, Chandler Carruth wrote:

> Author: chandlerc
> Date: Wed Aug 31 11:53:37 2011
> New Revision: 138860
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=138860&view=rev
> Log:
> Update libclang to have APIs corresponding to the new 'expansion' naming
> system for macro-backed source locations. The old APIs are preserved for
> legacy users.

Could you please also update the python bindings ? The old APIs should be removed eventually.

-Argyrios

> 
> This was intended to land with the main work of instantiation ->
> expansion, but despite running it by Doug over a month ago, I forgot to
> commit it. Very sorry for that...
> 
> Modified:
>    cfe/trunk/include/clang-c/Index.h
>    cfe/trunk/tools/libclang/CIndex.cpp
> 
> Modified: cfe/trunk/include/clang-c/Index.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=138860&r1=138859&r2=138860&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang-c/Index.h (original)
> +++ cfe/trunk/include/clang-c/Index.h Wed Aug 31 11:53:37 2011
> @@ -263,7 +263,7 @@
>  * \brief Identifies a specific source location within a translation
>  * unit.
>  *
> - * Use clang_getInstantiationLocation() or clang_getSpellingLocation()
> + * Use clang_getExpansionLocation() or clang_getSpellingLocation()
>  * to map a source location to a particular file, line, and column.
>  */
> typedef struct {
> @@ -339,8 +339,8 @@
>  * \brief Retrieve the file, line, column, and offset represented by
>  * the given source location.
>  *
> - * If the location refers into a macro instantiation, retrieves the
> - * location of the macro instantiation.
> + * If the location refers into a macro expansion, retrieves the
> + * location of the macro expansion.
>  *
>  * \param location the location within a source file that will be decomposed
>  * into its parts.
> @@ -357,6 +357,20 @@
>  * \param offset [out] if non-NULL, will be set to the offset into the
>  * buffer to which the given source location points.
>  */
> +CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
> +                                               CXFile *file,
> +                                               unsigned *line,
> +                                               unsigned *column,
> +                                               unsigned *offset);
> +
> +/**
> + * \brief Legacy API to retrieve the file, line, column, and offset represented
> + * by the given source location.
> + *
> + * This interface has been replaced by the newer interface
> + * \see clang_getExpansionLocation(). See that interface's documentation for
> + * details.
> + */
> CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
>                                                    CXFile *file,
>                                                    unsigned *line,
> 
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=138860&r1=138859&r2=138860&view=diff
> ==============================================================================
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Wed Aug 31 11:53:37 2011
> @@ -2826,11 +2826,11 @@
> }
> 
> extern "C" {
> -void clang_getInstantiationLocation(CXSourceLocation location,
> -                                    CXFile *file,
> -                                    unsigned *line,
> -                                    unsigned *column,
> -                                    unsigned *offset) {
> +void clang_getExpansionLocation(CXSourceLocation location,
> +                                CXFile *file,
> +                                unsigned *line,
> +                                unsigned *column,
> +                                unsigned *offset) {
>   SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
> 
>   if (!location.ptr_data[0] || Loc.isInvalid()) {
> @@ -2840,11 +2840,11 @@
> 
>   const SourceManager &SM =
>     *static_cast<const SourceManager*>(location.ptr_data[0]);
> -  SourceLocation InstLoc = SM.getExpansionLoc(Loc);
> +  SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
> 
>   // Check that the FileID is invalid on the expansion location.
>   // This can manifest in invalid code.
> -  FileID fileID = SM.getFileID(InstLoc);
> +  FileID fileID = SM.getFileID(ExpansionLoc);
>   bool Invalid = false;
>   const SrcMgr::SLocEntry &sloc = SM.getSLocEntry(fileID, &Invalid);
>   if (!sloc.isFile() || Invalid) {
> @@ -2855,11 +2855,20 @@
>   if (file)
>     *file = (void *)SM.getFileEntryForSLocEntry(sloc);
>   if (line)
> -    *line = SM.getExpansionLineNumber(InstLoc);
> +    *line = SM.getExpansionLineNumber(ExpansionLoc);
>   if (column)
> -    *column = SM.getExpansionColumnNumber(InstLoc);
> +    *column = SM.getExpansionColumnNumber(ExpansionLoc);
>   if (offset)
> -    *offset = SM.getDecomposedLoc(InstLoc).second;
> +    *offset = SM.getDecomposedLoc(ExpansionLoc).second;
> +}
> +
> +void clang_getInstantiationLocation(CXSourceLocation location,
> +                                    CXFile *file,
> +                                    unsigned *line,
> +                                    unsigned *column,
> +                                    unsigned *offset) {
> +  // Redirect to new API.
> +  clang_getExpansionLocation(location, file, line, column, offset);
> }
> 
> void clang_getSpellingLocation(CXSourceLocation location,
> @@ -3531,10 +3540,9 @@
>     const char *IsDef = clang_isCursorDefinition(Result)? " (Definition)" : "";
>     CXSourceLocation ResultLoc = clang_getCursorLocation(Result);
> 
> -    clang_getInstantiationLocation(Loc, &SearchFile, &SearchLine, &SearchColumn,
> -                                   0);
> -    clang_getInstantiationLocation(ResultLoc, &ResultFile, &ResultLine, 
> -                                   &ResultColumn, 0);
> +    clang_getExpansionLocation(Loc, &SearchFile, &SearchLine, &SearchColumn, 0);
> +    clang_getExpansionLocation(ResultLoc, &ResultFile, &ResultLine,
> +                               &ResultColumn, 0);
>     SearchFileName = clang_getFileName(SearchFile);
>     ResultFileName = clang_getFileName(ResultFile);
>     KindSpelling = clang_getCursorKindSpelling(Result.kind);
> @@ -3556,8 +3564,8 @@
>                                 = clang_getCursorKindSpelling(Definition.kind);
>       CXFile DefinitionFile;
>       unsigned DefinitionLine, DefinitionColumn;
> -      clang_getInstantiationLocation(DefinitionLoc, &DefinitionFile, 
> -                                     &DefinitionLine, &DefinitionColumn, 0);
> +      clang_getExpansionLocation(DefinitionLoc, &DefinitionFile,
> +                                 &DefinitionLine, &DefinitionColumn, 0);
>       CXString DefinitionFileName = clang_getFileName(DefinitionFile);
>       fprintf(stderr, "  -> %s(%s:%d:%d)\n",
>               clang_getCString(DefinitionKindSpelling),
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list