The 'Big Whine' patch:

Any use of a file from another package without a declared dependency will give a warning;

Also added some more _LOCALE_123_ macros so we need less format_string calls

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@753 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-09-24 20:24:22 +00:00
parent efcccb79c4
commit 36a36356c5
51 changed files with 246 additions and 132 deletions
+11 -8
View File
@@ -57,7 +57,7 @@ enum OpenBrace
/** Also stores errors found when tokenizing or parsing */
class TokenIterator {
public:
TokenIterator(const String& str, bool string_mode, vector<ScriptParseError>& errors);
TokenIterator(const String& str, Packaged* package, bool string_mode, vector<ScriptParseError>& errors);
/// Peek at the next token, doesn't move to the one after that
/** Can peek further forward by using higher values of offset.
@@ -75,6 +75,7 @@ class TokenIterator {
String input;
size_t pos;
String filename; ///< Filename of include files, "" for the main input
Packaged* package; ///< Package the input is from
vector<Token> buffer; ///< buffer of unread tokens, front() = current
stack<OpenBrace> open_braces; ///< braces/quotes we entered from script mode
bool newline; ///< Did we just pass a newline?
@@ -83,6 +84,7 @@ class TokenIterator {
String input;
size_t pos;
String filename;
Package* package;
};
stack<MoreInput> more; ///< Read tokens from here when we are done with the current input
@@ -115,9 +117,10 @@ bool isLongOper(const String& s) { return s==_(":=") || s==_("==") || s==_("!=")
// ----------------------------------------------------------------------------- : Tokenizing
TokenIterator::TokenIterator(const String& str, bool string_mode, vector<ScriptParseError>& errors)
TokenIterator::TokenIterator(const String& str, Packaged* package, bool string_mode, vector<ScriptParseError>& errors)
: input(str)
, pos(0)
, package(package)
, newline(false)
, errors(errors)
{
@@ -183,12 +186,12 @@ void TokenIterator::readToken() {
if (eol == String::npos) eol = input.size();
String include_file = trim(input.substr(pos, eol - pos));
// store the current input for later retrieval
MoreInput m = {input, eol, filename};
MoreInput m = {input, eol, filename, package};
more.push(m);
// read the entire file, and start at the beginning of it
pos = 0;
filename = include_file;
InputStreamP is = packages.openFileFromPackage(include_file);
InputStreamP is = packages.openFileFromPackage(package, include_file);
input = read_utf8_line(*is, true, true);
} else if (isAlpha(c) || c == _('_')) {
// name
@@ -345,10 +348,10 @@ void parseExpr(TokenIterator& input, Script& script, Precedence min_prec);
void parseOper(TokenIterator& input, Script& script, Precedence min_prec, InstructionType close_with = I_NOP, int close_with_data = 0);
ScriptP parse(const String& s, bool string_mode, vector<ScriptParseError>& errors_out) {
ScriptP parse(const String& s, Packaged* package, bool string_mode, vector<ScriptParseError>& errors_out) {
errors_out.clear();
// parse
TokenIterator input(s, string_mode, errors_out);
TokenIterator input(s, package, string_mode, errors_out);
ScriptP script(new Script);
parseOper(input, *script, PREC_ALL, I_RET);
Token eof = input.read();
@@ -363,9 +366,9 @@ ScriptP parse(const String& s, bool string_mode, vector<ScriptParseError>& error
}
}
ScriptP parse(const String& s, bool string_mode) {
ScriptP parse(const String& s, Packaged* package, bool string_mode) {
vector<ScriptParseError> errors;
ScriptP script = parse(s, string_mode, errors);
ScriptP script = parse(s, package, string_mode, errors);
if (!errors.empty()) {
throw ScriptParseErrors(errors);
}
+6 -2
View File
@@ -13,6 +13,8 @@
#include <util/error.hpp>
#include <script/script.hpp>
class Packaged;
// ----------------------------------------------------------------------------- : Parser
/// Parse a String to a Script
@@ -21,8 +23,10 @@
*
* Errors are stored in the output vector.
* If there are errors, the result is a null pointer
*
* The package is for loading included files, it may be null
*/
ScriptP parse(const String& s, bool string_mode, vector<ScriptParseError>& errors_out);
ScriptP parse(const String& s, Packaged* package, bool string_mode, vector<ScriptParseError>& errors_out);
/// Parse a String to a Script
/** If string_mode then s is interpreted as a string,
@@ -30,7 +34,7 @@ ScriptP parse(const String& s, bool string_mode, vector<ScriptParseError>& error
*
* If an error is encountered, an exception is thrown.
*/
ScriptP parse(const String& s, bool string_mode = false);
ScriptP parse(const String& s, Packaged* package = nullptr, bool string_mode = false);
// ----------------------------------------------------------------------------- : EOF
#endif
+2 -2
View File
@@ -46,7 +46,7 @@ ScriptValueP OptionalScript::invoke(Context& ctx, bool open_scope) const {
void OptionalScript::parse(Reader& reader, bool string_mode) {
vector<ScriptParseError> errors;
script = ::parse(unparsed, string_mode, errors);
script = ::parse(unparsed, reader.getPackage(), string_mode, errors);
// show parse errors as warnings
String include_warnings;
for (size_t i = 0 ; i < errors.size() ; ++i) {
@@ -104,7 +104,7 @@ const String& StringScript::get() const {
void StringScript::set(const String& s) {
unparsed = s;
script = ::parse(unparsed, true);
script = ::parse(unparsed, nullptr, true);
}
template <> void Reader::handle(StringScript& os) {
+2 -2
View File
@@ -112,7 +112,7 @@ class ScriptCollection : public ScriptValue {
public:
inline ScriptCollection(const Collection* v) : value(v) {}
virtual ScriptType type() const { return SCRIPT_COLLECTION; }
virtual String typeName() const { return format_string(_TYPE_("collection of"), type_name(*value->begin())); }
virtual String typeName() const { return _TYPE_1_("collection of", type_name(*value->begin())); }
virtual ScriptValueP getMember(const String& name) const {
long index;
if (name.ToLong(&index) && index >= 0 && (size_t)index < value->size()) {
@@ -160,7 +160,7 @@ class ScriptMap : public ScriptValue {
public:
inline ScriptMap(const Collection* v) : value(v) {}
virtual ScriptType type() const { return SCRIPT_COLLECTION; }
virtual String typeName() const { return format_string(_TYPE_("collection of"), type_name(value->begin())); }
virtual String typeName() const { return _TYPE_1_("collection of", type_name(value->begin())); }
virtual ScriptValueP getMember(const String& name) const {
return get_member(*value, name);
}