OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CustomCommand Class Referenceabstract

#include <CustomCommand.hh>

Inheritance diagram for CustomCommand:
Inheritance graph
Collaboration diagram for CustomCommand:
Collaboration graph

Public Member Functions

 CustomCommand (std::string name)
 
 CustomCommand (const CustomCommand &cmd)
 
virtual ~CustomCommand ()
 
std::string name () const
 
void setContext (InterpreterContext *context)
 
InterpreterContextcontext () const
 
void setInterpreter (ScriptInterpreter *si)
 
ScriptInterpreterinterpreter () const
 
virtual bool execute (const std::vector< DataObject > &arguments)=0
 
virtual std::string helpText () const =0
 
bool checkArgumentCount (int argumentCount, int minimum, int maximum)
 
bool checkIntegerArgument (const DataObject &argument)
 
bool checkPositiveIntegerArgument (const DataObject &argument)
 
bool checkUnsignedIntegerArgument (const DataObject &argument)
 
bool checkDoubleArgument (const DataObject &argument)
 

Private Member Functions

CustomCommandoperator= (const CustomCommand &)
 Assignment not allowed.
 

Private Attributes

std::string name_
 The name of the command.
 
InterpreterContextcontext_
 Context of the command.
 
ScriptInterpreterinterpreter_
 Interpreter for the command.
 

Detailed Description

Abstract base class for all CustomCommands for Interpreter.

CustomCommand is a user defined command designed for a particular task.

Definition at line 54 of file CustomCommand.hh.

Constructor & Destructor Documentation

◆ CustomCommand() [1/2]

CustomCommand::CustomCommand ( std::string  name)
explicit

Constructor.

Parameters
nameThe name of the command.

Definition at line 48 of file CustomCommand.cc.

48 :
49 name_(name), context_(NULL), interpreter_(NULL) {
50}
std::string name_
The name of the command.
std::string name() const
ScriptInterpreter * interpreter_
Interpreter for the command.
InterpreterContext * context_
Context of the command.

◆ CustomCommand() [2/2]

CustomCommand::CustomCommand ( const CustomCommand cmd)

Copy Constructor.

Parameters
cmdCustomCommand to be copied.

Definition at line 57 of file CustomCommand.cc.

57 :
58 name_(cmd.name()), context_(cmd.context()),
60}
InterpreterContext * context() const
ScriptInterpreter * interpreter() const

◆ ~CustomCommand()

CustomCommand::~CustomCommand ( )
virtual

Destructor.

Definition at line 66 of file CustomCommand.cc.

66 {
67}

Member Function Documentation

◆ checkArgumentCount()

bool CustomCommand::checkArgumentCount ( int  argumentCount,
int  minimum,
int  maximum 
)

Checks if the count of arguments fits between the given minimum and maximum arguments.

If the count of arguments is wrong, sets the error message and returns false.

Parameters
argumentCountThe count of the arguments.
minimumMinimum amount of arguments.
maximumMaximum amount of arguments.
Returns
True if the count of arguments is valid.

Definition at line 82 of file CustomCommand.cc.

85 {
86
87 if (argumentCount < minimum) {
88 DataObject* result = new DataObject();
89 result->setString("Not enough arguments.");
90 interpreter()->setResult(result);
91 return false;
92 } else if (argumentCount > maximum) {
93 DataObject* result = new DataObject();
94 result->setString("Too many arguments.");
95 interpreter()->setResult(result);
96 return false;
97 }
98 return true;
99}
virtual void setString(std::string value)
virtual void setResult(DataObject *result)

References interpreter(), ScriptInterpreter::setResult(), and DataObject::setString().

Referenced by BackTraceCommand::execute(), CommandsCommand::execute(), ConditionCommand::execute(), DisableBPCommand::execute(), DisassembleCommand::execute(), EnableBPCommand::execute(), HelpCommand::execute(), IgnoreCommand::execute(), InfoCommand::execute(), KillCommand::execute(), MemDumpCommand::execute(), MemWriteCommand::execute(), NextiCommand::execute(), QuitCommand::execute(), ResumeCommand::execute(), SettingCommand::execute(), StepiCommand::execute(), SymbolAddressCommand::execute(), UntilCommand::execute(), and WatchCommand::execute().

Here is the call graph for this function:

◆ checkDoubleArgument()

bool CustomCommand::checkDoubleArgument ( const DataObject argument)

Checks if the given argument is a valid double

If the argument is not double, sets the error message and returns false.

Parameters
argumentThe argument to check.
Returns
True if argument is double.

Definition at line 195 of file CustomCommand.cc.

195 {
196 try {
197 argument.doubleValue();
198 } catch (const NumberFormatException&) {
199 DataObject* result = new DataObject();
200 result->setString("Argument not double as expected.");
201 interpreter()->setResult(result);
202 return false;
203 }
204 return true;
205}
virtual double doubleValue() const

References DataObject::doubleValue(), interpreter(), ScriptInterpreter::setResult(), and DataObject::setString().

Referenced by StepiCommand::execute().

Here is the call graph for this function:

◆ checkIntegerArgument()

bool CustomCommand::checkIntegerArgument ( const DataObject argument)

Checks if the given argument is an integer.

If argument is not integer, sets the error message and returns false.

Parameters
argumentThe argument to check.
Returns
True if argument is integer.

Definition at line 110 of file CustomCommand.cc.

110 {
111 try {
112 argument.integerValue();
113 } catch (const NumberFormatException&) {
114 DataObject* result = new DataObject();
115 result->setString("Argument not integer as expected.");
116 interpreter()->setResult(result);
117 return false;
118 }
119 return true;
120}
virtual int integerValue() const

References DataObject::integerValue(), interpreter(), ScriptInterpreter::setResult(), and DataObject::setString().

Referenced by ConditionCommand::execute().

Here is the call graph for this function:

◆ checkPositiveIntegerArgument()

bool CustomCommand::checkPositiveIntegerArgument ( const DataObject argument)

Checks if the given argument is a positive integer (zero is included).

If argument is not positive integer, sets the error message and returns false. Note that this function assumes that the value range is that of an 'int', i.e., the maximum positive value is less than that of an 'unsigned int'.

Parameters
argumentThe argument to check.
Returns
True if argument is integer.

Definition at line 134 of file CustomCommand.cc.

134 {
135 bool argumentOk = false;
136 try {
137 argumentOk = (argument.integerValue() >= 0);
138
139 } catch (const NumberFormatException&) {
140 argumentOk = false;
141 }
142
143 if (!argumentOk) {
144 DataObject* result = new DataObject();
145 result->setString("Argument not positive integer as expected.");
146 interpreter()->setResult(result);
147 return false;
148 }
149
150 return true;
151}

References DataObject::integerValue(), interpreter(), ScriptInterpreter::setResult(), and DataObject::setString().

Referenced by CommandsCommand::execute(), IgnoreCommand::execute(), NextiCommand::execute(), ResumeCommand::execute(), and SimControlLanguageCommand::verifyBreakpointHandles().

Here is the call graph for this function:

◆ checkUnsignedIntegerArgument()

bool CustomCommand::checkUnsignedIntegerArgument ( const DataObject argument)

Checks if the given argument is an unsigned integer.

If argument is not unsigned integer, sets the error message and returns false. This function assumes that the value range of the argument is that of an 'unsigned int'.

Parameters
argumentThe argument to check.
Returns
True if argument is integer.

Definition at line 164 of file CustomCommand.cc.

164 {
165
166 try {
167 if (argument.stringValue().size() > 0) {
168 // ensure the first char is a digit, not a '-'
169 if (isdigit(argument.stringValue().at(0))) {
170 // this should throw NumberFormatException if the argument
171 // cannot be converted to an int
172 argument.integerValue();
173 return true;
174 }
175 }
176 } catch (const NumberFormatException&) {
177 }
178
179 // some of the checks failed, it's not an unsigned int
180 DataObject* result = new DataObject();
181 result->setString("Argument not positive integer as expected.");
182 interpreter()->setResult(result);
183 return false;
184}
virtual std::string stringValue() const

References DataObject::integerValue(), interpreter(), ScriptInterpreter::setResult(), DataObject::setString(), and DataObject::stringValue().

Referenced by MemDumpCommand::execute().

Here is the call graph for this function:

◆ context()

InterpreterContext * CustomCommand::context ( ) const

◆ execute()

virtual bool CustomCommand::execute ( const std::vector< DataObject > &  arguments)
pure virtual

◆ helpText()

virtual std::string CustomCommand::helpText ( ) const
pure virtual

◆ interpreter()

ScriptInterpreter * CustomCommand::interpreter ( ) const

Referenced by SimControlLanguageCommand::askConditionFromUser(), SimControlLanguageCommand::askExpressionFromUser(), checkArgumentCount(), checkDoubleArgument(), checkIntegerArgument(), SimControlLanguageCommand::checkMachineLoaded(), checkPositiveIntegerArgument(), SimControlLanguageCommand::checkProgramLoaded(), SimControlLanguageCommand::checkSimulationEnded(), SimControlLanguageCommand::checkSimulationInitialized(), SimControlLanguageCommand::checkSimulationNotAlreadyRunning(), SimControlLanguageCommand::checkSimulationStopped(), checkUnsignedIntegerArgument(), CmdHelp::execute(), BackTraceCommand::execute(), CommandsCommand::execute(), ConditionCommand::execute(), ConfCommand::execute(), DeleteBPCommand::execute(), DisassembleCommand::execute(), HelpCommand::execute(), IgnoreCommand::execute(), InfoRegistersCommand::execute(), InfoImmediatesCommand::execute(), InfoRegFilesCommand::execute(), InfoIunitsCommand::execute(), InfoBussesCommand::execute(), InfoPortsCommand::execute(), InfoSegmentsCommand::execute(), InfoFunitsCommand::execute(), InfoProcCommand::execute(), InfoStatsCommand::execute(), InfoProgramCommand::execute(), InfoCommand::execute(), KillCommand::execute(), MachCommand::execute(), MemDumpCommand::execute(), MemWriteCommand::execute(), ProgCommand::execute(), QuitCommand::execute(), SettingCommand::execute(), SymbolAddressCommand::execute(), CmdTrigger::execute(), CmdReset::execute(), CmdQuit::execute(), CmdOutput::execute(), CmdRegister::execute(), CmdMem::execute(), CmdAdvanceClock::execute(), CmdOutput::helpText(), SimControlLanguageCommand::outputStream(), SimControlLanguageCommand::parseBreakpoint(), SimControlLanguageCommand::parseDataAddressExpression(), SimControlLanguageCommand::parseInstructionAddressExpression(), SimControlLanguageCommand::printBreakpointInfo(), SimControlLanguageCommand::setErrorMessage(), SimControlLanguageCommand::setMemoryPointer(), SimControlLanguageCommand::simulatorFrontend(), and SimControlLanguageCommand::verifyBreakpointHandles().

◆ name()

std::string CustomCommand::name ( ) const

◆ operator=()

CustomCommand & CustomCommand::operator= ( const CustomCommand )
private

Assignment not allowed.

◆ setContext()

void CustomCommand::setContext ( InterpreterContext context)

◆ setInterpreter()

void CustomCommand::setInterpreter ( ScriptInterpreter si)

Member Data Documentation

◆ context_

InterpreterContext* CustomCommand::context_
private

Context of the command.

Definition at line 85 of file CustomCommand.hh.

◆ interpreter_

ScriptInterpreter* CustomCommand::interpreter_
private

Interpreter for the command.

Definition at line 87 of file CustomCommand.hh.

◆ name_

std::string CustomCommand::name_
private

The name of the command.

Definition at line 83 of file CustomCommand.hh.


The documentation for this class was generated from the following files: