CYTypedIdentifier *Aggregate::Decode(CYPool &pool) const {
_assert(!overlap);
+ if (signature.count == _not(size_t)) {
+ _assert(name != NULL);
+ return $ CYTypedIdentifier($ CYTypeReference(CYTypeReferenceStruct, $I($pool.strdup(name))));
+ }
+
CYTypeStructField *fields(NULL);
for (size_t i(signature.count); i != 0; --i) {
sig::Element &element(signature.elements[i - 1]);
void Aggregate::PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const {
_assert(!overlap);
+ _assert(signature.count != _not(size_t));
size_t offset(0);
uint8_t *base(reinterpret_cast<uint8_t *>(data));
}
JSValueRef Aggregate::FromFFI(JSContextRef context, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) const {
+ _assert(!overlap);
+ _assert(signature.count != _not(size_t));
return Struct_privateData::Make(context, data, *this, ffi, context, owner);
}
_assert(JSValueIsObjectOfClass(context, object, Type_privateData::Class_));
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(object)));
element.type = internal->type_;
+ _assert(element.type != NULL);
}
return CYMakeType(context, type);
void Copy(CYPool &pool, Element &lhs, const Element &rhs) {
lhs.name = pool.strdup(rhs.name);
- if (rhs.type == NULL)
- lhs.type = NULL;
- else
- lhs.type = rhs.type->Copy(pool);
+ _assert(rhs.type != NULL);
+ lhs.type = rhs.type->Copy(pool);
lhs.offset = rhs.offset;
}
void Copy(CYPool &pool, Signature &lhs, const Signature &rhs) {
size_t count(rhs.count);
lhs.count = count;
- lhs.elements = new(pool) Element[count];
- for (size_t index(0); index != count; ++index)
- Copy(pool, lhs.elements[index], rhs.elements[index]);
+ if (count == _not(size_t))
+ lhs.elements = NULL;
+ else {
+ lhs.elements = new(pool) Element[count];
+ for (size_t index(0); index != count; ++index)
+ Copy(pool, lhs.elements[index], rhs.elements[index]);
+ }
}
Void *Void::Copy(CYPool &pool, const char *rename) const {
}
ffi_type *Aggregate::GetFFI(CYPool &pool) const {
- // XXX: we can totally make overlap work
_assert(!overlap);
+ _assert(signature.count != _not(size_t));
ffi_type *ffi(new(pool) ffi_type());
ffi->size = 0;
char end = next;
const char *begin = *encoding;
- do next = *(*encoding)++;
- while (
- next != '=' &&
- next != '}'
- );
+ do switch (next = *(*encoding)++) {
+ case '\0':
+ _assert(false);
+ case '}':
+ // XXX: this is actually a type reference
+ aggregate->signature.count = _not(size_t);
+ next = '='; // this is a "break". I'm sorry
+ } while (next != '=');
+
size_t length = *encoding - begin - 1;
if (strncmp(begin, "?", length) != 0)
aggregate->name = (char *) pool.strmemdup(begin, length);
- if (next == '=')
+ if (aggregate->signature.count == _not(size_t))
+ aggregate->signature.elements = NULL;
+ else
Parse_(pool, &aggregate->signature, encoding, end, callback);
// XXX: this is a hack to support trivial unions
}
const char *Aggregate::Encode(CYPool &pool) const {
- return pool.strcat(overlap ? "(" : "{", name == NULL ? "?" : name, "=", Unparse(pool, &signature), overlap ? ")" : "}", NULL);
+ bool reference(signature.count == _not(size_t));
+ return pool.strcat(overlap ? "(" : "{",
+ name == NULL ? "?" : name,
+ reference ? "" : "=",
+ reference ? "" : Unparse(pool, &signature),
+ overlap ? ")" : "}", NULL);
}
const char *Function::Encode(CYPool &pool) const {