Commit 40c048cf authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fix some values not initialized + possibility of infinite loop

parent 7f03415a
......@@ -38,6 +38,7 @@ protected:
virtual bool _getTransitionMap(TransitionMap *mask);
virtual void _optimize(int recursionLevel)=0;
Recognizer();
virtual ~Recognizer() { }
virtual size_t _feed(const shared_ptr<ParserContextBase> &ctx, const string &input, size_t pos)=0;
string mName;
unsigned int mId;
......@@ -155,6 +156,9 @@ public:
* Initialize an empty grammar, giving a name for debugging.
**/
Grammar(const string &name);
virtual ~Grammar() { }
/**
* Include another grammar into this grammar.
**/
......
......@@ -17,6 +17,7 @@ public:
class ABNFRule : public ABNFBuilder{
public:
ABNFRule();
static shared_ptr<ABNFRule> create();
void setName(const string &name);
void setDefinedAs(const string &defined_as);
......@@ -56,6 +57,7 @@ private:
class ABNFElement : public ABNFBuilder{
public:
ABNFElement();
static shared_ptr<ABNFElement> create();
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void setElement(const shared_ptr<ABNFBuilder> &e);
......@@ -70,6 +72,7 @@ private:
class ABNFGroup : public ABNFBuilder{
public:
ABNFGroup();
static shared_ptr<ABNFGroup> create();
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
void setAlternation(const shared_ptr<ABNFAlternation> &a);
......@@ -95,6 +98,7 @@ private:
class ABNFOption : public ABNFBuilder{
public:
ABNFOption();
static shared_ptr<ABNFOption> create();
void setAlternation(const shared_ptr<ABNFAlternation> &a);
shared_ptr<Recognizer> buildRecognizer(const shared_ptr<Grammar> &grammar);
......
......@@ -127,7 +127,7 @@ void HandlerContext< _parserElementT >::recycle(){
//
template <typename _parserElementT>
ParserHandlerBase<_parserElementT>::ParserHandlerBase(const Parser<_parserElementT> &parser, const string &name) : mParser(parser), mRulename(tolower(name)){
ParserHandlerBase<_parserElementT>::ParserHandlerBase(const Parser<_parserElementT> &parser, const string &name) : mParser(parser), mRulename(tolower(name)), mCachedContext(NULL) {
}
template <typename _parserElementT>
......@@ -181,7 +181,7 @@ _parserElementT ParserHandler<_derivedParserElementT,_parserElementT>::invoke(co
//
template <typename _parserElementT>
ParserContext<_parserElementT>::ParserContext(Parser<_parserElementT> &parser) : mParser(parser){
ParserContext<_parserElementT>::ParserContext(Parser<_parserElementT> &parser) : mParser(parser), mRoot(NULL) {
}
template <typename _parserElementT>
......@@ -294,7 +294,7 @@ void ParserContext<_parserElementT>::removeBranch(const shared_ptr<HandlerContex
//
template <typename _parserElementT>
Parser<_parserElementT>::Parser(const shared_ptr<Grammar> &grammar) : mGrammar(grammar){
Parser<_parserElementT>::Parser(const shared_ptr<Grammar> &grammar) : mGrammar(grammar), mNullHandler(NULL), mNullCollector(NULL) {
if (!mGrammar->isComplete()){
cerr<<"Grammar not complete, aborting."<<endl;
return;
......
......@@ -140,7 +140,7 @@ private:
};
struct ParserLocalContext{
ParserLocalContext(){
ParserLocalContext() : mHandlerContext(NULL), mRecognizer(NULL), mAssignmentPos(0) {
}
void set(const shared_ptr<HandlerContextBase>& hc, const shared_ptr<Recognizer>& rec, size_t pos){
mHandlerContext=hc;
......
......@@ -37,7 +37,7 @@ void TransitionMap::merge(const TransitionMap* other){
Recognizer::Recognizer(){
Recognizer::Recognizer() : mId(0) {
}
void Recognizer::setName(const string& name){
......@@ -253,9 +253,8 @@ void Sequence::_optimize(int recursionLevel){
}
Loop::Loop(){
mMin=0;
mMax=-1;
Loop::Loop() : mRecognizer(NULL), mMin(0), mMax(-1) {
}
shared_ptr<Loop> Loop::setRecognizer(const shared_ptr<Recognizer> &element, int min, int max){
......
......@@ -44,6 +44,9 @@ void ABNFNumval::parseValues(const string &val, int base){
char *endptr=NULL;
do{
long lv=strtol(s,&endptr,base);
if (lv == 0 && s == endptr) {
break;
}
if (*endptr=='.') s=endptr+1;
else s=endptr;
mValues.push_back(lv);
......@@ -67,6 +70,10 @@ shared_ptr< Recognizer > ABNFOption::buildRecognizer(const shared_ptr< Grammar >
return Foundation::loop()->setRecognizer(mAlternation->buildRecognizer(grammar),0,1);
}
ABNFOption::ABNFOption() : mAlternation(NULL) {
}
shared_ptr< ABNFOption > ABNFOption::create(){
return make_shared<ABNFOption>();
}
......@@ -75,6 +82,10 @@ void ABNFOption::setAlternation(const shared_ptr< ABNFAlternation >& a){
mAlternation=a;
}
ABNFGroup::ABNFGroup() : mAlternation(NULL) {
}
shared_ptr< ABNFGroup > ABNFGroup::create(){
return make_shared<ABNFGroup>();
}
......@@ -103,6 +114,10 @@ shared_ptr< Recognizer > ABNFElement::buildRecognizer(const shared_ptr< Grammar
return NULL;
}
ABNFElement::ABNFElement() : mElement(NULL) {
}
shared_ptr< ABNFElement > ABNFElement::create(){
return make_shared<ABNFElement>();
}
......@@ -126,7 +141,9 @@ void ABNFElement::setProseVal(const string& prose){
}
}
ABNFRepetition::ABNFRepetition() : mMin(0), mMax(-1), mCount(-1), mElement(NULL) {
}
shared_ptr< ABNFRepetition > ABNFRepetition::create(){
return make_shared<ABNFRepetition>();
......@@ -148,6 +165,9 @@ void ABNFRepetition::setRepeat(const string& r){
mRepeat=r;
}
void ABNFRepetition::setElement(const shared_ptr< ABNFElement >& e){
mElement=e;
}
shared_ptr< Recognizer > ABNFRepetition::buildRecognizer(const shared_ptr< Grammar >& grammar){
if (mRepeat.empty()) return mElement->buildRecognizer(grammar);
......@@ -159,18 +179,6 @@ shared_ptr< Recognizer > ABNFRepetition::buildRecognizer(const shared_ptr< Gramm
}
}
ABNFRepetition::ABNFRepetition(){
mMin=0;
mMax=-1;
mCount=-1;
}
void ABNFRepetition::setElement(const shared_ptr< ABNFElement >& e){
mElement=e;
}
shared_ptr<ABNFConcatenation> ABNFConcatenation::create(){
return make_shared<ABNFConcatenation>();
}
......@@ -218,6 +226,9 @@ shared_ptr< Recognizer > ABNFAlternation::buildRecognizerNoOptim(const shared_pt
return sel;
}
ABNFRule::ABNFRule() : mAlternation(NULL) {
}
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