aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2019-11-02 22:15:57 -0700
committerPaul Gilbert2019-11-11 18:20:30 -0800
commit53fd662ac0bfc0263409290116ad3f76dfee33ac (patch)
tree0124e49da27967bef16c45a41ff7575fb4ebd21c /engines
parentc570d6f4b29e62f6177bf3c046d0e5761c57b5cc (diff)
downloadscummvm-rg350-53fd662ac0bfc0263409290116ad3f76dfee33ac.tar.gz
scummvm-rg350-53fd662ac0bfc0263409290116ad3f76dfee33ac.tar.bz2
scummvm-rg350-53fd662ac0bfc0263409290116ad3f76dfee33ac.zip
GLK: ARCHETYPE: Change to use C++ new/delete
Diffstat (limited to 'engines')
-rw-r--r--engines/glk/archetype/archetype.cpp10
-rw-r--r--engines/glk/archetype/expression.h8
-rw-r--r--engines/glk/archetype/id_table.h3
-rw-r--r--engines/glk/archetype/interpreter.cpp2
-rw-r--r--engines/glk/archetype/keywords.cpp2
-rw-r--r--engines/glk/archetype/linked_list.cpp4
-rw-r--r--engines/glk/archetype/linked_list.h2
-rw-r--r--engines/glk/archetype/parser.cpp8
-rw-r--r--engines/glk/archetype/saveload.cpp20
-rw-r--r--engines/glk/archetype/saveload.h3
-rw-r--r--engines/glk/archetype/semantic.cpp6
-rw-r--r--engines/glk/archetype/statement.h4
-rw-r--r--engines/glk/archetype/sys_object.cpp2
13 files changed, 47 insertions, 27 deletions
diff --git a/engines/glk/archetype/archetype.cpp b/engines/glk/archetype/archetype.cpp
index 4f388da521..e7e8da210d 100644
--- a/engines/glk/archetype/archetype.cpp
+++ b/engines/glk/archetype/archetype.cpp
@@ -247,9 +247,9 @@ void Archetype::lookup(int the_obj, int the_attr, ResultType &result, ContextTyp
} else {
// inherited - must create new node }
result._kind = ATTR_PTR;
- result._data._attr.acl_attr = (NodePtr)malloc(sizeof(NodeType));
+ result._data._attr.acl_attr = new NodeType();
- e = (ExprTree)malloc(sizeof(ExprNode));
+ e = new ExprNode();
undefine(*e);
eval_expr((ExprPtr)np->data, *e, c, RVALUE);
@@ -491,7 +491,7 @@ void Archetype::eval_expr(ExprTree the_expr, ResultType &result, ContextType &co
return;
// Do the two operations using a dummy expression node
- e = (ExprTree)malloc(sizeof(ExprNode));
+ e = new ExprNode();
*e = *the_expr;
switch (the_expr->_data._oper.op_name) {
@@ -519,7 +519,7 @@ void Archetype::eval_expr(ExprTree the_expr, ResultType &result, ContextType &co
e->_data._oper.right = &r1;
eval_expr(e, result, context, desired);
- free(e);
+ delete e;
break;
case OP_CHS:
@@ -906,7 +906,7 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType
}
else {
// do it for real
- the_object = (ObjectPtr)malloc(sizeof(ObjectType));
+ the_object = new ObjectType();
the_object->inherited_from = the_stmt->_data._create.archetype;
new_list(the_object->attributes);
new_list(the_object->methods);
diff --git a/engines/glk/archetype/expression.h b/engines/glk/archetype/expression.h
index 6ccc0b019a..90b1dab2f0 100644
--- a/engines/glk/archetype/expression.h
+++ b/engines/glk/archetype/expression.h
@@ -33,9 +33,11 @@ namespace Archetype {
const int OP_LPAREN = NUM_OPERS + 1; // book-keeping operator
const int OP_SEND_TO_TYPE = NUM_OPERS + 2; // for use with interpreter
+struct ExprNode;
+
struct OperNode {
int8 op_name;
- struct ExprNode *left, *right;
+ ExprNode *left, *right;
};
struct MessageTextQuoteNode {
@@ -76,6 +78,10 @@ union ExprNodeData {
struct ExprNode {
AclType _kind;
ExprNodeData _data;
+
+ ExprNode() : _kind(RESERVED) {
+ _data._reserved.keyword = RW_UNDEFINED;
+ }
};
typedef ExprNode *ExprPtr;
diff --git a/engines/glk/archetype/id_table.h b/engines/glk/archetype/id_table.h
index 2aff6d6ce9..4202e390d7 100644
--- a/engines/glk/archetype/id_table.h
+++ b/engines/glk/archetype/id_table.h
@@ -49,6 +49,9 @@ struct IdRecType {
int id_index; // The ID's index in the ID table
StringPtr id_name;
IdRecType *next;
+
+ IdRecType() : id_kind(UNDEFINED_ID), id_integer(0), id_index(0),
+ id_name(nullptr), next(nullptr) {}
};
typedef IdRecType *IdRecPtr;
diff --git a/engines/glk/archetype/interpreter.cpp b/engines/glk/archetype/interpreter.cpp
index 3beca744a5..c88f584b3f 100644
--- a/engines/glk/archetype/interpreter.cpp
+++ b/engines/glk/archetype/interpreter.cpp
@@ -336,7 +336,7 @@ bool assignment(ResultType &target, ResultType &value) {
cleanup(*e);
} else {
dispose_expr(e);
- e = (ExprPtr)malloc(sizeof(ExprNode));
+ e = new ExprNode();
undefine(*e);
}
}
diff --git a/engines/glk/archetype/keywords.cpp b/engines/glk/archetype/keywords.cpp
index e3514c6720..97cac8457f 100644
--- a/engines/glk/archetype/keywords.cpp
+++ b/engines/glk/archetype/keywords.cpp
@@ -131,7 +131,7 @@ void dispose_text_list(XArrayType &the_list) {
for (uint i = 0; i < the_list.size(); ++i) {
if (index_xarray(the_list, i, p))
- free((StringPtr)p);
+ delete (StringPtr)p;
}
dispose_xarray(the_list);
diff --git a/engines/glk/archetype/linked_list.cpp b/engines/glk/archetype/linked_list.cpp
index bc4719ca48..eef55b4e01 100644
--- a/engines/glk/archetype/linked_list.cpp
+++ b/engines/glk/archetype/linked_list.cpp
@@ -27,7 +27,7 @@ namespace Glk {
namespace Archetype {
void new_list(ListType &the_list) {
- the_list = (ListType)malloc(sizeof(NodeType));
+ the_list = new NodeType();
add_bytes(sizeof(NodeType));
the_list->key = 0;
the_list->data = nullptr;
@@ -40,7 +40,7 @@ void dispose_list(ListType &the_list) {
axe = theNode;
theNode = theNode->next;
add_bytes(-(int)sizeof(*axe));
- free(axe);
+ delete axe;
}
}
diff --git a/engines/glk/archetype/linked_list.h b/engines/glk/archetype/linked_list.h
index 372de365b8..e0f4b08cd2 100644
--- a/engines/glk/archetype/linked_list.h
+++ b/engines/glk/archetype/linked_list.h
@@ -32,6 +32,8 @@ struct NodeType {
void *data;
int key;
NodeType *next;
+
+ NodeType() : data(nullptr), key(0), next(nullptr) {}
};
typedef NodeType *NodePtr;
diff --git a/engines/glk/archetype/parser.cpp b/engines/glk/archetype/parser.cpp
index 0063e2818c..8c1c47c6f5 100644
--- a/engines/glk/archetype/parser.cpp
+++ b/engines/glk/archetype/parser.cpp
@@ -32,6 +32,8 @@ const int WORD_LEN = 32;
struct ParseType {
StringPtr word;
int object;
+
+ ParseType() : word(nullptr), object(0) {}
};
typedef ParseType *ParsePtr;
@@ -103,7 +105,7 @@ void add_parse_word(TargetListType which_list, String &the_word, int the_object)
do {
bar = the_word.indexOf('|');
if (bar != -1) {
- pp = (ParsePtr)malloc(sizeof(ParseType));
+ pp = new ParseType();
tempstr = the_word.left(bar - 1).left(g_vm->Abbreviate);
pp->word = NewConstStr(tempstr);
@@ -111,7 +113,7 @@ void add_parse_word(TargetListType which_list, String &the_word, int the_object)
the_word = String(the_word.c_str() + bar + 1);
pp->object = the_object;
- np = (NodePtr)malloc(sizeof(NodeType));
+ np = new NodeType();
np->key = pp->word->size();
np->data = pp;
@@ -275,7 +277,7 @@ void clear_parse_list(ListType &the_list) {
while (iterate_list(the_list, np)) {
pp = (ParsePtr)np->data;
FreeConstStr(pp->word);
- free(pp);
+ delete pp;
}
dispose_list(the_list);
diff --git a/engines/glk/archetype/saveload.cpp b/engines/glk/archetype/saveload.cpp
index 2816a1f480..7c47d77b8d 100644
--- a/engines/glk/archetype/saveload.cpp
+++ b/engines/glk/archetype/saveload.cpp
@@ -105,7 +105,7 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType &elemen
switch (mission) {
case LOAD:
assert(readStream);
- np = (NodePtr)malloc(sizeof(NodeType));
+ np = new NodeType();
add_bytes(sizeof(NodeType));
np->key = readStream->readSint16LE();
break;
@@ -156,7 +156,7 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType &elemen
case CASE_LIST:
switch (mission) {
case LOAD:
- this_case = (CasePairPtr)malloc(sizeof(CasePairType));
+ this_case = new CasePairType();
add_bytes(sizeof(CasePairType));
walk_expr(mission, bfile, this_case->value);
walk_stmt(mission, bfile, this_case->action);
@@ -172,7 +172,7 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType &elemen
if (mission == FREE) {
add_bytes(sizeof(CasePairType));
- free(this_case);
+ delete this_case;
}
break;
@@ -258,7 +258,7 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_
switch (mission) {
case LOAD:
assert(readStream);
- the_expr = (ExprTree)malloc(sizeof(ExprNode));
+ the_expr = new ExprNode();
add_bytes(sizeof(ExprNode));
the_expr->_kind = (AclType)readStream->readByte();
break;
@@ -392,7 +392,7 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_
// Postlude
switch (mission) {
case FREE:
- free(the_expr);
+ delete the_expr;
the_expr = nullptr;
break;
default:
@@ -442,7 +442,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr &
if (sentinel == END_SEQ)
return;
- the_stmt = (StatementPtr)malloc(sizeof(StatementType));
+ the_stmt = new StatementType();
add_bytes(sizeof(StatementType));
the_stmt->_kind = sentinel;
break;
@@ -521,7 +521,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr &
while (sentinel != END_SEQ) {
walk_expr(mission, bfile, this_expr);
- np = (NodePtr)malloc(sizeof(NodeType));
+ np = new NodeType();
add_bytes(sizeof(NodeType));
np->data = this_expr;
@@ -563,7 +563,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr &
switch (mission) {
case FREE:
add_bytes(sizeof(StatementType));
- free(the_stmt);
+ delete the_stmt;
break;
default:
break;
@@ -576,7 +576,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr &
void load_object(Common::ReadStream *f_in, ObjectPtr &the_object) {
StatementKind sentinel;
- the_object = (ObjectPtr)malloc(sizeof(ObjectType));
+ the_object = new ObjectType();
add_bytes(sizeof(ObjectType));
the_object->inherited_from = f_in->readSint16LE();
@@ -610,7 +610,7 @@ void dispose_object(ObjectPtr &the_object) {
dispose_stmt(the_object->other);
add_bytes(sizeof(ObjectType));
- free(the_object);
+ delete the_object;
the_object = nullptr;
}
diff --git a/engines/glk/archetype/saveload.h b/engines/glk/archetype/saveload.h
index 0f98eb2d7a..55f1ca6326 100644
--- a/engines/glk/archetype/saveload.h
+++ b/engines/glk/archetype/saveload.h
@@ -43,6 +43,9 @@ struct ObjectType {
ListType attributes;
ListType methods;
StatementPtr other;
+
+ ObjectType() : inherited_from(0), attributes(nullptr), methods(nullptr),
+ other(nullptr) {}
};
typedef ObjectType *ObjectPtr;
diff --git a/engines/glk/archetype/semantic.cpp b/engines/glk/archetype/semantic.cpp
index 132f530dfb..9e0660faf8 100644
--- a/engines/glk/archetype/semantic.cpp
+++ b/engines/glk/archetype/semantic.cpp
@@ -128,9 +128,9 @@ void add_undefined(int the_ID) {
if (np != nullptr) {
++*((IntegerPtr)np->data);
} else {
- np = (NodePtr)malloc(sizeof(NodeType));
+ np = new NodeType();
np->key = the_ID;
- ip = (IntegerPtr)malloc(sizeof(int));
+ ip = new int();
*ip = 1; // TODO: Should this be 0-based?
np->data = ip;
insert_item(g_vm->Overlooked, np);
@@ -161,7 +161,7 @@ bool display_undefined() {
else
g_vm->writeln("<unknown identifier>");
- free(ip);
+ delete ip;
}
dispose_list(g_vm->Overlooked);
diff --git a/engines/glk/archetype/statement.h b/engines/glk/archetype/statement.h
index 62c2095797..14dff86c71 100644
--- a/engines/glk/archetype/statement.h
+++ b/engines/glk/archetype/statement.h
@@ -88,6 +88,10 @@ union StatementTypeData {
struct StatementType {
StatementKind _kind;
StatementTypeData _data;
+
+ StatementType() : _kind(COMPOUND) {
+ _data._compound.statements = nullptr;
+ }
};
struct CasePairType {
diff --git a/engines/glk/archetype/sys_object.cpp b/engines/glk/archetype/sys_object.cpp
index f4402fde59..ebbe88202c 100644
--- a/engines/glk/archetype/sys_object.cpp
+++ b/engines/glk/archetype/sys_object.cpp
@@ -203,7 +203,7 @@ void send_to_system(int transport, String &strmsg, ResultType &result, ContextTy
break;
case PRESENT:
- np = (NodePtr)malloc(sizeof(NodeType));
+ np = new NodeType();
np->data = nullptr;
np->key = the_caller;