}
}
+const Interpreter::ParsedDefinition &Interpreter::GetDefinition(const string &identifier) const {
+ std::map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(identifier));
+ if (i != parsedDefinitions.end()) {
+ return i->second;
+ } else {
+ throw Error("access to undefined object " + identifier);
+ }
+}
+
-void *Interpreter::GetObject(int typeId, const std::string &name) {
- std::map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+void *Interpreter::GetObject(
+ int typeId,
+ const std::string &name) {
+ std::map<string, ParsedDefinition>::const_iterator
+ i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
- const TypeDescription &requested(TypeDescription::Get(typeId));
- const TypeDescription &actual(TypeDescription::Get(i->second.type));
+ const TypeDescription &requested =
+ TypeDescription::Get(typeId);
+ const TypeDescription &actual =
+ TypeDescription::Get(i->second.type);
if (requested.TypeId() == actual.TypeId()) {
return values[actual.TypeId()][i->second.id];
} else if (actual.IsSubtypeOf(requested)) {
- char *sub(reinterpret_cast<char *>(values[actual.TypeId()][i->second.id]));
- std::ptrdiff_t offset(actual.SupertypeOffset(requested));
+ char *sub = reinterpret_cast<char *>(
+ values[actual.TypeId()][i->second.id]);
+ std::ptrdiff_t offset =
+ actual.SupertypeOffset(requested);
+ return sub - offset;
+ } else {
+ throw Error("cannot cast " + actual.TypeName()
+ + " to " + requested.TypeName());
+ }
+ } else {
+ throw Error("access to undefined object " + name);
+ }
+}
+
+const void *Interpreter::GetObject(
+ int typeId,
+ const std::string &name) const {
+ std::map<string, ParsedDefinition>::const_iterator
+ i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ const TypeDescription &requested =
+ TypeDescription::Get(typeId);
+ const TypeDescription &actual =
+ TypeDescription::Get(i->second.type);
+ if (requested.TypeId() == actual.TypeId()) {
+ return values.at(actual.TypeId()).at(i->second.id);
+ } else if (actual.IsSubtypeOf(requested)) {
+ char *sub = reinterpret_cast<char *>(
+ values.at(actual.TypeId()).at(i->second.id));
+ std::ptrdiff_t offset =
+ actual.SupertypeOffset(requested);
return sub - offset;
} else {
- throw Error("cannot cast " + actual.TypeName() + " to " + requested.TypeName());
+ throw Error("cannot cast " + actual.TypeName()
+ + " to " + requested.TypeName());
}
} else {
throw Error("access to undefined object " + name);
if (fd.IsAggregate()) {
int arraySize(i->second->GetLiteral().ArraySize());
size_t memberSize = fd.IsReferenced() ? sizeof(char *) : fieldType.Size();
- char *aggregate = alloc.Alloc(arraySize * memberSize);
- char *iter = aggregate;
+ Array array;
+ array.size = arraySize * memberSize;
+ array.data = alloc.Alloc(array.size);
+ array.ref = fd.IsReferenced();
+ arrays.push_back(array);
+ char *iter = reinterpret_cast<char *>(array.data);
if (i->second->GetLiteral().GetType() == Literal::ARRAY_PROPS) {
const vector<PropertyList *> &list(i->second->GetLiteral().GetPropertyLists());
- for (vector<PropertyList *>::const_iterator j(list.begin()), end(list.end());
+ for (vector<PropertyList *>::const_iterator
+ j(list.begin()), end(list.end());
j != end; ++j, iter += memberSize) {
char *member;
if (fd.IsReferenced()) {
*reinterpret_cast<void **>(iter)
= GetObject(fd.TypeId(), *j);
} else {
- Postpone(iter, *j, fd.TypeId(), false);
+ Postpone(reinterpret_cast<char *>(array.data),
+ iter, *j, fd.TypeId(), false);
}
}
}
- std::memcpy(dest, &aggregate, sizeof(char *));
+ std::memcpy(dest, &array.data, sizeof(char *));
dest += sizeof(char *);
std::memcpy(dest, &arraySize, sizeof(int));
} else if (i->second->IsLiteral() && !fd.IsReferenced()) {
}
}
} else {
- Postpone(object, i->second->GetIdentifier(), fd.TypeId(), !fd.IsReferenced(), fd.IsAggregate());
+ Postpone(object, object + fd.Offset(), i->second->GetIdentifier(), fd.TypeId(), !fd.IsReferenced(), fd.IsAggregate());
}
}
td.Load(object);
}
void Interpreter::Postpone(
+ char *object,
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(dest, str, type, inlined, aggregate));
+ PostponedDefinition(object, dest, identifier, type, inlined, aggregate));
}