torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Driver.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /*******************************************************************************
17  * TORC - Copyright 2010 University of Southern California. All Rights Reserved.
18  *
19  * FILE : driver.cpp
20  *
21  * DATE : 08-July-2010
22  *
23  * DESCRIPTION : Defination of the torc::generic::Driver class
24  *
25  * REVISION HISTORY:
26  *
27  * SI REVISION AUTHOR CHANGES PRs
28  *[0] Initial Version Niladri
29  *[1] Initial Version Santanu
30  *
31  *******************************************************************************/
32 
33 #include <fstream>
34 #include <sstream>
35 
43 
44 namespace torc {
45 namespace generic {
46 
47 Driver::Driver(const EdifContextSharedPtr& inEdifCntx) : mTraceScanning(false),
48  mTraceParsing(false), mEdifCntx(inEdifCntx), mErrorObj() {}
49 
50 Driver::~Driver() throw () {}
51 
52 bool Driver::parseStream(std::istream& inStream, const std::string& inStreamName) {
53  mStreamName = inStreamName;
54 
55  Scanner scanner(&inStream);
56  scanner.set_debug(mTraceScanning);
57  this->mLexer = &scanner;
58 
59  Parser parser(*this);
61  return (parser.parse() == 0);
62 }
63 
64 bool Driver::parseFile(const std::string& inFileName) {
65  std::ifstream in(inFileName.c_str());
66  if(!in.good()) {
67  return false;
68  }
69  return parseStream(in, inFileName);
70 }
71 
72 bool Driver::parseString(const std::string& inString, const std::string& inStreamName) {
73  std::istringstream iss(inString);
74  return parseStream(iss, inStreamName);
75 }
76 
77 void Driver::error(const location& inLocation, const std::string& inMessage) {
78  std::cerr << "Error at:" << inLocation << ": " << inMessage << std::endl;
79 }
80 
81 void Driver::error(const std::string& inMessage) {
82  std::cerr << inMessage << std::endl;
83 }
84 
85 void Driver::setParserError(const Error& inSource) {
86  mErrorObj = ErrorSharedPtr(new Error(inSource));
87 }
88 
89 } // namespace generic
90 } // namespace torc
boost::shared_ptr< EdifContext > EdifContextSharedPtr
void set_debug_level(debug_level_type l)
Set the current debugging level.
A Bison parser.
Definition: Parser.h:111
Driver(const EdifContextSharedPtr &inEdifCntx)
construct a new parser driver context
Definition: Driver.cpp:47
ErrorSharedPtr mErrorObj
Definition: Driver.hpp:116
boost::shared_ptr< Error > ErrorSharedPtr
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
std::string mStreamName
Definition: Driver.hpp:105
bool parseStream(std::istream &inStream, const std::string &inStreamName="stream input")
Definition: Driver.cpp:52
bool parseFile(const std::string &inFileName)
Definition: Driver.cpp:64
void set_debug(bool b)
Definition: Scanner.cc:7125
void error(const class location &inLocation, const std::string &inMessage)
virtual int parse()
Definition: Parser.cc:2120
void setParserError(const Error &inSource)
Definition: Driver.cpp:85
bool parseString(const std::string &inString, const std::string &inStreamName="string stream")
Definition: Driver.cpp:72