From: Daniel Karbach Date: Mon, 3 Sep 2012 19:56:12 +0000 (+0200) Subject: made high level parser errors a bit more expressive X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=ad15762dbafd23a80ac765fd5bb114640fb0264e;p=l2e.git made high level parser errors a bit more expressive --- diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index 90498e7..c0d3a41 100644 --- a/src/loader/ParsedSource.cpp +++ b/src/loader/ParsedSource.cpp @@ -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::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,14 @@ 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); } }