[cfe-dev] Get name of MemberExpr expression

Alexey Knyshev via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 7 03:19:20 PST 2017


You should not check RecordDecl in this manner as soon as it MemberExpr is
"composite". I mean you should separately check base & memberDecl.

According to docs for MeberExpr::getMemberDecl
<https://clang.llvm.org/doxygen/classclang_1_1MemberExpr.html#a66dc522ec5732b5e4a1a90bdfe70919f>
The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.

2017-12-07 12:21 GMT+03:00 Qiufeng Yu <qyu4 at ncsu.edu>:

> I can also use the ASTMatcher to find all MemberExprs, but still can't
> narrow them down to those only called blockIdx.x and blockIdx.y.
> My Matcher is following:
>
> Matcher.addMatcher(memberExpr(hasObjectExpression(hasType(
> cxxRecordDecl(hasName("blockIdx.x"))))));
> Matcher.addMatcher(memberExpr(hasObjectExpression(hasType(
> cxxRecordDecl(hasName("blockIdx.y"))))));
>
> On Thu, Dec 7, 2017 at 3:55 AM, Qiufeng Yu <qyu4 at ncsu.edu> wrote:
>
>> Say the original code is int bx = blockIdx.x, I already found the
>> MemberExpr of this line of code, which is blockIdx.x. But all I have is
>> only this MemberExpr. What I need is the actual string representation of
>> this MemberExpr so that I can perform the string comparison to make sure
>> that this MemberExpr is indeed blockIdx.x, and perform the rewriting
>> process.
>>
>> On Thu, Dec 7, 2017 at 3:48 AM, Alexey Knyshev <alexey.knyshev at gmail.com>
>> wrote:
>>
>>> Hi,
>>> Do you mean finding AST corresponding to MemberExpr or you already found
>>> then and trying to figure out SourceLocation for them?
>>>
>>> Regards, Alexey K
>>>
>>> 2017-12-07 11:40 GMT+03:00 Qiufeng Yu via cfe-dev <
>>> cfe-dev at lists.llvm.org>:
>>>
>>>> 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
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>
>>>
>>> --
>>> linkedin.com/profile
>>> <https://www.linkedin.com/profile/view?id=AAMAABn6oKQBDhBteiQnWsYm-S9yxT7wQkfWhSw>
>>>
>>> github.com/alexeyknyshev
>>> bitbucket.org/alexeyknyshev
>>>
>>
>>
>


-- 
linkedin.com/profile
<https://www.linkedin.com/profile/view?id=AAMAABn6oKQBDhBteiQnWsYm-S9yxT7wQkfWhSw>

github.com/alexeyknyshev
bitbucket.org/alexeyknyshev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171207/53818f1f/attachment.html>


More information about the cfe-dev mailing list