Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Hi,
I am a novice developer hacking around ways to use clang for parsing C/CPP code.

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^



Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

Please let me know if I am doing anything bad or missing something.
The Makefile assumes that clang is installed in ~/llvm80



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

Main.cpp (4K) Download Attachment
test.cpp (216 bytes) Download Attachment
Main.mk (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Hi Keane,
Exactly my thoughts. But, how to do it?

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Hi,
On a second note, the code builds fine; but when I run the program it exits without any output. I added my own FunctionDecl visitor to MyRecursiveASTVisitor. I am guessing the code I am missing can be something to do with headers and methods which are tagged `XX` as prefix or suffix like, DeclXX.h or StmtXX.h or so.



On Fri, Jan 11, 2019 at 1:59 PM Aditya Atluri <[hidden email]> wrote:
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri


--
- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Attached updated source code.

On Fri, Jan 11, 2019 at 2:03 PM Aditya Atluri <[hidden email]> wrote:
Hi,
On a second note, the code builds fine; but when I run the program it exits without any output. I added my own FunctionDecl visitor to MyRecursiveASTVisitor. I am guessing the code I am missing can be something to do with headers and methods which are tagged `XX` as prefix or suffix like, DeclXX.h or StmtXX.h or so.



On Fri, Jan 11, 2019 at 1:59 PM Aditya Atluri <[hidden email]> wrote:
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri


--
- Aditya Atluri


--
- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

Main.cpp (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Sorry. My bad.
The code at line 100 should be MyASTConsumer than clang::ASTConsumer.
Thank you!

On Fri, Jan 11, 2019 at 2:03 PM Aditya Atluri <[hidden email]> wrote:
Attached updated source code.

On Fri, Jan 11, 2019 at 2:03 PM Aditya Atluri <[hidden email]> wrote:
Hi,
On a second note, the code builds fine; but when I run the program it exits without any output. I added my own FunctionDecl visitor to MyRecursiveASTVisitor. I am guessing the code I am missing can be something to do with headers and methods which are tagged `XX` as prefix or suffix like, DeclXX.h or StmtXX.h or so.



On Fri, Jan 11, 2019 at 1:59 PM Aditya Atluri <[hidden email]> wrote:
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri


--
- Aditya Atluri


--
- Aditya Atluri


--
- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
In reply to this post by Richard Smith via cfe-dev
Aditya,

In the call to setASTConsumer at line 99 should it not make an unique pointer of MyASTConsumer instead of clang::ASTConsumer?

ci.setASTConsumer(llvm::make_unique<clang::ASTConsumer>());

On Fri, Jan 11, 2019 at 6:04 PM Aditya Atluri via cfe-dev <[hidden email]> wrote:
Attached updated source code.

On Fri, Jan 11, 2019 at 2:03 PM Aditya Atluri <[hidden email]> wrote:
Hi,
On a second note, the code builds fine; but when I run the program it exits without any output. I added my own FunctionDecl visitor to MyRecursiveASTVisitor. I am guessing the code I am missing can be something to do with headers and methods which are tagged `XX` as prefix or suffix like, DeclXX.h or StmtXX.h or so.



On Fri, Jan 11, 2019 at 1:59 PM Aditya Atluri <[hidden email]> wrote:
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri


--
- Aditya Atluri


--
- Aditya Atluri
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
João Paulo L. de Carvalho
Computer Science |  IC-UNICAMP | Campinas , SP - Brazil

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Good eye! Fixed it. Thank you!

Hi,
When I run the program, I am seeing the Function add is being visited once (even though called twice). Attached test case and source code.
Here is the output from the program:

In HandleTopLevelDecl

Visiting Function add it has: 2 arguments

The argument types are: 

const T

const T

In HandleTopLevelDecl

Visiting Function foo it has: 0 arguments

The argument types are: 

In HandleTopLevelDecl

Visiting Function main it has: 0 arguments

The argument types are: 

In HandleTopLevelDecl

Visiting Function add it has: 2 arguments

The argument types are: 

const float

const float




On Fri, Jan 11, 2019 at 2:24 PM João Paulo Labegalini de Carvalho <[hidden email]> wrote:
Aditya,

In the call to setASTConsumer at line 99 should it not make an unique pointer of MyASTConsumer instead of clang::ASTConsumer?

ci.setASTConsumer(llvm::make_unique<clang::ASTConsumer>());

On Fri, Jan 11, 2019 at 6:04 PM Aditya Atluri via cfe-dev <[hidden email]> wrote:
Attached updated source code.

On Fri, Jan 11, 2019 at 2:03 PM Aditya Atluri <[hidden email]> wrote:
Hi,
On a second note, the code builds fine; but when I run the program it exits without any output. I added my own FunctionDecl visitor to MyRecursiveASTVisitor. I am guessing the code I am missing can be something to do with headers and methods which are tagged `XX` as prefix or suffix like, DeclXX.h or StmtXX.h or so.



On Fri, Jan 11, 2019 at 1:59 PM Aditya Atluri <[hidden email]> wrote:
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri


--
- Aditya Atluri


--
- Aditya Atluri
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
João Paulo L. de Carvalho
Computer Science |  IC-UNICAMP | Campinas , SP - Brazil


--
- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

Main.cpp (4K) Download Attachment
test.cpp (270 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

Richard Smith via cfe-dev
Aditya,

You are implementing VisitFunctionDecl, which visits only function declarations, and not uses (e.g.: call expressions).

If you are interested in call expressions you can either implement VisitCallExpr or use an AST Matcher (https://clang.llvm.org/docs/LibASTMatchersTutorial.html).

On Sat, Jan 12, 2019 at 1:58 PM Aditya Atluri <[hidden email]> wrote:
Good eye! Fixed it. Thank you!

Hi,
When I run the program, I am seeing the Function add is being visited once (even though called twice). Attached test case and source code.
Here is the output from the program:

In HandleTopLevelDecl

Visiting Function add it has: 2 arguments

The argument types are: 

const T

const T

In HandleTopLevelDecl

Visiting Function foo it has: 0 arguments

The argument types are: 

In HandleTopLevelDecl

Visiting Function main it has: 0 arguments

The argument types are: 

In HandleTopLevelDecl

Visiting Function add it has: 2 arguments

The argument types are: 

const float

const float




On Fri, Jan 11, 2019 at 2:24 PM João Paulo Labegalini de Carvalho <[hidden email]> wrote:
Aditya,

In the call to setASTConsumer at line 99 should it not make an unique pointer of MyASTConsumer instead of clang::ASTConsumer?

ci.setASTConsumer(llvm::make_unique<clang::ASTConsumer>());

On Fri, Jan 11, 2019 at 6:04 PM Aditya Atluri via cfe-dev <[hidden email]> wrote:
Attached updated source code.

On Fri, Jan 11, 2019 at 2:03 PM Aditya Atluri <[hidden email]> wrote:
Hi,
On a second note, the code builds fine; but when I run the program it exits without any output. I added my own FunctionDecl visitor to MyRecursiveASTVisitor. I am guessing the code I am missing can be something to do with headers and methods which are tagged `XX` as prefix or suffix like, DeclXX.h or StmtXX.h or so.



On Fri, Jan 11, 2019 at 1:59 PM Aditya Atluri <[hidden email]> wrote:
Great! The post helped me figure out the right sequence of syntax to use.
Here is how I figured it out. 
greped for LangOptions on clang/FrontEnd headers, found that CompilerInvocation takes LangOptions as an argument in one of its methods; CompilerInstance has a method to get its own instance of CompilerInvocation.



On Fri, Jan 11, 2019 at 1:26 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

https://stackoverflow.com/questions/38356485/how-do-i-put-clang-into-c-mode

 

From: Aditya Atluri [mailto:[hidden email]]
Sent: Friday, January 11, 2019 11:09 AM
To: Keane, Erich <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi Keane,

Exactly my thoughts. But, how to do it?

 

On Fri, Jan 11, 2019 at 1:05 PM Keane, Erich via cfe-dev <[hidden email]> wrote:

Those are typical of attempting to compile C++ code as C.  I’m not sure what the right way to set the LangOpts on CompilerInstance in libclang is, but you likely need to update those to set LangOpts correctly for the version of C++ you intend to support..

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Aditya Atluri via cfe-dev
Sent: Friday, January 11, 2019 11:02 AM
To: [hidden email]
Subject: [cfe-dev] Fwd: [LibTooling] Unable to parse cpp code when using libtooling feature

 

Hi,

I am a novice developer hacking around ways to use clang for parsing C/CPP code.

 

I am able to parse C code with clangs libtooling feature properly. But, when I use the code to parse CPP test code, I am getting the following error:

 

$ ./Main 

test.cpp:1:1: error: unknown type name 'template'

template<typename T>

^

test.cpp:1:9: error: expected identifier or '('

template<typename T>

        ^

test.cpp:6:19: error: expected expression

    float c = add<float>(a, b);

                  ^

test.cpp:6:15: error: use of undeclared identifier 'add'

    float c = add<float>(a, b);

              ^

 

 

Attached: Main.mk (to build test), Main.cpp (Clang 8.0 based libtooling source), test.cpp (test case)

 

Please let me know if I am doing anything bad or missing something.

The Makefile assumes that clang is installed in ~/llvm80

 

 

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


 

--

- Aditya Atluri

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
- Aditya Atluri


--
- Aditya Atluri


--
- Aditya Atluri
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


--
João Paulo L. de Carvalho
Computer Science |  IC-UNICAMP | Campinas , SP - Brazil


--
- Aditya Atluri


--
João Paulo L. de Carvalho
Computer Science |  IC-UNICAMP | Campinas , SP - Brazil

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev