+bool ParsedSource::IsDeclared(const std::string &name) const {
+ return declarations.count(name);
+}
+
+Declaration &ParsedSource::GetDeclaration(const std::string &name) {
+ map<string, Declaration *>::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<string, Declaration *>::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<string, Definition *>::const_iterator i(definitions.find(name));
+ if (i != definitions.end()) {
+ return *i->second;
+ } else {
+ 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);
+ }
+}
+
+const Definition &ParsedSource::GetDefinition(const std::string &name) const {
+ map<string, Definition *>::const_iterator i(definitions.find(name));
+ if (i != definitions.end()) {
+ return *i->second;
+ } else {
+ 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;
+ }
+}
+
+
+Definition::~Definition() {
+ if (isLiteral) {
+ delete reinterpret_cast<Literal *>(value);
+ } else {
+ delete reinterpret_cast<PropertyList *>(value);
+ }
+}
+