4 * Created on: Aug 26, 2012
8 #include "ParsedSource.h"
14 using std::runtime_error;
20 void ParsedSource::AddDeclaration(Declaration *d) {
21 map<string, Declaration *>::iterator i(declarations.find(d->Identifier()));
22 if (i != declarations.end()) {
23 if (d->TypeName() != i->second->TypeName()) {
24 throw runtime_error("invalid redeclaration of " + i->second->TypeName() + " " + d->Identifier());
27 declarations.insert(std::make_pair(d->Identifier(), d));
31 void ParsedSource::ExportDeclaration(Declaration *d) {
33 exports.insert(d->Identifier());
36 void ParsedSource::ExportIdentifier(const std::string &i) {
37 if (declarations.count(i)) {
40 throw runtime_error("cannot export undeclared identifier " + i);
45 void Definition::SetValue(Literal *v) {
50 void Definition::SetValue(PropertyList *v) {
55 Literal *Definition::GetLiteral() {
57 return (Literal *)value;
59 throw runtime_error("tried to access properties as literal");
63 const Literal *Definition::GetLiteral() const {
65 return (Literal *)value;
67 throw runtime_error("tried to access properties as literal");
71 PropertyList *Definition::GetProperties() {
73 return (PropertyList *)value;
75 throw runtime_error("tried to access literal value as property list");
79 const PropertyList *Definition::GetProperties() const {
81 return (PropertyList *)value;
83 throw runtime_error("tried to access literal value as property list");
88 PropertyList::~PropertyList() {
89 for (map<string, Value *>::iterator i(props.begin()), end(props.end()); i != end; ++i) {
95 Literal::Literal(const vector<Value *> &v)
105 Literal::Literal(bool b)
114 Literal::Literal(int r, int g, int b, int a)
123 Literal::Literal(const string &str)
133 Literal::Literal(int x, int y)
142 Literal::Literal(const string &typeName, PropertyList *properties)
157 ostream &operator <<(ostream &out, const loader::ParsedSource &source) {
158 out << "parsed source file" << endl;
159 out << "declared objects: " << endl;
160 for (map<string, loader::Declaration *>::const_iterator i(source.Declarations().begin()), end(source.Declarations().end()); i != end; ++i) {
161 out << " - " << i->first << " of type " << i->second->TypeName() << endl;
163 out << "exported objects: " << endl;
164 for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
165 out << " - " << *i << endl;