PageRenderTime 25ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs

http://github.com/icsharpcode/ILSpy
C# | 65 lines | 43 code | 5 blank | 17 comment | 5 complexity | 0f5eed720697c339182be2e32980512c MD5 | raw file
 1// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Threading;
21using ICSharpCode.NRefactory.CSharp;
22
23namespace ICSharpCode.Decompiler.Ast.Transforms
24{
25	public interface IAstTransform
26	{
27		void Run(AstNode compilationUnit);
28	}
29	
30	public static class TransformationPipeline
31	{
32		public static IAstTransform[] CreatePipeline(DecompilerContext context)
33		{
34			return new IAstTransform[] {
35				new PushNegation(),
36				new DelegateConstruction(context),
37				new PatternStatementTransform(context),
38				new ReplaceMethodCallsWithOperators(context),
39				new IntroduceUnsafeModifier(),
40				new AddCheckedBlocks(),
41				new DeclareVariables(context), // should run after most transforms that modify statements
42				new ConvertConstructorCallIntoInitializer(), // must run after DeclareVariables
43				new DecimalConstantTransform(),
44				new IntroduceUsingDeclarations(context),
45				new IntroduceExtensionMethods(context), // must run after IntroduceUsingDeclarations
46				new IntroduceQueryExpressions(context), // must run after IntroduceExtensionMethods
47				new CombineQueryExpressions(context),
48				new FlattenSwitchBlocks(), 
49			};
50		}
51		
52		public static void RunTransformationsUntil(AstNode node, Predicate<IAstTransform> abortCondition, DecompilerContext context)
53		{
54			if (node == null)
55				return;
56			
57			foreach (var transform in CreatePipeline(context)) {
58				context.CancellationToken.ThrowIfCancellationRequested();
59				if (abortCondition != null && abortCondition(transform))
60					return;
61				transform.Run(node);
62			}
63		}
64	}
65}