public static IExpression Tuple(params IExpression[] arguments) { if (arguments.Length == 0) { throw new System.Exception(); } else if (arguments.Length == 1) { return(arguments.Single()); } else { return(FunctionCall.Create(NameReference.Create(NameFactory.TupleFactoryReference(), NameFactory.CreateFunctionName), arguments)); } }
public static TypeBuilder WithComparableCompare(this TypeBuilder builder, EntityModifier modifier = null) { return(builder.With(FunctionBuilder.Create(NameFactory.ComparableCompare, ExpressionReadMode.ReadRequired, NameFactory.OrderingNameReference(), Block.CreateStatement( IfBranch.CreateIf(IsSame.Create(NameReference.CreateThised(), NameReference.Create("cmp")), new[] { Return.Create(NameFactory.OrderingEqualReference()) }), // let obj = cmp cast? Self VariableDeclaration.CreateStatement("obj", null, ExpressionFactory.CheckedSelfCast("cmp", NameFactory.ReferenceNameReference(builder.CreateTypeNameReference(TypeMutability.ReadOnly)))), // return this.compare(obj.value) Return.Create(FunctionCall.Create(NameReference.CreateThised(NameFactory.ComparableCompare), NameReference.Create("obj"))))) .SetModifier(EntityModifier.Override | modifier) .Parameters(FunctionParameter.Create("cmp", NameFactory.ReferenceNameReference(NameFactory.IComparableNameReference(TypeMutability.ReadOnly)))))); }
public static IExpression CheckedSelfCast(string paramName, INameReference currentTypeName) { return(Block.CreateExpression( // this is basically check for Self type // assert this.getType()==other.GetType() // please note // assert other is CurrentType // has different (and incorrect) meaning, because it does not really check both entities type // consider this to be IFooChild of IFoo->IFooParent->IFooChild // and current type would be IFooParent and the other would be of this type AssertTrue(IsSame.Create(FunctionCall.Create(NameReference.CreateThised(NameFactory.GetTypeFunctionName)), FunctionCall.Create(NameReference.Create(paramName, NameFactory.GetTypeFunctionName)))), // maybe in future it would be possible to dynamically cast to the actual type of other // this would mean static dispatch to later calls ExpressionFactory.GetOptionValue(ExpressionFactory.DownCast(NameReference.Create(paramName), currentTypeName)) )); }
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 IExpression Not(IExpression expr) { return(FunctionCall.Create(NameReference.Create(expr, NameFactory.NotOperator))); }
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))); }