[cfe-dev] Matching function argument that may not be valid

Daniel Dilts diltsman at gmail.com
Thu Apr 23 10:43:37 PDT 2015


Yeah, I suspected as much.  Is there any real option for finding this
location?  Would I have to do it where it is building the AST?

On Thu, Apr 23, 2015 at 10:25 AM, Manuel Klimek <klimek at google.com> wrote:

> Ok, this only works on valid code. If you have errors, all bets are off.
>
> On Thu, Apr 23, 2015 at 7:23 PM Daniel Dilts <diltsman at gmail.com> wrote:
>
>>
>>
>> On Fri, Apr 17, 2015 at 5:19 PM, Manuel Klimek <klimek at google.com> wrote:
>>
>>>
>>>
>>> On Thu, Apr 16, 2015 at 5:45 PM Daniel Dilts <diltsman at gmail.com> wrote:
>>>
>>>> I am attempting to write a tool that will generate a table from tokens
>>>> pulled from source code.
>>>>
>>>> I have a static template function in a template class.  I want to find
>>>> the first argument for all calls to the template function.
>>>>
>>>> The problem is that the token may or may not be defined, since they
>>>> will be defined in a generated table.
>>>>
>>>> If I use dump-ast it appears that the function call is omitted from the
>>>> AST, so I don't think that I can use AST matchers to find it.
>>>>
>>>
>>> I somehow can't believe that - all calls are in the AST.
>>>
>>
>>
>> Here is my example, using "clang version 3.7.0 (trunk 235602)".  Note
>> that the call to Func is not present in the AST.
>>
>> enum MyEnum
>> {
>> };
>> void Func(MyEnum v);
>> int main()
>> {
>>  Func(SomeEnumValue);
>>  return 0;
>> }
>>
>>
>>
>>
>> clang.exe -Xclang -ast-dump test.cpp
>> test.cpp:7:7: error: use of undeclared identifier 'SomeEnumValue'
>>         Func(SomeEnumValue);
>>              ^
>> TranslationUnitDecl 0x836140 <<invalid sloc>> <invalid sloc>
>> |-CXXRecordDecl 0x836400 <<invalid sloc>> <invalid sloc> implicit class
>> type_inf
>> o
>> | `-TypeVisibilityAttr 0x836470 <<invalid sloc>> Implicit Default
>> |-TypedefDecl 0x8364b0 <<invalid sloc>> <invalid sloc> implicit size_t
>> 'unsigned
>>  int'
>> |-TypedefDecl 0x836508 <<invalid sloc>> <invalid sloc> implicit
>> __builtin_va_lis
>> t 'char *'
>> |-EnumDecl 0x836538 <test.cpp:1:1, line:3:1> line:1:6 referenced MyEnum
>> 'int'
>> |-FunctionDecl 0x836630 <line:4:1, col:19> col:6 Func 'void (enum MyEnum)'
>> | `-ParmVarDecl 0x8365b8 <col:11, col:18> col:18 v 'enum MyEnum'
>> `-FunctionDecl 0x836718 <line:5:1, line:9:1> line:5:5 main 'int (void)'
>>   `-CompoundStmt 0x836880 <line:6:1, line:9:1>
>>     `-ReturnStmt 0x836870 <line:8:2, col:9>
>>       `-IntegerLiteral 0x836850 <col:9> 'int' 01 error generated.
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150423/d6b642e5/attachment.html>


More information about the cfe-dev mailing list