OpenASIP  2.0
TclInterpreter.hh
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 TclInterpreter.hh
26  *
27  * The declaration of TclInterpreter class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note reviewed 27 May 2004 by pj, jn, vpj, ll
31  * @note rating: yellow
32  */
33 
34 #ifndef TTA_TCL_INTERPRETER_HH
35 #define TTA_TCL_INTERPRETER_HH
36 
37 #include <string>
38 #include <tcl.h>
39 
40 #include "ScriptInterpreter.hh"
41 #include "Exception.hh"
42 
43 /**
44  * Tcl implementation of ScriptInterpreter.
45  *
46  * Tcl (Tool command language) is a very simple programming language. In TCE
47  * it is used for command language for Simulator. (Maybe for some other
48  * application too.)
49  *
50  * Is able to interpret all tcl commands and user defined CustomCommands.
51  */
53 public:
55  virtual ~TclInterpreter();
56 
57  virtual void initialize(
58  int argc,
59  char* argv[],
61  LineReader* reader);
62 
63  virtual void setVariableToInterpreter(
64  const std::string& name, const DataObject& value);
65  virtual DataObject variable(const std::string& name);
66  virtual bool interpret(const std::string& commandLine);
67  virtual void setResultToInterpreter(const DataObject& value);
68 
69  static DataObject tclObjToDataObject(Tcl_Obj* object);
70  static Tcl_Obj* dataObjectToTclObj(const DataObject& object);
71 
72  virtual bool processScriptFile(const std::string& scriptFileName);
73 
74  static int customCommandRedirector(
75  ClientData cd,
76  Tcl_Interp* interp,
77  int objc,
78  Tcl_Obj *CONST objv[]);
79 
80  virtual InterpreterContext& context() const;
81 
82 protected:
83  virtual void addCustomCommandToInterpreter(const CustomCommand& command);
85  const CustomCommand& command);
86 
87 private:
88  /// Copying not allowed.
90  /// Assignment not allowed
92 
93  /// Context for interpreter.
95  /// Interpreter instance.
96  Tcl_Interp* interpreter_;
97 
98 };
99 
100 #endif
TclInterpreter::addCustomCommandToInterpreter
virtual void addCustomCommandToInterpreter(const CustomCommand &command)
Definition: TclInterpreter.cc:192
TclInterpreter::removeCustomCommandFromInterpreter
virtual void removeCustomCommandFromInterpreter(const CustomCommand &command)
Definition: TclInterpreter.cc:206
Exception.hh
TclInterpreter::variable
virtual DataObject variable(const std::string &name)
Definition: TclInterpreter.cc:122
DataObject
Definition: DataObject.hh:50
TclInterpreter
Definition: TclInterpreter.hh:52
TclInterpreter::interpreter_
Tcl_Interp * interpreter_
Interpreter instance.
Definition: TclInterpreter.hh:96
TclInterpreter::context_
InterpreterContext * context_
Context for interpreter.
Definition: TclInterpreter.hh:94
TclInterpreter::operator=
TclInterpreter & operator=(const TclInterpreter &)
Assignment not allowed.
ScriptInterpreter.hh
CustomCommand
Definition: CustomCommand.hh:54
TclInterpreter::interpret
virtual bool interpret(const std::string &commandLine)
Definition: TclInterpreter.cc:138
InterpreterContext
Definition: InterpreterContext.hh:40
TclInterpreter::setResultToInterpreter
virtual void setResultToInterpreter(const DataObject &value)
Definition: TclInterpreter.cc:181
TclInterpreter::TclInterpreter
TclInterpreter()
Definition: TclInterpreter.cc:49
TclInterpreter::context
virtual InterpreterContext & context() const
Definition: TclInterpreter.cc:298
TclInterpreter::~TclInterpreter
virtual ~TclInterpreter()
Definition: TclInterpreter.cc:56
LineReader
Definition: LineReader.hh:52
TclInterpreter::setVariableToInterpreter
virtual void setVariableToInterpreter(const std::string &name, const DataObject &value)
Definition: TclInterpreter.cc:106
TclInterpreter::dataObjectToTclObj
static Tcl_Obj * dataObjectToTclObj(const DataObject &object)
Definition: TclInterpreter.cc:235
TclInterpreter::initialize
virtual void initialize(int argc, char *argv[], InterpreterContext *context, LineReader *reader)
Definition: TclInterpreter.cc:72
ScriptInterpreter
Definition: ScriptInterpreter.hh:55
TclInterpreter::customCommandRedirector
static int customCommandRedirector(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Definition: TclInterpreter.cc:270
TclInterpreter::tclObjToDataObject
static DataObject tclObjToDataObject(Tcl_Obj *object)
Definition: TclInterpreter.cc:221
TclInterpreter::processScriptFile
virtual bool processScriptFile(const std::string &scriptFileName)
Definition: TclInterpreter.cc:250