From 5d6b785e122093fe05e2ed14f688a8bce6bad6a9 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 26 Aug 2012 23:16:52 +0200 Subject: [PATCH] added more getters to ParsedSource --- src/loader/ParsedSource.cpp | 45 +++++++++++++++++++++++++++++++++++++ src/loader/ParsedSource.h | 7 ++++++ 2 files changed, 52 insertions(+) diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index ec26304..b019fe7 100644 --- a/src/loader/ParsedSource.cpp +++ b/src/loader/ParsedSource.cpp @@ -51,6 +51,51 @@ void ParsedSource::ExportIdentifier(const std::string &i) { } +bool ParsedSource::IsDeclared(const std::string &name) const { + return declarations.count(name); +} + +Declaration &ParsedSource::GetDeclaration(const std::string &name) { + map::const_iterator i(declarations.find(name)); + if (i != declarations.end()) { + return *i->second; + } else { + throw runtime_error("undeclared identifier " + name); + } +} + +const Declaration &ParsedSource::GetDeclaration(const std::string &name) const { + map::const_iterator i(declarations.find(name)); + if (i != declarations.end()) { + return *i->second; + } else { + throw runtime_error("undeclared identifier " + name); + } +} + +bool ParsedSource::IsDefined(const std::string &name) const { + return definitions.count(name); +} + +Definition &ParsedSource::GetDefinition(const std::string &name) { + map::const_iterator i(definitions.find(name)); + if (i != definitions.end()) { + return *i->second; + } else { + throw runtime_error("undefined identifier " + name); + } +} + +const Definition &ParsedSource::GetDefinition(const std::string &name) const { + map::const_iterator i(definitions.find(name)); + if (i != definitions.end()) { + return *i->second; + } else { + throw runtime_error("undefined identifier " + name); + } +} + + void Definition::SetValue(Literal *v) { value = v; isLiteral = true; diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h index 97137fb..d5347e5 100644 --- a/src/loader/ParsedSource.h +++ b/src/loader/ParsedSource.h @@ -159,6 +159,13 @@ public: void ExportDeclaration(Declaration *); void ExportIdentifier(const std::string &); + bool IsDeclared(const std::string &) const; + Declaration &GetDeclaration(const std::string &); + const Declaration &GetDeclaration(const std::string &) const; + bool IsDefined(const std::string &) const; + Definition &GetDefinition(const std::string &); + const Definition &GetDefinition(const std::string &) const; + const std::map &Declarations() const { return declarations; } const std::map &Definitions() const { return definitions; } const std::set &Exports() const { return exports; } -- 2.39.2