X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.cpp;h=1f7fc983053e68ab32047bdbba7abdc2f466d796;hb=2bd2e92a227af66386af1dfca2f52df6941f0f94;hp=ec263042a68cdba8d7c9c27e43479ae9fee1455f;hpb=32b5ea1b0f05283eb588b2b069d667f7c36e84da;p=l2e.git diff --git a/src/loader/ParsedSource.cpp b/src/loader/ParsedSource.cpp index ec26304..1f7fc98 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; @@ -282,6 +327,23 @@ const PropertyList *Literal::GetProperties() const { } } + +const Literal &Value::GetLiteral() const { + if (isLiteral) { + return *literal; + } else { + throw runtime_error("tried to access literal of identifier value"); + } +} + +const std::string &Value::GetIdentifier() const { + if (!isLiteral) { + return identifier; + } else { + throw runtime_error("tried to access identifier of literal value"); + } +} + }