[cfe-dev] How to get the StringLiteral EndLocation of the last token

chiasa.men via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 1 08:35:40 PDT 2021


Sorry, that was a quick one:
 Lexer::getLocForEndOfToken (pLiteral->getStrTokenLoc (parts-1),0,SM,LO) 
seems to work


On Mittwoch, 1. September 2021 17:26:40 CEST chiasa.men via cfe-dev wrote:
> The EndLoc of StringLiteral is the Loc returned by
> getStrTokenLoc(getNumConcatenated()-1).
> I understand that #6 concats the String tokens and the AST matcher gets the
> already concatenated string.
> 
> How do I know where the actual end (in the source file) is?
> 
> Example
> 
> Test:
> #define testmacro L"testexpansion"
> int main(int argc, char** argv) {
> auto test=testmacro L"append";
> }
> ‚Äč
> In the Matcher:
>   llvm::dbgs()<<"Range:"<<pLiteral->getBeginLoc().printToString(SM)<<",
> "<<pLiteral->getEndLoc().printToString(SM)<<"\n";
>   for (unsigned i = 0; i<pLiteral->getNumConcatenated();++i){
>     llvm::dbgs()<<"getStrTokenLoc "<<i<<"\n";
>     pLiteral->getStrTokenLoc(i).dump(SM);
>   }
> 
> output:
> Range:3:15 <Spelling=1:19>, :3:25
> getStrTokenLoc 0
> 
> :3:15 <Spelling=:1:19>
> 
> // which is !testmacro L"append";
> getStrTokenLoc 1
> 
> :3:25
> 
> // which is testmacro !L"append";
> 
> What I would need is this location:  testmacro L"append"!; (34)
> 
> What can I do to get the "actual" end of the StringLiteral in the
> SourceFile. Is there some kind of callback "onStringConcat" or a supposed
> way for this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210901/d5bb35c3/attachment.html>


More information about the cfe-dev mailing list