* PLUGIN_FINISH_TYPE for incomplete types and enums
@ 2021-12-17 11:51 mbndr
0 siblings, 0 replies; only message in thread
From: mbndr @ 2021-12-17 11:51 UTC (permalink / raw)
To: gcc-help
Hello,
I'm developing an analysis plugin for C++ code in GCC andwanted to get
all types in a source unit (class, struct, enum, union) but my code does
not work for enums and incomplete types.
1) Is there a way to get incomplete types instead of an error_mark_node?
My expected behavior: I can check that with COMPLETE_TYPE_P
2) Is there a way to also get enums working?
There was a patch in 2015
(https://gcc.gnu.org/legacy-ml/gcc-patches/2015-02/msg00016.html) but it
doesn't seem to work for me.
Plugin code simplified (plugin.cpp):
```cpp
#include "gcc-plugin.h"
#include "plugin.h"
#include "tree.h"
#include <cstdio>
int plugin_is_GPL_compatible;
static void cb_type(void *gcc_data, void *user_data)
{
tree type = (tree) gcc_data;
if (type == error_mark_node) {
fprintf(stderr, "error handling type\n");
return;
}
const char *name = IDENTIFIER_POINTER(DECL_NAME(TYPE_NAME(type)));
fprintf(stderr, "found type: %s\n", name);
}
int plugin_init(plugin_name_args *plugin_info, plugin_gcc_version *version)
{
register_callback(plugin_info->base_name, PLUGIN_FINISH_TYPE,
cb_type, NULL);
return 0;
}
```
Test file (test.cpp):
```cpp
class incomplete;
class clazz {};
enum my_enum { ITEM };
enum class my_enum_class { ITEM };
```
Compilation and running test:
```sh
$ g++ -shared -I$(gcc -print-file-name=plugin)/include -fPIC -fno-rtti
-O2 plugin.cpp -o plugin.so
$ gcc -c -Wall -Wextra -fplugin=./plugin.so test.cpp
error handling type
found type: clazz
```
The "error handling type" refers to the incomplete class.
I'm using GCC 11.1.0 but tested it also on 5, 6, 7, 9, 10.
I am grateful for any help. Thanks in advance.
Maxi
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-12-17 11:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 11:51 PLUGIN_FINISH_TYPE for incomplete types and enums mbndr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).