opts);
if( inputFromStdin ) {
-#if defined(CVC5_COMPETITION_MODE) && !defined(CVC5_SMTCOMP_APPLICATION_TRACK)
parserBuilder.withStreamInput(cin);
-#else /* CVC5_COMPETITION_MODE && !CVC5_SMTCOMP_APPLICATION_TRACK */
- parserBuilder.withLineBufferedStreamInput(cin);
-#endif /* CVC5_COMPETITION_MODE && !CVC5_SMTCOMP_APPLICATION_TRACK */
}
vector< vector<Command*> > allCommands;
opts);
if( inputFromStdin ) {
-#if defined(CVC5_COMPETITION_MODE) && !defined(CVC5_SMTCOMP_APPLICATION_TRACK)
parserBuilder.withStreamInput(cin);
-#else /* CVC5_COMPETITION_MODE && !CVC5_SMTCOMP_APPLICATION_TRACK */
- parserBuilder.withLineBufferedStreamInput(cin);
-#endif /* CVC5_COMPETITION_MODE && !CVC5_SMTCOMP_APPLICATION_TRACK */
}
std::unique_ptr<Parser> parser(parserBuilder.build());
#include "parser/antlr_input.h"
#include <antlr3.h>
-#include <limits.h>
+#include <limits>
#include "base/check.h"
#include "base/output.h"
return new AntlrInputStream(name, input, false, NULL, NULL);
}
-
-AntlrInputStream*
-AntlrInputStream::newStreamInputStream(std::istream& input,
- const std::string& name,
- bool lineBuffered)
+AntlrInputStream* AntlrInputStream::newStreamInputStream(
+ std::istream& input, const std::string& name)
{
pANTLR3_INPUT_STREAM inputStream = NULL;
pANTLR3_UINT8 inputStringCopy = NULL;
- LineBuffer* line_buffer = NULL;
-
- if(lineBuffered) {
- line_buffer = new LineBuffer(&input);
- inputStream = newAntlr3BufferedStream(input, name, line_buffer);
- } else {
-
- // Since these are all NULL on entry, realloc will be called
- char *basep = NULL, *boundp = NULL, *cp = NULL;
- /* 64KB seems like a reasonable default size. */
- size_t bufSize = 0x10000;
-
- /* Keep going until we can't go no more. */
- while( !input.eof() && !input.fail() ) {
-
- if( cp == boundp ) {
- /* We ran out of room in the buffer. Realloc at double the size. */
- ptrdiff_t offset = cp - basep;
- basep = (char *) realloc(basep, bufSize);
- if( basep == NULL ) {
- throw InputStreamException("Failed buffering input stream: " + name);
- }
- cp = basep + offset;
- boundp = basep + bufSize;
- bufSize *= 2;
- }
-
- /* Read as much as we have room for. */
- input.read( cp, boundp - cp );
- cp += input.gcount();
- }
-
- /* Make sure the fail bit didn't get set. */
- if( !input.eof() ) {
- throw InputStreamException("Stream input failed: " + name);
- }
- ptrdiff_t offset = cp - basep;
- Assert(offset >= 0);
- Assert(offset <= std::numeric_limits<uint32_t>::max());
- inputStringCopy = (pANTLR3_UINT8)basep;
- inputStream = newAntrl3InPlaceStream(inputStringCopy, (uint32_t) offset, name);
- }
-
- if( inputStream == NULL ) {
- throw InputStreamException("Couldn't initialize input: " + name);
- }
-
+ LineBuffer* line_buffer = new LineBuffer(&input);
+ inputStream = newAntlr3BufferedStream(input, name, line_buffer);
return new AntlrInputStream(name, inputStream, false, inputStringCopy,
line_buffer);
}
/** Create an input from an istream. */
static AntlrInputStream* newStreamInputStream(std::istream& input,
- const std::string& name,
- bool lineBuffered = false);
+ const std::string& name);
/** Create a string input.
* NOTE: the new AntlrInputStream will take ownership of input over
Input* Input::newStreamInput(InputLanguage lang,
std::istream& input,
- const std::string& name,
- bool lineBuffered)
+ const std::string& name)
{
- AntlrInputStream *inputStream =
- AntlrInputStream::newStreamInputStream(input, name, lineBuffered);
+ AntlrInputStream* inputStream =
+ AntlrInputStream::newStreamInputStream(input, name);
return AntlrInput::newInput(lang, *inputStream);
}
*/
static Input* newStreamInput(InputLanguage lang,
std::istream& input,
- const std::string& name,
- bool lineBuffered = false);
+ const std::string& name);
/** Create an input for the given string
*
case FILE_INPUT:
input = Input::newFileInput(d_lang, d_filename, d_mmap);
break;
- case LINE_BUFFERED_STREAM_INPUT:
- Assert(d_streamInput != NULL);
- input = Input::newStreamInput(d_lang, *d_streamInput, d_filename, true);
- break;
case STREAM_INPUT:
Assert(d_streamInput != NULL);
input = Input::newStreamInput(d_lang, *d_streamInput, d_filename);
return *this;
}
-ParserBuilder& ParserBuilder::withLineBufferedStreamInput(std::istream& input) {
- d_inputType = LINE_BUFFERED_STREAM_INPUT;
- d_streamInput = &input;
- return *this;
-}
-
ParserBuilder& ParserBuilder::withStringInput(const std::string& input) {
d_inputType = STRING_INPUT;
d_stringInput = input;
{
enum InputType {
FILE_INPUT,
- LINE_BUFFERED_STREAM_INPUT,
STREAM_INPUT,
STRING_INPUT
};
/** Set the parser to use the given stream for its input. */
ParserBuilder& withStreamInput(std::istream& input);
- /** Set the parser to use the given stream for its input. */
- ParserBuilder& withLineBufferedStreamInput(std::istream& input);
-
/** Set the parser to use the given string for its input. */
ParserBuilder& withStringInput(const std::string& input);