Commit 5cac0f07 authored by Ronan's avatar Ronan

replace NULL by nullptr keyword

parent 9862904a
......@@ -19,7 +19,7 @@
#ifndef _ABNF_H_
#define _ABNF_H_
#include "belr.hh"
#include "belr.h"
namespace belr{
......
......@@ -221,12 +221,12 @@ public:
/**
* Find a rule from the grammar, given its name.
* @param name the name of the rule
* @return the recognizer implementing this rule. Is NULL if the rule doesn't exist in the grammar.
* @return the recognizer implementing this rule. Is nullptr if the rule doesn't exist in the grammar.
**/
BELR_PUBLIC std::shared_ptr<Recognizer> findRule(const std::string &name);
/**
* Find a rule from the grammar, given its name.
* Unlike findRule(), getRule() never returns NULL.
* Unlike findRule(), getRule() never returns nullptr.
* If the rule is not (yet) defined, it returns an undefined pointer, that will be set later if the rule gets defined.
* This mechanism is required to allow defining rules in any order, and defining rules that call themselve recursively.
* @param name the name of the rule to get
......
......@@ -19,7 +19,7 @@
#ifndef _GRAMMARBUILDER_H_
#define _GRAMMARBUILDER_H_
#include "parser.hh"
#include "parser.h"
#include <vector>
using namespace std;
......@@ -161,9 +161,9 @@ public:
* the protocol or language described in the grammar.
* @param abnf the string that contains the abnf grammar.
* @param grammar an optional grammar to include.
* @return the Grammar object corresponding to the text definition loaded, NULL if an error occured.
* @return the Grammar object corresponding to the text definition loaded, nullptr if an error occured.
**/
BELR_PUBLIC std::shared_ptr<Grammar> createFromAbnf(const std::string &abnf, const std::shared_ptr<Grammar> &grammar=NULL);
BELR_PUBLIC std::shared_ptr<Grammar> createFromAbnf(const std::string &abnf, const std::shared_ptr<Grammar> &grammar=nullptr);
/**
* Create a grammar from an ABNF grammar defined in the text file pointed by path.
* An optional Grammar argument corresponding to a grammar to include can be passed.
......@@ -172,9 +172,9 @@ public:
* the protocol or language described in the grammar.
* @param path the path from where to load the abnf definition.
* @param grammar an optional grammar to include.
* @return the Grammar object corresponding to the text definition loaded, NULL if an error occured.
* @return the Grammar object corresponding to the text definition loaded, nullptr if an error occured.
**/
BELR_PUBLIC std::shared_ptr<Grammar> createFromAbnfFile(const std::string &path, const std::shared_ptr<Grammar> &grammar=NULL);
BELR_PUBLIC std::shared_ptr<Grammar> createFromAbnfFile(const std::string &path, const std::shared_ptr<Grammar> &grammar=nullptr);
private:
Parser<std::shared_ptr<ABNFBuilder>> mParser;
};
......
......@@ -24,7 +24,7 @@
#include <iostream>
#include <algorithm>
#include "belr.hh"
#include "belr.h"
namespace belr {
......@@ -404,7 +404,7 @@ void HandlerContext< _parserElementT >::recycle(){
//
template <typename _parserElementT>
ParserHandlerBase<_parserElementT>::ParserHandlerBase(const Parser<_parserElementT> &parser, const std::string &name) : mParser(parser), mRulename(tolower(name)), mCachedContext(NULL) {
ParserHandlerBase<_parserElementT>::ParserHandlerBase(const Parser<_parserElementT> &parser, const std::string &name) : mParser(parser), mRulename(tolower(name)), mCachedContext(nullptr) {
}
template <typename _parserElementT>
......@@ -449,7 +449,7 @@ _parserElementT ParserHandler<_derivedParserElementT,_parserElementT>::invoke(co
return universal_pointer_cast<_parserElementT>(mHandlerCreateFunc());
if (mHandlerCreateDebugFunc)
return universal_pointer_cast<_parserElementT>(mHandlerCreateDebugFunc(this->getRulename(), input.substr(begin, count)));
return NULL;
return nullptr;
}
......@@ -495,7 +495,7 @@ void ParserContext<_parserElementT>::_endParse(const ParserLocalContext &localct
if (count!=std::string::npos && count>0){
/*assign std::string to parent */
if (localctx.mRecognizer->getId()!=0)
mHandlerStack.back()->setChild(localctx.mRecognizer->getId(), begin, count, NULL);
mHandlerStack.back()->setChild(localctx.mRecognizer->getId(), begin, count, nullptr);
}else{
mHandlerStack.back()->undoAssignments(localctx.mAssignmentPos);
}
......@@ -504,7 +504,7 @@ void ParserContext<_parserElementT>::_endParse(const ParserLocalContext &localct
template <typename _parserElementT>
_parserElementT ParserContext<_parserElementT>::createRootObject(const std::string &input){
return mRoot ? mRoot->realize(input,0,input.size()) : NULL;
return mRoot ? mRoot->realize(input,0,input.size()) : nullptr;
}
template <typename _parserElementT>
......
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belr/abnf.hh"
#include "belr/abnf.h"
using namespace std;
using namespace belr;
......
......@@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belr/belr.hh"
#include "belr/parser.hh"
#include "belr/belr.h"
#include "belr/parser.h"
#include <algorithm>
#include <iostream>
......@@ -105,7 +105,7 @@ bool Recognizer::_getTransitionMap(TransitionMap* mask){
input.resize(2,'\0');
for(int i=0;i<256;++i){
input[0]=i;
if (feed(NULL,input,0)==1)
if (feed(nullptr,input,0)==1)
mask->mPossibleChars[i]=true;
}
return true;
......@@ -201,7 +201,7 @@ void Selector::_optimize(int recursionLevel){
for (auto it=mElements.begin(); it!=mElements.end(); ++it){
(*it)->optimize(recursionLevel);
}
TransitionMap *all=NULL;
TransitionMap *all=nullptr;
bool intersectionFound=false;
for (auto it=mElements.begin(); it!=mElements.end() && !intersectionFound; ++it){
TransitionMap *cur=new TransitionMap();
......@@ -403,7 +403,7 @@ Grammar::Grammar(const string& name) : mName(name){
Grammar::~Grammar() {
for(auto it = mRecognizerPointers.begin(); it != mRecognizerPointers.end(); ++it) {
shared_ptr<RecognizerPointer> pointer = dynamic_pointer_cast<RecognizerPointer>(*it);
pointer->setPointed(NULL);
pointer->setPointed(nullptr);
}
}
......@@ -448,7 +448,7 @@ shared_ptr<Recognizer> Grammar::findRule(const string &argname){
if (it!=mRules.end()){
return (*it).second;
}
return NULL;
return nullptr;
}
shared_ptr<Recognizer> Grammar::getRule(const string &argname){
......
......@@ -16,9 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belr/abnf.hh"
#include "belr/grammarbuilder.hh"
#include "belr/parser.hh"
#include "belr/abnf.h"
#include "belr/grammarbuilder.h"
#include "belr/parser.h"
#include "bctoolbox/logging.h"
......@@ -59,13 +59,13 @@ void ABNFNumval::parseValues(const string &val, int base){
mIsRange=true;
string first=val.substr(1,dash-1);
string last=val.substr(dash+1,string::npos);
mValues.push_back(strtol(first.c_str(),NULL,base));
mValues.push_back(strtol(last.c_str(),NULL,base));
mValues.push_back(strtol(first.c_str(),nullptr,base));
mValues.push_back(strtol(last.c_str(),nullptr,base));
}else{
mIsRange=false;
string tmp=val.substr(1,string::npos);
const char *s=tmp.c_str();
char *endptr=NULL;
char *endptr=nullptr;
do{
long lv=strtol(s,&endptr,base);
if (lv == 0 && s == endptr) {
......@@ -135,7 +135,7 @@ shared_ptr< Recognizer > ABNFElement::buildRecognizer(const shared_ptr< Grammar
}
bctbx_error("[belr] ABNFElement::buildRecognizer is empty, should not happen!");
abort();
return NULL;
return nullptr;
}
ABNFElement::ABNFElement() {
......@@ -221,7 +221,7 @@ shared_ptr<Recognizer> ABNFConcatenation::buildRecognizer(const shared_ptr<Gramm
}
return seq;
}
return NULL;
return nullptr;
}
void ABNFConcatenation::addRepetition(const shared_ptr< ABNFRepetition >& r){
......@@ -301,7 +301,7 @@ shared_ptr<Recognizer> ABNFRuleList::buildRecognizer(const shared_ptr<Grammar> &
grammar->addRule(rule->getName(), rule->buildRecognizer(grammar));
}
}
return NULL;
return nullptr;
}
ABNFGrammarBuilder::ABNFGrammarBuilder()
......@@ -345,10 +345,10 @@ shared_ptr<Grammar> ABNFGrammarBuilder::createFromAbnf(const string &abnf, const
shared_ptr<ABNFBuilder> builder = mParser.parseInput("rulelist",abnf,&parsed);
if (parsed<(size_t)abnf.size()){
bctbx_error("[belr] Only %llu bytes parsed over a total of %llu.", (unsigned long long)parsed, (unsigned long long) abnf.size());
return NULL;
return nullptr;
}
shared_ptr<Grammar> retGram;
if (gram==NULL) retGram=make_shared<Grammar>(abnf);
if (gram==nullptr) retGram=make_shared<Grammar>(abnf);
else retGram=gram;
builder->buildRecognizer(retGram);
bctbx_message("[belr] Succesfully created grammar with %i rules.", retGram->getNumRules());
......@@ -366,7 +366,7 @@ shared_ptr<Grammar> ABNFGrammarBuilder::createFromAbnfFile(const string &path, c
ifstream istr(path);
if (!istr.is_open()){
bctbx_error("[belr] Could not open %s", path.c_str());
return NULL;
return nullptr;
}
stringstream sstr;
sstr<<istr.rdbuf();
......
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <belr/parser.hh>
#include <belr/parser.h>
using namespace std;
......
......@@ -15,7 +15,7 @@ using namespace belr;
using namespace std;
int main(int argc, char *argv[]){
const char *file=NULL,*message_file=NULL;
const char *file=nullptr,*message_file=nullptr;
int rules_first=0;
int i;
int repeat_count=1;
......@@ -39,12 +39,12 @@ int main(int argc, char *argv[]){
}
}
rules_first=i+1;
ABNFGrammarBuilder builder;
shared_ptr<Grammar> grammar=make_shared<Grammar>(file);
grammar->include(make_shared<CoreRules>());
grammar = builder.createFromAbnfFile(file,grammar);
if (message_file){
ifstream istr(message_file);
if (!istr.is_open()){
......
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