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,87 @@
//
// AbstractDomainUpdate.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.SymbolicGraph {
class AbstractDomainUpdate<TFunc, TAbstractDomain> : Update<TFunc, TAbstractDomain>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
private readonly SymValue sv;
public AbstractDomainUpdate (SymValue sv)
{
this.sv = sv;
}
#region Overrides of Update
public override void Replay (MergeInfo<TFunc, TAbstractDomain> merge)
{
if (!merge.IsCommon (this.sv))
return;
TAbstractDomain val1 = merge.Graph1 [this.sv];
TAbstractDomain val2 = merge.Graph2 [this.sv];
bool weaker;
TAbstractDomain join = val1.Join (val2, merge.Widen, out weaker);
TAbstractDomain wasInResult = merge.Result [this.sv];
if (weaker) {
if (DebugOptions.Debug)
{
Console.WriteLine ("----SymGraph changed during AbstractDomainUpdate of {3} " +
"due to weaker abstractValue join (val1 = {0}, val2 = {1}, wasInResult = {2}",
val1, val2, wasInResult, this.sv);
}
merge.Changed = true;
}
if (join.Equals (wasInResult))
return;
merge.Result [this.sv] = join;
}
public override void ReplayElimination (MergeInfo<TFunc, TAbstractDomain> merge)
{
if (!merge.IsCommon (this.sv))
return;
TAbstractDomain val1 = merge.Graph1 [this.sv];
if (val1.IsTop)
merge.Result [this.sv] = val1;
else {
TAbstractDomain val2 = merge.Graph2 [this.sv];
if (val2.IsTop)
merge.Result [this.sv] = val2;
}
}
#endregion
}
}

View File

@ -0,0 +1,97 @@
//
// EdgeUpdate.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.SymbolicGraph {
class EdgeUpdate<TFunc, TAbstractDomain> : Update<TFunc, TAbstractDomain>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
private readonly SymValue from;
private readonly TFunc function;
public EdgeUpdate (SymValue from, TFunc function)
{
this.from = from;
this.function = function;
}
#region Overrides of Update
public override void Replay (MergeInfo<TFunc, TAbstractDomain> merge)
{
if (!merge.IsCommon (this.from))
return;
SymValue sv1 = merge.Graph1.LookupWithoutManifesting (this.from, this.function);
SymValue sv2 = merge.Graph2.LookupWithoutManifesting (this.from, this.function);
if (DebugOptions.Debug)
{
Console.WriteLine ("Replay edge update: {0} -{1} -> [ {2}, {3} ]",
this.from, this.function, sv1, sv2);
}
if (sv1 == null) {
if (this.function.KeepAsBottomField && merge.Graph1.HasAllBottomFields (this.from))
sv1 = merge.Graph1.BottomPlaceHolder;
else {
if (sv2 == null || merge.Widen || !this.function.ManifestField)
return;
if (DebugOptions.Debug)
{
Console.WriteLine ("---SymGraph changed due to manifestation of a top edge in Graph1");
}
merge.Changed = true;
}
}
if (sv2 == null) {
if (this.function.KeepAsBottomField && merge.Graph2.HasAllBottomFields (this.from))
sv2 = merge.Graph2.BottomPlaceHolder;
else {
if (merge.Widen || !this.function.ManifestField)
return;
if (DebugOptions.Debug)
{
Console.WriteLine ("---SymGraph changed due to manifestation of due to missing target in Graph2");
}
merge.Changed = true;
return;
}
}
SymValue r = merge.AddJointEdge (sv1, sv2, this.function, this.from);
if (r == null || r.UniqueId <= merge.LastCommonVariable)
return;
merge.JoinSymbolicValue (sv1, sv2, r);
}
public override void ReplayElimination (MergeInfo<TFunc, TAbstractDomain> merge)
{
}
#endregion
}
}

View File

@ -0,0 +1,79 @@
//
// EliminateEdgeUpdate.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.SymbolicGraph {
class EliminateEdgeUpdate<TFunc, TAbstractDomain> : Update<TFunc, TAbstractDomain>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
private readonly SymValue from;
private readonly TFunc function;
public EliminateEdgeUpdate (SymValue sv, TFunc function)
{
this.from = sv;
this.function = function;
}
#region Overrides of Update
public override void ReplayElimination (MergeInfo<TFunc, TAbstractDomain> merge)
{
if (!merge.IsCommon (this.from))
return;
merge.Result.Eliminate (this.function, this.from);
}
public override void Replay (MergeInfo<TFunc, TAbstractDomain> merge)
{
if (!merge.IsCommon (this.from))
return;
SymValue sv1 = merge.Graph1.LookupWithoutManifesting (this.from, this.function);
SymValue sv2 = merge.Graph2.LookupWithoutManifesting (this.from, this.function);
if (sv1 != null && sv2 != null)
return;
if (sv1 != null) {
if (DebugOptions.Debug)
{
Console.WriteLine ("---SymGraph changed due to EliminateEdgeUpdate {0}-{1} " +
"-> that is only in G1", this.from, this.function);
}
merge.Changed = true;
}
bool noEdgeInResult = merge.Result.LookupWithoutManifesting (this.from, this.function) == null;
if (noEdgeInResult)
return;
merge.Result.Eliminate (this.function, this.from);
}
#endregion
}
}

View File

@ -0,0 +1,64 @@
//
// EqualityPair.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.SymbolicGraph {
struct EqualityPair<TFunc, TAbstractDomain> : IEquatable<EqualityPair<TFunc, TAbstractDomain>>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
public readonly SymValue Sv1;
public readonly SymValue Sv2;
public EqualityPair (SymValue v1, SymValue v2)
{
this.Sv1 = v1;
this.Sv2 = v2;
}
#region Implementation of IEquatable<SymGraph<Constant,AbstractValue>.EqualityPair>
public bool Equals (EqualityPair<TFunc, TAbstractDomain> other)
{
return (this.Sv1 == other.Sv1 && this.Sv2 == other.Sv2);
}
#endregion
public override bool Equals (object obj)
{
if (obj is EqualityPair<TFunc, TAbstractDomain>)
return Equals ((EqualityPair<TFunc, TAbstractDomain>) obj);
return false;
}
public override int GetHashCode ()
{
return (this.Sv1 == null ? 1 : this.Sv1.GlobalId) + this.Sv2.GlobalId;
}
}
}

View File

@ -0,0 +1,60 @@
//
// EqualityUpdate.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.SymbolicGraph {
class EqualityUpdate<TFunc, TAbstractDomain> : Update<TFunc, TAbstractDomain>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
private readonly SymValue sv1;
private readonly SymValue sv2;
public EqualityUpdate (SymValue sv1, SymValue sv2)
{
this.sv1 = sv1;
this.sv2 = sv2;
}
#region Overrides of Update
public override void Replay (MergeInfo<TFunc, TAbstractDomain> merge)
{
if (!merge.IsCommon (this.sv1) || !merge.IsCommon (this.sv2) || (!merge.Graph1.IsEqual (this.sv1, this.sv2) || merge.Result.IsEqual (this.sv1, this.sv2)))
return;
if (merge.Graph2.IsEqual (this.sv1, this.sv2))
merge.Result.AssumeEqual (this.sv1, this.sv2);
else
merge.Changed = true;
}
public override void ReplayElimination (MergeInfo<TFunc, TAbstractDomain> merge)
{
}
#endregion
}
}

View File

@ -0,0 +1,53 @@
//
// IMergeInfo.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 Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.SymbolicGraph {
interface IMergeInfo {
bool Changed { get; }
IEnumerable<Tuple<SymValue, SymValue, SymValue>> MergeTriples { get; }
IImmutableMap<SymValue, Sequence<SymValue>> ForwardG1Map { get; }
IImmutableMap<SymValue, Sequence<SymValue>> ForwardG2Map { get; }
bool IsResultGraph<TFunc, TAbstractDomain> (SymGraph<TFunc, TAbstractDomain> graph)
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain>;
bool IsGraph1<TFunc, TAbstractDomain> (SymGraph<TFunc, TAbstractDomain> graph)
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain>;
bool IsGraph2<TFunc, TAbstractDomain> (SymGraph<TFunc, TAbstractDomain> graph)
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain>;
}
}

View File

@ -0,0 +1,71 @@
//
// MultiEdge.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.SymbolicGraph {
struct MultiEdge<TFunc, TAbstractDomain> : IEquatable<MultiEdge<TFunc, TAbstractDomain>>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
public readonly int Arity;
public readonly int Index;
public readonly TFunc Function;
public MultiEdge (TFunc function, int index, int arity)
{
this.Function = function;
this.Index = index;
this.Arity = arity;
}
#region Implementation of IEquatable<MultiEdge>
public bool Equals (MultiEdge<TFunc, TAbstractDomain> other)
{
return (this.Index == other.Index && this.Arity == other.Arity && this.Function.Equals (other.Function));
}
#endregion
public override bool Equals (object obj)
{
if (obj is MultiEdge<TFunc, TAbstractDomain>)
return Equals ((MultiEdge<TFunc, TAbstractDomain>) obj);
return false;
}
public override int GetHashCode ()
{
return this.Arity*13 + this.Index;
}
public override string ToString ()
{
return String.Format ("[{0}:{1}]", this.Function, this.Index);
}
}
}

View File

@ -0,0 +1,60 @@
//
// MultiEdgeUpdate.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.SymbolicGraph {
class MultiEdgeUpdate<TFunc, TAbstractDomain> : Update<TFunc, TAbstractDomain>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
private readonly SymValue[] from;
private readonly TFunc function;
public MultiEdgeUpdate (SymValue[] from, TFunc function)
{
this.function = function;
this.from = from;
}
#region Overrides of Update
public override void Replay (MergeInfo<TFunc, TAbstractDomain> merge)
{
int len = this.from.Length;
for (int i = 0; i < len; i++) {
SymValue sv = this.from [i];
if (merge.IsCommon (sv))
merge.JoinMultiEdge (sv, sv, new MultiEdge<TFunc, TAbstractDomain> (this.function, i, len));
}
}
public override void ReplayElimination (MergeInfo<TFunc, TAbstractDomain> merge)
{
}
#endregion
}
}

View File

@ -0,0 +1,62 @@
//
// SymGraphTerm.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.Linq;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.SymbolicGraph {
struct SymGraphTerm<TFunc> : IEquatable<SymGraphTerm<TFunc>>
where TFunc : IEquatable<TFunc> {
public readonly SymValue[] Args;
public readonly TFunc Function;
public SymGraphTerm (TFunc function, params SymValue[] args)
{
this.Function = function;
this.Args = args;
}
public bool Equals (SymGraphTerm<TFunc> that)
{
if (!this.Function.Equals (that.Function) || this.Args.Length != that.Args.Length)
return false;
for (int i = 0; i < this.Args.Length; i++) {
if (!this.Args [i].Equals (that.Args [i]))
return false;
}
return true;
}
public override string ToString ()
{
var args = this.Args == null ? "<no args>" : string.Join (", ", this.Args.Select (a => a.ToString ()));
return string.Format ("Term({0}, {{{1}}})", this.Function, args);
}
}
}

View File

@ -0,0 +1,53 @@
//
// Update.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.DataStructures;
namespace Mono.CodeContracts.Static.Analysis.HeapAnalysis.SymbolicGraph {
abstract class Update<TFunc, TAbstractDomain>
where TFunc : IEquatable<TFunc>, IConstantInfo
where TAbstractDomain : IAbstractDomainForEGraph<TAbstractDomain>, IEquatable<TAbstractDomain> {
public Update<TFunc, TAbstractDomain> Next { get; private set; }
public abstract void Replay (MergeInfo<TFunc, TAbstractDomain> merge);
public abstract void ReplayElimination (MergeInfo<TFunc, TAbstractDomain> merge);
public static Update<TFunc, TAbstractDomain> Reverse (Sequence<Update<TFunc, TAbstractDomain>> updates,
Sequence<Update<TFunc, TAbstractDomain>> common)
{
Update<TFunc, TAbstractDomain> last = null;
for (; updates != common; updates = updates.Tail) {
Update<TFunc, TAbstractDomain> head = updates.Head;
head.Next = last;
last = head;
}
return last;
}
}
}