summaryrefslogtreecommitdiff
path: root/gcc/c-lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-lex.c')
-rwxr-xr-xgcc/c-lex.c324
1 files changed, 25 insertions, 299 deletions
diff --git a/gcc/c-lex.c b/gcc/c-lex.c
index c82fc96..bfb2552 100755
--- a/gcc/c-lex.c
+++ b/gcc/c-lex.c
@@ -30,17 +30,10 @@ Boston, MA 02111-1307, USA. */
#include "c-tree.h"
#include "flags.h"
#include "c-parse.h"
-#include "c-pragma.h"
#include "toplev.h"
-#ifdef MULTIBYTE_CHARS
-#include "mbchar.h"
-#include <locale.h>
-#endif /* MULTIBYTE_CHARS */
-
-#include "cpplib.h"
-extern cpp_reader parse_in;
-extern cpp_options parse_options;
+/* Stream for reading from the input file. */
+FILE *finput;
extern void yyprint (FILE *, int, YYSTYPE);
@@ -52,12 +45,8 @@ tree ridpointers[(int) RID_MAX];
/* Cause the `yydebug' variable to be defined. */
#define YYDEBUG 1
-extern unsigned char *yy_cur, *yy_lim;
-
-extern int yy_get_token ();
-
-#define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
-#define UNGETC(c) ((void)(c), yy_cur--)
+#define GETC() getc(finput)
+#define UNGETC(c) ungetc(c, finput)
/* the declaration found for the last IDENTIFIER token read in.
yylex must look this up to detect typedefs, which get token type TYPENAME,
@@ -90,10 +79,6 @@ static int indent_level = 0; /* Number of { minus number of }. */
/* Nonzero if end-of-file has been seen on input. */
static int end_of_file;
-
-#ifdef HANDLE_GENERIC_PRAGMAS
-static int handle_generic_pragma (int);
-#endif /* HANDLE_GENERIC_PRAGMAS */
static int whitespace_cr (int);
static int skip_white_space (int);
static int skip_white_space_on_line (void);
@@ -155,17 +140,17 @@ char *
init_parse (filename)
char *filename;
{
- parse_in.show_column = 1;
- if (! cpp_start_read (&parse_in, filename))
- abort ();
-
+ /* Open input file. */
if (filename == 0 || !strcmp (filename, "-"))
- filename = "stdin";
+ {
+ finput = stdin;
+ filename = "stdin";
+ }
+ else
+ finput = fopen (filename, "r");
- /* cpp_start_read always puts at least one line directive into the
- token buffer. We must arrange to read it out here. */
- yy_cur = parse_in.token_buffer;
- yy_lim = CPP_PWRITTEN (&parse_in);
+ if (finput == 0)
+ pfatal_with_name (filename);
init_lex ();
@@ -175,7 +160,7 @@ init_parse (filename)
void
finish_parse ()
{
- cpp_finish (&parse_in);
+ fclose(finput);
}
void
@@ -188,12 +173,6 @@ init_lex ()
and will increment it to 1. */
lineno = 0;
-#ifdef MULTIBYTE_CHARS
- /* Change to the native locale for multibyte conversions. */
- setlocale (LC_CTYPE, "");
- literal_codeset = getenv ("LANG");
-#endif
-
maxtoken = 40;
token_buffer = (char *) xmalloc (maxtoken + 2);
@@ -361,16 +340,12 @@ skip_white_space (c)
}
}
-/* Skips all of the white space at the current location in the input file.
- Must use and reset nextchar if it has the next character. */
+/* Skips all of the white space at the current location in the input file. */
void
position_after_white_space ()
{
- register int c;
-
- c = GETC();
-
+ int c = GETC();
UNGETC (skip_white_space (c));
}
@@ -422,27 +397,13 @@ extend_token_buffer (p)
return token_buffer + offset;
}
-
-#if defined HANDLE_PRAGMA
-/* Local versions of these macros, that can be passed as function pointers. */
-static int
-pragma_getc ()
-{
- return GETC();
-}
-static void
-pragma_ungetc (arg)
- int arg;
-{
- UNGETC (arg);
-}
-#endif
+/* At the beginning of the file, check for a #line directive indicating
+ the real name of the file. */
void check_line_directive()
{
- check_newline ();
- yy_cur--;
+ ungetc(check_newline(), finput);
}
/* At the beginning of a line, increment the line number
@@ -478,7 +439,7 @@ check_newline ()
/* If a letter follows, then if the word here is `line', skip
it and ignore it; otherwise, ignore the line, with an error
- if the word isn't `pragma', `ident', `define', or `undef'. */
+ if the word isn't `pragma', `define', or `undef'. */
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
@@ -489,46 +450,9 @@ check_newline ()
&& GETC() == 'g'
&& GETC() == 'm'
&& GETC() == 'a'
- && ((c = GETC()) == ' ' || c == '\t' || c == '\n'
- || whitespace_cr (c) ))
+ && ((c = GETC()) == ' ' || c == '\t' || c == '\n' || whitespace_cr (c)))
{
- while (c == ' ' || c == '\t' || whitespace_cr (c))
- c = GETC ();
- if (c == '\n')
- return c;
-
-#if defined HANDLE_PRAGMA || defined HANDLE_GENERIC_PRAGMAS
- UNGETC (c);
- token = yylex ();
- if (token != IDENTIFIER)
- goto skipline;
-#endif /* HANDLE_PRAGMA || HANDLE_GENERIC_PRAGMAS */
-
-#ifdef HANDLE_PRAGMA
- /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS (if
- both are defined), in order to give the back end a chance to
- override the interpretation of generic style pragmas. */
-
- if (TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
- goto skipline;
-
- if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
- IDENTIFIER_POINTER (yylval.ttype)))
- return GETC ();
-#endif /* HANDLE_PRAGMA */
-
-#ifdef HANDLE_GENERIC_PRAGMAS
- if (handle_generic_pragma (token))
- return GETC ();
-#endif /* HANDLE_GENERIC_PRAGMAS */
-
- /* Issue a warning message if we have been asked to do so.
- Ignoring unknown pragmas in system header file unless
- an explcit -Wunknown-pragmas has been given. */
- if (warn_unknown_pragmas > 1
- || (warn_unknown_pragmas && ! in_system_header))
- warning ("ignoring pragma: %s", token_buffer);
-
+ warning ("ignoring pragma");
goto skipline;
}
}
@@ -568,45 +492,6 @@ check_newline ()
&& ((c = GETC()) == ' ' || c == '\t'))
goto linenum;
}
- else if (c == 'i')
- {
- if (GETC() == 'd'
- && GETC() == 'e'
- && GETC() == 'n'
- && GETC() == 't'
- && ((c = GETC()) == ' ' || c == '\t'))
- {
- /* #ident. The pedantic warning is now in cccp.c. */
-
- /* Here we have just seen `#ident '.
- A string constant should follow. */
-
- c = skip_white_space_on_line ();
-
- /* If no argument, ignore the line. */
- if (c == '\n')
- return c;
-
- UNGETC (c);
- token = yylex ();
- if (token != STRING
- || TREE_CODE (yylval.ttype) != STRING_CST)
- {
- error ("invalid #ident");
- goto skipline;
- }
-
- if (!flag_no_ident)
- {
-#ifdef ASM_OUTPUT_IDENT
- ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
-#endif
- }
-
- /* Skip the rest of this line. */
- goto skipline;
- }
- }
error ("undefined or invalid # directive");
goto skipline;
@@ -782,50 +667,7 @@ linenum:
c = GETC();
return c;
}
-
-#ifdef HANDLE_GENERIC_PRAGMAS
-/* Handle a #pragma directive.
- TOKEN is the token we read after `#pragma'. Processes the entire input
- line and return non-zero iff the pragma has been successfully parsed. */
-
-/* This function has to be in this file, in order to get at
- the token types. */
-
-static int
-handle_generic_pragma (token)
- register int token;
-{
- register int c;
-
- for (;;)
- {
- switch (token)
- {
- case IDENTIFIER:
- case TYPENAME:
- case STRING:
- case CONSTANT:
- handle_pragma_token (token_buffer, yylval.ttype);
- break;
- default:
- handle_pragma_token (token_buffer, NULL);
- }
- c = GETC ();
-
- while (c == ' ' || c == '\t')
- c = GETC ();
- UNGETC (c);
-
- if (c == '\n' || c == EOF)
- return handle_pragma_token (NULL, NULL);
-
- token = yylex ();
- }
-}
-
-#endif /* HANDLE_GENERIC_PRAGMAS */
-
#define ENDFILE -1 /* token that represents end-of-file */
/* Read an escape sequence, returning its equivalent as a character,
@@ -1022,7 +864,7 @@ yylex ()
register int value;
int wide_flag = 0;
- c = GETC();
+ c = GETC();
/* Effectively do c = skip_white_space (c)
but do it faster in the usual cases. */
@@ -1097,20 +939,10 @@ yylex ()
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
case '_':
- case '$':
letter:
p = token_buffer;
- while (ISALNUM (c) || c == '_' || c == '$')
+ while (ISALNUM (c) || c == '_')
{
- /* Make sure this char really belongs in an identifier. */
- if (c == '$')
- {
- if (! dollars_in_ident)
- error ("`$' in identifier");
- else if (pedantic)
- pedwarn ("`$' in identifier");
- }
-
if (p >= token_buffer + maxtoken)
p = extend_token_buffer (p);
@@ -1714,7 +1546,7 @@ yylex ()
UNGETC (c);
*p = 0;
- if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
+ if (ISALNUM (c) || c == '.' || c == '_'
|| (!flag_traditional && (c == '-' || c == '+')
&& (p[-1] == 'e' || p[-1] == 'E')))
error ("missing white space after number `%s'", token_buffer);
@@ -1730,10 +1562,6 @@ yylex ()
int chars_seen = 0;
unsigned width = TYPE_PRECISION (char_type_node);
int max_chars;
-#ifdef MULTIBYTE_CHARS
- int longest_char = local_mb_cur_max ();
- (void) local_mbtowc (NULL, NULL, 0);
-#endif
max_chars = TYPE_PRECISION (integer_type_node) / width;
if (wide_flag)
@@ -1757,10 +1585,6 @@ yylex ()
if (width < HOST_BITS_PER_INT
&& (unsigned) c >= ((unsigned)1 << width))
pedwarn ("escape sequence out of range for character");
-#ifdef MAP_CHARACTER
- if (ISPRINT (c))
- c = MAP_CHARACTER (c);
-#endif
}
else if (c == '\n')
{
@@ -1768,66 +1592,6 @@ yylex ()
pedwarn ("ANSI C forbids newline in character constant");
lineno++;
}
- else
- {
-#ifdef MULTIBYTE_CHARS
- wchar_t wc;
- int i;
- int char_len = -1;
- for (i = 1; i <= longest_char; ++i)
- {
- if (i > maxtoken - 4)
- extend_token_buffer (token_buffer);
-
- token_buffer[i] = c;
- char_len = local_mbtowc (& wc,
- token_buffer + 1,
- i);
- if (char_len != -1)
- break;
- c = GETC ();
- }
- if (char_len > 1)
- {
- /* mbtowc sometimes needs an extra char before accepting */
- if (char_len < i)
- UNGETC (c);
- if (! wide_flag)
- {
- /* Merge character into result; ignore excess chars. */
- for (i = 1; i <= char_len; ++i)
- {
- if (i > max_chars)
- break;
- if (width < HOST_BITS_PER_INT)
- result = (result << width)
- | (token_buffer[i]
- & ((1 << width) - 1));
- else
- result = token_buffer[i];
- }
- num_chars += char_len;
- goto tryagain;
- }
- c = wc;
- }
- else
- {
- if (char_len == -1)
- warning ("Ignoring invalid multibyte character");
- if (wide_flag)
- c = wc;
-#ifdef MAP_CHARACTER
- else
- c = MAP_CHARACTER (c);
-#endif
- }
-#else /* ! MULTIBYTE_CHARS */
-#ifdef MAP_CHARACTER
- c = MAP_CHARACTER (c);
-#endif
-#endif /* ! MULTIBYTE_CHARS */
- }
if (wide_flag)
{
@@ -1894,10 +1658,6 @@ yylex ()
{
unsigned width = wide_flag ? WCHAR_TYPE_SIZE
: TYPE_PRECISION (char_type_node);
-#ifdef MULTIBYTE_CHARS
- int longest_char = local_mb_cur_max ();
- (void) local_mbtowc (NULL, NULL, 0);
-#endif
c = GETC ();
p = token_buffer + 1;
@@ -1919,40 +1679,6 @@ yylex ()
pedwarn ("ANSI C forbids newline in string constant");
lineno++;
}
- else
- {
-#ifdef MULTIBYTE_CHARS
- wchar_t wc;
- int i;
- int char_len = -1;
- for (i = 0; i < longest_char; ++i)
- {
- if (p + i >= token_buffer + maxtoken)
- p = extend_token_buffer (p);
- p[i] = c;
-
- char_len = local_mbtowc (& wc, p, i + 1);
- if (char_len != -1)
- break;
- c = GETC ();
- }
- if (char_len == -1)
- warning ("Ignoring invalid multibyte character");
- else
- {
- /* mbtowc sometimes needs an extra char before accepting */
- if (char_len <= i)
- UNGETC (c);
- if (! wide_flag)
- {
- p += (i + 1);
- c = GETC ();
- continue;
- }
- c = wc;
- }
-#endif /* MULTIBYTE_CHARS */
- }
/* Add this single character into the buffer either as a wchar_t
or as a single byte. */