OpenASIP  2.0
Script.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file Script.cc
26  *
27  * Definition of Script class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31  */
32 
33 #include <string>
34 using std::string;
35 #include <vector>
36 using std::vector;
37 
38 #include "Script.hh"
39 #include "Application.hh"
40 
41 /**
42  * Constructor.
43  *
44  * @param interpreter Interpreter for script.
45  * @param scriptLine A line of script.
46  */
47 Script::Script(ScriptInterpreter* interpreter, std::string scriptLine) :
48  interpreter_(interpreter), executeCalled_(false) {
49  scriptLines_.push_back(scriptLine);
50 }
51 
52 /**
53  * Constructor.
54  *
55  * @param interpreter Interpreter for script.
56  * @param script Script lines.
57  */
59  ScriptInterpreter* interpreter,
60  std::vector<std::string>& script) {
61 
62  interpreter_ = interpreter;
63  for (unsigned int i = 0; i < script.size(); i++) {
64  scriptLines_.push_back(script[i]);
65  }
66 }
67 
68 /**
69  * Destructor.
70  */
72 }
73 
74 /**
75  * Executes the script.
76  *
77  * @return The result of execution as a DataObject.
78  * @exception ScriptExecutionFailure If execution of script fails.
79  * @exception NumberFormatException If DataObject operation fails.
80  */
84 
85  for (unsigned int i = 0; i < scriptLines_.size(); i++) {
87  string method = "Script::execute()";
88  string message = "Interpreter error: " +
90  throw ScriptExecutionFailure(__FILE__, __LINE__, method, message);
91  }
92  }
93  DataObject obj;
95  result_ = obj;
96  executeCalled_ = true;
97  return obj;
98 }
99 
100 /**
101  * Returns the script.
102  *
103  * @return The script.
104  */
105 std::vector<std::string>
106 Script::script() const {
107  return scriptLines_;
108 }
Script::scriptLines_
std::vector< std::string > scriptLines_
Contains script.
Definition: Script.hh:65
Script::execute
virtual DataObject execute()
Definition: Script.cc:82
Script::script
virtual std::vector< std::string > script() const
Definition: Script.cc:106
Script::executeCalled_
bool executeCalled_
Flag indicating whether script has been executed or not.
Definition: Script.hh:63
ScriptInterpreter::result
virtual std::string result()
Definition: ScriptInterpreter.cc:191
DataObject
Definition: DataObject.hh:50
Script::result_
DataObject result_
Result of execution.
Definition: Script.hh:61
Application.hh
Script::interpreter_
ScriptInterpreter * interpreter_
Interpreter executing the commands.
Definition: Script.hh:58
ScriptInterpreter::interpret
virtual bool interpret(const std::string &commandLine)=0
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
Application::initialize
static void initialize()
Definition: Application.cc:99
ScriptExecutionFailure
Definition: Exception.hh:657
Script.hh
Script::Script
Script(ScriptInterpreter *interpreter, std::string scriptLine)
Definition: Script.cc:47
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
Script::~Script
virtual ~Script()
Definition: Script.cc:71