X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/663c538f2306bb586edeb3e7ff501863acf8e89b..c22e009d49bb891a560f8a6219fe3499859eff4b:/Replace.cpp diff --git a/Replace.cpp b/Replace.cpp index f1283de..f914af9 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -289,6 +289,10 @@ CYStatement *CYEmpty::Replace(CYContext &context) { return NULL; } +CYExpression *CYEncodedType::Replace(CYContext &context) { + return typed_->Replace(context); +} + CYStatement *CYExpress::Replace(CYContext &context) { while (CYExpress *express = dynamic_cast(next_)) { CYCompound *compound(dynamic_cast(express->expression_)); @@ -522,13 +526,26 @@ CYStatement *CYLabel::Replace(CYContext &context) { } CYExpression *CYLambda::Replace(CYContext &context) { - return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_), parameters_->TypeSignature(context, type_->Replace(context))); + return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_), parameters_->TypeSignature(context, typed_->Replace(context))); } CYStatement *CYLetStatement::Replace(CYContext &context) { return $E($ CYCall(CYNonLocalize(context, $ CYFunctionExpression(NULL, declarations_->Parameter(context), code_)), declarations_->Argument(context))); } +CYExpression *CYMultiply::Replace(CYContext &context) { + CYInfix::Replace(context); + + CYExpression *lhp(lhs_->Primitive(context)); + CYExpression *rhp(rhs_->Primitive(context)); + + if (CYNumber *lhn = lhp->Number(context)) + if (CYNumber *rhn = rhp->Number(context)) + return $D(lhn->Value() * rhn->Value()); + + return this; +} + namespace cy { namespace Syntax { @@ -865,32 +882,73 @@ CYStatement *Try::Replace(CYContext &context) { } } -CYExpression *CYTypeArrayOf::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("arrayOf")), $ CYArgument(size_)); +CYExpression *CYTypeArrayOf::Replace_(CYContext &context, CYExpression *type) { + return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("arrayOf")), $ CYArgument(size_))); } -CYExpression *CYTypeConstant::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("constant"))); +CYExpression *CYTypeBlockWith::Replace_(CYContext &context, CYExpression *type) { + return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("blockWith")), parameters_->Argument(context))); +} + +CYExpression *CYTypeConstant::Replace_(CYContext &context, CYExpression *type) { + return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("constant")))); } CYStatement *CYTypeDefinition::Replace(CYContext &context) { - return $E($ CYAssign($V(typed_->identifier_), typed_->type_->Replace(context))); + return $E($ CYAssign($V(typed_->identifier_), typed_->Replace(context))); +} + +CYExpression *CYTypeError::Replace(CYContext &context) { + _assert(false); + return NULL; +} + +CYExpression *CYTypeModifier::Replace(CYContext &context, CYExpression *type) { $T(type) + return Replace_(context, type); +} + +CYExpression *CYTypeFunctionWith::Replace_(CYContext &context, CYExpression *type) { + return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("functionWith")), parameters_->Argument(context))); +} + +CYExpression *CYTypeLong::Replace(CYContext &context) { + return $ CYCall($ CYDirectMember(specifier_->Replace(context), $ CYString("long"))); +} + +CYExpression *CYTypePointerTo::Replace_(CYContext &context, CYExpression *type) { + return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("pointerTo")))); } -CYExpression *CYTypeFunctionWith::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("functionWith")), parameters_->Argument(context)); +CYExpression *CYTypeShort::Replace(CYContext &context) { + return $ CYCall($ CYDirectMember(specifier_->Replace(context), $ CYString("short"))); } -CYExpression *CYTypePointerTo::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("pointerTo"))); +CYExpression *CYTypeSigned::Replace(CYContext &context) { + return $ CYCall($ CYDirectMember(specifier_->Replace(context), $ CYString("signed"))); +} + +CYExpression *CYTypeUnsigned::Replace(CYContext &context) { + return $ CYCall($ CYDirectMember(specifier_->Replace(context), $ CYString("unsigned"))); } CYExpression *CYTypeVariable::Replace(CYContext &context) { - return expression_; + return $V(name_); +} + +CYExpression *CYTypeVoid::Replace(CYContext &context) { + return $N1($V("Type"), $ CYString("v")); +} + +CYExpression *CYTypeVolatile::Replace_(CYContext &context, CYExpression *type) { + return next_->Replace(context, $ CYCall($ CYDirectMember(type, $ CYString("volatile")))); +} + +CYExpression *CYTypedIdentifier::Replace(CYContext &context) { + return modifier_->Replace(context, specifier_->Replace(context)); } CYArgument *CYTypedParameter::Argument(CYContext &context) { $T(NULL) - return $ CYArgument(typed_->type_->Replace(context), next_->Argument(context)); + return $ CYArgument(typed_->Replace(context), next_->Argument(context)); } CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL) @@ -898,7 +956,7 @@ CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL) } CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix) - return next_->TypeSignature(context, $ CYAdd(prefix, typed_->type_->Replace(context))); + return next_->TypeSignature(context, $ CYAdd(prefix, typed_->Replace(context))); } CYStatement *CYVar::Replace(CYContext &context) {