aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/input.c')
-rw-r--r--gcc/cp/input.c76
1 files changed, 45 insertions, 31 deletions
diff --git a/gcc/cp/input.c b/gcc/cp/input.c
index b7fb9e2..5feb1fd 100644
--- a/gcc/cp/input.c
+++ b/gcc/cp/input.c
@@ -1,6 +1,7 @@
/* Input handling for G++.
Copyright (C) 1992, 93-98, 1999 Free Software Foundation, Inc.
Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
+ Enhanced by Michael Tiemann (tiemann@cygnus.com) to better support USE_CPPLIB
This file is part of GNU CC.
@@ -31,14 +32,16 @@ Boston, MA 02111-1307, USA. */
#include "system.h"
-extern FILE *finput;
-
+#if !USE_CPPLIB
struct putback_buffer {
char *buffer;
int buffer_size;
int index;
};
+static struct putback_buffer putback = {NULL, 0, -1};
+#endif
+
struct input_source {
/* saved string */
char *str;
@@ -51,7 +54,9 @@ struct input_source {
char *filename;
int lineno;
struct pending_input *input;
+#if !USE_CPPLIB
struct putback_buffer putback;
+#endif
};
static struct input_source *input, *free_inputs;
@@ -62,9 +67,6 @@ extern int lineno;
#if USE_CPPLIB
extern unsigned char *yy_cur, *yy_lim;
extern int yy_get_token ();
-#define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
-#else
-#define GETC() getc (finput)
#endif
extern void feed_input PROTO((char *, int));
@@ -76,7 +78,6 @@ extern int input_redirected PROTO((void));
static inline struct input_source * allocate_input PROTO((void));
static inline void free_input PROTO((struct input_source *));
static inline void end_input PROTO((void));
-static inline int sub_getch PROTO((void));
static inline struct input_source *
allocate_input ()
@@ -104,8 +105,6 @@ free_input (inp)
free_inputs = inp;
}
-static struct putback_buffer putback = {NULL, 0, -1};
-
/* Some of these external functions are declared inline in case this file
is included in lex.c. */
@@ -121,21 +120,28 @@ feed_input (str, len)
while (len && !str[len-1])
len--;
+#if USE_CPPLIB
+ if (yy_lim > yy_cur)
+ /* If we've started reading the next token, we're hosed. */
+ my_friendly_abort (990710);
+ cpp_push_buffer (&parse_in, str, len);
+ CPP_BUFFER (&parse_in)->manual_pop = 1;
+#else
inp->str = str;
inp->length = len;
inp->offset = 0;
- inp->next = input;
- inp->filename = input_filename;
- inp->lineno = lineno;
- inp->input = save_pending_input ();
inp->putback = putback;
putback.buffer = NULL;
putback.buffer_size = 0;
putback.index = -1;
+#endif
+ inp->next = input;
+ inp->filename = input_filename;
+ inp->lineno = lineno;
+ inp->input = save_pending_input ();
input = inp;
}
-struct pending_input *to_be_restored; /* XXX */
extern int end_of_file;
static inline void
@@ -143,20 +149,28 @@ end_input ()
{
struct input_source *inp = input;
+#if USE_CPPLIB
+ cpp_pop_buffer (&parse_in);
+#else
+ putback = inp->putback;
+#endif
+
end_of_file = 0;
input = inp->next;
input_filename = inp->filename;
lineno = inp->lineno;
/* Get interface/implementation back in sync. */
extract_interface_info ();
- putback = inp->putback;
restore_pending_input (inp->input);
free_input (inp);
}
-static inline int
-sub_getch ()
+inline int
+getch ()
{
+#if USE_CPPLIB
+ return (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ());
+#else
if (putback.index != -1)
{
int ch = putback.buffer[putback.index];
@@ -178,7 +192,8 @@ sub_getch ()
}
return (unsigned char)input->str[input->offset++];
}
- return GETC ();
+ return getc (finput);
+#endif
}
inline
@@ -186,6 +201,14 @@ void
put_back (ch)
int ch;
{
+#if USE_CPPLIB
+ if (ch == EOF)
+ ;
+ else if (yy_cur[-1] != ch)
+ my_friendly_abort (990709);
+ else
+ yy_cur--;
+#else
if (ch != EOF)
{
if (putback.index == putback.buffer_size - 1)
@@ -196,25 +219,16 @@ put_back (ch)
my_friendly_assert (putback.buffer != NULL, 224);
putback.buffer[++putback.index] = ch;
}
-}
-
-extern int linemode;
-
-int
-getch ()
-{
- int ch = sub_getch ();
- if (linemode && ch == '\n')
- {
- put_back (ch);
- ch = EOF;
- }
- return ch;
+#endif
}
inline
int
input_redirected ()
{
+#ifdef USE_CPPLIB
+ return CPP_BUFFER(&parse_in)->manual_pop;
+#else
return input != 0;
+#endif
}