[PATCH] D115014: [clang] RFC: NFC: simplify macro tokens assignment

zhouyizhou via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 3 03:04:44 PST 2021


zhouyizhou added a comment.

In D115014#3169400 <https://reviews.llvm.org/D115014#3169400>, @simon_tatham wrote:

> I don't think so, I'm afraid. If you look at the definition of `MacroInfo::tokens_begin()` in `clang/include/clang/Lex/MacroInfo.h`, you see that it doesn't return a raw `Token *`: it returns a C++ iterator object.
>
>   using tokens_iterator = SmallVectorImpl<Token>::const_iterator;
>   
>   tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
>
> So you do have to dereference the iterator to get a `Token &`, and then address-take that to turn it into a `Token *`.

Thank Simon for reviewing my patch  ;-)

In llvm/include/llvm/ADT/SmallVector.h, I found  this: using const_iterator = const T *;

also I use gdb to print the return type of tokens_begin()
(gdb) ptype const_iterator
type = const class clang::Token {

...
} *

So, there still remains little puzzle in my head  ;-)

Thanks again
Zhouyi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115014



More information about the cfe-commits mailing list