public Shield() { Front frontPanel = new Front(); Rear rearPanel = new Rear(); Top topPanel = new Top(); Bottom bottomPanel = new Bottom(); Right rightPanel = new Right(); Left leftPanel = new Left(); }
public override int Evaluate(ProgramState state) { return(Left.Evaluate(state) + Right.Evaluate(state)); }
/// <summary> /// Get the expression on the left of the left-most dot operator. /// </summary> public override Expression FirstPrefix() { return(Left.FirstPrefix()); }
protected override INotifyExpression <bool> ApplyParametersCore(IDictionary <string, object> parameters, IDictionary <INotifiable, INotifiable> trace) { return(new ObservableLogicXor(Left.ApplyParameters(parameters, trace), Right.ApplyParameters(parameters, trace))); }
public override void Emit(EmitContext ec) { if (IsBitwiseBoolean && UserOperator == null) { EmitBitwiseBoolean(ec); return; } if ((Binary.Oper & Binary.Operator.EqualityMask) != 0) { EmitEquality(ec); return; } Label is_null_label = ec.DefineLabel(); Label end_label = ec.DefineLabel(); if (ec.HasSet(BuilderContext.Options.AsyncBody) && Right.ContainsEmitWithAwait()) { Left = Left.EmitToField(ec); Right = Right.EmitToField(ec); } if (UnwrapLeft != null) { UnwrapLeft.EmitCheck(ec); } // // Don't emit HasValue check when left and right expressions are same // if (UnwrapRight != null && !Binary.Left.Equals(Binary.Right)) { UnwrapRight.EmitCheck(ec); if (UnwrapLeft != null) { ec.Emit(OpCodes.And); } } ec.Emit(OpCodes.Brfalse, is_null_label); if (UserOperator != null) { var args = new Arguments(2); args.Add(new Argument(Left)); args.Add(new Argument(Right)); var call = new CallEmitter(); call.EmitPredefined(ec, UserOperator, args); } else { Binary.EmitOperator(ec, Left, Right); } // // Wrap the result when the operator return type is nullable type // if (type.IsNullableType) { ec.Emit(OpCodes.Newobj, NullableInfo.GetConstructor(type)); } ec.Emit(OpCodes.Br_S, end_label); ec.MarkLabel(is_null_label); if ((Binary.Oper & Binary.Operator.ComparisonMask) != 0) { ec.EmitInt(0); } else { LiftedNull.Create(type, loc).Emit(ec); } ec.MarkLabel(end_label); }
// // Emits optimized equality or inequality operator when possible // void EmitEquality(EmitContext ec) { // // Either left or right is null // if (UnwrapLeft != null && Binary.Right.IsNull) // TODO: Optimize for EmitBranchable // // left.HasValue == false // { UnwrapLeft.EmitCheck(ec); if (Binary.Oper == Binary.Operator.Equality) { ec.EmitInt(0); ec.Emit(OpCodes.Ceq); } return; } if (UnwrapRight != null && Binary.Left.IsNull) { // // right.HasValue == false // UnwrapRight.EmitCheck(ec); if (Binary.Oper == Binary.Operator.Equality) { ec.EmitInt(0); ec.Emit(OpCodes.Ceq); } return; } Label dissimilar_label = ec.DefineLabel(); Label end_label = ec.DefineLabel(); if (UserOperator != null) { var left = Left; if (UnwrapLeft != null) { UnwrapLeft.EmitCheck(ec); } else { // Keep evaluation order same if (!(Left is VariableReference)) { Left.Emit(ec); var lt = new LocalTemporary(Left.Type); lt.Store(ec); left = lt; } } if (UnwrapRight != null) { UnwrapRight.EmitCheck(ec); if (UnwrapLeft != null) { ec.Emit(OpCodes.Bne_Un, dissimilar_label); Label compare_label = ec.DefineLabel(); UnwrapLeft.EmitCheck(ec); ec.Emit(OpCodes.Brtrue, compare_label); if (Binary.Oper == Binary.Operator.Equality) { ec.EmitInt(1); } else { ec.EmitInt(0); } ec.Emit(OpCodes.Br, end_label); ec.MarkLabel(compare_label); } else { ec.Emit(OpCodes.Brfalse, dissimilar_label); } } else { ec.Emit(OpCodes.Brfalse, dissimilar_label); } var args = new Arguments(2); args.Add(new Argument(left)); args.Add(new Argument(Right)); var call = new CallEmitter(); call.EmitPredefined(ec, UserOperator, args); } else { if (ec.HasSet(BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait()) { Left = Left.EmitToField(ec); Right = Right.EmitToField(ec); } // // Emit underlying value comparison first. // // For this code: int? a = 1; bool b = a == 1; // // We emit something similar to this. Expressions with side effects have local // variable created by Unwrap expression // // left.GetValueOrDefault () // right // bne.un.s dissimilar_label // left.HasValue // br.s end_label // dissimilar_label: // ldc.i4.0 // end_label: // Left.Emit(ec); Right.Emit(ec); ec.Emit(OpCodes.Bne_Un_S, dissimilar_label); // // Check both left and right expressions for Unwrap call in which // case we need to run get_HasValue() check because the type is // nullable and could have null value // if (UnwrapLeft != null) { UnwrapLeft.EmitCheck(ec); } if (UnwrapRight != null) { UnwrapRight.EmitCheck(ec); } if (UnwrapLeft != null && UnwrapRight != null) { if (Binary.Oper == Binary.Operator.Inequality) { ec.Emit(OpCodes.Xor); } else { ec.Emit(OpCodes.Ceq); } } else { if (Binary.Oper == Binary.Operator.Inequality) { ec.EmitInt(0); ec.Emit(OpCodes.Ceq); } } } ec.Emit(OpCodes.Br_S, end_label); ec.MarkLabel(dissimilar_label); if (Binary.Oper == Binary.Operator.Inequality) { ec.EmitInt(1); } else { ec.EmitInt(0); } ec.MarkLabel(end_label); }
public decimal Interpret(Dictionary <string, decimal> context) { return(Left.Interpret(context) * Right.Interpret(context)); }
public override bool IsSatisfiedBy(TEntity obj) { return(Left.IsSatisfiedBy(obj) || Right.IsSatisfiedBy(obj)); }
public static bool operator >=(Version Left, Version Right) { return(Left.CompareTo(Right) >= 0); }
/// <summary> /// Gets the LINQ expression which represents the current specification. /// </summary> /// <returns>The LINQ expression.</returns> public override Expression <Func <T, bool> > GetExpression() { //var body = Expression.AndAlso(Left.GetExpression().Body, Right.GetExpression().Body); //return Expression.Lambda<Func<T, bool>>(body, Left.GetExpression().Parameters); return(Left.GetExpression().And(Right.GetExpression())); }
public override bool IsStatic() { return(Left.IsStatic()); }
public override HlTypeDefinition GetResultType(HlCompilation c) { return(Left.GetResultType(c)); }
public override void SetChildrenScopes(NovaScope scope) { Left.SetScope(scope); Right.SetScope(scope); }
protected virtual void OnLeft() { Left?.Invoke(this); }
public override void RenameUses(Identifier orig, Identifier newi) { Left.RenameUses(orig, newi); Right.RenameUses(orig, newi); }
public override int GetHashCode() { return(Left.GetHashCode() ^ Right.GetHashCode()); }
/// <summary> /// Apply the member constraints to an actual value, succeeding /// succeeding as soon as one of them succeeds. /// </summary> /// <param name="actual">The actual value</param> /// <returns>True if either constraint succeeded</returns> public override ConstraintResult ApplyTo <TActual>(TActual actual) { bool hasSucceeded = Left.ApplyTo(actual).IsSuccess || Right.ApplyTo(actual).IsSuccess; return(new ConstraintResult(this, actual, hasSucceeded)); }
public override string Explain() { return($"{Left?.Explain()} {Operation} {Right?.Explain()}"); }
public override double CalculateValue(double calvalue) { return(Math.Pow(Left.CalculateValue(calvalue), Right.CalculateValue(calvalue))); }
public bool Equals(Left other) { var equ = _value.GetType().GetMethods().Where(m => m.Name == "Equals" && m.GetParameters()[0].ParameterType != typeof(object)).Single(); return((bool)equ.Invoke(_value, new object[] { other == null ? null : other._value })); }
public override string ToString() { return($"({Left.ToString()}+{Right.ToString()})"); }
public override bool ContainsEmitWithAwait() { return(Left.ContainsEmitWithAwait() || Right.ContainsEmitWithAwait()); }
public override double CalculateValue(double calvalue) { return(Left.CalculateValue(calvalue) + Right.CalculateValue(calvalue)); }
void EmitBitwiseBoolean(EmitContext ec) { Label load_left = ec.DefineLabel(); Label load_right = ec.DefineLabel(); Label end_label = ec.DefineLabel(); Label is_null_label = ec.DefineLabel(); bool or = Binary.Oper == Binary.Operator.BitwiseOr; // // Both operands are bool? types // if (UnwrapLeft != null && UnwrapRight != null) { if (ec.HasSet(BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait()) { Left = Left.EmitToField(ec); Right = Right.EmitToField(ec); } else { UnwrapLeft.Store(ec); UnwrapRight.Store(ec); } Left.Emit(ec); ec.Emit(OpCodes.Brtrue_S, load_right); Right.Emit(ec); ec.Emit(OpCodes.Brtrue_S, load_left); UnwrapLeft.EmitCheck(ec); ec.Emit(OpCodes.Brfalse_S, load_right); // load left ec.MarkLabel(load_left); if (or) { UnwrapRight.Load(ec); } else { UnwrapLeft.Load(ec); } ec.Emit(OpCodes.Br_S, end_label); // load right ec.MarkLabel(load_right); if (or) { UnwrapLeft.Load(ec); } else { UnwrapRight.Load(ec); } ec.MarkLabel(end_label); return; } // // Faster version when one operand is bool // if (UnwrapLeft == null) { // // (bool, bool?) // // Optimizes remaining (false & bool?), (true | bool?) which are not easy to handle // in binary expression reduction // var c = Left as BoolConstant; if (c != null) { // Keep evaluation order UnwrapRight.Store(ec); ec.EmitInt(or ? 1 : 0); ec.Emit(OpCodes.Newobj, NullableInfo.GetConstructor(type)); } else if (Left.IsNull) { UnwrapRight.Emit(ec); ec.Emit(or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, is_null_label); UnwrapRight.Load(ec); ec.Emit(OpCodes.Br_S, end_label); ec.MarkLabel(is_null_label); LiftedNull.Create(type, loc).Emit(ec); } else { Left.Emit(ec); ec.Emit(or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, load_right); ec.EmitInt(or ? 1 : 0); ec.Emit(OpCodes.Newobj, NullableInfo.GetConstructor(type)); ec.Emit(OpCodes.Br_S, end_label); ec.MarkLabel(load_right); UnwrapRight.Original.Emit(ec); } } else { // // (bool?, bool) // // Keep left-right evaluation order UnwrapLeft.Store(ec); // // Optimizes remaining (bool? & false), (bool? | true) which are not easy to handle // in binary expression reduction // var c = Right as BoolConstant; if (c != null) { ec.EmitInt(or ? 1 : 0); ec.Emit(OpCodes.Newobj, NullableInfo.GetConstructor(type)); } else if (Right.IsNull) { UnwrapLeft.Emit(ec); ec.Emit(or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, is_null_label); UnwrapLeft.Load(ec); ec.Emit(OpCodes.Br_S, end_label); ec.MarkLabel(is_null_label); LiftedNull.Create(type, loc).Emit(ec); } else { Right.Emit(ec); ec.Emit(or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, load_right); ec.EmitInt(or ? 1 : 0); ec.Emit(OpCodes.Newobj, NullableInfo.GetConstructor(type)); ec.Emit(OpCodes.Br_S, end_label); ec.MarkLabel(load_right); UnwrapLeft.Load(ec); } } ec.MarkLabel(end_label); }
public override Function SimplifyFunction() { Left = Left.SimplifyFunction(); Right = Right.SimplifyFunction(); if (Left.IsConstant() && Right.IsConstant()) { return(new RealNumber(CalculateValue(0))); } if (Left.ToString() == "0") { return(Right); } if (Right.ToString() == "0") { return(Left); } if (Left is Plus && Right.IsConstant()) { if (Left.Left.IsConstant()) { Function function = new Plus(); function.Left = Left.Right; function.Right = new RealNumber(Right.CalculateValue(0) + Left.Left.CalculateValue(0)); return(function.SimplifyFunction()); } if (Left.Right.IsConstant()) { Function function = new Plus(); function.Left = Left.Left; function.Right = new RealNumber(Left.Right.CalculateValue(0) + Right.CalculateValue(0)); return(function.SimplifyFunction()); } } if (Right is Plus && Left.IsConstant()) { if (Right.Left.IsConstant()) { Function function = new Plus(); function.Left = Right.Right; function.Right = new RealNumber(Right.Left.CalculateValue(0) + Left.CalculateValue(0)); return(function.SimplifyFunction()); } if (Right.Right.IsConstant()) { Function function = new Plus(); function.Left = Right.Left; function.Right = new RealNumber(Right.Right.CalculateValue(0) + Left.CalculateValue(0)); return(function.SimplifyFunction()); } } if (Left is Substract && Right.IsConstant()) { if (Left.Left.IsConstant()) { Function function = new Substract(); function.Right = Left.Right; function.Left = new RealNumber(Left.Left.CalculateValue(0) + Right.CalculateValue(0)); return(function.SimplifyFunction()); } if (Left.Right.IsConstant()) { Function function = new Plus(); function.Left = Left.Left; function.Right = new RealNumber(Right.CalculateValue(0) - Left.Right.CalculateValue(0)); return(function.SimplifyFunction()); } } if (Right is Substract && Left.IsConstant()) { if (Right.Left.IsConstant()) { Function function = new Substract(); function.Left = new RealNumber(Right.Left.CalculateValue(0) + Left.CalculateValue(0)); function.Right = Right.Right; return(function.SimplifyFunction()); } if (Right.Right.IsConstant()) { Function function = new Plus(); function.Left = Right.Left; function.Right = new RealNumber(Left.CalculateValue(0) - Right.Right.CalculateValue(0)); return(function.SimplifyFunction()); } } if (Left is NaturalLogarithm && Right is NaturalLogarithm) { if (Left.Left.IsConstant() && Right.Left.IsConstant()) { Function function = new NaturalLogarithm(); function.Left = new RealNumber(Left.Left.CalculateValue(0) * Right.Left.CalculateValue(0)); return(function.SimplifyFunction()); } } return(this); }
public Expression Build() => Build(Left.Build());
public SortedSet <string> GetLanguage(int maxSteps) { SortedSet <string> emptyLanguage = new SortedSet <string>(CompareByLength); SortedSet <string> languageResult = new SortedSet <string>(CompareByLength); SortedSet <string> languageLeft, languageRight; if (maxSteps < 1) { return(emptyLanguage); } switch (Operator) { case OperatorEnum.One: languageResult.Add(Terminals); goto case OperatorEnum.Or; case OperatorEnum.Or: languageLeft = Left == null ? emptyLanguage : Left.GetLanguage(maxSteps - 1); languageRight = Right == null ? emptyLanguage : Right.GetLanguage(maxSteps - 1); foreach (string s in languageLeft) { languageResult.Add(s); } foreach (string s in languageRight) { languageResult.Add(s); } break; case OperatorEnum.Dot: languageLeft = Left == null ? emptyLanguage : Left.GetLanguage(maxSteps - 1); languageRight = Right == null ? emptyLanguage : Right.GetLanguage(maxSteps - 1); foreach (string s1 in languageLeft) { foreach (string s2 in languageRight) { languageResult.Add(s1 + s2); } } break; case OperatorEnum.Star: case OperatorEnum.Plus: languageLeft = Left == null ? emptyLanguage : Left.GetLanguage(maxSteps - 1); foreach (string s in languageLeft) { languageResult.Add(s); } for (int i = 1; i < maxSteps; i++) { HashSet <string> languageTemp = new HashSet <string>(languageResult); foreach (string s1 in languageLeft) { foreach (string s2 in languageTemp) { languageResult.Add(s1 + s2); } } } if (Operator == OperatorEnum.Star) { languageResult.Add(""); } break; } return(languageResult); }
private bool Equals(Thickness other) { return(Left.Equals(other.Left) && Top.Equals(other.Top) && Right.Equals(other.Right) && Bottom.Equals(other.Bottom)); }
public override string GetTypeIgnoreGeneric() { return($"{Left.GetTypeIgnoreGeneric()}.{Right.Translate()}"); }
protected override string InnerTranslate() { return($"{Left.Translate()}.{Right.Translate()}"); }
public override void Parenthesize() { Left.Parenthesize(); Right.Parenthesize(); }