-/*
- * ParsedSource.cpp
- *
- * Created on: Aug 26, 2012
- * Author: holy
- */
-
#include "ParsedSource.h"
#include "utility.h"
}
+Literal::Literal(const string &typeName, const vector<string> &ids)
+: props(0)
+, typeName(typeName)
+, identifiers(ids)
+, i1(0), i2(0)
+, i3(0), i4(0)
+, b(false)
+, type(ARRAY_IDENTS) {
+
+}
+
Literal::Literal(bool b)
: props(0)
, typeName("Boolean")
}
+Literal::Literal(const vector<ScriptToken *> &s)
+: props(0)
+, script(s)
+, i1(0), i2(0)
+, i3(0), i4(0)
+, b(false)
+, type(SCRIPT) {
+
+}
+
Literal::~Literal() {
switch (type) {
case ARRAY_VALUES:
case OBJECT:
delete props;
break;
+ case SCRIPT:
+ for (vector<ScriptToken *>::const_iterator i(script.begin()), end(script.end()); i != end; ++i) {
+ delete *i;
+ }
+ break;
default:
break;
}
}
}
+const vector<string> &Literal::GetIdentifiers() const {
+ if (type == ARRAY_IDENTS) {
+ return identifiers;
+ } else {
+ throw runtime_error("tried to access identifiers of non-array literal");
+ }
+}
+
bool Literal::GetBoolean() const {
if (type == BOOLEAN) {
return b;
}
}
+const vector<ScriptToken *> &Literal::GetScript() const {
+ if (type == SCRIPT) {
+ return script;
+ } else {
+ throw runtime_error("tried to access script of non-script literal");
+ }
+}
+
Value::~Value() {
if (isLiteral) {
}
}
+
+ScriptToken::ScriptToken(const string &s, Type t)
+: literal(0)
+, str(s)
+, type(t) {
+ if (type == LITERAL) {
+ throw runtime_error("cannot create script literal without literal");
+ }
+}
+
+ScriptToken::ScriptToken(Literal *l)
+: literal(l)
+, str()
+, type(LITERAL) {
+ if (!literal) {
+ throw runtime_error("cannot create script literal without literal");
+ }
+}
+
+ScriptToken::~ScriptToken() {
+ delete literal;
+}
+
+const string &ScriptToken::RegisterName() const {
+ if (type == REGISTER) {
+ return str;
+ } else {
+ throw runtime_error("access to register name of non-register script token");
+ }
+}
+
+const string &ScriptToken::CommandName() const {
+ if (type == COMMAND) {
+ return str;
+ } else {
+ throw runtime_error("access to command name of non-command script token");
+ }
+}
+
+const string &ScriptToken::Identifier() const {
+ if (type == IDENTIFIER) {
+ return str;
+ } else {
+ throw runtime_error("access to identifier of non-identifier script token");
+ }
+}
+
+const string &ScriptToken::Label() const {
+ if (type == LABEL) {
+ return str;
+ } else {
+ throw runtime_error("access to label of non-label script token");
+ }
+}
+
+const Literal *ScriptToken::GetLiteral() const {
+ if (type == LITERAL) {
+ return literal;
+ } else {
+ throw runtime_error("access to literal value of non-literal script token");
+ }
+}
+
}
namespace std {
ostream &operator <<(ostream &out, const loader::ParsedSource &source) {
- out << "parsed source file" << endl;
+ out << "parsed sources" << endl;
+ out << "==============" << endl;
out << "declared objects: " << endl;
for (map<string, loader::Declaration *>::const_iterator i(source.Declarations().begin()), end(source.Declarations().end()); i != end; ++i) {
out << " - " << i->first << " of type " << i->second->TypeName() << endl;
for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
out << " - " << *i << endl;
}
+ out << endl;
return out;
}
case loader::Literal::ARRAY_PROPS:
out << "array of property lists";
break;
+ case loader::Literal::ARRAY_IDENTS:
+ out << "array of identifiers";
+ break;
case loader::Literal::BOOLEAN:
out << "boolean, " << (l.GetBoolean() ? "true" : "false");
break;
case loader::Literal::OBJECT:
out << "object of type " << l.GetTypeName();
break;
+ case loader::Literal::SCRIPT:
+ out << "script";
+ break;
}
return out;
}