コード例 #1
0
        public static MatchContext Match(ICodePattern pattern, object @object)
        {
            var context = new MatchContext();

            context.Success = pattern.Match(context, @object);
            return(context);
        }
コード例 #2
0
 private void ProcessCtorInvocation()
 {
     V_3 = this.GetStatementsForInvocation(out V_1, out V_0, out V_2);
     if (V_3 == null)
     {
         return;
     }
     this.patternsContext = new CodePatternsContext(V_3);
     stackVariable10      = new ICodePattern[5];
     stackVariable10[0]   = new NullCoalescingPattern(this.patternsContext, this.methodContext);
     stackVariable10[1]   = new TernaryConditionPatternAgressive(this.patternsContext, this.typeSystem);
     stackVariable10[2]   = new ArrayInitialisationPattern(this.patternsContext, this.typeSystem);
     stackVariable10[3]   = new VariableInliningPatternAggressive(this.patternsContext, this.methodContext, this.context.get_Language().get_VariablesToNotInlineFinder());
     stackVariable10[4]   = new MultiAssignPattern(this.patternsContext, this.methodContext);
     V_4 = new List <ICodePattern>(stackVariable10);
     if (V_2)
     {
         V_4.Add(new InitializationPattern(this.patternsContext, this.context));
     }
     if (!this.ProcessStatementCollection(V_3, V_4))
     {
         return;
     }
     if (V_3.get_Item(0).get_CodeNodeType() != 5)
     {
         return;
     }
     V_5 = (V_3.get_Item(0) as ExpressionStatement).get_Expression() as MethodInvocationExpression;
     if (V_5.get_CodeNodeType() != 52 && V_5.get_CodeNodeType() != 53)
     {
         return;
     }
     this.methodContext.set_CtorInvokeExpression(V_5);
     return;
 }
コード例 #3
0
 public static bool TryMatch(this ICodePattern self, MatchContext context, object object)
 {
     if (self == null)
     {
         return(true);
     }
     return(self.Match(context, object));
 }
コード例 #4
0
 protected virtual IEnumerable <ICodePattern> GetCodePatterns()
 {
     stackVariable1    = new ICodePattern[6];
     stackVariable1[0] = new NullCoalescingPattern(this.patternsContext, this.context.get_MethodContext());
     stackVariable1[1] = this.GetTernaryPattern(this.patternsContext);
     stackVariable1[2] = new ArrayInitialisationPattern(this.patternsContext, this.typeSystem);
     stackVariable1[3] = new ObjectInitialisationPattern(this.patternsContext, this.typeSystem);
     stackVariable1[4] = new CollectionInitializationPattern(this.patternsContext, this.typeSystem);
     stackVariable1[5] = this.GetVariableInliningPattern(this.patternsContext);
     return(stackVariable1);
 }
コード例 #5
0
        public override ICodeNode VisitBlockStatement(BlockStatement node)
        {
            node = (BlockStatement)base.VisitBlockStatement(node);

            if (node == null)
            {
                return(node);
            }

            ICodePattern[] patternArray = new ICodePattern[]
            {
                new NullCoalescingPattern(patternsContext, context.MethodContext),
                GetTernaryPattern(patternsContext),
                new ArrayInitialisationPattern(patternsContext, typeSystem),
                new ObjectInitialisationPattern(patternsContext, typeSystem),
                new CollectionInitializationPattern(patternsContext, typeSystem),
                GetVariableInliningPattern(patternsContext),
            };

            bool matched = false;

            do
            {
                matched = false;
                Statement resultedStatement;
                int       replacedStatementsCount;
                int       startIndex;
                foreach (ICodePattern pattern in patternArray)
                {
                    if (pattern.TryMatch(node.Statements, out startIndex, out resultedStatement, out replacedStatementsCount))
                    {
                        matched = true;
                        if (resultedStatement != null)
                        {
                            RemoveRangeAndInsert(node, startIndex, replacedStatementsCount, resultedStatement);
                        }
                        else
                        {
                            RemoveRange(node.Statements, startIndex, replacedStatementsCount);
                        }
                        break;
                    }
                }
            }while(matched);
            return(node);
        }
コード例 #6
0
		public override ICodeNode VisitBlockStatement(BlockStatement node)
		{
			node = (BlockStatement)base.VisitBlockStatement(node);

			if (node == null)
			{
				return node;
			}

            ICodePattern[] patternArray = new ICodePattern[]
												{
                                                    new NullCoalescingPattern(patternsContext, context.MethodContext),
                                                    GetTernaryPattern(patternsContext),
                                                    new ArrayInitialisationPattern(patternsContext, typeSystem),
                                                    new ObjectInitialisationPattern(patternsContext, typeSystem),
                                                    new CollectionInitializationPattern(patternsContext, typeSystem),
                                                    GetVariableInliningPattern(patternsContext),
                                                };

			bool matched = false;
			do
			{
				matched = false;
				Statement resultedStatement;
				int replacedStatementsCount;
				int startIndex;
				foreach (ICodePattern pattern in patternArray)
				{
					if(pattern.TryMatch(node.Statements, out startIndex, out resultedStatement, out replacedStatementsCount))
					{
						matched = true;
						if (resultedStatement != null)
						{
							RemoveRangeAndInsert(node, startIndex, replacedStatementsCount, resultedStatement);
						}
						else
						{
							RemoveRange(node.Statements, startIndex, replacedStatementsCount);
						}
						break;
					}
				}
			}while(matched);
			return node;
		}
コード例 #7
0
		static SelfAssignment()
		{
			stackVariable0 = new Assignment();
			stackVariable1 = new SelfAssignment.SelfIncrementExpression();
			stackVariable1.set_Bind(new Func<Expression, MatchData>(SelfAssignment.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__17_0));
			stackVariable0.set_Target(stackVariable1);
			stackVariable5 = new Binary();
			stackVariable5.set_Bind(new Func<BinaryExpression, MatchData>(SelfAssignment.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__17_1));
			stackVariable9 = new ContextData();
			stackVariable9.set_Name("Target");
			stackVariable9.set_Comparer(new ExpressionComparer());
			stackVariable5.set_Left(stackVariable9);
			stackVariable12 = new Literal();
			stackVariable12.set_Value(1);
			stackVariable5.set_Right(stackVariable12);
			stackVariable5.set_IsChecked(new bool?(false));
			stackVariable0.set_Expression(stackVariable5);
			SelfAssignment.IncrementPattern = stackVariable0;
			stackVariable17 = new Assignment();
			stackVariable18 = new SelfAssignment.SelfAssignmentExpression();
			stackVariable18.set_Bind(new Func<Expression, MatchData>(SelfAssignment.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__17_2));
			stackVariable17.set_Target(stackVariable18);
			stackVariable22 = new Binary();
			stackVariable22.set_Bind(new Func<BinaryExpression, MatchData>(SelfAssignment.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__17_3));
			stackVariable26 = new ContextData();
			stackVariable26.set_Name("Target");
			stackVariable26.set_Comparer(new ExpressionComparer());
			stackVariable22.set_Left(stackVariable26);
			stackVariable29 = new SelfAssignment.SelfAssignmentValue();
			stackVariable29.set_Bind(new Func<Expression, MatchData>(SelfAssignment.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__17_4));
			stackVariable22.set_Right(stackVariable29);
			stackVariable22.set_IsChecked(new bool?(false));
			stackVariable17.set_Expression(stackVariable22);
			SelfAssignment.AssignmentOperatorPattern = stackVariable17;
			return;
		}
コード例 #8
0
 public ICodeNode VisitBinaryExpression(BinaryExpression node)
 {
     stackVariable3    = new ICodePattern[5];
     stackVariable3[0] = CanCastStep.canCastToReferenceTypePattern;
     stackVariable3[1] = CanCastStep.canCastToValueTypePattern;
     stackVariable3[2] = CanCastStep.canCastComparisonToNullPattern;
     stackVariable3[3] = CanCastStep.canCastComparisonToZeroPattern;
     stackVariable3[4] = CanCastStep.canCastComparisonToFalsePattern;
     if (this.TryMatchCanCastPattern(node, (IEnumerable <ICodePattern>)stackVariable3, out V_0))
     {
         return(V_0);
     }
     stackVariable19    = new ICodePattern[5];
     stackVariable19[0] = CanCastStep.negatedCanCastToReferenceTypePattern;
     stackVariable19[1] = CanCastStep.negatedCanCastToValueTypePattern;
     stackVariable19[2] = CanCastStep.negatedCanCastComparisonToNullPattern;
     stackVariable19[3] = CanCastStep.negatedCanCastComparisonToZeroPattern;
     stackVariable19[4] = CanCastStep.negatedCanCastComparisonToFalsePattern;
     if (!this.TryMatchCanCastPattern(node, (IEnumerable <ICodePattern>)stackVariable19, out V_0))
     {
         return(null);
     }
     return(new UnaryExpression(1, V_0, null));
 }
コード例 #9
0
 public static MatchContext Match(ICodePattern pattern, object object)
 {
     V_0 = new MatchContext();
     V_0.set_Success(pattern.Match(V_0, object));
     return(V_0);
 }
コード例 #10
0
 static CanCastStep()
 {
     stackVariable0 = new Binary();
     stackVariable1 = new SafeCast();
     stackVariable1.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_0));
     stackVariable0.set_Left(stackVariable1);
     stackVariable5 = new Constant();
     stackVariable5.set_Value((BinaryOperator)10);
     stackVariable0.set_Operator(stackVariable5);
     stackVariable8 = new Literal();
     stackVariable8.set_Value(null);
     stackVariable0.set_Right(stackVariable8);
     CanCastStep.canCastToReferenceTypePattern = stackVariable0;
     stackVariable10 = new Binary();
     stackVariable11 = new SafeCast();
     stackVariable11.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_1));
     stackVariable10.set_Left(stackVariable11);
     stackVariable15 = new Constant();
     stackVariable15.set_Value((BinaryOperator)9);
     stackVariable10.set_Operator(stackVariable15);
     stackVariable18 = new Literal();
     stackVariable18.set_Value(null);
     stackVariable10.set_Right(stackVariable18);
     CanCastStep.negatedCanCastToReferenceTypePattern = stackVariable10;
     stackVariable20 = new Binary();
     stackVariable21 = new SafeCast();
     stackVariable21.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_2));
     stackVariable20.set_Left(stackVariable21);
     stackVariable25 = new Constant();
     stackVariable25.set_Value((BinaryOperator)10);
     stackVariable20.set_Operator(stackVariable25);
     stackVariable28 = new Literal();
     stackVariable28.set_Value(0);
     stackVariable20.set_Right(stackVariable28);
     CanCastStep.canCastToValueTypePattern = stackVariable20;
     stackVariable31 = new Binary();
     stackVariable32 = new SafeCast();
     stackVariable32.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_3));
     stackVariable31.set_Left(stackVariable32);
     stackVariable36 = new Constant();
     stackVariable36.set_Value((BinaryOperator)9);
     stackVariable31.set_Operator(stackVariable36);
     stackVariable39 = new Literal();
     stackVariable39.set_Value(0);
     stackVariable31.set_Right(stackVariable39);
     CanCastStep.negatedCanCastToValueTypePattern = stackVariable31;
     stackVariable42 = new Binary();
     stackVariable43 = new SafeCast();
     stackVariable43.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_4));
     stackVariable42.set_Left(stackVariable43);
     stackVariable47 = new Constant();
     stackVariable47.set_Value((BinaryOperator)15);
     stackVariable42.set_Operator(stackVariable47);
     stackVariable50 = new Literal();
     stackVariable50.set_Value(null);
     stackVariable42.set_Right(stackVariable50);
     CanCastStep.canCastComparisonToNullPattern = stackVariable42;
     stackVariable52 = new Binary();
     stackVariable53 = new SafeCast();
     stackVariable53.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_5));
     stackVariable52.set_Left(stackVariable53);
     stackVariable57 = new Constant();
     stackVariable57.set_Value((BinaryOperator)14);
     stackVariable52.set_Operator(stackVariable57);
     stackVariable60 = new Literal();
     stackVariable60.set_Value(null);
     stackVariable52.set_Right(stackVariable60);
     CanCastStep.negatedCanCastComparisonToNullPattern = stackVariable52;
     stackVariable62 = new Binary();
     stackVariable63 = new SafeCast();
     stackVariable63.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_6));
     stackVariable62.set_Left(stackVariable63);
     stackVariable67 = new Constant();
     stackVariable67.set_Value((BinaryOperator)15);
     stackVariable62.set_Operator(stackVariable67);
     stackVariable70 = new Literal();
     stackVariable70.set_Value(0);
     stackVariable62.set_Right(stackVariable70);
     CanCastStep.canCastComparisonToZeroPattern = stackVariable62;
     stackVariable73 = new Binary();
     stackVariable74 = new SafeCast();
     stackVariable74.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_7));
     stackVariable73.set_Left(stackVariable74);
     stackVariable78 = new Constant();
     stackVariable78.set_Value((BinaryOperator)14);
     stackVariable73.set_Operator(stackVariable78);
     stackVariable81 = new Literal();
     stackVariable81.set_Value(0);
     stackVariable73.set_Right(stackVariable81);
     CanCastStep.negatedCanCastComparisonToZeroPattern = stackVariable73;
     stackVariable84 = new Binary();
     stackVariable85 = new SafeCast();
     stackVariable85.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_8));
     stackVariable84.set_Left(stackVariable85);
     stackVariable89 = new Constant();
     stackVariable89.set_Value((BinaryOperator)10);
     stackVariable84.set_Operator(stackVariable89);
     stackVariable92 = new Literal();
     stackVariable92.set_Value(false);
     stackVariable84.set_Right(stackVariable92);
     CanCastStep.canCastComparisonToFalsePattern = stackVariable84;
     stackVariable95 = new Binary();
     stackVariable96 = new SafeCast();
     stackVariable96.set_Bind(new Func <SafeCastExpression, MatchData>(CanCastStep.u003cu003ec.u003cu003e9.u003cu002ecctoru003eb__16_9));
     stackVariable95.set_Left(stackVariable96);
     stackVariable100 = new Constant();
     stackVariable100.set_Value((BinaryOperator)9);
     stackVariable95.set_Operator(stackVariable100);
     stackVariable103 = new Literal();
     stackVariable103.set_Value(false);
     stackVariable95.set_Right(stackVariable103);
     CanCastStep.negatedCanCastComparisonToFalsePattern = stackVariable95;
     return;
 }