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,38 @@
//
// ArrayTypeNode.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.Cecil;
namespace Mono.CodeContracts.Static.AST {
class ArrayTypeNode : TypeNode {
public ArrayTypeNode (TypeNode type, int lowerBound, int rank) :
base (new ArrayType (type.TypeDefinition, rank))
{
}
}
}

View File

@@ -0,0 +1,86 @@
//
// AssemblyNode.cs
//
// Authors:
// Alexander Chebaturkin (chebaturkin@gmail.com)
//
// Copyright (C) 2011 Alexander Chebaturkin
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
namespace Mono.CodeContracts.Static.AST {
class AssemblyNode : Node {
private readonly AssemblyDefinition definition;
private IEnumerable<Module> modules;
public AssemblyNode (AssemblyDefinition definition) : base (NodeType.Assembly)
{
this.definition = definition;
}
public string FullName
{
get { return this.definition.FullName; }
}
public IEnumerable<Module> Modules
{
get
{
if (this.modules == null)
this.modules = this.definition.Modules.Select (it => new Module (it)).ToList ();
return this.modules;
}
}
public TypeNode GetType (string ns, string className)
{
foreach (Module module in Modules) {
TypeNode type = module.GetType (ns, className);
if (type != null)
return type;
}
IEnumerable<TypeDefinition> enumerable = this.definition.Modules.SelectMany (m => m.Types);
TypeDefinition firstOrDefault = enumerable.FirstOrDefault (t => t.Namespace == ns && t.Name == className);
if (firstOrDefault == null)
return null;
return TypeNode.Create (firstOrDefault);
}
public static AssemblyNode ReadAssembly (string filename)
{
var readerParameters = new ReaderParameters ();
AssemblyDefinition definition = AssemblyDefinition.ReadAssembly (filename, readerParameters);
return new AssemblyNode (definition);
}
public static AssemblyNode GetSystemAssembly ()
{
return ReadAssembly (typeof (object).Module.Assembly.Location);
}
}
}

View File

@@ -0,0 +1,46 @@
//
// AssignmentStatement.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 {
class AssignmentStatement : Statement {
public AssignmentStatement (Expression source, Expression target)
: base (NodeType.AssignmentStatement)
{
Source = source;
Target = target;
}
public Expression Source { get; set; }
public Expression Target { get; set; }
public override string ToString ()
{
return string.Format ("{0} := {1};", Target, Source);
}
}
}

View File

@@ -0,0 +1,56 @@
//
// BinaryExpression.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 {
class BinaryExpression : Expression {
public BinaryExpression (NodeType nodeType) : base (nodeType)
{
}
public BinaryExpression (NodeType nodeType, Expression left, Expression right) : base (nodeType)
{
Left = left;
Right = right;
}
public BinaryExpression (NodeType nodeType, Expression left, Expression right, TypeNode type)
: base (nodeType, type)
{
Left = left;
Right = right;
}
public Expression Left { get; set; }
public Expression Right { get; set; }
public override string ToString ()
{
return string.Format ("({1} :{0}: {2})", NodeType, Left, Right);
}
}
}

View File

@@ -0,0 +1,112 @@
//
// BinaryOperator.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.Analysis.Numerical;
namespace Mono.CodeContracts.Static.AST {
enum BinaryOperator {
Add,
Add_Ovf,
Add_Ovf_Un,
And,
Ceq,
Cobjeq,
Cne_Un,
Cge,
Cge_Un,
Cgt,
Cgt_Un,
Cle,
Cle_Un,
Clt,
Clt_Un,
Div,
Div_Un,
LogicalAnd,
LogicalOr,
Mul,
Mul_Ovf,
Mul_Ovf_Un,
Or,
Rem,
Rem_Un,
Shl,
Shr,
Shr_Un,
Sub,
Sub_Ovf,
Sub_Ovf_Un,
Xor
}
static class BinaryOperatorExtensions {
public static ExpressionOperator ToExpressionOperator(this BinaryOperator op)
{
switch (op) {
case BinaryOperator.Add:
return ExpressionOperator.Add;
case BinaryOperator.And:
return ExpressionOperator.And;
case BinaryOperator.Ceq:
return ExpressionOperator.Equal;
case BinaryOperator.Cobjeq:
return ExpressionOperator.Equal_Obj;
case BinaryOperator.Cne_Un:
return ExpressionOperator.NotEqual;
case BinaryOperator.Cge:
return ExpressionOperator.GreaterEqualThan;
case BinaryOperator.Cgt:
return ExpressionOperator.GreaterThan;
case BinaryOperator.Cle:
return ExpressionOperator.LessEqualThan;
case BinaryOperator.Clt:
return ExpressionOperator.LessThan;
case BinaryOperator.Div:
return ExpressionOperator.Div;
case BinaryOperator.LogicalAnd:
return ExpressionOperator.LogicalAnd;
case BinaryOperator.LogicalOr:
return ExpressionOperator.LogicalOr;
case BinaryOperator.Mul:
return ExpressionOperator.Mult;
case BinaryOperator.Or:
return ExpressionOperator.Or;
case BinaryOperator.Rem:
return ExpressionOperator.Mod;
case BinaryOperator.Sub:
return ExpressionOperator.Sub;
case BinaryOperator.Xor:
return ExpressionOperator.Xor;
default:
return ExpressionOperator.Unknown;
}
}
}
}

View File

@@ -0,0 +1,50 @@
//
// Block.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 {
class Block : Statement {
public Block (List<Statement> statements) : base (NodeType.Block)
{
Statements = statements;
}
public Block () : base (NodeType.Block)
{
}
public int ILOffset { get; set; }
public List<Statement> Statements { get; set; }
public override string ToString ()
{
return string.Format ("Block(Off:{0}, Stmts:{1})", ILOffset, Statements.Count);
}
}
}

View File

@@ -0,0 +1,50 @@
//
// BlockExpression.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 {
class BlockExpression : Expression {
public Block Block;
public BlockExpression (Block block, TypeNode type)
: this ()
{
this.Block = block;
Type = type;
}
public BlockExpression (Block block) : this ()
{
this.Block = block;
}
public BlockExpression ()
: base (NodeType.BlockExpression)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
//
// Branch.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 {
class Branch : Statement {
public readonly bool LeavesExceptionBlock;
public Expression Condition;
public Block Target;
public bool IsShortOffset;
public bool Unsigned;
public Branch (Expression condition, Block target, bool isShortOffset, bool unsigned, bool leavesExceptionBlock) : base (NodeType.Branch)
{
this.Condition = condition;
this.Target = target;
this.IsShortOffset = isShortOffset;
this.Unsigned = unsigned;
this.LeavesExceptionBlock = leavesExceptionBlock;
}
public override string ToString ()
{
return string.Format ("Branch({0}, {1})", this.Condition == null ? "<no cond>" : this.Condition.ToString (), this.Target == null ? "<no target>" : this.Target.ToString ());
}
}
enum BranchOperator {
Beq,
Bge,
Bge_Un,
Bgt,
Bgt_Un,
Ble,
Ble_Un,
Blt,
Blt_Un,
Bne_un
}
}

View File

@@ -0,0 +1,45 @@
//
// CatchFilter.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 {
class CatchFilter : Statement {
public CatchFilter () : base (NodeType.Filter)
{
}
public CatchFilter (Block block, Expression expression)
: base (NodeType.Filter)
{
Block = block;
Expression = expression;
}
public Block Block { get; set; }
public Expression Expression { get; set; }
}
}

View File

@@ -0,0 +1,66 @@
//
// Class.cs
//
// Authors:
// Alexander Chebaturkin (chebaturkin@gmail.com)
//
// Copyright (C) 2011 Alexander Chebaturkin
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
namespace Mono.CodeContracts.Static.AST {
class Class : TypeNode {
public Class (TypeDefinition firstOrDefault) : base (firstOrDefault)
{
NodeType = NodeType.Class;
}
public IEnumerable<Method> GetMethods (string name, params TypeNode[] args)
{
IEnumerable<Method> enumerable = Methods.Where (m => m.Name == name);
foreach (Method method in enumerable) {
List<Parameter> parameters = method.Parameters;
bool ok = true;
if (args.Length != parameters.Count)
continue;
for (int i = 0; i < args.Length; i++) {
if (!parameters [i].Type.Equals (args [i])) {
ok = false;
break;
}
}
if (ok)
yield return method;
}
}
public Method GetMethod (string name, params TypeNode[] args)
{
return GetMethods (name, args).FirstOrDefault ();
}
}
}

View File

@@ -0,0 +1,46 @@
//
// Construct.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 {
class Construct : NaryExpression {
public Construct ()
: base (null, NodeType.Construct)
{
}
public Construct (Expression constructor, List<Expression> arguments)
: base (arguments, NodeType.Construct)
{
Constructor = constructor;
}
public Expression Constructor { get; set; }
}
}

View File

@@ -0,0 +1,206 @@
//
// CoreSystemTypes.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.Cecil;
namespace Mono.CodeContracts.Static.AST {
sealed class CoreSystemTypes {
private static CoreSystemTypes _instance;
private readonly ModuleDefinition Module;
private Lazy<AssemblyNode> systemAssembly;
private Lazy<TypeNode> typeArray;
private Lazy<TypeNode> typeBoolean;
private Lazy<TypeNode> typeByte;
private Lazy<TypeNode> typeChar;
private Lazy<TypeNode> typeDouble;
private Lazy<TypeNode> typeInt16;
private Lazy<TypeNode> typeInt32;
private Lazy<TypeNode> typeInt64;
private Lazy<TypeNode> typeIntPtr;
private Lazy<TypeNode> typeObject;
private Lazy<TypeNode> typeSByte;
private Lazy<TypeNode> typeSingle;
private Lazy<TypeNode> typeString;
private Lazy<TypeNode> typeSystemType;
private Lazy<TypeNode> typeUInt16;
private Lazy<TypeNode> typeUInt32;
private Lazy<TypeNode> typeUInt64;
private Lazy<TypeNode> typeUIntPtr;
private Lazy<TypeNode> typeVoid;
public CoreSystemTypes (ModuleDefinition module)
{
this.Module = module;
InitializeLazyTypes ();
}
public static ModuleDefinition ModuleDefinition { get; set; }
public static CoreSystemTypes Instance
{
get { return GetOrCreateInstance (ModuleDefinition); }
}
public TypeNode TypeObject
{
get { return this.typeObject.Value; }
}
public TypeNode TypeString
{
get { return this.typeString.Value; }
}
public TypeNode TypeBoolean
{
get { return this.typeBoolean.Value; }
}
public TypeNode TypeVoid
{
get { return this.typeVoid.Value; }
}
public TypeNode TypeSByte
{
get { return this.typeSByte.Value; }
}
public TypeNode TypeByte
{
get { return this.typeByte.Value; }
}
public TypeNode TypeInt16
{
get { return this.typeInt16.Value; }
}
public TypeNode TypeInt32
{
get { return this.typeInt32.Value; }
}
public TypeNode TypeInt64
{
get { return this.typeInt64.Value; }
}
public TypeNode TypeSingle
{
get { return this.typeSingle.Value; }
}
public TypeNode TypeDouble
{
get { return this.typeDouble.Value; }
}
public TypeNode TypeUInt16
{
get { return this.typeUInt16.Value; }
}
public TypeNode TypeUInt32
{
get { return this.typeUInt32.Value; }
}
public TypeNode TypeUInt64
{
get { return this.typeUInt64.Value; }
}
public AssemblyNode SystemAssembly
{
get { return this.systemAssembly.Value; }
}
public TypeNode TypeIntPtr
{
get { return this.typeIntPtr.Value; }
}
public TypeNode TypeArray
{
get { return this.typeArray.Value; }
}
public TypeNode TypeUIntPtr
{
get { return this.typeUIntPtr.Value; }
}
public TypeNode TypeChar
{
get { return this.typeChar.Value; }
}
public TypeNode TypeSystemType
{
get { return this.typeSystemType.Value; }
}
private static CoreSystemTypes GetOrCreateInstance (ModuleDefinition module)
{
if (_instance == null)
_instance = new CoreSystemTypes (module);
return _instance;
}
private void InitializeLazyTypes ()
{
this.typeVoid = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (void))));
this.typeSByte = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (SByte))));
this.typeByte = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Byte))));
this.typeInt16 = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Int16))));
this.typeInt32 = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Int32))));
this.typeInt64 = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Int64))));
this.typeUInt16 = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (UInt16))));
this.typeUInt32 = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (UInt32))));
this.typeUInt64 = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (UInt64))));
this.typeSingle = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Single))));
this.typeDouble = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Double))));
this.typeBoolean = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Boolean))));
this.typeObject = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (object))));
this.typeString = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (string))));
this.typeArray = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Array))));
this.typeIntPtr = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (IntPtr))));
this.typeUIntPtr = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (UIntPtr))));
this.typeChar = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (char))));
this.typeSystemType = new Lazy<TypeNode> (() => TypeNode.Create (this.Module.Import (typeof (Type))));
this.systemAssembly = new Lazy<AssemblyNode> (() => AssemblyNode.GetSystemAssembly ());
}
}
}

View File

@@ -0,0 +1,35 @@
//
// EndFinally.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 {
class EndFinally : Statement {
public EndFinally () : base (NodeType.EndFinally)
{
}
}
}

View File

@@ -0,0 +1,47 @@
//
// Ensures.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 {
class Ensures : MethodContractElement {
public Ensures ()
: base (NodeType.Ensures)
{
}
public Ensures (NodeType nodeType)
: base (nodeType)
{
}
public Ensures (Expression condition)
: this ()
{
Assertion = condition;
}
}
}

View File

@@ -0,0 +1,43 @@
//
// ExceptionHandler.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 {
class ExceptionHandler : Node {
public ExceptionHandler () : base (NodeType.ExceptionHandler)
{
}
public NodeType HandlerType { get; set; }
public Block TryStartBlock { get; set; }
public Block BlockAfterTryEnd { get; set; }
public Block HandlerStartBlock { get; set; }
public Block BlockAfterHandlerEnd { get; set; }
public Block FilterExpression { get; set; }
public TypeNode FilterType { get; set; }
}
}

View File

@@ -0,0 +1,48 @@
//
// Expression.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 {
class Expression : Node {
protected TypeNode type;
public Expression (NodeType nodeType) : base (nodeType)
{
}
public Expression (NodeType nodeType, TypeNode type) : base (nodeType)
{
this.type = type;
}
public virtual TypeNode Type
{
get { return this.type; }
set { this.type = value; }
}
}
}

View File

@@ -0,0 +1,48 @@
//
// ExpressionStatement.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 {
class ExpressionStatement : Statement {
public ExpressionStatement () : base (NodeType.ExpressionStatement)
{
}
public ExpressionStatement (Expression expression)
: base (NodeType.ExpressionStatement)
{
Expression = expression;
}
public Expression Expression { get; set; }
public override string ToString ()
{
return string.Format ("ExpressionStatement({0})", Expression);
}
}
}

View File

@@ -0,0 +1,42 @@
//
// FaultHandler.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 {
class FaultHandler : Statement {
public FaultHandler () : base (NodeType.FaultHandler)
{
}
public FaultHandler (Block block) : this ()
{
Block = block;
}
public Block Block { get; set; }
}
}

View File

@@ -0,0 +1,107 @@
//
// Field.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.Cecil;
namespace Mono.CodeContracts.Static.AST {
class Field : Member {
private readonly FieldDefinition definition;
public Field (FieldDefinition definition) : base (NodeType.Field)
{
this.definition = definition;
}
#region Overrides of Member
public override bool IsStatic
{
get { return this.definition.IsStatic; }
}
public TypeNode FieldType
{
get { return TypeNode.Create (this.definition.FieldType); }
}
public string Name
{
get { return this.definition.Name; }
}
public override TypeNode DeclaringType
{
get { return TypeNode.Create (this.definition.DeclaringType); }
}
public override Module Module
{
get { return new Module (this.definition.Module); }
}
public override bool IsPublic
{
get { return this.definition.IsPublic; }
}
public override bool IsPrivate
{
get { return this.definition.IsPrivate; }
}
public override bool IsAssembly
{
get { return this.definition.IsAssembly; }
}
public override bool IsFamily
{
get { return this.definition.IsFamily; }
}
public override bool IsFamilyOrAssembly
{
get { return this.definition.IsFamilyOrAssembly; }
}
public override bool IsFamilyAndAssembly
{
get { return this.definition.IsFamilyAndAssembly; }
}
public bool IsReadonly
{
get { return this.definition.IsInitOnly; }
}
public bool IsCompilerGenerated
{
get { return this.definition.IsCompilerControlled; }
}
#endregion
}
}

Some files were not shown because too many files have changed in this diff Show More