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.
29 namespace Mono.CodeContracts.Static.Analysis.StackAnalysis {
31 private StackInfo<object> stack;
34 get { return this.stack.Depth; }
37 public object this [int offset] {
38 get { return this.stack [offset]; }
41 public StackInfo (int depth, int capacity)
43 this.stack = new StackInfo<object> (depth, capacity);
46 private StackInfo (StackInfo<object> copy)
51 public StackInfo Pop (int slots)
53 return new StackInfo (this.stack.Pop (slots));
56 public StackInfo Push ()
58 this.stack.Push (null);
62 public StackInfo PushThis ()
64 this.stack.Push (true);
68 public StackInfo Push<T> (T target)
70 this.stack.Push (target);
74 public void Adjust (int delta)
79 this.stack.Pop (-delta);
80 for (int i = 0; i < delta; ++i)
84 public bool IsThis (int offset)
86 return As<bool> (offset);
89 public bool TryGet<T> (int offset, out T target)
91 object o = this [offset];
100 private T As<T> (int offset)
103 TryGetTarget (offset, out res);
107 public StackInfo Clone ()
109 return new StackInfo (new StackInfo<object> (this.stack));
112 public override string ToString ()
114 return this.stack.ToString ();
117 public bool TryGetTarget<T> (int offset, out T target)
119 if (this [offset] is T) {
120 target = (T) this [offset];