From 5b4dabb2071e2e09cd70a156beed03b12bec477a Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 5 Jan 2016 00:39:00 -0800 Subject: [PATCH] Allow strings to be used as extern or field names. --- Analyze.cpp | 42 ++++++-------- Decode.cpp | 129 ++++++++++++++++++++--------------------- Decode.hpp | 2 +- Execute.cpp | 6 +- ObjectiveC/Library.mm | 2 +- ObjectiveC/Output.cpp | 13 +++-- ObjectiveC/Replace.cpp | 11 ++-- ObjectiveC/Syntax.hpp | 24 ++++---- Output.cpp | 55 ++++++++++-------- Parser.ypp.in | 71 ++++++++++++----------- Replace.cpp | 31 +++++----- Syntax.hpp | 121 ++++++++++++++++++++++++-------------- sig/types.hpp | 38 ++++++------ 13 files changed, 297 insertions(+), 248 deletions(-) diff --git a/Analyze.cpp b/Analyze.cpp index f5195a0..f1ef107 100644 --- a/Analyze.cpp +++ b/Analyze.cpp @@ -289,16 +289,10 @@ static CYStatement *CYTranslateBlock(CXTranslationUnit unit, CXCursor cursor) { return $ CYBlock(statements); } -static CYTypedIdentifier *CYDecodeType(CXType type); -static void CYParseType(CXType type, CYTypedIdentifier *typed); +static CYType *CYDecodeType(CXType type); +static void CYParseType(CXType type, CYType *typed); -static CYTypedIdentifier *CYDecodeType(CXType type, const CYCXString &identifier) { - CYTypedIdentifier *typed(CYDecodeType(type)); - typed->identifier_ = $ CYIdentifier(identifier.Pool($pool)); - return typed; -} - -static void CYParseEnumeration(CXCursor cursor, CYTypedIdentifier *typed) { +static void CYParseEnumeration(CXCursor cursor, CYType *typed) { CYList constants; CYForChild(cursor, fun([&](CXCursor child) { @@ -306,23 +300,21 @@ static void CYParseEnumeration(CXCursor cursor, CYTypedIdentifier *typed) { constants->*$ CYEnumConstant($I($pool.strdup(CYCXString(child))), $D(clang_getEnumConstantDeclValue(child))); })); - CYTypedIdentifier *integer(CYDecodeType(clang_getEnumDeclIntegerType(cursor))); + CYType *integer(CYDecodeType(clang_getEnumDeclIntegerType(cursor))); typed->specifier_ = $ CYTypeEnum(NULL, integer->specifier_, constants); } -static void CYParseStructure(CXCursor cursor, CYTypedIdentifier *typed) { +static void CYParseStructure(CXCursor cursor, CYType *typed) { CYList fields; CYForChild(cursor, fun([&](CXCursor child) { - if (clang_getCursorKind(child) == CXCursor_FieldDecl) { - CYTypedIdentifier *field(CYDecodeType(clang_getCursorType(child), child)); - fields->*$ CYTypeStructField(field); - } + if (clang_getCursorKind(child) == CXCursor_FieldDecl) + fields->*$ CYTypeStructField(CYDecodeType(clang_getCursorType(child)), $I(CYCXString(child).Pool($pool))); })); typed->specifier_ = $ CYTypeStruct(NULL, $ CYStructTail(fields)); } -static void CYParseCursor(CXType type, CXCursor cursor, CYTypedIdentifier *typed) { +static void CYParseCursor(CXType type, CXCursor cursor, CYType *typed) { CYCXString spelling(cursor); switch (CXCursorKind kind = clang_getCursorKind(cursor)) { @@ -351,19 +343,19 @@ static void CYParseCursor(CXType type, CXCursor cursor, CYTypedIdentifier *typed } } -static CYTypedParameter *CYParseSignature(CXType type, CYTypedIdentifier *typed) { +static CYTypedParameter *CYParseSignature(CXType type, CYType *typed) { CYParseType(clang_getResultType(type), typed); CYList parameters; for (int i(0), e(clang_getNumArgTypes(type)); i != e; ++i) - parameters->*$ CYTypedParameter(CYDecodeType(clang_getArgType(type, i))); + parameters->*$ CYTypedParameter(CYDecodeType(clang_getArgType(type, i)), NULL); return parameters; } -static void CYParseFunction(CXType type, CYTypedIdentifier *typed) { +static void CYParseFunction(CXType type, CYType *typed) { typed = typed->Modify($ CYTypeFunctionWith(clang_isFunctionTypeVariadic(type), CYParseSignature(type, typed))); } -static void CYParseType(CXType type, CYTypedIdentifier *typed) { +static void CYParseType(CXType type, CYType *typed) { switch (CXTypeKind kind = type.kind) { case CXType_Unexposed: { CXType result(clang_getResultType(type)); @@ -481,8 +473,8 @@ static void CYParseType(CXType type, CYTypedIdentifier *typed) { typed = typed->Modify($ CYTypeConstant()); } -static CYTypedIdentifier *CYDecodeType(CXType type) { - CYTypedIdentifier *typed($ CYTypedIdentifier(NULL)); +static CYType *CYDecodeType(CXType type) { + CYType *typed($ CYType(NULL)); CYParseType(type, typed); return typed; } @@ -516,7 +508,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien CYLocalPool pool; - CYTypedIdentifier typed(NULL); + CYType typed; CYParseEnumeration(cursor, &typed); CYOptions options; @@ -595,7 +587,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien CYLocalPool pool; - CYTypedIdentifier typed(NULL); + CYType typed; CYParseStructure(cursor, &typed); CYOptions options; @@ -610,7 +602,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien case CXCursor_TypedefDecl: { CYLocalPool local; - CYTypedIdentifier *typed(CYDecodeType(clang_getTypedefDeclUnderlyingType(cursor))); + CYType *typed(CYDecodeType(clang_getTypedefDeclUnderlyingType(cursor))); if (typed->specifier_ == NULL) value << "(typedef " << CYCXString(clang_getTypeSpelling(clang_getTypedefDeclUnderlyingType(cursor))) << ")"; else { diff --git a/Decode.cpp b/Decode.cpp index cf58ad4..c20fb1c 100644 --- a/Decode.cpp +++ b/Decode.cpp @@ -27,190 +27,187 @@ 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($ CYTypeVariable("double")); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeVariable("float")); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeVariable("float")); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeSigned)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeCharacter(CYTypeSigned)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 1)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 1)); } #ifdef __SIZEOF_INT128__ template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeInt128(CYTypeSigned)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeInt128(CYTypeSigned)); } #endif template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 2)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 2)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 3)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 3)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeSigned, 0)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeSigned, 0)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeCharacter(CYTypeUnsigned)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeCharacter(CYTypeUnsigned)); } template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeIntegral(CYTypeUnsigned, 1)); +CYType *Primitive::Decode(CYPool &pool) const { + return $ CYType($ CYTypeIntegral(CYTypeUnsigned, 1)); } #ifdef __SIZEOF_INT128__ template <> -CYTypedIdentifier *Primitive::Decode(CYPool &pool) const { - return $ CYTypedIdentifier($ CYTypeInt128(CYTypeUnsigned)); +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 *Enum::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)); - CYTypedIdentifier *typed(type.Decode(pool)); + CYType *typed(type.Decode(pool)); _assert(typed->modifier_ == NULL); - return $ CYTypedIdentifier($ CYTypeEnum(identifier, typed->specifier_, values)); + return $ CYType($ CYTypeEnum(identifier, typed->specifier_, values)); } -CYTypedIdentifier *Aggregate::Decode(CYPool &pool) const { +CYType *Aggregate::Decode(CYPool &pool) const { _assert(!overlap); if (signature.count == _not(size_t)) { _assert(name != NULL); - return $ CYTypedIdentifier($ CYTypeReference(CYTypeReferenceStruct, $I($pool.strdup(name)))); + 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_); diff --git a/Decode.hpp b/Decode.hpp index eac172d..0946cd3 100644 --- a/Decode.hpp +++ b/Decode.hpp @@ -26,6 +26,6 @@ #include "Syntax.hpp" -CYTypedIdentifier *CYDecodeType(CYPool &pool, struct sig::Type *type); +CYType *CYDecodeType(CYPool &pool, struct sig::Type *type); #endif//DECODE_HPP diff --git a/Execute.cpp b/Execute.cpp index 9af250c..310ddf6 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1738,6 +1738,8 @@ static JSValueRef Functor_callAsFunction_toCYON(JSContextRef context, JSObjectRe sig::Function function(internal->variadic_); sig::Copy(pool, function.signature, internal->signature_); + CYString *name; + auto typed(CYDecodeType(pool, &function)); { std::ostringstream str; Dl_info info; @@ -1752,14 +1754,14 @@ static JSValueRef Functor_callAsFunction_toCYON(JSContextRef context, JSObjectRe str << "+0x" << std::hex << offset; } - typed->identifier_ = new(pool) CYIdentifier(pool.strdup(str.str().c_str())); + name = new(pool) CYString(pool.strdup(str.str().c_str())); } std::ostringstream str; CYOptions options; CYOutput output(*str.rdbuf(), options); output.pretty_ = true; - (new(pool) CYExternalExpression(new(pool) CYString("C"), typed))->Output(output, CYNoFlags); + (new(pool) CYExternalExpression(new(pool) CYString("C"), typed, name))->Output(output, CYNoFlags); return CYCastJSValue(context, CYJSString(str.str())); } CYCatch(NULL) } diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index e7c16b8..65cb5c2 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -842,7 +842,7 @@ static bool CYBlockSignature(CYPool &pool, NSBlock *self, sig::Signature &signat return [super cy$toCYON:objective inSet:objects]; _oassert(objects.insert(self).second); - CYTypedIdentifier *typed((new(pool) CYTypeExpression(CYDecodeType(pool, &type)))->typed_); + CYType *typed((new(pool) CYTypeExpression(CYDecodeType(pool, &type)))->typed_); CYTypeModifier *&modifier(CYGetLast(typed->modifier_)); CYTypeBlockWith *with(dynamic_cast(modifier)); _assert(with != NULL); diff --git a/ObjectiveC/Output.cpp b/ObjectiveC/Output.cpp index e2bb0f8..6927938 100644 --- a/ObjectiveC/Output.cpp +++ b/ObjectiveC/Output.cpp @@ -49,7 +49,7 @@ void CYImplementation::Output(CYOutput &out, CYFlags flags) const { } void CYImplementationField::Output(CYOutput &out) const { - out << *typed_; + type_->Output(out, name_); out.Terminate(); out << '\n'; } @@ -65,8 +65,13 @@ void CYMessage::Output(CYOutput &out) const { CYForEach (parameter, parameters_) if (parameter->name_ != NULL) { out << ' ' << *parameter->name_; - if (parameter->type_ != NULL) - out << ':' << *parameter->type_->identifier_; + // XXX: this is off somehow + if (parameter->identifier_ != NULL) { + out << ':'; + if (parameter->type_ != NULL) + out << '(' << *parameter->type_ << ')'; + out << *parameter->identifier_; + } } out << code_; @@ -133,7 +138,7 @@ void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const { out << ',' << ' '; else comma = true; - out << *parameter->typed_; + parameter->type_->Output(out, parameter->name_); } out << ')' << ' ' << '{' << '\n'; diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 9d6f100..01eb727 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -25,7 +25,7 @@ #include "ObjectiveC/Syntax.hpp" -static CYExpression *MessageType(CYContext &context, CYTypedIdentifier *type, CYMessageParameter *next, CYExpression *extra = NULL) { +static CYExpression *MessageType(CYContext &context, CYType *type, CYMessageParameter *next, CYExpression *extra = NULL) { CYExpression *left($C0($M(type->Replace(context), $S("toString")))); if (extra != NULL) left = $ CYAdd(left, extra); @@ -70,12 +70,12 @@ CYStatement *CYImplementationField::Replace(CYContext &context) const { $T(NULL) CYVariable *cyn($V("$cyn")); CYVariable *cyt($V("$cyt")); - CYExpression *type($C0($M(typed_->Replace(context), $S("toString")))); + CYExpression *type($C0($M(type_->Replace(context), $S("toString")))); return $ CYBlock($$->* $E($ CYAssign(cyt, type))->* $E($ CYAssign(cyn, $N1($V("Type"), cyt)))->* - $E($C5($V("class_addIvar"), $V("$cyc"), $S(typed_->identifier_->Word()), $M(cyn, $S("size")), $M(cyn, $S("alignment")), cyt))->* + $E($C5($V("class_addIvar"), $V("$cyc"), name_->PropertyName(context), $M(cyn, $S("size")), $M(cyn, $S("alignment")), cyt))->* next_->Replace(context) ); } @@ -112,7 +112,7 @@ CYExpression *CYMessage::TypeSignature(CYContext &context) const { CYFunctionParameter *CYMessageParameter::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); - return type_ == NULL ? next : $ CYFunctionParameter($B(type_->identifier_), next); + return type_ == NULL ? next : $ CYFunctionParameter($B(identifier_), next); } CYSelector *CYMessageParameter::Selector(CYContext &context) const { @@ -154,7 +154,8 @@ CYTarget *CYObjCDictionary::Replace(CYContext &context) { } CYTarget *CYObjCBlock::Replace(CYContext &context) { - return $C1($ CYTypeExpression(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_)); + // XXX: wtf is happening here? + return $C1($ CYTypeExpression(($ CYType(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_)); } CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL) diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index f47d935..d185f0d 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -43,11 +43,11 @@ struct CYInstanceLiteral : struct CYObjCBlock : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; CYTypedParameter *parameters_; CYStatement *code_; - CYObjCBlock(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) : + CYObjCBlock(CYType *typed, CYTypedParameter *parameters, CYStatement *code) : typed_(typed), parameters_(parameters), code_(code) @@ -159,11 +159,13 @@ struct CYSelector : struct CYImplementationField : CYNext { - CYTypedIdentifier *typed_; + CYType *type_; + CYPropertyName *name_; - CYImplementationField(CYTypedIdentifier *typed, CYImplementationField *next = NULL) : + CYImplementationField(CYType *type, CYPropertyName *name, CYImplementationField *next = NULL) : CYNext(next), - typed_(typed) + type_(type), + name_(name) { } @@ -175,12 +177,14 @@ struct CYMessageParameter : CYNext { CYWord *name_; - CYTypedIdentifier *type_; + CYType *type_; + CYIdentifier *identifier_; - CYMessageParameter(CYWord *name, CYTypedIdentifier *type, CYMessageParameter *next = NULL) : + CYMessageParameter(CYWord *name, CYType *type = NULL, CYIdentifier *identifier = NULL, CYMessageParameter *next = NULL) : CYNext(next), name_(name), - type_(type) + type_(type), + identifier_(identifier) { } @@ -194,11 +198,11 @@ struct CYMessage : CYNext { bool instance_; - CYTypedIdentifier *type_; + CYType *type_; CYMessageParameter *parameters_; CYBlock code_; - CYMessage(bool instance, CYTypedIdentifier *type, CYMessageParameter *parameters, CYStatement *code) : + CYMessage(bool instance, CYType *type, CYMessageParameter *parameters, CYStatement *code) : instance_(instance), type_(type), parameters_(parameters), diff --git a/Output.cpp b/Output.cpp index 1552304..2c2ef36 100644 --- a/Output.cpp +++ b/Output.cpp @@ -458,12 +458,15 @@ void CYExtend::Output(CYOutput &out, CYFlags flags) const { } void CYExternalDefinition::Output(CYOutput &out, CYFlags flags) const { - out << "extern" << ' ' << abi_ << ' ' << typed_; + out << "extern" << ' ' << abi_ << ' '; + type_->Output(out, name_); out.Terminate(); } void CYExternalExpression::Output(CYOutput &out, CYFlags flags) const { - out << '(' << "extern" << ' ' << abi_ << ' ' << typed_ << ')'; + out << '(' << "extern" << ' ' << abi_ << ' '; + type_->Output(out, name_); + out << ')'; } void CYFatArrow::Output(CYOutput &out, CYFlags flags) const { @@ -668,26 +671,26 @@ void CYTemplate::Output(CYOutput &out, CYFlags flags) const { _assert(false); } -void CYTypeArrayOf::Output(CYOutput &out, CYIdentifier *identifier) const { - next_->Output(out, Precedence(), identifier, false); +void CYTypeArrayOf::Output(CYOutput &out, CYPropertyName *name) const { + next_->Output(out, Precedence(), name, false); out << '['; out << size_; out << ']'; } -void CYTypeBlockWith::Output(CYOutput &out, CYIdentifier *identifier) const { +void CYTypeBlockWith::Output(CYOutput &out, CYPropertyName *name) const { out << '(' << '^'; - next_->Output(out, Precedence(), identifier, false); + next_->Output(out, Precedence(), name, false); out << ')' << '(' << parameters_ << ')'; } -void CYTypeConstant::Output(CYOutput &out, CYIdentifier *identifier) const { +void CYTypeConstant::Output(CYOutput &out, CYPropertyName *name) const { out << "const"; - next_->Output(out, Precedence(), identifier, false); + next_->Output(out, Precedence(), name, false); } -void CYTypeFunctionWith::Output(CYOutput &out, CYIdentifier *identifier) const { - next_->Output(out, Precedence(), identifier, false); +void CYTypeFunctionWith::Output(CYOutput &out, CYPropertyName *name) const { + next_->Output(out, Precedence(), name, false); out << '(' << parameters_; if (variadic_) { if (parameters_ != NULL) @@ -697,24 +700,24 @@ void CYTypeFunctionWith::Output(CYOutput &out, CYIdentifier *identifier) const { out << ')'; } -void CYTypePointerTo::Output(CYOutput &out, CYIdentifier *identifier) const { +void CYTypePointerTo::Output(CYOutput &out, CYPropertyName *name) const { out << '*'; - next_->Output(out, Precedence(), identifier, false); + next_->Output(out, Precedence(), name, false); } -void CYTypeVolatile::Output(CYOutput &out, CYIdentifier *identifier) const { +void CYTypeVolatile::Output(CYOutput &out, CYPropertyName *name) const { out << "volatile"; - next_->Output(out, Precedence(), identifier, true); + next_->Output(out, Precedence(), name, true); } -void CYTypeModifier::Output(CYOutput &out, int precedence, CYIdentifier *identifier, bool space) const { - if (this == NULL && identifier == NULL) +void CYTypeModifier::Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const { + if (this == NULL && name == NULL) return; else if (space) out << ' '; if (this == NULL) { - out << identifier; + name->PropertyName(out); return; } @@ -722,14 +725,18 @@ void CYTypeModifier::Output(CYOutput &out, int precedence, CYIdentifier *identif if (protect) out << '('; - Output(out, identifier); + Output(out, name); if (protect) out << ')'; } -void CYTypedIdentifier::Output(CYOutput &out) const { +void CYType::Output(CYOutput &out, CYPropertyName *name) const { out << *specifier_; - modifier_->Output(out, 0, identifier_, true); + modifier_->Output(out, 0, name, true); +} + +void CYType::Output(CYOutput &out) const { + Output(out, NULL); } void CYEncodedType::Output(CYOutput &out, CYFlags flags) const { @@ -737,7 +744,7 @@ void CYEncodedType::Output(CYOutput &out, CYFlags flags) const { } void CYTypedParameter::Output(CYOutput &out) const { - out << typed_; + type_->Output(out, name_); if (next_ != NULL) out << ',' << ' ' << next_; } @@ -751,7 +758,8 @@ void CYLambda::Output(CYOutput &out, CYFlags flags) const { } void CYTypeDefinition::Output(CYOutput &out, CYFlags flags) const { - out << "typedef" << ' ' << *typed_; + out << "typedef" << ' '; + type_->Output(out, name_); out.Terminate(); } @@ -994,7 +1002,8 @@ void CYStructTail::Output(CYOutput &out) const { out << ' ' << '{' << '\n'; ++out.indent_; CYForEach (field, fields_) { - out << '\t' << *field->typed_; + out << '\t'; + field->type_->Output(out, field->name_); out.Terminate(); out << '\n'; } diff --git a/Parser.ypp.in b/Parser.ypp.in index c3f2379..9db7666 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -89,8 +89,10 @@ %union { CYTypeModifier *modifier_; } %union { CYTypeSpecifier *specifier_; } %union { CYTypedFormal *typedFormal_; } -%union { CYTypedIdentifier *typedIdentifier_; } +%union { CYTypedLocation *typedLocation_; } +%union { CYTypedName *typedName_; } %union { CYTypedParameter *typedParameter_; } +%union { CYType *typedThing_; } @end @begin ObjectiveC @@ -678,28 +680,28 @@ type; }) %type IntegerNumber %type IntegerType %type IntegerTypeOpt -%type PrefixedType +%type PrefixedType %type PrimitiveReference %type PrimitiveType %type StructFieldListOpt -%type SuffixedType -%type SuffixedTypeOpt -%type TypeSignifier -%type TypeSignifierNone -%type TypeSignifierOpt +%type SuffixedType +%type SuffixedTypeOpt +%type TypeSignifier +%type TypeSignifierNone +%type TypeSignifierOpt %type TypeSigning %type ParameterTail %type TypeQualifierLeft %type TypeQualifierLeftOpt -%type TypeQualifierRight -%type TypeQualifierRightOpt -%type TypedIdentifierDefinition -%type TypedIdentifierEncoding -%type TypedIdentifierField -%type TypedIdentifierMaybe -%type TypedIdentifierNo -%type TypedIdentifierTagged -%type TypedIdentifierYes +%type TypeQualifierRight +%type TypeQualifierRightOpt +%type TypedIdentifierDefinition +%type TypedIdentifierEncoding +%type TypedIdentifierField +%type TypedIdentifierMaybe +%type TypedIdentifierNo +%type TypedIdentifierTagged +%type TypedIdentifierYes %type TypedParameterList_ %type TypedParameterList %type TypedParameterListOpt @@ -735,7 +737,7 @@ type; }) %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type TypeOpt +%type TypeOpt %type VariadicCall @end @@ -2027,12 +2029,13 @@ ExportSpecifier @begin C /* Cycript (C): Type Encoding {{{ */ TypeSignifier - : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); } + : IdentifierType[name] { $$ = CYNew CYTypedName(@name, $name); } + | StringLiteral[name] { $$ = CYNew CYTypedName(@name, $name); } | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } ; TypeSignifierNone - : { $$ = CYNew CYTypedIdentifier(@$); } + : { $$ = CYNew CYTypedName(@$); } ; TypeSignifierOpt @@ -2067,7 +2070,7 @@ SuffixedType : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); } | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); } | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } - | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedName(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } ; SuffixedTypeOpt @@ -2116,7 +2119,7 @@ IntegerTypeOpt ; StructFieldListOpt - : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); } + : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $typed->name_, $next); } | { $$ = NULL; } ; @@ -2163,11 +2166,11 @@ TypedIdentifierMaybe ; TypedIdentifierYes - : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } + : TypedIdentifierMaybe[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } ; TypedIdentifierNo - : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } + : TypedIdentifierMaybe[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } ; TypedIdentifierTagged @@ -2177,18 +2180,18 @@ TypedIdentifierTagged TypedIdentifierField : TypedIdentifierYes[pass] { $$ = $pass; } - | TypedIdentifierTagged[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } + | TypedIdentifierTagged[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } ; TypedIdentifierEncoding : TypedIdentifierNo[pass] { $$ = $pass; } - | TypedIdentifierTagged[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } + | TypedIdentifierTagged[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } | "void" TypeSignifierNone[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } ; TypedIdentifierDefinition : TypedIdentifierYes[pass] { $$ = $pass; } - | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } | "void" TypeSignifier[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } ; @@ -2207,7 +2210,7 @@ ClassSuperOpt ; ImplementationFieldListOpt - : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); } + : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $typed->name_, $next); } | { $$ = NULL; } ; @@ -2218,11 +2221,11 @@ MessageScope TypeOpt : "(" TypedIdentifierNo[type] ")" { $$ = $type; } - | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); } + | { $$ = CYNew CYType(CYNew CYTypeVariable("id")); } ; MessageParameter - : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); } + : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $$ = CYNew CYMessageParameter($tag, $type, $identifier); } ; MessageParameterList @@ -2236,7 +2239,7 @@ MessageParameterListOpt MessageParameters : MessageParameterList[pass] { $$ = $pass; } - | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); } + | Word[tag] { $$ = CYNew CYMessageParameter($tag); } ; ClassMessageDeclaration @@ -2418,7 +2421,7 @@ TypedParameterList_ ; TypedParameterList - : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); } + : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, identifier, $$->parameters_); } | "..." { $$ = CYNew CYTypedFormal(true); } ; @@ -2456,7 +2459,7 @@ IdentifierNoOf ; TypeDefinition - : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); } + : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = CYNew CYTypeDefinition($typed, identifier); } ; Statement__ @@ -2473,7 +2476,7 @@ IdentifierNoOf ; ExternCStatement - : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternalDefinition(CYNew CYString("C"), $typed); } + : TypedIdentifierField[typed] TerminatorHard { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = CYNew CYExternalDefinition(CYNew CYString("C"), $typed, identifier); } | TypeDefinition[pass] { $$ = $pass; } ; @@ -2496,7 +2499,7 @@ Statement__ ; PrimaryExpression - : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed); } + : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed, $typed->name_); } ; /* }}} */ @end diff --git a/Replace.cpp b/Replace.cpp index 103f6f8..f84d7e3 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -390,11 +390,11 @@ CYTarget *CYExtend::Replace(CYContext &context) { } CYStatement *CYExternalDefinition::Replace(CYContext &context) { - return $E($ CYAssign($V(typed_->identifier_), $ CYExternalExpression(abi_, typed_))); + return $E($ CYAssign($V(name_), $ CYExternalExpression(abi_, type_, name_))); } CYTarget *CYExternalExpression::Replace(CYContext &context) { - return $C1(typed_->Replace(context), $C2($V("dlsym"), $V("RTLD_DEFAULT"), $S(typed_->identifier_->Word()))); + return $C1(type_->Replace(context), $C2($V("dlsym"), $V("RTLD_DEFAULT"), name_->PropertyName(context))); } CYNumber *CYFalse::Number(CYContext &context) { @@ -1099,6 +1099,12 @@ CYString *CYString::Concat(CYContext &context, CYString *rhs) const { return $S(value, size); } +CYIdentifier *CYString::Identifier() const { + if (const char *word = Word()) + return $ CYIdentifier(word); + return NULL; +} + CYNumber *CYString::Number(CYContext &context) { // XXX: there is a precise algorithm for this return NULL; @@ -1124,14 +1130,13 @@ CYTarget *CYStructTail::Replace(CYContext &context) { CYList names; CYForEach (field, fields_) { - CYTypedIdentifier *typed(field->typed_); - types->*$ CYElementValue(typed->Replace(context)); + types->*$ CYElementValue(field->type_->Replace(context)); CYExpression *name; - if (typed->identifier_ == NULL) + if (field->name_ == NULL) name = NULL; else - name = $S(typed->identifier_->Word()); + name = field->name_->PropertyName(context); names->*$ CYElementValue(name); } @@ -1231,9 +1236,7 @@ CYTarget *CYTypeConstant::Replace_(CYContext &context, CYTarget *type) { } CYStatement *CYTypeDefinition::Replace(CYContext &context) { - CYIdentifier *identifier(typed_->identifier_); - typed_->identifier_ = NULL; - return $ CYLexical(false, $B1($B(identifier, $ CYTypeExpression(typed_)))); + return $ CYLexical(false, $B1($B(name_, $ CYTypeExpression(type_)))); } CYTarget *CYTypeEnum::Replace(CYContext &context) { @@ -1317,11 +1320,11 @@ CYTarget *CYTypeVolatile::Replace_(CYContext &context, CYTarget *type) { return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("volatile")))); } -CYTarget *CYTypedIdentifier::Replace(CYContext &context) { +CYTarget *CYType::Replace(CYContext &context) { return modifier_->Replace(context, specifier_->Replace(context)); } -CYTypeFunctionWith *CYTypedIdentifier::Function() { +CYTypeFunctionWith *CYType::Function() { CYTypeModifier *&modifier(CYGetLast(modifier_)); if (modifier == NULL) return NULL; @@ -1335,15 +1338,15 @@ CYTypeFunctionWith *CYTypedIdentifier::Function() { } CYArgument *CYTypedParameter::Argument(CYContext &context) { $T(NULL) - return $ CYArgument(typed_->Replace(context), next_->Argument(context)); + return $ CYArgument(type_->Replace(context), next_->Argument(context)); } CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL) - return $ CYFunctionParameter($ CYBinding(typed_->identifier_ ?: context.Unique()), next_->Parameters(context)); + return $ CYFunctionParameter($ CYBinding(name_ ?: context.Unique()), next_->Parameters(context)); } CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix) - return next_->TypeSignature(context, $ CYAdd(prefix, typed_->Replace(context))); + return next_->TypeSignature(context, $ CYAdd(prefix, type_->Replace(context))); } CYForInitializer *CYVar::Replace(CYContext &context) { diff --git a/Syntax.hpp b/Syntax.hpp index 5b74e43..5f9d705 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -120,6 +120,7 @@ struct CYOutput { struct CYExpression; struct CYAssignment; +struct CYIdentifier; struct CYPropertyName { virtual bool Computed() const { @@ -130,6 +131,10 @@ struct CYPropertyName { return false; } + virtual CYIdentifier *Identifier() { + return NULL; + } + virtual CYExpression *PropertyName(CYContext &context) = 0; virtual void PropertyName(CYOutput &out) const = 0; }; @@ -271,6 +276,10 @@ struct CYIdentifier : { } + CYIdentifier *Identifier() override { + return this; + } + virtual const char *Word() const; CYIdentifier *Replace(CYContext &context, CYIdentifierKind); }; @@ -780,6 +789,7 @@ struct CYString : return value_; } + virtual CYIdentifier *Identifier() const; virtual const char *Word() const; virtual CYNumber *Number(CYContext &context); @@ -2195,8 +2205,8 @@ struct CYTypeModifier : virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0; CYTarget *Replace(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0; - void Output(CYOutput &out, int precedence, CYIdentifier *identifier, bool space) const; + virtual void Output(CYOutput &out, CYPropertyName *name) const = 0; + void Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const; virtual CYTypeFunctionWith *Function() { return NULL; } }; @@ -2215,7 +2225,7 @@ struct CYTypeArrayOf : CYPrecedence(1) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypeConstant : @@ -2229,7 +2239,7 @@ struct CYTypeConstant : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypePointerTo : @@ -2243,7 +2253,7 @@ struct CYTypePointerTo : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypeVolatile : @@ -2257,50 +2267,63 @@ struct CYTypeVolatile : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; -struct CYTypedIdentifier : - CYNext, +struct CYType : CYThing { - CYLocation location_; - CYIdentifier *identifier_; CYTypeSpecifier *specifier_; CYTypeModifier *modifier_; - CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) : - location_(location), - identifier_(identifier), - specifier_(NULL), - modifier_(NULL) - { - } - - CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) : - identifier_(NULL), + CYType(CYTypeSpecifier *specifier = NULL, CYTypeModifier *modifier = NULL) : specifier_(specifier), modifier_(modifier) { } - inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) { + inline CYType *Modify(CYTypeModifier *modifier) { CYSetLast(modifier_) = modifier; return this; } + void Output(CYOutput &out, CYPropertyName *name) const; + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out) const; CYTypeFunctionWith *Function(); }; +struct CYTypedLocation : + CYType +{ + CYLocation location_; + + CYTypedLocation(const CYLocation &location) : + location_(location) + { + } +}; + +struct CYTypedName : + CYTypedLocation +{ + CYPropertyName *name_; + + CYTypedName(const CYLocation &location, CYPropertyName *name = NULL) : + CYTypedLocation(location), + name_(name) + { + } +}; + struct CYEncodedType : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; - CYEncodedType(CYTypedIdentifier *typed) : + CYEncodedType(CYType *typed) : typed_(typed) { } @@ -2315,11 +2338,13 @@ struct CYTypedParameter : CYNext, CYThing { - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next = NULL) : + CYTypedParameter(CYType *type, CYIdentifier *name, CYTypedParameter *next = NULL) : CYNext(next), - typed_(typed) + type_(type), + name_(name) { } @@ -2344,11 +2369,11 @@ struct CYTypedFormal { struct CYLambda : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; CYTypedParameter *parameters_; CYStatement *code_; - CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) : + CYLambda(CYType *typed, CYTypedParameter *parameters, CYStatement *code) : typed_(typed), parameters_(parameters), code_(code) @@ -2430,11 +2455,13 @@ struct CYExternalExpression : CYTarget { CYString *abi_; - CYTypedIdentifier *typed_; + CYType *type_; + CYPropertyName *name_; - CYExternalExpression(CYString *abi, CYTypedIdentifier *typed) : + CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) : abi_(abi), - typed_(typed) + type_(type), + name_(name) { } @@ -2448,11 +2475,13 @@ struct CYExternalDefinition : CYStatement { CYString *abi_; - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYExternalDefinition(CYString *abi, CYTypedIdentifier *typed) : + CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) : abi_(abi), - typed_(typed) + type_(type), + name_(name) { } @@ -2465,9 +2494,9 @@ struct CYExternalDefinition : struct CYTypeExpression : CYTarget { - CYTypedIdentifier *typed_; + CYType *typed_; - CYTypeExpression(CYTypedIdentifier *typed) : + CYTypeExpression(CYType *typed) : typed_(typed) { } @@ -2481,10 +2510,12 @@ struct CYTypeExpression : struct CYTypeDefinition : CYStatement { - CYTypedIdentifier *typed_; + CYType *type_; + CYIdentifier *name_; - CYTypeDefinition(CYTypedIdentifier *typed) : - typed_(typed) + CYTypeDefinition(CYType *type, CYIdentifier *name) : + type_(type), + name_(name) { } @@ -2508,7 +2539,7 @@ struct CYTypeBlockWith : CYPrecedence(0) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; }; struct CYTypeFunctionWith : @@ -2527,7 +2558,7 @@ struct CYTypeFunctionWith : CYPrecedence(1) virtual CYTarget *Replace_(CYContext &context, CYTarget *type); - virtual void Output(CYOutput &out, CYIdentifier *identifier) const; + void Output(CYOutput &out, CYPropertyName *name) const override; virtual CYTypeFunctionWith *Function() { return this; } }; @@ -2535,11 +2566,13 @@ struct CYTypeFunctionWith : struct CYTypeStructField : CYNext { - CYTypedIdentifier *typed_; + CYType *type_; + CYPropertyName *name_; - CYTypeStructField(CYTypedIdentifier *typed, CYTypeStructField *next = NULL) : + CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) : CYNext(next), - typed_(typed) + type_(type), + name_(name) { } }; diff --git a/sig/types.hpp b/sig/types.hpp index 2f536ac..d32d1da 100644 --- a/sig/types.hpp +++ b/sig/types.hpp @@ -36,7 +36,7 @@ #include "Standard.hpp" class CYPool; -struct CYTypedIdentifier; +struct CYType; struct CYTypedParameter; namespace sig { @@ -61,7 +61,7 @@ struct Type { virtual const char *GetName() const; virtual const char *Encode(CYPool &pool) const = 0; - virtual CYTypedIdentifier *Decode(CYPool &pool) const = 0; + virtual CYType *Decode(CYPool &pool) const = 0; virtual ffi_type *GetFFI(CYPool &pool) const = 0; virtual void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const = 0; @@ -77,7 +77,7 @@ struct Primitive : } const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -101,7 +101,7 @@ struct Void : Void *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -114,7 +114,7 @@ struct Unknown : Unknown *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -127,7 +127,7 @@ struct String : String *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -141,7 +141,7 @@ struct Meta : Meta *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -154,7 +154,7 @@ struct Selector : Selector *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -175,7 +175,7 @@ struct Bits : Bits *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -195,7 +195,7 @@ struct Pointer : Pointer *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -217,7 +217,7 @@ struct Array : Array *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -238,7 +238,7 @@ struct Object : Object *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -272,7 +272,7 @@ struct Enum : const char *GetName() const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -296,7 +296,7 @@ struct Aggregate : const char *GetName() const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; + CYType *Decode(CYPool &pool) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -308,8 +308,8 @@ struct Callable : { Signature signature; - CYTypedIdentifier *Decode(CYPool &pool) const override; - virtual CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const = 0; + CYType *Decode(CYPool &pool) const override; + virtual CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const = 0; }; struct Function : @@ -325,7 +325,7 @@ struct Function : Function *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override; + CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; @@ -339,8 +339,8 @@ struct Block : Block *Copy(CYPool &pool, const char *rename = NULL) const override; const char *Encode(CYPool &pool) const override; - CYTypedIdentifier *Decode(CYPool &pool) const override; - CYTypedIdentifier *Modify(CYPool &pool, CYTypedIdentifier *result, CYTypedParameter *parameters) const override; + CYType *Decode(CYPool &pool) const override; + CYType *Modify(CYPool &pool, CYType *result, CYTypedParameter *parameters) const override; ffi_type *GetFFI(CYPool &pool) const override; void PoolFFI(CYPool *pool, JSContextRef context, ffi_type *ffi, void *data, JSValueRef value) const override; -- 2.45.2