public FunctionCall ConvertIndexerIntoSetter(IExpression rhs) { this.ChildrenNodes.WhereType <IOwnedNode>().ForEach(it => it.DetachFrom(this)); NameReference idx_getter = this.Name; idx_getter.Prefix.DetachFrom(idx_getter); return(new FunctionCall(CallMode.Indexer, NameReference.Create(this.Name.Prefix, NameFactory.PropertySetter), this.UserArguments.Concat(FunctionArgument.Create(NameFactory.PropertySetterValueParameter, rhs)), requestedOutcomeType: null)); }
public static IExpression DownCast(IExpression lhs, INameReference rhsTypeName) { // if the expression is not of the given type we get null // if it is the runtime type IS PRESERVED // say you have statically types object // x *Object // and in runtime x is Orange // if you cast it to Vehicle you will get null, when you cast it to Fruit you will get Orange (sic!) IExpression condition = IsType.Create(lhs, rhsTypeName); IExpression success = ExpressionFactory.StackConstructor(NameFactory.OptionNameReference(rhsTypeName), FunctionArgument.Create(ReinterpretType.Create(lhs, rhsTypeName))); IExpression failure = ExpressionFactory.StackConstructor(NameFactory.OptionNameReference(rhsTypeName)); return(IfBranch.CreateIf(condition, new[] { success }, IfBranch.CreateElse(new[] { failure }))); }
private static CallContext createCallContext(ComputationContext ctx, NameReference name, FunctionDefinition callTarget) { IExpression this_context = name.GetContext(callTarget); if (this_context == null) { return(new CallContext()); } this_context.Evaluated(ctx, EvaluationCall.AdHocCrossJump); bool is_static_call; if (callTarget.IsExtension) { is_static_call = this_context is NameReference name_ref && name_ref.Binding.Match.Instance.Target is Extension; } else { is_static_call = callTarget.Modifier.HasStatic; } if (is_static_call) { return new CallContext() { StaticContext = this_context.Evaluation.Components } } ; else { return new CallContext() { MetaThisArgument = FunctionArgument.Create(this_context) } }; }
internal void RouteSetup(int?minLimit, int?max1Limit) { if (this.prepared) { throw new Exception("Something wrong?"); } this.prepared = true; this.expr.DetachFrom(this); if (max1Limit.HasValue) { this.expr = FunctionCall.Create(NameFactory.SpreadFunctionReference(), FunctionArgument.Create(this.expr), FunctionArgument.Create(NatLiteral.Create($"{minLimit}")), FunctionArgument.Create(NatLiteral.Create($"{max1Limit}"))); } else { this.expr = FunctionCall.Create(NameFactory.SpreadFunctionReference(), FunctionArgument.Create(this.expr), FunctionArgument.Create(NatLiteral.Create($"{minLimit}"))); } this.expr.AttachTo(this); }
public static FunctionCall Constructor(IExpression name, params IExpression[] arguments) { return(Constructor(name, arguments.Select(it => FunctionArgument.Create(it)).ToArray())); }
public static FunctionCall Indexer(IExpression expr, params IExpression[] arguments) { return(Indexer(expr, arguments.Select(it => FunctionArgument.Create(it)).ToArray())); }
public static IExpression IsNotEqual(IExpression lhs, IExpression rhs) { return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.NotEqualOperator), FunctionArgument.Create(rhs))); }
public static IExpression Divide(IExpression lhs, IExpression rhs) { return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.DivideOperator), FunctionArgument.Create(rhs))); }
public static IExpression AddOverflow(IExpression lhs, IExpression rhs) { return(FunctionCall.Create(NameReference.Create(lhs, NameFactory.AddOverflowOperator), FunctionArgument.Create(rhs))); }
public static IExpression InitializeIndexable(string name, params IExpression[] arguments) { return(Block.CreateStatement(arguments.ZipWithIndex().Select(it => Assignment.CreateStatement(FunctionCall.Indexer(NameReference.Create(name), FunctionArgument.Create(NatLiteral.Create($"{it.Item2}"))), it.Item1)))); }