From eb2ad5ffd08128d31af32f3929a3295fcfa251e9 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 31 Jan 2013 08:12:29 +0100 Subject: [PATCH] simplified definition postponing --- src/loader/Interpreter.cpp | 14 ++++++++++---- src/loader/Interpreter.h | 27 ++++++++++++++++++++------- src/main.cpp | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 8f9e9dc..8b54fc1 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -329,7 +329,7 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis *reinterpret_cast(iter) = GetObject(fd.TypeId(), *j); } else { - Postpone(typeId, id, fd.Offset() + (iter - aggregate), *j, fd.TypeId(), false); + Postpone(iter, *j, fd.TypeId(), false); } } } @@ -355,7 +355,7 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis } } } else { - Postpone(typeId, id, fd.Offset(), i->second->GetIdentifier(), fd.TypeId(), !fd.IsReferenced()); + Postpone(object, i->second->GetIdentifier(), fd.TypeId(), !fd.IsReferenced(), fd.IsAggregate()); } } td.Load(object); @@ -860,11 +860,17 @@ bool Interpreter::CanLink(const Value &v) const { return v.IsLiteral() || source.IsDefined(v.GetIdentifier()); } -void Interpreter::Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined) { +void Interpreter::Postpone( + char *dest, + const std::string &identifier, + int type, + bool inlined, + bool aggregate) { char *str(alloc.Alloc(identifier.size() + 1)); std::memcpy(str, identifier.c_str(), identifier.size()); str[identifier.size()] = '\0'; - postponedDefinitions.push_back(PostponedDefinition(type, id, offset, str, linkedType, inlined)); + postponedDefinitions.push_back( + PostponedDefinition(dest, str, type, inlined, aggregate)); } diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 454fccc..5a8e3ab 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -51,14 +51,22 @@ public: int id; }; struct PostponedDefinition { - PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType, bool inlined) - : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType), inlined(inlined) { } - int type; - int id; - std::ptrdiff_t offset; + PostponedDefinition( + char *dest, + const char *identifier, + int type, + bool inlined, + bool aggregate) + : dest(dest) + , identifier(identifier) + , type(type) + , inlined(inlined) + , aggregate(aggregate) { } + char *dest; const char *identifier; - int linkedType; + int type; bool inlined; + bool aggregate; }; const std::set &ExportedIdentifiers() const { return source.Exports(); } @@ -85,7 +93,12 @@ private: SDL_Surface *GetImage(const std::string &); bool CanLink(const Value &) const; - void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined); + void Postpone( + char *dest, + const std::string &identifier, + int type, + bool inlined = true, + bool aggregate = false); private: const ParsedSource &source; diff --git a/src/main.cpp b/src/main.cpp index e0b7a47..d790928 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,7 +179,7 @@ int main(int argc, char **argv) { if (intp.PostponedDefinitions().size() > 0) { for (vector::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) { - std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl; + std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl; } return 3; } -- 2.39.2