Commit dc8f2643 authored by Florent Jacquemard's avatar Florent Jacquemard
Browse files

replace all pointers in namespace parsing by smart pointers

containers (Records) contain smart pointers to runs
tables and runs contain smart pointers to records
parent f48d1108
......@@ -2235,8 +2235,6 @@
43CDB7932577899500956DDF /* KeySIO.cpp */,
4352BE2E25E40EF600F045BC /* KeySV.hpp */,
4352BE2D25E40EF600F045BC /* KeySV.cpp */,
433278E2260DC6CA00D6AD17 /* RunFactory.hpp */,
433278E1260DC6CA00D6AD17 /* RunFactory.tpp */,
43979C6B22A11DBC008BA390 /* RunFilterMode.hpp */,
43847D7D23F5980C00059835 /* RunFilterMode.cpp */,
439EA0BB224CCF91006E742E /* RunFilter.hpp */,
......@@ -2251,6 +2249,8 @@
430046F12604CF97000E9898 /* RunInner.tpp */,
434F406422FB198300C3940E /* RunRanked.hpp */,
434F406322FB198300C3940E /* RunRanked.tpp */,
433278E2260DC6CA00D6AD17 /* RunFactory.hpp */,
433278E1260DC6CA00D6AD17 /* RunFactory.tpp */,
431864B123099B5900940ECB /* RunCompare.hpp */,
4313D8DD2613231800702519 /* RunCompare.cpp */,
43E7762A2684829200F90AAF /* RunOrder.hpp */,
......
......@@ -81,7 +81,7 @@ Run* Key<K>::failRun(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
assert(t1.weight().is_one());
label_t a = SymbLabel::make_fail(this->size());
return new RunTerm(t1, a, t1.weight());
}
......
......@@ -104,8 +104,10 @@ bool KeyS::complete() const
}
void KeyS::runs(std::stack<RunInner<KeyS>*>& si,
std::stack<std::pair<const KeyS*, RunTerm*>>& st,
// std::stack<RunInner<KeyS>*>& si,
// std::stack<std::pair<const KeyS*, RunTerm*>>& st,
void KeyS::runs(StackInner<KeyS>& si,
StackTerm<KeyS>& st,
ParsingEnv& env) const
{
assert(si.empty());
......@@ -114,7 +116,7 @@ void KeyS::runs(std::stack<RunInner<KeyS>*>& si,
}
RunTerm* KeyS::failRun(const ParsingEnv& env) const
std::shared_ptr<RunTerm> KeyS::failRun(const ParsingEnv& env) const
{
return RunFactory<KeyS>::failRun(*this, env);
}
......@@ -122,18 +124,22 @@ RunTerm* KeyS::failRun(const ParsingEnv& env) const
// protected
void KeyS::RunsTerminal(const Transition& t,
std::stack<std::pair<const KeyS*, RunTerm*>>& st,
StackTerm<KeyS>& st,
//std::stack<std::pair<const KeyS*, RunTerm*>>& st,
const ParsingEnv& env) const
{
RunTerm* r = new RunTerm(t, 0); // length = 0
// RunTerm* r = new RunTerm(t, 0);
std::shared_ptr<RunTerm> r = std::make_shared<RunTerm>(t, 0); // length = 0
TRACE("NEW terminal run {} -> {} for {}", *r, *this, t);
st.push(std::make_pair((KeyS*) NULL, r)); // this key is complete
st.push(std::make_pair(*this, r)); // this key is complete
}
// protected
void KeyS::RunsInner(const Transition& t,
std::stack<RunInner<KeyS>*>& si,
StackInner<KeyS>& si,
// std::stack<RunInner<KeyS>*>& si,
const ParsingEnv& env) const
{
......
......@@ -13,6 +13,8 @@
#define KeyS_hpp
#include <stdio.h>
#include <iostream>
#include <memory> // shared_ptr
#include <assert.h>
#include <stack> // std::stack
#include <queue> // std::queue
......@@ -78,7 +80,6 @@ namespace parsing{
/// Some synthesized attribute contain weight values.
/// The weight of a key is computed from the attributes and an input symbol.
/// Key made of one state of a base WTA (trivial augmented state).
/// no attributes.
/// extended with rank for k-best algo (not used for 1-best).
......@@ -152,11 +153,12 @@ public:
/// @warning the runs constructed are added to the given stacks.
/// - si will contain inner runs, partial or complete.
/// - st will contains pairs made of
/// - a complete instance k' of k if k is partial, and NULL otherwise.
/// - a complete instance k' of k if k is partial,
/// or k itself otherwise.
/// - a complete terminal run targeting r'
/// All the runs in stacks must be deallocate elsewhere.
virtual void runs(std::stack<RunInner<KeyS>*>& si,
std::stack<std::pair<const KeyS*, RunTerm*>>& st,
virtual void runs(StackInner<KeyS>& si,
StackTerm<KeyS>& st,
ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
......@@ -167,7 +169,7 @@ public:
/// - fail symbol
/// - weight zero (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
RunTerm* failRun(const ParsingEnv& env) const;
std::shared_ptr<RunTerm> failRun(const ParsingEnv& env) const;
friend std::ostream& operator<<(std::ostream& o, const KeyS& k);
......@@ -200,9 +202,9 @@ protected:
/// @param t transition to build terminal runs. must be terminal and complete.
/// @param st a stack to be filled with pairs containing terminal runs.
/// @param env parsing environment, containing a wta and pool.
virtual void RunsTerminal(const Transition& t,
std::stack<std::pair<const KeyS*, RunTerm*>>& st,
const ParsingEnv& env) const;
void RunsTerminal(const Transition& t,
StackTerm<KeyS>& st,
const ParsingEnv& env) const;
/// add to the given stack some inner runs built from the given transition.
/// @param t transition to build inner runs. must be inner and complete.
......@@ -211,9 +213,9 @@ protected:
/// @warning the runs constructed are added to the given stack.
/// They can be partial or complete.
/// They must be deallocate elsewhere.
virtual void RunsInner(const Transition& t,
std::stack<RunInner<KeyS>*>& si,
const ParsingEnv& env) const;
void RunsInner(const Transition& t,
StackInner<KeyS>& si,
const ParsingEnv& env) const;
};
......
......@@ -65,9 +65,9 @@ _barlen(k._barlen) // k is the parent (fs, ns) or matcher (instanciate)
assert(r.size() > 0);
assert(r.size() == t.size());
assert(_state == k._state); // check downcast of KeyS
assert(r.key(r.size()-1)); // last sibling
const KeySI& last = r.key(r.size()-1); // last sibling
// instanciate k with last key in r
init_instanciate(k, *(r.key(r.size()-1)), t, env);
init_instanciate(k, last, t, env);
}
// next sibling
else
......@@ -77,8 +77,8 @@ _barlen(k._barlen) // k is the parent (fs, ns) or matcher (instanciate)
assert(0 < i); // there is at least one previous sibling
assert(i < t.size()); // r partial
assert(_state == t.state(i)); // check downcast of KeyS
assert(r.key(i-1)); // last sibling
init_nextsibling(k, *(r.key(i-1)), t, i, env);
const KeySI& last = r.key(i-1); // last sibling
init_nextsibling(k, last, t, i, env);
}
}
......@@ -167,9 +167,9 @@ void KeySI::init_nextsibling(const KeySI& parent,
void KeySI::init_instanciate(const KeySI& head,
const KeySI& last,
const Transition& t,
const ParsingEnv& env)
const KeySI& last,
const Transition& t,
const ParsingEnv& env)
{
assert(last.complete());
_interval = head._interval;
......@@ -264,8 +264,10 @@ size_t KeySI::size() const
}
void KeySI::runs(std::stack<RunInner<KeySI>*>& si,
std::stack<std::pair<const KeySI*, RunTerm*>>& st,
void KeySI::runs(StackInner<KeySI>& si,
StackTerm<KeySI>& st,
//std::stack<RunInner<KeySI>*>& si,
//std::stack<std::pair<const KeySI*, RunTerm*>>& st,
ParsingEnv& env) const
{
RunFactory<KeySI>::runs(*this, si, st, env);
......@@ -290,7 +292,8 @@ void KeySI::runs(std::stack<RunInner<KeySI>*>& si,
// not the default of RunFactory (consider interval)
void KeySI::RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySI*, RunTerm*>>& st,
StackTerm<KeySI>& st,
// std::stack<std::pair<const KeySI*, RunTerm*>>& st,
const ParsingEnv& env) const
{
const label_t& a = t.label();
......@@ -367,7 +370,8 @@ void KeySI::RunsTerminal(const Transition& t,
// not the default of RunFactory (filter out not inhabited intervals)
void KeySI::RunsInner(const Transition& t,
std::stack<RunInner<KeySI>*>& si,
StackInner<KeySI>& si,
// std::stack<RunInner<KeySI>*>& si,
const ParsingEnv& env) const
{
const label_t& a = t.label();
......@@ -407,11 +411,11 @@ void KeySI::RunsInner(const Transition& t,
// not the default of RunFactory
RunTerm* KeySI::failRun(const ParsingEnv& env) const
std::shared_ptr<RunTerm> KeySI::failRun(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
assert(t0.weight().is_zero());
assert(_interval);
if (! _interval->aligned())
{
......@@ -420,7 +424,9 @@ RunTerm* KeySI::failRun(const ParsingEnv& env) const
}
label_t a = SymbLabel::make_fail(this->size());
size_t length = _interval->size();
return new RunTerm(t0, a, t0.weight(), length);
std::shared_ptr<RunTerm> r =
std::make_shared<RunTerm>(t0, a, t0.weight(), length);
return r;
}
......
......@@ -12,6 +12,8 @@
#define KeySI_hpp
#include <stdio.h>
#include <iostream>
#include <memory> // shared_ptr
#include <assert.h>
#include "util.hpp"
......@@ -99,12 +101,14 @@ public:
/// @warning the runs constructed are added to the given stacks.
/// - si will contain inner runs, partial or complete.
/// - st will contains pairs made of
/// - a complete instance k' of k if k is partial, and NULL otherwise.
/// - a complete instance k' of k if k is partial,
/// or k itself otherwise.
/// - a complete terminal run targeting r'
/// All the runs in stacks must be deallocate elsewhere.
void runs(std::stack<RunInner<KeySI>*>& si,
std::stack<std::pair<const KeySI*, RunTerm*>>& st,
void runs(StackInner<KeySI>& si,
StackTerm<KeySI>& st,
ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
/// @param env parsing environment.
......@@ -114,7 +118,7 @@ public:
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().
RunTerm* failRun(const ParsingEnv& env) const;
std::shared_ptr<RunTerm> failRun(const ParsingEnv& env) const;
/// @brief printer
friend std::ostream& operator<<(std::ostream& o, const KeySI& p);
......@@ -171,9 +175,10 @@ protected:
/// add to the given stack some terminal runs built from the given transition.
/// @param t transition to build terminal runs. must be terminal and complete.
/// @param st a stack to be filled with pairs containing terminal runs.
virtual void RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySI*, RunTerm*>>& st,
const ParsingEnv& env) const;
void RunsTerminal(const Transition& t,
StackTerm<KeySI>& si,
// std::stack<std::pair<const KeySI*, RunTerm*>>& st,
const ParsingEnv& env) const;
/// add to the given stack some inner runs built from the given transition.
/// @param t transition to build inner runs. must be inner and complete.
......@@ -181,10 +186,11 @@ protected:
/// @warning the runs constructed are added to the given stack.
/// They can be partial or complete.
/// They must be deallocate elsewhere.
virtual void RunsInner(const Transition& t,
std::stack<RunInner<KeySI>*>& si,
const ParsingEnv& env) const;
void RunsInner(const Transition& t,
StackInner<KeySI>& si,
// std::stack<RunInner<KeySI>*>& si,
const ParsingEnv& env) const;
/// @brief weight for the case of a and tr terminal.
virtual Weight terminalWeight(label_t a,
const Transition& tr,
......
......@@ -76,9 +76,8 @@ _post_laston(false)
{
assert(r.size() == t.size());
assert(_state == k._state); // check downcast of KeyS
const KeySIO* last = r.key(r.size()-1); // last sibling
assert(last);
init_instanciate(k, *last, t, env);
const KeySIO& last = r.key(r.size()-1); // last sibling
init_instanciate(k, last, t, env);
}
// next sibling
else
......@@ -88,9 +87,8 @@ _post_laston(false)
assert(0 < i); // there is at least one previous sibling
assert(i < t.size()); // r partial
assert(_state == t.state(i)); // check downcast of KeyS
const KeySIO* last = r.key(i-1); // previous sibling
assert(last);
init_nextsibling(k, *last, t, i, env);
const KeySIO& last = r.key(i-1); // previous sibling
init_nextsibling(k, last, t, i, env);
}
}
......@@ -287,8 +285,10 @@ size_t KeySIO::size() const
}
void KeySIO::runs(std::stack<RunInner<KeySIO>*>& si,
std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
void KeySIO::runs(StackInner<KeySIO>& si,
// std::stack<RunInner<KeySIO>*>& si,
StackTerm<KeySIO>& st,
// std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
ParsingEnv& env) const
{
RunFactory<KeySIO>::runs(*this, si, st, env);
......@@ -296,7 +296,8 @@ void KeySIO::runs(std::stack<RunInner<KeySIO>*>& si,
void KeySIO::RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
StackTerm<KeySIO>& st,
//std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
const ParsingEnv& env) const
{
assert(P_KNOWN(_pre));
......@@ -451,7 +452,8 @@ void KeySIO::RunsTerminal(const Transition& t,
void KeySIO::addTerminalRun(//const KeySIO& k,
size_t n, // nb points
const Transition& t,
std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
StackTerm<KeySIO>& st,
// std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
const ParsingEnv& env) const
{
assert(this->complete());
......@@ -549,7 +551,8 @@ Weight KeySIO::terminalWeight(label_t a,
void KeySIO::RunsInner(const Transition& t,
std::stack<RunInner<KeySIO>*>& si,
StackInner<KeySIO>& si,
// std::stack<RunInner<KeySIO>*>& si,
const ParsingEnv& env) const
{
const label_t& a = t.label();
......
......@@ -12,6 +12,8 @@
#define KeySIO_hpp
#include <stdio.h>
#include <iostream>
#include <memory> // shared_ptr
#include <assert.h>
#include <utility> // std::pair, std::make_pair
......@@ -143,11 +145,12 @@ public:
/// @warning the runs constructed are added to the given stacks.
/// - si will contain inner runs, partial or complete.
/// - st will contains pairs made of
/// - a complete instance k' of k if k is partial, and NULL otherwise.
/// - a complete instance k' of k if k is partial,
/// or k itself otherwise.
/// - a complete terminal run targeting r'
/// All the runs in stacks must be deallocate elsewhere.
void runs(std::stack<RunInner<KeySIO>*>& si,
std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
void runs(StackInner<KeySIO>& si,
StackTerm<KeySIO>& st,
ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
......@@ -228,7 +231,7 @@ protected:
/// @param t transition to build terminal runs. must be terminal and complete.
/// @param st a stack to be filled with pairs containing terminal runs.
virtual void RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
StackTerm<KeySIO>& st,
const ParsingEnv& env) const;
/// add to the given stack some inner runs built from the given transition.
......@@ -238,7 +241,7 @@ protected:
/// They can be partial or complete.
/// They must be deallocate elsewhere.
virtual void RunsInner(const Transition& t,
std::stack<RunInner<KeySIO>*>& si,
StackInner<KeySIO>& si,
const ParsingEnv& env) const;
/// @brief weight for the case of a and tr terminal.
......@@ -277,7 +280,7 @@ private:
void addTerminalRun(//const KeySIO& k,
size_t n, // nb points
const Transition& t,
std::stack<std::pair<const KeySIO*, RunTerm*>>& st,
StackTerm<KeySIO>& st,
const ParsingEnv& env) const;
};
......
......@@ -78,9 +78,8 @@ _post(k._post)
assert(r.size() == t.size());
assert(_state == k._state); // check downcast of KeyS
assert(r.size() > 0);
const KeySIP* last = r.key(r.size()-1);
assert(last);
init_instanciate(k, *last, t, env);
const KeySIP& last = r.key(r.size()-1);
init_instanciate(k, last, t, env);
}
// next sibling
else
......@@ -90,9 +89,8 @@ _post(k._post)
assert(0 < i); // there is at least one previous sibling
assert(i < t.size()); // r partial
assert(_state == t.state(i)); // check downcast of KeyS
const KeySIP* last = r.key(i-1);
assert(last);
init_nextsibling(k, *last, t, i, env);
const KeySIP& last = r.key(i-1);
init_nextsibling(k, last, t, i, env);
}
}
......@@ -238,8 +236,10 @@ size_t KeySIP::size() const
}
void KeySIP::runs(std::stack<RunInner<KeySIP>*>& si,
std::stack<std::pair<const KeySIP*, RunTerm*>>& st,
void KeySIP::runs(StackInner<KeySIP>& si,
// std::stack<RunInner<KeySIP>*>& si,
StackTerm<KeySIP>& st,
// std::stack<std::pair<const KeySIP*, RunTerm*>>& st,
ParsingEnv& env) const
{
RunFactory<KeySIP>::runs(*this, si, st, env);
......@@ -247,7 +247,8 @@ void KeySIP::runs(std::stack<RunInner<KeySIP>*>& si,
void KeySIP::RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySIP*, RunTerm*>>& st,
StackTerm<KeySIP>& st,
// std::stack<std::pair<const KeySIP*, RunTerm*>>& st,
const ParsingEnv& env) const
{
assert(P_KNOWN(_pre));
......@@ -390,7 +391,8 @@ Weight KeySIP::terminalWeight(label_t a,
void KeySIP::RunsInner(const Transition& t,
std::stack<RunInner<KeySIP>*>& si,
StackInner<KeySIP>& si,
// std::stack<RunInner<KeySIP>*>& si,
const ParsingEnv& env) const
{
const label_t& a = t.label();
......
......@@ -13,6 +13,8 @@
#define KeySIP_hpp
#include <stdio.h>
#include <iostream>
#include <memory> // shared_ptr
#include <assert.h>
#include "util.hpp"
......@@ -109,11 +111,12 @@ public:
/// @warning the runs constructed are added to the given stacks.
/// - si will contain inner runs, partial or complete.
/// - st will contains pairs made of
/// - a complete instance k' of k if k is partial, and NULL otherwise.
/// - a complete instance k' of k if k is partial,
/// or k itself otherwise.
/// - a complete terminal run targeting r'
/// All the runs in stacks must be deallocate elsewhere.
void runs(std::stack<RunInner<KeySIP>*>& si,
std::stack<std::pair<const KeySIP*, RunTerm*>>& st,
void runs(StackInner<KeySIP>& si,
StackTerm<KeySIP>& st,
ParsingEnv& env) const;
/// @brief printer
......@@ -165,7 +168,7 @@ protected:
/// @param t transition to build terminal runs. must be terminal and complete.
/// @param st a stack to be filled with pairs containing terminal runs.
virtual void RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySIP*, RunTerm*>>& st,
StackTerm<KeySIP>& st,
const ParsingEnv& env) const;
/// add to the given stack some inner runs built from the given transition.
......@@ -175,7 +178,7 @@ protected:
/// They can be partial or complete.
/// They must be deallocate elsewhere.
virtual void RunsInner(const Transition& t,
std::stack<RunInner<KeySIP>*>& si,
StackInner<KeySIP>& si,
const ParsingEnv& env) const;
/// @brief weight for the case of a and tr terminal.
......
......@@ -151,7 +151,7 @@ Run<KeySIR>* KeySIR::failRun(const ParsingEnv& env) const
{
assert(env.wta);
const Transition& t1 = env.dummyTransition_one();
assert(t1.weight().one());
assert(t1.weight().is_one());
if (! _interval->aligned())
{
assert(env.segment);
......
......@@ -13,6 +13,8 @@
#define KeySIR_hpp
#include <stdio.h>
#include <iostream>
#include <memory> // shared_ptr
#include <assert.h>
#include <utility> // std::pair, std::make_pair
......
......@@ -245,9 +245,11 @@ bool KeySV::complete() const
}
void KeySV::runs(std::stack<RunInner<KeySV>*>& si,
std::stack<std::pair<const KeySV*, RunTerm*>>& st,
ParsingEnv& env) const
void KeySV::runs(StackInner<KeySV>& si,
//std::stack<RunInner<KeySV>*>& si,
StackTerm<KeySV>& st,
//std::stack<std::pair<const KeySV*, RunTerm*>>& st,
ParsingEnv& env) const
{
RunFactory<KeySV>::runs(*this, si, st, env);
}
......@@ -255,7 +257,8 @@ void KeySV::runs(std::stack<RunInner<KeySV>*>& si,
// not the default of RunFactory (consider interval)
void KeySV::RunsTerminal(const Transition& t,
std::stack<std::pair<const KeySV*, RunTerm*>>& st,
StackTerm<KeySV>& st,
//std::stack<std::pair<const KeySV*, RunTerm*>>& st,
const ParsingEnv& env) const
{
const label_t& a = t.label();
......@@ -338,7 +341,8 @@ void KeySV::RunsTerminal(const Transition& t,
// not the default of RunFactory (filter out not inhabited intervals)
void KeySV::RunsInner(const Transition& t,
std::stack<RunInner<KeySV>*>& si,
StackInner<KeySV>& si,
//std::stack<RunInner<KeySV>*>& si,
const ParsingEnv& env) const
{
const label_t& a = t.label();
......@@ -395,15 +399,17 @@ size_t KeySV::points() const
// not the default of RunFactory (use specific size of this class)
RunTerm* KeySV::failRun(const ParsingEnv& env) const
std:shared_ptr<RunTerm> KeySV::failRun(const ParsingEnv& env) const
{
//return RunFactory<KeySV>::failRun(*this, env);
assert(env.wta);
const Transition& t0 = env.dummyTransition_zero();
assert(t0.weight().zero());
assert(t0.weight().is_zero());
size_t length = this->size(); // number of input symbols parsed
label_t a = SymbLabel::make_fail(length);
return new RunTerm(t0, a, t0.weight(), length);
std:shared_ptr<RunTerm> r =
std:make_shared<RunTerm>(t0, a, t0.weight(), length);
return r;
}
......
......@@ -13,6 +13,8 @@
#define KeySV_hpp
#include <stdio.h>
#include <iostream>
#include <memory> // shared_ptr
#include <assert.h>
#include <utility> // std::pair, std::make_pair
#include <memory>
......@@ -99,8 +101,8 @@ public:
/// - a complete instance k' of k if k is partial, and NULL otherwise.
/// - a complete terminal run targeting r'
/// All the runs in stacks must be deallocate elsewhere.
void runs(std::stack<RunInner<KeySV>*>& si,
std::stack<std::pair<const KeySV*, RunTerm*>>& st,
void runs(StackInner<KeySV>& si,
StackTerm<KeySV>& st,
ParsingEnv& env) const;
/// allocate and return a special Run representing a parse failure for this key.
......@@ -111,7 +113,7 @@ public:
/// - fail symbol
/// - weight one (in the domain of the base wta).
/// This returned run will answer succesfully to Run.fail().