[colobot] 84/377: Moving CBotParExpr class in its own header and source files.
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:01 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit 75f5126dddb81f6fba5c8ada95ade7bb12e80e9f
Author: Grunaka <dev at romainbreton.fr>
Date: Wed Nov 11 20:36:47 2015 +0100
Moving CBotParExpr class in its own header and source files.
---
src/CBot/CBot.cpp | 168 ------------------------------
src/CBot/CBot.h | 14 ---
src/CBot/CBotInstr/CBotExprUnaire.cpp | 1 +
src/CBot/CBotInstr/CBotParExpr.cpp | 188 ++++++++++++++++++++++++++++++++++
src/CBot/CBotInstr/CBotParExpr.h | 62 +++++++++++
src/CBot/CBotTwoOpExpr.cpp | 2 +
src/CBot/CMakeLists.txt | 1 +
7 files changed, 254 insertions(+), 182 deletions(-)
diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp
index de9f730..93642bc 100644
--- a/src/CBot/CBot.cpp
+++ b/src/CBot/CBot.cpp
@@ -1673,174 +1673,6 @@ CBotInstr* CBotBoolExpr::Compile(CBotToken* &p, CBotCStack* pStack)
return nullptr;
}
-//////////////////////////////////////////////////////////////////////////////////////////
-
-
-//////////////////////////////////////////////////////////////////////////////////////
-// compile either:
-// instruction in parentheses (...)
-// a unary expression (negative, not)
-// variable name
-// variables pre and post-incremented or decremented
-// a given number DefineNum
-// a constant
-// procedure call
-// new statement
-//
-// this class has no constructor, because there is never an instance of this class
-// the object returned by Compile is the class corresponding to the instruction
-
-
-CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
-{
- CBotCStack* pStk = pStack->TokenStack();
-
- pStk->SetStartError(p->GetStart());
-
- // is it an expression in parentheses?
- if (IsOfType(p, ID_OPENPAR))
- {
- CBotInstr* inst = CBotExpression::Compile(p, pStk);
-
- if (nullptr != inst)
- {
- if (IsOfType(p, ID_CLOSEPAR))
- {
- return pStack->Return(inst, pStk);
- }
- pStk->SetError(TX_CLOSEPAR, p->GetStart());
- }
- delete inst;
- return pStack->Return(nullptr, pStk);
- }
-
- // is this a unary operation?
- CBotInstr* inst = CBotExprUnaire::Compile(p, pStk);
- if (inst != nullptr || !pStk->IsOk())
- return pStack->Return(inst, pStk);
-
- // is it a variable name?
- if (p->GetType() == TokenTypVar)
- {
- // this may be a method call without the "this." before
- inst = CBotExprVar::CompileMethode(p, pStk);
- if (inst != nullptr) return pStack->Return(inst, pStk);
-
-
- // is it a procedure call?
- inst = CBotInstrCall::Compile(p, pStk);
- if (inst != nullptr || !pStk->IsOk())
- return pStack->Return(inst, pStk);
-
-
- CBotToken* pvar = p;
- // no, it an "ordinaty" variable
- inst = CBotExprVar::Compile(p, pStk);
-
- CBotToken* pp = p;
- // post incremented or decremented?
- if (IsOfType(p, ID_INC, ID_DEC))
- {
- if (pStk->GetType() >= CBotTypBoolean)
- {
- pStk->SetError(TX_BADTYPE, pp);
- delete inst;
- return pStack->Return(nullptr, pStk);
- }
-
- // recompile the variable for read-only
- delete inst;
- p = pvar;
- inst = CBotExprVar::Compile(p, pStk, PR_READ);
- p = p->GetNext();
-
- CBotPostIncExpr* i = new CBotPostIncExpr();
- i->SetToken(pp);
- i->m_Instr = inst; // associated statement
- return pStack->Return(i, pStk);
- }
- return pStack->Return(inst, pStk);
- }
-
- // pre increpemted or pre decremented?
- CBotToken* pp = p;
- if (IsOfType(p, ID_INC, ID_DEC))
- {
- CBotPreIncExpr* i = new CBotPreIncExpr();
- i->SetToken(pp);
-
- if (p->GetType() == TokenTypVar)
- {
- if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ)))
- {
- if (pStk->GetType() >= CBotTypBoolean)
- {
- pStk->SetError(TX_BADTYPE, pp);
- delete inst;
- return pStack->Return(nullptr, pStk);
- }
- return pStack->Return(i, pStk);
- }
- delete i;
- return pStack->Return(nullptr, pStk);
- }
- }
-
- // is it a number or DefineNum?
- if (p->GetType() == TokenTypNum ||
- p->GetType() == TokenTypDef )
- {
- CBotInstr* inst = CBotExprNum::Compile(p, pStk);
- return pStack->Return(inst, pStk);
- }
-
- // is this a chaine?
- if (p->GetType() == TokenTypString)
- {
- CBotInstr* inst = CBotExprAlpha::Compile(p, pStk);
- return pStack->Return(inst, pStk);
- }
-
- // is a "true" or "false"
- if (p->GetType() == ID_TRUE ||
- p->GetType() == ID_FALSE )
- {
- CBotInstr* inst = CBotExprBool::Compile(p, pStk);
- return pStack->Return(inst, pStk);
- }
-
- // is an object to be created with new
- if (p->GetType() == ID_NEW)
- {
- CBotInstr* inst = CBotNew::Compile(p, pStk);
- return pStack->Return(inst, pStk);
- }
-
- // is a null pointer
- if (IsOfType(p, ID_NULL))
- {
- CBotInstr* inst = new CBotExprNull ();
- inst->SetToken(pp);
- CBotVar* var = CBotVar::Create("", CBotTypNullPointer);
- pStk->SetVar(var);
- return pStack->Return(inst, pStk);
- }
-
- // is a number nan
- if (IsOfType(p, ID_NAN))
- {
- CBotInstr* inst = new CBotExprNan ();
- inst->SetToken(pp);
- CBotVar* var = CBotVar::Create("", CBotTypInt);
- var->SetInit(CBotVar::InitType::IS_NAN);
- pStk->SetVar(var);
- return pStack->Return(inst, pStk);
- }
-
-
- return pStack->Return(nullptr, pStk);
-}
-
//////////////////////////////////////////////////////////////////////////////////////
// index management for arrays
// array [ expression ]
diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h
index 6ae6885..7fc2a71 100644
--- a/src/CBot/CBot.h
+++ b/src/CBot/CBot.h
@@ -755,20 +755,6 @@ public:
CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
};
-
-
-// possibly an expression in parentheses ( ... )
-// there is never an instance of this class
-// being the object returned inside the parenthesis
-class CBotParExpr : public CBotInstr
-{
-private:
-
-public:
- static
- CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
-};
-
// all operations with two operands
class CBotTwoOpExpr : public CBotInstr
diff --git a/src/CBot/CBotInstr/CBotExprUnaire.cpp b/src/CBot/CBotInstr/CBotExprUnaire.cpp
index 1d63f1d..e1a18e7 100644
--- a/src/CBot/CBotInstr/CBotExprUnaire.cpp
+++ b/src/CBot/CBotInstr/CBotExprUnaire.cpp
@@ -19,6 +19,7 @@
// Modules inlcude
#include "CBotExprUnaire.h"
+#include "CBotParExpr.h"
// Local include
diff --git a/src/CBot/CBotInstr/CBotParExpr.cpp b/src/CBot/CBotInstr/CBotParExpr.cpp
new file mode 100644
index 0000000..1e9e53e
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotParExpr.cpp
@@ -0,0 +1,188 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsitec.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+// Modules inlcude
+#include "CBotParExpr.h"
+#include "CBotExprUnaire.h"
+#include "CBotExprVar.h"
+#include "CBotInstrCall.h"
+#include "CBotPostIncExpr.h"
+#include "CBotPreIncExpr.h"
+#include "CBotExprNum.h"
+#include "CBotExprAlpha.h"
+#include "CBotExprBool.h"
+#include "CBotNew.h"
+#include "CBotExprNull.h"
+#include "CBotExprNan.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+CBotInstr* CBotParExpr::Compile(CBotToken* &p, CBotCStack* pStack)
+{
+ CBotCStack* pStk = pStack->TokenStack();
+
+ pStk->SetStartError(p->GetStart());
+
+ // is it an expression in parentheses?
+ if (IsOfType(p, ID_OPENPAR))
+ {
+ CBotInstr* inst = CBotExpression::Compile(p, pStk);
+
+ if (nullptr != inst)
+ {
+ if (IsOfType(p, ID_CLOSEPAR))
+ {
+ return pStack->Return(inst, pStk);
+ }
+ pStk->SetError(TX_CLOSEPAR, p->GetStart());
+ }
+ delete inst;
+ return pStack->Return(nullptr, pStk);
+ }
+
+ // is this a unary operation?
+ CBotInstr* inst = CBotExprUnaire::Compile(p, pStk);
+ if (inst != nullptr || !pStk->IsOk())
+ return pStack->Return(inst, pStk);
+
+ // is it a variable name?
+ if (p->GetType() == TokenTypVar)
+ {
+ // this may be a method call without the "this." before
+ inst = CBotExprVar::CompileMethode(p, pStk);
+ if (inst != nullptr) return pStack->Return(inst, pStk);
+
+
+ // is it a procedure call?
+ inst = CBotInstrCall::Compile(p, pStk);
+ if (inst != nullptr || !pStk->IsOk())
+ return pStack->Return(inst, pStk);
+
+
+ CBotToken* pvar = p;
+ // no, it an "ordinaty" variable
+ inst = CBotExprVar::Compile(p, pStk);
+
+ CBotToken* pp = p;
+ // post incremented or decremented?
+ if (IsOfType(p, ID_INC, ID_DEC))
+ {
+ if (pStk->GetType() >= CBotTypBoolean)
+ {
+ pStk->SetError(TX_BADTYPE, pp);
+ delete inst;
+ return pStack->Return(nullptr, pStk);
+ }
+
+ // recompile the variable for read-only
+ delete inst;
+ p = pvar;
+ inst = CBotExprVar::Compile(p, pStk, PR_READ);
+ p = p->GetNext();
+
+ CBotPostIncExpr* i = new CBotPostIncExpr();
+ i->SetToken(pp);
+ i->m_Instr = inst; // associated statement
+ return pStack->Return(i, pStk);
+ }
+ return pStack->Return(inst, pStk);
+ }
+
+ // pre increpemted or pre decremented?
+ CBotToken* pp = p;
+ if (IsOfType(p, ID_INC, ID_DEC))
+ {
+ CBotPreIncExpr* i = new CBotPreIncExpr();
+ i->SetToken(pp);
+
+ if (p->GetType() == TokenTypVar)
+ {
+ if (nullptr != (i->m_Instr = CBotExprVar::Compile(p, pStk, PR_READ)))
+ {
+ if (pStk->GetType() >= CBotTypBoolean)
+ {
+ pStk->SetError(TX_BADTYPE, pp);
+ delete inst;
+ return pStack->Return(nullptr, pStk);
+ }
+ return pStack->Return(i, pStk);
+ }
+ delete i;
+ return pStack->Return(nullptr, pStk);
+ }
+ }
+
+ // is it a number or DefineNum?
+ if (p->GetType() == TokenTypNum ||
+ p->GetType() == TokenTypDef )
+ {
+ CBotInstr* inst = CBotExprNum::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is this a chaine?
+ if (p->GetType() == TokenTypString)
+ {
+ CBotInstr* inst = CBotExprAlpha::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is a "true" or "false"
+ if (p->GetType() == ID_TRUE ||
+ p->GetType() == ID_FALSE )
+ {
+ CBotInstr* inst = CBotExprBool::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is an object to be created with new
+ if (p->GetType() == ID_NEW)
+ {
+ CBotInstr* inst = CBotNew::Compile(p, pStk);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is a null pointer
+ if (IsOfType(p, ID_NULL))
+ {
+ CBotInstr* inst = new CBotExprNull ();
+ inst->SetToken(pp);
+ CBotVar* var = CBotVar::Create("", CBotTypNullPointer);
+ pStk->SetVar(var);
+ return pStack->Return(inst, pStk);
+ }
+
+ // is a number nan
+ if (IsOfType(p, ID_NAN))
+ {
+ CBotInstr* inst = new CBotExprNan ();
+ inst->SetToken(pp);
+ CBotVar* var = CBotVar::Create("", CBotTypInt);
+ var->SetInit(CBotVar::InitType::IS_NAN);
+ pStk->SetVar(var);
+ return pStack->Return(inst, pStk);
+ }
+
+
+ return pStack->Return(nullptr, pStk);
+}
diff --git a/src/CBot/CBotInstr/CBotParExpr.h b/src/CBot/CBotInstr/CBotParExpr.h
new file mode 100644
index 0000000..de0df45
--- /dev/null
+++ b/src/CBot/CBotInstr/CBotParExpr.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsitec.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+// Modules inlcude
+#include "CBot.h"
+
+// Local include
+
+// Global include
+
+
+////////////////////////////////////////////////////////////////////////////////
+// possibly an expression in parentheses ( ... )
+// there is never an instance of this class
+// being the object returned inside the parenthesis
+////////////////////////////////////////////////////////////////////////////////
+// compile either:
+// instruction in parentheses (...)
+// a unary expression (negative, not)
+// variable name
+// variables pre and post-incremented or decremented
+// a given number DefineNum
+// a constant
+// procedure call
+// new statement
+//
+// this class has no constructor, because there is never an instance of this class
+// the object returned by Compile is the class corresponding to the instruction
+////////////////////////////////////////////////////////////////////////////////
+
+/*!
+ * \brief The CBotParExpr class
+ */
+class CBotParExpr : public CBotInstr
+{
+public:
+ /*!
+ * \brief Compile
+ * \param p
+ * \param pStack
+ * \return
+ */
+ static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
+};
diff --git a/src/CBot/CBotTwoOpExpr.cpp b/src/CBot/CBotTwoOpExpr.cpp
index bc3ebdf..9f4cb2c 100644
--- a/src/CBot/CBotTwoOpExpr.cpp
+++ b/src/CBot/CBotTwoOpExpr.cpp
@@ -23,6 +23,8 @@
#include "CBot.h"
+#include "CBotInstr/CBotParExpr.h"
+
#include <cassert>
namespace
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 4cff8ef..dc6f746 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -34,6 +34,7 @@ set(SOURCES
CBotInstr/CBotListInstr.cpp
CBotInstr/CBotBlock.cpp
CBotInstr/CBotExprUnaire.cpp
+ CBotInstr/CBotParExpr.cpp
)
# Includes
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list