#include "ParsedSource.h"
+#include "utility.h"
+
#include <ostream>
#include <stdexcept>
namespace loader {
+ParsedSource::~ParsedSource() {
+ for (map<string, Declaration *>::const_iterator i(declarations.begin()), end(declarations.end()); i != end; ++i) {
+ delete i->second;
+ }
+}
+
void ParsedSource::AddDeclaration(Declaration *d) {
map<string, Declaration *>::iterator i(declarations.find(d->Identifier()));
if (i != declarations.end()) {
}
}
+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);
+ }
+}
void Definition::SetValue(Literal *v) {
value = v;
Literal *Definition::GetLiteral() {
if (isLiteral) {
- return (Literal *)value;
+ return reinterpret_cast<Literal *>(value);
} else {
throw runtime_error("tried to access properties as literal");
}
const Literal *Definition::GetLiteral() const {
if (isLiteral) {
- return (Literal *)value;
+ return reinterpret_cast<Literal *>(value);
} else {
throw runtime_error("tried to access properties as literal");
}
PropertyList *Definition::GetProperties() {
if (!isLiteral) {
- return (PropertyList *)value;
+ return reinterpret_cast<PropertyList *>(value);
} else {
throw runtime_error("tried to access literal value as property list");
}
const PropertyList *Definition::GetProperties() const {
if (!isLiteral) {
- return (PropertyList *)value;
+ return reinterpret_cast<PropertyList *>(value);
+ } else if (GetLiteral()->GetType() == Literal::OBJECT) {
+ return GetLiteral()->GetProperties();
} else {
throw runtime_error("tried to access literal value as property list");
}
}
+Literal::Literal(const string &dir, const string &path)
+: props(0)
+, str(CatPath(dir, path))
+, i1(0), i2(0)
+, i3(0), i4(0)
+, b(false)
+, type(STRING) {
+
+}
+
Literal::Literal(const string &str)
: props(0)
, str(str)
}
+Literal::~Literal() {
+ switch (type) {
+ case ARRAY_VALUES:
+ for (vector<Value *>::const_iterator i(values.begin()), end(values.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ case ARRAY_PROPS:
+ for (vector<PropertyList *>::const_iterator i(propertyLists.begin()), end(propertyLists.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
+ case OBJECT:
+ delete props;
+ break;
+ default:
+ break;
+ }
+}
+
const vector<Value *> &Literal::GetValues() const {
if (type == ARRAY_VALUES) {
}
+Value::~Value() {
+ if (isLiteral) {
+ delete literal;
+ }
+}
+
const Literal &Value::GetLiteral() const {
if (isLiteral) {
return *literal;
case loader::Literal::NUMBER:
out << "number, " << l.GetNumber();
break;
+ case loader::Literal::PATH:
+ out << "path, \"" << l.GetString() << '"';
+ break;
case loader::Literal::STRING:
out << "string, \"" << l.GetString() << '"';
break;