Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
//
// AccessPathFilter.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;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
class AccessPathFilter<TMember> {
public static AccessPathFilter<TMember> NoFilter = new AccessPathFilter<TMember> ();
private readonly Flags flags;
private readonly TMember member;
private readonly MemberFilter member_filter;
private AccessPathFilter ()
{
this.flags = Flags.AllowLocals;
this.member_filter = MemberFilter.NoFilter;
}
private AccessPathFilter (TMember member, MemberFilter memberFilter)
{
this.member_filter = memberFilter;
this.member = member;
}
public bool AllowLocal
{
get { return (this.flags & Flags.AllowLocals) == Flags.AllowLocals; }
}
public bool HasVisibilityMember
{
get { return this.member_filter != MemberFilter.NoFilter; }
}
public TMember VisibilityMember
{
get { return this.member; }
}
public static AccessPathFilter<TMember> FromPrecondition (TMember member)
{
return new AccessPathFilter<TMember> (member, MemberFilter.FromPrecondition);
}
public static AccessPathFilter<TMember> FromPostcondition (TMember member)
{
return new AccessPathFilter<TMember> (member, MemberFilter.FromPostcondition);
}
public static AccessPathFilter<TMember> IsVisibleFrom (TMember member)
{
return new AccessPathFilter<TMember> (member, MemberFilter.FromMethodBody);
}
public bool FilterOutPathElement<P> (P element)
where P : IVisibilityCheck<TMember>
{
switch (this.member_filter) {
case MemberFilter.FromPrecondition:
return !element.IsAsVisibleAs (this.member);
case MemberFilter.FromPostcondition:
return !element.IfRootIsParameter || !element.IsVisibleFrom (this.member);
case MemberFilter.FromMethodBody:
return !element.IsVisibleFrom (this.member);
default:
return false;
}
}
#region Nested type: Flags
[Flags]
private enum Flags {
AllowLocals = 1,
RequireParameter = 2
}
#endregion
#region Nested type: MemberFilter
private enum MemberFilter {
NoFilter = 0,
FromPrecondition,
FromPostcondition,
FromMethodBody
}
#endregion
}
}

View File

@@ -0,0 +1,35 @@
//
// IVisibilityCheck.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.
//
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
interface IVisibilityCheck<TMember> {
bool IfRootIsParameter { get; }
bool IsAsVisibleAs (TMember member);
bool IsVisibleFrom (TMember member);
}
}

View File

@@ -0,0 +1,69 @@
//
// MethodCallPathElement.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 Mono.CodeContracts.Static.AST;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
class MethodCallPathElement : PathElement<Method> {
private readonly bool is_boolean_typed;
private readonly bool is_compressed;
private readonly bool is_getter;
public MethodCallPathElement (Method method,
bool isGetter, bool isBooleanTyped,
bool isStatic, string description,
SymFunction func, bool isCompressed)
: base (method, description, func)
{
this.is_boolean_typed = isBooleanTyped;
this.is_getter = isGetter;
this.is_compressed = isCompressed;
this.isStatic = isStatic;
}
public override bool IsAddressOf
{
get { return !this.is_compressed; }
}
public override bool IsMethodCall
{
get { return true; }
}
public override bool IsGetter
{
get { return this.is_getter; }
}
public override bool IsBooleanTyped
{
get { return this.is_boolean_typed; }
}
}
}

View File

@@ -0,0 +1,67 @@
//
// ParameterPathElement.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 Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Providers;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
class ParameterPathElement : PathElement<Parameter> {
public ParameterPathElement (Parameter p, string description,
SymFunction c, IMetaDataProvider metaDataProvider)
: base (p, description, c)
{
TypeNode type = metaDataProvider.ParameterType (p);
ResultType = metaDataProvider.ManagedPointer (type);
if (metaDataProvider.IsManagedPointer (type))
this.isManagedPointer = true;
}
public override bool IsParameter
{
get { return true; }
}
public override bool IsAddressOf
{
get { return false; }
}
public override Result Decode<Data, Result, Visitor, Label> (Label label, Visitor visitor, Data data)
{
Parameter p = this.Element;
return visitor.LoadArg (label, p, false, Dummy.Value, data);
}
public override bool IsCallerVisible ()
{
return true;
}
}
}

View File

@@ -0,0 +1,63 @@
//
// PathElement.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 Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.AST.Visitors;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths
{
abstract class PathElement
{
public virtual bool IsBooleanTyped { get { return false; } }
public virtual bool IsDeref { get { return false; } }
public virtual bool IsMethodCall { get { return false; } }
public virtual bool IsGetter { get { return false; } }
public virtual bool IsStatic { get { return false; } }
public virtual bool IsUnmanagedPointer { get { return false; } }
public virtual bool IsManagedPointer { get { return false; } }
public virtual bool IsParameter { get { return false; } }
public virtual bool IsParameterRef { get { return false; } }
public virtual string CastTo { get { return ""; } }
public abstract bool IsAddressOf { get; }
public virtual bool TryField(out Field f)
{
f = default(Field);
return false;
}
public abstract bool TryGetResultType(out TypeNode type);
public abstract TResult Decode<TData, TResult, TVisitor, TLabel>(TLabel label, TVisitor visitor, TData data)
where TVisitor : IAggregateVisitor<TLabel, TData, TResult>;
public abstract override string ToString();
}
}

View File

@@ -0,0 +1,43 @@
//
// PathElementBase.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 Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.Providers;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
abstract class PathElementBase : PathElement {
public readonly SymFunction Func;
protected PathElementBase (SymFunction c)
{
this.Func = c;
}
public abstract bool TrySetType (TypeNode expectedType, IMetaDataProvider metaDataProvider, out TypeNode type);
}
}

View File

@@ -0,0 +1,205 @@
//
// PathElement`1.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 Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Providers;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
class PathElement<T> : PathElementBase {
public readonly string Description;
public readonly T Element;
protected string castTo;
protected bool isManagedPointer;
protected bool isStatic;
protected bool isUnmanagedPointer;
#region Overrides of PathElement
public override bool IsStatic
{
get { return this.isStatic; }
}
public override bool IsUnmanagedPointer
{
get { return this.isUnmanagedPointer; }
}
public override bool IsManagedPointer
{
get { return this.isManagedPointer; }
}
public override bool IsParameterRef
{
get { return typeof (T) == typeof (Parameter); }
}
public override string CastTo
{
get { return this.castTo; }
}
public override bool IsAddressOf
{
get { return true; }
}
public override bool TryField (out Field f)
{
if (typeof (T) == typeof (Field)) {
f = (Field) (object) this.Element;
return true;
}
f = default(Field);
return false;
}
public override bool TryGetResultType (out TypeNode type)
{
type = ResultType;
return true;
}
public override TResult Decode<TData, TResult, TVisitor, TLabel> (TLabel label, TVisitor visitor, TData data)
{
if (typeof (T) == typeof (Field)) {
var field = (Field) (object) this.Element;
if (this.isStatic)
return visitor.LoadStaticFieldAddress (label, field, Dummy.Value, data);
return visitor.LoadFieldAddress (label, field, Dummy.Value, Dummy.Value, data);
}
if (typeof (T) == typeof (Local)) {
var local = (Local) (object) this.Element;
return visitor.LoadLocalAddress (label, local, Dummy.Value, data);
}
if (typeof (T) == typeof (Method)) {
var method = (Method) (object) this.Element;
bool isVirtualMethod = this.Func.IsVirtualMethod;
return visitor.Call (label, method, isVirtualMethod, Indexable<TypeNode>.Empty, Dummy.Value, Indexable<Dummy>.Empty, data);
}
if (typeof (T) == typeof (Parameter)) {
var parameter = (Parameter) (object) this.Element;
return visitor.LoadArgAddress (label, parameter, false, Dummy.Value, data);
}
throw new InvalidOperationException ("Field, Local, Method or Parameter expected");
}
public override string ToString ()
{
return this.Description;
}
#endregion
public PathElement (T element, string description, SymFunction c) : base (c)
{
this.Element = element;
this.Description = description;
this.isStatic = false;
this.isUnmanagedPointer = false;
this.isManagedPointer = false;
}
public TypeNode ResultType { get; protected set; }
public virtual bool IsCallerVisible ()
{
return (typeof (T) == typeof (Parameter));
}
#region Overrides of PathElementBase
public override bool TrySetType (TypeNode expectedType, IMetaDataProvider metaDataProvider, out TypeNode resultType)
{
if (typeof (T) == typeof (Parameter)) {
var p = (Parameter) (object) this.Element;
TypeNode type = metaDataProvider.ParameterType (p);
this.isManagedPointer = metaDataProvider.IsManagedPointer (type);
ResultType = resultType = metaDataProvider.ManagedPointer (type);
return true;
}
if (typeof (T) == typeof (Field)) {
var f = (Field) (object) this.Element;
TypeNode type = metaDataProvider.FieldType (f);
this.isStatic = metaDataProvider.IsStatic (f);
this.isManagedPointer = metaDataProvider.IsManagedPointer (type);
ResultType = resultType = metaDataProvider.ManagedPointer (type);
TypeNode declaringType = metaDataProvider.DeclaringType (f);
if (metaDataProvider.IsManagedPointer (expectedType))
expectedType = metaDataProvider.ElementType (expectedType);
expectedType = metaDataProvider.Unspecialized (expectedType);
if (!metaDataProvider.IsStatic (f) && declaringType.Equals (expectedType) &&
(!metaDataProvider.DerivesFrom (expectedType, declaringType) ||
!metaDataProvider.IsProtected (f) && !metaDataProvider.IsPublic (f)))
this.castTo = metaDataProvider.FullName (declaringType);
return true;
}
if (typeof (T) == typeof (Local)) {
var local = (Local) (object) this.Element;
TypeNode type = metaDataProvider.LocalType (local);
this.isManagedPointer = metaDataProvider.IsManagedPointer (type);
ResultType = resultType = metaDataProvider.ManagedPointer (type);
return true;
}
if (typeof (T) == typeof (Method)) {
var method = (Method) (object) this.Element;
ResultType = resultType = !IsAddressOf
? metaDataProvider.ReturnType (method)
: metaDataProvider.ManagedPointer (metaDataProvider.ReturnType (method));
if (metaDataProvider.IsManagedPointer (expectedType))
expectedType = metaDataProvider.ElementType (expectedType);
expectedType = metaDataProvider.Unspecialized (expectedType);
TypeNode declaringType = metaDataProvider.DeclaringType (method);
if (!metaDataProvider.IsStatic (method) && declaringType.Equals (expectedType) &&
(!metaDataProvider.DerivesFrom (expectedType, declaringType)
|| !metaDataProvider.IsProtected (method) && !metaDataProvider.IsPublic (method)))
this.castTo = metaDataProvider.FullName (declaringType);
return true;
}
ResultType = resultType = default(TypeNode);
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,110 @@
//
// PathExtensions.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.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
static class PathExtensions {
public static HashSet<Field> FieldsIn (this Sequence<PathElement> path)
{
var result = new HashSet<Field> ();
if (path != null) {
foreach (PathElement element in path.AsEnumerable ()) {
Field f;
if (element.TryField (out f))
result.Add (f);
}
}
return result;
}
public static string ToCodeString (this PathElement[] path)
{
return PathToString (path);
}
public static string ToCodeString (this Sequence<PathElement> path)
{
return PathToString (path.AsEnumerable ());
}
private static string PathToString (IEnumerable<PathElement> path)
{
bool first = true;
bool isReference = false;
bool isUnmanagedPointer = false;
var sb = new StringBuilder ();
List<PathElement> pathL = path.ToList ();
for (int i = 0; i < pathL.Count; i++) {
PathElement element = pathL [i];
if (element.IsMethodCall && !element.IsGetter && element.IsStatic) {
string oldString = sb.ToString ();
sb = new StringBuilder ();
sb.AppendFormat ("{0}({1})", element, oldString);
} else {
if (!string.IsNullOrEmpty (element.CastTo)) {
string oldString = sb.ToString ();
sb = new StringBuilder ();
sb.AppendFormat ("(({0}{1}){2})", element.CastTo, isUnmanagedPointer ? "*" : "", oldString);
}
sb.Append (isUnmanagedPointer ? "->" : ".");
sb.Append (element.ToString ());
if (element.IsMethodCall && !element.IsGetter)
sb.Append ("()");
}
if (first)
first = false;
int num = (element.IsAddressOf ? 1 : 0) + (element.IsUnmanagedPointer ? 1 : 0) + (element.IsManagedPointer ? 1 : 0);
isUnmanagedPointer = element.IsUnmanagedPointer;
for (int j = 0; j < num; j++) {
if (j + 1 < pathL.Count) {
if (pathL [j + 1].IsDeref)
++j;
} else
isReference = true;
}
}
if (isReference)
return isUnmanagedPointer ? sb.ToString () : "&" + sb;
if (isUnmanagedPointer)
return "*" + sb;
return sb.ToString ();
}
}
}

View File

@@ -0,0 +1,103 @@
//
// SpecialPathElement.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 Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Providers;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
class SpecialPathElement : PathElement<SpecialPathElementKind> {
private object type;
public SpecialPathElement (SpecialPathElementKind element, SymFunction c) : base (element, element.ToString (), c)
{
this.castTo = "";
}
public override bool IsAddressOf
{
get { return false; }
}
public override bool IsDeref
{
get { return this.Element == SpecialPathElementKind.Deref; }
}
public override bool TryGetResultType (out TypeNode resultType)
{
if (this.type is TypeNode) {
resultType = (TypeNode) this.type;
return true;
}
resultType = default (TypeNode);
return false;
}
public override bool TrySetType (TypeNode expectedType, IMetaDataProvider metaDataProvider, out TypeNode resultType)
{
switch (this.Element) {
case SpecialPathElementKind.Length:
this.castTo = metaDataProvider.IsArray (expectedType)
|| metaDataProvider.System_String.Equals (expectedType)
? ""
: "System.Array";
resultType = metaDataProvider.System_Int32;
return true;
case SpecialPathElementKind.Deref:
if (metaDataProvider.IsManagedPointer (expectedType)) {
TypeNode type = metaDataProvider.ElementType (expectedType);
this.type = type;
resultType = type;
return true;
}
resultType = default(TypeNode);
return false;
default:
resultType = default(TypeNode);
return false;
}
}
public override Result Decode<Data, Result, Visitor, Label> (Label label, Visitor visitor, Data data)
{
switch (this.Element) {
case SpecialPathElementKind.Length:
return visitor.LoadLength (label, Dummy.Value, Dummy.Value, data);
case SpecialPathElementKind.Deref:
throw new NotImplementedException ();
default:
throw new InvalidOperationException ();
}
}
}
}

View File

@@ -0,0 +1,34 @@
//
// SpecialPathElementKind.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.
//
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths {
enum SpecialPathElementKind {
Length,
Deref
}
}