1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
//
// Subroutine.cs
//
// Authors:
// Alexander Chebaturkin (chebaturkin@gmail.com)
//
// Copyright (C) 2011 Alexander Chebaturkin
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IO;
using Mono.CodeContracts.Static.Analysis;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.ControlFlow {
abstract class Subroutine : IPropertyCollection, IEquatable<Subroutine> {
private static int _subroutineIdGenerator;
private readonly PropertyCollection properties = new PropertyCollection ();
private readonly int subroutine_id = _subroutineIdGenerator++;
public virtual SubroutineKind Kind
{
get { return SubroutineKind.Unknown; }
}
public int Id
{
get { return this.subroutine_id; }
}
public abstract CFGBlock Entry { get; }
public abstract CFGBlock EntryAfterRequires { get; }
public abstract CFGBlock Exit { get; }
public abstract CFGBlock ExceptionExit { get; }
public abstract string Name { get; }
public abstract int BlockCount { get; }
public abstract IEnumerable<CFGBlock> Blocks { get; }
public virtual bool IsRequires
{
get { return false; }
}
public virtual bool IsEnsures
{
get { return false; }
}
public virtual bool IsOldValue
{
get { return false; }
}
public virtual bool IsMethod
{
get { return false; }
}
public virtual bool IsConstructor
{
get { return false; }
}
public virtual bool IsInvariant
{
get { return false; }
}
public virtual bool IsContract
{
get { return false; }
}
public bool IsEnsuresOrOldValue
{
get { return IsEnsures || IsOldValue; }
}
public abstract EdgeMap<EdgeTag> SuccessorEdges { get; }
public abstract EdgeMap<EdgeTag> PredecessorEdges { get; }
public abstract DepthFirst.Visitor<CFGBlock, Dummy> EdgeInfo { get; }
public virtual bool IsFaultFinally
{
get { return false; }
}
public abstract bool HasReturnValue { get; }
public abstract bool HasContextDependentStackDepth { get; }
public abstract int StackDelta { get; }
#region IPropertyCollection Members
public bool TryGetValue<T> (TypedKey key, out T value)
{
return this.properties.TryGetValue (key, out value);
}
#endregion
#region Implementation of IPropertyCollection
public bool Contains (TypedKey key)
{
return this.properties.Contains (key);
}
public void Add<T> (TypedKey key, T value)
{
this.properties.Add (key, value);
}
#endregion
public override string ToString ()
{
return string.Format ("SR {0}: BlockCount:{1}, Kind:{2}", Id, BlockCount, Kind);
}
public abstract IEnumerable<CFGBlock> SuccessorBlocks (CFGBlock block);
public IEnumerable<Pair<EdgeTag, CFGBlock>> SuccessorEdgesFor (CFGBlock block)
{
return SuccessorEdges [block];
}
public abstract IEnumerable<CFGBlock> PredecessorBlocks (CFGBlock block);
public abstract bool IsJoinPoint (CFGBlock block);
public abstract bool IsSplitPoint (CFGBlock block);
public abstract bool HasSingleSuccessor (APC point, out APC ifFound);
public abstract bool HasSinglePredecessor (APC point, out APC ifFound);
public abstract void AddEdgeSubroutine (CFGBlock from, CFGBlock to, Subroutine subroutine, EdgeTag tag);
public abstract IEnumerable<APC> Successors (APC pc);
public abstract IEnumerable<APC> Predecessors (APC pc);
public abstract bool IsSubroutineEnd (CFGBlock block);
public abstract bool IsSubroutineStart (CFGBlock block);
public abstract bool IsCatchFilterHeader (CFGBlock block);
public abstract APC ComputeTargetFinallyContext (APC pc, CFGBlock succ);
public abstract Sequence<Pair<EdgeTag, Subroutine>> EdgeSubroutinesOuterToInner (CFGBlock current, CFGBlock succ, out bool isExceptionHandlerEdge, Sequence<Edge<CFGBlock, EdgeTag>> context);
public abstract Sequence<Pair<EdgeTag, Subroutine>> GetOrdinaryEdgeSubroutines (CFGBlock current, CFGBlock succ, Sequence<Edge<CFGBlock, EdgeTag>> context);
public abstract void Initialize ();
public abstract IEnumerable<Subroutine> UsedSubroutines (HashSet<int> alreadySeen);
public IEnumerable<Subroutine> UsedSubroutines ()
{
return UsedSubroutines (new HashSet<int> ());
}
public abstract IEnumerable<CFGBlock> ExceptionHandlers<Data, Type> (CFGBlock block, Subroutine innerSubroutine,
Data data, IHandlerFilter<Data> handlerPredicate);
public abstract void Print (TextWriter tw, ILPrinter<APC> printer,
Func<CFGBlock, IEnumerable<Sequence<Edge<CFGBlock, EdgeTag>>>> contextLookup,
Sequence<Edge<CFGBlock, EdgeTag>> context,
HashSet<Pair<Subroutine, Sequence<Edge<CFGBlock, EdgeTag>>>> set);
#region Implementation of IEquatable<Subroutine>
public bool Equals (Subroutine other)
{
return Id == other.Id;
}
#endregion
}
}
|