Revision: 14049
Author: bazald
Date: Wed Jun 18 03:09:10 2014 UTC
Log: New command: break
--sets/--clears :interrupt on a production
--prints which rules have had :interrupt added
http://code.google.com/p/soar/source/detail?r=14049
Added:
/trunk/SoarSuite/Core/CLI/src/cli_break.cpp
Modified:
/trunk/SoarSuite/Core/CLI/CommandLineInterface.cxx
/trunk/SoarSuite/Core/CLI/src/cli_Cli.h
/trunk/SoarSuite/Core/CLI/src/cli_CommandLineInterface.cpp
/trunk/SoarSuite/Core/CLI/src/cli_CommandLineInterface.h
/trunk/SoarSuite/Core/CLI/src/cli_Commands.h
/trunk/SoarSuite/Core/SoarKernel/src/print.cpp
/trunk/SoarSuite/Core/SoarKernel/src/production.h
/trunk/SoarSuite/Core/SoarKernel/src/rete.cpp
/trunk/SoarSuite/Tests/UnitTests/src/cliparsertest.h
=======================================
--- /dev/null
+++ /trunk/SoarSuite/Core/CLI/src/cli_break.cpp Wed Jun 18 03:09:10 2014 UTC
@@ -0,0 +1,66 @@
+/////////////////////////////////////////////////////////////////
+// break command file.
+//
+// Author: Mitchell Keith Bloch,
baz...@umich.edu
+// Date : 2014
+//
+/////////////////////////////////////////////////////////////////
+
+#include <portability.h>
+
+#include "sml_Utils.h"
+#include "cli_CommandLineInterface.h"
+
+#include "cli_Commands.h"
+
+#include <assert.h>
+
+#include "sml_Names.h"
+
+#include "sml_KernelSML.h"
+#include "gsysparam.h"
+#include "rete.h"
+#include "sml_AgentSML.h"
+#include "symtab.h"
+#include "production.h"
+
+using namespace cli;
+using namespace sml;
+
+bool CommandLineInterface::DoBreak(const char &mode, const std::string
&production) {
+ agent* agnt = m_pAgentSML->GetSoarAgent();
+
+ if(mode == 's' || mode == 'c') {
+ Symbol* sym = find_sym_constant(agnt, production.c_str());
+ rete_node* prod = (sym && sym->sc.production) ?
sym->sc.production->p_node : 0;
+
+ if(!prod)
+ return SetError("Production not found: " + production);
+
+ if(mode == 's' && !sym->sc.production->interrupt) {
+ sym->sc.production->interrupt = true;
+ sym->sc.production->interrupt_break = true;
+ }
+ else if(mode == 'c' && sym->sc.production->interrupt) {
+ sym->sc.production->interrupt = false;
+ sym->sc.production->interrupt_break = false;
+ }
+ }
+ else {
+ assert(mode == 'p');
+
+ for(int i = 0; i != NUM_PRODUCTION_TYPES; ++i) {
+ for(struct production_struct * prod =
agnt->all_productions_of_type[i]; prod; prod = prod->next) {
+ if(prod->interrupt_break)
+ m_Result << prod->name->
sc.name << std::endl;
+ }
+ }
+ }
+
+ // Transfer the result from m_XMLResult into pResponse
+ // We pass back the name of the command we just executed which becomes
the tag name
+ // used in the resulting XML.
+ if (!m_RawOutput) XMLResultToResponse("break") ;
+
+ return true;
+}
=======================================
--- /trunk/SoarSuite/Core/CLI/CommandLineInterface.cxx Wed Jun 4 17:17:42
2014 UTC
+++ /trunk/SoarSuite/Core/CLI/CommandLineInterface.cxx Wed Jun 18 03:09:10
2014 UTC
@@ -1,6 +1,7 @@
#include "src/cli_addwme.cpp"
#include "src/cli_alias.cpp"
#include "src/cli_allocate.cpp"
+#include "src/cli_break.cpp"
#include "src/cli_captureinput.cpp"
#include "src/cli_cd.cpp"
#include "src/cli_chunknameformat.cpp"
=======================================
--- /trunk/SoarSuite/Core/CLI/src/cli_Cli.h Wed Jun 4 17:17:42 2014 UTC
+++ /trunk/SoarSuite/Core/CLI/src/cli_Cli.h Wed Jun 18 03:09:10 2014 UTC
@@ -38,6 +38,12 @@
virtual bool DoAllocate(const std::string& pool, int blocks) = 0;
+ /**
+ * @brief break command
+ * @param pProduction The production
+ */
+ virtual bool DoBreak(const char &mode, const std::string
&production) = 0;
+
enum eCaptureInputMode
{
CAPTURE_INPUT_OPEN,
=======================================
--- /trunk/SoarSuite/Core/CLI/src/cli_CommandLineInterface.cpp Wed Jun 4
17:17:42 2014 UTC
+++ /trunk/SoarSuite/Core/CLI/src/cli_CommandLineInterface.cpp Wed Jun 18
03:09:10 2014 UTC
@@ -40,6 +40,7 @@
m_Parser.AddCommand(new cli::AddWMECommand(*this));
m_Parser.AddCommand(new cli::AliasCommand(*this));
m_Parser.AddCommand(new cli::AllocateCommand(*this));
+ m_Parser.AddCommand(new cli::BreakCommand(*this));
m_Parser.AddCommand(new cli::CaptureInputCommand(*this));
m_Parser.AddCommand(new cli::CDCommand(*this));
m_Parser.AddCommand(new cli::ChunkNameFormatCommand(*this));
=======================================
--- /trunk/SoarSuite/Core/CLI/src/cli_CommandLineInterface.h Wed Jun 4
17:17:42 2014 UTC
+++ /trunk/SoarSuite/Core/CLI/src/cli_CommandLineInterface.h Wed Jun 18
03:09:10 2014 UTC
@@ -113,6 +113,7 @@
virtual bool DoAddWME(const std::string& id, std::string
attribute, const std::string& value, bool acceptable);
virtual bool DoAlias(std::vector< std::string >* argv = 0);
virtual bool DoAllocate(const std::string& pool, int blocks);
+ virtual bool DoBreak(const char &mode, const std::string
&production);
virtual bool DoCaptureInput(eCaptureInputMode mode, bool autoflush
= false, std::string* pathname = 0);
virtual bool DoCD(const std::string* pDirectory = 0);
virtual bool DoChunkNameFormat(const bool* pLongFormat = 0, const
int64_t* pCount = 0, const std::string* pPrefix = 0);
=======================================
--- /trunk/SoarSuite/Core/CLI/src/cli_Commands.h Thu Jun 5 17:30:16 2014
UTC
+++ /trunk/SoarSuite/Core/CLI/src/cli_Commands.h Wed Jun 18 03:09:10 2014
UTC
@@ -110,6 +110,78 @@
AllocateCommand& operator=(const AllocateCommand&);
};
+ class BreakCommand : public cli::ParserCommand
+ {
+ public:
+ BreakCommand(cli::Cli& cli) : cli(cli), ParserCommand() {}
+ virtual ~BreakCommand() {}
+ virtual const char* GetString() const { return "break"; }
+ virtual const char* GetSyntax() const
+ {
+ return "Syntax: break [-cps] production_name";
+ }
+
+ virtual bool Parse(std::vector< std::string >&argv)
+ {
+ cli::Options opt;
+ OptionsData optionsData[] =
+ {
+ {'c', "clear", OPTARG_NONE},
+ {'p', "print", OPTARG_NONE},
+ {'s', "set", OPTARG_NONE},
+ {0, 0, OPTARG_NONE} // null
+ };
+
+ char option = 0;
+
+ for (;;)
+ {
+ if ( !opt.ProcessOptions( argv, optionsData ) )
+ return cli.SetError( opt.GetError().c_str());
+
+ if (opt.GetOption() == -1) break;
+
+ if (option != 0)
+ return cli.SetError( "break takes only one option at a
time." );
+ option = static_cast<char>(opt.GetOption());
+ }
+
+ switch (option)
+ {
+ case 'c':
+ case 's':
+ if(argv.size() != 3)
+ return cli.SetError( "break --set/--clear takes
exactly one argument." );
+
+ // case: clear the interrupt flag on the production
+ return cli.DoBreak(option, argv[2]);
+
+ case 'p':
+ if(argv.size() != 2)
+ return cli.SetError( "break --print takes no
arguments." );
+
+ // case: set the interrupt flag on the production
+ return cli.DoBreak('p', "");
+
+ default:
+ if(argv.size() == 1)
+ return cli.DoBreak('p', "");
+ else if(argv.size() == 2)
+ return cli.DoBreak('s', argv[1]);
+ else
+ return cli.SetError( "break used incorrectly." );
+ }
+
+ // bad: no option, but more than one argument
+ return cli.SetError( "break takes exactly one argument." );
+ }
+
+ private:
+ cli::Cli& cli;
+
+ BreakCommand& operator=(const BreakCommand&);
+ };
+
class CaptureInputCommand : public cli::ParserCommand
{
public:
=======================================
--- /trunk/SoarSuite/Core/SoarKernel/src/print.cpp Wed Jun 4 17:17:42 2014
UTC
+++ /trunk/SoarSuite/Core/SoarKernel/src/print.cpp Wed Jun 18 03:09:10 2014
UTC
@@ -853,7 +853,7 @@
xml_att_val(thisAgent, kProductionDeclaredSupport,
kProductionDeclaredISupport);
}
- if (p->interrupt)
+ if (p->interrupt && !p->interrupt_break)
print_string(thisAgent, " :interrupt\n");
/*
=======================================
--- /trunk/SoarSuite/Core/SoarKernel/src/production.h Thu Apr 19 18:37:52
2012 UTC
+++ /trunk/SoarSuite/Core/SoarKernel/src/production.h Wed Jun 18 03:09:10
2014 UTC
@@ -111,9 +111,13 @@
struct instantiation_struct *instantiations; /* dll of inst's in MS */
int OPERAND_which_assert_list; /* RCHONG: 10.11 */
byte interrupt; /* SW: 7.31.03 */
- bool already_fired; /* RPM test workaround for bug #139 */
- bool rl_rule; /* if true, is a Soar-RL rule */
+ struct {
+ bool interrupt_break : 1;
+ bool already_fired : 1; /* RPM test workaround for bug #139 */
+ bool rl_rule : 1; /* if true, is a Soar-RL rule */
+ };
+
double rl_update_count; /* number of (potentially fractional) updates
to this rule */
unsigned int rl_ref_count; /* number of states referencing this rule
in prev_op_rl_rules list */
=======================================
--- /trunk/SoarSuite/Core/SoarKernel/src/rete.cpp Wed Jun 4 17:17:42 2014
UTC
+++ /trunk/SoarSuite/Core/SoarKernel/src/rete.cpp Wed Jun 18 03:09:10 2014
UTC
@@ -7479,7 +7479,8 @@
prod->instantiations = NIL;
prod->filename = NIL;
prod->p_node = NIL;
- prod->interrupt = FALSE;
+ prod->interrupt = FALSE;
+ prod->interrupt_break = false;
sym = reteload_symbol_from_index (thisAgent,f);
symbol_add_ref (sym);
=======================================
--- /trunk/SoarSuite/Tests/UnitTests/src/cliparsertest.h Wed Jun 4
17:17:42 2014 UTC
+++ /trunk/SoarSuite/Tests/UnitTests/src/cliparsertest.h Wed Jun 18
03:09:10 2014 UTC
@@ -13,6 +13,7 @@
virtual bool DoAddWME(const std::string& id, std::string attribute,
const std::string& value, bool acceptable) { return false; }
virtual bool DoAlias(std::vector< std::string >* argv = 0) { return
false; }
virtual bool DoAllocate(const std::string& pool, int blocks) { return
false; }
+ virtual bool DoBreak(const char &mode, const std::string &production)
{ return false; }
virtual bool DoCaptureInput(eCaptureInputMode mode, bool autoflush =
false, std::string* pathname = 0) { return false; }
virtual bool DoCD(const std::string* pDirectory = 0) { return false; }
virtual bool DoChunkNameFormat(const bool* pLongFormat = 0, const
int64_t* pCount = 0, const std::string* pPrefix = 0) { return false; }