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,109 @@
//
// CodeVisitor.cs
//
// Authors:
// Alexander Chebaturkin (chebaturkin@gmail.com)
//
// Copyright (C) 2012 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.IO;
using Mono.CodeContracts.Static.Analysis;
using Mono.CodeContracts.Static.ControlFlow;
using Mono.CodeContracts.Static.DataFlowAnalysis;
using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Providers;
namespace Mono.CodeContracts.Static.AST.Visitors {
class CodeVisitor<Variable, Expression, ContextData, EdgeData>
: ILVisitorBase<APC, Expression, Variable, bool, bool>,
IAnalysis<APC, bool, IILVisitor<APC, Expression, Variable, bool, bool>, EdgeData>
where ContextData : IMethodContextProvider {
private ICodeLayer<Expression, Variable, ContextData, EdgeData> codeLayer;
public ContextData Context
{
get { return this.codeLayer.ILDecoder.ContextProvider; }
}
protected IMetaDataProvider MetaDataProvider
{
get { return this.codeLayer.MetaDataProvider; }
}
public void Run (ICodeLayer<Expression, Variable, ContextData, EdgeData> codeLayer)
{
this.codeLayer = codeLayer;
codeLayer.CreateForward (this) (true);
}
#region Overrides of ILVisitorBase<APC,Expression,Variable,bool,bool>
public override bool DefaultVisit (APC pc, bool data)
{
return data;
}
#endregion
#region Implementation of IAnalysis<APC,bool,IILVisitor<APC,Expression,Variable,bool,bool>,EdgeData>
public IILVisitor<APC, Expression, Variable, bool, bool> GetVisitor ()
{
return this;
}
public virtual bool Join (Pair<APC, APC> edge, bool newstate, bool prevstate, out bool weaker, bool widen)
{
weaker = false;
return true;
}
public bool ImmutableVersion (bool arg)
{
return arg;
}
public bool MutableVersion (bool arg)
{
return arg;
}
public bool EdgeConversion (APC @from, APC to, bool isJoinPoint, EdgeData data, bool state)
{
return state;
}
public bool IsBottom (APC pc, bool state)
{
return !state;
}
public Predicate<APC> SaveFixPointInfo (IFixPointInfo<APC, bool> fixPointInfo)
{
return null;
}
public void Dump (Pair<bool, TextWriter> pair)
{
}
#endregion
}
}

View File

@@ -0,0 +1,467 @@
//
// DefaultNodeVisitor.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;
namespace Mono.CodeContracts.Static.AST.Visitors {
class DefaultNodeVisitor : NodeVisitor {
#region Overrides of NodeVisitor
public override Node Visit (Node node)
{
if (node == null)
return null;
switch (node.NodeType) {
case NodeType.Nop:
return node;
#region Binary
case NodeType.Add:
case NodeType.Sub:
case NodeType.Rem:
case NodeType.Clt:
case NodeType.Cgt:
case NodeType.Ceq:
case NodeType.Box:
case NodeType.Le:
case NodeType.Mul:
case NodeType.Div:
case NodeType.Div_Un:
case NodeType.Rem_Un:
case NodeType.And:
case NodeType.Or:
case NodeType.Shr:
case NodeType.Xor:
case NodeType.Shl:
case NodeType.Shr_Un:
case NodeType.Ne:
case NodeType.Ge:
case NodeType.Gt:
case NodeType.Lt:
case NodeType.Eq:
return VisitBinaryExpression ((BinaryExpression) node);
#endregion
case NodeType.Call:
case NodeType.Jmp:
case NodeType.MethodCall:
return VisitMethodCall ((MethodCall) node);
case NodeType.Conv:
case NodeType.Conv_I1:
case NodeType.Conv_I2:
case NodeType.Conv_I8:
case NodeType.Conv_I4:
case NodeType.Conv_R4:
case NodeType.Conv_R8:
case NodeType.Neg:
case NodeType.Not:
case NodeType.LogicalNot:
return VisitUnaryExpression ((UnaryExpression) node);
case NodeType.Literal:
return VisitLiteral ((Literal) node);
case NodeType.This:
return VisitThis ((This) node);
case NodeType.Block:
return VisitBlock ((Block) node);
case NodeType.Branch:
return VisitBranch ((Branch) node);
case NodeType.Return:
return VisitReturn ((Return) node);
case NodeType.AssignmentStatement:
return VisitAssignmentStatement ((AssignmentStatement) node);
case NodeType.Local:
return VisitLocal ((Local) node);
case NodeType.Parameter:
return VisitParameter ((Parameter) node);
case NodeType.ExpressionStatement:
return VisitExpressionStatement ((ExpressionStatement) node);
case NodeType.Method:
return VisitMethod ((Method) node);
case NodeType.MethodContract:
return VisitMethodContract ((MethodContract) node);
case NodeType.Requires:
return VisitRequires ((Requires) node);
case NodeType.Ensures:
return VisitEnsures ((Ensures) node);
case NodeType.TypeNode:
return VisitTypeNode ((TypeNode) node);
case NodeType.Assembly:
return VisitAssembly ((AssemblyNode) node);
case NodeType.Module:
return VisitModule ((Module) node);
case NodeType.MemberBinding:
return VisitMemberBinding ((MemberBinding) node);
case NodeType.Construct:
return VisitConstruct ((Construct) node);
}
return VisitUnknownNodeType (node);
}
public virtual AssemblyNode VisitAssembly (AssemblyNode node)
{
if (node == null)
return null;
VisitModuleList (node.Modules);
return node;
}
public virtual void VisitModuleList (IEnumerable<Module> node)
{
if (node == null)
return;
foreach (Module module in node)
VisitModule (module);
}
private Module VisitModule (Module node)
{
if (node == null)
return null;
VisitTypeNodeList (node.Types);
return node;
}
public virtual Statement VisitAssignmentStatement (AssignmentStatement node)
{
if (node == null)
return node;
node.Target = VisitTargetExpression (node.Target);
node.Source = VisitExpression (node.Source);
return node;
}
public virtual Expression VisitBinaryExpression (BinaryExpression node)
{
if (node == null)
return node;
node.Left = VisitExpression (node.Left);
node.Right = VisitExpression (node.Right);
return node;
}
public virtual Block VisitBlock (Block node)
{
if (node == null)
return null;
node.Statements = VisitStatementList (node.Statements);
return node;
}
public virtual List<Statement> VisitStatementList (List<Statement> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++)
node [i] = (Statement) Visit (node [i]);
return node;
}
public virtual Statement VisitBranch (Branch node)
{
if (node == null)
return null;
node.Condition = VisitExpression (node.Condition);
return node;
}
public virtual Expression VisitConstruct (Construct node)
{
if (node == null)
return null;
node.Constructor = VisitExpression (node.Constructor);
node.Arguments = VisitExpressionList (node.Arguments);
return node;
}
public virtual Ensures VisitEnsures (Ensures node)
{
if (node == null)
return null;
node.Assertion = VisitExpression (node.Assertion);
node.UserMessage = VisitExpression (node.UserMessage);
return node;
}
public virtual Expression VisitExpression (Expression node)
{
if (node == null)
return null;
return node;
}
public virtual Statement VisitExpressionStatement (ExpressionStatement node)
{
if (node == null)
return null;
node.Expression = VisitExpression (node.Expression);
return node;
}
public virtual Expression VisitLiteral (Literal node)
{
return node;
}
public virtual Expression VisitLocal (Local node)
{
if (node == null)
return null;
node.Type = VisitTypeNode (node.Type);
//todo: maybe there should be something else
return node;
}
public virtual Expression VisitMemberBinding (MemberBinding node)
{
if (node == null)
return null;
node.TargetObject = VisitExpression (node.TargetObject);
return node;
}
public virtual Method VisitMethod (Method node)
{
if (node == null)
return null;
node.ReturnType = VisitTypeNode (node.ReturnType);
node.Parameters = VisitParameterList (node.Parameters);
node.MethodContract = VisitMethodContract (node.MethodContract);
node.Body = VisitBlock (node.Body);
return node;
}
public virtual List<Parameter> VisitParameterList (List<Parameter> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++)
node [i] = VisitParameter (node [i]);
return node;
}
public virtual Expression VisitMethodCall (MethodCall node)
{
if (node == null)
return null;
node.Callee = VisitExpression (node.Callee);
node.Arguments = VisitExpressionList (node.Arguments);
return node;
}
public virtual MethodContract VisitMethodContract (MethodContract node)
{
if (node == null)
return null;
node.Requires = VisitRequiresList (node.Requires);
node.Ensures = VisitEnsuresList (node.Ensures);
return node;
}
public virtual List<Ensures> VisitEnsuresList (List<Ensures> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++)
node [i] = (Ensures) Visit (node [i]);
return node;
}
public virtual List<Requires> VisitRequiresList (List<Requires> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++)
node [i] = (Requires) Visit (node [i]);
return node;
}
public virtual Parameter VisitParameter (Parameter node)
{
if (node == null)
return null;
node.Type = VisitTypeNode (node.Type);
//todo: there may be something else
return node;
}
public virtual Requires VisitRequires (Requires node)
{
if (node == null)
return null;
node.Assertion = VisitExpression (node.Assertion);
node.UserMessage = VisitExpression (node.UserMessage);
return node;
}
public virtual Return VisitReturn (Return node)
{
if (node == null)
return null;
node.Expression = VisitExpression (node.Expression);
return node;
}
public virtual Expression VisitTargetExpression (Expression node)
{
return VisitExpression (node);
}
public virtual Expression VisitThis (This node)
{
if (node == null)
return null;
node.Type = VisitTypeNode (node.Type);
return node;
}
public virtual TypeNode VisitTypeNode (TypeNode node)
{
if (node == null)
return null;
var clazz = node as Class;
if (clazz != null)
clazz.BaseType = VisitTypeNode (clazz.BaseType);
VisitPropertiesList (node.Properties);
VisitMethodsList (node.Methods);
VisitTypeNodeList (node.NestedTypes);
return node;
}
public virtual List<Property> VisitPropertiesList (List<Property> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++) {
Property property = node [i];
if (property != null)
node [i] = (Property) Visit (node [i]);
}
return node;
}
public virtual List<Method> VisitMethodsList (List<Method> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++) {
Method method = node [i];
if (method != null)
node [i] = (Method) Visit (node [i]);
}
return node;
}
public virtual List<TypeNode> VisitTypeNodeList (List<TypeNode> node)
{
if (node == null)
return null;
for (int i = 0; i < node.Count; i++) {
TypeNode method = node [i];
if (method != null)
node [i] = (TypeNode) Visit (node [i]);
}
return node;
}
public virtual Expression VisitUnaryExpression (UnaryExpression node)
{
if (node == null)
return null;
node.Operand = VisitExpression (node.Operand);
return node;
}
public virtual Node VisitUnknownNodeType (Node node)
{
return node;
}
#endregion
}
}

View File

@@ -0,0 +1,35 @@
//
// IAggregateVisitor.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.DataStructures;
namespace Mono.CodeContracts.Static.AST.Visitors {
interface IAggregateVisitor<Label, Data, Result> : IILVisitor<Label, Dummy, Dummy, Data, Result> {
Result Aggregate (Label pc, Label aggregateStart, bool canBeTargetOfBranch, Data data);
}
}

View File

@@ -0,0 +1,35 @@
//
// ICodeConsumer.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.Providers;
namespace Mono.CodeContracts.Static.AST.Visitors {
interface ICodeConsumer<Data, Result> {
Result Accept<Label> (ICodeProvider<Label> codeProvider, Label entryPoint, Data data);
}
}

View File

@@ -0,0 +1,38 @@
//
// IExpressionILVisitor.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.AST.Visitors {
interface IExpressionILVisitor<Label, Source, Dest, Data, Result> {
Result Binary (Label pc, BinaryOperator bop, Dest dest, Source src1, Source src2, Data data);
Result Unary (Label pc, UnaryOperator uop, bool unsigned, Dest dest, Source source, Data data);
Result LoadNull (Label pc, Dest dest, Data polarity);
Result LoadConst (Label pc, TypeNode type, object constant, Dest dest, Data data);
Result Sizeof (Label pc, TypeNode type, Dest dest, Data data);
Result Isinst (Label pc, TypeNode type, Dest dest, Source obj, Data data);
}
}

View File

@@ -0,0 +1,102 @@
//
// IILVisitor.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.DataStructures;
namespace Mono.CodeContracts.Static.AST.Visitors {
interface IILVisitor<TLabel, TSource, TDest, TData, TResult> :
IExpressionILVisitor<TLabel, TSource, TDest, TData, TResult>,
ISyntheticILVisitor<TLabel, TSource, TDest, TData, TResult> {
TResult Arglist (TLabel pc, TDest dest, TData data);
TResult Branch (TLabel pc, TLabel target, bool leavesExceptionBlock, TData data);
TResult BranchCond (TLabel pc, TLabel target, BranchOperator bop, TSource value1, TSource value2, TData data);
TResult BranchTrue (TLabel pc, TLabel target, TSource cond, TData data);
TResult BranchFalse (TLabel pc, TLabel target, TSource cond, TData data);
TResult Break (TLabel pc, TData data);
TResult Call<TypeList, ArgList> (TLabel pc, Method method, bool virt, TypeList extraVarargs, TDest dest, ArgList args, TData data)
where TypeList : IIndexable<TypeNode>
where ArgList : IIndexable<TSource>;
TResult Calli<TypeList, ArgList> (TLabel pc, TypeNode returnType, TypeList argTypes, bool instance, TDest dest, TSource functionPointer, ArgList args, TData data)
where TypeList : IIndexable<TypeNode>
where ArgList : IIndexable<TSource>;
TResult CheckFinite (TLabel pc, TDest dest, TSource source, TData data);
TResult CopyBlock (TLabel pc, TSource destAddress, TSource srcAddress, TSource len, TData data);
TResult EndFilter (TLabel pc, TSource decision, TData data);
TResult EndFinally (TLabel pc, TData data);
TResult Jmp (TLabel pc, Method method, TData data);
TResult LoadArg (TLabel pc, Parameter argument, bool isOld, TDest dest, TData data);
TResult LoadArgAddress (TLabel pc, Parameter argument, bool isOld, TDest dest, TData data);
TResult LoadLocal (TLabel pc, Local local, TDest dest, TData data);
TResult LoadLocalAddress (TLabel pc, Local local, TDest dest, TData data);
TResult Nop (TLabel pc, TData data);
TResult Pop (TLabel pc, TSource source, TData data);
TResult Return (TLabel pc, TSource source, TData data);
TResult StoreArg (TLabel pc, Parameter argument, TSource source, TData data);
TResult StoreLocal (TLabel pc, Local local, TSource source, TData data);
TResult Switch (TLabel pc, TypeNode type, IEnumerable<Pair<object, TLabel>> cases, TSource value, TData data);
TResult Box (TLabel pc, TypeNode type, TDest dest, TSource source, TData data);
TResult ConstrainedCallvirt<TypeList, ArgList> (TLabel pc, Method method, TypeNode constraint, TypeList extraVarargs, TDest dest, ArgList args, TData data)
where TypeList : IIndexable<TypeNode>
where ArgList : IIndexable<TSource>;
TResult CastClass (TLabel pc, TypeNode type, TDest dest, TSource obj, TData data);
TResult CopyObj (TLabel pc, TypeNode type, TSource destPtr, TSource sourcePtr, TData data);
TResult Initobj (TLabel pc, TypeNode type, TSource ptr, TData data);
TResult LoadElement (TLabel pc, TypeNode type, TDest dest, TSource array, TSource index, TData data);
TResult LoadField (TLabel pc, Field field, TDest dest, TSource obj, TData data);
TResult LoadFieldAddress (TLabel pc, Field field, TDest dest, TSource obj, TData data);
TResult LoadLength (TLabel pc, TDest dest, TSource array, TData data);
TResult LoadStaticField (TLabel pc, Field field, TDest dest, TData data);
TResult LoadStaticFieldAddress (TLabel pc, Field field, TDest dest, TData data);
TResult LoadTypeToken (TLabel pc, TypeNode type, TDest dest, TData data);
TResult LoadFieldToken (TLabel pc, Field type, TDest dest, TData data);
TResult LoadMethodToken (TLabel pc, Method type, TDest dest, TData data);
TResult NewArray<ArgList> (TLabel pc, TypeNode type, TDest dest, ArgList lengths, TData data)
where ArgList : IIndexable<TSource>;
TResult NewObj<ArgList> (TLabel pc, Method ctor, TDest dest, ArgList args, TData data)
where ArgList : IIndexable<TSource>;
TResult MkRefAny (TLabel pc, TypeNode type, TDest dest, TSource obj, TData data);
TResult RefAnyType (TLabel pc, TDest dest, TSource source, TData data);
TResult RefAnyVal (TLabel pc, TypeNode type, TDest dest, TSource source, TData data);
TResult Rethrow (TLabel pc, TData data);
TResult StoreElement (TLabel pc, TypeNode type, TSource array, TSource index, TSource value, TData data);
TResult StoreField (TLabel pc, Field field, TSource obj, TSource value, TData data);
TResult StoreStaticField (TLabel pc, Field field, TSource value, TData data);
TResult Throw (TLabel pc, TSource exception, TData data);
TResult Unbox (TLabel pc, TypeNode type, TDest dest, TSource obj, TData data);
TResult UnboxAny (TLabel pc, TypeNode type, TDest dest, TSource obj, TData data);
}
}

View File

@@ -0,0 +1,371 @@
//
// ILVisitorBase.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.ControlFlow;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.AST.Visitors
{
/// <summary>
/// Abstract base implementation of ILVisitor
/// </summary>
/// <remarks> Each (non-overriden) operation returns DefaultVisit(pc, data) </remarks>
abstract class ILVisitorBase<Label, Source, Dest, Data, Result>
: IILVisitor<Label, Source, Dest, Data, Result>
{
public abstract Result DefaultVisit(Label pc, Data data);
#region Implementation of IExpressionILVisitor<Label,Type,Source,Dest,Data,Result>
public virtual Result Binary(Label pc, BinaryOperator bop, Dest dest, Source operand1, Source operand2, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Isinst(Label pc, TypeNode type, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadNull(Label pc, Dest dest, Data polarity)
{
return DefaultVisit (pc, polarity);
}
public virtual Result LoadConst(Label pc, TypeNode type, object constant, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Sizeof(Label pc, TypeNode type, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Unary(Label pc, UnaryOperator uop, bool unsigned, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
#endregion
#region Implementation of IILVisitor<Label,Local,Parameter,Method,Field,Type,Source,Dest,Data,Result>
public virtual Result Arglist(Label pc, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Branch(Label pc, Label target, bool leavesExceptionBlock, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result BranchCond(Label pc, Label target, BranchOperator bop, Source value1, Source value2, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result BranchTrue(Label pc, Label target, Source cond, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result BranchFalse(Label pc, Label target, Source cond, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Break(Label pc, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Call<TypeList, ArgList>(Label pc, Method method, bool virt, TypeList extraVarargs, Dest dest, ArgList args, Data data)
where TypeList : IIndexable<TypeNode> where ArgList : IIndexable<Source>
{
return DefaultVisit (pc, data);
}
public virtual Result Calli<TypeList, ArgList>(Label pc, TypeNode returnType, TypeList argTypes, bool instance, Dest dest, Source functionPointer, ArgList args, Data data)
where TypeList : IIndexable<TypeNode> where ArgList : IIndexable<Source>
{
return DefaultVisit (pc, data);
}
public virtual Result CheckFinite(Label pc, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result CopyBlock(Label pc, Source destAddress, Source srcAddress, Source len, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result EndFilter(Label pc, Source decision, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result EndFinally(Label pc, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Jmp(Label pc, Method method, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadArg(Label pc, Parameter param, bool isOld, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadArgAddress(Label pc, Parameter param, bool isOld, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadLocal(Label pc, Local local, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadLocalAddress(Label pc, Local local, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Nop(Label pc, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Pop(Label pc, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Return(Label pc, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result StoreArg(Label pc, Parameter param, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result StoreLocal(Label pc, Local local, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Switch(Label pc, TypeNode type, IEnumerable<Pair<object, Label>> cases, Source value, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Box(Label pc, TypeNode type, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result ConstrainedCallvirt<TypeList, ArgList>(Label pc, Method method, TypeNode constraint, TypeList extraVarargs, Dest dest, ArgList args, Data data)
where TypeList : IIndexable<TypeNode>
where ArgList : IIndexable<Source>
{
return DefaultVisit (pc, data);
}
public virtual Result CastClass(Label pc, TypeNode type, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result CopyObj(Label pc, TypeNode type, Source destPtr, Source sourcePtr, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Initobj(Label pc, TypeNode type, Source ptr, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadElement(Label pc, TypeNode type, Dest dest, Source array, Source index, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadField(Label pc, Field field, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadFieldAddress(Label pc, Field field, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadLength(Label pc, Dest dest, Source array, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadStaticField(Label pc, Field field, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadStaticFieldAddress(Label pc, Field field, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadTypeToken(Label pc, TypeNode type, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadFieldToken(Label pc, Field field, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadMethodToken(Label pc, Method method, Dest dest, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result NewArray<ArgList>(Label pc, TypeNode type, Dest dest, ArgList lengths, Data data)
where ArgList : IIndexable<Source>
{
return DefaultVisit (pc, data);
}
public virtual Result NewObj<ArgList>(Label pc, Method ctor, Dest dest, ArgList args, Data data)
where ArgList : IIndexable<Source>
{
return DefaultVisit (pc, data);
}
public virtual Result MkRefAny(Label pc, TypeNode type, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result RefAnyType(Label pc, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result RefAnyVal(Label pc, TypeNode type, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Rethrow(Label pc, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result StoreElement(Label pc, TypeNode type, Source array, Source index, Source value, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result StoreField(Label pc, Field field, Source obj, Source value, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result StoreStaticField(Label pc, Field field, Source value, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Throw(Label pc, Source exception, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Unbox(Label pc, TypeNode type, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result UnboxAny(Label pc, TypeNode type, Dest dest, Source obj, Data data)
{
return DefaultVisit (pc, data);
}
#endregion
#region Implementation of ISyntheticILVisitor<Label,Method,Field,Type,Source,Dest,Data,Result>
public virtual Result Entry(Label pc, Method method, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Assume(Label pc, EdgeTag tag, Source condition, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result Assert(Label pc, EdgeTag tag, Source condition, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result BeginOld(Label pc, Label matchingEnd, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result EndOld(Label pc, Label matchingBegin, TypeNode type, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadStack(Label pc, int offset, Dest dest, Source source, bool isOld, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadStackAddress(Label pc, int offset, Dest dest, Source source, TypeNode type, bool isOld, Data data)
{
return DefaultVisit (pc, data);
}
public virtual Result LoadResult(Label pc, TypeNode type, Dest dest, Source source, Data data)
{
return DefaultVisit (pc, data);
}
#endregion
}
}

View File

@@ -0,0 +1,35 @@
//
// IMethodCodeConsumer.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.Providers;
namespace Mono.CodeContracts.Static.AST.Visitors {
interface IMethodCodeConsumer<Data, Result> {
Result Accept<Label, Handler> (IMethodCodeProvider<Label, Handler> codeProvider, Label entry, Method method, Data data);
}
}

View File

@@ -0,0 +1,34 @@
//
// ISymbolicExpressionVisitor.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.AST.Visitors {
interface ISymbolicExpressionVisitor<Label, Source, Dest, Data, Result>
: IExpressionILVisitor<Label, Source, Dest, Data, Result> {
Result SymbolicConstant (Label pc, Dest variable, Data data);
}
}

View File

@@ -0,0 +1,42 @@
//
// ISyntheticILVisitor.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.ControlFlow;
namespace Mono.CodeContracts.Static.AST.Visitors {
interface ISyntheticILVisitor<Label, Source, Dest, Data, Result> {
Result Entry (Label pc, Method method, Data data);
Result Assume (Label pc, EdgeTag tag, Source condition, Data data);
Result Assert (Label pc, EdgeTag tag, Source condition, Data data);
Result LoadStack (Label pc, int offset, Dest dest, Source source, bool isOld, Data data);
Result LoadStackAddress (Label pc, int offset, Dest dest, Source source, TypeNode type, bool isOld, Data data);
Result LoadResult (Label pc, TypeNode type, Dest dest, Source source, Data data);
Result BeginOld (Label pc, Label matchingEnd, Data data);
Result EndOld (Label pc, Label matchingBegin, TypeNode type, Dest dest, Source source, Data data);
}
}

View File

@@ -0,0 +1,436 @@
//
// NodeInspector.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;
namespace Mono.CodeContracts.Static.AST.Visitors {
class NodeInspector {
public virtual void Visit (Node node)
{
if (node == null)
return;
switch (node.NodeType) {
case NodeType.Nop:
break;
#region Binary
case NodeType.Add:
case NodeType.Sub:
case NodeType.Rem:
case NodeType.Clt:
case NodeType.Cgt:
case NodeType.Ceq:
case NodeType.Box:
case NodeType.Le:
case NodeType.Mul:
case NodeType.Div:
case NodeType.Div_Un:
case NodeType.Rem_Un:
case NodeType.And:
case NodeType.Or:
case NodeType.Shr:
case NodeType.Xor:
case NodeType.Shl:
case NodeType.Shr_Un:
case NodeType.Ne:
case NodeType.Ge:
case NodeType.Gt:
case NodeType.Lt:
case NodeType.Eq:
VisitBinaryExpression ((BinaryExpression) node);
break;
#endregion
case NodeType.Call:
case NodeType.Jmp:
case NodeType.MethodCall:
VisitMethodCall ((MethodCall) node);
break;
case NodeType.Conv:
case NodeType.Conv_I1:
case NodeType.Conv_I2:
case NodeType.Conv_I8:
case NodeType.Conv_I4:
case NodeType.Conv_R4:
case NodeType.Conv_R8:
case NodeType.Neg:
case NodeType.Not:
case NodeType.LogicalNot:
VisitUnaryExpression ((UnaryExpression) node);
break;
case NodeType.Literal:
VisitLiteral ((Literal) node);
break;
case NodeType.This:
VisitThis ((This) node);
break;
case NodeType.Block:
VisitBlock ((Block) node);
break;
case NodeType.Branch:
VisitBranch ((Branch) node);
break;
case NodeType.Return:
VisitReturn ((Return) node);
break;
case NodeType.AssignmentStatement:
VisitAssignmentStatement ((AssignmentStatement) node);
break;
case NodeType.Local:
VisitLocal ((Local) node);
break;
case NodeType.Parameter:
VisitParameter ((Parameter) node);
break;
case NodeType.ExpressionStatement:
VisitExpressionStatement ((ExpressionStatement) node);
break;
case NodeType.Method:
VisitMethod ((Method) node);
break;
case NodeType.MethodContract:
VisitMethodContract ((MethodContract) node);
break;
case NodeType.Requires:
VisitRequires ((Requires) node);
break;
case NodeType.Ensures:
VisitEnsures ((Ensures) node);
break;
case NodeType.TypeNode:
VisitTypeNode ((TypeNode) node);
break;
case NodeType.Assembly:
VisitAssembly ((AssemblyNode) node);
break;
case NodeType.Module:
VisitModule ((Module) node);
break;
case NodeType.MemberBinding:
VisitMemberBinding ((MemberBinding) node);
break;
case NodeType.Construct:
VisitConstruct ((Construct) node);
break;
default:
VisitUnknownNodeType (node);
break;
}
}
public virtual void VisitAssembly (AssemblyNode node)
{
if (node == null)
return;
VisitModuleList (node.Modules);
}
public virtual void VisitModuleList (IEnumerable<Module> node)
{
if (node == null)
return;
foreach (Module module in node)
VisitModule (module);
}
public virtual void VisitModule (Module node)
{
if (node == null)
return;
VisitTypeNodeList (node.Types);
}
public virtual void VisitAssignmentStatement (AssignmentStatement node)
{
if (node == null)
return;
VisitTargetExpression (node.Target);
VisitExpression (node.Source);
}
public virtual void VisitBinaryExpression (BinaryExpression node)
{
if (node == null)
return;
VisitExpression (node.Left);
VisitExpression (node.Right);
}
public virtual void VisitBlock (Block node)
{
if (node == null)
return;
VisitStatementList (node.Statements);
}
public virtual void VisitStatementList (List<Statement> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++)
Visit (node [i]);
}
public virtual void VisitBranch (Branch node)
{
if (node == null)
return;
VisitExpression (node.Condition);
}
public virtual void VisitConstruct (Construct node)
{
if (node == null)
return;
VisitExpression (node.Constructor);
VisitExpressionList (node.Arguments);
}
public virtual void VisitExpressionList (List<Expression> list)
{
if (list == null)
return;
for (int i = 0; i < list.Count; ++i)
Visit (list [i]);
}
public virtual void VisitEnsures (Ensures node)
{
if (node == null)
return;
VisitExpression (node.Assertion);
VisitExpression (node.UserMessage);
}
public virtual void VisitExpression (Expression node)
{
if (node == null)
return;
//todo: maybe there will be something
}
public virtual void VisitExpressionStatement (ExpressionStatement node)
{
if (node == null)
return;
VisitExpression (node.Expression);
}
public virtual void VisitLiteral (Literal node)
{
}
public virtual void VisitLocal (Local node)
{
if (node == null)
return;
VisitTypeNode (node.Type);
//todo: maybe there should be something else
}
public virtual void VisitMemberBinding (MemberBinding node)
{
if (node == null)
return;
VisitExpression (node.TargetObject);
}
public virtual void VisitMethod (Method node)
{
if (node == null)
return;
VisitTypeNode (node.ReturnType);
VisitParameterList (node.Parameters);
VisitMethodContract (node.MethodContract);
VisitBlock (node.Body);
}
public virtual void VisitParameterList (List<Parameter> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++)
VisitParameter (node [i]);
}
public virtual void VisitMethodCall (MethodCall node)
{
if (node == null)
return;
VisitExpression (node.Callee);
VisitExpressionList (node.Arguments);
}
public virtual void VisitMethodContract (MethodContract node)
{
if (node == null)
return;
VisitRequiresList (node.Requires);
VisitEnsuresList (node.Ensures);
}
public virtual void VisitEnsuresList (List<Ensures> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++)
Visit (node [i]);
}
public virtual void VisitRequiresList (List<Requires> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++)
Visit (node [i]);
}
public virtual void VisitParameter (Parameter node)
{
if (node == null)
return;
VisitTypeNode (node.Type);
//todo: there may be something else
}
public virtual void VisitRequires (Requires node)
{
if (node == null)
return;
VisitExpression (node.Assertion);
VisitExpression (node.UserMessage);
}
public virtual void VisitReturn (Return node)
{
if (node == null)
return;
VisitExpression (node.Expression);
}
public virtual void VisitTargetExpression (Expression node)
{
VisitExpression (node);
}
public virtual void VisitThis (This node)
{
if (node == null)
return;
VisitTypeNode (node.Type);
}
public virtual void VisitTypeNode (TypeNode node)
{
if (node == null)
return;
var clazz = node as Class;
if (clazz != null)
VisitTypeNode (clazz.BaseType);
VisitPropertiesList (node.Properties);
VisitMethodsList (node.Methods);
VisitTypeNodeList (node.NestedTypes);
}
public virtual void VisitPropertiesList (List<Property> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++) {
Property property = node [i];
if (property != null)
Visit (node [i]);
}
}
public virtual void VisitMethodsList (List<Method> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++) {
Method method = node [i];
if (method != null)
Visit (node [i]);
}
}
public virtual void VisitTypeNodeList (List<TypeNode> node)
{
if (node == null)
return;
for (int i = 0; i < node.Count; i++) {
TypeNode typeNode = node [i];
if (typeNode != null)
Visit (typeNode);
}
}
public virtual void VisitUnaryExpression (UnaryExpression node)
{
if (node == null)
return;
VisitExpression (node.Operand);
}
public virtual void VisitUnknownNodeType (Node node)
{
}
}
}

View File

@@ -0,0 +1,46 @@
//
// NodeVisitor.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;
namespace Mono.CodeContracts.Static.AST.Visitors {
abstract class NodeVisitor {
public abstract Node Visit (Node node);
public virtual List<Expression> VisitExpressionList (List<Expression> list)
{
if (list == null)
return null;
for (int i = 0; i < list.Count; ++i)
list [i] = (Expression) Visit (list [i]);
return list;
}
}
}

View File

@@ -0,0 +1,36 @@
//
// ValueCodeVisitor.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.Analysis;
using Mono.CodeContracts.Static.DataStructures;
namespace Mono.CodeContracts.Static.AST.Visitors {
class ValueCodeVisitor<Variable> :
CodeVisitor<Variable, Variable, IValueContextProvider<Variable>, IImmutableMap<Variable, Sequence<Variable>>> {
}
}