scummvm/engines/private/symbol.cpp

166 lines
4.6 KiB
C++
Raw Normal View History

2021-02-13 17:55:30 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "private/grammar.h"
2021-02-16 20:51:09 +00:00
#include "private/private.h"
#include "private/tokens.h"
2020-12-30 22:33:25 +00:00
namespace Private {
2021-01-01 15:22:05 +00:00
SymbolMap settings, variables, cursors, locations, rects;
ConstantList constants;
2021-02-07 17:08:28 +00:00
NameList variableList;
NameList locationList;
2021-01-12 23:49:12 +00:00
StringQueue stringToDefine;
RectQueue rectToDefine;
2021-01-01 15:22:05 +00:00
2021-01-10 23:44:27 +00:00
void defineSymbol(char *n, Common::Rect *r) {
Common::String *s = new Common::String(n);
stringToDefine.push(*s);
rectToDefine.push(r);
2021-01-01 15:22:05 +00:00
}
2021-01-10 23:44:27 +00:00
void showSymbol(Symbol *s) {
if (s->type == NUM)
2021-02-14 16:31:22 +00:00
debugC(1, kPrivateDebugCode, "%s %d",s->name->c_str(), s->u.val);
else if (s->type == STRING)
2021-02-14 16:31:22 +00:00
debugC(1, kPrivateDebugCode, "%s %s", s->name->c_str(), s->u.str);
else if (s->type == NAME)
2021-02-14 16:31:22 +00:00
debugC(1, kPrivateDebugCode, "%s %d",s->name->c_str(), s->type);
else
2021-02-14 16:31:22 +00:00
debugC(1, kPrivateDebugCode, "%s %d", s->name->c_str(), s->type);
}
2021-01-10 18:38:10 +00:00
void setSymbol(Symbol *s, int v) {
s->u.val = v;
}
2021-01-10 23:44:27 +00:00
/* find s in symbol table symlist */
2021-02-13 21:44:23 +00:00
Symbol *lookup(Common::String s, SymbolMap symlist) {
2021-01-09 19:11:30 +00:00
Symbol *r = symlist.getVal(s);
return r;
2021-01-02 03:58:58 +00:00
}
2021-01-10 23:44:27 +00:00
/* lookup some name in some symbol table */
Symbol *lookupName(char *n) {
//debug("looking up %s", n);
Common::String *s = new Common::String(n);
2021-01-02 03:58:58 +00:00
if (settings.contains(*s))
return lookup(*s, settings);
2021-01-02 03:58:58 +00:00
else if (variables.contains(*s))
return lookup(*s, variables);
2021-01-02 03:58:58 +00:00
else if (cursors.contains(*s))
return lookup(*s, cursors);
2021-01-02 03:58:58 +00:00
else if (locations.contains(*s))
return lookup(*s, locations);
2021-01-02 03:58:58 +00:00
else if (rects.contains(*s))
return lookup(*s, rects);
else {
2021-02-14 16:31:22 +00:00
debugC(1, kPrivateDebugCode, "WARNING: %s not defined", s->c_str());
return constant(STRING, 0, (char *)s->c_str());
}
2021-01-01 15:22:05 +00:00
}
2021-01-10 23:44:27 +00:00
void installAll(char *n) {
Common::String *s;
Common::Rect *r;
assert(stringToDefine.size() > 0);
while (!stringToDefine.empty()) {
s = new Common::String(stringToDefine.pop());
r = rectToDefine.pop();
//debug("name %s", s->c_str());
if (strcmp(n, "settings") == 0) {
assert(r == NULL);
install(s, STRING, 0, (char *)s->c_str(), r, &settings);
2021-02-16 11:19:12 +00:00
} else if (strcmp(n, "variables") == 0) {
assert(r == NULL);
install(s, NAME, 0, NULL, r, &variables);
2021-01-12 23:49:12 +00:00
variableList.push_front(*s);
2021-02-16 11:19:12 +00:00
} else if (strcmp(n, "cursors") == 0) {
assert(r == NULL);
install(s, NAME, 0, NULL, r, &cursors);
2021-02-16 11:19:12 +00:00
} else if (strcmp(n, "locations") == 0) {
assert(r == NULL);
install(s, NAME, 0, NULL, r, &locations);
2021-02-07 17:08:28 +00:00
locationList.push_front(*s);
2021-02-16 11:19:12 +00:00
} else if (strcmp(n, "rects") == 0) {
assert(r != NULL);
2021-01-09 19:11:30 +00:00
install(s, RECT, 0, NULL, r, &rects);
2021-02-16 11:19:12 +00:00
} else
error("invalid symbol type");
}
2021-01-01 15:22:05 +00:00
}
2021-01-10 23:44:27 +00:00
Symbol *constant(int t, int d, char *s) {
Symbol *sp;
Common::String *n = new Common::String("<constant>");
2021-02-13 21:13:40 +00:00
sp = (Symbol *)malloc(sizeof(Symbol));
sp->name = n;
sp->type = t;
if (t == NUM || t == NAME)
sp->u.val = d;
else if (t == STRING)
sp->u.str = s;
else
assert(0);
constants.push_front(sp);
return sp;
}
2021-01-10 23:44:27 +00:00
/* install some symbol s in a symbol table */
Symbol *install(Common::String *n, int t, int d, char *s, Common::Rect *r, SymbolMap *symlist) {
Common::String *name = new Common::String(*n);
Symbol *sp;
2021-02-13 21:13:40 +00:00
sp = (Symbol *)malloc(sizeof(Symbol));
sp->name = name;
sp->type = t;
if (t == NUM || t == NAME)
sp->u.val = d;
else if (t == STRING)
sp->u.str = s;
else if (t == RECT)
sp->u.rect = r;
else
assert(0);
symlist->setVal(*n, sp);
assert(symlist->size() > 0);
return sp;
}
2020-12-30 22:33:25 +00:00
2021-02-13 21:27:24 +00:00
} // End of namespace Private