Skip to content
Permalink
Browse files

Broken support of not emitting output nodes that become bad. Better t…

…ests.
  • Loading branch information
nfomon committed Aug 2, 2015
1 parent d60c98b commit 68793a454c2c31b09d9cfa3f2f57b1ade23fc049
@@ -20,6 +20,8 @@ auto_ptr<Compiler> exstatik::MakeCompiler(const string& name) {
auto_ptr<Compiler> c(new Compiler());
if ("Statik" == name) {
c->push_back(CreateLexer_Simple());
} else if ("KeywordTest" == name) {
c->push_back(CreateLexer_KeywordTest());
} else if ("Splash" == name) {
c->push_back(CreateLexer_Splash());
} else if ("Moderate" == name) {
@@ -38,6 +38,11 @@ auto_ptr<Rule> exstatik::CreateLexer_Splash() {
return lexer;
}

auto_ptr<Rule> exstatik::CreateLexer_KeywordTest() {
auto_ptr<Rule> lexer(KEYWORD("a"));
return lexer;
}

auto_ptr<Rule> exstatik::CreateLexer_Moderate() {
auto_ptr<Rule> lexer(STAR("lexer"));
Rule* or_ = lexer->AddChild(OR("Or"));
@@ -12,6 +12,7 @@ namespace exstatik {

std::auto_ptr<statik::Rule> CreateLexer_Simple();
std::auto_ptr<statik::Rule> CreateLexer_Splash();
std::auto_ptr<statik::Rule> CreateLexer_KeywordTest();
std::auto_ptr<statik::Rule> CreateLexer_Moderate();
std::auto_ptr<statik::Rule> CreateLexer_Complex();
std::auto_ptr<statik::Rule> CreateLexer_Nifty();
@@ -6,11 +6,28 @@
#include "List.h"
#include "SLog.h"

#include <ostream>
#include <string>
using std::ostream;
using std::string;

using namespace statik;

/* BatchItem public */

std::string Batch::BatchItem::Print() const {
if (!node) {
throw SError("Cannot print defective BatchItem");
}
string s(UnMapBatchOp(op) + " " + string(*node));
if (pos) {
s += " @ " + string(*pos);
}
return s;
}

/* Batch public */

std::string Batch::UnMapBatchOp(const BATCH_OP& op) {
switch (op) {
case OP_INSERT: return "OP_INSERT";
@@ -46,7 +63,19 @@ void Batch::Clear() {
string Batch::Print() const {
string s;
for (batch_iter i = m_batch.begin(); i != m_batch.end(); ++i) {
s += "\n" + UnMapBatchOp(i->op) + " - " + string(*i->node);
s += "\n" + i->Print();
}
return s;
}

/* non-member */

ostream& statik::operator<< (ostream& out, const Batch::BatchItem& item) {
out << item.Print();
return out;
}

ostream& statik::operator<< (ostream& out, const Batch& batch) {
out << batch.Print();
return out;
}
@@ -18,6 +18,7 @@

#include "List.h"

#include <ostream>
#include <set>
#include <string>
#include <utility>
@@ -41,6 +42,8 @@ class Batch {
const List* node;
BATCH_OP op;
const List* pos;

std::string Print() const;
};

typedef std::vector<BatchItem> batch_vec;
@@ -63,6 +66,9 @@ class Batch {
batch_vec m_batch;
};

std::ostream& operator<< (std::ostream& out, const Batch::BatchItem& item);
std::ostream& operator<< (std::ostream& out, const Batch& batch);

}

#endif // _statik_Batch_h_
@@ -356,6 +356,10 @@ void IncParser::ProcessActions() {

void IncParser::ComputeOutput_Update(const STree& node, Batch& out_batch, const List*& behind_node) {
g_log.debug() << "IncParser " << m_name << ": Computing output UPDATE for node " << node;
if (node.GetState().IsPending() || node.GetState().IsBad()) {
g_log.debug() << " - state is " << node.GetState() << ", so not computing output";
return;
}

node.GetOutputFunc() ();
OutputList& output = node.GetOutputFunc().GetOutput();
@@ -449,12 +453,16 @@ void IncParser::ComputeOutput_Update(const STree& node, Batch& out_batch, const
m_outputPerNode[&node] = output; // copy
}

g_log.debug() << "Done computing UPDATE output for node " << node << ". Batch so far: " << out_batch.Print();
g_log.debug() << "Done computing UPDATE output for node " << node << ". Batch so far: " << out_batch;
node.GetOutputFunc().Sync();
}

void IncParser::ComputeOutput_Insert(const STree& node, Batch& out_batch, const List*& behind_node) {
g_log.debug() << "IncParser " << m_name << ": Computing output INSERT for node " << node;
if (node.GetState().IsPending() || node.GetState().IsBad()) {
g_log.debug() << " - state is " << node.GetState() << ", so not computing output";
return;
}

node.GetOutputFunc() ();
const OutputList& output = node.GetOutputFunc().GetOutput();
@@ -473,12 +481,16 @@ void IncParser::ComputeOutput_Insert(const STree& node, Batch& out_batch, const
} else {
m_outputPerNode[&node] = output; // copy
}
g_log.debug() << "Done computing INSERT output for node " << node << ". Batch so far: " << out_batch.Print();
g_log.debug() << "Done computing INSERT output for node " << node << ". Batch so far: " << out_batch;
node.GetOutputFunc().Sync();
}

void IncParser::ComputeOutput_Delete(const STree& node, Batch& out_batch) {
g_log.debug() << "IncParser " << m_name << ": Computing output DELETE for node " << node;
if (node.GetState().IsPending() || node.GetState().IsBad()) {
g_log.debug() << " - state is " << node.GetState() << ", so not computing output";
return;
}

output_mod_iter prev_output_i = m_outputPerNode.find(&node);
if (m_outputPerNode.end() == prev_output_i) {
@@ -493,7 +505,7 @@ void IncParser::ComputeOutput_Delete(const STree& node, Batch& out_batch) {
RemoveOutput(*prev_item, out_batch);
}
m_outputPerNode.erase(&node);
g_log.debug() << "Done computing DELETE output for node " << node << ". Batch so far: " << out_batch.Print();
g_log.debug() << "Done computing DELETE output for node " << node << ". Batch so far: " << out_batch;
}

void IncParser::Cleanup() {
@@ -550,6 +562,7 @@ const List* IncParser::GetOEnd(const OutputItem& item) const {

void IncParser::SanityCheck() {
g_log.debug() << "Sanity check " << m_sancount;
g_log.debug();
g_san.info();
g_san.info() << "Sanity check " << m_sancount;
SanityCheck(&m_root);
@@ -98,7 +98,7 @@ void OutputFunc_Pass::operator() () {
}
const STree& child = *m_node->children.front();
m_output.clear();
m_output.push_back(OutputItem(child));
m_output.push_back(OutputItem(child, m_node->GetState().GetStation()));
}

/* OutputFunc_Basic */
@@ -111,7 +111,7 @@ OutputFunc_Basic::OutputFunc_Basic(const string& name, const string& value)
void OutputFunc_Basic::operator() () {
g_log.debug() << "OutputFunc_Basic " << m_onode;
if (m_output.empty()) {
m_output.push_back(OutputItem(m_onode));
m_output.push_back(OutputItem(m_onode, m_node->GetState().GetStation()));
}
}

@@ -129,7 +129,7 @@ OutputFunc_IValues::OutputFunc_IValues(const string& name)
void OutputFunc_IValues::operator() () {
g_log.debug() << "OutputFunc_IValues " << m_onode;
if (m_output.empty()) {
m_output.push_back(m_onode);
m_output.push_back(OutputItem(m_onode, m_node->GetState().GetStation()));
}
/*
string value;
@@ -180,29 +180,12 @@ void OutputFunc_Winner::operator() () {
if (winner) {
g_log.debug() << "**** OutputFunc_Winner: " << *m_node << " Declaring winner " << *winner;
m_winner = winner;
m_output.push_back(OutputItem(*m_winner));
m_output.push_back(OutputItem(*m_winner, m_node->GetState().GetStation()));
} else {
g_log.debug() << "**** OutputFunc_Winner: No winner.";
}
}

/*
void OutputFunc_Winner::ConnectONodes() {
g_log.debug() << "OutputFunc_Winner::ConnectONodes() " << *m_node;
if (m_winner) {
g_log.debug() << "**** OutputFunc_Winner: " << *m_node << " Setting ONodes from winner " << *m_winner;
m_ostart = m_winner->GetOutputFunc().OStart();
m_oend = m_winner->GetOutputFunc().OEnd();
if (!m_ostart) {
g_log.error() << "Failed to set OStart from winner";
}
} else {
m_ostart = NULL;
m_oend = NULL;
}
}
*/

auto_ptr<OutputFunc> OutputFunc_Winner::Clone() {
return auto_ptr<OutputFunc>(new OutputFunc_Winner());
}
@@ -215,7 +198,7 @@ void OutputFunc_Sequence::operator() () {

if (m_node->GetState().IsBad()) {
for (STree::child_iter child = m_node->children.begin(); child != m_node->children.end(); ++child) {
m_output.push_back(OutputItem(**child));
m_output.push_back(OutputItem(**child, m_node->GetState().GetStation()));
}
return;
}
@@ -231,53 +214,14 @@ void OutputFunc_Sequence::operator() () {
break;
} else if (istate.IsDone() || istate.IsOK()) {
g_log.debug() << "**** OutputFunc_Sequence: " << *m_node << " aborting after " << (istate.IsOK() ? "ok" : "done") << " child " << **child;
m_output.push_back(**child);
m_output.push_back(OutputItem(**child, m_node->GetState().GetStation()));
break;
} else if (!istate.IsComplete()) {
throw SError("OutputFunc Seq found child in unknown state");
}
m_output.push_back(**child);
}
}

/*
void OutputFunc_Sequence::ConnectONodes() {
g_log.debug() << "OutputFunc_Sequence::ConnectONodes() " << *m_node;
g_log.debug() << "OutputFunc_Sequence at " << *m_node << ": Connecting ONodes";
for (STree::child_iter child = m_node->children.begin(); child != m_node->children.end(); ++child) {
g_log.debug() << " - processing child: " << **child;
// If m_node is Complete and this is the first child past the last approved
// child, then discard the output of this child onwards.
const State& istate = (*child)->GetState();
if (istate.IsBad()) {
g_log.debug() << " - child is bad -- abort";
break;
}
OutputFunc& cof = (*child)->GetOutputFunc();
if ((cof.OStart() && !cof.OEnd()) || (!cof.OStart() && cof.OEnd())) {
throw SError("OutputFunc_Sequence() found " + string(**child) + " with only an ostart or oend, but not both");
}
if (!cof.OStart()) {
g_log.debug() << " - child has no OStart; skipping";
continue;
}
if (!m_ostart) {
m_ostart = cof.OStart();
m_ostart->left = NULL;
} else {
cof.OStart()->left = m_oend;
m_oend->right = cof.OStart();
}
m_oend = cof.OEnd();
m_oend->right = NULL;
if (!istate.IsComplete()) {
g_log.debug() << " - child is not complete; aborting";
break;
}
m_output.push_back(OutputItem(**child, m_node->GetState().GetStation()));
}
}
*/

auto_ptr<OutputFunc> OutputFunc_Sequence::Clone() {
return auto_ptr<OutputFunc>(new OutputFunc_Sequence());
@@ -304,25 +248,6 @@ void OutputFunc_Cap::operator() () {
m_output = m_outputFunc->GetOutput();
}

/*
void OutputFunc_Cap::ConnectONodes() {
g_log.debug() << "OutputFunc_Cap at " << *m_node << ": Connecting ONodes";
m_outputFunc->ConnectONodes();
if (m_outputFunc->OStart()) {
m_capStart.right = m_outputFunc->OStart();
m_outputFunc->OStart()->left = &m_capStart;
} else {
m_capStart.right = &m_capEnd;
}
if (m_outputFunc->OEnd()) {
m_outputFunc->OEnd()->right = &m_capEnd;
m_capEnd.left = m_outputFunc->OEnd();
} else {
m_capEnd.left = &m_capStart;
}
}
*/

auto_ptr<OutputFunc> OutputFunc_Cap::Clone() {
return auto_ptr<OutputFunc>(new OutputFunc_Cap(m_outputFunc->Clone(), m_cap));
}
@@ -5,6 +5,7 @@
#define _statik_OutputFunc_h_

#include "List.h"
#include "State.h"

#include <list>
#include <map>
@@ -26,12 +27,14 @@ std::auto_ptr<OutputFunc> MakeOutputFunc_Sequence();
std::auto_ptr<OutputFunc> MakeOutputFunc_Cap(std::auto_ptr<OutputFunc> outputFunc, const std::string& cap);

struct OutputItem {
OutputItem(const List& onode)
OutputItem(const List& onode, State::Station station)
: onode(&onode),
child(NULL) {}
OutputItem(const STree& child)
child(NULL),
station(station) {}
OutputItem(const STree& child, State::Station station)
: onode(NULL),
child(&child) {}
child(&child),
station(station) {}
bool operator==(const OutputItem& rhs) const {
return onode == rhs.onode && child == rhs.child;
}
@@ -49,34 +52,10 @@ struct OutputItem {
}
const List* onode;
const STree* child;
const List* ostart; // set by IncParser
const List* oend; // set by IncParser
State::Station station;
std::string prev_value; // set/used by IncParser, not OutputFuncs
};

/*
class OutputList {
public:
typedef output_list::const_iterator const_iterator;
typedef output_list::iterator iterator;
const_iterator begin() const { return m_output.begin(); }
const_iterator end() const { return m_output.end(); }
size_t size() const { return m_output.size(); }
List* OStart() const {
if (m_output.empty()) {
return NULL;
}
OutputItem& start = m_output.front();
if (start.onode) {
return start.onode;
}
return start.child->GetOutputList().OStart();
}
private:
typedef std::list<OutputItem> output_list;
output_list m_output;
};
*/
typedef std::list<OutputItem> OutputList;

class OutputFunc {
@@ -96,7 +75,6 @@ class OutputFunc {
virtual std::auto_ptr<OutputFunc> Clone() = 0;

protected:

const STree* m_node;
OutputList m_output;

0 comments on commit 68793a4

Please sign in to comment.
You can’t perform that action at this time.