[cfe-dev] Right parenthesis of a condition.

Alexey Knyshev via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 28 03:54:45 PST 2018


What you get is RAW (preprocessed) source file with original line mappings.
Clang should know how to deal with such marked files but probably you have
to tweak something (flags or whatever). Anyway, I'm not expect in clang
default build pipeline ( preprocessing => compilation => linking) so
probably someone with such experience could shed a bit more light on it.

Regards, Alexey K

2018-02-28 14:08 GMT+03:00 Dorian Haglund <dorian.haglund at gmail.com>:

> Thanks for your help Alexey.
>
> It made me realize that I forgot a very important step of my problem:
>
> Before giving the file to be monitored to clang, we preprocess the source
> with gcc.
>
> Which means that is if the original source file /tmp/test.c is:
>
> #include <stdlib.h>
>
> int main()
> {
>   int* a = 0;
>   if (a != NULL)
>     return 1;
>   return 0;
> }
>
>
> Clang would receive (I only pasted the last 15 lines) :
>
> # 2 "/tmp/test.c" 2
>
>
> # 3 "/tmp/test.c"
> int main()
> {
>   int* a = 0;
>   if (a !=
> # 6 "/tmp/test.c" 3 4
>           ((void *)0)
> # 6 "/tmp/test.c"
>               )
>     return 1;
>   return 0;
> }
>
> In that case, I would like to get the location of the enclosing
> parenthesis for the 'IfStmt' (the one just before the 'return 1;'). I tried
> to toy with the lexer to get it but with no success.
> Do you have any idea ?
>
> Best regards
>
>
> 2018-02-28 10:21 GMT+01:00 Alexey Knyshev <alexey.knyshev at gmail.com>:
>
>> Hi Dorian,
>>
>> Hope it would be helpful:
>> https://stackoverflow.com/a/24223347
>>
>> Regards, Alexey K
>>
>> 2018-02-28 12:11 GMT+03:00 Dorian Haglund via cfe-dev <
>> cfe-dev at lists.llvm.org>:
>>
>>> Hello,
>>>
>>> I'm using the clang library to monitor (among other things) the if
>>> statements in my program.
>>>
>>> i need to get the location of the right parenthesis of the condition of
>>> the if (and while) statements.
>>>
>>> I've tried things such as:
>>>
>>> auto condLocEnd = statement->getCond()->getLocEnd();auto condLoc = Lexer::findLocationAfterToken(condLocEnd, tok::r_paren, sm, LangOptions(), false);
>>>
>>> Unfortunately condLoc is invalid when the condition contains a macro.
>>> Eg: if(p == NULL). I can't figure out how to get the location of the
>>> right parenthesis.
>>>
>>> Do you know how to get it ? If it is not possible, could you explain why
>>> ?
>>> Best regards,
>>>
>>>
>>> --
>>> Dorian Haglund
>>>
>>> _______________________________________________
>>> 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
>>
>
>
>
> --
> Dorian Haglund
>



-- 
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/20180228/f3887980/attachment.html>


More information about the cfe-dev mailing list