]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Interpreter.cpp
lousy implementation of "array of identifiers" type
[l2e.git] / src / loader / Interpreter.cpp
index 7dcb41e969c0de829f87ef56c67896e0c0dfc82a..e64110dbf7175801cbd2cde01aea701ce874d4d1 100644 (file)
@@ -127,10 +127,9 @@ void Interpreter::ReadLiteral(const Definition &dfn) {
 void Interpreter::ReadLiteral(int typeId, int id, char *object, const Literal &literal) {
        switch (literal.GetType()) {
                case Literal::ARRAY_VALUES:
-                       throw Error("named value arrays are not supported, sorry");
-                       break;
                case Literal::ARRAY_PROPS:
-                       throw Error("named property list arrays are not supported, sorry");
+               case Literal::ARRAY_IDENTS:
+                       throw Error("named arrays are not supported, sorry");
                        break;
                case Literal::BOOLEAN:
                        new (object) bool(literal.GetBoolean());
@@ -177,10 +176,9 @@ void *Interpreter::GetObject(int typeId, const Value &v) {
                        int typeId(0), id(0);
                        switch (v.GetLiteral().GetType()) {
                                case Literal::ARRAY_VALUES:
-                                       throw Error("cannot copy value arrays, sorry");
-                                       break;
                                case Literal::ARRAY_PROPS:
-                                       throw Error("cannot copy property list arrays, sorry");
+                               case Literal::ARRAY_IDENTS:
+                                       throw Error("cannot copy arrays, sorry");
                                        break;
                                case Literal::BOOLEAN:
                                        {
@@ -287,20 +285,35 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis
                        char *dest(object + fd.Offset());
                        if (fd.IsAggregate()) {
                                int arraySize(i->second->GetLiteral().ArraySize());
-                               char *aggregate(alloc.Alloc(fieldType.Size() * arraySize));
-                               char *iter(aggregate);
+                               char *aggregate;
                                if (i->second->GetLiteral().GetType() == Literal::ARRAY_PROPS) {
+                                       aggregate = alloc.Alloc(fieldType.Size() * arraySize);
+                                       char *iter = aggregate;
                                        const vector<PropertyList *> &list(i->second->GetLiteral().GetPropertyLists());
                                        for (vector<PropertyList *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
                                                fieldType.Construct(iter);
                                                ReadObject(fieldType.TypeId(), -1, iter, **j);
                                        }
-                               } else {
+                               } else if (i->second->GetLiteral().GetType() == Literal::ARRAY_VALUES) {
+                                       aggregate = alloc.Alloc(fieldType.Size() * arraySize);
+                                       char *iter = aggregate;
                                        const vector<Value *> &list(i->second->GetLiteral().GetValues());
                                        for (vector<Value *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
                                                fieldType.Construct(iter);
                                                ReadLiteral(fieldType.TypeId(), -1, iter, (*j)->GetLiteral());
                                        }
+                               } else {
+                                       aggregate = alloc.Alloc(sizeof(char *) * arraySize);
+                                       char *iter = aggregate;
+                                       const vector<string> &list(i->second->GetLiteral().GetIdentifiers());
+                                       for (vector<string>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += sizeof(void *)) {
+                                               if (source.IsDefined(*j)) {
+                                                       *reinterpret_cast<void **>(iter)
+                                                                       = GetObject(fd.TypeId(), *j);
+                                               } else {
+                                                       Postpone(typeId, id, fd.Offset() + (iter - aggregate), *j, fd.TypeId(), false);
+                                               }
+                                       }
                                }
                                if (fd.IsReferenced()) {
                                        std::memcpy(dest, &aggregate, sizeof(char *));