X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.cpp;h=c0d3a411782fea5e840b97720b2222c8d120a416;hb=ad15762dbafd23a80ac765fd5bb114640fb0264e;hp=2075828e19b707b28e0afac8e77ca811da588a47;hpb=40e697f7265b98dd99918d9c3f5541d9878d80b0;p=l2e.git diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index 2075828..c0d3a41 100644 --- a/src/loader/ParsedSource.cpp +++ b/src/loader/ParsedSource.cpp @@ -7,6 +7,8 @@ #include "ParsedSource.h" +#include "utility.h" + #include #include @@ -88,7 +90,14 @@ Definition &ParsedSource::GetDefinition(const std::string &name) { if (i != definitions.end()) { return *i->second; } else { - throw runtime_error("undefined identifier " + name); + string msg("undefined identifier " + name); + map::const_iterator i(declarations.find(name)); + if (i != declarations.end()) { + msg += ", declared as " + i->second->TypeName(); + } else { + msg += ", not declared"; + } + throw runtime_error(msg); } } @@ -97,7 +106,20 @@ const Definition &ParsedSource::GetDefinition(const std::string &name) const { if (i != definitions.end()) { return *i->second; } else { - throw runtime_error("undefined identifier " + name); + string msg("undefined identifier " + name); + map::const_iterator i(declarations.find(name)); + if (i != declarations.end()) { + msg += ", declared as " + i->second->TypeName(); + } else { + msg += ", not declared"; + } + throw runtime_error(msg); + } +} + +void ParsedSource::WriteHeader(std::ostream &out) const { + for (std::set::const_iterator i(exports.begin()), end(exports.end()); i != end; ++i) { + out << GetDeclaration(*i).TypeName() << ' ' << *i << std::endl; } } @@ -147,6 +169,8 @@ PropertyList *Definition::GetProperties() { const PropertyList *Definition::GetProperties() const { if (!isLiteral) { return reinterpret_cast(value); + } else if (GetLiteral()->GetType() == Literal::OBJECT) { + return GetLiteral()->GetProperties(); } else { throw runtime_error("tried to access literal value as property list"); } @@ -207,6 +231,16 @@ Literal::Literal(int number) } +Literal::Literal(const string &dir, const string &path) +: props(0) +, str(CatPath(dir, path)) +, i1(0), i2(0) +, i3(0), i4(0) +, b(false) +, type(STRING) { + +} + Literal::Literal(const string &str) : props(0) , str(str) @@ -426,6 +460,9 @@ ostream &operator <<(ostream &out, const loader::Literal &l) { case loader::Literal::NUMBER: out << "number, " << l.GetNumber(); break; + case loader::Literal::PATH: + out << "path, \"" << l.GetString() << '"'; + break; case loader::Literal::STRING: out << "string, \"" << l.GetString() << '"'; break;