Re: [cfe-users] Missing AST Node for parsing code with std::vector::data()

2020-12-14 Thread Richard Smith via cfe-users
On Thu, 3 Dec 2020 at 04:02, Владимир Фролов via cfe-users <
cfe-users@lists.llvm.org> wrote:

> Greetings! I'm using clang for source-to-source translation.
>
> Recently I got a problem with parsing code which use templates.
> First, here is the working example:
>
> struct MyTestVector2
> {
>  unsigned int _data[6];
>  unsigned int * data() { return &_data[0]; }
> };
> ...
> MyTestVector2 testData2;
> kernel_TestColor(&hit,
> testData2.data(), tidX, tidY);
> This code processed normally and i gon correct "CXXMemberCallExpr" node
> for kernel_TestColor which i actually need.
> Then i changed MyTestVector2 to template:
>
> template
> struct MyTestVector2
> {
>  T _data[6];
>  T * data() { return &_data[0]; }
> };
>
> ...
> MyTestVector2 testData2;
> kernel_TestColor(&hit,
> testData2.data(), tidX, tidY);
>
> This time i got
>
> `-DeclStmt 0x5816e128 
>   `-VarDecl 0x5816e0c0  col:31 invalid testData2
> 'MyTestVector2':'MyTestVector2'
>
> This time, The AST node for kernel_TestColor is just missed!
> The code is absolutely correct itself, it can be build and run.
>

What interface are you using to parse the code with Clang? (libclang?
libTooling? Direct use of the C++ API?)

The above AST dump shows that Clang thinks the declaration of the variable
'testData2' is invalid (see the "invaild" in the declaration). Clang should
also have produced a diagnostic message explaining this, but some of the
ways of using Clang as a library don't set up a diagnostic consumer by
default, meaning that error message is just being thrown away. If you set
up a diagnostic consumer, Clang should tell you what's going wrong.

I suspect the problem is either something you elided in the above code or
it's an issue with the compilation flags in use, because the above example
in isolation looks fine.


> I'm using AST processing for code generation, so it is important for me to
> get  AST node for kernel_TestColor and then analyze its arguments.
> I understand that this seems to be not a bug, but ... may be, there is a
> way to make parser more tolerant to data types ... because what i actually
> need is just a strings of all parameters, so, just having "
> testData2.data()" at some level of AST for the second parameter of 
> kernel_TestColor
> would be enough for me.
>
> I would be appretiate for help or advice.
> Currently i use llvm 10.
> Thanks!
> --
> Best Regards,
>  Frolov V.A.
>
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


[cfe-users] (closed) Missing AST Node for parsing code with std::vector::data()

2020-12-14 Thread Владимир Фролов via cfe-users
Richard, thank you very much for the answer! >>I suspect the problem is either something you elided in the above code or it's an issue with the compilation flags in use, because the above example in isolation looks fineYes, exactly! In fact David already helps me to find the problem )Sorry i didnt wrote it here, used such mailing list first time! I have create a minimal example which helps me to catch itIt seems that i have specified language options too late ... : data/input.cpp:1:10: error: unknown type name 'class'template https://github.com/FROL256/clang_parse_ast_example/blob/main/main.cpp (lines 162--170, wrong way, too late)(lines 148--155, right way, works) I think that in my main project i didn't got such error message (unknown type name 'class') due to other errors related to missed includes.After I add some stl types definition and some functions from  to processed source code,  then finally i got AST parsed correcty. Thank you very much, clang is awesome!  15.12.2020, 10:15, "Richard Smith" :On Thu, 3 Dec 2020 at 04:02, Владимир Фролов via cfe-users  wrote:Greetings! I'm using clang for source-to-source translation. Recently I got a problem with parsing code which use templates.First, here is the working example: struct MyTestVector2{ unsigned int _data[6]; unsigned int * data() { return &_data[0]; }};... MyTestVector2 testData2;kernel_TestColor(&hit,                 testData2.data(), tidX, tidY);This code processed normally and i gon correct "CXXMemberCallExpr" node for kernel_TestColor which i actually need.Then i changed MyTestVector2 to template: templatestruct MyTestVector2{ T _data[6]; T * data() { return &_data[0]; }}; ...MyTestVector2 testData2;kernel_TestColor(&hit,                testData2.data(), tidX, tidY); This time i got `-DeclStmt 0x5816e128   `-VarDecl 0x5816e0c0  col:31 invalid testData2 'MyTestVector2':'MyTestVector2' This time, The AST node for kernel_TestColor is just missed!The code is absolutely correct itself, it can be build and run. What interface are you using to parse the code with Clang? (libclang? libTooling? Direct use of the C++ API?) The above AST dump shows that Clang thinks the declaration of the variable 'testData2' is invalid (see the "invaild" in the declaration). Clang should also have produced a diagnostic message explaining this, but some of the ways of using Clang as a library don't set up a diagnostic consumer by default, meaning that error message is just being thrown away. If you set up a diagnostic consumer, Clang should tell you what's going wrong. I suspect the problem is either something you elided in the above code or it's an issue with the compilation flags in use, because the above example in isolation looks fine.  I'm using AST processing for code generation, so it is important for me to get  AST node for kernel_TestColor and then analyze its arguments.I understand that this seems to be not a bug, but ... may be, there is a way to make parser more tolerant to data types ... because what i actually need is just a strings of all parameters, so, just having "testData2.data()" at some level of AST for the second parameter of kernel_TestColor would be enough for me. I would be appretiate for help or advice.Currently i use llvm 10.Thanks!-- Best Regards, Frolov V.A. ___cfe-users mailing listcfe-users@lists.llvm.orghttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users  -- С уважением,Фролов В. А. ___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users