1 /* Test of cpp_callbacks::comments. */
3 #include "gcc-plugin.h"
8 #include "diagnostic.h"
9 #include "c-family/c-pragma.h"
11 int plugin_is_GPL_compatible
;
13 /* Test callback for cpp_callbacks::comments. */
16 my_comment_cb (cpp_reader
*, location_t loc
,
17 const unsigned char *content
, size_t len
)
19 if (in_system_header_at (loc
))
22 /* CONTENT contains the opening slash-star (or slash-slash),
23 and for C-style comments contains the closing star-slash. */
24 gcc_assert (len
>= 2);
25 gcc_assert (content
[0] == '/');
26 gcc_assert (content
[1] == '*' || content
[1] == '/');
27 bool c_style
= (content
[1] == '*');
30 gcc_assert (content
[len
- 2] == '*');
31 gcc_assert (content
[len
- 1] == '/');
35 inform (loc
, "got C-style comment; length=%i", len
);
37 inform (loc
, "got C++-style comment; length=%i", len
);
39 /* Print the content of the comment.
40 For a C-style comment, the buffer CONTENT contains the opening
41 slash-star and closing star-slash, so we can't directly verify
42 it in the DejaGnu test without adding another comment, which
43 would trigger this callback again.
44 Hence we skip the syntactically-significant parts of the comment
46 fprintf (stderr
, "stripped content of comment: >");
47 /* Avoid printing trailing star-slash. */
50 for (size_t i
= 2; i
< len
; i
++)
51 fputc (content
[i
], stderr
);
52 fprintf (stderr
, "<\n");
56 plugin_init (struct plugin_name_args
*plugin_info
,
57 struct plugin_gcc_version
*version
)
59 cpp_callbacks
*cb
= cpp_get_callbacks (parse_in
);
60 cb
->comment
= my_comment_cb
;