OpenASIP  2.0
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. More...
 

Private Attributes

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

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 }

◆ 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()),
59  interpreter_(cmd.interpreter()) {
60 }

◆ ~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 }

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

Referenced by HelpCommand::execute(), KillCommand::execute(), QuitCommand::execute(), DisableBPCommand::execute(), IgnoreCommand::execute(), StepiCommand::execute(), ResumeCommand::execute(), ConditionCommand::execute(), UntilCommand::execute(), CommandsCommand::execute(), WatchCommand::execute(), MemDumpCommand::execute(), EnableBPCommand::execute(), NextiCommand::execute(), BackTraceCommand::execute(), InfoCommand::execute(), MemWriteCommand::execute(), SymbolAddressCommand::execute(), DisassembleCommand::execute(), and SettingCommand::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 }

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 }

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(), ResumeCommand::execute(), NextiCommand::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 }

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(), HelpCommand::execute(), QuitCommand::execute(), KillCommand::execute(), ConfCommand::execute(), MachCommand::execute(), ProgCommand::execute(), BackTraceCommand::execute(), ConditionCommand::execute(), DeleteBPCommand::execute(), CommandsCommand::execute(), IgnoreCommand::execute(), MemDumpCommand::execute(), DisassembleCommand::execute(), SymbolAddressCommand::execute(), InfoCommand::execute(), MemWriteCommand::execute(), SettingCommand::execute(), CmdHelp::execute(), CmdTrigger::execute(), CmdReset::execute(), CmdQuit::execute(), InfoRegistersCommand::execute(), CmdOutput::execute(), CmdRegister::execute(), CmdMem::execute(), CmdAdvanceClock::execute(), InfoImmediatesCommand::execute(), InfoRegFilesCommand::execute(), InfoIunitsCommand::execute(), InfoBussesCommand::execute(), InfoPortsCommand::execute(), InfoSegmentsCommand::execute(), InfoFunitsCommand::execute(), InfoProcCommand::execute(), InfoStatsCommand::execute(), InfoProgramCommand::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:
CustomCommand::name
std::string name() const
NumberFormatException
Definition: Exception.hh:421
DataObject
Definition: DataObject.hh:50
DataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:344
CustomCommand::context
InterpreterContext * context() const
CustomCommand::name_
std::string name_
The name of the command.
Definition: CustomCommand.hh:83
DataObject::doubleValue
virtual double doubleValue() const
Definition: DataObject.cc:386
DataObject::integerValue
virtual int integerValue() const
Definition: DataObject.cc:204
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
DataObject::setString
virtual void setString(std::string value)
Definition: DataObject.cc:130
CustomCommand::interpreter_
ScriptInterpreter * interpreter_
Interpreter for the command.
Definition: CustomCommand.hh:87
CustomCommand::context_
InterpreterContext * context_
Context of the command.
Definition: CustomCommand.hh:85