2 // ExpressionAnalysisFacade.cs
5 // Alexander Chebaturkin (chebaturkin@gmail.com)
7 // Copyright (C) 2011 Alexander Chebaturkin
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using Mono.CodeContracts.Static.AST.Visitors;
31 using Mono.CodeContracts.Static.Analysis.HeapAnalysis;
32 using Mono.CodeContracts.Static.ControlFlow;
33 using Mono.CodeContracts.Static.DataFlowAnalysis;
34 using Mono.CodeContracts.Static.DataStructures;
35 using Mono.CodeContracts.Static.Providers;
37 namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis {
38 class ExpressionAnalysisFacade<TSymValue, TContext, TEdgeData>
39 where TSymValue : IEquatable<TSymValue>
40 where TContext : IValueContextProvider<TSymValue>
41 where TEdgeData : IImmutableMap<TSymValue, LispList<TSymValue>> {
43 public readonly Predicate<APC> IsUnreachable;
45 public readonly ICodeLayer<TSymValue, TSymValue, TContext, TEdgeData> ValueLayer;
46 private IFixPointInfo<APC, ExprDomain<TSymValue>> fix_point_info;
48 public ExpressionAnalysisFacade (ICodeLayer<TSymValue, TSymValue, TContext, TEdgeData> valueLayer,
49 Predicate<APC> isUnreachable)
51 this.ValueLayer = valueLayer;
52 this.IsUnreachable = isUnreachable;
55 public bool PreStateLookup (APC label, out ExprDomain<TSymValue> ifFound)
57 return this.fix_point_info.PreStateLookup (label, out ifFound);
60 public bool PostStateLookup (APC label, out ExprDomain<TSymValue> ifFound)
62 return this.fix_point_info.PostStateLookup (label, out ifFound);
65 public void SaveFixPointInfo (IFixPointInfo<APC, ExprDomain<TSymValue>> fixPointInfo)
67 this.fix_point_info = fixPointInfo;
70 public ExprDomain<TSymValue> InitialValue (Func<TSymValue, int> keyConverter)
72 return ExprDomain<TSymValue>.TopValue (keyConverter);
75 public IAnalysis<APC, ExprDomain<TSymValue>, IILVisitor<APC, TSymValue, TSymValue, ExprDomain<TSymValue>, ExprDomain<TSymValue>>, TEdgeData>
76 CreateExpressionAnalysis ()
78 return new ValueAnalysis<TSymValue, TContext, TEdgeData> (this);
81 public IILDecoder<APC, LabeledSymbol<APC, TSymValue>, TSymValue, IExpressionContextProvider<LabeledSymbol<APC, TSymValue>, TSymValue>, TEdgeData>
83 IILDecoder<APC, TSymValue, TSymValue, IValueContextProvider<TSymValue>, TEdgeData> ilDecoder)
85 return new ExpressionDecoder<TSymValue, TContext, TEdgeData> (ilDecoder, this);