/* Input handling for G++.
Copyright (C) 1992, 1993 Free Software Foundation, Inc.
Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* G++ needs to do enough saving and re-parsing of text that it is
necessary to abandon the simple FILE* model and use a mechanism where
we can pre-empt one input stream with another derived from saved text;
we may need to do this arbitrarily often, and cannot depend on having
the GNU library available, so FILE objects just don't cut it.
This file is written as a separate module, but can be included by
cp-lex.c for very minor efficiency gains (primarily in function
struct pending_input
*save_pending_input ();
void restore_pending_input ();
/* current position, when reading as input */
/* obstack to free this input string from when finished, if any */
/* linked list maintenance */
struct input_source
*next
;
/* values to restore after reading all of current string */
struct pending_input
*input
;
static struct input_source
*input
, *free_inputs
;
extern char *input_filename
;
#define inline __inline__
static inline struct input_source
*
struct input_source
*inp
;
inp
= (struct input_source
*) xmalloc (sizeof (struct input_source
));
struct input_source
*inp
;
obstack_free (inp
->obstack
, inp
->str
);
static int putback_char
= -1;
/* Some of these external functions are declared inline in case this file
is included in cp-lex.c. */
feed_input (str
, len
, delete)
struct input_source
*inp
= allocate_input ();
/* This shouldn't be necessary. */
while (len
&& !str
[len
-1])
inp
->filename
= input_filename
;
inp
->input
= save_pending_input ();
inp
->putback_char
= putback_char
;
struct pending_input
*to_be_restored
; /* XXX */
if (input
->offset
== input
->length
)
struct input_source
*inp
= input
;
my_friendly_assert (putback_char
== -1, 223);
to_be_restored
= inp
->input
;
else if (input
->offset
> input
->length
)
struct input_source
*inp
= input
;
input_filename
= inp
->filename
;
/* Get interface/implementation back in sync. */
extract_interface_info ();
putback_char
= inp
->putback_char
;
return input
->str
[input
->offset
++];
my_friendly_assert (putback_char
== -1, 224);