From 296dac6bc278400e3d17b4596de8e10f515c07f1 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 8 Feb 2017 11:03:42 +0100 Subject: DIRECTOR: Lingo: Switched Symbol::name to Common::String --- engines/director/lingo/lingo-builtins.cpp | 3 +-- engines/director/lingo/lingo-code.cpp | 10 +++++----- engines/director/lingo/lingo-codegen.cpp | 10 +++------- engines/director/lingo/lingo.cpp | 3 +-- engines/director/lingo/lingo.h | 2 +- 5 files changed, 11 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp index 40a6e917ca..2005aa11a2 100644 --- a/engines/director/lingo/lingo-builtins.cpp +++ b/engines/director/lingo/lingo-builtins.cpp @@ -254,8 +254,7 @@ void Lingo::initBuiltIns() { for (BuiltinProto *blt = builtins; blt->name; blt++) { Symbol *sym = new Symbol; - sym->name = (char *)calloc(strlen(blt->name) + 1, 1); - Common::strlcpy(sym->name, blt->name, strlen(blt->name)); + sym->name = blt->name; sym->type = BLTIN; sym->nargs = blt->minArgs; sym->maxArgs = blt->maxArgs; diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index 7046fed979..9e737176a8 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -170,8 +170,8 @@ void Lingo::c_printtop(void) { if (!d.u.sym) { warning("Inconsistent stack: var, val: %d", d.u.i); } else { - if (d.u.sym->name) - warning("var: %s", d.u.sym->name); + if (!d.u.sym->name.empty()) + warning("var: %s", d.u.sym->name.c_str()); else warning("Nameless var. val: %d", d.u.sym->u.i); } @@ -305,7 +305,7 @@ void Lingo::c_assign() { if (d1.u.sym->type != INT && d1.u.sym->type != VOID && d1.u.sym->type != FLOAT && d1.u.sym->type != STRING) { - warning("assignment to non-variable '%s'", d1.u.sym->name); + warning("assignment to non-variable '%s'", d1.u.sym->name.c_str()); return; } @@ -341,13 +341,13 @@ void Lingo::c_assign() { bool Lingo::verify(Symbol *s) { if (s->type != INT && s->type != VOID && s->type != FLOAT && s->type != STRING && s->type != POINT) { - warning("attempt to evaluate non-variable '%s'", s->name); + warning("attempt to evaluate non-variable '%s'", s->name.c_str()); return false; } if (s->type == VOID) - warning("Variable used before assigning a value '%s'", s->name); + warning("Variable used before assigning a value '%s'", s->name.c_str()); return true; } diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp index 32d0bbbc11..dccb95e0c1 100644 --- a/engines/director/lingo/lingo-codegen.cpp +++ b/engines/director/lingo/lingo-codegen.cpp @@ -170,8 +170,7 @@ Symbol *Lingo::lookupVar(const char *name, bool create, bool putInGlobalList) { return NULL; sym = new Symbol; - sym->name = (char *)calloc(strlen(name) + 1, 1); - Common::strlcpy(sym->name, name, strlen(name) + 1); + sym->name = name; sym->type = VOID; sym->u.i = 0; @@ -198,7 +197,6 @@ void Lingo::cleanLocalVars() { for (SymbolHash::const_iterator h = _localvars->begin(); h != _localvars->end(); ++h) { if (!h->_value->global) { Symbol *sym = h->_value; - free(sym->name); delete sym; } } @@ -218,8 +216,7 @@ void Lingo::define(Common::String &name, int start, int nargs, Common::String *p if (sym == NULL) { // Create variable if it was not defined sym = new Symbol; - sym->name = (char *)calloc(name.size() + 1, 1); - Common::strlcpy(sym->name, name.c_str(), name.size() + 1); + sym->name = name; sym->type = HANDLER; _handlers[ENTITY_INDEX(_eventHandlerTypeIds[name.c_str()], _currentEntityId)] = sym; @@ -388,8 +385,7 @@ void Lingo::codeFactory(Common::String &name) { Symbol *sym = new Symbol; - sym->name = (char *)calloc(name.size() + 1, 1); - Common::strlcpy(sym->name, name.c_str(), name.size()); + sym->name = name; sym->type = BLTIN; sym->nargs = -1; sym->maxArgs = 0; diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index f7eafda11b..9a92d2f2ac 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -75,7 +75,6 @@ struct EventHandlerType { }; Symbol::Symbol() { - name = NULL; type = VOID; u.s = NULL; nargs = 0; @@ -395,7 +394,7 @@ Common::String *Datum::toString() { *s = "#void"; break; case VAR: - *s = Common::String::format("var: #%s", u.sym->name); + *s = Common::String::format("var: #%s", u.sym->name.c_str()); break; default: warning("Incorrect operation toString() for type: %s", type2str()); diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index afadef7a90..66f3d3a3d3 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -104,7 +104,7 @@ struct Pointer_Hash { typedef Common::HashMap FuncHash; struct Symbol { /* symbol table entry */ - char *name; + Common::String name; int type; union { int i; /* VAR */ -- cgit v1.2.3