X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/e2ce853b4a48f8278dc46e4143aa845b18948651..2f33dd04e61fcd883fc6ddcb8f2add8fd9a45eba:/Decode.cpp diff --git a/Decode.cpp b/Decode.cpp index 823e6b4..63bb9ef 100644 --- a/Decode.cpp +++ b/Decode.cpp @@ -27,161 +27,192 @@ namespace sig { template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVariable("bool")); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeVariable("bool")); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeNeutral)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeCharacter(CYTypeNeutral)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVariable("double")); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeFloating(1)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVariable("float")); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeFloating(0)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeSigned)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeFloating(2)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 1)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeCharacter(CYTypeSigned)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 2)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 1)); } +#ifdef __SIZEOF_INT128__ template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 3)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeInt128(CYTypeSigned)); +} +#endif + +template <> +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 2)); +} + +template <> +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 3)); +} + +template <> +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 0)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 0)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeCharacter(CYTypeUnsigned)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeUnsigned)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeUnsigned, 1)); } +#ifdef __SIZEOF_INT128__ template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 1)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeInt128(CYTypeUnsigned)); } +#endif template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 2)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeUnsigned, 2)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 3)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeUnsigned, 3)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 0)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeUnsigned, 0)); } -CYTypedIdentifier *Void::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVoid()); +CYType *Void::Decode(CYPool &pool) const { + return $ CYType($ CYTypeVoid()); } -CYTypedIdentifier *Unknown::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeError()); +CYType *Unknown::Decode(CYPool &pool) const { + return $ CYType($ CYTypeError()); } -CYTypedIdentifier *String::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeNeutral), $ CYTypePointerTo()); +CYType *String::Decode(CYPool &pool) const { + return $ CYType($ CYTypeCharacter(CYTypeNeutral), $ CYTypePointerTo()); } #ifdef CY_OBJECTIVEC -CYTypedIdentifier *Meta::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVariable("Class")); +CYType *Meta::Decode(CYPool &pool) const { + return $ CYType($ CYTypeVariable("Class")); } -CYTypedIdentifier *Selector::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVariable("SEL")); +CYType *Selector::Decode(CYPool &pool) const { + return $ CYType($ CYTypeVariable("SEL")); } #endif -CYTypedIdentifier *Bits::Decode(CYPool &pool) const { +CYType *Bits::Decode(CYPool &pool) const { _assert(false); } -CYTypedIdentifier *Pointer::Decode(CYPool &pool) const { +CYType *Pointer::Decode(CYPool &pool) const { return CYDecodeType(pool, &type)->Modify($ CYTypePointerTo()); } -CYTypedIdentifier *Array::Decode(CYPool &pool) const { +CYType *Array::Decode(CYPool &pool) const { return CYDecodeType(pool, &type)->Modify($ CYTypeArrayOf($D(size))); } #ifdef CY_OBJECTIVEC -CYTypedIdentifier *Object::Decode(CYPool &pool) const { +CYType *Object::Decode(CYPool &pool) const { if (name == NULL) - return $ CYTypedIdentifier($ CYTypeVariable("id")); + return $ CYType($ CYTypeVariable("id")); else - return $ CYTypedIdentifier($ CYTypeVariable(name), $ CYTypePointerTo()); + return $ CYType($ CYTypeVariable(name), $ CYTypePointerTo()); } #endif -CYTypedIdentifier *Aggregate::Decode(CYPool &pool) const { +CYType *Enum::Decode(CYPool &pool) const { + CYEnumConstant *values(NULL); + for (size_t i(count); i != 0; --i) + values = $ CYEnumConstant($I(pool.strdup(constants[i - 1].name)), $D(constants[i - 1].value), values); + CYIdentifier *identifier(name == NULL ? NULL : $I(name)); + CYType *typed(type.Decode(pool)); + _assert(typed->modifier_ == NULL); + return $ CYType($ CYTypeEnum(identifier, typed->specifier_, values)); +} + +CYType *Aggregate::Decode(CYPool &pool) const { _assert(!overlap); + if (signature.count == _not(size_t)) { + _assert(name != NULL); + return $ CYType($ 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]); - CYTypedIdentifier *typed(CYDecodeType(pool, element.type)); - if (element.name != NULL) - typed->identifier_ = $I(element.name); - fields = $ CYTypeStructField(typed, fields); + fields = $ CYTypeStructField(CYDecodeType(pool, element.type), element.name == NULL ? NULL : $I(element.name), fields); } CYIdentifier *identifier(name == NULL ? NULL : $I(name)); - return $ CYTypedIdentifier($ CYTypeStruct(identifier, $ CYStructTail(fields))); + return $ CYType($ CYTypeStruct(identifier, $ CYStructTail(fields))); } -CYTypedIdentifier *Callable::Decode(CYPool &pool) const { +CYType *Callable::Decode(CYPool &pool) const { _assert(signature.count != 0); CYTypedParameter *parameters(NULL); for (size_t i(signature.count - 1); i != 0; --i) - parameters = $ CYTypedParameter(CYDecodeType(pool, signature.elements[i].type), parameters); + parameters = $ CYTypedParameter(CYDecodeType(pool, signature.elements[i].type), NULL, parameters); return Modify(pool, CYDecodeType(pool, signature.elements[0].type), parameters); } -CYTypedIdentifier *Function::Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const { +CYType *Function::Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const { return result->Modify($ CYTypeFunctionWith(variadic, parameters)); } #ifdef CY_OBJECTIVEC -CYTypedIdentifier *Block::Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const { +CYType *Block::Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const { return result->Modify($ CYTypeBlockWith(parameters)); } -CYTypedIdentifier *Block::Decode(CYPool &pool) const { +CYType *Block::Decode(CYPool &pool) const { if (signature.count == 0) - return $ CYTypedIdentifier($ CYTypeVariable("NSBlock"), $ CYTypePointerTo()); + return $ CYType($ CYTypeVariable("NSBlock"), $ CYTypePointerTo()); return Callable::Decode(pool); } #endif } -CYTypedIdentifier *CYDecodeType(CYPool &pool, struct sig::Type *type) { - CYTypedIdentifier *typed(type->Decode(pool)); +CYType *CYDecodeType(CYPool &pool, struct sig::Type *type) { + CYType *typed(type->Decode(pool)); if ((type->flags & JOC_TYPE_CONST) != 0) { if (dynamic_cast(type) != NULL) typed->modifier_ = $ CYTypeConstant(typed->modifier_);