diff --git a/src/CBot/CBotClass.h b/src/CBot/CBotClass.h index 10bb83ca..68b61cc6 100644 --- a/src/CBot/CBotClass.h +++ b/src/CBot/CBotClass.h @@ -275,10 +275,15 @@ public: CBotCStack* pStack); /*! - * \brief Compile1 - * \param p - * \param pStack - * \return + * \brief Pre-compile a new class + * \param p[in, out] Pointer to first token of the class, will be updated to point to first token after the class definition + * \param pStack Compile stack + * + * This function is used to find the beginning and end of class definition. + * + * If any errors in the code are detected, this function will set the error on compile stack and return nullptr. + * + * \return Precompiled class, or nullptr in case of error */ static CBotClass* Compile1(CBotToken* &p, CBotCStack* pStack); diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h index 66637b51..bab5e2bb 100644 --- a/src/CBot/CBotInstr/CBotFunction.h +++ b/src/CBot/CBotInstr/CBotFunction.h @@ -60,11 +60,16 @@ public: bool bLocal = true); /*! - * \brief Compile1 Pre-compile a new function. - * \param p - * \param pStack - * \param pClass - * \return + * \brief Pre-compile a new function + * \param p[in, out] Pointer to first token of the function, will be updated to point to first token after the function definition + * \param pStack Compile stack + * \param pClass If this is a class method, pointer to class this function is part of, otherwise nullptr + * + * This function is used to find the beginning and end of function definition. + * + * If any errors in the code are detected, this function will set the error on compile stack and return nullptr. + * + * \return Precompiled function, or nullptr in case of error */ static CBotFunction* Compile1(CBotToken* &p, CBotCStack* pStack, diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp index fdb36eb8..dce62198 100644 --- a/src/CBot/CBotProgram.cpp +++ b/src/CBot/CBotProgram.cpp @@ -93,11 +93,15 @@ bool CBotProgram::Compile(const std::string& program, std::vector& if ( p->GetType() == ID_CLASS || ( p->GetType() == ID_PUBLIC && p->GetNext()->GetType() == ID_CLASS )) { - m_classes.push_back(CBotClass::Compile1(p, pStack.get())); + CBotClass* newclass = CBotClass::Compile1(p, pStack.get()); + if (newclass != nullptr) + m_classes.push_back(newclass); } else { - m_functions.push_back(CBotFunction::Compile1(p, pStack.get(), nullptr)); + CBotFunction* newfunc = CBotFunction::Compile1(p, pStack.get(), nullptr); + if (newfunc != nullptr) + m_functions.push_back(newfunc); } }