This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Pragma handling: non-C front ends should not require c_lex()
- To: gcc-patches at gcc dot gnu dot org
- Subject: Pragma handling: non-C front ends should not require c_lex()
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Mon, 15 Oct 2001 23:22:58 +0100
Back-ends that have their own pragmas have code in their <arch>.c file
to process the pragmas, which required c_lex() and other baggage to
read tokens. With this patch, token reading is done through a
language hook, which by default calls abort(), but is overridden to
point to c_lex() by the C front ends. This solves the link issue.
This has bootstrapped x86 Linux without regressions. I have created a
first stage compiler to powerpc-apple-darwin, c4x-foo-rtems,
i370-ibm-linux. I'm about to create two more for i960 and v850.
Documentation update is included.
Assuming they succeed, OK to commit?
This patch includes my patch of 2 days ago to change the return value
of c_lex().
Neil.
* c-lang.c (LANG_HOOKS_GET_PRAGMA_TOKEN): Define.
* c-lex.c: Include cpplib.h earlier.
(c_lex): Change prototype.
* c-lex.h (c_lex): Similarly.
* c-parse.in (yyprint, yyerror, last_token, _yylex):
Update to handle token pointers.
(NAME): Remove.
* c-pragma.c (handle_pragma_pack): Update for new language hook.
(handle_pragma_weak): Similarly.
* cpplex.c (token_spellings): Non-operators no longer have spellings.
(cpp_spell_token, cpp_output_token): Update.
(cpp_type2name): Remove.
* cpplib.h (cpp_type2name): Remove.
* langhooks.c (default_get_pragma_token): New.
* langhooks.h (LANG_HOOKS_GET_PRAGMA_TOKEN,
default_get_pragma_token): New.
(LANG_HOOKS_INITIALIZER): Update.
* toplev.h (struct lang_hooks): New get_pragma_token.
(lex_pragma_token): New macro.
* cp/cp-lang.c: Include c-lex.h.
(LANG_HOOKS_GET_PRAGMA_TOKEN): Define.
* cp/lex.c (parse_strconst_pragma,
handle_pragma_java_exceptions): Update.
* cp/spew.c (last_token, read_token, yyerror): Update to handle
token pointers.
(NAME): Remove.
* doc/tm.texi: Update.
* config/darwin-c.c: Don't include c-lex.h.
(darwin_pragma_options, darwin_pragma_unused): Update.
* config/c4x/c4x.c: Don't include c-lex.h.
(c_lex_func, c4x_init_pragma): Remove.
(c4x_parse_pragma): Update.
* config/c4x/c4x.h (REGISTER_TARGET_PRAGMAS): Update.
* config/c4x/c4x-protos.h (c4x_init_pragma): Remove.
* config/i370/i370.c: Don't include c-lex.h.
(i370_pr_map): Update.
* config/i960/i960-c.c: Don't include c-lex.h.
(i960_pr_align, i960_pr_noalign): Update.
* config/v850/v850-c.c: Don't include c-lex.h.
(ghs_pragma_section, ghs_pragma_interrupt, ghs_pragma_starttda,
ghs_pragma_startsda, ghs_pragma_startzda, ghs_pragma_endtda,
ghs_pragma_endsda, ghs_pragma_endzda): Update.
============================================================
Index: gcc/c-lang.c
*** c-lang.c 2001/10/08 20:54:07 1.57
--- gcc/c-lang.c 2001/10/15 21:14:31
*************** static void c_post_options PARAMS ((void
*** 48,53 ****
--- 48,55 ----
static int c_disregard_inline_limits PARAMS ((tree));
static int c_cannot_inline_tree_fn PARAMS ((tree *));
+ #undef LANG_HOOKS_GET_PRAGMA_TOKEN
+ #define LANG_HOOKS_GET_PRAGMA_TOKEN c_lex
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT c_init
#undef LANG_HOOKS_INIT_OPTIONS
============================================================
Index: gcc/c-lex.c
*** c-lex.c 2001/10/07 16:50:50 1.153
--- gcc/c-lex.c 2001/10/15 21:14:37
*************** Software Foundation, 59 Temple Place - S
*** 27,37 ****
#include "tree.h"
#include "input.h"
#include "output.h"
#include "c-lex.h"
#include "c-tree.h"
#include "flags.h"
#include "timevar.h"
- #include "cpplib.h"
#include "c-pragma.h"
#include "toplev.h"
#include "intl.h"
--- 27,37 ----
#include "tree.h"
#include "input.h"
#include "output.h"
+ #include "cpplib.h"
#include "c-lex.h"
#include "c-tree.h"
#include "flags.h"
#include "timevar.h"
#include "c-pragma.h"
#include "toplev.h"
#include "intl.h"
*************** parse_float (data)
*** 763,769 ****
warning ("floating point number exceeds range of '%s'", typename);
}
! int
c_lex (value)
tree *value;
{
--- 763,769 ----
warning ("floating point number exceeds range of '%s'", typename);
}
! const cpp_token *
c_lex (value)
tree *value;
{
*************** c_lex (value)
*** 823,829 ****
default: break;
}
! return tok->type;
}
#define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0)
--- 823,829 ----
default: break;
}
! return tok;
}
#define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0)
============================================================
Index: gcc/c-lex.h
*** c-lex.h 2001/08/22 14:34:45 1.24
--- gcc/c-lex.h 2001/10/15 21:14:37
*************** Software Foundation, 59 Temple Place - S
*** 24,30 ****
extern tree make_pointer_declarator PARAMS ((tree, tree));
extern void position_after_white_space PARAMS ((void));
! extern int c_lex PARAMS ((tree *));
extern const char *init_c_lex PARAMS ((const char *));
extern int indent_level;
--- 24,30 ----
extern tree make_pointer_declarator PARAMS ((tree, tree));
extern void position_after_white_space PARAMS ((void));
! extern const cpp_token *c_lex PARAMS ((tree *));
extern const char *init_c_lex PARAMS ((const char *));
extern int indent_level;
============================================================
Index: gcc/c-parse.in
*** c-parse.in 2001/10/11 07:07:26 1.108
--- gcc/c-parse.in 2001/10/15 21:14:45
*************** end ifc
*** 300,308 ****
/* Tell yyparse how to print a token's value, if yydebug is set. */
! #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
! static void yyprint PARAMS ((FILE *, int, YYSTYPE));
static void yyerror PARAMS ((const char *));
static int yylexname PARAMS ((void));
static inline int _yylex PARAMS ((void));
--- 300,308 ----
/* Tell yyparse how to print a token's value, if yydebug is set. */
! #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE)
! static void yyprint PARAMS ((FILE *));
static void yyerror PARAMS ((const char *));
static int yylexname PARAMS ((void));
static inline int _yylex PARAMS ((void));
*************** end ifobjc
*** 3244,3250 ****
/* yylex() is a thin wrapper around c_lex(), all it does is translate
cpplib.h's token codes into yacc's token codes. */
! static enum cpp_ttype last_token;
/* The reserved keyword table. */
struct resword
--- 3244,3250 ----
/* yylex() is a thin wrapper around c_lex(), all it does is translate
cpplib.h's token codes into yacc's token codes. */
! static const cpp_token *last_token;
/* The reserved keyword table. */
struct resword
*************** finish_parse ()
*** 3563,3596 ****
errorcount += cpp_errors (parse_in);
}
! #define NAME(type) cpp_type2name (type)
!
static void
yyerror (msgid)
const char *msgid;
{
const char *string = _(msgid);
! if (last_token == CPP_EOF)
! error ("%s at end of input", string);
! else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
{
! unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
! const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
! if (val <= UCHAR_MAX && ISGRAPH (val))
! error ("%s before %s'%c'", string, ell, val);
! else
! error ("%s before %s'\\x%x'", string, ell, val);
}
- else if (last_token == CPP_STRING
- || last_token == CPP_WSTRING)
- error ("%s before string constant", string);
- else if (last_token == CPP_NUMBER)
- error ("%s before numeric constant", string);
- else if (last_token == CPP_NAME)
- error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
- else
- error ("%s before '%s' token", string, NAME(last_token));
}
static int
--- 3563,3592 ----
errorcount += cpp_errors (parse_in);
}
! /* Simple diagnostics that mention the following token. */
static void
yyerror (msgid)
const char *msgid;
{
const char *string = _(msgid);
! switch (last_token->type)
{
! case CPP_EOF:
! error ("%s at end of input", string);
! break;
!
! case CPP_STRING:
! case CPP_WSTRING:
! error ("%s before string literal %s",
! string, cpp_token_as_text (parse_in, last_token));
! break;
!
! default:
! error ("%s before \"%s\" token",
! string, cpp_token_as_text (parse_in, last_token));
! break;
}
}
static int
*************** end ifobjc
*** 3629,3635 ****
const char *name = fname_string (rid_code);
yylval.ttype = build_string (strlen (name) + 1, name);
- last_token = CPP_STRING; /* so yyerror won't choke */
return STRING;
}
--- 3625,3630 ----
*************** _yylex ()
*** 3670,3676 ****
{
get_next:
last_token = c_lex (&yylval.ttype);
! switch (last_token)
{
case CPP_EQ: return '=';
case CPP_NOT: return '!';
--- 3665,3671 ----
{
get_next:
last_token = c_lex (&yylval.ttype);
! switch (last_token->type)
{
case CPP_EQ: return '=';
case CPP_NOT: return '!';
*************** _yylex ()
*** 3747,3762 ****
ifobjc
{
tree after_at;
! enum cpp_ttype after_at_type;
! after_at_type = c_lex (&after_at);
! if (after_at_type == CPP_NAME
&& C_IS_RESERVED_WORD (after_at)
&& OBJC_IS_AT_KEYWORD (C_RID_CODE (after_at)))
{
yylval.ttype = after_at;
- last_token = after_at_type;
return rid_to_yy [(int) C_RID_CODE (after_at)];
}
_cpp_backup_tokens (parse_in, 1);
--- 3742,3756 ----
ifobjc
{
tree after_at;
! const cpp_token *after_at_token;
! after_at_token = c_lex (&after_at);
! if (after_at_token->type == CPP_NAME
&& C_IS_RESERVED_WORD (after_at)
&& OBJC_IS_AT_KEYWORD (C_RID_CODE (after_at)))
{
yylval.ttype = after_at;
return rid_to_yy [(int) C_RID_CODE (after_at)];
}
_cpp_backup_tokens (parse_in, 1);
*************** end ifobjc
*** 3776,3782 ****
/* These tokens should not survive translation phase 4. */
case CPP_HASH:
case CPP_PASTE:
! error ("syntax error at '%s' token", NAME(last_token));
goto get_next;
default:
--- 3770,3777 ----
/* These tokens should not survive translation phase 4. */
case CPP_HASH:
case CPP_PASTE:
! error ("syntax error at \"%s\" token",
! cpp_token_as_text (parse_in, last_token));
goto get_next;
default:
*************** set_yydebug (value)
*** 3813,3863 ****
/* Function used when yydebug is set, to print a token in more detail. */
static void
! yyprint (file, yychar, yyl)
FILE *file;
- int yychar;
- YYSTYPE yyl;
{
! tree t = yyl.ttype;
!
! fprintf (file, " [%s]", NAME(last_token));
!
! switch (yychar)
! {
! case IDENTIFIER:
! case TYPENAME:
! case OBJECTNAME:
! case TYPESPEC:
! case TYPE_QUAL:
! case SCSPEC:
! if (IDENTIFIER_POINTER (t))
! fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
! break;
!
! case CONSTANT:
! fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
! if (TREE_CODE (t) == INTEGER_CST)
! fprintf (file,
! #if HOST_BITS_PER_WIDE_INT == 64
! #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
! " 0x%x%016x",
! #else
! #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
! " 0x%lx%016lx",
! #else
! " 0x%llx%016llx",
! #endif
! #endif
! #else
! #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
! " 0x%lx%08lx",
! #else
! " 0x%x%08x",
! #endif
! #endif
! TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
! break;
! }
}
/* This is not the ideal place to put these, but we have to get them out
--- 3808,3817 ----
/* Function used when yydebug is set, to print a token in more detail. */
static void
! yyprint (file)
FILE *file;
{
! fprintf (file, " [%s]", cpp_token_as_text (parse_in, last_token));
}
/* This is not the ideal place to put these, but we have to get them out
============================================================
Index: gcc/c-pragma.c
*** c-pragma.c 2001/08/31 19:27:12 1.45
--- gcc/c-pragma.c 2001/10/15 21:14:46
*************** mark_align_stack (p)
*** 171,176 ****
--- 171,177 ----
#pragma pack (push, ID, N)
#pragma pack (pop)
#pragma pack (pop, ID) */
+
static void
handle_pragma_pack (dummy)
cpp_reader *dummy ATTRIBUTE_UNUSED;
*************** handle_pragma_pack (dummy)
*** 180,189 ****
enum cpp_ttype token;
enum { set, push, pop } action;
! if (c_lex (&x) != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma pack' - ignored");
! token = c_lex (&x);
if (token == CPP_CLOSE_PAREN)
{
action = set;
--- 181,190 ----
enum cpp_ttype token;
enum { set, push, pop } action;
! if (lex_pragma_token (&x)->type != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma pack' - ignored");
! token = lex_pragma_token (&x)->type;
if (token == CPP_CLOSE_PAREN)
{
action = set;
*************** handle_pragma_pack (dummy)
*** 193,199 ****
{
align = TREE_INT_CST_LOW (x);
action = set;
! if (c_lex (&x) != CPP_CLOSE_PAREN)
BAD ("malformed '#pragma pack' - ignored");
}
else if (token == CPP_NAME)
--- 194,200 ----
{
align = TREE_INT_CST_LOW (x);
action = set;
! if (lex_pragma_token (&x)->type != CPP_CLOSE_PAREN)
BAD ("malformed '#pragma pack' - ignored");
}
else if (token == CPP_NAME)
*************** handle_pragma_pack (dummy)
*** 212,230 ****
else
BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
! token = c_lex (&x);
if (token != CPP_COMMA && action == push)
BAD_ACTION;
if (token == CPP_COMMA)
{
! token = c_lex (&x);
if (token == CPP_NAME)
{
id = x;
! if (action == push && c_lex (&x) != CPP_COMMA)
BAD_ACTION;
! token = c_lex (&x);
}
if (action == push)
--- 213,231 ----
else
BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
! token = lex_pragma_token (&x)->type;
if (token != CPP_COMMA && action == push)
BAD_ACTION;
if (token == CPP_COMMA)
{
! token = lex_pragma_token (&x)->type;
if (token == CPP_NAME)
{
id = x;
! if (action == push && lex_pragma_token (&x)->type != CPP_COMMA)
BAD_ACTION;
! token = lex_pragma_token (&x)->type;
}
if (action == push)
*************** handle_pragma_pack (dummy)
*** 232,238 ****
if (token == CPP_NUMBER)
{
align = TREE_INT_CST_LOW (x);
! token = c_lex (&x);
}
else
BAD_ACTION;
--- 233,239 ----
if (token == CPP_NUMBER)
{
align = TREE_INT_CST_LOW (x);
! token = lex_pragma_token (&x)->type;
}
else
BAD_ACTION;
*************** handle_pragma_pack (dummy)
*** 246,252 ****
else
BAD ("malformed '#pragma pack' - ignored");
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma pack'");
if (action != pop)
--- 247,253 ----
else
BAD ("malformed '#pragma pack' - ignored");
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of '#pragma pack'");
if (action != pop)
*************** handle_pragma_weak (dummy)
*** 286,299 ****
value = 0;
! if (c_lex (&name) != CPP_NAME)
BAD ("malformed #pragma weak, ignored");
! t = c_lex (&x);
if (t == CPP_EQ)
{
! if (c_lex (&value) != CPP_NAME)
BAD ("malformed #pragma weak, ignored");
! t = c_lex (&x);
}
if (t != CPP_EOF)
warning ("junk at end of #pragma weak");
--- 287,300 ----
value = 0;
! if (lex_pragma_token (&name)->type != CPP_NAME)
BAD ("malformed #pragma weak, ignored");
! t = lex_pragma_token (&x)->type;
if (t == CPP_EQ)
{
! if (lex_pragma_token (&value)->type != CPP_NAME)
BAD ("malformed #pragma weak, ignored");
! t = lex_pragma_token (&x)->type;
}
if (t != CPP_EOF)
warning ("junk at end of #pragma weak");
============================================================
Index: gcc/cpplex.c
*** cpplex.c 2001/10/11 21:21:57 1.175
--- gcc/cpplex.c 2001/10/15 21:14:51
*************** struct token_spelling
*** 72,79 ****
static const unsigned char *const digraph_spellings[] =
{ U"%:", U"%:%:", U"<:", U":>", U"<%", U"%>" };
! #define OP(e, s) { SPELL_OPERATOR, U s },
! #define TK(e, s) { s, U STRINGX (e) },
static const struct token_spelling token_spellings[N_TTYPES] = { TTYPE_TABLE };
#undef OP
#undef TK
--- 72,79 ----
static const unsigned char *const digraph_spellings[] =
{ U"%:", U"%:%:", U"<:", U":>", U"<%", U"%>" };
! #define OP(e, s) { SPELL_OPERATOR, U s },
! #define TK(e, s) { s, NULL },
static const struct token_spelling token_spellings[N_TTYPES] = { TTYPE_TABLE };
#undef OP
#undef TK
*************** cpp_spell_token (pfile, token, buffer)
*** 1477,1483 ****
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default:
! cpp_ice (pfile, "unknown string token %s\n", TOKEN_NAME (token));
return buffer;
}
if (tag) *buffer++ = tag;
--- 1477,1483 ----
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default:
! cpp_ice (pfile, "impossible string token, code %u", token->type);
return buffer;
}
if (tag) *buffer++ = tag;
*************** cpp_spell_token (pfile, token, buffer)
*** 1489,1495 ****
break;
case SPELL_NONE:
! cpp_ice (pfile, "Unspellable token %s", TOKEN_NAME (token));
break;
}
--- 1489,1495 ----
break;
case SPELL_NONE:
! cpp_ice (pfile, "unspellable token, code %u", token->type);
break;
}
*************** cpp_token_as_text (pfile, token)
*** 1512,1525 ****
return start;
}
- /* Used by C front ends. Should really move to using cpp_token_as_text. */
- const char *
- cpp_type2name (type)
- enum cpp_ttype type;
- {
- return (const char *) token_spellings[type].name;
- }
-
/* Writes the spelling of token to FP, without any preceding space.
Separated from cpp_spell_token for efficiency - to avoid stdio
double-buffering. */
--- 1512,1517 ----
*************** cpp_output_token (token, fp)
*** 1574,1580 ****
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default:
! fprintf (stderr, "impossible STRING token %s\n", TOKEN_NAME (token));
return;
}
if (tag) putc (tag, fp);
--- 1566,1572 ----
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default:
! fprintf (stderr, "impossible string token, code %u", token->type);
return;
}
if (tag) putc (tag, fp);
============================================================
Index: gcc/cpplib.h
*** cpplib.h 2001/10/14 17:43:58 1.197
--- gcc/cpplib.h 2001/10/15 21:14:52
*************** extern int cpp_ideq PARAMS ((const cpp
*** 551,557 ****
const char *));
extern void cpp_output_line PARAMS ((cpp_reader *, FILE *));
extern void cpp_output_token PARAMS ((const cpp_token *, FILE *));
- extern const char *cpp_type2name PARAMS ((enum cpp_ttype));
extern unsigned int cpp_parse_escape PARAMS ((cpp_reader *,
const unsigned char **,
const unsigned char *,
--- 551,556 ----
============================================================
Index: gcc/langhooks.c
*** langhooks.c 2001/10/11 06:50:50 1.3
--- gcc/langhooks.c 2001/10/15 21:14:53
*************** Boston, MA 02111-1307, USA. */
*** 29,34 ****
--- 29,44 ----
#include "integrate.h"
#include "langhooks.h"
+ /* The default routine to get a token in a #pragma directive. The C
+ front end overrides this; other front-ends should never call it.
+ Using a language hook avoids requiring all front ends to pull in
+ cpplib and c_lex(). */
+ const struct cpp_token *
+ default_get_pragma_token (ptree)
+ tree *ptree ATTRIBUTE_UNUSED;
+ {
+ abort ();
+ }
/* lang_hooks.tree_inlining.walk_subtrees is called by walk_tree()
after handling common cases, but before walking code-specific
============================================================
Index: gcc/langhooks.h
*** langhooks.h 2001/10/08 20:54:07 1.1
--- gcc/langhooks.h 2001/10/15 21:14:53
*************** Boston, MA 02111-1307, USA. */
*** 40,45 ****
--- 40,50 ----
#define LANG_HOOKS_POST_OPTIONS NULL
#endif
+ /* Get a token in a #pragma directive. */
+ struct cpp_token;
+ extern const struct cpp_token *default_get_pragma_token PARAMS ((tree *));
+ #define LANG_HOOKS_GET_PRAGMA_TOKEN default_get_pragma_token
+
/* Declarations of default tree inlining hooks. */
tree tree_inlining_default_hook_walk_subtrees PARAMS ((tree*, int *,
walk_tree_fn,
*************** int tree_inlining_default_hook_anon_aggr
*** 108,113 ****
--- 113,119 ----
LANG_HOOKS_INIT_OPTIONS, \
LANG_HOOKS_DECODE_OPTION, \
LANG_HOOKS_POST_OPTIONS, \
+ LANG_HOOKS_GET_PRAGMA_TOKEN, \
LANG_HOOKS_TREE_INLINING_INITIALIZER \
}
============================================================
Index: gcc/toplev.h
*** toplev.h 2001/10/08 20:54:07 1.74
--- gcc/toplev.h 2001/10/15 21:14:53
*************** Software Foundation, 59 Temple Place - S
*** 24,29 ****
--- 24,30 ----
#ifdef ANSI_PROTOTYPES
union tree_node;
struct rtx_def;
+ struct cpp_token;
#endif
/* If non-NULL, return one past-the-end of the matching SUBPART of
*************** struct lang_hooks
*** 165,170 ****
--- 166,176 ----
/* Called when all command line options have been processed. */
void (*post_options) PARAMS ((void));
+
+ /* Get the next token in a #pragma directive. Defaults to a routine
+ that aborts, as it is intended for C front ends only. */
+ const struct cpp_token * (*get_pragma_token) PARAMS ((union tree_node **));
+ # define lex_pragma_token(PTREE) (*lang_hooks.get_pragma_token) (PTREE)
struct lang_hooks_for_tree_inlining tree_inlining;
============================================================
Index: gcc/config/darwin-c.c
*** darwin-c.c 2001/06/28 19:55:52 1.1
--- gcc/config/darwin-c.c 2001/10/15 21:14:54
*************** Boston, MA 02111-1307, USA. */
*** 25,31 ****
#include "cpplib.h"
#include "tree.h"
#include "c-pragma.h"
- #include "c-lex.h"
#include "c-tree.h"
#include "toplev.h"
#include "tm_p.h"
--- 25,30 ----
*************** darwin_pragma_options (pfile)
*** 94,110 ****
char *arg;
tree t, x;
! if (c_lex (&t) != CPP_NAME)
BAD ("malformed '#pragma options', ignoring");
arg = IDENTIFIER_POINTER (t);
if (strcmp (arg, "align"))
BAD ("malformed '#pragma options', ignoring");
! if (c_lex (&t) != CPP_EQ)
BAD ("malformed '#pragma options', ignoring");
! if (c_lex (&t) != CPP_NAME)
BAD ("malformed '#pragma options', ignoring");
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma options'");
arg = IDENTIFIER_POINTER (t);
--- 93,109 ----
char *arg;
tree t, x;
! if (lex_pragma_token (&t)->type != CPP_NAME)
BAD ("malformed '#pragma options', ignoring");
arg = IDENTIFIER_POINTER (t);
if (strcmp (arg, "align"))
BAD ("malformed '#pragma options', ignoring");
! if (lex_pragma_token (&t)->type != CPP_EQ)
BAD ("malformed '#pragma options', ignoring");
! if (lex_pragma_token (&t)->type != CPP_NAME)
BAD ("malformed '#pragma options', ignoring");
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of '#pragma options'");
arg = IDENTIFIER_POINTER (t);
*************** darwin_pragma_unused (pfile)
*** 127,145 ****
tree decl, x;
int tok;
! if (c_lex (&x) != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma unused', ignoring");
while (1)
{
! tok = c_lex (&decl);
if (tok == CPP_NAME && decl)
{
tree local = IDENTIFIER_LOCAL_VALUE (decl);
if (local && (TREE_CODE (local) == PARM_DECL
|| TREE_CODE (local) == VAR_DECL))
TREE_USED (local) = 1;
! tok = c_lex (&x);
if (tok != CPP_COMMA)
break;
}
--- 126,144 ----
tree decl, x;
int tok;
! if (lex_pragma_token (&x)->type != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma unused', ignoring");
while (1)
{
! tok = lex_pragma_token (&decl)->type;
if (tok == CPP_NAME && decl)
{
tree local = IDENTIFIER_LOCAL_VALUE (decl);
if (local && (TREE_CODE (local) == PARM_DECL
|| TREE_CODE (local) == VAR_DECL))
TREE_USED (local) = 1;
! tok = lex_pragma_token (&x)->type;
if (tok != CPP_COMMA)
break;
}
*************** darwin_pragma_unused (pfile)
*** 148,153 ****
if (tok != CPP_CLOSE_PAREN)
BAD ("missing ')' after '#pragma unused', ignoring");
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma unused'");
}
--- 147,152 ----
if (tok != CPP_CLOSE_PAREN)
BAD ("missing ')' after '#pragma unused', ignoring");
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of '#pragma unused'");
}
============================================================
Index: gcc/config/c4x/c4x-protos.h
*** c4x-protos.h 2001/08/18 20:25:51 1.21
--- gcc/config/c4x/c4x-protos.h 2001/10/15 21:14:54
*************** extern void c4x_pr_FUNC_IS_PURE PARAMS
*** 304,310 ****
extern void c4x_pr_FUNC_NEVER_RETURNS PARAMS ((cpp_reader *));
extern void c4x_pr_INTERRUPT PARAMS ((cpp_reader *));
extern void c4x_pr_ignored PARAMS ((cpp_reader *));
- extern void c4x_init_pragma PARAMS ((int (*) (tree *)));
#endif
#endif /* ! GCC_C4X_PROTOS_H */
--- 304,309 ----
============================================================
Index: gcc/config/c4x/c4x.c
*** c4x.c 2001/10/07 16:51:09 1.95
--- gcc/config/c4x/c4x.c 2001/10/15 21:15:02
*************** Boston, MA 02111-1307, USA. */
*** 45,51 ****
#include "c-tree.h"
#include "ggc.h"
#include "cpplib.h"
- #include "c-lex.h"
#include "c-pragma.h"
#include "toplev.h"
#include "c4x-protos.h"
--- 45,50 ----
*************** c4x_operand_subword (op, i, validate_add
*** 4512,4527 ****
-1 for a malformed pragma. */
#define BAD(msgid, arg) do { warning (msgid, arg); return -1; } while (0)
- static int (*c_lex_func) (tree *);
-
- void
- c4x_init_pragma (get_token)
- int (*get_token) PARAMS ((tree *));
- {
- c_lex_func = get_token;
- }
-
-
static int
c4x_parse_pragma (name, func, sect)
const char *name;
--- 4511,4516 ----
*************** c4x_parse_pragma (name, func, sect)
*** 4530,4554 ****
{
tree f, s, x;
! if (c_lex_func (&x) != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma %s' - ignored", name);
! if (c_lex_func (&f) != CPP_NAME)
BAD ("missing function name in '#pragma %s' - ignored", name);
if (sect)
{
! if (c_lex_func (&x) != CPP_COMMA)
BAD ("malformed '#pragma %s' - ignored", name);
! if (c_lex_func (&s) != CPP_STRING)
BAD ("missing section name in '#pragma %s' - ignored", name);
*sect = s;
}
! if (c_lex_func (&x) != CPP_CLOSE_PAREN)
BAD ("missing ')' for '#pragma %s' - ignored", name);
! if (c_lex_func (&x) != CPP_EOF)
warning ("junk at end of '#pragma %s'", name);
*func = f;
--- 4519,4543 ----
{
tree f, s, x;
! if (lex_pragma_token (&x)->type != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma %s' - ignored", name);
! if (lex_pragma_token (&f)->type != CPP_NAME)
BAD ("missing function name in '#pragma %s' - ignored", name);
if (sect)
{
! if (lex_pragma_token (&x)->type != CPP_COMMA)
BAD ("malformed '#pragma %s' - ignored", name);
! if (lex_pragma_token (&s)->type != CPP_STRING)
BAD ("missing section name in '#pragma %s' - ignored", name);
*sect = s;
}
! if (lex_pragma_token (&x)->type != CPP_CLOSE_PAREN)
BAD ("missing ')' for '#pragma %s' - ignored", name);
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of '#pragma %s'", name);
*func = f;
============================================================
Index: gcc/config/c4x/c4x.h
*** c4x.h 2001/09/11 16:49:57 1.85
--- gcc/config/c4x/c4x.h 2001/10/15 21:15:09
*************** do { \
*** 2348,2354 ****
cpp_register_pragma (PFILE, 0, "FUNC_NO_GLOBAL_ASG", c4x_pr_ignored); \
cpp_register_pragma (PFILE, 0, "FUNC_NO_IND_ASG", c4x_pr_ignored); \
cpp_register_pragma (PFILE, 0, "INTERRUPT", c4x_pr_INTERRUPT); \
- c4x_init_pragma (&c_lex); \
} while (0)
/* Assembler Commands for Alignment. */
--- 2348,2353 ----
============================================================
Index: gcc/config/i370/i370.c
*** i370.c 2001/08/10 16:19:18 1.20
--- gcc/config/i370/i370.c 2001/10/15 21:15:13
*************** Boston, MA 02111-1307, USA. */
*** 40,46 ****
#include "toplev.h"
#include "cpplib.h"
#include "c-pragma.h"
- #include "c-lex.h"
#include "tm_p.h"
#include "target.h"
#include "target-def.h"
--- 40,45 ----
*************** i370_pr_map (pfile)
*** 1042,1054 ****
{
tree name, alias, x;
! if (c_lex (&x) == CPP_OPEN_PAREN
! && c_lex (&name) == CPP_NAME
! && c_lex (&x) == CPP_COMMA
! && c_lex (&alias) == CPP_NAME
! && c_lex (&x) == CPP_CLOSE_PAREN)
{
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma map");
mvs_add_alias (IDENTIFIER_POINTER (name), IDENTIFIER_POINTER (alias), 1);
--- 1041,1053 ----
{
tree name, alias, x;
! if (lex_pragma_token (&x)->type == CPP_OPEN_PAREN
! && lex_pragma_token (&name)->type == CPP_NAME
! && lex_pragma_token (&x)->type == CPP_COMMA
! && lex_pragma_token (&alias)->type == CPP_NAME
! && lex_pragma_token (&x)->type == CPP_CLOSE_PAREN)
{
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma map");
mvs_add_alias (IDENTIFIER_POINTER (name), IDENTIFIER_POINTER (alias), 1);
============================================================
Index: gcc/config/i960/i960-c.c
*** i960-c.c 2001/03/15 16:29:10 1.1
--- gcc/config/i960/i960-c.c 2001/10/15 21:15:13
*************** Boston, MA 02111-1307, USA. */
*** 27,33 ****
#include "cpplib.h"
#include "tree.h"
#include "c-pragma.h"
- #include "c-lex.h"
#include "toplev.h"
#include "ggc.h"
#include "tm_p.h"
--- 27,32 ----
*************** i960_pr_align (pfile)
*** 59,67 ****
enum cpp_ttype type;
int align;
! type = c_lex (&number);
if (type == CPP_OPEN_PAREN)
! type = c_lex (&number);
if (type == CPP_NAME)
{
warning ("sorry, not implemented: #pragma align NAME=SIZE");
--- 58,66 ----
enum cpp_ttype type;
int align;
! type = lex_pragma_token (&number)->type;
if (type == CPP_OPEN_PAREN)
! type = lex_pragma_token (&number)->type;
if (type == CPP_NAME)
{
warning ("sorry, not implemented: #pragma align NAME=SIZE");
*************** i960_pr_noalign (pfile)
*** 102,110 ****
enum cpp_ttype type;
tree number;
! type = c_lex (&number);
if (type == CPP_OPEN_PAREN)
! type = c_lex (&number);
if (type == CPP_NAME)
{
warning ("sorry, not implemented: #pragma noalign NAME");
--- 101,109 ----
enum cpp_ttype type;
tree number;
! type = lex_pragma_token (&number)->type;
if (type == CPP_OPEN_PAREN)
! type = lex_pragma_token (&number)->type;
if (type == CPP_NAME)
{
warning ("sorry, not implemented: #pragma noalign NAME");
============================================================
Index: gcc/config/v850/v850-c.c
*** v850-c.c 2001/09/21 01:27:06 1.2
--- gcc/config/v850/v850-c.c 2001/10/15 21:15:14
*************** Boston, MA 02111-1307, USA. */
*** 24,30 ****
#include "cpplib.h"
#include "tree.h"
#include "c-pragma.h"
- #include "c-lex.h"
#include "toplev.h"
#include "ggc.h"
#include "tm_p.h"
--- 24,29 ----
*************** ghs_pragma_section (pfile)
*** 125,131 ****
const char *sect, *alias;
enum GHS_section_kind kind;
! type = c_lex (&x);
if (type == CPP_EOF && !repeat)
goto reset;
--- 124,130 ----
const char *sect, *alias;
enum GHS_section_kind kind;
! type = lex_pragma_token (&x)->type;
if (type == CPP_EOF && !repeat)
goto reset;
*************** ghs_pragma_section (pfile)
*** 135,148 ****
goto bad;
repeat = 0;
! if (c_lex (&x) != CPP_EQ)
goto bad;
! if (c_lex (&x) != CPP_NAME)
goto bad;
alias = IDENTIFIER_POINTER (x);
! type = c_lex (&x);
if (type == CPP_COMMA)
repeat = 1;
else if (type != CPP_EOF)
--- 134,147 ----
goto bad;
repeat = 0;
! if (lex_pragma_token (&x)->type != CPP_EQ)
goto bad;
! if (lex_pragma_token (&x)->type != CPP_NAME)
goto bad;
alias = IDENTIFIER_POINTER (x);
! type = lex_pragma_token (&x)->type;
if (type == CPP_COMMA)
repeat = 1;
else if (type != CPP_EOF)
*************** ghs_pragma_interrupt (pfile)
*** 197,203 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs interrupt");
mark_current_function_as_interrupt ();
--- 196,202 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs interrupt");
mark_current_function_as_interrupt ();
*************** ghs_pragma_starttda (pfile)
*** 209,215 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs starttda");
push_data_area (DATA_AREA_TDA);
--- 208,214 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs starttda");
push_data_area (DATA_AREA_TDA);
*************** ghs_pragma_startsda (pfile)
*** 221,227 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs startsda");
push_data_area (DATA_AREA_SDA);
--- 220,226 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs startsda");
push_data_area (DATA_AREA_SDA);
*************** ghs_pragma_startzda (pfile)
*** 233,239 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs startzda");
push_data_area (DATA_AREA_ZDA);
--- 232,238 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs startzda");
push_data_area (DATA_AREA_ZDA);
*************** ghs_pragma_endtda (pfile)
*** 245,251 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs endtda");
pop_data_area (DATA_AREA_TDA);
--- 244,250 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs endtda");
pop_data_area (DATA_AREA_TDA);
*************** ghs_pragma_endsda (pfile)
*** 257,263 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs endsda");
pop_data_area (DATA_AREA_SDA);
--- 256,262 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs endsda");
pop_data_area (DATA_AREA_SDA);
*************** ghs_pragma_endzda (pfile)
*** 269,275 ****
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma ghs endzda");
pop_data_area (DATA_AREA_ZDA);
--- 268,274 ----
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma ghs endzda");
pop_data_area (DATA_AREA_ZDA);
============================================================
Index: gcc/cp/cp-lang.c
*** cp-lang.c 2001/10/08 20:53:40 1.1
--- gcc/cp/cp-lang.c 2001/10/15 21:15:14
*************** Boston, MA 02111-1307, USA. */
*** 25,31 ****
--- 25,34 ----
#include "cp-tree.h"
#include "toplev.h"
#include "langhooks.h"
+ #include "c-lex.h"
+ #undef LANG_HOOKS_GET_PRAGMA_TOKEN
+ #define LANG_HOOKS_GET_PRAGMA_TOKEN c_lex
#undef LANG_HOOKS_INIT
#define LANG_HOOKS_INIT cxx_init
#undef LANG_HOOKS_FINISH
============================================================
Index: gcc/cp/lex.c
*** lex.c 2001/10/14 17:44:00 1.252
--- gcc/cp/lex.c 2001/10/15 21:15:18
*************** parse_strconst_pragma (name, opt)
*** 1058,1068 ****
tree result, x;
enum cpp_ttype t;
! t = c_lex (&x);
if (t == CPP_STRING)
{
result = x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma %s", name);
return result;
}
--- 1058,1068 ----
tree result, x;
enum cpp_ttype t;
! t = lex_pragma_token (&x)->type;
if (t == CPP_STRING)
{
result = x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma %s", name);
return result;
}
*************** handle_pragma_java_exceptions (dfile)
*** 1180,1186 ****
cpp_reader *dfile ATTRIBUTE_UNUSED;
{
tree x;
! if (c_lex (&x) != CPP_EOF)
warning ("junk at end of #pragma GCC java_exceptions");
choose_personality_routine (lang_java);
--- 1180,1186 ----
cpp_reader *dfile ATTRIBUTE_UNUSED;
{
tree x;
! if (lex_pragma_token (&x)->type != CPP_EOF)
warning ("junk at end of #pragma GCC java_exceptions");
choose_personality_routine (lang_java);
============================================================
Index: gcc/cp/spew.c
*** spew.c 2001/10/02 15:43:44 1.53
--- gcc/cp/spew.c 2001/10/15 21:15:21
*************** static void debug_yychar PARAMS ((int));
*** 138,144 ****
/* In parse.y: */
extern char *debug_yytranslate PARAMS ((int));
#endif
! static enum cpp_ttype last_token;
static tree last_token_id;
/* From lex.c: */
--- 138,144 ----
/* In parse.y: */
extern char *debug_yytranslate PARAMS ((int));
#endif
! static const cpp_token *last_token;
static tree last_token_id;
/* From lex.c: */
*************** read_token (t)
*** 262,268 ****
last_token = c_lex (&last_token_id);
t->yylval.ttype = last_token_id;
! switch (last_token)
{
#define YYCHAR(yy) t->yychar = yy; break;
#define YYCODE(c) t->yylval.code = c;
--- 262,268 ----
last_token = c_lex (&last_token_id);
t->yylval.ttype = last_token_id;
! switch (last_token->type)
{
#define YYCHAR(yy) t->yychar = yy; break;
#define YYCODE(c) t->yylval.code = c;
*************** debug_yychar (yy)
*** 1468,1506 ****
#endif
! #define NAME(type) cpp_type2name (type)
!
void
yyerror (msgid)
const char *msgid;
{
const char *string = _(msgid);
! if (last_token == CPP_EOF)
! error ("%s at end of input", string);
! else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
! {
! unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
! const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
! if (val <= UCHAR_MAX && ISGRAPH (val))
! error ("%s before %s'%c'", string, ell, val);
! else
! error ("%s before %s'\\x%x'", string, ell, val);
! }
! else if (last_token == CPP_STRING
! || last_token == CPP_WSTRING)
! error ("%s before string constant", string);
! else if (last_token == CPP_NUMBER)
! error ("%s before numeric constant", string);
! else if (last_token == CPP_NAME)
! {
! if (TREE_CODE (last_token_id) == IDENTIFIER_NODE)
! error ("%s before `%s'", string, IDENTIFIER_POINTER (last_token_id));
! else if (ISGRAPH (yychar))
! error ("%s before `%c'", string, yychar);
! else
! error ("%s before `\%o'", string, yychar);
}
- else
- error ("%s before `%s' token", string, NAME (last_token));
}
--- 1468,1495 ----
#endif
! /* Simple diagnostics that mention the following token. */
void
yyerror (msgid)
const char *msgid;
{
const char *string = _(msgid);
! switch (last_token->type)
! {
! case CPP_EOF:
! error ("%s at end of input", string);
! break;
!
! case CPP_STRING:
! case CPP_WSTRING:
! error ("%s before string literal %s",
! string, cpp_token_as_text (parse_in, last_token));
! break;
!
! default:
! error ("%s before \"%s\" token",
! string, cpp_token_as_text (parse_in, last_token));
! break;
}
}
============================================================
Index: gcc/doc/tm.texi
*** tm.texi 2001/10/14 17:44:00 1.63
--- gcc/doc/tm.texi 2001/10/15 21:15:50
*************** pragma of the form
*** 8514,8537 ****
@var{space} is the case-sensitive namespace of the pragma, or
@code{NULL} to put the pragma in the global namespace. The callback
routine receives @var{pfile} as its first argument, which can be passed
! on to cpplib's functions if necessary. It may read any text after the
! @var{name} by making calls to @code{c_lex}. Text which is not read by
! the callback will be silently ignored.
For an example use of this routine, see @file{c4x.h} and the callback
routines defined in @file{c4x.c}.
-
- Note that the use of @code{c_lex} is specific to the C and C++
- compilers. It will not work in the Java or Fortran compilers, or any
- other language compilers for that matter. Thus if @code{c_lex} is going
- to be called from target-specific code, it must only be done so when
- building the C and C++ compilers. This can be done by defining the
- variables @code{c_target_objs} and @code{cxx_target_objs} in the
- target entry in the @file{config.gcc} file. These variables should name
- the target-specific, language-specific object file which contains the
- code that uses @code{c_lex}. Note it will also be necessary to add a
- rule to the makefile fragment pointed to by @code{tmake_file} that shows
- how to build this object file.
@end deftypefun
@findex HANDLE_SYSV_PRAGMA
--- 8514,8527 ----
@var{space} is the case-sensitive namespace of the pragma, or
@code{NULL} to put the pragma in the global namespace. The callback
routine receives @var{pfile} as its first argument, which can be passed
! on to cpplib's functions if necessary. You can lex tokens after the
! @var{name} through the language hook @code{get_pragma_token}, or more
! naturally by using the macro @code{lex_pragma_token}. Tokens that are
! not read by the callback will be silently ignored. The end of the line
! is indicated by a token of type @code{CPP_EOF}.
For an example use of this routine, see @file{c4x.h} and the callback
routines defined in @file{c4x.c}.
@end deftypefun
@findex HANDLE_SYSV_PRAGMA