I was able to solve my problem by making sure to get the expansion location 
before calling getPreviousToken.

On Feb 17, 2020, at 5:42 PM, Lewis, Cannada 
<canl...@sandia.gov<mailto:canl...@sandia.gov>> wrote:

I am trying to use the getPreviousToken function from 
clang-tools-extra<https://github.com/llvm/llvm-project/tree/master/clang-tools-extra>/clang-tidy<https://github.com/llvm/llvm-project/tree/master/clang-tools-extra/clang-tidy>/utils<https://github.com/llvm/llvm-project/tree/master/clang-tools-extra/clang-tidy/utils>/LexerUtils.cpp,
 but am having issues when the SourceLocation comes from a macro.  Let’s say I 
have the following functions:

#include <Kokkos_Core.hpp>
#include <string>

// The macros are  defined such that KOKKOS_FUNCTION is empty and 
KOKKOS_INLINE_FUNCITON = “inline”

KOKKOS_FUNCTION
void useString(std::string const& s, int i){ }

KOKKOS_INLINE_FUNCTION
void useString2(std::string const& s, int i){ }

If I take the FunctionDecl for useString and use getBeginLoc, I will get a 
location that corresponds to the token void right before useString, I then use 
getPreviousToken to find the KOKKOS_FUNCTION macro and all is well.

But if I call getBeginLoc on useString2 my location starts off in the macro 
(I’m not really sure exactly what that means, my guess is that it starts on the 
inline keyword) and if I use that location for getPreviousToken, I don’t get 
the ‘}' from the line with useString, instead I get some location from other 
headers included in Kokkos_Core.hpp.  I don’t think that this is the intended 
behavior, but I don’t have a minimal working example at the moment. I did track 
it down to  where getPreviousToken calls getWithOffset(-1) on the source 
location and it is that new location which is the unexpected location.

Any help would be appreciated.

-Cannada Lewis

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

Reply via email to