[cfe-dev] Fwd: I am trying to using clang to do autocomplete, How to go to declaration of a macro?

罗勇刚(Yonggang Luo) via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 23 04:45:17 PST 2016


I am interested in the location of that macro:( because I want to implement
go to definition directly by calling to clang.exe.

On Wed, Nov 23, 2016 at 8:38 PM, Alex L <arphaman at gmail.com> wrote:

>
>
> On 23 November 2016 at 12:11, 罗勇刚(Yonggang Luo) <luoyonggang at gmail.com>
> wrote:
>
>> Thanks a lot, Alex.
>> I am trying to do that in command line:) how to do that?
>> I meas clang.exe driver:)
>>
>
> As far as I know you can't query about the definition of a macro with
> command line and clang, but you can list all the macro definitions by using
> "clang -dM -E foo.cpp". This might work for you if you're just interested
> in the text of the macro definition, since you can search for a macro like "FOO"
> in that list.
>
>
>>
>>
>> On Wed, Nov 23, 2016 at 7:39 PM, Alex L <arphaman at gmail.com> wrote:
>>
>>> I'm not sure that I understood your question correctly, but if you are
>>> working on auto completion then you can use Preprocessor::getMacroDefinition
>>> to lookup the definition of a some macro. Specifically, as long as you're
>>> working with Sema, you can use code similar to the one below:
>>>
>>>   for (const auto &M : PP.macros()) {
>>>     auto MD = PP.getMacroDefinition(M->first);
>>>     if (MD) {
>>>       // you have access to macro definition here and can lookup it's
>>> source location
>>>       // by using MD.getMacroInfo()->getDefinitionLoc()
>>>     }
>>>   }
>>>
>>> Alex
>>>
>>> On 23 November 2016 at 11:00, 罗勇刚(Yonggang Luo) via cfe-dev <
>>> cfe-dev at lists.llvm.org> wrote:
>>>
>>>>
>>>> ---------- Forwarded message ----------
>>>> From: 罗勇刚(Yonggang Luo) <luoyonggang at gmail.com>
>>>> Date: Wed, Nov 23, 2016 at 6:58 PM
>>>> Subject: I am trying to using clang to do autocomplete, How to go to
>>>> declaration of a macro?
>>>> To: Clang Dev <cfe-dev at cs.uiuc.edu>
>>>>
>>>>
>>>> For exmaple
>>>>
>>>> #define FOO 0
>>>>
>>>> int foo() {
>>>>   int x = FOO; /* How to go to decleration of FOO here? *./
>>>> }
>>>>
>>>> --
>>>>          此致
>>>>>>>> 罗勇刚
>>>> Yours
>>>>     sincerely,
>>>> Yonggang Luo
>>>>
>>>>
>>>>
>>>> --
>>>>          此致
>>>>>>>> 罗勇刚
>>>> Yours
>>>>     sincerely,
>>>> Yonggang Luo
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>
>>
>>
>> --
>>          此致
>>>> 罗勇刚
>> Yours
>>     sincerely,
>> Yonggang Luo
>>
>
>


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161123/27a05182/attachment.html>


More information about the cfe-dev mailing list