Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 31, 2017
1 parent 08e8463 commit 6eabdca
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 103 deletions.
31 changes: 15 additions & 16 deletions doomsday/sdk/libcore/include/de/scriptsys/statement.h
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_STATEMENT_H
Expand Down Expand Up @@ -59,21 +59,20 @@ class Statement : public ISerializable
static Statement *constructFrom(Reader &from);

protected:
typedef dbyte SerialId;

enum SerialIds {
ASSIGN,
CATCH,
EXPRESSION,
FLOW,
FOR,
FUNCTION,
IF,
PRINT,
TRY,
WHILE,
DELETE,
SCOPE
enum class SerialId : dbyte
{
Assign,
Catch,
Expression,
Flow,
For,
Function,
If,
Print,
Try,
While,
Delete,
Scope,
};

private:
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libcore/src/scriptsys/assignstatement.cpp
Expand Up @@ -104,14 +104,14 @@ void AssignStatement::execute(Context &context) const

void AssignStatement::operator >> (Writer &to) const
{
to << SerialId(ASSIGN) << duint8(_indexCount) << _args;
to << dbyte(SerialId::Assign) << duint8(_indexCount) << _args;
}

void AssignStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != ASSIGN)
from.readAs<dbyte>(id);
if (id != SerialId::Assign)
{
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
Expand Down
16 changes: 8 additions & 8 deletions doomsday/sdk/libcore/src/scriptsys/catchstatement.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/CatchStatement"
Expand Down Expand Up @@ -57,10 +57,10 @@ bool CatchStatement::matches(Error const &err) const
// Not specified, so catches all.
return true;
}

NameExpression const *name = dynamic_cast<NameExpression const *>(&_args->at(0));
DENG2_ASSERT(name != NULL);

return (name->identifier() == "Error" || // Generic catch-all.
name->identifier() == err.name() || // Exact match.
String(err.name()).endsWith("_" + name->identifier())); // Sub-error match.
Expand All @@ -74,23 +74,23 @@ void CatchStatement::executeCatch(Context &context, Error const &err) const
RefValue &ref = context.evaluator().evaluateTo<RefValue>(&_args->at(1));
ref.assign(new TextValue(err.asText()));
}

// Begin the catch compound.
context.start(_compound.firstStatement(), next());
}

void CatchStatement::operator >> (Writer &to) const
{
to << SerialId(CATCH) << duint8(flags) << *_args << _compound;
to << dbyte(SerialId::Catch) << duint8(flags) << *_args << _compound;
}

void CatchStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != CATCH)
from.readAs<dbyte>(id);
if (id != SerialId::Catch)
{
/// @throw DeserializationError The identifier that species the type of the
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
throw DeserializationError("CatchStatement::operator <<", "Invalid ID");
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/sdk/libcore/src/scriptsys/deletestatement.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/DeleteStatement"
Expand Down Expand Up @@ -60,16 +60,16 @@ void DeleteStatement::execute(Context &context) const

void DeleteStatement::operator >> (Writer &to) const
{
to << SerialId(DELETE) << *_targets;
to << dbyte(SerialId::Delete) << *_targets;
}

void DeleteStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != DELETE)
from.readAs<dbyte>(id);
if (id != SerialId::Delete)
{
/// @throw DeserializationError The identifier that species the type of the
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
throw DeserializationError("DeleteStatement::operator <<", "Invalid ID");
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/sdk/libcore/src/scriptsys/expressionstatement.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/ExpressionStatement"
Expand Down Expand Up @@ -43,16 +43,16 @@ void ExpressionStatement::execute(Context &context) const

void ExpressionStatement::operator >> (Writer &to) const
{
to << SerialId(EXPRESSION) << *_expression;
to << dbyte(SerialId::Expression) << *_expression;
}

void ExpressionStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != EXPRESSION)
from.readAs<dbyte>(id);
if (id != SerialId::Expression)
{
/// @throw DeserializationError The identifier that species the type of the
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
throw DeserializationError("ExpressionStatement::operator <<", "Invalid ID");
}
Expand Down
38 changes: 19 additions & 19 deletions doomsday/sdk/libcore/src/scriptsys/flowstatement.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/FlowStatement"
Expand All @@ -30,33 +30,33 @@ using namespace de;

#define HAS_ARG 0x80
#define TYPE_MASK 0x7f

FlowStatement::FlowStatement() : _type(PASS), _arg(0)
{}
FlowStatement::FlowStatement(Type type, Expression *countArgument)
: _type(type), _arg(countArgument)

FlowStatement::FlowStatement(Type type, Expression *countArgument)
: _type(type), _arg(countArgument)
{}

FlowStatement::~FlowStatement()
{
delete _arg;
}

void FlowStatement::execute(Context &context) const
{
Evaluator &eval = context.evaluator();

switch (_type)
{
case PASS:
context.proceed();
break;

case CONTINUE:
context.jumpContinue();
break;

case BREAK:
if (_arg)
{
Expand All @@ -65,9 +65,9 @@ void FlowStatement::execute(Context &context) const
else
{
context.jumpBreak();
}
}
break;

case RETURN:
if (_arg)
{
Expand All @@ -79,23 +79,23 @@ void FlowStatement::execute(Context &context) const
context.process().finish();
}
break;

case THROW:
if (_arg)
{
throw Error("thrown in script", eval.evaluate(_arg).asText());
}
}
else
{
/// @todo Rethrow the current error.
context.proceed();
}
}
}
}

void FlowStatement::operator >> (Writer &to) const
{
to << SerialId(FLOW);
to << dbyte(SerialId::Flow);
duint8 header = duint8(_type);
if (_arg)
{
Expand All @@ -111,10 +111,10 @@ void FlowStatement::operator >> (Writer &to) const
void FlowStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != FLOW)
from.readAs<dbyte>(id);
if (id != SerialId::Flow)
{
/// @throw DeserializationError The identifier that species the type of the
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
throw DeserializationError("FlowStatement::operator <<", "Invalid ID");
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libcore/src/scriptsys/forstatement.cpp
Expand Up @@ -69,14 +69,14 @@ void ForStatement::execute(Context &context) const

void ForStatement::operator >> (Writer &to) const
{
to << SerialId(FOR) << *_iterator << *_iteration << _compound;
to << dbyte(SerialId::For) << *_iterator << *_iteration << _compound;
}

void ForStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != FOR)
from.readAs<dbyte>(id);
if (id != SerialId::For)
{
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/sdk/libcore/src/scriptsys/functionstatement.cpp
Expand Up @@ -85,14 +85,14 @@ void FunctionStatement::execute(Context &context) const

void FunctionStatement::operator >> (Writer &to) const
{
to << SerialId(FUNCTION) << *_identifier << *_function << _defaults;
to << dbyte(SerialId::Function) << *_identifier << *_function << _defaults;
}

void FunctionStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != FUNCTION)
from.readAs<dbyte>(id);
if (id != SerialId::Function)
{
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
Expand Down
16 changes: 8 additions & 8 deletions doomsday/sdk/libcore/src/scriptsys/ifstatement.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/IfStatement"
Expand Down Expand Up @@ -80,8 +80,8 @@ void IfStatement::execute(Context &context) const

void IfStatement::operator >> (Writer &to) const
{
to << SerialId(IF);
to << dbyte(SerialId::If);

// Branches.
to << duint16(_branches.size());
for (Branches::const_iterator i = _branches.begin(); i != _branches.end(); ++i)
Expand All @@ -96,15 +96,15 @@ void IfStatement::operator >> (Writer &to) const
void IfStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != IF)
from.readAs<dbyte>(id);
if (id != SerialId::If)
{
/// @throw DeserializationError The identifier that species the type of the
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
throw DeserializationError("IfStatement::operator <<", "Invalid ID");
}
clear();

// Branches.
duint16 count;
from >> count;
Expand All @@ -114,6 +114,6 @@ void IfStatement::operator << (Reader &from)
setBranchCondition(Expression::constructFrom(from));
from >> branchCompound();
}

from >> _elseCompound;
}
10 changes: 5 additions & 5 deletions doomsday/sdk/libcore/src/scriptsys/printstatement.cpp
Expand Up @@ -62,22 +62,22 @@ void PrintStatement::execute(Context &context) const
}
os << (*i)->asText();
}

LOG_SCR_MSG(_E(m)) << msg;

context.proceed();
}

void PrintStatement::operator >> (Writer &to) const
{
to << SerialId(PRINT) << *_arg;
to << dbyte(SerialId::Print) << *_arg;
}

void PrintStatement::operator << (Reader &from)
{
SerialId id;
from >> id;
if (id != PRINT)
from.readAs<dbyte>(id);
if (id != SerialId::Print)
{
/// @throw DeserializationError The identifier that species the type of the
/// serialized statement was invalid.
Expand Down

0 comments on commit 6eabdca

Please sign in to comment.