AST Parsing in C/C++ files

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

AST Parsing in C/C++ files

Vassil Vassilev via cfe-dev
Hello all,

My question is quite simple, not sure about the complexity of the explanation: the AST generated for a file when having .c extension vs when it has .cc is different even having the same content, is there a reason for this behavior? I am building a tool that needs parsing C/C++ files so I have files with the extension .c, .cc, .cpp. All .c and .cpp seem to work properly, but not the .cc files. I have tried those .c files working to change the extension to .cc and they stop working; so there is something that I do not understand. The reason is that, probably, I am missing or misunderstanding something.
Thank you.

Kind regards,


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

Re: AST Parsing in C/C++ files

Vassil Vassilev via cfe-dev

.cc is typically a C++ extension, so they are being parsed as C++ files.  The AST ends up being different because the rules/meaning of the code changes slightly (less slightly in some cases!) with the language.

 

You can force the language to be C or C++ with the command line: ā€œ-x cā€ or ā€œ-x c++ā€

 

From: cfe-dev <[hidden email]> On Behalf Of Marcos Horro via cfe-dev
Sent: Friday, June 12, 2020 4:40 AM
To: [hidden email]
Subject: [cfe-dev] AST Parsing in C/C++ files

 

Hello all,

 

My question is quite simple, not sure about the complexity of the explanation: the AST generated for a file when having .c extension vs when it has .cc is different even having the same content, is there a reason for this behavior? I am building a tool that needs parsing C/C++ files so I have files with the extension .c, .cc, .cpp. All .c and .cpp seem to work properly, but not the .cc files. I have tried those .c files working to change the extension to .cc and they stop working; so there is something that I do not understand. The reason is that, probably, I am missing or misunderstanding something.

Thank you.

 

Kind regards,

 


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

Re: AST Parsing in C/C++ files

Vassil Vassilev via cfe-dev
In reply to this post by Vassil Vassilev via cfe-dev


Note also that the AST changes with dialect (c++11 etc).

Thanks,

Stephen.

On 12/06/2020 12:40, Marcos Horro via cfe-dev wrote:
Hello all,

My question is quite simple, not sure about the complexity of the explanation: the AST generated for a file when having .c extension vs when it has .cc is different even having the same content, is there a reason for this behavior? I am building a tool that needs parsing C/C++ files so I have files with the extension .c, .cc, .cpp. All .c and .cpp seem to work properly, but not the .cc files. I have tried those .c files working to change the extension to .cc and they stop working; so there is something that I do not understand. The reason is that, probably, I am missing or misunderstanding something.
Thank you.

Kind regards,


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

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