From e78885d45285f663ba6cdf412294101d29aba258 Mon Sep 17 00:00:00 2001 From: IlyaShurupov Date: Sat, 23 Mar 2024 12:16:44 +0300 Subject: [PATCH] dont use NULL macro --- Objects/private/compiler/Constants.cpp | 6 +++--- Objects/private/compiler/Functions.cpp | 8 ++++---- Objects/private/interpreter/Interpreter.cpp | 18 +++++++++--------- Objects/private/interpreter/OperandsStack.cpp | 2 +- Objects/private/interpreter/ScopeStack.cpp | 2 +- Objects/private/parser/Parser.cpp | 2 +- Objects/private/primitives/DictObject.cpp | 10 +++++----- Objects/private/primitives/EnumObject.cpp | 8 ++++---- Objects/private/primitives/FloatObject.cpp | 4 ++-- Objects/private/primitives/IntObject.cpp | 4 ++-- Objects/private/primitives/LinkObject.cpp | 12 ++++++------ Objects/private/primitives/ListObject.cpp | 4 ++-- Objects/private/primitives/MethodObject.cpp | 4 ++-- Objects/private/primitives/NullObject.cpp | 16 ++++++++-------- Objects/private/primitives/Stringobject.cpp | 2 +- Objects/private/primitives/TypeObject.cpp | 2 +- 16 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Objects/private/compiler/Constants.cpp b/Objects/private/compiler/Constants.cpp index aa8dd48..0569902 100644 --- a/Objects/private/compiler/Constants.cpp +++ b/Objects/private/compiler/Constants.cpp @@ -50,7 +50,7 @@ ConstObject* ConstObjectsPool::registerObject(obj::Object* obj) { ConstObject* ConstObjectsPool::get(tp::alni val) { auto idx = mIntegers.presents(val); - ConstObject* const_obj = NULL; + ConstObject* const_obj = nullptr; if (idx) { const_obj = mIntegers.getSlotVal(idx); } else { @@ -62,7 +62,7 @@ ConstObject* ConstObjectsPool::get(tp::alni val) { ConstObject* ConstObjectsPool::get(const std::string& val) { auto idx = mStrings.presents(val); - ConstObject* const_obj = NULL; + ConstObject* const_obj = nullptr; if (idx) { const_obj = mStrings.getSlotVal(idx); } else { @@ -74,7 +74,7 @@ ConstObject* ConstObjectsPool::get(const std::string& val) { ConstObject* ConstObjectsPool::get(tp::alnf val) { auto idx = mFloats.presents(val); - ConstObject* const_obj = NULL; + ConstObject* const_obj = nullptr; if (idx) { const_obj = mFloats.getSlotVal(idx); } else { diff --git a/Objects/private/compiler/Functions.cpp b/Objects/private/compiler/Functions.cpp index 65e1ebe..9ceb42a 100644 --- a/Objects/private/compiler/Functions.cpp +++ b/Objects/private/compiler/Functions.cpp @@ -62,13 +62,13 @@ void FunctionDefinition::EvalStatement(Statement* stm) { EvalExpr(stm_while->mCondition); - auto jump_if_inst = inst(Instruction(NULL, Instruction::InstType::JUMP_IF_NOT)); + auto jump_if_inst = inst(Instruction(nullptr, Instruction::InstType::JUMP_IF_NOT)); if (stm_while->mScope) { EvalStatement(stm_while->mScope); } - auto jump_inst = inst(Instruction(NULL, Instruction::InstType::JUMP)); + auto jump_inst = inst(Instruction(nullptr, Instruction::InstType::JUMP)); auto end_mark = inst(Instruction()); jump_if_inst->data.mInstTarget = &end_mark->data; @@ -82,13 +82,13 @@ void FunctionDefinition::EvalStatement(Statement* stm) { EvalExpr(stm_if->mCondition); - auto jump_if_inst = inst(Instruction(NULL, Instruction::InstType::JUMP_IF_NOT)); + auto jump_if_inst = inst(Instruction(nullptr, Instruction::InstType::JUMP_IF_NOT)); if (stm_if->mOnTrue) { EvalStatement(stm_if->mOnTrue); } - auto jump_inst = inst(Instruction(NULL, Instruction::InstType::JUMP)); + auto jump_inst = inst(Instruction(nullptr, Instruction::InstType::JUMP)); auto else_mark = inst(Instruction()); if (stm_if->mOnFalse) { diff --git a/Objects/private/interpreter/Interpreter.cpp b/Objects/private/interpreter/Interpreter.cpp index bb4e645..293d763 100644 --- a/Objects/private/interpreter/Interpreter.cpp +++ b/Objects/private/interpreter/Interpreter.cpp @@ -33,7 +33,7 @@ void Interpreter::exec(obj::MethodObject* method, obj::ClassObject* self, obj::D return; } - mCallStack.enter({ NULL, method, 0 }); + mCallStack.enter({ nullptr, method, 0 }); mCallStack.mStack.last().mSelf = self; stepBytecodeIn(); @@ -250,7 +250,7 @@ void Interpreter::stepBytecodeIn() { case OpCode::OBJ_CREATE: { auto type = mOperandsStack.getOperand(); - Object* new_obj = NULL; + Object* new_obj = nullptr; // basic types auto idx = NDO->types.presents(type->val); @@ -272,11 +272,11 @@ void Interpreter::stepBytecodeIn() { // PUSH_ARGS protocol tp::uint2 len = 0; mOperandsStack.push((Object*) len); - mOperandsStack.push(NULL); + mOperandsStack.push(nullptr); // CALL protocol mScopeStack.enterScope(false); - mCallStack.enter({ NULL, method, 0 }); + mCallStack.enter({ nullptr, method, 0 }); break; } @@ -313,14 +313,14 @@ void Interpreter::stepBytecodeIn() { // Layout of OperandsStack: // .... // +1) length : to chech number of args - // +2) NULL : stop saving args + // +2) nullptr : stop saving args // +3) object1 // +4) object2 // ... tp::uint2 len = read_byte(bytecode); mOperandsStack.push((Object*) len); - mOperandsStack.push(NULL); + mOperandsStack.push(nullptr); break; } @@ -367,7 +367,7 @@ void Interpreter::stepBytecodeIn() { NDO_CASTV(MethodObject, obj, method); mScopeStack.enterScope(false); - mCallStack.enter({ NULL, method, 0 }); + mCallStack.enter({ nullptr, method, 0 }); // push self mCallStack.mStack.last().mSelf = mLastParent; @@ -376,7 +376,7 @@ void Interpreter::stepBytecodeIn() { (*mTypeMethod)(this); mIsTypeMethod = false; - mTypeMethod = NULL; + mTypeMethod = nullptr; break; } @@ -455,7 +455,7 @@ void Interpreter::stepBytecodeIn() { auto parent = mOperandsStack.getOperand(); bool is_method = read_byte(bytecode); - Object* child = NULL; + Object* child = nullptr; TypeMethods::LookupKey tm_key; if (is_method) { diff --git a/Objects/private/interpreter/OperandsStack.cpp b/Objects/private/interpreter/OperandsStack.cpp index d37fb20..b83b3c5 100644 --- a/Objects/private/interpreter/OperandsStack.cpp +++ b/Objects/private/interpreter/OperandsStack.cpp @@ -15,7 +15,7 @@ void OperandStack::push(Operand operand) { } void OperandStack::pop() { - ASSERT(mIdx != NULL && "stack overflow"); + ASSERT(mIdx != 0 && "stack overflow"); mIdx--; } diff --git a/Objects/private/interpreter/ScopeStack.cpp b/Objects/private/interpreter/ScopeStack.cpp index 3f9d9ed..74a926e 100644 --- a/Objects/private/interpreter/ScopeStack.cpp +++ b/Objects/private/interpreter/ScopeStack.cpp @@ -40,7 +40,7 @@ void ScopeStack::enterScope(bool aChildReachable) { } void ScopeStack::leaveScope() { - ASSERT(mIdx != NULL && "stack overflow"); + ASSERT(mIdx != 0 && "stack overflow"); mBuff[mIdx - 1].~Scope(); mIdx--; } diff --git a/Objects/private/parser/Parser.cpp b/Objects/private/parser/Parser.cpp index b5afd12..50dbbb4 100644 --- a/Objects/private/parser/Parser.cpp +++ b/Objects/private/parser/Parser.cpp @@ -31,7 +31,7 @@ Parser::Result Parser::parse(const std::string& stream) { bind(parser); std::string streamStd(stream.c_str()); - streamStd += "\n"; // for windows os to be happy + streamStd += "\n"; // for Windows os to be happy ASSERT(parser.valid()); diff --git a/Objects/private/primitives/DictObject.cpp b/Objects/private/primitives/DictObject.cpp index 22cf7b6..409ae2e 100644 --- a/Objects/private/primitives/DictObject.cpp +++ b/Objects/private/primitives/DictObject.cpp @@ -142,7 +142,7 @@ const tp::Map& DictObject::getItems() const { return items static auto tm_get = TypeMethod{ .nameid = "get", .descr = "gets the object", - .args = { { "str key", NULL } }, + .args = { { "str key", nullptr } }, .exec = [](const TypeMethod* tm) { auto const self = (DictObject*) tm->self; @@ -156,12 +156,12 @@ static auto tm_get = TypeMethod{ .nameid = "get", tm->ret.obj = self->getSlotVal(idx); } }, - .ret = { "object", NULL } }; + .ret = { "object", nullptr } }; static auto tm_put = TypeMethod{ .nameid = "put", .descr = "puts the object into the dictinary", - .args = { { "key", NULL }, { "object", NULL } }, + .args = { { "key", nullptr }, { "object", nullptr } }, .exec = [](const TypeMethod* tm) { auto const self = (DictObject*) tm->self; @@ -180,7 +180,7 @@ static auto tm_remove = TypeMethod{ .nameid = "remove", .descr = "remove the object from the dictinary", .args = { - { "key", NULL }, + { "key", nullptr }, }, .exec = [](const TypeMethod* tm) { auto const self = (DictObject*)tm->self; @@ -194,7 +194,7 @@ static auto tm_remove = TypeMethod{ }, }; -struct obj::ObjectType DictObject::TypeData = { .base = NULL, +struct obj::ObjectType DictObject::TypeData = { .base = nullptr, .constructor = DictObject::constructor, .destructor = DictObject::destructor, .copy = DictObject::copy, diff --git a/Objects/private/primitives/EnumObject.cpp b/Objects/private/primitives/EnumObject.cpp index e4dde7c..0074b8f 100644 --- a/Objects/private/primitives/EnumObject.cpp +++ b/Objects/private/primitives/EnumObject.cpp @@ -10,7 +10,7 @@ using namespace tp; void EnumObject::constructor(EnumObject* self) { self->active = 0; self->nentries = 0; - self->entries = NULL; + self->entries = nullptr; } void obj::EnumObject::destructor(EnumObject* self) { @@ -126,7 +126,7 @@ static void load(ArchiverIn& file_self, EnumObject* self) { file_self >> self->active; if (self->active == -1) { self->nentries = 0; - self->entries = NULL; + self->entries = nullptr; return; } file_self >> self->nentries; @@ -134,7 +134,7 @@ static void load(ArchiverIn& file_self, EnumObject* self) { file_self.readBytes((tp::int1*) self->entries, self->nentries * ENV_ALNI_SIZE_B); } -bool obj::EnumObject::compare(EnumObject* first, EnumObject* second) { return first->entries != NULL && second->entries != NULL && first->active == second->active; } +bool obj::EnumObject::compare(EnumObject* first, EnumObject* second) { return first->entries != nullptr && second->entries != nullptr && first->active == second->active; } EnumObject* obj::EnumObject::create(tp::InitialierList list) { auto enum_object = (EnumObject*) obj::NDO->create("enum"); @@ -160,7 +160,7 @@ struct ObjectTypeConversions EnumObjectTypeConversions = { }; struct obj::ObjectType obj::EnumObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = (object_constructor) EnumObject::constructor, .destructor = (object_destructor) EnumObject::destructor, .copy = (object_copy) EnumObject::copy, diff --git a/Objects/private/primitives/FloatObject.cpp b/Objects/private/primitives/FloatObject.cpp index 74d040c..4f9a331 100644 --- a/Objects/private/primitives/FloatObject.cpp +++ b/Objects/private/primitives/FloatObject.cpp @@ -57,9 +57,9 @@ struct ObjectTypeAriphmetics FloatObject::TypeAriphm = { }; struct obj::ObjectType obj::FloatObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = (object_constructor) FloatObject::constructor, - .destructor = NULL, + .destructor = nullptr, .copy = (object_copy) FloatObject::copy, .size = sizeof(FloatObject), .name = "float", diff --git a/Objects/private/primitives/IntObject.cpp b/Objects/private/primitives/IntObject.cpp index 40217b0..d27aa3f 100644 --- a/Objects/private/primitives/IntObject.cpp +++ b/Objects/private/primitives/IntObject.cpp @@ -58,9 +58,9 @@ struct ObjectTypeAriphmetics IntObject::TypeAriphm = { }; struct obj::ObjectType obj::IntObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = IntObject::constructor, - .destructor = NULL, + .destructor = nullptr, .copy = (object_copy) IntObject::copy, .size = sizeof(IntObject), .name = "int", diff --git a/Objects/private/primitives/LinkObject.cpp b/Objects/private/primitives/LinkObject.cpp index d01dc90..56a1ca1 100644 --- a/Objects/private/primitives/LinkObject.cpp +++ b/Objects/private/primitives/LinkObject.cpp @@ -20,7 +20,7 @@ LinkObject* LinkObject::create(Object* in) { alni LinkObject::save_size(LinkObject* self) { return sizeof(alni); } void LinkObject::save(LinkObject* self, ArchiverOut& file_self) { - if (self->link != NULL) { + if (self->link != nullptr) { alni link_object_save_adress = NDO->save(file_self, self->link); file_self << link_object_save_adress; } else { @@ -35,7 +35,7 @@ void LinkObject::load(ArchiverIn& file_self, LinkObject* self) { file_self >> saved_object_adress; if (saved_object_adress == -1) { - self->link = NULL; + self->link = nullptr; } else { self->link = NDO->load(file_self, saved_object_adress); NDO->refinc(self->link); @@ -66,7 +66,7 @@ void LinkObject::setLink(Object* obj) { link = obj; } -static auto tm_set = TypeMethod{ .nameid = "set", .descr = "sets the link", .args = { { "target", NULL } }, .exec = [](const TypeMethod* tm) { +static auto tm_set = TypeMethod{ .nameid = "set", .descr = "sets the link", .args = { { "target", nullptr } }, .exec = [](const TypeMethod* tm) { auto const self = (LinkObject*) tm->self; auto const target = tm->args[0].obj; self->setLink(target); @@ -82,15 +82,15 @@ static auto tm_get = TypeMethod{ .nameid = "get", tm->ret.obj = link; } }, - .ret = { "the link", NULL } }; + .ret = { "the link", nullptr } }; -struct obj::ObjectType LinkObject::TypeData = { .base = NULL, +struct obj::ObjectType LinkObject::TypeData = { .base = nullptr, .constructor = LinkObject::constructor, .destructor = (object_destructor) LinkObject::destructor, .copy = LinkObject::copy, .size = sizeof(LinkObject), .name = "link", - .convesions = NULL, + .convesions = nullptr, .save_size = (object_save_size) LinkObject::save_size, .save = (object_save) LinkObject::save, .load = (object_load) LinkObject::load, diff --git a/Objects/private/primitives/ListObject.cpp b/Objects/private/primitives/ListObject.cpp index 2ca192e..0d339e8 100644 --- a/Objects/private/primitives/ListObject.cpp +++ b/Objects/private/primitives/ListObject.cpp @@ -106,13 +106,13 @@ void ListObject::popBack() { const tp::List& ListObject::getItems() const { return items; } -struct obj::ObjectType obj::ListObject::TypeData = { .base = NULL, +struct obj::ObjectType obj::ListObject::TypeData = { .base = nullptr, .constructor = ListObject::constructor, .destructor = ListObject::destructor, .copy = ListObject::copy, .size = sizeof(ListObject), .name = "list", - .convesions = NULL, + .convesions = nullptr, .save_size = (object_save_size) save_size, .save = (object_save) save, .load = (object_load) load, diff --git a/Objects/private/primitives/MethodObject.cpp b/Objects/private/primitives/MethodObject.cpp index 7cce12e..671a1bb 100644 --- a/Objects/private/primitives/MethodObject.cpp +++ b/Objects/private/primitives/MethodObject.cpp @@ -6,13 +6,13 @@ using namespace obj; struct ObjectType MethodObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = (object_constructor) MethodObject::constructor, .destructor = (object_destructor) MethodObject::destructor, .copy = (object_copy) MethodObject::copy, .size = sizeof(MethodObject), .name = "method", - .convesions = NULL, + .convesions = nullptr, .save_size = (object_save_size) MethodObject::save_size, .save = (object_save) MethodObject::save, .load = (object_load) MethodObject::load, diff --git a/Objects/private/primitives/NullObject.cpp b/Objects/private/primitives/NullObject.cpp index 7864ce8..fd099f6 100644 --- a/Objects/private/primitives/NullObject.cpp +++ b/Objects/private/primitives/NullObject.cpp @@ -5,7 +5,7 @@ using namespace obj; using namespace tp; -obj::NullObject* obj::NdoNull_globalInstance = NULL; +obj::NullObject* obj::NdoNull_globalInstance = nullptr; bool uninit_flag = false; void NullObject::uninit() { @@ -16,7 +16,7 @@ void NullObject::uninit() { void NullObject::destructor(Object* self) { DEBUG_ASSERT(uninit_flag && "Only one the instance of NullObject exists and thus it can't be destroyed"); } -std::string to_string(NullObject* self) { return "NULL"; } +std::string to_string(NullObject* self) { return "nullptr"; } alni to_int(NullObject* self) { return 0; } @@ -29,19 +29,19 @@ obj::TypeMethods* tm_construct() { } struct ObjectTypeConversions NullObjectTypeConversions = { - .from_int = NULL, - .from_float = NULL, - .from_string = NULL, + .from_int = nullptr, + .from_float = nullptr, + .from_string = nullptr, .to_string = (object_to_string) to_string, .to_int = (object_to_int) to_int, .to_float = (object_to_float) to_float, }; struct ObjectType NullObject::TypeData = { - .base = NULL, - .constructor = NULL, + .base = nullptr, + .constructor = nullptr, .destructor = NullObject::destructor, - .copy = NULL, + .copy = nullptr, .size = sizeof(NullObject), .name = "null", .convesions = &NullObjectTypeConversions, diff --git a/Objects/private/primitives/Stringobject.cpp b/Objects/private/primitives/Stringobject.cpp index 09878fe..3cbda2d 100644 --- a/Objects/private/primitives/Stringobject.cpp +++ b/Objects/private/primitives/Stringobject.cpp @@ -64,7 +64,7 @@ struct ObjectTypeConversions StringObjectTypeConversions = { }; struct obj::ObjectType StringObject::TypeData = { - .base = NULL, + .base = nullptr, .constructor = StringObject::constructor, .destructor = (object_destructor) StringObject::destructor, .copy = StringObject::copy, diff --git a/Objects/private/primitives/TypeObject.cpp b/Objects/private/primitives/TypeObject.cpp index 5544983..98fced2 100644 --- a/Objects/private/primitives/TypeObject.cpp +++ b/Objects/private/primitives/TypeObject.cpp @@ -54,7 +54,7 @@ static struct ObjectTypeConversions conversions = { }; struct obj::ObjectType TypeObject::TypeData = { - .base = NULL, + .base = nullptr, //.constructor = (object_constructor) TypeObject::constructor, .size = sizeof(TypeObject), .name = "typeobject",