Commit 1c6d383a authored by Mariana Suarez's avatar Mariana Suarez

Fix zero as null pointer constant issue

parent 795edaee
......@@ -45,7 +45,7 @@ void Executer::initialize(TreeNode* tree, ErrorList* _errorList)
breaking = false;
returning = false;
waiting = false;
returnValue = 0;
returnValue = nullptr;
executeCurrent = false;
......@@ -94,7 +94,7 @@ void Executer::execute()
delete calledFunction.variableTable;
currentNode = calledFunction.function;
if (returnValue == 0)
if (returnValue == nullptr)
currentNode->setNullValue(); // Handle an empty return value
else
currentNode->setValue(returnValue);
......@@ -103,11 +103,11 @@ void Executer::execute()
return;
}
if (newScope == 0) {
if (newScope == nullptr) {
TreeNode* currentParent = currentNode->parent();
currentNode = currentNode->nextSibling();
if(currentNode == 0) { //running off sibling list
if(currentNode == nullptr) { //running off sibling list
currentNode = currentParent;
if(currentNode == rootNode) {
......@@ -129,7 +129,7 @@ void Executer::execute()
else
currentNode = newScope;
newScope = 0;
newScope = nullptr;
}
......@@ -297,7 +297,7 @@ bool Executer::checkParameterType(TreeNode* node, int valueType, int errorCode)
// //qDebug() << "called";
uint quantity = node->childCount();
TreeNode* currentChild = node->firstChild();
while (currentChild != 0) {
while (currentChild != nullptr) {
if (currentChild->value()->type() != valueType) {
switch (valueType) {
case Value::String:
......@@ -368,7 +368,7 @@ void Executer::executeScope(TreeNode* node) {
if(parentTokenType == Token::Learn) {
//We have the end of a Learn, so we should return
returning = true;
returnValue = 0;
returnValue = nullptr;
return;
}
newScope = node;
......@@ -408,7 +408,7 @@ void Executer::executeFunctionCall(TreeNode* node) {
}
if (returning) { // if the function is already executed and returns now
returnValue = 0;
returnValue = nullptr;
returning = false;
// //qDebug() << "==> functionReturned!";
return;
......@@ -610,7 +610,7 @@ void Executer::executeBreak(TreeNode* node) {
TreeNode* ns = getParentOfTokenTypes(node, &tokenTypes);
if(ns!=0)
if(ns!=nullptr)
newScope = ns;
//else
// We could add an error right HERE
......@@ -623,7 +623,7 @@ void Executer::executeReturn(TreeNode* node) {
if(node->childCount()>0)
returnValue = node->child(0)->value();
else
returnValue = 0;
returnValue = nullptr;
returning = true;
}
void Executer::executeWait(TreeNode* node) {
......@@ -1091,7 +1091,7 @@ TreeNode* Executer::getParentOfTokenTypes(TreeNode* child, QList<int>* types) {
if(child->parent()->token()->type()==type)
return child->parent();
else if(child->parent()->token()->type()==Token::Root)
return 0;
return nullptr;
}
return getParentOfTokenTypes(child->parent(), types);
}
......
......@@ -47,7 +47,7 @@ void Parser::parse()
// //qDebug() << "Parser::parse() -- main parse loop called";
TreeNode* resultNode = parseStatement(); // parse the next statement
if (resultNode == 0) { // no statement was found
if (resultNode == nullptr) { // no statement was found
addError(i18n("Expected a command, instead got '%1'", currentToken->look()), *currentToken, 0);
return;
}
......@@ -59,9 +59,9 @@ void Parser::parse()
currentScope->appendChild(resultNode);
}
if (newScope != 0) {
if (newScope != nullptr) {
currentScope = newScope;
newScope = 0;
newScope = nullptr;
}
}
......@@ -405,8 +405,8 @@ TreeNode* Parser::parseTerm()
// //qDebug() << "Parser::parseTerm()";
TreeNode* termNode = parseSignedFactor();
TreeNode* pos = termNode;
TreeNode* left = 0;
TreeNode* right = 0;
TreeNode* left = nullptr;
TreeNode* right = nullptr;
while ( (currentToken->type() == Token::Multiplication) ||
(currentToken->type() == Token::Division) ||
......@@ -417,7 +417,7 @@ TreeNode* Parser::parseTerm()
pos->appendChild(left);
nextToken();
right = parseSignedFactor();
if (right != 0)
if (right != nullptr)
pos->appendChild(right);
termNode = pos;
}
......@@ -430,10 +430,10 @@ TreeNode* Parser::parseExpression()
// //qDebug() << "Parser::parseExpression()";
TreeNode* expressionNode = parseTerm();
TreeNode* pos = expressionNode;
TreeNode* left = 0;
TreeNode* right = 0;
TreeNode* left = nullptr;
TreeNode* right = nullptr;
Token* prevToken = 0;
Token* prevToken = nullptr;
while ((currentToken->type() == Token::Addition) ||
(currentToken->type() == Token::Substracton) ||
......@@ -456,7 +456,7 @@ TreeNode* Parser::parseExpression()
right = parseExpression();
else
right = parseTerm();
if (right != 0) pos->appendChild(right);
if (right != nullptr) pos->appendChild(right);
expressionNode = pos;
}
return expressionNode;
......
......@@ -24,11 +24,11 @@
#include "token.h"
Translator* Translator::m_instance = 0; // initialize pointer
Translator* Translator::m_instance = nullptr; // initialize pointer
Translator* Translator::instance()
{
if (m_instance == 0) m_instance = new Translator; // create sole instance if its the first call
if (m_instance == nullptr) m_instance = new Translator; // create sole instance if its the first call
return m_instance; // address of sole instance
}
......@@ -40,7 +40,7 @@ Translator::Translator()
Translator::~Translator()
{
delete m_instance;
m_instance = 0;
m_instance = nullptr;
}
......
......@@ -24,7 +24,7 @@
TreeNode::~TreeNode()
{
if (childList != 0) {
if (childList != nullptr) {
// this should work here:
qDeleteAll(*childList);
childList->clear();
......@@ -41,15 +41,15 @@ void TreeNode::init(TreeNode* parent, Token* token)
{
setParent(parent);
setToken(token);
childList = 0;
childList = nullptr;
currentChildIndex = -1;
_value = 0;
_value = nullptr;
}
void TreeNode::appendChild(TreeNode* newChild)
{
if (childList == 0) childList = new ChildList();
if (childList == nullptr) childList = new ChildList();
newChild->setParent(this);
childList->append(newChild);
// // // QString out = QString("TreeNode::appendChild(): \"%5\" [%6] @ (%1,%2)-(%3,%4) to parent '%7'")
......@@ -67,22 +67,22 @@ void TreeNode::appendChild(TreeNode* newChild)
TreeNode* TreeNode::child(int i)
{
if (childList == 0) return 0;
if (childList == nullptr) return nullptr;
if (0 <= i && i < childList->size()) return childList->at(i);
return 0;
return nullptr;
}
TreeNode* TreeNode::firstChild()
{
if (childList == 0 || childList->isEmpty()) return 0;
if (childList == nullptr || childList->isEmpty()) return nullptr;
currentChildIndex = 0;
return childList->first();
}
TreeNode* TreeNode::nextChild()
{
if (childList == 0) return 0;
if (childList == nullptr) return nullptr;
currentChildIndex++;
return child(currentChildIndex);
}
......@@ -96,7 +96,7 @@ int TreeNode::findChildIndex(TreeNode* child)
TreeNode* TreeNode::nextSibling()
{
if (_parent == 0) return 0;
if (_parent == nullptr) return nullptr;
return _parent->child(_parent->findChildIndex(this)+1);
}
......@@ -111,7 +111,7 @@ QString TreeNode::toString()
// recursively walk through tree and show node names with indentation
void TreeNode::showTree(QString& str, int indent)
{
if (childList == 0) return;
if (childList == nullptr) return;
indent++;
TreeNode* node;
for (int i = 0; i < childList->size(); i++) {
......
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