X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b0385401f63fe31f3cc1459ed159747a445852d6..447b698cea96010d0850e056348ef6cd085b96d9:/ObjectiveC/Syntax.hpp diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index 8beabb9..d185f0d 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -22,10 +22,10 @@ #ifndef CYCRIPT_OBJECTIVEC_SYNTAX_HPP #define CYCRIPT_OBJECTIVEC_SYNTAX_HPP -#include "Parser.hpp" +#include "../Syntax.hpp" struct CYInstanceLiteral : - CYExpression + CYTarget { CYNumber *number_; @@ -36,18 +36,18 @@ struct CYInstanceLiteral : CYPrecedence(1) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYObjCBlock : - CYExpression + 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) @@ -56,12 +56,12 @@ struct CYObjCBlock : CYPrecedence(1) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYBox : - CYExpression + CYTarget { CYExpression *value_; @@ -72,7 +72,53 @@ struct CYBox : CYPrecedence(1) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYObjCArray : + CYTarget +{ + CYElement *elements_; + + CYObjCArray(CYElement *elements = NULL) : + elements_(elements) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYObjCKeyValue : + CYNext +{ + CYExpression *key_; + CYExpression *value_; + + CYObjCKeyValue(CYExpression *key, CYExpression *value, CYObjCKeyValue *next) : + CYNext(next), + key_(key), + value_(value) + { + } +}; + +struct CYObjCDictionary : + CYTarget +{ + CYObjCKeyValue *pairs_; + + CYObjCDictionary(CYObjCKeyValue *pairs) : + pairs_(pairs) + { + } + + CYPrecedence(0) + + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -97,27 +143,29 @@ struct CYSelectorPart : struct CYSelector : CYLiteral { - CYSelectorPart *name_; + CYSelectorPart *parts_; - CYSelector(CYSelectorPart *name) : - name_(name) + CYSelector(CYSelectorPart *parts) : + parts_(parts) { } CYPrecedence(1) - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYClassField : - CYNext +struct CYImplementationField : + CYNext { - CYTypedIdentifier *typed_; + CYType *type_; + CYPropertyName *name_; - CYClassField(CYTypedIdentifier *typed, CYClassField *next = NULL) : - CYNext(next), - typed_(typed) + CYImplementationField(CYType *type, CYPropertyName *name, CYImplementationField *next = NULL) : + CYNext(next), + type_(type), + name_(name) { } @@ -128,12 +176,15 @@ struct CYClassField : struct CYMessageParameter : CYNext { - CYWord *tag_; - CYTypedIdentifier *type_; + CYWord *name_; + CYType *type_; + CYIdentifier *identifier_; - CYMessageParameter(CYWord *tag, CYTypedIdentifier *type) : - tag_(tag), - type_(type) + CYMessageParameter(CYWord *name, CYType *type = NULL, CYIdentifier *identifier = NULL, CYMessageParameter *next = NULL) : + CYNext(next), + name_(name), + type_(type), + identifier_(identifier) { } @@ -147,20 +198,20 @@ struct CYMessage : CYNext { bool instance_; - CYTypedIdentifier *type_; + CYType *type_; CYMessageParameter *parameters_; CYBlock code_; - CYMessage(bool instance, CYTypedIdentifier *type, CYMessageParameter *parameter, CYStatement *code) : + CYMessage(bool instance, CYType *type, CYMessageParameter *parameters, CYStatement *code) : instance_(instance), type_(type), - parameters_(parameter), + parameters_(parameters), code_(code) { } CYStatement *Replace(CYContext &context, bool replace) const; - void Output(CYOutput &out, bool replace) const; + void Output(CYOutput &out) const; CYExpression *TypeSignature(CYContext &context) const; }; @@ -181,52 +232,25 @@ struct CYProtocol : void Output(CYOutput &out) const; }; -struct CYClass { - CYClassName *name_; - CYExpression *super_; +struct CYImplementation : + CYStatement +{ + CYIdentifier *name_; + CYExpression *extends_; CYProtocol *protocols_; - CYClassField *fields_; + CYImplementationField *fields_; CYMessage *messages_; - CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : + CYImplementation(CYIdentifier *name, CYExpression *extends, CYProtocol *protocols, CYImplementationField *fields, CYMessage *messages) : name_(name), - super_(super), + extends_(extends), protocols_(protocols), fields_(fields), messages_(messages) { } - virtual ~CYClass() { - } - - CYExpression *Replace_(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - -struct CYClassExpression : - CYClass, - CYExpression -{ - CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : - CYClass(name, super, protocols, fields, messages) - { - } - - CYPrecedence(0) - - virtual CYExpression *Replace(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - -struct CYClassStatement : - CYClass, - CYStatement -{ - CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) : - CYClass(name, super, protocols, fields, messages) - { - } + CYCompact(None) virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; @@ -235,21 +259,23 @@ struct CYClassStatement : struct CYCategory : CYStatement { - CYClassName *name_; + CYIdentifier *name_; CYMessage *messages_; - CYCategory(CYClassName *name, CYMessage *messages) : + CYCategory(CYIdentifier *name, CYMessage *messages) : name_(name), messages_(messages) { } + CYCompact(None) + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYSend : - CYExpression + CYTarget { CYArgument *arguments_; @@ -274,7 +300,7 @@ struct CYSendDirect : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -286,7 +312,7 @@ struct CYSendSuper : { } - virtual CYExpression *Replace(CYContext &context); + virtual CYTarget *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; };