static int save_macros (cpp_reader *, cpp_hashnode *, void *);
/* This structure represents a macro definition on disk. */
-struct macrodef_struct
+struct macrodef_struct
{
unsigned int definition_length;
unsigned short name_length;
unsigned short flags;
};
-/* This is how we write out a macro definition.
+/* This is how we write out a macro definition.
Suitable for being called by cpp_forall_identifiers. */
static int
case NT_VOID:
if (! (hn->flags & NODE_POISONED))
return 1;
-
+
case NT_MACRO:
if ((hn->flags & NODE_BUILTIN))
return 1;
defn = NODE_NAME (hn);
s.definition_length = s.name_length;
}
-
+
if (fwrite (&s, sizeof (s), 1, f) != 1
|| fwrite (defn, 1, s.definition_length, f) != s.definition_length)
{
}
}
return 1;
-
+
case NT_ASSERTION:
/* Not currently implemented. */
return 1;
save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
{
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
-
+
if (hn->type != NT_VOID)
{
struct cpp_string news;
{
struct cpp_string *sp;
unsigned char *text;
-
+
sp = XNEW (struct cpp_string);
*slot = sp;
const unsigned char *p = (const unsigned char *)p_p;
size_t i;
hashval_t h;
-
+
h = 0;
for (i = 0; i < sz; i++)
h = h * 67 - (*p++ - 113);
{
/* Save the list of non-void identifiers for the dependency checking. */
r->savedstate = XNEW (struct cpp_savedstate);
- r->savedstate->definedhash = htab_create (100, cpp_string_hash,
+ r->savedstate->definedhash = htab_create (100, cpp_string_hash,
cpp_string_eq, NULL);
cpp_forall_identifiers (r, save_idents, r->savedstate);
-
+
/* Write out the list of defined identifiers. */
cpp_forall_identifiers (r, write_macdef, f);
count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
{
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
-
+
switch (hn->type)
{
case NT_MACRO:
if (hn->flags & NODE_BUILTIN)
return 1;
-
+
/* else fall through. */
case NT_VOID:
{
struct cpp_string news;
void **slot;
-
+
news.len = NODE_LEN (hn);
news.text = NODE_NAME (hn);
slot = (void **) htab_find (ss->definedhash, &news);
write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
{
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
-
+
switch (hn->type)
{
case NT_MACRO:
if (hn->flags & NODE_BUILTIN)
return 1;
-
+
/* else fall through. */
case NT_VOID:
{
struct cpp_string news;
void **slot;
-
+
news.len = NODE_LEN (hn);
news.text = NODE_NAME (hn);
slot = (void **) htab_find (ss->definedhash, &news);
struct cpp_savedstate *const ss = r->savedstate;
unsigned char *definedstrs;
size_t i;
-
+
/* Collect the list of identifiers which have been seen and
weren't defined to anything previously. */
ss->hashsize = 0;
with the preprocessor's current definitions. It will be consistent
when:
- - anything that was defined just before the PCH was generated
+ - anything that was defined just before the PCH was generated
is defined the same way now; and
- anything that was not defined then, but is defined now, was not
used by the PCH.
unsigned char *first, *last;
unsigned int i;
unsigned int counter;
-
+
/* Read in the list of identifiers that must be defined
Check that they are defined in the same way. */
for (;;)
{
cpp_hashnode *h;
const unsigned char *newdefn;
-
+
if (read (fd, &m, sizeof (m)) != sizeof (m))
goto error;
-
+
if (m.name_length == 0)
break;
namebuf = XNEWVEC (unsigned char, namebufsz);
}
- if ((size_t)read (fd, namebuf, m.definition_length)
+ if ((size_t)read (fd, namebuf, m.definition_length)
!= m.definition_length)
goto error;
-
+
h = cpp_lookup (r, namebuf, m.name_length);
if (m.flags & NODE_POISONED
|| h->type != NT_MACRO
}
newdefn = cpp_macro_definition (r, h);
-
+
if (m.definition_length != ustrlen (newdefn)
|| memcmp (namebuf, newdefn, m.definition_length) != 0)
{
nl.defs = XNEWVEC (cpp_hashnode *, nl.asize);
cpp_forall_identifiers (r, &collect_ht_nodes, &nl);
qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
-
+
/* Loop through nl.defs and undeftab, both of which are sorted lists.
There should be no matches. */
first = undeftab;
last = undeftab + m.definition_length;
i = 0;
-
+
while (first < last && i < nl.n_defs)
{
int cmp = ustrcmp (first, NODE_NAME (nl.defs[i]));
-
+
if (cmp < 0)
first += ustrlen (first) + 1;
else if (cmp > 0)
else
{
if (CPP_OPTION (r, warn_invalid_pch))
- cpp_error (r, CPP_DL_WARNING_SYSHDR,
+ cpp_error (r, CPP_DL_WARNING_SYSHDR,
"%s: not used because `%s' is defined",
name, first);
goto fail;
}
}
-
+
free(nl.defs);
nl.defs = NULL;
free (undeftab);
if (counter && r->counter)
{
if (CPP_OPTION (r, warn_invalid_pch))
- cpp_error (r, CPP_DL_WARNING_SYSHDR,
+ cpp_error (r, CPP_DL_WARNING_SYSHDR,
"%s: not used because `__COUNTER__' is invalid",
name);
goto fail;
/* Save all the existing macros. */
-struct save_macro_data
+struct save_macro_data
{
uchar **defns;
size_t count;
file were not saved in this way, but this is not done (yet), except
for builtins, and for #assert by default. */
-static int
+static int
save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
{
struct save_macro_data *data = (struct save_macro_data *)data_p;
if (data->count == data->array_size)
{
data->array_size *= 2;
- data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
+ data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
}
-
+
switch (h->type)
{
case NT_ASSERTION:
data->defns[data->count][defnlen] = '\n';
}
break;
-
+
default:
abort ();
}
cpp_prepare_state (cpp_reader *r, struct save_macro_data **data)
{
struct save_macro_data *d = XNEW (struct save_macro_data);
-
+
d->array_size = 512;
d->defns = XNEWVEC (uchar *, d->array_size);
d->count = 0;
}
/* Given a precompiled header that was previously determined to be valid,
- apply all its definitions (and undefinitions) to the current state.
+ apply all its definitions (and undefinitions) to the current state.
DEPNAME is passed to deps_restore. */
int
struct lexer_state old_state;
unsigned int counter;
- /* Restore spec_nodes, which will be full of references to the old
+ /* Restore spec_nodes, which will be full of references to the old
hashtable entries and so will now be invalid. */
{
struct spec_nodes *s = &r->spec_nodes;
r->counter = counter;
return 0;
-
+
error:
cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
return -1;