]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/ParsedSource.cpp
made high level parser errors a bit more expressive
[l2e.git] / src / loader / ParsedSource.cpp
index bceed089f0377f4a4678edc84414afa4d7c3084b..c0d3a411782fea5e840b97720b2222c8d120a416 100644 (file)
@@ -90,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<string, Declaration *>::const_iterator i(declarations.find(name));
+               if (i != declarations.end()) {
+                       msg += ", declared as " + i->second->TypeName();
+               } else {
+                       msg += ", not declared";
+               }
+               throw runtime_error(msg);
        }
 }
 
@@ -99,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<string, Declaration *>::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<string>::const_iterator i(exports.begin()), end(exports.end()); i != end; ++i) {
+               out << GetDeclaration(*i).TypeName() << ' ' << *i << std::endl;
        }
 }