]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/ParsedSource.cpp
revised array type notation
[l2e.git] / src / loader / ParsedSource.cpp
index bceed089f0377f4a4678edc84414afa4d7c3084b..e1a1d0aa030e3100e0a831205407e611443fb4aa 100644 (file)
@@ -90,7 +90,14 @@ Definition &ParsedSource::GetDefinition(const std::string &name) {
        if (i != definitions.end()) {
                return *i->second;
        } else {
-               throw runtime_error("undefined identifier " + name);
+               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);
        }
 }
 
@@ -99,7 +106,20 @@ const Definition &ParsedSource::GetDefinition(const std::string &name) const {
        if (i != definitions.end()) {
                return *i->second;
        } else {
-               throw runtime_error("undefined identifier " + name);
+               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;
        }
 }
 
@@ -171,11 +191,14 @@ Literal::Literal(const vector<Value *> &v)
 , i3(0), i4(0)
 , b(false)
 , type(ARRAY_VALUES) {
-
+       if (!v.empty()) {
+               typeName = v.front()->GetLiteral().GetTypeName();
+       }
 }
 
-Literal::Literal(const std::vector<PropertyList *> &pls)
+Literal::Literal(const string &typeName, const vector<PropertyList *> &pls)
 : props(0)
+, typeName(typeName)
 , propertyLists(pls)
 , i1(0), i2(0)
 , i3(0), i4(0)
@@ -186,6 +209,7 @@ Literal::Literal(const std::vector<PropertyList *> &pls)
 
 Literal::Literal(bool b)
 : props(0)
+, typeName("Boolean")
 , i1(0), i2(0)
 , i3(0), i4(0)
 , b(b)
@@ -195,6 +219,7 @@ Literal::Literal(bool b)
 
 Literal::Literal(int r, int g, int b, int a)
 : props(0)
+, typeName("Color")
 , i1(r), i2(g)
 , i3(b), i4(a)
 , b(false)
@@ -204,6 +229,7 @@ Literal::Literal(int r, int g, int b, int a)
 
 Literal::Literal(int number)
 : props(0)
+, typeName("Number")
 , i1(number), i2(0)
 , i3(0), i4(0)
 , b(false)
@@ -213,6 +239,7 @@ Literal::Literal(int number)
 
 Literal::Literal(const string &dir, const string &path)
 : props(0)
+, typeName("Path")
 , str(CatPath(dir, path))
 , i1(0), i2(0)
 , i3(0), i4(0)
@@ -223,6 +250,7 @@ Literal::Literal(const string &dir, const string &path)
 
 Literal::Literal(const string &str)
 : props(0)
+, typeName("String")
 , str(str)
 , i1(0), i2(0)
 , i3(0), i4(0)
@@ -233,6 +261,7 @@ Literal::Literal(const string &str)
 
 Literal::Literal(int x, int y)
 : props(0)
+, typeName("Vector")
 , i1(x), i2(y)
 , i3(0), i4(0)
 , b(false)
@@ -242,7 +271,7 @@ Literal::Literal(int x, int y)
 
 Literal::Literal(const string &typeName, PropertyList *properties)
 : props(properties)
-, str(typeName)
+, typeName(typeName)
 , i1(0), i2(0)
 , i3(0), i4(0)
 , b(false)
@@ -360,11 +389,7 @@ int Literal::GetY() const {
 }
 
 const string &Literal::GetTypeName() const {
-       if (type == OBJECT) {
-               return str;
-       } else {
-               throw runtime_error("tried to access type name of non-object literal");
-       }
+       return typeName;
 }
 
 const PropertyList *Literal::GetProperties() const {