public static List <IOperationProvider> GenerateConditionalSetup(string token, ConditionalKeywords keywords, ConditionalOperationOptions options) { string uncommentOperationId = $"Uncomment (line): {token} -> ()"; string reduceCommentOperationId = $"Reduce comment (line): ({token}{token}) -> ({token})"; IOperationProvider uncomment = new Replacement(token, string.Empty, uncommentOperationId); IOperationProvider reduceComment = new Replacement($"{token}{token}", token, reduceCommentOperationId); ConditionalTokens conditionalTokens = new ConditionalTokens { IfTokens = new[] { $"{token}{keywords.KeywordPrefix}{keywords.IfKeyword}" }, ElseTokens = new[] { $"{token}{keywords.KeywordPrefix}{keywords.ElseKeyword}" }, ElseIfTokens = new[] { $"{token}{keywords.KeywordPrefix}{keywords.ElseIfKeyword}" }, EndIfTokens = new[] { $"{token}{keywords.KeywordPrefix}{keywords.EndIfKeyword}", $"{token}{token}{keywords.KeywordPrefix}{keywords.EndIfKeyword}" }, ActionableIfTokens = new[] { $"{token}{token}{keywords.KeywordPrefix}{keywords.IfKeyword}" }, ActionableElseTokens = new[] { $"{token}{token}{keywords.KeywordPrefix}{keywords.ElseKeyword}" }, ActionableElseIfTokens = new[] { $"{token}{token}{keywords.KeywordPrefix}{keywords.ElseIfKeyword}" }, ActionableOperations = new[] { uncommentOperationId, reduceCommentOperationId } }; ConditionEvaluator evaluator = EvaluatorSelector.Select(options.EvaluatorType); IOperationProvider conditional = new Conditional(conditionalTokens, options.WholeLine, options.TrimWhitespace, evaluator, options.Id); return(new List <IOperationProvider>() { conditional, reduceComment, uncomment }); }
public static List <IOperationProvider> XmlConditionalSetup(string evaluatorType, bool wholeLine, bool trimWhiteSpace, string id) { // This is the operationId (flag) for the balanced nesting. string commentFixingOperationId = "Fix pseudo comments (XML)"; // This is not an operationId (flag), it does not toggle the operation. // But conditional doesn't care, it takes the flags its given and sets them as appropriate. // It lets BalancedNesting know it's been reset. string commentFixingResetId = "Reset pseudo comment fixer (XML)"; IOperationProvider balancedComments = new BalancedNesting("<!--", "-->", "-- >", commentFixingOperationId, commentFixingResetId); ConditionalTokens tokens = new ConditionalTokens { EndIfTokens = new[] { "#endif", "<!--#endif" }, ActionableIfTokens = new[] { "<!--#if" }, ActionableElseTokens = new[] { "#else", "<!--#else" }, ActionableElseIfTokens = new[] { "#elseif", "<!--#elseif" }, ActionableOperations = new[] { commentFixingOperationId, commentFixingResetId } }; ConditionEvaluator evaluator = EvaluatorSelector.Select(evaluatorType); IOperationProvider conditional = new Conditional(tokens, wholeLine, trimWhiteSpace, evaluator, id); return(new List <IOperationProvider>() { conditional, balancedComments }); }
public void FadeOut() { for (int i = 0; i < animations.Count; i++) { animations[i].FadeOut(); } if (canvas) { Conditional.Wait(duration).Do(() => { if (canvas) { canvas.enabled = false; } }); } if (includeChildrenGroups) { for (var i = 0; i < childrenGroups.Count; i++) { childrenGroups[i].FadeOut(); } } }
public static List <IOperationProvider> CStyleLineCommentsConditionalSetup(string evaluatorType, bool wholeLine, bool trimWhiteSpace, string id) { string uncommentOperationId = "Uncomment (C style): (//) -> ()"; string reduceCommentsOperationId = "Reduce comment (C style): (////) -> (//)"; // temporary - one time test IOperationProvider uncomment = new Replacement("//", string.Empty, uncommentOperationId); IOperationProvider reduceComment = new Replacement("////", "//", reduceCommentsOperationId); ConditionalTokens tokens = new ConditionalTokens { IfTokens = new[] { "//#if" }, ElseTokens = new[] { "//#else" }, ElseIfTokens = new[] { "//#elseif" }, EndIfTokens = new[] { "//#endif" }, ActionableIfTokens = new[] { "////#if" }, ActionableElseIfTokens = new[] { "////#elseif" }, ActionableElseTokens = new[] { "////#else" }, ActionableOperations = new[] { uncommentOperationId, reduceCommentsOperationId } }; ConditionEvaluator evaluator = EvaluatorSelector.Select(evaluatorType); IOperationProvider conditional = new Conditional(tokens, wholeLine, trimWhiteSpace, evaluator, id); return(new List <IOperationProvider>() { conditional, reduceComment, uncomment }); }
public static List <IOperationProvider> RemLineCommentConditionalSetup(String evaluatorType, bool wholeLine, bool trimWhiteSpace, string id) { string uncommentOperationId = "Replacement (rem line): (rem) -> ()"; string reduceCommentOperationId = "Uncomment (rem line): (rem rem) -> (rem)"; IOperationProvider uncomment = new Replacement("rem", string.Empty, uncommentOperationId); IOperationProvider reduceComment = new Replacement("rem rem", "rem", reduceCommentOperationId); ConditionalTokens tokens = new ConditionalTokens { IfTokens = new[] { "rem #if" }, ElseTokens = new[] { "rem #else" }, ElseIfTokens = new[] { "rem #elseif" }, EndIfTokens = new[] { "rem #endif", "rem rem #endif" }, ActionableIfTokens = new[] { "rem rem #if" }, ActionableElseIfTokens = new[] { "rem rem #elseif" }, ActionableElseTokens = new[] { "rem rem #else" }, ActionableOperations = new[] { uncommentOperationId, reduceCommentOperationId } }; ConditionEvaluator evaluator = EvaluatorSelector.Select(evaluatorType); IOperationProvider conditional = new Conditional(tokens, wholeLine, trimWhiteSpace, evaluator, id); return(new List <IOperationProvider>() { conditional, reduceComment, uncomment }); }
public override void Emit(EmitContext ec) { var rc = new ResolveContext(ec.MemberContext); var expr = new Conditional(new BooleanExpression(condition), invoke, assign, loc).Resolve(rc); expr.Emit(ec); }
public void AddCondintional(Conditional c) { conditionalList.Add(c); SpawnButton(c); conditionButtons.SelectLast(); }
/// <summary> /// Checks an interrupt condition, executing the given behaviour only if the condition returns False /// -Returns Success if the given behaviour returns Success and the condition returns False /// -Returns Running if the given behaviour returns Running and the condition returns False /// -Returns Failure if the given behaviour returns Failure or the condition returns True /// /// Possibly not a good solution for interrupt style behaviour in the long run as it is very difficult to write /// conditions for interrupting without adding lots of state elsewhere to track when interrupts occur /// </summary> /// <param name="name">the name of the interruptible</param> /// <param name="behaviour"></param> /// <param name="interruptCondition"></param> /// <param name="onInterruptReturn"></param> public Interruptible(string name, BehaviourComponent behaviour, Conditional interruptCondition, BehaviourReturnCode onInterruptReturn) { Name = name; _behaviourComponent = behaviour; _interruptCondition = interruptCondition; _onInterruptReturn = onInterruptReturn; }
public void InitPanel(Conditional c) { conditionalPanel.SwitchContexts(this.gameObject); cond = c as MatchingTagConditional; conditionalPanel.currConditional = c; UpdateDisplay(); }
public static IHtmlContent GenerateHtml <TModel>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, bool> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, Conditional conditional = null, bool disabled = false) { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; bool isChecked = ExpressionHelpers.GetPropertyValueFromModelAndExpression(model, propertyLambdaExpression); if (labelOptions != null) { labelOptions.For = propertyName; } var checkboxItemViewModel = new CheckboxItemViewModel { Id = propertyName, Name = propertyName, Value = true.ToString(), Label = labelOptions, Hint = hintOptions, Conditional = conditional, Disabled = disabled, Checked = isChecked }; return(htmlHelper.Partial("/GovUkDesignSystemComponents/CheckboxItem.cshtml", checkboxItemViewModel)); }
public void TestBlockCommentConditionalSetup() { IEnumerable <IOperationProvider> ops = new ConditionalConfig().ConfigureFromJObject(BlockConditionalSetup, null); IList <IOperationProvider> operations = new List <IOperationProvider>(ops); Assert.Equal(2, operations.Count); // conditional & pseudo comment balancer Assert.True(operations[0] is Conditional); Conditional conditionalOp = operations[0] as Conditional; Assert.Equal(2, conditionalOp.Tokens.EndIfTokens.Count); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("#endif")); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("/*#endif")); Assert.Equal(1, conditionalOp.Tokens.ActionableIfTokens.Count); Assert.Equal("/*#if", conditionalOp.Tokens.ActionableIfTokens[0]); Assert.Equal(2, conditionalOp.Tokens.ActionableElseIfTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Contains("#elseif")); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Contains("/*#elseif")); Assert.Equal(2, conditionalOp.Tokens.ActionableElseTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Contains("#else")); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Contains("/*#else")); Assert.True(conditionalOp.WholeLine); Assert.True(conditionalOp.TrimWhitespace); }
private static void EvaluateFail(Conditional conditional) { string msg = null; var isException = false; var match = Regex.Match(conditional.MatchValue, @"\{\{\s*(?<type>fail|exception)\s*(?<msg>.*?)\s*}\}", RegexOptions.IgnoreCase); if (match.Success) { var group = match.Groups["msg"]; if (group != null && group.Captures.Count != 0) { msg = group.Captures[0].Value; } group = match.Groups["type"]; isException = group != null && group.Captures.Count != 0 && group.Captures[0].Value == "exception"; } string exceptionMsg; if (isException) { exceptionMsg = msg; } else { exceptionMsg = "Fail directive"; if (!IsNullOrWhiteSpace(msg)) { exceptionMsg += ": " + msg; } } throw new VoteSubstitutionException(exceptionMsg); }
internal static Conditional FixUpType(Conditional conditional) { Contract.Requires(conditional != null); conditional.Condition = ConvertToBoolean(conditional.Condition); var mergedType = conditional.ResultIfTrue.Type; if (!TypeHelper.TypesAreEquivalent(conditional.ResultIfTrue.Type, conditional.ResultIfFalse.Type)) { mergedType = TypeHelper.MergedType(TypeHelper.StackType(conditional.ResultIfTrue.Type), TypeHelper.StackType(conditional.ResultIfFalse.Type)); if (mergedType.TypeCode == PrimitiveTypeCode.Int32) { if (conditional.ResultIfTrue.Type.TypeCode == PrimitiveTypeCode.Boolean) { conditional.ResultIfFalse = ConvertToBoolean(conditional.ResultIfFalse); mergedType = conditional.ResultIfTrue.Type; } else if (conditional.ResultIfFalse.Type.TypeCode == PrimitiveTypeCode.Boolean) { conditional.ResultIfTrue = ConvertToBoolean(conditional.ResultIfTrue); mergedType = conditional.ResultIfFalse.Type; } } } conditional.Type = mergedType; return(conditional); }
public void TestLineCommentConditionalSetup() { IEnumerable <IOperationProvider> ops = new ConditionalConfig().ConfigureFromJObject(LineConditionalSetup, null); IList <IOperationProvider> operations = new List <IOperationProvider>(ops); Assert.Equal(3, operations.Count); Assert.True(operations[0] is Conditional); Conditional conditionalOp = operations[0] as Conditional; Assert.Equal(conditionalOp.Tokens.IfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.IfTokens[0], "//#if"); Assert.Equal(conditionalOp.Tokens.ElseIfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ElseIfTokens[0], "//#elseif"); Assert.Equal(conditionalOp.Tokens.ElseTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ElseTokens[0], "//#else"); Assert.Equal(conditionalOp.Tokens.EndIfTokens.Count, 2); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("//#endif")); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("////#endif")); Assert.Equal(conditionalOp.Tokens.ActionableIfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ActionableIfTokens[0], "////#if"); Assert.Equal(conditionalOp.Tokens.ActionableElseIfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ActionableElseIfTokens[0], "////#elseif"); Assert.Equal(conditionalOp.Tokens.ActionableElseTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ActionableElseTokens[0], "////#else"); Assert.True(conditionalOp.WholeLine); Assert.True(conditionalOp.TrimWhitespace); }
public void Visit(Conditional node) { if (node != null) { DoesRequire = true; } }
protected override EP_VP1 Visit(Conditional node) { node.Children[0].Visit(this); node.Threads[0].Visit(this); node.Threads[1].Visit(this); return(this); }
/// <summary> /// Formata o texto de uma <see cref="Conditional"/> /// </summary> /// <param name="conditional">Condicional a ser formatada</param> /// <param name="sqlCommand">Objeto <see cref="StringBuilder"/> no qual será adicionado texto</param> /// <returns>Retorna o próprio objeto</returns> private DefaultPersistenceSqlParser Format(Conditional conditional, StringBuilder sqlCommand) { Format((ConditionalTerm)conditional.Left, sqlCommand); Append(' ', sqlCommand).AppendSqlOperator(conditional.Operator.Op, sqlCommand).Append(' ', sqlCommand); Format((ConditionalTerm)conditional.Right, sqlCommand); return(this); }
static SCode DistributeDisjunction(Conditional predicate, SCode alternative) { //Debug.Write ("\n; Distribute disjunction."); return(Conditional.Make(predicate.Predicate, Disjunction.Make(predicate.Consequent, alternative), Disjunction.Make(predicate.Alternative, alternative))); }
private IfStatement TryParseIfStatement() { if (_scanner.CurrentToken.Type != TokenType.IF) { return(null); } _scanner.Next(); CheckTokenTypeAndGoNext(TokenType.PAREN_OPEN); Conditional conditional = TryParseConditional() ?? throw new UnexpectedToken(_scanner.CurrentToken.Position); CheckTokenTypeAndGoNext(TokenType.PAREN_CLOSE); Statement statementIf = TryParseStatement() ?? throw new UnexpectedToken(_scanner.CurrentToken.Position); if (_scanner.CurrentToken.Type != TokenType.ELSE) { return(new IfStatement(conditional, statementIf)); } _scanner.Next(); Statement statementElse = TryParseStatement() ?? throw new UnexpectedToken(_scanner.CurrentToken.Position); return(new IfStatement(conditional, statementIf, statementElse)); }
private ParenConditional TryParseParenConditional() { bool isNegated = false; if (_scanner.CurrentToken.Type == TokenType.NOT) { isNegated = true; _scanner.Next(); } if (_scanner.CurrentToken.Type != TokenType.PAREN_OPEN && !isNegated) { return(null); } if (_scanner.CurrentToken.Type != TokenType.PAREN_OPEN && isNegated) { throw new UnexpectedToken(_scanner.CurrentToken.Position); } _scanner.Next(); Conditional conditional = TryParseConditional() ?? throw new UnexpectedToken(_scanner.CurrentToken.Position); CheckTokenTypeAndGoNext(TokenType.PAREN_CLOSE); return(new ParenConditional(conditional, isNegated)); }
private BehaviorTree DefensiveBehavior(Court court) { var isReachableNode = new Conditional(court) { Predicate = IsOpponentReachable }; var blockNode = new Action(court) { Function = BlockPath }; var defenseBehavior = new Sequence(court) { Order = new List <int> { 0, 1 }, Children = new List <BehaviorTree> { isReachableNode, blockNode } }; return(defenseBehavior); }
public void Conditional(Conditional conditional) { conditional.Condition.Accept(this); var elseBranch = _il.DefineLabel(); var afterBranch = _il.DefineLabel(); _il.Emit(OpCodes.Brfalse, elseBranch); conditional.Then.Accept(this); if (conditional.Then.Type != conditional.Type) { _compiler.ExtendedConvertToType(conditional.Then.Type, conditional.Type, false); } _il.Emit(OpCodes.Br, afterBranch); _il.MarkLabel(elseBranch); conditional.Else.Accept(this); if (conditional.Else.Type != conditional.Type) { _compiler.ExtendedConvertToType(conditional.Else.Type, conditional.Type, false); } _il.MarkLabel(afterBranch); }
public override void TraverseChildren(IConditional conditional) { base.TraverseChildren(conditional); Conditional cond = (Conditional)conditional; cond.Condition = ConvertToBoolean(cond.Condition); if (!TypeHelper.TypesAreEquivalent(conditional.ResultIfTrue.Type, conditional.ResultIfFalse.Type)) { var mergedType = TypeHelper.MergedType(TypeHelper.StackType(conditional.ResultIfTrue.Type), TypeHelper.StackType(conditional.ResultIfFalse.Type)); if (mergedType.TypeCode == PrimitiveTypeCode.Int32) { if (conditional.ResultIfTrue.Type.TypeCode == PrimitiveTypeCode.Boolean) { cond.ResultIfFalse = ConvertToBoolean(cond.ResultIfFalse); mergedType = cond.ResultIfTrue.Type; } else if (cond.ResultIfFalse.Type.TypeCode == PrimitiveTypeCode.Boolean) { cond.ResultIfTrue = ConvertToBoolean(cond.ResultIfTrue); mergedType = cond.ResultIfFalse.Type; } } cond.Type = mergedType; } }
public void TestCustomConditionalSetupExplicitStyleSpecification() { IEnumerable <IOperationProvider> ops = new ConditionalConfig().ConfigureFromJObject(CustomConditionalSetupExplicitStyleSpecification, null); IList <IOperationProvider> operations = new List <IOperationProvider>(ops); Assert.Equal(1, operations.Count); Assert.True(operations[0] is Conditional); Conditional conditionalOp = operations[0] as Conditional; Assert.Equal(1, conditionalOp.Tokens.ActionableIfTokens.Count); Assert.Equal("<!--#if", conditionalOp.Tokens.ActionableIfTokens[0]); Assert.Equal(2, conditionalOp.Tokens.ActionableElseTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Contains("<!--#else")); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Contains("#else")); Assert.Equal(2, conditionalOp.Tokens.ActionableElseIfTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Contains("<!--#elseif")); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Contains("#elseif")); Assert.Equal(2, conditionalOp.Tokens.EndIfTokens.Count); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("<!--#endif")); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("#endif")); Assert.True(conditionalOp.WholeLine); Assert.True(conditionalOp.TrimWhitespace); }
protected internal override void TraverseConditional(Conditional cond) { Traverse(cond.Test); _writer.Write(" ? "); Traverse(cond.IfTrue); _writer.Write(" : "); Traverse(cond.IfFalse); }
public override IExpression Visit(Conditional conditional) { conditional.ResultIfFalse = Visit(conditional.ResultIfFalse); conditional.ResultIfTrue = Visit(conditional.ResultIfTrue); conditional.Condition = Visit(conditional.Condition); conditional.Type = this.Visit(conditional.Type); return(conditional); }
protected BaseExpression(string propertyName, object value, object operand, Conditional conditional) { this._guid = Guid.NewGuid(); this._propertyName = propertyName; this._value = value; this._operand = operand; this._conditional = conditional; }
protected internal override void TraverseConditional(Conditional cond) { Traverse(cond.Test); _writer.Write(" ? "); Traverse(cond.IfTrue); _writer.Write(" : "); Traverse(cond.IfFalse); }
public void Visit(Conditional node) { // if there's a condition node, recurse into it if (node != null && node.Condition != null) { node.Condition.Accept(this); } }
public IList <Expression> Visit(Conditional node) { List <Expression> expressionsInBody = node.GetBody().SelectMany(x => x.Accept(this)).ToList(); expressionsInBody.Add(node.Condition); return(expressionsInBody); }
public void CheckConditional(Conditional cond) { // lookup if conditional in dictionary // check if allowed to fire // if allowed, fire program }
public ClauseInJoin(string first, string second, Is op, Conditional condition, bool where) { _first = first; _second = second; _operator = op; _condition = condition; _where = where; }
public static ExpressionAnalyser CreateExpression(Expression expression, String leftSide, Conditional condition, String rightSide) { if (expression == Expression.NOTHING) return new ExpressionAnalyser(new ExpressionLeftSide(leftSide), condition, new ExpressionRightSide(rightSide)); else if (expression == Expression.AND) return new AndConditional(new ExpressionLeftSide(leftSide), condition, new ExpressionRightSide(rightSide)); return new OrConditional(new ExpressionLeftSide(leftSide), condition, new ExpressionRightSide(rightSide)); }
public ComponentDescription(string id, string componentName, bool canResize, bool canFlip, double minSize, ComponentProperty[] properties, ConnectionGroup[] connections, RenderDescription[] renderDescriptions, Conditional<FlagOptions>[] flags, ComponentDescriptionMetadata metadata) { ID = id; ComponentName = componentName; CanResize = canResize; CanFlip = canFlip; MinSize = minSize; Properties = properties; Connections = connections; RenderDescriptions = renderDescriptions; Flags = flags; Metadata = metadata; }
public NumericExpression( string numericProperty, NumericOperand numericOperand, double value, Conditional conditional) : base(numericProperty, value, numericOperand, conditional) { this._binaryExpression = new CodeBinaryOperatorExpression( new CodeCastExpression( "System.Double", new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), numericProperty)), (CodeBinaryOperatorType) Enum.Parse(typeof(CodeBinaryOperatorType), numericOperand.ToString(), true), new CodePrimitiveExpression(value)); }
/// <summary> /// string content functions /// </summary> /// <example> /// "abcdefg".StartsWith("abc") ? /// </example> public StringExpression( string stringProperty, StringOperand operand, string value, Conditional conditional) : base(stringProperty, value, operand, conditional) { this._binaryExpression = new CodeBinaryOperatorExpression { Left = new CodeMethodInvokeExpression( CodeTypeReferenceExpression, "StringFunction", new CodeExpression[] { new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), stringProperty), new CodePrimitiveExpression(value), new CodePrimitiveExpression(operand), }), Operator = CodeBinaryOperatorType.ValueEquality, Right = CodePrimitiveExpressionTrue }; }
// Use this for initialization void Start () { Memory = new BlackBoard(); Memory.Set<GameObject>("Player", GameObject.FindGameObjectWithTag("Player")); Conditional playerClose = new Conditional(isCloseToPlayer); Conditional playerMoving = new Conditional(isPlayerMoving); BehaviorAction MoveToPlayer = new BehaviorAction(moveToPlayer); BehaviorAction WanderAroundPlayer = new BehaviorAction(wanderAroundPlayer); Selector stayCloseToPlayer = new Selector( new Sequence( new Inverter(playerClose), playerMoving, MoveToPlayer ), WanderAroundPlayer ); behaviour = new BehaviorLibrary.Behavior(stayCloseToPlayer); }
protected internal override void TraverseConditional(Conditional cond) { cond.Children.ForEach(Traverse); var t_iftrue = Types[cond.IfTrue]; var t_iffalse = Types[cond.IfFalse]; if (t_iftrue == null || t_iffalse == null) Types.Add(cond, null); else { (t_iftrue == t_iffalse).AssertTrue(); Types.Add(cond, t_iftrue); } }
public override void OnReset() { // Reset the public properties back to their original values. conditionalTask = null; }
public ExpressionAnalyser(ExpressionLeftSide leftSide, Conditional conditional, ExpressionRightSide rightSide) { this.Expression = new Tuple<ExpressionLeftSide, Conditional, ExpressionRightSide>(leftSide, conditional, rightSide); }
void case_702() #line 4939 "cs-parser.jay" { Error_SyntaxError (Token.CLOSE_BRACE); yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], null, GetLocation (yyVals[-3+yyTop])); lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop])); lexer.putback ('}'); }
void case_699() #line 4921 "cs-parser.jay" { yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop])); lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop])); }
private Expression ParseConditional(Expression condition, TokenSet followers) //^ requires this.currentToken == Token.Conditional; //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile; { this.GetNextToken(); SourceLocationBuilder slb = new SourceLocationBuilder(condition.SourceLocation); Expression resultIfTrue = this.ParseExpression(followers|Token.Colon); Expression resultIfFalse; if (this.currentToken == Token.Colon) { this.GetNextToken(); resultIfFalse = this.ParseExpression(followers); } else { this.Skip(Token.Colon); //gives appropriate error message if (!followers[this.currentToken]) //Assume that only the : is missing. Go ahead as if it were specified. resultIfFalse = this.ParseExpression(followers); else resultIfFalse = this.ParseDummyExpression(); } slb.UpdateToSpan(resultIfFalse.SourceLocation); Expression result = new Conditional(condition, resultIfTrue, resultIfFalse, slb); this.SkipTo(followers); return result; }
public virtual void Visit(Conditional node) { if (node != null) { AcceptChildren(node); } }
protected internal override Node TransformConditional(Conditional cond) { return Dispatch(cond); }
public void AddConditional(Conditional condition) { PlayConditions.Add(condition); }
public void Conditional(Conditional conditional) { conditional.Condition.Accept(this); var elseBranch = _il.DefineLabel(); var afterBranch = _il.DefineLabel(); _il.Emit(OpCodes.Brfalse, elseBranch); conditional.Then.Accept(this); if (conditional.Then.Type != conditional.Type) _compiler.ExtendedConvertToType(conditional.Then.Type, conditional.Type, false); _il.Emit(OpCodes.Br, afterBranch); _il.MarkLabel(elseBranch); conditional.Else.Accept(this); if (conditional.Else.Type != conditional.Type) _compiler.ExtendedConvertToType(conditional.Else.Type, conditional.Type, false); _il.MarkLabel(afterBranch); }
public override void Emit(CodeGen g, Type from, Type to) { var l = g.LocalInitedFromStack(from); Type toUnderlying = Helpers.GetNullableUnderlyingType(to); Type fromUnderlying = Helpers.GetNullableUnderlyingType(from); var cond = new Conditional( l.Property("HasValue"), new NewObject( g.TypeMapper.TypeInfo.FindConstructor(to, new Operand[] { new FakeTypedOperand(toUnderlying), }), new Operand[] { new ConversationWrapper(_internalConversation, l.Property("Value"), fromUnderlying, toUnderlying) }), new DefaultValue(to)); //GetImplicit(l.Property("Value"), toUnderlying, false, g.TypeMapper), l, from, toUnderlying cond.EmitGet(g); }
public virtual object Visit (Conditional conditionalExpression) { return null; }
public override void Emit (EmitContext ec) { var rc = new ResolveContext (ec.MemberContext); var expr = new Conditional (new BooleanExpression (condition), invoke, assign, loc).Resolve (rc); expr.Emit (ec); }
void case_701() #line 4932 "cs-parser.jay" { Error_SyntaxError (yyToken); yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], null, GetLocation (yyVals[-3+yyTop])); lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop])); }
private bool WriteWhileLoop(BasicBlock block, Loop loop, List<CodeStatement> stmts, Context context) { var loopContext = context.NewLoop(loop); CodeWhileStatement whileStmt; if (block.Statements.Count > 1) { // emit a while(true) { $bb.stmts; if($condition) { $then_stmts; break; } ... } whileStmt = new CodeWhileStatement { TestExpression = new CodePrimitiveExpression(true) }; var conditional = new Conditional(this.graph, block); WriteIf(block, conditional, whileStmt.Statements, loopContext); } else { var last = (CodeExpressionStatement)block.Statements.Last(); var test = last.Expression; if (block.ElseEdge == loop.Follow) { test = test.Invert(); } // emit a pre-tested loop whileStmt = new CodeWhileStatement { TestExpression = test }; } AddStatement(stmts, whileStmt); if (!loop.Tails.Contains(block)) { WriteLoopInner(block, loop, whileStmt.Statements, loopContext); } if (loop.Follow != null) { return WriteCode(null, (BasicBlock)loop.Follow, stmts, context); } return false; }
protected internal virtual void TraverseConditional(Conditional cond) { cond.Unsupported(); }
protected internal override void TraverseConditional(Conditional cond) { Dispatch(cond); }
public override object Visit (Conditional conditionalExpression) { var result = new ConditionalExpression (); if (conditionalExpression.Expr != null) result.AddChild ((Expression)conditionalExpression.Expr.Accept (this), Roles.Condition); var location = LocationsBag.GetLocations (conditionalExpression); result.AddChild (new CSharpTokenNode (Convert (conditionalExpression.Location), ConditionalExpression.QuestionMarkRole), ConditionalExpression.QuestionMarkRole); if (conditionalExpression.TrueExpr != null) result.AddChild ((Expression)conditionalExpression.TrueExpr.Accept (this), ConditionalExpression.TrueRole); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location [0]), ConditionalExpression.ColonRole), ConditionalExpression.ColonRole); if (conditionalExpression.FalseExpr != null) result.AddChild ((Expression)conditionalExpression.FalseExpr.Accept (this), ConditionalExpression.FalseRole); return result; }
protected override bool DoDefineMembers () { if (!base.DoDefineMembers ()) return false; Location loc = Location; var equals_parameters = ParametersCompiled.CreateFullyResolved ( new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), Compiler.BuiltinTypes.Object); Method equals = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc), Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc), equals_parameters, null); equals_parameters[0].Resolve (equals, 0); Method tostring = new Method (this, new TypeExpression (Compiler.BuiltinTypes.String, loc), Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc), ParametersCompiled.EmptyReadOnlyParameters, null); ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc); TypeExpr current_type; if (CurrentTypeParameters != null) { var targs = new TypeArguments (); for (int i = 0; i < CurrentTypeParameters.Count; ++i) { targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location)); } current_type = new GenericTypeExpr (Definition, targs, loc); } else { current_type = new TypeExpression (Definition, loc); } var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc); equals_block.AddStatement (new BlockVariable (new TypeExpression (li_other.Type, loc), li_other)); var other_variable = new LocalVariableReference (li_other, loc); MemberAccess system_collections_generic = new MemberAccess (new MemberAccess ( new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc); Expression rs_equals = null; Expression string_concat = new StringConstant (Compiler.BuiltinTypes, "{", loc); Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc); for (int i = 0; i < parameters.Count; ++i) { var p = parameters [i]; var f = (Field) Members [i * 2]; MemberAccess equality_comparer = new MemberAccess (new MemberAccess ( system_collections_generic, "EqualityComparer", new TypeArguments (new SimpleName (CurrentTypeParameters [i].Name, loc)), loc), "Default", loc); Arguments arguments_equal = new Arguments (2); arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name))); arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name))); Expression field_equal = new Invocation (new MemberAccess (equality_comparer, "Equals", loc), arguments_equal); Arguments arguments_hashcode = new Arguments (1); arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name))); Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer, "GetHashCode", loc), arguments_hashcode); IntConstant FNV_prime = new IntConstant (Compiler.BuiltinTypes, 16777619, loc); rs_hashcode = new Binary (Binary.Operator.Multiply, new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode), FNV_prime); Expression field_to_string = new Conditional (new BooleanExpression (new Binary (Binary.Operator.Inequality, new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc))), new Invocation (new MemberAccess ( new MemberAccess (new This (f.Location), f.Name), "ToString"), null), new StringConstant (Compiler.BuiltinTypes, string.Empty, loc), loc); if (rs_equals == null) { rs_equals = field_equal; string_concat = new Binary (Binary.Operator.Addition, string_concat, new Binary (Binary.Operator.Addition, new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc), field_to_string)); continue; } // // Implementation of ToString () body using string concatenation // string_concat = new Binary (Binary.Operator.Addition, new Binary (Binary.Operator.Addition, string_concat, new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc)), field_to_string); rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal); } string_concat = new Binary (Binary.Operator.Addition, string_concat, new StringConstant (Compiler.BuiltinTypes, " }", loc)); // // Equals (object obj) override // var other_variable_assign = new TemporaryVariableReference (li_other, loc); equals_block.AddStatement (new StatementExpression ( new SimpleAssign (other_variable_assign, new As (equals_block.GetParameterReference (0, loc), current_type, loc), loc))); Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc)); if (rs_equals != null) equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals); equals_block.AddStatement (new Return (equals_test, loc)); equals.Block = equals_block; equals.Define (); Members.Add (equals); // // GetHashCode () override // Method hashcode = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Int, loc), Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("GetHashCode", loc), ParametersCompiled.EmptyReadOnlyParameters, null); // // Modified FNV with good avalanche behavior and uniform // distribution with larger hash sizes. // // const int FNV_prime = 16777619; // int hash = (int) 2166136261; // foreach (int d in data) // hash = (hash ^ d) * FNV_prime; // hash += hash << 13; // hash ^= hash >> 7; // hash += hash << 3; // hash ^= hash >> 17; // hash += hash << 5; ToplevelBlock hashcode_top = new ToplevelBlock (Compiler, loc); Block hashcode_block = new Block (hashcode_top, loc, loc); hashcode_top.AddStatement (new Unchecked (hashcode_block, loc)); var li_hash = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Int, hashcode_top, loc); hashcode_block.AddStatement (new BlockVariable (new TypeExpression (li_hash.Type, loc), li_hash)); LocalVariableReference hash_variable_assign = new LocalVariableReference (li_hash, loc); hashcode_block.AddStatement (new StatementExpression ( new SimpleAssign (hash_variable_assign, rs_hashcode))); var hash_variable = new LocalVariableReference (li_hash, loc); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.Addition, hash_variable, new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 13, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable, new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 7, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.Addition, hash_variable, new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 3, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable, new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 17, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.Addition, hash_variable, new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 5, loc))))); hashcode_block.AddStatement (new Return (hash_variable, loc)); hashcode.Block = hashcode_top; hashcode.Define (); Members.Add (hashcode); // // ToString () override // ToplevelBlock tostring_block = new ToplevelBlock (Compiler, loc); tostring_block.AddStatement (new Return (string_concat, loc)); tostring.Block = tostring_block; tostring.Define (); Members.Add (tostring); return true; }
private bool WriteEndlessLoop(BasicBlock block, Loop loop, List<CodeStatement> stmts, Context context) { var loopContext = context.NewLoop(loop); CodeWhileStatement whileStmt = new CodeWhileStatement { TestExpression = new CodePrimitiveExpression(true) }; AddStatement(stmts, whileStmt); if (block.Successors.Count > 1) { var conditional = new Conditional(this.graph, block); WriteIf(block, conditional, whileStmt.Statements, loopContext); } else { WriteBasicBlock(block, whileStmt.Statements); } if (!loop.Tails.Contains(block)) { WriteLoopInner(block, loop, whileStmt.Statements, loopContext); } if (loop.Follow != null) { return WriteCode(null, (BasicBlock)loop.Follow, stmts, context); } return false; }
private bool WriteIf(BasicBlock block, Conditional conditional, List<CodeStatement> stmts, Context context) { var preStmts = block.Statements.Take(block.Statements.Count - 1); AddManyStatements(stmts, preStmts); var last = (CodeExpressionStatement)block.Statements.Last(); var ifStmt = new CodeIfStatement { Condition = last.Expression }; AddStatement(stmts, ifStmt); bool emptyThen = false; // is there a follow? if (conditional.Follow != null && conditional.Follow != context.LoopFollow) { // process the THEN part bool isBreak = false; var succ = block.ThenEdge; if (succ.DfsTraversed != DfsTraversal.Alpha) { if (succ != conditional.Follow) { // THEN part ifStmt.Condition = ifStmt.Condition.Invert(); isBreak = WriteCode(block, (BasicBlock)succ, ifStmt.TrueStatements, context.NewUntil(conditional.Follow)); } else { // empty THEN part => negate ELSE part isBreak = WriteCode(block, (BasicBlock)block.ElseEdge, ifStmt.TrueStatements, context.NewUntil(conditional.Follow)); emptyThen = true; } } // process the ELSE part succ = block.ElseEdge; if (succ.DfsTraversed != DfsTraversal.Alpha) { if (succ != conditional.Follow) { // ELSE part List<CodeStatement> output; if (isBreak) output = stmts; else output = ifStmt.FalseStatements; isBreak = WriteCode(block, (BasicBlock)succ, output, context.NewUntil(conditional.Follow)); if (block == conditional.Follow) return isBreak; } } else if (!emptyThen) { // already visited => emit label throw new InvalidOperationException(); } // Continue with the follow return WriteCode(null, (BasicBlock)conditional.Follow, stmts, context); } else { // no follow => if..then..else ifStmt.Condition = ifStmt.Condition.Invert(); var isBreak = WriteCode(block, (BasicBlock)block.ThenEdge, ifStmt.TrueStatements, context); var output = ifStmt.FalseStatements; if (isBreak) output = stmts; return WriteCode(block, (BasicBlock)block.ElseEdge, output, context); } }
public ValidTarget(Target targ, Conditional condi) { target = targ; conditional = condi; }
protected override void TraverseOperator(Operator op) { var lhs = op.Args.FirstOrDefault(); var rhs = op.Args.SecondOrDefault(); var targ = op.Args.FirstOrDefault(); var opt = op.OperatorType; if (opt.IsAssign()) { // todo. implement this with the use of SafeExpandOpAssign var equiv = op.UnsafeExpandOpAssign(); Traverse(equiv); } else if (opt == OperatorType.AndAlso) { var equiv = new Conditional(lhs, rhs, new Const(false)); Traverse(equiv); } else if (opt == OperatorType.OrElse) { var equiv = new Conditional(lhs, new Const(true), rhs); Traverse(equiv); } else { op.Args.ForEach(Traverse); switch (opt) { case OperatorType.Add: il.add(); break; case OperatorType.And: il.and(); break; case OperatorType.Divide: il.div(); break; case OperatorType.Equal: il.ceq(); break; case OperatorType.GreaterThan: il.cgt(); break; case OperatorType.GreaterThanOrEqual: il.cge(); break; case OperatorType.LeftShift: il.shl(); break; case OperatorType.LessThan: il.clt(); break; case OperatorType.LessThanOrEqual: il.cle(); break; case OperatorType.Modulo: il.rem(); break; case OperatorType.Multiply: il.mul(); break; case OperatorType.Negate: il.neg(); break; case OperatorType.Not: var is_bool = targ.Type() == typeof(bool); if (is_bool) il.ldc_i4(0).ceq(); else il.not(); break; case OperatorType.NotEqual: il.cne(); break; case OperatorType.Or: il.or(); break; case OperatorType.RightShift: il.shr(); break; case OperatorType.Subtract: il.sub(); break; case OperatorType.Xor: il.xor(); break; default: throw AssertionHelper.Fail(); } } }