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,158 @@
//
// FullExpressionDecoder.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.AST;
using Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths;
using Mono.CodeContracts.Static.Analysis.Numerical;
using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Lattices;
using Mono.CodeContracts.Static.Providers;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class FullExpressionDecoder<V, E> : IFullExpressionDecoder<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
public readonly VisitorForIsBinaryExpression<V, E> BinaryExpressionVisitor;
public readonly VisitorForIsInst<V, E> IsInstVisitor;
public readonly VisitorForIsNull<V, E> IsNullVisitor;
public readonly VisitorForSizeOf<V, E> SizeOfVisitor;
public readonly VisitorForIsUnaryExpression<V, E> UnaryExpressionVisitor;
public readonly VisitorForUnderlyingVariable<V, E> UnderlyingVariableVisitor;
public readonly VisitorForValueOf<V, E> ValueOfVisitor;
public readonly VisitorForVariable<V, E> VariableVisitor;
public readonly VisitorForVariablesIn<V, E> VariablesInVisitor;
protected readonly IMetaDataProvider MetaDataProvider;
#region Implementation of IFullExpressionDecoder<V,E>
public bool IsVariable (E expr, out object variable)
{
V var;
bool res = VisitorForVariable<V, E>.IsVariable (expr, out var, this);
variable = var;
return res;
}
public V UnderlyingVariable (E expr)
{
return VisitorForUnderlyingVariable<V, E>.IsUnderlyingVariable (expr, this);
}
public bool IsNull (E expr)
{
return VisitorForIsNull<V, E>.IsNull (expr, this);
}
public bool IsConstant (E expr, out object value, out TypeNode type)
{
return VisitorForValueOf<V, E>.IsConstant (expr, out value, out type, this);
}
public bool IsSizeof (E expr, out TypeNode type)
{
return VisitorForSizeOf<V, E>.IsSizeOf (expr, out type, this);
}
public bool IsIsinst (E expr, out E arg, out TypeNode type)
{
return VisitorForIsInst<V, E>.IsIsInst (expr, out type, out arg, this);
}
public bool IsUnaryExpression (E expr, out UnaryOperator op, out E arg)
{
return VisitorForIsUnaryExpression<V, E>.IsUnary (expr, out op, out arg, this);
}
public bool IsBinaryExpression (E expr, out BinaryOperator op, out E left, out E right)
{
return VisitorForIsBinaryExpression<V, E>.IsBinary (expr, out op, out left, out right, this);
}
public void AddFreeVariables (E expr, ISet<E> set)
{
VisitorForVariablesIn<V, E>.AddFreeVariables (expr, set, this);
}
public Sequence<PathElement> GetVariableAccessPath (E expr)
{
return ContextProvider.ValueContext.AccessPathList (ContextProvider.ExpressionContext.GetPC (expr), ContextProvider.ExpressionContext.Unrefine (expr), true, false);
}
public bool TryGetType (E expr, out TypeNode type)
{
FlatDomain<TypeNode> aType = ContextProvider.ExpressionContext.GetType (expr);
if (aType.IsNormal()) {
type = aType.Value;
return true;
}
type = null;
return false;
}
public bool TrySizeOfAsConstant (E expr, out int sizeAsConstant)
{
return TrySizeOf (expr, out sizeAsConstant);
}
private bool TrySizeOf (E expr, out int sizeAsConstant)
{
TypeNode type;
if (VisitorForSizeOf<V, E>.IsSizeOf (expr, out type, this)) {
int size = this.MetaDataProvider.TypeSize (type);
if (size != -1) {
sizeAsConstant = size;
return true;
}
}
sizeAsConstant = -1;
return false;
}
#endregion
public FullExpressionDecoder (IMetaDataProvider metaDataProvider, IExpressionContextProvider<E, V> contextProvider)
{
ContextProvider = contextProvider;
this.MetaDataProvider = metaDataProvider;
this.VariableVisitor = new VisitorForVariable<V, E> ();
this.UnderlyingVariableVisitor = new VisitorForUnderlyingVariable<V, E> ();
this.UnaryExpressionVisitor = new VisitorForIsUnaryExpression<V, E> ();
this.BinaryExpressionVisitor = new VisitorForIsBinaryExpression<V, E> ();
this.VariablesInVisitor = new VisitorForVariablesIn<V, E> (contextProvider);
this.ValueOfVisitor = new VisitorForValueOf<V, E> ();
this.SizeOfVisitor = new VisitorForSizeOf<V, E> ();
this.IsInstVisitor = new VisitorForIsInst<V, E> ();
this.IsNullVisitor = new VisitorForIsNull<V, E> ();
}
public IExpressionContextProvider<E, V> ContextProvider { get; private set; }
}
}

View File

@@ -0,0 +1,50 @@
//
// IFullExpressionDecoder.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 Mono.CodeContracts.Static.AST;
using Mono.CodeContracts.Static.Analysis.HeapAnalysis.Paths;
using Mono.CodeContracts.Static.Analysis.Numerical;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
interface IFullExpressionDecoder<Variable, Expression> {
bool IsVariable (Expression expr, out object variable);
Variable UnderlyingVariable (Expression expr);
bool IsNull (Expression expr);
bool IsConstant (Expression expr, out object value, out TypeNode type);
bool IsSizeof (Expression expr, out TypeNode type);
bool IsIsinst (Expression expr, out Expression arg, out TypeNode type);
bool IsUnaryExpression (Expression expr, out UnaryOperator op, out Expression arg);
bool IsBinaryExpression (Expression expr, out BinaryOperator op, out Expression left, out Expression right);
void AddFreeVariables (Expression expr, ISet<Expression> set);
Sequence<PathElement> GetVariableAccessPath (Expression expr);
bool TryGetType (Expression expr, out TypeNode type);
bool TrySizeOfAsConstant (Expression expr, out int sizeAsConstant);
}
}

View File

@@ -0,0 +1,82 @@
//
// QueryVisitor.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.AST.Visitors;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
abstract class QueryVisitor<V, E> : ISymbolicExpressionVisitor<E, E, V, Dummy, bool>
where V : IEquatable<V>
where E : IEquatable<E>
{
#region ISymbolicExpressionVisitor<E,E,V,Dummy,bool> Members
public virtual bool Binary (E pc, BinaryOperator op, V dest, E operand1, E operand2, Dummy data)
{
return false;
}
public virtual bool Isinst (E pc, TypeNode type, V dest, E obj, Dummy data)
{
return false;
}
public virtual bool LoadNull (E pc, V dest, Dummy polarity)
{
return false;
}
public virtual bool LoadConst (E pc, TypeNode type, object constant, V dest, Dummy data)
{
return false;
}
public virtual bool Sizeof (E pc, TypeNode type, V dest, Dummy data)
{
return false;
}
public virtual bool Unary (E pc, UnaryOperator op, bool unsigned, V dest, E source, Dummy data)
{
return false;
}
public virtual bool SymbolicConstant (E pc, V variable, Dummy data)
{
return false;
}
#endregion
protected static bool Decode<Visitor> (E expr, Visitor visitor, FullExpressionDecoder<V,E> decoder)
where Visitor : QueryVisitor<V, E>
{
return decoder.ContextProvider.ExpressionContext.Decode<Dummy, bool, Visitor> (expr, visitor, Dummy.Value);
}
}
}

View File

@@ -0,0 +1,61 @@
//
// VisitorForIsBinaryExpression.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;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForIsBinaryExpression<V, E> : QueryVisitor<V, E>
where V : IEquatable<V> where E : IEquatable<E> {
private BinaryOperator op;
private E left;
private E right;
public static bool IsBinary (E expr, out BinaryOperator bop, out E left, out E right, FullExpressionDecoder<V,E> decoder)
{
VisitorForIsBinaryExpression<V, E> v = decoder.BinaryExpressionVisitor;
bool res = Decode (expr, v, decoder);
bop = v.op;
left = v.left;
right = v.right;
return res;
}
public override bool Binary (E pc, BinaryOperator op, V dest, E operand1, E operand2, Dummy data)
{
this.op = op;
this.left = operand1;
this.right = operand2;
return true;
}
}
}

View File

@@ -0,0 +1,58 @@
//
// VisitorForIsInst.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;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForIsInst<V, E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
private E argument;
private TypeNode type;
public static bool IsIsInst (E expr, out TypeNode type, out E arg, FullExpressionDecoder<V,E> decoder)
{
VisitorForIsInst<V, E> v = decoder.IsInstVisitor;
bool res = Decode (expr, v, decoder);
arg = v.argument;
type = v.type;
return res;
}
public override bool Isinst (E pc, TypeNode type, V dest, E obj, Dummy data)
{
this.type = type;
this.argument = obj;
return true;
}
}
}

View File

@@ -0,0 +1,48 @@
//
// VisitorForIsNull.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.ExpressionAnalysis.Decoding {
class VisitorForIsNull<V, E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
public static bool IsNull (E expr, FullExpressionDecoder<V, E> decoder)
{
VisitorForIsNull<V, E> v = decoder.IsNullVisitor;
return Decode (expr, v, decoder);
}
public override bool LoadNull (E pc, V dest, Dummy polarity)
{
return true;
}
}
}

View File

@@ -0,0 +1,56 @@
//
// VisitorForIsUnaryExpression.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;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForIsUnaryExpression<V, E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
private E Argument;
private UnaryOperator Operator;
public static bool IsUnary (E expr, out UnaryOperator op, out E arg, FullExpressionDecoder<V, E> decoder)
{
VisitorForIsUnaryExpression<V, E> v = decoder.UnaryExpressionVisitor;
bool res = Decode (expr, v, decoder);
op = v.Operator;
arg = v.Argument;
return res;
}
public override bool Unary (E pc, UnaryOperator op, bool unsigned, V dest, E source, Dummy data)
{
this.Argument = source;
this.Operator = op;
return true;
}
}
}

View File

@@ -0,0 +1,55 @@
//
// VisitorForSizeOf.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;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForSizeOf<V, E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
private TypeNode result;
public static bool IsSizeOf (E expr, out TypeNode type, FullExpressionDecoder<V, E> decoder)
{
VisitorForSizeOf<V, E> v = decoder.SizeOfVisitor;
bool res = Decode (expr, v, decoder);
type = v.result;
return res;
}
public override bool Sizeof (E pc, TypeNode type, V dest, Dummy data)
{
this.result = type;
return true;
}
}
}

View File

@@ -0,0 +1,88 @@
//
// VisitorForUnderlyingVariable.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;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForUnderlyingVariable<V,E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
private V Variable;
public static V IsUnderlyingVariable (E expr, FullExpressionDecoder<V, E> decoder)
{
VisitorForUnderlyingVariable<V, E> visitor = decoder.UnderlyingVariableVisitor;
Decode (expr, visitor, decoder);
return visitor.Variable;
}
public override bool Binary (E pc, BinaryOperator op, V dest, E operand1, E operand2, Dummy data)
{
this.Variable = dest;
return true;
}
public override bool Isinst (E pc, TypeNode type, V dest, E obj, Dummy data)
{
this.Variable = dest;
return true;
}
public override bool LoadConst (E pc, TypeNode type, object constant, V dest, Dummy data)
{
this.Variable = dest;
return true;
}
public override bool LoadNull (E pc, V dest, Dummy polarity)
{
this.Variable = dest;
return true;
}
public override bool Sizeof (E pc, TypeNode type, V dest, Dummy data)
{
this.Variable = dest;
return true;
}
public override bool SymbolicConstant (E pc, V variable, Dummy data)
{
this.Variable = variable;
return true;
}
public override bool Unary (E pc, UnaryOperator op, bool unsigned, V dest, E source, Dummy data)
{
this.Variable = dest;
return true;
}
}
}

View File

@@ -0,0 +1,64 @@
//
// VisitorForValueOf.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;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForValueOf<V, E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
private TypeNode Type;
private object Value;
public static bool IsConstant (E expr, out object value, out TypeNode type, FullExpressionDecoder<V, E> decoder)
{
VisitorForValueOf<V, E> v = decoder.ValueOfVisitor;
bool res = Decode (expr, v, decoder);
value = v.Value;
type = v.Type;
return res;
}
public override bool LoadNull (E pc, V dest, Dummy polarity)
{
this.Type = null;
this.Value = null;
return true;
}
public override bool LoadConst (E pc, TypeNode type, object constant, V dest, Dummy data)
{
this.Type = type;
this.Value = constant;
return true;
}
}
}

View File

@@ -0,0 +1,52 @@
//
// VisitorForVariable.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.ExpressionAnalysis.Decoding {
class VisitorForVariable<V,E> : QueryVisitor<V, E>
where V : IEquatable<V>
where E : IEquatable<E> {
private V variable;
public static bool IsVariable (E expr, out V var, FullExpressionDecoder<V, E> decoder)
{
VisitorForVariable<V, E> visitor = decoder.VariableVisitor;
bool res = Decode (expr, visitor, decoder);
var = visitor.variable;
return res;
}
public override bool SymbolicConstant (E pc, V variable, Dummy data)
{
this.variable = variable;
return true;
}
}
}

View File

@@ -0,0 +1,100 @@
//
// VisitorForVariablesIn.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.AST;
using Mono.CodeContracts.Static.AST.Visitors;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.Analysis.ExpressionAnalysis.Decoding {
class VisitorForVariablesIn<V, E> : ISymbolicExpressionVisitor<E, E, V, ISet<E>, Dummy>
where V : IEquatable<V>
where E : IEquatable<E> {
private readonly IExpressionContextProvider<E, V> contextProvider;
public VisitorForVariablesIn (IExpressionContextProvider<E, V> contextProvider)
{
this.contextProvider = contextProvider;
}
public static void AddFreeVariables (E expr, ISet<E> set, FullExpressionDecoder<V, E> decoder)
{
decoder.VariablesInVisitor.Recurse (expr, set);
}
private void Recurse (E expr, ISet<E> set)
{
this.contextProvider.ExpressionContext.Decode<ISet<E>, Dummy, VisitorForVariablesIn<V, E>> (expr, this, set);
}
#region Implementation of IExpressionILVisitor<E,E,V,ISet<E>,Dummy>
public Dummy Binary (E pc, BinaryOperator op, V dest, E operand1, E operand2, ISet<E> data)
{
Recurse (operand1, data);
Recurse (operand2, data);
return Dummy.Value;
}
public Dummy Isinst (E pc, TypeNode type, V dest, E obj, ISet<E> data)
{
data.Add (pc);
return Dummy.Value;
}
public Dummy LoadNull (E pc, V dest, ISet<E> polarity)
{
return Dummy.Value;
}
public Dummy LoadConst (E pc, TypeNode type, object constant, V dest, ISet<E> data)
{
return Dummy.Value;
}
public Dummy Sizeof (E pc, TypeNode type, V dest, ISet<E> data)
{
data.Add (pc);
return Dummy.Value;
}
public Dummy Unary (E pc, UnaryOperator op, bool unsigned, V dest, E source, ISet<E> data)
{
Recurse (source, data);
return Dummy.Value;
}
#endregion
#region Implementation of ISymbolicExpressionVisitor<E,E,V,ISet<E>,Dummy>
public Dummy SymbolicConstant (E pc, V variable, ISet<E> data)
{
return Dummy.Value;
}
#endregion
}
}