Commit 8c389f84 by Zack Weinberg Committed by Zack Weinberg

cpphash.c (timestamp): Delete.

	* cpphash.c (timestamp): Delete.
	(del_HASHNODE): If type is T_MCONST, free value.cpval.
	(special_symbol): Remove unnecessary braces.  Remove
	T_VERSION.  Treat T_STDC like T_CONST unless
	STDC_0_IN_SYSTEM_HEADERS.  Render both __DATE__ and __TIME__
	when one is encountered, then convert them into T_MCONST
	nodes.
	* cppinit.c (builtin_array): version_string is T_MCONST.
	__STDC__ has a "1" in its cpval.  Don't have a terminator
	entry.  Clean up which entries are dumped.
	(initialize_builtins): Only __STDC__ gets the special
	-traditional treatment.  Count the length of builtin_array.
	Render version_string here.
	* cpphash.h: Remove T_VERSION.  Add T_MCONST.
	* cpplib.h (struct cpp_reader): Remove timebuf.

From-SVN: r33047
parent 3a3677ff
2000-04-09 Zack Weinberg <zack@wolery.cumb.org>
* cpphash.c (timestamp): Delete.
(del_HASHNODE): If type is T_MCONST, free value.cpval.
(special_symbol): Remove unnecessary braces. Remove
T_VERSION. Treat T_STDC like T_CONST unless
STDC_0_IN_SYSTEM_HEADERS. Render both __DATE__ and __TIME__
when one is encountered, then convert them into T_MCONST
nodes.
* cppinit.c (builtin_array): version_string is T_MCONST.
__STDC__ has a "1" in its cpval. Don't have a terminator
entry. Clean up which entries are dumped.
(initialize_builtins): Only __STDC__ gets the special
-traditional treatment. Count the length of builtin_array.
Render version_string here.
* cpphash.h: Remove T_VERSION. Add T_MCONST.
* cpplib.h (struct cpp_reader): Remove timebuf.
2000-04-09 Richard Henderson <rth@cygnus.com> 2000-04-09 Richard Henderson <rth@cygnus.com>
* genrecog.c (pred): Update comparison_operator for the unordered * genrecog.c (pred): Update comparison_operator for the unordered
......
...@@ -42,7 +42,6 @@ static void push_macro_expansion PARAMS ((cpp_reader *, ...@@ -42,7 +42,6 @@ static void push_macro_expansion PARAMS ((cpp_reader *,
static int unsafe_chars PARAMS ((cpp_reader *, int, int)); static int unsafe_chars PARAMS ((cpp_reader *, int, int));
static int macro_cleanup PARAMS ((cpp_buffer *, cpp_reader *)); static int macro_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static enum cpp_token macarg PARAMS ((cpp_reader *, int)); static enum cpp_token macarg PARAMS ((cpp_reader *, int));
static struct tm *timestamp PARAMS ((cpp_reader *));
static void special_symbol PARAMS ((HASHNODE *, cpp_reader *)); static void special_symbol PARAMS ((HASHNODE *, cpp_reader *));
/* Initial hash table size. (It can grow if necessary - see hashtab.c.) */ /* Initial hash table size. (It can grow if necessary - see hashtab.c.) */
...@@ -141,6 +140,8 @@ del_HASHNODE (x) ...@@ -141,6 +140,8 @@ del_HASHNODE (x)
if (h->type == T_MACRO) if (h->type == T_MACRO)
_cpp_free_definition (h->value.defn); _cpp_free_definition (h->value.defn);
else if (h->type == T_MCONST)
free ((void *) h->value.cpval);
free ((void *) h->name); free ((void *) h->name);
free (h); free (h);
} }
...@@ -794,18 +795,6 @@ macarg (pfile, rest_args) ...@@ -794,18 +795,6 @@ macarg (pfile, rest_args)
} }
static struct tm *
timestamp (pfile)
cpp_reader *pfile;
{
if (!pfile->timebuf)
{
time_t t = time ((time_t *) 0);
pfile->timebuf = localtime (&t);
}
return pfile->timebuf;
}
static const char * const monthnames[] = static const char * const monthnames[] =
{ {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
...@@ -854,6 +843,7 @@ _cpp_quote_string (pfile, src) ...@@ -854,6 +843,7 @@ _cpp_quote_string (pfile, src)
* buffer *without* rescanning. * buffer *without* rescanning.
*/ */
#define DSC(str) (const U_CHAR *)str, sizeof str - 1
static void static void
special_symbol (hp, pfile) special_symbol (hp, pfile)
HASHNODE *hp; HASHNODE *hp;
...@@ -867,22 +857,15 @@ special_symbol (hp, pfile) ...@@ -867,22 +857,15 @@ special_symbol (hp, pfile)
{ {
case T_FILE: case T_FILE:
case T_BASE_FILE: case T_BASE_FILE:
{ ip = cpp_file_buffer (pfile);
ip = cpp_file_buffer (pfile); if (hp->type == T_BASE_FILE)
if (hp->type == T_BASE_FILE) while (CPP_PREV_BUFFER (ip) != NULL)
{ ip = CPP_PREV_BUFFER (ip);
while (CPP_PREV_BUFFER (ip) != NULL)
ip = CPP_PREV_BUFFER (ip);
}
buf = ip->nominal_fname;
if (!buf) buf = ip->nominal_fname;
buf = ""; CPP_RESERVE (pfile, 3 + 4 * strlen (buf));
CPP_RESERVE (pfile, 3 + 4 * strlen (buf)); _cpp_quote_string (pfile, buf);
_cpp_quote_string (pfile, buf); return;
return;
}
case T_INCLUDE_LEVEL: case T_INCLUDE_LEVEL:
{ {
...@@ -897,16 +880,21 @@ special_symbol (hp, pfile) ...@@ -897,16 +880,21 @@ special_symbol (hp, pfile)
return; return;
} }
case T_VERSION: case T_STDC:
len = strlen (hp->value.cpval); #ifdef STDC_0_IN_SYSTEM_HEADERS
CPP_RESERVE (pfile, 3 + len); ip = cpp_file_buffer (pfile);
CPP_PUTC_Q (pfile, '"'); if (ip->system_header_p && !cpp_defined (pfile, DSC("__STRICT_ANSI__")))
CPP_PUTS_Q (pfile, hp->value.cpval, len); {
CPP_PUTC_Q (pfile, '"'); CPP_RESERVE (pfile, 2);
CPP_NUL_TERMINATE_Q (pfile); CPP_PUTC_Q (pfile, '0');
return; CPP_NUL_TERMINATE_Q (pfile);
return;
}
#endif
/* else fall through */
case T_CONST: case T_CONST:
case T_MCONST:
constant:
buf = hp->value.cpval; buf = hp->value.cpval;
if (!buf) if (!buf)
return; return;
...@@ -919,19 +907,6 @@ special_symbol (hp, pfile) ...@@ -919,19 +907,6 @@ special_symbol (hp, pfile)
CPP_NUL_TERMINATE_Q (pfile); CPP_NUL_TERMINATE_Q (pfile);
return; return;
case T_STDC:
CPP_RESERVE (pfile, 2);
#ifdef STDC_0_IN_SYSTEM_HEADERS
ip = cpp_file_buffer (pfile);
if (ip->system_header_p
&& !cpp_defined (pfile, (const U_CHAR *) "__STRICT_ANSI__", 15))
CPP_PUTC_Q (pfile, '0');
else
#endif
CPP_PUTC_Q (pfile, '1');
CPP_NUL_TERMINATE_Q (pfile);
return;
case T_SPECLINE: case T_SPECLINE:
{ {
long line; long line;
...@@ -945,21 +920,31 @@ special_symbol (hp, pfile) ...@@ -945,21 +920,31 @@ special_symbol (hp, pfile)
case T_DATE: case T_DATE:
case T_TIME: case T_TIME:
/* Generate both __DATE__ and __TIME__, stuff them into their
respective hash nodes, and mark the nodes T_MCONST so we
don't have to do this again. We don't generate these strings
at init time because time() and localtime() are very slow on
some systems. */
{ {
struct tm *timebuf; time_t tt = time (NULL);
struct tm *tb = localtime (&tt);
HASHNODE *d, *t;
CPP_RESERVE (pfile, 20);
timebuf = timestamp (pfile);
if (hp->type == T_DATE) if (hp->type == T_DATE)
sprintf (CPP_PWRITTEN (pfile), "\"%s %2d %4d\"", d = hp, t = _cpp_lookup (pfile, DSC("__TIME__"));
monthnames[timebuf->tm_mon],
timebuf->tm_mday, timebuf->tm_year + 1900);
else else
sprintf (CPP_PWRITTEN (pfile), "\"%02d:%02d:%02d\"", t = hp, d = _cpp_lookup (pfile, DSC("__DATE__"));
timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec);
d->value.cpval = xmalloc (sizeof "'Oct 11 1347'");
CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile))); sprintf ((char *)d->value.cpval, "\"%s %2d %4d\"",
return; monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900);
d->type = T_MCONST;
t->value.cpval = xmalloc (sizeof "'12:34:56'");
sprintf ((char *)t->value.cpval, "\"%02d:%02d:%02d\"",
tb->tm_hour, tb->tm_min, tb->tm_sec);
t->type = T_MCONST;
goto constant;
} }
case T_POISON: case T_POISON:
...@@ -974,6 +959,7 @@ special_symbol (hp, pfile) ...@@ -974,6 +959,7 @@ special_symbol (hp, pfile)
return; return;
} }
} }
#undef DSC
/* Expand a macro call. /* Expand a macro call.
HP points to the symbol that is the macro being called. HP points to the symbol that is the macro being called.
......
...@@ -91,10 +91,10 @@ enum node_type ...@@ -91,10 +91,10 @@ enum node_type
T_FILE, /* `__FILE__' */ T_FILE, /* `__FILE__' */
T_BASE_FILE, /* `__BASE_FILE__' */ T_BASE_FILE, /* `__BASE_FILE__' */
T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
T_VERSION, /* `__VERSION__' */
T_TIME, /* `__TIME__' */ T_TIME, /* `__TIME__' */
T_STDC, /* `__STDC__' */ T_STDC, /* `__STDC__' */
T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */ T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */
T_MCONST, /* Ditto, but the string is malloced memory */
T_MACRO, /* macro defined by `#define' */ T_MACRO, /* macro defined by `#define' */
T_DISABLED, /* macro temporarily turned off for rescan */ T_DISABLED, /* macro temporarily turned off for rescan */
T_POISON, /* macro defined with `#pragma poison' */ T_POISON, /* macro defined with `#pragma poison' */
......
...@@ -588,9 +588,8 @@ cpp_cleanup (pfile) ...@@ -588,9 +588,8 @@ cpp_cleanup (pfile)
be entered in the macro hash table under the name NAME, with value be entered in the macro hash table under the name NAME, with value
VALUE (if any). FLAGS tweaks the behavior a little: VALUE (if any). FLAGS tweaks the behavior a little:
DUMP write debug info for this macro DUMP write debug info for this macro
STDC define only if not -traditional VERS value is the global version_string, quoted
ULP value is the global user_label_prefix (which can't be ULP value is the global user_label_prefix
put directly into the table).
*/ */
struct builtin struct builtin
...@@ -601,35 +600,35 @@ struct builtin ...@@ -601,35 +600,35 @@ struct builtin
unsigned short flags; unsigned short flags;
}; };
#define DUMP 0x01 #define DUMP 0x01
#define STDC 0x02 #define VERS 0x02
#define VERS 0x04 #define ULP 0x04
#define ULP 0x08
static const struct builtin builtin_array[] = static const struct builtin builtin_array[] =
{ {
{ "__TIME__", 0, T_TIME, DUMP }, { "__TIME__", 0, T_TIME, 0 },
{ "__DATE__", 0, T_DATE, DUMP }, { "__DATE__", 0, T_DATE, 0 },
{ "__FILE__", 0, T_FILE, 0 }, { "__FILE__", 0, T_FILE, 0 },
{ "__BASE_FILE__", 0, T_BASE_FILE, 0 }, { "__BASE_FILE__", 0, T_BASE_FILE, 0 },
{ "__LINE__", 0, T_SPECLINE, 0 }, { "__LINE__", 0, T_SPECLINE, 0 },
{ "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 }, { "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 },
{ "__VERSION__", 0, T_VERSION, DUMP|VERS },
{ "__STDC__", 0, T_STDC, DUMP|STDC }, { "__VERSION__", 0, T_MCONST, DUMP|VERS },
{ "__USER_LABEL_PREFIX__", 0, T_CONST, DUMP|ULP },
{ "__USER_LABEL_PREFIX__", 0, T_CONST, ULP }, { "__STDC__", "1", T_STDC, DUMP },
{ "__REGISTER_PREFIX__", REGISTER_PREFIX, T_CONST, 0 }, { "__REGISTER_PREFIX__", REGISTER_PREFIX, T_CONST, DUMP },
{ "__HAVE_BUILTIN_SETJMP__", "1", T_CONST, 0 }, { "__HAVE_BUILTIN_SETJMP__", "1", T_CONST, DUMP },
#ifndef NO_BUILTIN_SIZE_TYPE #ifndef NO_BUILTIN_SIZE_TYPE
{ "__SIZE_TYPE__", SIZE_TYPE, T_CONST, DUMP }, { "__SIZE_TYPE__", SIZE_TYPE, T_CONST, DUMP },
#endif #endif
#ifndef NO_BUILTIN_PTRDIFF_TYPE #ifndef NO_BUILTIN_PTRDIFF_TYPE
{ "__PTRDIFF_TYPE__", PTRDIFF_TYPE, T_CONST, DUMP }, { "__PTRDIFF_TYPE__", PTRDIFF_TYPE, T_CONST, DUMP },
#endif #endif
#ifndef NO_BUILTIN_WCHAR_TYPE #ifndef NO_BUILTIN_WCHAR_TYPE
{ "__WCHAR_TYPE__", WCHAR_TYPE, T_CONST, DUMP }, { "__WCHAR_TYPE__", WCHAR_TYPE, T_CONST, DUMP },
#endif #endif
{ 0, 0, 0, 0 }
}; };
#define builtin_array_end \
builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
/* Subroutine of cpp_start_read; reads the builtins table above and /* Subroutine of cpp_start_read; reads the builtins table above and
enters the macros into the hash table. */ enters the macros into the hash table. */
...@@ -641,15 +640,18 @@ initialize_builtins (pfile) ...@@ -641,15 +640,18 @@ initialize_builtins (pfile)
const struct builtin *b; const struct builtin *b;
const char *val; const char *val;
HASHNODE *hp; HASHNODE *hp;
for(b = builtin_array; b->name; b++) for(b = builtin_array; b < builtin_array_end; b++)
{ {
if ((b->flags & STDC) && CPP_TRADITIONAL (pfile)) if (b->type == T_STDC && CPP_TRADITIONAL (pfile))
continue; continue;
if (b->flags & ULP) if (b->flags & ULP)
val = user_label_prefix; val = user_label_prefix;
else if (b->flags & VERS) else if (b->flags & VERS)
val = version_string; {
val = xmalloc (strlen (version_string) + 3);
sprintf ((char *)val, "\"%s\"", version_string);
}
else else
val = b->value; val = b->value;
...@@ -662,7 +664,6 @@ initialize_builtins (pfile) ...@@ -662,7 +664,6 @@ initialize_builtins (pfile)
if ((b->flags & DUMP) && CPP_OPTION (pfile, debug_output)) if ((b->flags & DUMP) && CPP_OPTION (pfile, debug_output))
dump_special_to_buffer (pfile, b->name); dump_special_to_buffer (pfile, b->name);
} }
} }
#undef DUMP #undef DUMP
#undef STDC #undef STDC
......
...@@ -352,8 +352,6 @@ struct cpp_reader ...@@ -352,8 +352,6 @@ struct cpp_reader
long lineno; long lineno;
struct tm *timebuf;
/* Buffer of -M output. */ /* Buffer of -M output. */
struct deps *deps; struct deps *deps;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment