Commit b8a3c979 authored by Ronan's avatar Ronan

remove useless constructors

parent 65c22085
......@@ -74,7 +74,7 @@ protected:
Recognizer();
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos)=0;
std::string mName;
unsigned int mId;
unsigned int mId = 0;
};
class CharRecognizer : public Recognizer{
......@@ -89,7 +89,6 @@ private:
class Selector : public Recognizer{
public:
Selector();
std::shared_ptr<Selector> addRecognizer(const std::shared_ptr<Recognizer> &element);
protected:
virtual void _optimize(int recursionLevel);
......@@ -97,20 +96,17 @@ protected:
size_t _feedExclusive(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
virtual bool _getTransitionMap(TransitionMap *mask);
std::list<std::shared_ptr<Recognizer>> mElements;
bool mIsExclusive;
bool mIsExclusive = false;
};
/**This is an optimization of the first one for the case where there can be only a single match*/
class ExclusiveSelector : public Selector{
public:
ExclusiveSelector();
private:
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
};
class Sequence : public Recognizer{
public:
Sequence();
std::shared_ptr<Sequence> addRecognizer(const std::shared_ptr<Recognizer> &element);
virtual bool _getTransitionMap(TransitionMap *mask);
protected:
......@@ -122,7 +118,6 @@ private:
class Loop : public Recognizer{
public:
Loop();
std::shared_ptr<Loop> setRecognizer(const std::shared_ptr<Recognizer> &element, int min=0, int max=-1);
virtual bool _getTransitionMap(TransitionMap *mask);
protected:
......@@ -130,7 +125,8 @@ protected:
private:
virtual size_t _feed(const std::shared_ptr<ParserContextBase> &ctx, const std::string &input, size_t pos);
std::shared_ptr<Recognizer> mRecognizer;
int mMin, mMax;
int mMin = 0;
int mMax = -1;
};
......@@ -171,7 +167,6 @@ public:
class RecognizerPointer : public Recognizer{
public:
RecognizerPointer();
std::shared_ptr<Recognizer> getPointed();
void setPointed(const std::shared_ptr<Recognizer> &r);
private:
......
......@@ -35,7 +35,6 @@ public:
class ABNFRule : public ABNFBuilder{
public:
ABNFRule();
static std::shared_ptr<ABNFRule> create();
void setName(const std::string &name);
void setDefinedAs(const std::string &defined_as);
......@@ -62,7 +61,6 @@ private:
class ABNFNumval : public ABNFBuilder{
public:
ABNFNumval();
static std::shared_ptr<ABNFNumval> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void setDecVal(const std::string &decval);
......@@ -71,12 +69,11 @@ public:
private:
void parseValues(const std::string &val, int base);
std::vector<int> mValues;
bool mIsRange;
bool mIsRange = false;
};
class ABNFElement : public ABNFBuilder{
public:
ABNFElement();
static std::shared_ptr<ABNFElement> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void setElement(const std::shared_ptr<ABNFBuilder> &e);
......@@ -91,7 +88,6 @@ private:
class ABNFGroup : public ABNFBuilder{
public:
ABNFGroup();
static std::shared_ptr<ABNFGroup> create();
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
void setAlternation(const std::shared_ptr<ABNFAlternation> &a);
......@@ -101,7 +97,6 @@ private:
class ABNFRepetition : public ABNFBuilder{
public:
ABNFRepetition();
static std::shared_ptr<ABNFRepetition> create();
void setRepeat(const std::string &r);
void setMin(int min);
......@@ -110,14 +105,15 @@ public:
void setElement(const std::shared_ptr<ABNFElement> &e);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
private:
int mMin, mMax, mCount;
int mMin = 0;
int mMax = -1;
int mCount = -1;
std::string mRepeat;
std::shared_ptr<ABNFElement> mElement;
};
class ABNFOption : public ABNFBuilder{
public:
ABNFOption();
static std::shared_ptr<ABNFOption> create();
void setAlternation(const std::shared_ptr<ABNFAlternation> &a);
std::shared_ptr<Recognizer> buildRecognizer(const std::shared_ptr<Grammar> &grammar);
......
......@@ -46,10 +46,11 @@ public:
template <typename _derivedParserElementT, typename _parserElementT, typename _valueT>
class ParserCollector : public CollectorBase<_parserElementT,_valueT>{
public:
ParserCollector(const std::function<void (_derivedParserElementT , _valueT)> &fn) : mFunc(fn){
}
ParserCollector(const std::function<void (_derivedParserElementT , _valueT)> &fn) : mFunc(fn) {}
virtual void invoke(_parserElementT obj, _valueT value);
void invokeWithChild(_parserElementT obj, _parserElementT child);
private:
std::function<void (_derivedParserElementT, _valueT)> mFunc;
};
......@@ -57,10 +58,11 @@ private:
template <typename _derivedParserElementT, typename _parserElementT, typename _valueT>
class ParserChildCollector : public CollectorBase<_parserElementT,_valueT>{
public:
ParserChildCollector(const std::function<void (_derivedParserElementT , _valueT)> &fn) : mFunc(fn){
}
ParserChildCollector(const std::function<void (_derivedParserElementT , _valueT)> &fn) : mFunc(fn){}
virtual void invoke(_parserElementT obj, _valueT value);
virtual void invokeWithChild(_parserElementT obj, _parserElementT child);
private:
std::function<void (_derivedParserElementT, _valueT)> mFunc;
};
......@@ -76,17 +78,20 @@ class HandlerContextBase;
template <typename _parserElementT>
class ParserHandlerBase : public std::enable_shared_from_this<ParserHandlerBase<_parserElementT>>{
friend class HandlerContext<_parserElementT>;
public:
virtual _parserElementT invoke(const std::string &input, size_t begin, size_t count)=0;
std::shared_ptr<HandlerContext<_parserElementT>> createContext();
const std::string &getRulename()const{
return mRulename;
}
protected:
void releaseContext(const std::shared_ptr<HandlerContext<_parserElementT>> &ctx);
ParserHandlerBase(const Parser<_parserElementT> &parser, const std::string &name);
void installCollector(const std::string &rulename, const std::shared_ptr<AbstractCollector<_parserElementT>> &collector);
const std::shared_ptr<AbstractCollector<_parserElementT>> &getCollector(unsigned int rule_id)const;
private:
std::map<unsigned int, std::shared_ptr<AbstractCollector<_parserElementT>> > mCollectors;
const Parser<_parserElementT> &mParser;
......@@ -98,11 +103,10 @@ template <typename _derivedParserElementT, typename _parserElementT>
class ParserHandler : public ParserHandlerBase<_parserElementT>{
public:
ParserHandler(const Parser<_parserElementT> &parser, const std::string &rulename, const std::function<_derivedParserElementT ()> &create)
: ParserHandlerBase<_parserElementT>(parser, rulename), mHandlerCreateFunc(create){
}
: ParserHandlerBase<_parserElementT>(parser, rulename), mHandlerCreateFunc(create){}
ParserHandler(const Parser<_parserElementT> &parser, const std::string &rulename, const std::function<_derivedParserElementT (const std::string &, const std::string &)> &create)
: ParserHandlerBase<_parserElementT>(parser, rulename), mHandlerCreateDebugFunc(create){
}
: ParserHandlerBase<_parserElementT>(parser, rulename), mHandlerCreateDebugFunc(create){}
template <typename _derivedParserElementTChild>
std::shared_ptr<ParserHandler<_derivedParserElementT,_parserElementT>> setCollector(const std::string &child_rule_name, std::function<void (_derivedParserElementTChild , const std::string & )> fn){
this->installCollector(child_rule_name, std::make_shared<ParserCollector<_derivedParserElementT,_parserElementT,const std::string&>>(fn));
......@@ -119,6 +123,7 @@ public:
return std::static_pointer_cast<ParserHandler<_derivedParserElementT,_parserElementT>>(this->shared_from_this());
}
_parserElementT invoke(const std::string &input, size_t begin, size_t count);
private:
std::function<_derivedParserElementT ()> mHandlerCreateFunc;
std::function<_derivedParserElementT (const std::string &, const std::string &)> mHandlerCreateDebugFunc;
......@@ -126,17 +131,17 @@ private:
template <typename _parserElementT>
class Assignment{
public:
Assignment(const std::shared_ptr<AbstractCollector<_parserElementT>> &c, size_t begin, size_t count, const std::shared_ptr<HandlerContext<_parserElementT>> &child)
: mCollector(c.get()), mBegin(begin), mCount(count), mChild(child) {}
void invoke(_parserElementT parent, const std::string &input);
private:
AbstractCollector<_parserElementT> * mCollector;//not a shared_ptr for optimization, the collector cannot disapear
size_t mBegin;
size_t mCount;
std::shared_ptr<HandlerContext<_parserElementT>> mChild;
public:
Assignment(const std::shared_ptr<AbstractCollector<_parserElementT>> &c, size_t begin, size_t count, const std::shared_ptr<HandlerContext<_parserElementT>> &child)
: mCollector(c.get()), mBegin(begin), mCount(count), mChild(child)
{
}
void invoke(_parserElementT parent, const std::string &input);
};
class HandlerContextBase : public std::enable_shared_from_this<HandlerContextBase>{
......@@ -148,6 +153,7 @@ template <typename _parserElementT>
class HandlerContext : public HandlerContextBase{
public:
HandlerContext(const std::shared_ptr<ParserHandlerBase<_parserElementT>> &handler);
void setChild(unsigned int subrule_id, size_t begin, size_t count, const std::shared_ptr<HandlerContext> &child);
_parserElementT realize(const std::string &input, size_t begin, size_t count);
std::shared_ptr<HandlerContext<_parserElementT>> branch();
......@@ -155,6 +161,7 @@ public:
size_t getLastIterator()const;
void undoAssignments(size_t pos);
void recycle();
private:
ParserHandlerBase<_parserElementT> & mHandler;
std::vector<Assignment<_parserElementT>> mAssignments;
......@@ -185,6 +192,7 @@ class ParserContext : public ParserContextBase{
public:
ParserContext(Parser<_parserElementT> &parser);
_parserElementT createRootObject(const std::string &input);
protected:
virtual void beginParse(ParserLocalContext &ctx, const std::shared_ptr<Recognizer> &rec);
virtual void endParse(const ParserLocalContext &ctx, const std::string &input, size_t begin, size_t count);
......@@ -196,6 +204,7 @@ protected:
std::shared_ptr<HandlerContext<_parserElementT>> _branch();
void _merge(const std::shared_ptr<HandlerContext<_parserElementT>> &other);
void _removeBranch(const std::shared_ptr<HandlerContext<_parserElementT>> &other);
private:
Parser<_parserElementT> & mParser;
std::list<std::shared_ptr<HandlerContext<_parserElementT>>> mHandlerStack;
......@@ -213,8 +222,10 @@ template <typename _parserElementT>
class Parser{
friend class ParserContext<_parserElementT>;
friend class ParserHandlerBase<_parserElementT>;
public:
Parser(const std::shared_ptr<Grammar> &grammar);
template <typename _derivedParserElementT>
std::shared_ptr<ParserHandler<_derivedParserElementT,_parserElementT>> setHandler(const std::string &rulename,const std::function<_derivedParserElementT ()> & handler){
auto ret=std::make_shared<ParserHandler<_derivedParserElementT,_parserElementT>>(*this, rulename,handler);
......@@ -231,6 +242,7 @@ public:
}
_parserElementT parseInput(const std::string &rulename, const std::string &input, size_t *parsed_size);
private:
std::shared_ptr<ParserHandlerBase<_parserElementT>> &getHandler(unsigned int);
void installHandler(const std::shared_ptr<ParserHandlerBase<_parserElementT>> &handler);
......@@ -246,6 +258,7 @@ public:
static std::shared_ptr<DebugElement> create(const std::string &rulename, const std::string &value);
void addChild(const std::shared_ptr<DebugElement> &e);
BELR_PUBLIC std::ostream &tostream(int level, std::ostream &str)const;
private:
std::string mRulename;
std::string mValue;
......
......@@ -54,11 +54,6 @@ void TransitionMap::merge(const TransitionMap* other){
}
}
Recognizer::Recognizer() : mId(0) {
}
void Recognizer::setName(const std::string& name){
static unsigned int id_base=0;
mName=name;
......@@ -142,10 +137,6 @@ void CharRecognizer::_optimize(int recursionLevel){
}
Selector::Selector() : mIsExclusive(false){
}
shared_ptr<Selector> Selector::addRecognizer(const shared_ptr<Recognizer> &r){
mElements.push_back(r);
return static_pointer_cast<Selector> (shared_from_this());
......@@ -221,19 +212,11 @@ void Selector::_optimize(int recursionLevel){
}
}
ExclusiveSelector::ExclusiveSelector() {
mIsExclusive = true;
}
size_t ExclusiveSelector::_feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos){
return Selector::_feedExclusive(ctx, input, pos);
}
Sequence::Sequence(){
}
shared_ptr<Sequence> Sequence::addRecognizer(const shared_ptr<Recognizer> &element){
mElements.push_back(element);
return static_pointer_cast<Sequence>( shared_from_this());
......@@ -272,10 +255,6 @@ void Sequence::_optimize(int recursionLevel){
}
Loop::Loop() : mMin(0), mMax(-1) {
}
shared_ptr<Loop> Loop::setRecognizer(const shared_ptr<Recognizer> &element, int min, int max){
mMin=min;
mMax=max;
......@@ -369,9 +348,6 @@ shared_ptr<Recognizer> Utils::char_range(int begin, int end){
return make_shared<CharRange>(begin, end);
}
RecognizerPointer::RecognizerPointer() {
}
shared_ptr<Recognizer> RecognizerPointer::getPointed(){
return mRecognizer;
}
......
......@@ -30,10 +30,6 @@ using namespace std;
// =============================================================================
namespace belr{
ABNFNumval::ABNFNumval() : mIsRange(false) {
}
shared_ptr< ABNFNumval > ABNFNumval::create(){
return make_shared<ABNFNumval>();
}
......@@ -91,10 +87,6 @@ shared_ptr< Recognizer > ABNFOption::buildRecognizer(const shared_ptr< Grammar >
return Foundation::loop()->setRecognizer(mAlternation->buildRecognizer(grammar),0,1);
}
ABNFOption::ABNFOption() {
}
shared_ptr< ABNFOption > ABNFOption::create(){
return make_shared<ABNFOption>();
}
......@@ -103,10 +95,6 @@ void ABNFOption::setAlternation(const shared_ptr< ABNFAlternation >& a){
mAlternation=a;
}
ABNFGroup::ABNFGroup() {
}
shared_ptr< ABNFGroup > ABNFGroup::create(){
return make_shared<ABNFGroup>();
}
......@@ -135,10 +123,6 @@ shared_ptr< Recognizer > ABNFElement::buildRecognizer(const shared_ptr< Grammar
return nullptr;
}
ABNFElement::ABNFElement() {
}
shared_ptr< ABNFElement > ABNFElement::create(){
return make_shared<ABNFElement>();
}
......@@ -162,10 +146,6 @@ void ABNFElement::setProseVal(const string& prose){
}
}
ABNFRepetition::ABNFRepetition() : mMin(0), mMax(-1), mCount(-1) {
}
shared_ptr< ABNFRepetition > ABNFRepetition::create(){
return make_shared<ABNFRepetition>();
}
......@@ -247,10 +227,6 @@ shared_ptr< Recognizer > ABNFAlternation::buildRecognizerNoOptim(const shared_pt
return sel;
}
ABNFRule::ABNFRule() {
}
shared_ptr<ABNFRule> ABNFRule::create(){
return make_shared<ABNFRule>();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment