[cfe-dev] Get name of MemberExpr expression

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 8 15:50:17 PST 2017


If all you want is a string, you might also consider using 
Stmt::printPretty().

This is rarely what people actually want though. Usually assuring that 
this is the kind of expression you're looking for might be necessary as 
well, i.e. the thing after the dot is actually a variable.

On 12/7/17 12:53 AM, Qiufeng Yu via cfe-dev wrote:
> With getBase(), I will get an Expr, but how do I get the actual base? 
> In other words, all I want is a string "blockIdx" so that I can 
> perform something like
> if(string == "blockIdx"){
>     Rewrite.replaceText()......
> }
>
> On Thu, Dec 7, 2017 at 3:49 AM, Aleksei Sidorin <a.sidorin at samsung.com 
> <mailto:a.sidorin at samsung.com>> wrote:
>
>     Hello,
>
>     You can use getBase() method to retrieve 'blockIdx' and
>     getMemberDecl() to find out what declaration is being referred.
>
>     07.12.2017 11:40, Qiufeng Yu via cfe-dev пишет:
>>     Hi all,
>>
>>     I'm new to clang and currently working on a project where I need
>>     to rewrite some codes in CUDA source file.
>>
>>     For example, if I have the following CUDA code:
>>
>>     int bx = blockIdx.x;
>>     int by = blockIdx.y;
>>
>>     I want to rewrite the blockIdx and blockIdx.x and blockIdx.y to
>>     some other code:
>>     int bx = something else;
>>     int by = something else;
>>
>>     My problem is that how do I find the MemberExpr blockIdx,x and
>>     blockIdx.y?
>>
>>     I know how to get the MemberExpr, but I have no clue how to
>>     extract the name of the MemberExpr in order to know that it is
>>     the right MemberExpr for me to rewrite.
>>
>>     Any help is appreciated.
>>
>>
>>     Patrick
>>
>>
>>     _______________________________________________
>>     cfe-dev mailing list
>>     cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>     http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>     <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
>
>
>     -- 
>     Best regards,
>     Aleksei Sidorin,
>     SRR, Samsung Electronics
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list