[PATCH] D159086: Change begin of macro in translateSourceRange in libclang

2023-08-29 Thread Christoph Busold via Phabricator via cfe-commits
quic-cbusold created this revision.
quic-cbusold added a reviewer: klimek.
Herald added a subscriber: arphaman.
Herald added a project: All.
quic-cbusold requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently translateSourceRange changes the end location in case of
a macro. When getting the source location for a macro invocation
it therefore returns the beginning of the macro definition with
the end of the macro invocation (with everything inbetween). This
change makes it return only the location of the macro invocation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159086

Files:
  clang/tools/libclang/CIndex.cpp


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -151,11 +151,13 @@
   const CharSourceRange &R) {
   // We want the last character in this location, so we will adjust the
   // location accordingly.
+  SourceLocation BeginLoc = R.getBegin();
   SourceLocation EndLoc = R.getEnd();
   bool IsTokenRange = R.isTokenRange();
   if (EndLoc.isValid() && EndLoc.isMacroID() &&
   !SM.isMacroArgExpansion(EndLoc)) {
 CharSourceRange Expansion = SM.getExpansionRange(EndLoc);
+BeginLoc = Expansion.getBegin();
 EndLoc = Expansion.getEnd();
 IsTokenRange = Expansion.isTokenRange();
   }
@@ -166,7 +168,7 @@
   }
 
   CXSourceRange Result = {
-  {&SM, &LangOpts}, R.getBegin().getRawEncoding(), 
EndLoc.getRawEncoding()};
+  {&SM, &LangOpts}, BeginLoc.getRawEncoding(), EndLoc.getRawEncoding()};
   return Result;
 }
 


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -151,11 +151,13 @@
   const CharSourceRange &R) {
   // We want the last character in this location, so we will adjust the
   // location accordingly.
+  SourceLocation BeginLoc = R.getBegin();
   SourceLocation EndLoc = R.getEnd();
   bool IsTokenRange = R.isTokenRange();
   if (EndLoc.isValid() && EndLoc.isMacroID() &&
   !SM.isMacroArgExpansion(EndLoc)) {
 CharSourceRange Expansion = SM.getExpansionRange(EndLoc);
+BeginLoc = Expansion.getBegin();
 EndLoc = Expansion.getEnd();
 IsTokenRange = Expansion.isTokenRange();
   }
@@ -166,7 +168,7 @@
   }
 
   CXSourceRange Result = {
-  {&SM, &LangOpts}, R.getBegin().getRawEncoding(), EndLoc.getRawEncoding()};
+  {&SM, &LangOpts}, BeginLoc.getRawEncoding(), EndLoc.getRawEncoding()};
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D159086: Change begin of macro in translateSourceRange in libclang

2023-09-04 Thread Christoph Busold via Phabricator via cfe-commits
quic-cbusold abandoned this revision.
quic-cbusold added a comment.

This does not work. Need more debugging on my end.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159086/new/

https://reviews.llvm.org/D159086

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits