Skip to content

Commit

Permalink
Refactor|libdeng2|Script: Added DeleteStatement
Browse files Browse the repository at this point in the history
Deleting is now a proper statement, which matches the semantics of
the script language.

This forces records to observe their members for deletion.
  • Loading branch information
skyjake committed Dec 3, 2012
1 parent 390525b commit ea21e6e
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 98 deletions.
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/DeleteStatement
@@ -0,0 +1 @@
#include "scriptsys/deletestatement.h"
8 changes: 6 additions & 2 deletions doomsday/libdeng2/include/de/data/record.h
Expand Up @@ -46,7 +46,8 @@ namespace de
*
* @ingroup data
*/
class DENG2_PUBLIC Record : public ISerializable, public LogEntry::Arg::Base
class DENG2_PUBLIC Record : public ISerializable, public LogEntry::Arg::Base,
DENG2_OBSERVES(Variable, Deletion)
{
public:
/// Unknown variable name was given. @ingroup errors
Expand Down Expand Up @@ -298,7 +299,10 @@ namespace de
// Implements LogEntry::Arg::Base.
LogEntry::Arg::Type logEntryArgType() const { return LogEntry::Arg::STRING; }
String asText() const { return asText("", 0); }


// Observes Variable deletion.
void variableBeingDeleted(Variable &variable);

private:
struct Instance;
Instance * d;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libdeng2/include/de/data/recordvalue.h
Expand Up @@ -98,6 +98,7 @@ class DENG2_PUBLIC RecordValue : public Value, DENG2_OBSERVES(Record, Deletion)
Value *duplicate() const;
Text asText() const;
dsize size() const;
void setElement(Value const &index, Value *elementValue);
Value *duplicateElement(Value const &value) const;
bool contains(Value const &value) const;
bool isTrue() const;
Expand All @@ -113,7 +114,7 @@ class DENG2_PUBLIC RecordValue : public Value, DENG2_OBSERVES(Record, Deletion)
public:
Record *_record;
OwnershipFlags _ownership;
OwnershipFlags _oldOwnership;
OwnershipFlags _oldOwnership; // prior to serialization
};

Q_DECLARE_OPERATORS_FOR_FLAGS(RecordValue::OwnershipFlags)
Expand Down
66 changes: 66 additions & 0 deletions doomsday/libdeng2/include/de/scriptsys/deletestatement.h
@@ -0,0 +1,66 @@
/*
* The Doomsday Engine Project -- libdeng2
*
* Copyright (c) 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* 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 2 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://www.gnu.org/licenses/>.
*/

#ifndef LIBDENG2_DELETESTATEMENT_H
#define LIBDENG2_DELETESTATEMENT_H

#include "../libdeng2.h"
#include "../Statement"
#include "../ArrayExpression"
#include <string>
#include <vector>

namespace de
{
/**
* Deletes variables.
*
* @ingroup script
*/
class DeleteStatement : public Statement
{
public:
/// Trying to delete something other than a reference (RefValue). @ingroup errors
DENG2_ERROR(LeftValueError);

public:
DeleteStatement();

/**
* Constructor.
*
* @param targets Expression that resolves to a reference (array of RefValues).
* Statement gets ownership.
*/
DeleteStatement(ArrayExpression *targets);

~DeleteStatement();

void execute(Context &context) const;

// Implements ISerializable.
void operator >> (Writer &to) const;
void operator << (Reader &from);

private:
ArrayExpression *_targets;
};
}

#endif /* LIBDENG2_DELETESTATEMENT_H */
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/scriptsys/expression.h
Expand Up @@ -62,7 +62,7 @@ namespace de
NewSubrecord = 0x8,

/// Identifier must exist and will be deleted.
Delete = 0x10,
//Delete = 0x10,

/// Imports an external namespace into the local namespace (as a reference).
Import = 0x20,
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libdeng2/include/de/scriptsys/parser.h
Expand Up @@ -39,6 +39,7 @@ namespace de
class WhileStatement;
class ForStatement;
class AssignStatement;
class DeleteStatement;
class FunctionStatement;
class ArrayExpression;
class DictionaryExpression;
Expand Down Expand Up @@ -101,7 +102,7 @@ namespace de

ExpressionStatement *parseDeclarationStatement();

ExpressionStatement *parseDeleteStatement();
DeleteStatement *parseDeleteStatement();

FunctionStatement *parseFunctionStatement();

Expand Down
3 changes: 2 additions & 1 deletion doomsday/libdeng2/include/de/scriptsys/statement.h
Expand Up @@ -71,7 +71,8 @@ namespace de
IF,
PRINT,
TRY,
WHILE
WHILE,
DELETE
};

private:
Expand Down
3 changes: 3 additions & 0 deletions doomsday/libdeng2/scriptsys.pri
Expand Up @@ -6,6 +6,7 @@ HEADERS += \
include/de/Compound \
include/de/ConstantExpression \
include/de/Context \
include/de/DeleteStatement \
include/de/DictionaryExpression \
include/de/Evaluator \
include/de/Expression \
Expand Down Expand Up @@ -41,6 +42,7 @@ HEADERS += \
include/de/scriptsys/compound.h \
include/de/scriptsys/constantexpression.h \
include/de/scriptsys/context.h \
include/de/scriptsys/deletestatement.h \
include/de/scriptsys/dictionaryexpression.h \
include/de/scriptsys/evaluator.h \
include/de/scriptsys/expression.h \
Expand Down Expand Up @@ -76,6 +78,7 @@ SOURCES += \
src/scriptsys/compound.cpp \
src/scriptsys/constantexpression.cpp \
src/scriptsys/context.cpp \
src/scriptsys/deletestatement.cpp \
src/scriptsys/dictionaryexpression.cpp \
src/scriptsys/evaluator.cpp \
src/scriptsys/expression.cpp \
Expand Down

0 comments on commit ea21e6e

Please sign in to comment.