This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: #import and PCH
Neil Booth <neil@daikokuya.co.uk> writes:
> Geoffrey Keating wrote:-
>
> >
> > #import worked by setting a flag bit on cpplib's hash table. This is
> > somewhat annoying from a PCH perspective, and is kind of ugly too.
>
> It's not that bad. Your patch adds a lot of code in comparison.
This isn't much code compared to what would be necessary to save and
restore the include file splay tree.
> > This patch changes the behaviour so that #import uses macro
> > definitions to track whether a header is included or not, and then
> > PCH works with it automatically.
>
> How about just removing #import? What about #pragma once?
#pragma once is a problem for another day.
> > + /* Construct the name of the (synthetic) guard macro.
> > + This shouldn't be a name that could cause conflicts with user
> > + macro names. */
>
> You don't need to use a real identifier. You could prepend it with a
> space, or anything other than "#".
I thought of that, but was worried it might cause trouble with -dM.
> > + unsigned char *guard_macro;
> > + size_t i, len;
> > + static const unsigned char head[] = "__CPP_IMPORT_";
> > +
> > + len = sizeof (head) + header->val.str.len * 2;
> > + guard_macro = alloca (len);
> > + memcpy (guard_macro, head, sizeof (head) - 1);
> > + if (header->type == CPP_HEADER_NAME)
> > + guard_macro[sizeof (head) - 1] = 'A';
> > + else
> > + guard_macro[sizeof (head) - 1] = 'S';
> > + for (i = 0; i < header->val.str.len; i++)
> > + {
> > + guard_macro[sizeof (head) + 2 * i] =
> > + 'A' + (header->val.str.text[i] & 0xF);
> > + guard_macro[sizeof (head) + 2 * i + 1] =
> > + 'a' + (header->val.str.text[i] >> 4 & 0xF);
> > + }
> > +
> > + /* If the macro isn't defined, define it (as a builtin macro,
> > + it's easier) and include the file. */
> > +
> > + if (! cpp_defined (pfile, guard_macro, len))
>
> I don't like that you've developed your own system of multiple
> include guard tracking here. It should use the same code as the other
> stuff.
That brings us back to saving and restoring the splay tree.
> What if #import <a.h> is followed by #include <a.h> ?
This is an intentional change.
> > + {
> > + cpp_hashnode *h = cpp_lookup (pfile, guard_macro, len);
> > + h->type = NT_MACRO;
> > + h->flags |= NODE_BUILTIN;
> > + h->value.builtin = BT_SPECLINE;
> > + do_include_common (pfile, IT_INCLUDE, header);
>
> Things being NODE_BUILTIN induce special behaviour in other parts of
> cpplib. Does this affect your macros?
Yes, but only in good ways. For instance, there are no warnings about
these macros being unused.
--
- Geoffrey Keating <geoffk@geoffk.org>