void process( InputData &id ) { /* Open the input file for reading. */ assert( id.inputFileName != 0 ); ifstream *inFile = new ifstream( id.inputFileName ); if ( ! inFile->is_open() ) error() << "could not open " << id.inputFileName << " for reading" << endp; /* Used for just a few things. */ std::ostringstream hostData; /* Make the first input item. */ InputItem *firstInputItem = new InputItem; firstInputItem->type = InputItem::HostData; firstInputItem->loc.fileName = id.inputFileName; firstInputItem->loc.line = 1; firstInputItem->loc.col = 1; id.inputItems.append( firstInputItem ); Scanner scanner( id, id.inputFileName, *inFile, 0, 0, 0, false ); scanner.do_scan(); /* Finished, final check for errors.. */ if ( gblErrorCount > 0 ) exit(1); /* Now send EOF to all parsers. */ id.terminateAllParsers(); /* Bail on above error. */ if ( gblErrorCount > 0 ) exit(1); /* Locate the backend program */ /* Compiles machines. */ id.prepareMachineGen(); if ( gblErrorCount > 0 ) exit(1); id.makeOutputStream(); /* Generates the reduced machine, which we use to write output. */ if ( !generateXML ) { id.generateReduced(); if ( gblErrorCount > 0 ) exit(1); } id.verifyWritesHaveData(); if ( gblErrorCount > 0 ) exit(1); /* * From this point on we should not be reporting any errors. */ id.openOutput(); id.writeOutput(); /* Close the input and the intermediate file. */ delete inFile; /* If writing to a file, delete the ostream, causing it to flush. * Standard out is flushed automatically. */ if ( id.outputFileName != 0 ) { delete id.outStream; delete id.outFilter; } assert( gblErrorCount == 0 ); }