-//\r
-// Expr.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- abstract class Expr {\r
-\r
- protected Expr (MethodInfo methodInfo)\r
- {\r
- this.MethodInfo = methodInfo;\r
- }\r
-\r
- public abstract ExprType ExprType { get; }\r
- public abstract TypeReference ReturnType { get; }\r
-\r
- public MethodInfo MethodInfo { get; private set; }\r
-\r
-\r
- }\r
-}\r
+//
+// Expr.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ abstract class Expr {
+
+ protected Expr (MethodInfo methodInfo)
+ {
+ this.MethodInfo = methodInfo;
+ }
+
+ public abstract ExprType ExprType { get; }
+ public abstract TypeReference ReturnType { get; }
+
+ public MethodInfo MethodInfo { get; private set; }
+
+
+ }
+}
-//\r
-// ExprAdd.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprAdd : ExprBinaryOpArithmetic {\r
-\r
- public ExprAdd (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)\r
- : base (methodInfo, left, right, signage, overflow)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Add; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprAdd.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprAdd : ExprBinaryOpArithmetic {
+
+ public ExprAdd (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)
+ : base (methodInfo, left, right, signage, overflow)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Add; }
+ }
+
+ }
+}
-//\r
-// ExprBinaryOp.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- abstract class ExprBinaryOp : Expr {\r
-\r
- public ExprBinaryOp (MethodInfo methodInfo, Expr left, Expr right, Sn signage)\r
- : base (methodInfo)\r
- {\r
- this.Left = left;\r
- this.Right = right;\r
- this.Signage = signage;\r
- }\r
-\r
- public Expr Left { get; private set; }\r
- public Expr Right { get; private set; }\r
- public Sn Signage { get; private set; }\r
-\r
- public bool IsSigned {\r
- get { return this.Signage == Sn.Signed; }\r
- }\r
-\r
- public bool IsUnsigned {\r
- get { return this.Signage == Sn.Unsigned; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprBinaryOp.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ abstract class ExprBinaryOp : Expr {
+
+ public ExprBinaryOp (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
+ : base (methodInfo)
+ {
+ this.Left = left;
+ this.Right = right;
+ this.Signage = signage;
+ }
+
+ public Expr Left { get; private set; }
+ public Expr Right { get; private set; }
+ public Sn Signage { get; private set; }
+
+ public bool IsSigned {
+ get { return this.Signage == Sn.Signed; }
+ }
+
+ public bool IsUnsigned {
+ get { return this.Signage == Sn.Unsigned; }
+ }
+
+ }
+}
-//\r
-// ExprBinaryOpArithmetic.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- abstract class ExprBinaryOpArithmetic : ExprBinaryOp {\r
-\r
- public ExprBinaryOpArithmetic (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)\r
- : base (methodInfo, left, right, signage)\r
- {\r
- this.Overflow = overflow;\r
- }\r
-\r
- public bool Overflow { get; private set; }\r
-\r
- public override TypeReference ReturnType {\r
- get {\r
- if (base.Left.ReturnType.FullName == "System.Int8" ||\r
- base.Left.ReturnType.FullName == "System.Int16") {\r
- return base.MethodInfo.TypeInt32;\r
- }\r
- if (base.Left.ReturnType.FullName == "System.Uint8" ||\r
- base.Left.ReturnType.FullName == "System.Uint16") {\r
- return base.MethodInfo.TypeUInt32;\r
- }\r
- return base.Left.ReturnType;\r
- }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprBinaryOpArithmetic.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ abstract class ExprBinaryOpArithmetic : ExprBinaryOp {
+
+ public ExprBinaryOpArithmetic (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)
+ : base (methodInfo, left, right, signage)
+ {
+ this.Overflow = overflow;
+ }
+
+ public bool Overflow { get; private set; }
+
+ public override TypeReference ReturnType {
+ get {
+ if (base.Left.ReturnType.FullName == "System.Int8" ||
+ base.Left.ReturnType.FullName == "System.Int16") {
+ return base.MethodInfo.TypeInt32;
+ }
+ if (base.Left.ReturnType.FullName == "System.Uint8" ||
+ base.Left.ReturnType.FullName == "System.Uint16") {
+ return base.MethodInfo.TypeUInt32;
+ }
+ return base.Left.ReturnType;
+ }
+ }
+
+ }
+}
-//\r
-// ExprBinaryOpComparison.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- abstract class ExprBinaryOpComparison : ExprBinaryOp {\r
-\r
- public ExprBinaryOpComparison (MethodInfo methodInfo, Expr left, Expr right, Sn signage)\r
- : base (methodInfo, left, right, signage)\r
- {\r
- }\r
-\r
- public override TypeReference ReturnType {\r
- get { return base.MethodInfo.TypeBoolean; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprBinaryOpComparison.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ abstract class ExprBinaryOpComparison : ExprBinaryOp {
+
+ public ExprBinaryOpComparison (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
+ : base (methodInfo, left, right, signage)
+ {
+ }
+
+ public override TypeReference ReturnType {
+ get { return base.MethodInfo.TypeBoolean; }
+ }
+
+ }
+}
-//\r
-// ExprBlock.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprBlock : Expr {\r
-\r
- public ExprBlock (MethodInfo methodInfo, IEnumerable<Expr> exprs)\r
- : base (methodInfo)\r
- {\r
- this.Exprs = exprs;\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Block; }\r
- }\r
-\r
- public override TypeReference ReturnType {\r
- get { return base.MethodInfo.TypeVoid; }\r
- }\r
-\r
- public IEnumerable<Expr> Exprs { get; private set; }\r
-\r
- }\r
-}\r
+//
+// ExprBlock.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprBlock : Expr {
+
+ public ExprBlock (MethodInfo methodInfo, IEnumerable<Expr> exprs)
+ : base (methodInfo)
+ {
+ this.Exprs = exprs;
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Block; }
+ }
+
+ public override TypeReference ReturnType {
+ get { return base.MethodInfo.TypeVoid; }
+ }
+
+ public IEnumerable<Expr> Exprs { get; private set; }
+
+ }
+}
-//\r
-// ExprBox.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprBox : Expr {\r
-\r
- public ExprBox (MethodInfo methodInfo, Expr exprToBox)\r
- : base (methodInfo)\r
- {\r
- this.ExprToBox = exprToBox;\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Box; }\r
- }\r
-\r
- public override Mono.Cecil.TypeReference ReturnType {\r
- get { return this.ExprToBox.ReturnType; }\r
- }\r
-\r
- public Expr ExprToBox { get; private set; }\r
-\r
- }\r
-}\r
+//
+// ExprBox.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprBox : Expr {
+
+ public ExprBox (MethodInfo methodInfo, Expr exprToBox)
+ : base (methodInfo)
+ {
+ this.ExprToBox = exprToBox;
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Box; }
+ }
+
+ public override Mono.Cecil.TypeReference ReturnType {
+ get { return this.ExprToBox.ReturnType; }
+ }
+
+ public Expr ExprToBox { get; private set; }
+
+ }
+}
-//\r
-// ExprCall.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprCall : Expr {\r
-\r
- public ExprCall (MethodInfo methodInfo, MethodReference method, IEnumerable<Expr> parameters)\r
- : base (methodInfo)\r
- {\r
- this.Method = method;\r
- this.Parameters = parameters;\r
- }\r
-\r
- public MethodReference Method { get; private set; }\r
- public IEnumerable<Expr> Parameters { get; private set; }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Call; }\r
- }\r
-\r
- public override TypeReference ReturnType {\r
- get { return this.Method.ReturnType.ReturnType; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprCall.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprCall : Expr {
+
+ public ExprCall (MethodInfo methodInfo, MethodReference method, IEnumerable<Expr> parameters)
+ : base (methodInfo)
+ {
+ this.Method = method;
+ this.Parameters = parameters;
+ }
+
+ public MethodReference Method { get; private set; }
+ public IEnumerable<Expr> Parameters { get; private set; }
+
+ public override ExprType ExprType {
+ get { return ExprType.Call; }
+ }
+
+ public override TypeReference ReturnType {
+ get { return this.Method.ReturnType.ReturnType; }
+ }
+
+ }
+}
-//\r
-// ExprCompareEqual.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprCompareEqual : ExprBinaryOpComparison {\r
-\r
- public ExprCompareEqual (MethodInfo methodInfo, Expr left, Expr right)\r
- : base (methodInfo, left, right, Sn.None)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.CompareEqual; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprCompareEqual.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprCompareEqual : ExprBinaryOpComparison {
+
+ public ExprCompareEqual (MethodInfo methodInfo, Expr left, Expr right)
+ : base (methodInfo, left, right, Sn.None)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.CompareEqual; }
+ }
+
+ }
+}
-//\r
-// ExprCompareGreaterThan.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprCompareGreaterThan : ExprBinaryOpComparison {\r
-\r
- public ExprCompareGreaterThan (MethodInfo methodInfo, Expr left, Expr right, Sn signage)\r
- : base (methodInfo, left, right, signage)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.CompareGreaterThan; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprCompareGreaterThan.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprCompareGreaterThan : ExprBinaryOpComparison {
+
+ public ExprCompareGreaterThan (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
+ : base (methodInfo, left, right, signage)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.CompareGreaterThan; }
+ }
+
+ }
+}
-//\r
-// ExprCompareLessThan.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprCompareLessThan : ExprBinaryOpComparison {\r
-\r
- public ExprCompareLessThan (MethodInfo methodInfo, Expr left, Expr right, Sn signage)\r
- : base (methodInfo, left, right, signage)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.CompareLessThan; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprCompareLessThan.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprCompareLessThan : ExprBinaryOpComparison {
+
+ public ExprCompareLessThan (MethodInfo methodInfo, Expr left, Expr right, Sn signage)
+ : base (methodInfo, left, right, signage)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.CompareLessThan; }
+ }
+
+ }
+}
-//\r
-// ExprConv.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprConv : Expr {\r
-\r
- public ExprConv (MethodInfo methodInfo, Expr exprToConvert, TypeCode convToType)\r
- : base (methodInfo)\r
- {\r
- this.ExprToConvert = exprToConvert;\r
- this.ConvToType = convToType;\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Conv; }\r
- }\r
-\r
- public Expr ExprToConvert { get; private set; }\r
- public TypeCode ConvToType { get; private set; }\r
-\r
- public override TypeReference ReturnType {\r
- get {\r
- switch (this.ConvToType) {\r
- case TypeCode.Int32:\r
- return base.MethodInfo.TypeInt32;\r
- case TypeCode.Int64:\r
- return base.MethodInfo.TypeInt64;\r
- default:\r
- throw new NotSupportedException ("Cannot conv to: " + this.ConvToType);\r
- }\r
- }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprConv.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprConv : Expr {
+
+ public ExprConv (MethodInfo methodInfo, Expr exprToConvert, TypeCode convToType)
+ : base (methodInfo)
+ {
+ this.ExprToConvert = exprToConvert;
+ this.ConvToType = convToType;
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Conv; }
+ }
+
+ public Expr ExprToConvert { get; private set; }
+ public TypeCode ConvToType { get; private set; }
+
+ public override TypeReference ReturnType {
+ get {
+ switch (this.ConvToType) {
+ case TypeCode.Int32:
+ return base.MethodInfo.TypeInt32;
+ case TypeCode.Int64:
+ return base.MethodInfo.TypeInt64;
+ default:
+ throw new NotSupportedException ("Cannot conv to: " + this.ConvToType);
+ }
+ }
+ }
+
+ }
+}
-//\r
-// ExprLoadArg.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprLoadArg : Expr {\r
-\r
- public ExprLoadArg (MethodInfo methodInfo, int index)\r
- : base (methodInfo)\r
- {\r
- this.Index = index;\r
- }\r
-\r
- public int Index { get; private set; }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.LoadArg; }\r
- }\r
-\r
- public override TypeReference ReturnType {\r
- get {\r
- return base.MethodInfo.Method.Parameters [this.Index].ParameterType;\r
- }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprLoadArg.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprLoadArg : Expr {
+
+ public ExprLoadArg (MethodInfo methodInfo, int index)
+ : base (methodInfo)
+ {
+ this.Index = index;
+ }
+
+ public int Index { get; private set; }
+
+ public override ExprType ExprType {
+ get { return ExprType.LoadArg; }
+ }
+
+ public override TypeReference ReturnType {
+ get {
+ return base.MethodInfo.Method.Parameters [this.Index].ParameterType;
+ }
+ }
+
+ }
+}
-//\r
-// ExprLoadConstant.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprLoadConstant : Expr {\r
-\r
- public ExprLoadConstant (MethodInfo methodInfo, object value)\r
- : base (methodInfo)\r
- {\r
- this.Value = value;\r
-\r
- if (value == null) {\r
- this.returnType = methodInfo.TypeObject;\r
- } else {\r
- Type type = value.GetType();\r
- this.returnType = methodInfo.Module.Import (type);\r
- }\r
- }\r
-\r
- private TypeReference returnType;\r
-\r
- public object Value { get; private set; }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.LoadConstant; }\r
- }\r
-\r
- public override TypeReference ReturnType {\r
- get { return this.returnType; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprLoadConstant.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprLoadConstant : Expr {
+
+ public ExprLoadConstant (MethodInfo methodInfo, object value)
+ : base (methodInfo)
+ {
+ this.Value = value;
+
+ if (value == null) {
+ this.returnType = methodInfo.TypeObject;
+ } else {
+ Type type = value.GetType();
+ this.returnType = methodInfo.Module.Import (type);
+ }
+ }
+
+ private TypeReference returnType;
+
+ public object Value { get; private set; }
+
+ public override ExprType ExprType {
+ get { return ExprType.LoadConstant; }
+ }
+
+ public override TypeReference ReturnType {
+ get { return this.returnType; }
+ }
+
+ }
+}
-//\r
-// ExprNop.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprNop : Expr {\r
-\r
- public ExprNop (MethodInfo methodInfo)\r
- : base (methodInfo)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Nop; }\r
- }\r
-\r
- public override Mono.Cecil.TypeReference ReturnType {\r
- get { return base.MethodInfo.TypeVoid; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprNop.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprNop : Expr {
+
+ public ExprNop (MethodInfo methodInfo)
+ : base (methodInfo)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Nop; }
+ }
+
+ public override Mono.Cecil.TypeReference ReturnType {
+ get { return base.MethodInfo.TypeVoid; }
+ }
+
+ }
+}
-//\r
-// ExprReturn.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprReturn : Expr {\r
-\r
- public ExprReturn (MethodInfo methodInfo)\r
- : base (methodInfo)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Return; }\r
- }\r
-\r
- public override TypeReference ReturnType {\r
- get { return base.MethodInfo.TypeVoid; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprReturn.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprReturn : Expr {
+
+ public ExprReturn (MethodInfo methodInfo)
+ : base (methodInfo)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Return; }
+ }
+
+ public override TypeReference ReturnType {
+ get { return base.MethodInfo.TypeVoid; }
+ }
+
+ }
+}
-//\r
-// ExprSub.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- class ExprSub : ExprBinaryOpArithmetic {\r
-\r
- public ExprSub (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)\r
- : base (methodInfo, left, right, signage, overflow)\r
- {\r
- }\r
-\r
- public override ExprType ExprType {\r
- get { return ExprType.Sub; }\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprSub.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ class ExprSub : ExprBinaryOpArithmetic {
+
+ public ExprSub (MethodInfo methodInfo, Expr left, Expr right, Sn signage, bool overflow)
+ : base (methodInfo, left, right, signage, overflow)
+ {
+ }
+
+ public override ExprType ExprType {
+ get { return ExprType.Sub; }
+ }
+
+ }
+}
-//\r
-// ExprType.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- enum ExprType {\r
-\r
- Unknown,\r
-\r
- Block,\r
-\r
- Nop,\r
- LoadArg,\r
- LoadConstant,\r
- CompareLessThan,\r
- CompareGreaterThan,\r
- CompareEqual,\r
- Call,\r
- Return,\r
- Box,\r
- Conv,\r
- Add,\r
- Sub,\r
-\r
- }\r
-}\r
+//
+// ExprType.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ enum ExprType {
+
+ Unknown,
+
+ Block,
+
+ Nop,
+ LoadArg,
+ LoadConstant,
+ CompareLessThan,
+ CompareGreaterThan,
+ CompareEqual,
+ Call,
+ Return,
+ Box,
+ Conv,
+ Add,
+ Sub,
+
+ }
+}
-//\r
-// Sn.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite.Ast {\r
- enum Sn {\r
- None,\r
- Signed,\r
- Unsigned\r
- }\r
-}\r
+//
+// Sn.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite.Ast {
+ enum Sn {
+ None,
+ Signed,
+ Unsigned
+ }
+}
-//\r
-// CompileVisitor.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil.Cil;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-\r
-namespace Mono.CodeContracts.Rewrite.AstVisitors {\r
- class CompileVisitor : ExprVisitor {\r
-\r
- public CompileVisitor (CilWorker il, Dictionary<Expr, Instruction> instructionLookup)\r
- : this (il, instructionLookup, il.Append)\r
- {\r
- }\r
-\r
- public CompileVisitor (CilWorker il, Dictionary<Expr, Instruction> instructionLookup, Action<Instruction> fnEmit)\r
- {\r
- this.il = il;\r
- this.instructionLookup = instructionLookup;\r
- this.fnEmit = fnEmit;\r
- }\r
-\r
- private CilWorker il;\r
- private Dictionary<Expr, Instruction> instructionLookup;\r
- private Action<Instruction> fnEmit;\r
-\r
- private void Emit (Expr originalExpr, Instruction inst)\r
- {\r
- Instruction originalInst;\r
- if (this.instructionLookup != null) {\r
- // TODO: Doesn't handle inherited contracts - need to check what to do in this case.\r
- if (this.instructionLookup.TryGetValue (originalExpr, out originalInst)) {\r
- inst.SequencePoint = originalInst.SequencePoint;\r
- }\r
- }\r
- this.fnEmit (inst);\r
- }\r
-\r
- private void Emit (Expr originalExpr, Func<Instruction> fnCreateInstruction)\r
- {\r
- Instruction inst = fnCreateInstruction();\r
- this.Emit (originalExpr, inst);\r
- }\r
-\r
- private void Emit (Expr originalExpr, Func<IEnumerable<Instruction>> fnCreateInstruction)\r
- {\r
- throw new NotImplementedException ();\r
- }\r
-\r
- protected override Expr VisitNop (ExprNop e)\r
- {\r
- var instNop = this.il.Create (OpCodes.Nop);\r
- this.Emit (e, instNop);\r
- return e;\r
- }\r
-\r
- protected override Expr VisitLoadArg (ExprLoadArg e)\r
- {\r
- this.Emit (e, () => {\r
- int index = e.Index;\r
- switch (index) {\r
- case 0:\r
- return this.il.Create (OpCodes.Ldarg_0);\r
- case 1:\r
- return this.il.Create (OpCodes.Ldarg_1);\r
- case 2:\r
- return this.il.Create (OpCodes.Ldarg_2);\r
- case 3:\r
- return this.il.Create (OpCodes.Ldarg_3);\r
- default:\r
- if (e.Index <= 255) {\r
- return this.il.Create (OpCodes.Ldarg_S, (byte) index);\r
- } else {\r
- return this.il.Create (OpCodes.Ldarg, index);\r
- }\r
- }\r
- // Required due to bug in compiler\r
- throw new NotSupportedException();\r
- });\r
- \r
- return e;\r
- }\r
-\r
- protected override Expr VisitLoadConstant (ExprLoadConstant e)\r
- {\r
- this.Emit (e, () => {\r
- object v = e.Value;\r
- if (v == null) {\r
- return this.il.Create (OpCodes.Ldnull);\r
- }\r
- Type vType = v.GetType ();\r
- TypeCode vTypeCode = Type.GetTypeCode (vType);\r
- switch (vTypeCode) {\r
- case TypeCode.Int32:\r
- int value = (int) v;\r
- switch (value) {\r
- case -1:\r
- return this.il.Create (OpCodes.Ldc_I4_M1);\r
- case 0:\r
- return this.il.Create (OpCodes.Ldc_I4_0);\r
- case 1:\r
- return this.il.Create (OpCodes.Ldc_I4_1);\r
- case 2:\r
- return this.il.Create (OpCodes.Ldc_I4_2);\r
- case 3:\r
- return this.il.Create (OpCodes.Ldc_I4_3);\r
- case 4:\r
- return this.il.Create (OpCodes.Ldc_I4_4);\r
- case 5:\r
- return this.il.Create (OpCodes.Ldc_I4_5);\r
- case 6:\r
- return this.il.Create (OpCodes.Ldc_I4_6);\r
- case 7:\r
- return this.il.Create (OpCodes.Ldc_I4_7);\r
- case 8:\r
- return this.il.Create (OpCodes.Ldc_I4_8);\r
- default:\r
- if (value >= -128 && value <= 127) {\r
- return this.il.Create (OpCodes.Ldc_I4_S, (sbyte) value);\r
- } else {\r
- return this.il.Create (OpCodes.Ldc_I4, value);\r
- }\r
- }\r
- // Required due to bug in compiler\r
- throw new NotSupportedException();\r
- case TypeCode.Single:\r
- return this.il.Create (OpCodes.Ldc_R4, (float) v);\r
- case TypeCode.Double:\r
- return this.il.Create (OpCodes.Ldc_R8, (double) v);\r
- case TypeCode.String:\r
- return this.il.Create (OpCodes.Ldstr, (string) v);\r
- default:\r
- throw new NotSupportedException ("Cannot handle constant: " + vTypeCode);\r
- }\r
- // Required due to bug in compiler\r
- throw new NotSupportedException();\r
- });\r
-\r
- return e;\r
- }\r
-\r
- private Expr VisitBinary (ExprBinaryOp e, Func<Instruction> fnCreateIl)\r
- {\r
- this.Visit (e.Left);\r
- this.Visit (e.Right);\r
- var inst = fnCreateIl ();\r
- this.Emit (e, inst);\r
- return e;\r
- }\r
-\r
- protected override Expr VisitCompareLessThan (ExprCompareLessThan e)\r
- {\r
- return this.VisitBinary (e, () => this.il.Create (e.IsSigned ? OpCodes.Clt : OpCodes.Clt_Un));\r
- }\r
-\r
- protected override Expr VisitCompareGreaterThan (ExprCompareGreaterThan e)\r
- {\r
- return this.VisitBinary (e, () => this.il.Create (e.IsSigned ? OpCodes.Cgt : OpCodes.Cgt_Un));\r
- }\r
-\r
- protected override Expr VisitCompareEqual (ExprCompareEqual e)\r
- {\r
- return this.VisitBinary (e, () => this.il.Create (OpCodes.Ceq));\r
- }\r
-\r
- protected override Expr VisitAdd (ExprAdd e)\r
- {\r
- return this.VisitBinary (e, () => {\r
- if (!e.Overflow) {\r
- return this.il.Create (OpCodes.Add);\r
- } else {\r
- return this.il.Create (e.IsSigned ? OpCodes.Add_Ovf : OpCodes.Add_Ovf_Un);\r
- }\r
- });\r
- }\r
-\r
- protected override Expr VisitSub (ExprSub e)\r
- {\r
- return this.VisitBinary (e, () => {\r
- if (!e.Overflow) {\r
- return this.il.Create (OpCodes.Sub);\r
- } else {\r
- return this.il.Create (e.IsSigned ? OpCodes.Sub_Ovf : OpCodes.Sub_Ovf_Un);\r
- }\r
- });\r
- }\r
-\r
- protected override Expr VisitCall (ExprCall e)\r
- {\r
- foreach (var param in e.Parameters) {\r
- this.Visit (param);\r
- }\r
- var instCall = this.il.Create (OpCodes.Call, e.Method);\r
- this.Emit (e, instCall);\r
- return e;\r
- }\r
-\r
- protected override Expr VisitReturn (ExprReturn e)\r
- {\r
- var instReturn = this.il.Create (OpCodes.Ret);\r
- this.Emit (e, instReturn);\r
- return e;\r
- }\r
-\r
- protected override Expr VisitBox (ExprBox e)\r
- {\r
- this.Visit (e.ExprToBox);\r
- var instBox = this.il.Create (OpCodes.Box, e.ReturnType);\r
- this.Emit (e, instBox);\r
- return e;\r
- }\r
-\r
- protected override Expr VisitConv (ExprConv e)\r
- {\r
- this.Visit (e.ExprToConvert);\r
- Instruction instConv;\r
- switch (e.ConvToType) {\r
- case TypeCode.Int32:\r
- instConv = this.il.Create (OpCodes.Conv_I4);\r
- break;\r
- case TypeCode.Int64:\r
- instConv = this.il.Create (OpCodes.Conv_I8);\r
- break;\r
- default:\r
- throw new NotSupportedException ("Cannot conv to: " + e.ConvToType);\r
- }\r
- this.Emit (e, instConv);\r
- return e;\r
- }\r
-\r
- }\r
-}\r
+//
+// CompileVisitor.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil.Cil;
+using Mono.CodeContracts.Rewrite.Ast;
+
+namespace Mono.CodeContracts.Rewrite.AstVisitors {
+ class CompileVisitor : ExprVisitor {
+
+ public CompileVisitor (CilWorker il, Dictionary<Expr, Instruction> instructionLookup)
+ : this (il, instructionLookup, il.Append)
+ {
+ }
+
+ public CompileVisitor (CilWorker il, Dictionary<Expr, Instruction> instructionLookup, Action<Instruction> fnEmit)
+ {
+ this.il = il;
+ this.instructionLookup = instructionLookup;
+ this.fnEmit = fnEmit;
+ }
+
+ private CilWorker il;
+ private Dictionary<Expr, Instruction> instructionLookup;
+ private Action<Instruction> fnEmit;
+
+ private void Emit (Expr originalExpr, Instruction inst)
+ {
+ Instruction originalInst;
+ if (this.instructionLookup != null) {
+ // TODO: Doesn't handle inherited contracts - need to check what to do in this case.
+ if (this.instructionLookup.TryGetValue (originalExpr, out originalInst)) {
+ inst.SequencePoint = originalInst.SequencePoint;
+ }
+ }
+ this.fnEmit (inst);
+ }
+
+ private void Emit (Expr originalExpr, Func<Instruction> fnCreateInstruction)
+ {
+ Instruction inst = fnCreateInstruction();
+ this.Emit (originalExpr, inst);
+ }
+
+ private void Emit (Expr originalExpr, Func<IEnumerable<Instruction>> fnCreateInstruction)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override Expr VisitNop (ExprNop e)
+ {
+ var instNop = this.il.Create (OpCodes.Nop);
+ this.Emit (e, instNop);
+ return e;
+ }
+
+ protected override Expr VisitLoadArg (ExprLoadArg e)
+ {
+ this.Emit (e, () => {
+ int index = e.Index;
+ switch (index) {
+ case 0:
+ return this.il.Create (OpCodes.Ldarg_0);
+ case 1:
+ return this.il.Create (OpCodes.Ldarg_1);
+ case 2:
+ return this.il.Create (OpCodes.Ldarg_2);
+ case 3:
+ return this.il.Create (OpCodes.Ldarg_3);
+ default:
+ if (e.Index <= 255) {
+ return this.il.Create (OpCodes.Ldarg_S, (byte) index);
+ } else {
+ return this.il.Create (OpCodes.Ldarg, index);
+ }
+ }
+ // Required due to bug in compiler
+ throw new NotSupportedException();
+ });
+
+ return e;
+ }
+
+ protected override Expr VisitLoadConstant (ExprLoadConstant e)
+ {
+ this.Emit (e, () => {
+ object v = e.Value;
+ if (v == null) {
+ return this.il.Create (OpCodes.Ldnull);
+ }
+ Type vType = v.GetType ();
+ TypeCode vTypeCode = Type.GetTypeCode (vType);
+ switch (vTypeCode) {
+ case TypeCode.Int32:
+ int value = (int) v;
+ switch (value) {
+ case -1:
+ return this.il.Create (OpCodes.Ldc_I4_M1);
+ case 0:
+ return this.il.Create (OpCodes.Ldc_I4_0);
+ case 1:
+ return this.il.Create (OpCodes.Ldc_I4_1);
+ case 2:
+ return this.il.Create (OpCodes.Ldc_I4_2);
+ case 3:
+ return this.il.Create (OpCodes.Ldc_I4_3);
+ case 4:
+ return this.il.Create (OpCodes.Ldc_I4_4);
+ case 5:
+ return this.il.Create (OpCodes.Ldc_I4_5);
+ case 6:
+ return this.il.Create (OpCodes.Ldc_I4_6);
+ case 7:
+ return this.il.Create (OpCodes.Ldc_I4_7);
+ case 8:
+ return this.il.Create (OpCodes.Ldc_I4_8);
+ default:
+ if (value >= -128 && value <= 127) {
+ return this.il.Create (OpCodes.Ldc_I4_S, (sbyte) value);
+ } else {
+ return this.il.Create (OpCodes.Ldc_I4, value);
+ }
+ }
+ // Required due to bug in compiler
+ throw new NotSupportedException();
+ case TypeCode.Single:
+ return this.il.Create (OpCodes.Ldc_R4, (float) v);
+ case TypeCode.Double:
+ return this.il.Create (OpCodes.Ldc_R8, (double) v);
+ case TypeCode.String:
+ return this.il.Create (OpCodes.Ldstr, (string) v);
+ default:
+ throw new NotSupportedException ("Cannot handle constant: " + vTypeCode);
+ }
+ // Required due to bug in compiler
+ throw new NotSupportedException();
+ });
+
+ return e;
+ }
+
+ private Expr VisitBinary (ExprBinaryOp e, Func<Instruction> fnCreateIl)
+ {
+ this.Visit (e.Left);
+ this.Visit (e.Right);
+ var inst = fnCreateIl ();
+ this.Emit (e, inst);
+ return e;
+ }
+
+ protected override Expr VisitCompareLessThan (ExprCompareLessThan e)
+ {
+ return this.VisitBinary (e, () => this.il.Create (e.IsSigned ? OpCodes.Clt : OpCodes.Clt_Un));
+ }
+
+ protected override Expr VisitCompareGreaterThan (ExprCompareGreaterThan e)
+ {
+ return this.VisitBinary (e, () => this.il.Create (e.IsSigned ? OpCodes.Cgt : OpCodes.Cgt_Un));
+ }
+
+ protected override Expr VisitCompareEqual (ExprCompareEqual e)
+ {
+ return this.VisitBinary (e, () => this.il.Create (OpCodes.Ceq));
+ }
+
+ protected override Expr VisitAdd (ExprAdd e)
+ {
+ return this.VisitBinary (e, () => {
+ if (!e.Overflow) {
+ return this.il.Create (OpCodes.Add);
+ } else {
+ return this.il.Create (e.IsSigned ? OpCodes.Add_Ovf : OpCodes.Add_Ovf_Un);
+ }
+ });
+ }
+
+ protected override Expr VisitSub (ExprSub e)
+ {
+ return this.VisitBinary (e, () => {
+ if (!e.Overflow) {
+ return this.il.Create (OpCodes.Sub);
+ } else {
+ return this.il.Create (e.IsSigned ? OpCodes.Sub_Ovf : OpCodes.Sub_Ovf_Un);
+ }
+ });
+ }
+
+ protected override Expr VisitCall (ExprCall e)
+ {
+ foreach (var param in e.Parameters) {
+ this.Visit (param);
+ }
+ var instCall = this.il.Create (OpCodes.Call, e.Method);
+ this.Emit (e, instCall);
+ return e;
+ }
+
+ protected override Expr VisitReturn (ExprReturn e)
+ {
+ var instReturn = this.il.Create (OpCodes.Ret);
+ this.Emit (e, instReturn);
+ return e;
+ }
+
+ protected override Expr VisitBox (ExprBox e)
+ {
+ this.Visit (e.ExprToBox);
+ var instBox = this.il.Create (OpCodes.Box, e.ReturnType);
+ this.Emit (e, instBox);
+ return e;
+ }
+
+ protected override Expr VisitConv (ExprConv e)
+ {
+ this.Visit (e.ExprToConvert);
+ Instruction instConv;
+ switch (e.ConvToType) {
+ case TypeCode.Int32:
+ instConv = this.il.Create (OpCodes.Conv_I4);
+ break;
+ case TypeCode.Int64:
+ instConv = this.il.Create (OpCodes.Conv_I8);
+ break;
+ default:
+ throw new NotSupportedException ("Cannot conv to: " + e.ConvToType);
+ }
+ this.Emit (e, instConv);
+ return e;
+ }
+
+ }
+}
-//\r
-// ExprVisitor.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-\r
-namespace Mono.CodeContracts.Rewrite.AstVisitors {\r
- abstract class ExprVisitor {\r
-\r
- public virtual Expr Visit (Expr e)\r
- {\r
- switch (e.ExprType) {\r
- case ExprType.Block:\r
- return this.VisitBlock ((ExprBlock) e);\r
- case ExprType.Nop:\r
- return this.VisitNop ((ExprNop) e);\r
- case ExprType.Call:\r
- return this.VisitCall ((ExprCall) e);\r
- case ExprType.CompareEqual:\r
- return this.VisitCompareEqual ((ExprCompareEqual) e);\r
- case ExprType.CompareLessThan:\r
- return this.VisitCompareLessThan ((ExprCompareLessThan) e);\r
- case ExprType.CompareGreaterThan:\r
- return this.VisitCompareGreaterThan ((ExprCompareGreaterThan) e);\r
- case ExprType.Add:\r
- return this.VisitAdd ((ExprAdd) e);\r
- case ExprType.Sub:\r
- return this.VisitSub ((ExprSub) e);\r
- case ExprType.LoadArg:\r
- return this.VisitLoadArg ((ExprLoadArg) e);\r
- case ExprType.LoadConstant:\r
- return this.VisitLoadConstant ((ExprLoadConstant) e);\r
- case ExprType.Return:\r
- return this.VisitReturn ((ExprReturn) e);\r
- case ExprType.Box:\r
- return this.VisitBox ((ExprBox) e);\r
- case ExprType.Conv:\r
- return this.VisitConv ((ExprConv) e);\r
- default:\r
- throw new NotSupportedException ("Cannot handle: " + e.ExprType);\r
- }\r
- }\r
-\r
- protected virtual Expr VisitCollection (IEnumerable<Expr> collection, Expr e, Func<IEnumerable<Expr>, Expr> fnCreateNew)\r
- {\r
- int index = 0;\r
- List<Expr> exprs = null;\r
- foreach (var expr in collection) {\r
- Expr exprVisited = this.Visit (expr);\r
- if (exprs != null || exprVisited != expr) {\r
- if (exprs == null) {\r
- exprs = new List<Expr> (collection.Take (index));\r
- }\r
- exprs.Add (exprVisited);\r
- }\r
- index++;\r
- }\r
- if (exprs == null) {\r
- return e;\r
- } else {\r
- return fnCreateNew(exprs);\r
- }\r
- }\r
-\r
- protected Expr VisitCollection (Expr e, Func<IEnumerable<Expr>, Expr> fnCreateNew, params Expr [] collection)\r
- {\r
- return this.VisitCollection (collection, e, fnCreateNew);\r
- }\r
-\r
- protected virtual Expr VisitBlock (ExprBlock e)\r
- {\r
- return this.VisitCollection (e.Exprs, e, exprs => new ExprBlock (e.MethodInfo, exprs));\r
- }\r
-\r
- protected virtual Expr VisitNop (ExprNop e)\r
- {\r
- return e;\r
- }\r
-\r
- protected virtual Expr VisitLoadArg (ExprLoadArg e)\r
- {\r
- return e;\r
- }\r
-\r
- protected virtual Expr VisitLoadConstant (ExprLoadConstant e)\r
- {\r
- return e;\r
- }\r
-\r
- protected virtual Expr VisitCompareLessThan (ExprCompareLessThan e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprCompareLessThan (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage), e.Left, e.Right);\r
- }\r
-\r
- protected virtual Expr VisitCompareGreaterThan (ExprCompareGreaterThan e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprCompareGreaterThan (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage), e.Left, e.Right);\r
- }\r
-\r
- protected virtual Expr VisitCompareEqual (ExprCompareEqual e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprCompareEqual (e.MethodInfo, exprs.First (), exprs.ElementAt (1)), e.Left, e.Right);\r
- }\r
-\r
- protected virtual Expr VisitAdd (ExprAdd e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprAdd (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage, e.Overflow), e.Left, e.Right);\r
- }\r
-\r
- protected virtual Expr VisitSub (ExprSub e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprSub (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage, e.Overflow), e.Left, e.Right);\r
- }\r
-\r
- protected virtual Expr VisitCall (ExprCall e)\r
- {\r
- return this.VisitCollection (e.Parameters, e, exprs => new ExprCall (e.MethodInfo, e.Method, exprs));\r
- }\r
-\r
- protected virtual Expr VisitReturn (ExprReturn e)\r
- {\r
- return e;\r
- }\r
-\r
- protected virtual Expr VisitBox (ExprBox e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprBox (e.MethodInfo, exprs.First ()), e.ExprToBox);\r
- }\r
-\r
- protected virtual Expr VisitConv (ExprConv e)\r
- {\r
- return this.VisitCollection (e, exprs => new ExprConv (e.MethodInfo, exprs.First (), e.ConvToType), e.ExprToConvert);\r
- }\r
- }\r
-}\r
+//
+// ExprVisitor.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.Ast;
+
+namespace Mono.CodeContracts.Rewrite.AstVisitors {
+ abstract class ExprVisitor {
+
+ public virtual Expr Visit (Expr e)
+ {
+ switch (e.ExprType) {
+ case ExprType.Block:
+ return this.VisitBlock ((ExprBlock) e);
+ case ExprType.Nop:
+ return this.VisitNop ((ExprNop) e);
+ case ExprType.Call:
+ return this.VisitCall ((ExprCall) e);
+ case ExprType.CompareEqual:
+ return this.VisitCompareEqual ((ExprCompareEqual) e);
+ case ExprType.CompareLessThan:
+ return this.VisitCompareLessThan ((ExprCompareLessThan) e);
+ case ExprType.CompareGreaterThan:
+ return this.VisitCompareGreaterThan ((ExprCompareGreaterThan) e);
+ case ExprType.Add:
+ return this.VisitAdd ((ExprAdd) e);
+ case ExprType.Sub:
+ return this.VisitSub ((ExprSub) e);
+ case ExprType.LoadArg:
+ return this.VisitLoadArg ((ExprLoadArg) e);
+ case ExprType.LoadConstant:
+ return this.VisitLoadConstant ((ExprLoadConstant) e);
+ case ExprType.Return:
+ return this.VisitReturn ((ExprReturn) e);
+ case ExprType.Box:
+ return this.VisitBox ((ExprBox) e);
+ case ExprType.Conv:
+ return this.VisitConv ((ExprConv) e);
+ default:
+ throw new NotSupportedException ("Cannot handle: " + e.ExprType);
+ }
+ }
+
+ protected virtual Expr VisitCollection (IEnumerable<Expr> collection, Expr e, Func<IEnumerable<Expr>, Expr> fnCreateNew)
+ {
+ int index = 0;
+ List<Expr> exprs = null;
+ foreach (var expr in collection) {
+ Expr exprVisited = this.Visit (expr);
+ if (exprs != null || exprVisited != expr) {
+ if (exprs == null) {
+ exprs = new List<Expr> (collection.Take (index));
+ }
+ exprs.Add (exprVisited);
+ }
+ index++;
+ }
+ if (exprs == null) {
+ return e;
+ } else {
+ return fnCreateNew(exprs);
+ }
+ }
+
+ protected Expr VisitCollection (Expr e, Func<IEnumerable<Expr>, Expr> fnCreateNew, params Expr [] collection)
+ {
+ return this.VisitCollection (collection, e, fnCreateNew);
+ }
+
+ protected virtual Expr VisitBlock (ExprBlock e)
+ {
+ return this.VisitCollection (e.Exprs, e, exprs => new ExprBlock (e.MethodInfo, exprs));
+ }
+
+ protected virtual Expr VisitNop (ExprNop e)
+ {
+ return e;
+ }
+
+ protected virtual Expr VisitLoadArg (ExprLoadArg e)
+ {
+ return e;
+ }
+
+ protected virtual Expr VisitLoadConstant (ExprLoadConstant e)
+ {
+ return e;
+ }
+
+ protected virtual Expr VisitCompareLessThan (ExprCompareLessThan e)
+ {
+ return this.VisitCollection (e, exprs => new ExprCompareLessThan (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage), e.Left, e.Right);
+ }
+
+ protected virtual Expr VisitCompareGreaterThan (ExprCompareGreaterThan e)
+ {
+ return this.VisitCollection (e, exprs => new ExprCompareGreaterThan (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage), e.Left, e.Right);
+ }
+
+ protected virtual Expr VisitCompareEqual (ExprCompareEqual e)
+ {
+ return this.VisitCollection (e, exprs => new ExprCompareEqual (e.MethodInfo, exprs.First (), exprs.ElementAt (1)), e.Left, e.Right);
+ }
+
+ protected virtual Expr VisitAdd (ExprAdd e)
+ {
+ return this.VisitCollection (e, exprs => new ExprAdd (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage, e.Overflow), e.Left, e.Right);
+ }
+
+ protected virtual Expr VisitSub (ExprSub e)
+ {
+ return this.VisitCollection (e, exprs => new ExprSub (e.MethodInfo, exprs.First (), exprs.ElementAt (1), e.Signage, e.Overflow), e.Left, e.Right);
+ }
+
+ protected virtual Expr VisitCall (ExprCall e)
+ {
+ return this.VisitCollection (e.Parameters, e, exprs => new ExprCall (e.MethodInfo, e.Method, exprs));
+ }
+
+ protected virtual Expr VisitReturn (ExprReturn e)
+ {
+ return e;
+ }
+
+ protected virtual Expr VisitBox (ExprBox e)
+ {
+ return this.VisitCollection (e, exprs => new ExprBox (e.MethodInfo, exprs.First ()), e.ExprToBox);
+ }
+
+ protected virtual Expr VisitConv (ExprConv e)
+ {
+ return this.VisitCollection (e, exprs => new ExprConv (e.MethodInfo, exprs.First (), e.ConvToType), e.ExprToConvert);
+ }
+ }
+}
-//\r
-// InstructionExtentVisitor.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-using Mono.Cecil.Cil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.AstVisitors {\r
- class InstructionExtentVisitor : ExprVisitor {\r
-\r
- public InstructionExtentVisitor (Dictionary<Expr, Instruction> instructionLookup)\r
- {\r
- this.instructionLookup = instructionLookup;\r
- }\r
-\r
- private Dictionary<Expr, Instruction> instructionLookup;\r
- private List<Instruction> instructions = new List<Instruction> ();\r
-\r
- public IEnumerable<Instruction> Instructions {\r
- get {\r
- return this.instructions.OrderBy (x => x.Offset);\r
- }\r
- }\r
-\r
- public override Expr Visit (Expr e)\r
- {\r
- Instruction inst;\r
- if (this.instructionLookup.TryGetValue (e, out inst)) {\r
- this.instructions.Add (inst);\r
- }\r
- return base.Visit (e);\r
- }\r
-\r
- }\r
-}\r
+//
+// InstructionExtentVisitor.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.Ast;
+using Mono.Cecil.Cil;
+
+namespace Mono.CodeContracts.Rewrite.AstVisitors {
+ class InstructionExtentVisitor : ExprVisitor {
+
+ public InstructionExtentVisitor (Dictionary<Expr, Instruction> instructionLookup)
+ {
+ this.instructionLookup = instructionLookup;
+ }
+
+ private Dictionary<Expr, Instruction> instructionLookup;
+ private List<Instruction> instructions = new List<Instruction> ();
+
+ public IEnumerable<Instruction> Instructions {
+ get {
+ return this.instructions.OrderBy (x => x.Offset);
+ }
+ }
+
+ public override Expr Visit (Expr e)
+ {
+ Instruction inst;
+ if (this.instructionLookup.TryGetValue (e, out inst)) {
+ this.instructions.Add (inst);
+ }
+ return base.Visit (e);
+ }
+
+ }
+}
-//\r
-// SourcePositionVisitor.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-using Mono.Cecil.Cil;\r
-\r
-namespace Mono.CodeContracts.Rewrite.AstVisitors {\r
- class SourcePositionVisitor : ExprVisitor {\r
-\r
- public struct CodePosition {\r
-\r
- public static readonly CodePosition Empty = new CodePosition ();\r
-\r
- public CodePosition (int line, int column)\r
- : this ()\r
- {\r
- this.Line = line;\r
- this.Column = column;\r
- }\r
-\r
- public int Line { get; private set; }\r
- public int Column { get; private set; }\r
-\r
- public bool IsEmpty {\r
- get {\r
- return this.Line == 0 && this.Column == 0;\r
- }\r
- }\r
-\r
- public static bool operator < (CodePosition a, CodePosition b)\r
- {\r
- if (a.Line < b.Line) {\r
- return true;\r
- }\r
- if (a.Line > b.Line) {\r
- return false;\r
- }\r
- return a.Column < b.Column;\r
- }\r
-\r
- public static bool operator > (CodePosition a, CodePosition b)\r
- {\r
- if (a.Line > b.Line) {\r
- return true;\r
- }\r
- if (a.Line < b.Line) {\r
- return false;\r
- }\r
- return a.Column > b.Column;\r
- }\r
-\r
- }\r
-\r
- public SourcePositionVisitor (Dictionary<Expr, Instruction> instructionLookup)\r
- {\r
- this.instructionLookup = instructionLookup;\r
- this.SourceCodeFileName = null;\r
- this.StartPosition = CodePosition.Empty;\r
- this.EndPosition = CodePosition.Empty;\r
- }\r
-\r
- private Dictionary<Expr, Instruction> instructionLookup;\r
-\r
- public string SourceCodeFileName { get; private set; }\r
- public CodePosition StartPosition { get; private set; }\r
- public CodePosition EndPosition { get; private set; }\r
-\r
- public override Expr Visit (Expr e)\r
- {\r
- Instruction inst;\r
- if (this.instructionLookup.TryGetValue (e, out inst)) {\r
- var seq = inst.SequencePoint;\r
- if (seq != null) {\r
- this.SourceCodeFileName = seq.Document.Url;\r
- var instStart = new CodePosition(seq.StartLine, seq.StartColumn);\r
- if (this.StartPosition.IsEmpty || instStart < this.StartPosition) {\r
- this.StartPosition = instStart;\r
- }\r
- var instEnd = new CodePosition (seq.EndLine, seq.EndColumn);\r
- if (this.EndPosition.IsEmpty || instEnd > this.EndPosition) {\r
- this.EndPosition = instEnd;\r
- }\r
- }\r
- }\r
- return base.Visit (e);\r
- }\r
-\r
- }\r
-}\r
+//
+// SourcePositionVisitor.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.Ast;
+using Mono.Cecil.Cil;
+
+namespace Mono.CodeContracts.Rewrite.AstVisitors {
+ class SourcePositionVisitor : ExprVisitor {
+
+ public struct CodePosition {
+
+ public static readonly CodePosition Empty = new CodePosition ();
+
+ public CodePosition (int line, int column)
+ : this ()
+ {
+ this.Line = line;
+ this.Column = column;
+ }
+
+ public int Line { get; private set; }
+ public int Column { get; private set; }
+
+ public bool IsEmpty {
+ get {
+ return this.Line == 0 && this.Column == 0;
+ }
+ }
+
+ public static bool operator < (CodePosition a, CodePosition b)
+ {
+ if (a.Line < b.Line) {
+ return true;
+ }
+ if (a.Line > b.Line) {
+ return false;
+ }
+ return a.Column < b.Column;
+ }
+
+ public static bool operator > (CodePosition a, CodePosition b)
+ {
+ if (a.Line > b.Line) {
+ return true;
+ }
+ if (a.Line < b.Line) {
+ return false;
+ }
+ return a.Column > b.Column;
+ }
+
+ }
+
+ public SourcePositionVisitor (Dictionary<Expr, Instruction> instructionLookup)
+ {
+ this.instructionLookup = instructionLookup;
+ this.SourceCodeFileName = null;
+ this.StartPosition = CodePosition.Empty;
+ this.EndPosition = CodePosition.Empty;
+ }
+
+ private Dictionary<Expr, Instruction> instructionLookup;
+
+ public string SourceCodeFileName { get; private set; }
+ public CodePosition StartPosition { get; private set; }
+ public CodePosition EndPosition { get; private set; }
+
+ public override Expr Visit (Expr e)
+ {
+ Instruction inst;
+ if (this.instructionLookup.TryGetValue (e, out inst)) {
+ var seq = inst.SequencePoint;
+ if (seq != null) {
+ this.SourceCodeFileName = seq.Document.Url;
+ var instStart = new CodePosition(seq.StartLine, seq.StartColumn);
+ if (this.StartPosition.IsEmpty || instStart < this.StartPosition) {
+ this.StartPosition = instStart;
+ }
+ var instEnd = new CodePosition (seq.EndLine, seq.EndColumn);
+ if (this.EndPosition.IsEmpty || instEnd > this.EndPosition) {
+ this.EndPosition = instEnd;
+ }
+ }
+ }
+ return base.Visit (e);
+ }
+
+ }
+}
-//\r
-// AssemblyRef.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using System.IO;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- public struct AssemblyRef {\r
-\r
- public struct TwoStreams {\r
-\r
- public TwoStreams (Stream assembly, Stream symbols)\r
- : this ()\r
- {\r
- this.Assembly = assembly;\r
- this.Symbols = symbols;\r
- }\r
-\r
- public Stream Assembly { get; private set; }\r
- public Stream Symbols { get; private set; }\r
-\r
- }\r
-\r
- public AssemblyRef (string filename)\r
- : this ()\r
- {\r
- this.Filename = filename;\r
- }\r
-\r
- public AssemblyRef (TwoStreams streams)\r
- : this ()\r
- {\r
- this.Streams = streams;\r
- }\r
-\r
- public string Filename { get; private set; }\r
- public TwoStreams Streams { get; private set; }\r
-\r
- public bool IsFilename {\r
- get {\r
- return this.Filename != null;\r
- }\r
- }\r
-\r
- public bool IsStream {\r
- get {\r
- return this.Streams.Assembly != null;\r
- }\r
- }\r
-\r
- public bool IsSet {\r
- get {\r
- return this.Filename != null || this.Streams.Assembly != null;\r
- }\r
- }\r
-\r
- public static implicit operator AssemblyRef (string filename)\r
- {\r
- return new AssemblyRef (filename);\r
- }\r
-\r
- public static implicit operator AssemblyRef (Stream stream)\r
- {\r
- return new AssemblyRef (new TwoStreams (stream, null));\r
- }\r
-\r
- }\r
-}\r
+//
+// AssemblyRef.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using System.IO;
+
+namespace Mono.CodeContracts.Rewrite {
+ public struct AssemblyRef {
+
+ public struct TwoStreams {
+
+ public TwoStreams (Stream assembly, Stream symbols)
+ : this ()
+ {
+ this.Assembly = assembly;
+ this.Symbols = symbols;
+ }
+
+ public Stream Assembly { get; private set; }
+ public Stream Symbols { get; private set; }
+
+ }
+
+ public AssemblyRef (string filename)
+ : this ()
+ {
+ this.Filename = filename;
+ }
+
+ public AssemblyRef (TwoStreams streams)
+ : this ()
+ {
+ this.Streams = streams;
+ }
+
+ public string Filename { get; private set; }
+ public TwoStreams Streams { get; private set; }
+
+ public bool IsFilename {
+ get {
+ return this.Filename != null;
+ }
+ }
+
+ public bool IsStream {
+ get {
+ return this.Streams.Assembly != null;
+ }
+ }
+
+ public bool IsSet {
+ get {
+ return this.Filename != null || this.Streams.Assembly != null;
+ }
+ }
+
+ public static implicit operator AssemblyRef (string filename)
+ {
+ return new AssemblyRef (filename);
+ }
+
+ public static implicit operator AssemblyRef (Stream stream)
+ {
+ return new AssemblyRef (new TwoStreams (stream, null));
+ }
+
+ }
+}
-//\r
-// ConditionTextExtractor.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.AstVisitors;\r
-using System.IO;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class ConditionTextExtractor {\r
-\r
- public ConditionTextExtractor (string filename, SourcePositionVisitor.CodePosition start, SourcePositionVisitor.CodePosition end)\r
- {\r
- this.filename = filename;\r
- this.start = start;\r
- this.end = end;\r
- }\r
-\r
- private string filename;\r
- private SourcePositionVisitor.CodePosition start, end;\r
-\r
- enum State {\r
- FunctionName,\r
- Parameters,\r
- };\r
-\r
- private State state;\r
-\r
- public string GetConditionText ()\r
- {\r
- if (this.filename == null || this.start.IsEmpty || this.end.IsEmpty){\r
- return "<unknown source code position>";\r
- }\r
- string[] lines;\r
- try {\r
- lines = File.ReadAllLines (this.filename);\r
- } catch {\r
- return "<cannot access source code>";\r
- }\r
- try {\r
- StringBuilder sb = new StringBuilder ();\r
- for (int i = this.start.Line; i <= this.end.Line; i++) {\r
- string line = lines [i - 1];\r
- if (i == this.end.Line && this.end.Column != 0) {\r
- line = line.Substring (0, this.end.Column - 1);\r
- }\r
- if (i == this.start.Line && this.start.Column != 0) {\r
- line = line.Substring (this.start.Column - 1);\r
- }\r
- sb.Append (line.Trim());\r
- }\r
- string cndStr = sb.ToString ();\r
- \r
- this.state = State.FunctionName;\r
- \r
- var cnd = this.RunStateMachine (cndStr);\r
- \r
- return cnd.ToString ().Trim ();\r
- } catch {\r
- return "<source-code parse error>";\r
- }\r
- }\r
-\r
- private StringBuilder RunStateMachine (string line)\r
- {\r
- StringBuilder cnd = new StringBuilder ();\r
- int inBrackets = 0;\r
- bool inDoubleQuotes = false;\r
- bool inSingleQuotes = false;\r
- bool inEscape = false;\r
- foreach (char c in line) {\r
- switch (this.state) {\r
- case State.FunctionName:\r
- if (c == '(') {\r
- this.state = State.Parameters;\r
- }\r
- break;\r
- case State.Parameters:\r
- switch (c) {\r
- case ',':\r
- if (inBrackets == 0 && !inDoubleQuotes && !inSingleQuotes) {\r
- return cnd;\r
- }\r
- break;\r
- case '(':\r
- if (!inDoubleQuotes && !inSingleQuotes) {\r
- inBrackets++;\r
- }\r
- break;\r
- case ')':\r
- if (!inDoubleQuotes && !inSingleQuotes) {\r
- if (inBrackets == 0) {\r
- return cnd;\r
- }\r
- inBrackets--;\r
- }\r
- break;\r
- case '"':\r
- if (!inEscape) {\r
- inDoubleQuotes = !inDoubleQuotes;\r
- }\r
- break;\r
- case '\'':\r
- if (!inEscape) {\r
- inSingleQuotes = !inSingleQuotes;\r
- }\r
- break;\r
- case '\\':\r
- inEscape = true;\r
- goto forceEscape;\r
- }\r
- inEscape = false;\r
- forceEscape:\r
- cnd.Append (c);\r
- break;\r
- default:\r
- throw new NotSupportedException ("Cannot handle state: " + this.state);\r
- }\r
- }\r
-\r
- return new StringBuilder ("<bad source code>");\r
- }\r
-\r
- }\r
-}\r
+//
+// ConditionTextExtractor.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.AstVisitors;
+using System.IO;
+
+namespace Mono.CodeContracts.Rewrite {
+ class ConditionTextExtractor {
+
+ public ConditionTextExtractor (string filename, SourcePositionVisitor.CodePosition start, SourcePositionVisitor.CodePosition end)
+ {
+ this.filename = filename;
+ this.start = start;
+ this.end = end;
+ }
+
+ private string filename;
+ private SourcePositionVisitor.CodePosition start, end;
+
+ enum State {
+ FunctionName,
+ Parameters,
+ };
+
+ private State state;
+
+ public string GetConditionText ()
+ {
+ if (this.filename == null || this.start.IsEmpty || this.end.IsEmpty){
+ return "<unknown source code position>";
+ }
+ string[] lines;
+ try {
+ lines = File.ReadAllLines (this.filename);
+ } catch {
+ return "<cannot access source code>";
+ }
+ try {
+ StringBuilder sb = new StringBuilder ();
+ for (int i = this.start.Line; i <= this.end.Line; i++) {
+ string line = lines [i - 1];
+ if (i == this.end.Line && this.end.Column != 0) {
+ line = line.Substring (0, this.end.Column - 1);
+ }
+ if (i == this.start.Line && this.start.Column != 0) {
+ line = line.Substring (this.start.Column - 1);
+ }
+ sb.Append (line.Trim());
+ }
+ string cndStr = sb.ToString ();
+
+ this.state = State.FunctionName;
+
+ var cnd = this.RunStateMachine (cndStr);
+
+ return cnd.ToString ().Trim ();
+ } catch {
+ return "<source-code parse error>";
+ }
+ }
+
+ private StringBuilder RunStateMachine (string line)
+ {
+ StringBuilder cnd = new StringBuilder ();
+ int inBrackets = 0;
+ bool inDoubleQuotes = false;
+ bool inSingleQuotes = false;
+ bool inEscape = false;
+ foreach (char c in line) {
+ switch (this.state) {
+ case State.FunctionName:
+ if (c == '(') {
+ this.state = State.Parameters;
+ }
+ break;
+ case State.Parameters:
+ switch (c) {
+ case ',':
+ if (inBrackets == 0 && !inDoubleQuotes && !inSingleQuotes) {
+ return cnd;
+ }
+ break;
+ case '(':
+ if (!inDoubleQuotes && !inSingleQuotes) {
+ inBrackets++;
+ }
+ break;
+ case ')':
+ if (!inDoubleQuotes && !inSingleQuotes) {
+ if (inBrackets == 0) {
+ return cnd;
+ }
+ inBrackets--;
+ }
+ break;
+ case '"':
+ if (!inEscape) {
+ inDoubleQuotes = !inDoubleQuotes;
+ }
+ break;
+ case '\'':
+ if (!inEscape) {
+ inSingleQuotes = !inSingleQuotes;
+ }
+ break;
+ case '\\':
+ inEscape = true;
+ goto forceEscape;
+ }
+ inEscape = false;
+ forceEscape:
+ cnd.Append (c);
+ break;
+ default:
+ throw new NotSupportedException ("Cannot handle state: " + this.state);
+ }
+ }
+
+ return new StringBuilder ("<bad source code>");
+ }
+
+ }
+}
-//\r
-// ContractRequiresInfo.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class ContractRequiresInfo {\r
-\r
- public ContractRequiresInfo (Expr originalExpr, Expr rewrittenExpr)\r
- {\r
- this.OriginalExpr = originalExpr;\r
- this.RewrittenExpr = rewrittenExpr;\r
- }\r
-\r
- public Expr OriginalExpr { get; private set; }\r
- public Expr RewrittenExpr { get; private set; }\r
-\r
- }\r
-}\r
+//
+// ContractRequiresInfo.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.Ast;
+
+namespace Mono.CodeContracts.Rewrite {
+ class ContractRequiresInfo {
+
+ public ContractRequiresInfo (Expr originalExpr, Expr rewrittenExpr)
+ {
+ this.OriginalExpr = originalExpr;
+ this.RewrittenExpr = rewrittenExpr;
+ }
+
+ public Expr OriginalExpr { get; private set; }
+ public Expr RewrittenExpr { get; private set; }
+
+ }
+}
-//\r
-// ContractRuntime.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-using System.Diagnostics.Contracts;\r
-using Mono.Cecil.Cil;\r
-using System.Diagnostics.Contracts.Internal;\r
-using System.Diagnostics;\r
-using System.Runtime.ConstrainedExecution;\r
-using System.Runtime.CompilerServices;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class ContractsRuntime {\r
-\r
- private const string Namespace = "System.Diagnostics.Contracts";\r
-\r
- public ContractsRuntime (ModuleDefinition module, RewriterOptions options)\r
- {\r
- this.module = module;\r
- this.options = options;\r
- }\r
-\r
- private ModuleDefinition module;\r
- private RewriterOptions options;\r
-\r
- private TypeDefinition typeContractsRuntime = null;\r
- private TypeDefinition typeContractException = null;\r
- private MethodDefinition methodContractExceptionCons = null;\r
- private MethodDefinition methodTriggerFailure = null;\r
- private MethodDefinition methodReportFailure = null;\r
- private MethodDefinition methodRequires = null;\r
-\r
- private void EnsureTypeContractRuntime ()\r
- {\r
- if (this.typeContractsRuntime == null) {\r
- // namespace System.Diagnostics.Contracts {\r
- // [CompilerGenerated]\r
- // private static class __ContractsRuntime {\r
- // }\r
- // }\r
- \r
- // Create type\r
- TypeReference typeObject = this.module.Import (typeof (object));\r
- TypeDefinition type = new TypeDefinition ("__ContractsRuntime", Namespace,\r
- TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.NotPublic | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, // | TypeAttributes.BeforeFieldInit,\r
- typeObject);\r
- this.module.Types.Add (type);\r
- // Attach custom attributes\r
- var attrCompilerGeneratedCons = typeof (CompilerGeneratedAttribute).GetConstructor (Type.EmptyTypes);\r
- CustomAttribute attrCompilerGenerated = new CustomAttribute (this.module.Import (attrCompilerGeneratedCons));\r
- type.CustomAttributes.Add (attrCompilerGenerated);\r
- // Store type\r
- this.typeContractsRuntime = type;\r
- }\r
- }\r
-\r
- private void EnsureTypeContractException ()\r
- {\r
- if (this.options.ThrowOnFailure && this.typeContractException == null) {\r
- // [CompilerGenerated]\r
- // private class ContractException : Exception {\r
- // internal ContractException(ContractFailureKind kind, string usermsg, string condition, Exception inner)\r
- // : base(failure, inner)\r
- // {\r
- // }\r
- // }\r
- \r
- // Prepare type references\r
- TypeReference typeVoid = this.module.Import (typeof (void));\r
- TypeReference typeContractFailureKind = this.module.Import (typeof (ContractFailureKind));\r
- TypeReference typeString = this.module.Import (typeof (string));\r
- TypeReference typeException = this.module.Import (typeof (Exception));\r
- // Create type\r
- TypeDefinition type = new TypeDefinition ("ContractException", Namespace,\r
- TypeAttributes.NestedPrivate | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, typeException);\r
- //this.typeContractsRuntime.NestedTypes.Add (type);\r
- this.module.Types.Add(type);\r
- // Create constructor\r
- MethodDefinition cons = new MethodDefinition (".ctor",\r
- MethodAttributes.Assem | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, typeVoid);\r
- cons.Parameters.Add (new ParameterDefinition ("kind", 1, ParameterAttributes.None, typeContractFailureKind));\r
- cons.Parameters.Add (new ParameterDefinition ("failure", 2, ParameterAttributes.None, typeString));\r
- cons.Parameters.Add (new ParameterDefinition ("usermsg", 3, ParameterAttributes.None, typeString));\r
- cons.Parameters.Add (new ParameterDefinition ("condition", 4, ParameterAttributes.None, typeString));\r
- cons.Parameters.Add (new ParameterDefinition ("inner", 5, ParameterAttributes.None, typeException));\r
- var il = cons.Body.CilWorker;\r
- il.Emit (OpCodes.Ldarg_0);\r
- il.Emit (OpCodes.Ldarg_2);\r
- il.Emit (OpCodes.Ldarg_S, cons.Parameters [4]);\r
- MethodReference mExceptionCons = this.module.Import (typeof (Exception).GetConstructor (new [] { typeof (string), typeof (Exception) }));\r
- il.Emit (OpCodes.Call, mExceptionCons);\r
- il.Emit (OpCodes.Ret);\r
- type.Methods.Add (cons);\r
- // Attach custom attributes\r
- var attrCompilerGeneratedCons = typeof (CompilerGeneratedAttribute).GetConstructor (Type.EmptyTypes);\r
- CustomAttribute attrCompilerGenerated = new CustomAttribute (this.module.Import (attrCompilerGeneratedCons));\r
- type.CustomAttributes.Add (attrCompilerGenerated);\r
- // Store constructor and type\r
- this.methodContractExceptionCons = cons;\r
- this.typeContractException = type;\r
- }\r
- }\r
-\r
- private void EnsureMethodTriggerFailure ()\r
- {\r
- if (this.methodTriggerFailure == null) {\r
- // if the ThrowOnFailure option is true, then:\r
- // internal static void TriggerFailure(ContractFailureKind kind, string message, string userMessage, string conditionText, Exception inner)\r
- // {\r
- // throw new ContractException(kind, message, userMessage, conditionText, inner);\r
- // }\r
- \r
- // if the ThrowOnFailure option is false, then:\r
- // internal static void TriggerFailure(ContractFailureKind kind, string message, string userMessage, string conditionText, Exception inner)\r
- // {\r
- // Debug.Fail(message, userMessage);\r
- // }\r
- \r
- // Prepare type references\r
- TypeReference typeVoid = this.module.Import (typeof (void));\r
- TypeReference typeContractFailureKind = this.module.Import (typeof (ContractFailureKind));\r
- TypeReference typeString = this.module.Import (typeof (string));\r
- TypeReference typeException = this.module.Import (typeof (Exception));\r
- // Create method\r
- MethodDefinition method = new MethodDefinition ("TriggerFailure",\r
- MethodAttributes.Assem | MethodAttributes.Static, typeVoid);\r
- method.Parameters.Add (new ParameterDefinition ("kind", 1, ParameterAttributes.None, typeContractFailureKind));\r
- method.Parameters.Add (new ParameterDefinition ("message", 2, ParameterAttributes.None, typeString));\r
- method.Parameters.Add (new ParameterDefinition ("userMessage", 3, ParameterAttributes.None, typeString));\r
- method.Parameters.Add (new ParameterDefinition ("conditionText", 4, ParameterAttributes.None, typeString));\r
- method.Parameters.Add (new ParameterDefinition ("inner", 5, ParameterAttributes.None, typeException));\r
- var il = method.Body.CilWorker;\r
- if (this.options.ThrowOnFailure) {\r
- il.Emit (OpCodes.Ldarg_0);\r
- il.Emit (OpCodes.Ldarg_1);\r
- il.Emit (OpCodes.Ldarg_2);\r
- il.Emit (OpCodes.Ldarg_3);\r
- il.Emit (OpCodes.Ldarg_S, method.Parameters [4]);\r
- il.Emit (OpCodes.Newobj, this.methodContractExceptionCons);\r
- il.Emit (OpCodes.Throw);\r
- } else {\r
- var mDebugFail = typeof (Debug).GetMethod ("Fail", new [] { typeof (string), typeof(string) });\r
- MethodReference methodDebugFail = this.module.Import (mDebugFail);\r
- il.Emit (OpCodes.Ldarg_1);\r
- il.Emit (OpCodes.Ldarg_2);\r
- il.Emit (OpCodes.Call, methodDebugFail);\r
- il.Emit (OpCodes.Ret);\r
- }\r
- this.typeContractsRuntime.Methods.Add (method);\r
- this.methodTriggerFailure = method;\r
- }\r
- }\r
-\r
- private void EnsureMethodReportFailure ()\r
- {\r
- if (this.methodReportFailure == null) {\r
- // internal static void ReportFailure(ContractFailureKind kind, string message, string conditionText, Exception inner)\r
- // {\r
- // string s = ContractHelper.RaiseContractFailedEvent(kind, message, conditionText, inner);\r
- // if (s != null) {\r
- // TriggerFailure(kind, s, message, conditionText, inner);\r
- // }\r
- // }\r
- \r
- // Prepare type references\r
- TypeReference typeVoid = this.module.Import (typeof (void));\r
- TypeReference typeContractFailureKind = this.module.Import (typeof (ContractFailureKind));\r
- TypeReference typeString = this.module.Import (typeof (string));\r
- TypeReference typeException = this.module.Import (typeof (Exception));\r
- MethodReference mRaiseContractFailedEvent = this.module.Import (typeof (ContractHelper).GetMethod ("RaiseContractFailedEvent"));\r
- // Create method\r
- MethodDefinition method = new MethodDefinition ("ReportFailure",\r
- MethodAttributes.Assem | MethodAttributes.Static, typeVoid);\r
- method.Parameters.Add (new ParameterDefinition ("kind", 1, ParameterAttributes.None, typeContractFailureKind));\r
- method.Parameters.Add (new ParameterDefinition ("message", 2, ParameterAttributes.None, typeString));\r
- method.Parameters.Add (new ParameterDefinition ("conditionText", 3, ParameterAttributes.None, typeString));\r
- method.Parameters.Add (new ParameterDefinition ("inner", 4, ParameterAttributes.None, typeException));\r
- VariableDefinition vMsg = new VariableDefinition ("sMsg", 0, method, typeString);\r
- method.Body.Variables.Add (vMsg);\r
- method.Body.InitLocals = true;\r
- var il = method.Body.CilWorker;\r
- il.Emit (OpCodes.Ldarg_0);\r
- il.Emit (OpCodes.Ldarg_1);\r
- il.Emit (OpCodes.Ldarg_2);\r
- il.Emit (OpCodes.Ldarg_3);\r
- il.Emit (OpCodes.Call, mRaiseContractFailedEvent);\r
- il.Emit (OpCodes.Stloc_0);\r
- il.Emit (OpCodes.Ldloc_0);\r
- var instRet = il.Create (OpCodes.Ret);\r
- il.Emit (OpCodes.Brfalse_S, instRet);\r
- il.Emit (OpCodes.Ldarg_0);\r
- il.Emit (OpCodes.Ldloc_0);\r
- il.Emit (OpCodes.Ldarg_1);\r
- il.Emit (OpCodes.Ldarg_2);\r
- il.Emit (OpCodes.Ldarg_3);\r
- il.Emit (OpCodes.Call, this.methodTriggerFailure);\r
- il.Append (instRet);\r
- this.typeContractsRuntime.Methods.Add (method);\r
- this.methodReportFailure = method;\r
- }\r
- }\r
-\r
- private void EnsureGlobal ()\r
- {\r
- this.EnsureTypeContractRuntime ();\r
- this.EnsureTypeContractException ();\r
- this.EnsureMethodTriggerFailure ();\r
- this.EnsureMethodReportFailure ();\r
- }\r
-\r
- public MethodDefinition GetRequires ()\r
- {\r
- this.EnsureGlobal ();\r
- if (this.methodRequires == null) {\r
- // [DebuggerNonUserCode]\r
- // [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]\r
- // internal static void Requires(bool condition, string message, string conditionText)\r
- // {\r
- // if (!condition) {\r
- // ReportFailure(ContractFailureKind.Precondition, message, conditionText, null);\r
- // }\r
- // }\r
- \r
- // Prepare type references\r
- TypeReference typeVoid = this.module.Import (typeof (void));\r
- TypeReference typeBoolean = this.module.Import (typeof (bool));\r
- TypeReference typeString = this.module.Import (typeof (string));\r
- // Create method\r
- MethodDefinition method = new MethodDefinition ("Requires",\r
- MethodAttributes.Assem | MethodAttributes.Static, typeVoid);\r
- method.Parameters.Add (new ParameterDefinition ("condition", 1, ParameterAttributes.None, typeBoolean));\r
- method.Parameters.Add (new ParameterDefinition ("message", 2, ParameterAttributes.None, typeString));\r
- method.Parameters.Add (new ParameterDefinition ("conditionText", 3, ParameterAttributes.None, typeString));\r
- var il = method.Body.CilWorker;\r
- il.Emit (OpCodes.Ldarg_0);\r
- var instRet = il.Create(OpCodes.Ret);\r
- il.Emit (OpCodes.Brtrue_S, instRet);\r
- il.Emit (OpCodes.Ldc_I4_0); // Assumes ContractFailureKind.Precondition == 0\r
- il.Emit (OpCodes.Ldarg_1);\r
- il.Emit (OpCodes.Ldarg_2);\r
- il.Emit (OpCodes.Ldnull);\r
- il.Emit (OpCodes.Call, this.methodReportFailure);\r
- il.Append (instRet);\r
- this.typeContractsRuntime.Methods.Add (method);\r
- // Attach custom attributes\r
- var attrDebugNonUserCodeCons = typeof (DebuggerNonUserCodeAttribute).GetConstructor (Type.EmptyTypes);\r
- CustomAttribute attrDebugNonUserCode = new CustomAttribute (this.module.Import (attrDebugNonUserCodeCons));\r
- method.CustomAttributes.Add (attrDebugNonUserCode);\r
- var attrReliabilityContractCons = typeof (ReliabilityContractAttribute).GetConstructor (new [] { typeof (Consistency), typeof (Cer) });\r
- // Blob for attribute: new ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)\r
- byte [] blob = new byte [] { 1, 0, 3, 0, 0, 0, 1, 0, 0, 0 };\r
- CustomAttribute attrReliabilityContract = new CustomAttribute (this.module.Import (attrReliabilityContractCons), blob);\r
- method.CustomAttributes.Add (attrReliabilityContract);\r
- // Store method\r
- this.methodRequires = method;\r
- }\r
- return this.methodRequires;\r
- }\r
-\r
- }\r
-}\r
+//
+// ContractRuntime.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+using System.Diagnostics.Contracts;
+using Mono.Cecil.Cil;
+using System.Diagnostics.Contracts.Internal;
+using System.Diagnostics;
+using System.Runtime.ConstrainedExecution;
+using System.Runtime.CompilerServices;
+
+namespace Mono.CodeContracts.Rewrite {
+ class ContractsRuntime {
+
+ private const string Namespace = "System.Diagnostics.Contracts";
+
+ public ContractsRuntime (ModuleDefinition module, RewriterOptions options)
+ {
+ this.module = module;
+ this.options = options;
+ }
+
+ private ModuleDefinition module;
+ private RewriterOptions options;
+
+ private TypeDefinition typeContractsRuntime = null;
+ private TypeDefinition typeContractException = null;
+ private MethodDefinition methodContractExceptionCons = null;
+ private MethodDefinition methodTriggerFailure = null;
+ private MethodDefinition methodReportFailure = null;
+ private MethodDefinition methodRequires = null;
+
+ private void EnsureTypeContractRuntime ()
+ {
+ if (this.typeContractsRuntime == null) {
+ // namespace System.Diagnostics.Contracts {
+ // [CompilerGenerated]
+ // private static class __ContractsRuntime {
+ // }
+ // }
+
+ // Create type
+ TypeReference typeObject = this.module.Import (typeof (object));
+ TypeDefinition type = new TypeDefinition ("__ContractsRuntime", Namespace,
+ TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.NotPublic | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, // | TypeAttributes.BeforeFieldInit,
+ typeObject);
+ this.module.Types.Add (type);
+ // Attach custom attributes
+ var attrCompilerGeneratedCons = typeof (CompilerGeneratedAttribute).GetConstructor (Type.EmptyTypes);
+ CustomAttribute attrCompilerGenerated = new CustomAttribute (this.module.Import (attrCompilerGeneratedCons));
+ type.CustomAttributes.Add (attrCompilerGenerated);
+ // Store type
+ this.typeContractsRuntime = type;
+ }
+ }
+
+ private void EnsureTypeContractException ()
+ {
+ if (this.options.ThrowOnFailure && this.typeContractException == null) {
+ // [CompilerGenerated]
+ // private class ContractException : Exception {
+ // internal ContractException(ContractFailureKind kind, string usermsg, string condition, Exception inner)
+ // : base(failure, inner)
+ // {
+ // }
+ // }
+
+ // Prepare type references
+ TypeReference typeVoid = this.module.Import (typeof (void));
+ TypeReference typeContractFailureKind = this.module.Import (typeof (ContractFailureKind));
+ TypeReference typeString = this.module.Import (typeof (string));
+ TypeReference typeException = this.module.Import (typeof (Exception));
+ // Create type
+ TypeDefinition type = new TypeDefinition ("ContractException", Namespace,
+ TypeAttributes.NestedPrivate | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, typeException);
+ //this.typeContractsRuntime.NestedTypes.Add (type);
+ this.module.Types.Add(type);
+ // Create constructor
+ MethodDefinition cons = new MethodDefinition (".ctor",
+ MethodAttributes.Assem | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, typeVoid);
+ cons.Parameters.Add (new ParameterDefinition ("kind", 1, ParameterAttributes.None, typeContractFailureKind));
+ cons.Parameters.Add (new ParameterDefinition ("failure", 2, ParameterAttributes.None, typeString));
+ cons.Parameters.Add (new ParameterDefinition ("usermsg", 3, ParameterAttributes.None, typeString));
+ cons.Parameters.Add (new ParameterDefinition ("condition", 4, ParameterAttributes.None, typeString));
+ cons.Parameters.Add (new ParameterDefinition ("inner", 5, ParameterAttributes.None, typeException));
+ var il = cons.Body.CilWorker;
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldarg_2);
+ il.Emit (OpCodes.Ldarg_S, cons.Parameters [4]);
+ MethodReference mExceptionCons = this.module.Import (typeof (Exception).GetConstructor (new [] { typeof (string), typeof (Exception) }));
+ il.Emit (OpCodes.Call, mExceptionCons);
+ il.Emit (OpCodes.Ret);
+ type.Methods.Add (cons);
+ // Attach custom attributes
+ var attrCompilerGeneratedCons = typeof (CompilerGeneratedAttribute).GetConstructor (Type.EmptyTypes);
+ CustomAttribute attrCompilerGenerated = new CustomAttribute (this.module.Import (attrCompilerGeneratedCons));
+ type.CustomAttributes.Add (attrCompilerGenerated);
+ // Store constructor and type
+ this.methodContractExceptionCons = cons;
+ this.typeContractException = type;
+ }
+ }
+
+ private void EnsureMethodTriggerFailure ()
+ {
+ if (this.methodTriggerFailure == null) {
+ // if the ThrowOnFailure option is true, then:
+ // internal static void TriggerFailure(ContractFailureKind kind, string message, string userMessage, string conditionText, Exception inner)
+ // {
+ // throw new ContractException(kind, message, userMessage, conditionText, inner);
+ // }
+
+ // if the ThrowOnFailure option is false, then:
+ // internal static void TriggerFailure(ContractFailureKind kind, string message, string userMessage, string conditionText, Exception inner)
+ // {
+ // Debug.Fail(message, userMessage);
+ // }
+
+ // Prepare type references
+ TypeReference typeVoid = this.module.Import (typeof (void));
+ TypeReference typeContractFailureKind = this.module.Import (typeof (ContractFailureKind));
+ TypeReference typeString = this.module.Import (typeof (string));
+ TypeReference typeException = this.module.Import (typeof (Exception));
+ // Create method
+ MethodDefinition method = new MethodDefinition ("TriggerFailure",
+ MethodAttributes.Assem | MethodAttributes.Static, typeVoid);
+ method.Parameters.Add (new ParameterDefinition ("kind", 1, ParameterAttributes.None, typeContractFailureKind));
+ method.Parameters.Add (new ParameterDefinition ("message", 2, ParameterAttributes.None, typeString));
+ method.Parameters.Add (new ParameterDefinition ("userMessage", 3, ParameterAttributes.None, typeString));
+ method.Parameters.Add (new ParameterDefinition ("conditionText", 4, ParameterAttributes.None, typeString));
+ method.Parameters.Add (new ParameterDefinition ("inner", 5, ParameterAttributes.None, typeException));
+ var il = method.Body.CilWorker;
+ if (this.options.ThrowOnFailure) {
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldarg_1);
+ il.Emit (OpCodes.Ldarg_2);
+ il.Emit (OpCodes.Ldarg_3);
+ il.Emit (OpCodes.Ldarg_S, method.Parameters [4]);
+ il.Emit (OpCodes.Newobj, this.methodContractExceptionCons);
+ il.Emit (OpCodes.Throw);
+ } else {
+ var mDebugFail = typeof (Debug).GetMethod ("Fail", new [] { typeof (string), typeof(string) });
+ MethodReference methodDebugFail = this.module.Import (mDebugFail);
+ il.Emit (OpCodes.Ldarg_1);
+ il.Emit (OpCodes.Ldarg_2);
+ il.Emit (OpCodes.Call, methodDebugFail);
+ il.Emit (OpCodes.Ret);
+ }
+ this.typeContractsRuntime.Methods.Add (method);
+ this.methodTriggerFailure = method;
+ }
+ }
+
+ private void EnsureMethodReportFailure ()
+ {
+ if (this.methodReportFailure == null) {
+ // internal static void ReportFailure(ContractFailureKind kind, string message, string conditionText, Exception inner)
+ // {
+ // string s = ContractHelper.RaiseContractFailedEvent(kind, message, conditionText, inner);
+ // if (s != null) {
+ // TriggerFailure(kind, s, message, conditionText, inner);
+ // }
+ // }
+
+ // Prepare type references
+ TypeReference typeVoid = this.module.Import (typeof (void));
+ TypeReference typeContractFailureKind = this.module.Import (typeof (ContractFailureKind));
+ TypeReference typeString = this.module.Import (typeof (string));
+ TypeReference typeException = this.module.Import (typeof (Exception));
+ MethodReference mRaiseContractFailedEvent = this.module.Import (typeof (ContractHelper).GetMethod ("RaiseContractFailedEvent"));
+ // Create method
+ MethodDefinition method = new MethodDefinition ("ReportFailure",
+ MethodAttributes.Assem | MethodAttributes.Static, typeVoid);
+ method.Parameters.Add (new ParameterDefinition ("kind", 1, ParameterAttributes.None, typeContractFailureKind));
+ method.Parameters.Add (new ParameterDefinition ("message", 2, ParameterAttributes.None, typeString));
+ method.Parameters.Add (new ParameterDefinition ("conditionText", 3, ParameterAttributes.None, typeString));
+ method.Parameters.Add (new ParameterDefinition ("inner", 4, ParameterAttributes.None, typeException));
+ VariableDefinition vMsg = new VariableDefinition ("sMsg", 0, method, typeString);
+ method.Body.Variables.Add (vMsg);
+ method.Body.InitLocals = true;
+ var il = method.Body.CilWorker;
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldarg_1);
+ il.Emit (OpCodes.Ldarg_2);
+ il.Emit (OpCodes.Ldarg_3);
+ il.Emit (OpCodes.Call, mRaiseContractFailedEvent);
+ il.Emit (OpCodes.Stloc_0);
+ il.Emit (OpCodes.Ldloc_0);
+ var instRet = il.Create (OpCodes.Ret);
+ il.Emit (OpCodes.Brfalse_S, instRet);
+ il.Emit (OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldloc_0);
+ il.Emit (OpCodes.Ldarg_1);
+ il.Emit (OpCodes.Ldarg_2);
+ il.Emit (OpCodes.Ldarg_3);
+ il.Emit (OpCodes.Call, this.methodTriggerFailure);
+ il.Append (instRet);
+ this.typeContractsRuntime.Methods.Add (method);
+ this.methodReportFailure = method;
+ }
+ }
+
+ private void EnsureGlobal ()
+ {
+ this.EnsureTypeContractRuntime ();
+ this.EnsureTypeContractException ();
+ this.EnsureMethodTriggerFailure ();
+ this.EnsureMethodReportFailure ();
+ }
+
+ public MethodDefinition GetRequires ()
+ {
+ this.EnsureGlobal ();
+ if (this.methodRequires == null) {
+ // [DebuggerNonUserCode]
+ // [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
+ // internal static void Requires(bool condition, string message, string conditionText)
+ // {
+ // if (!condition) {
+ // ReportFailure(ContractFailureKind.Precondition, message, conditionText, null);
+ // }
+ // }
+
+ // Prepare type references
+ TypeReference typeVoid = this.module.Import (typeof (void));
+ TypeReference typeBoolean = this.module.Import (typeof (bool));
+ TypeReference typeString = this.module.Import (typeof (string));
+ // Create method
+ MethodDefinition method = new MethodDefinition ("Requires",
+ MethodAttributes.Assem | MethodAttributes.Static, typeVoid);
+ method.Parameters.Add (new ParameterDefinition ("condition", 1, ParameterAttributes.None, typeBoolean));
+ method.Parameters.Add (new ParameterDefinition ("message", 2, ParameterAttributes.None, typeString));
+ method.Parameters.Add (new ParameterDefinition ("conditionText", 3, ParameterAttributes.None, typeString));
+ var il = method.Body.CilWorker;
+ il.Emit (OpCodes.Ldarg_0);
+ var instRet = il.Create(OpCodes.Ret);
+ il.Emit (OpCodes.Brtrue_S, instRet);
+ il.Emit (OpCodes.Ldc_I4_0); // Assumes ContractFailureKind.Precondition == 0
+ il.Emit (OpCodes.Ldarg_1);
+ il.Emit (OpCodes.Ldarg_2);
+ il.Emit (OpCodes.Ldnull);
+ il.Emit (OpCodes.Call, this.methodReportFailure);
+ il.Append (instRet);
+ this.typeContractsRuntime.Methods.Add (method);
+ // Attach custom attributes
+ var attrDebugNonUserCodeCons = typeof (DebuggerNonUserCodeAttribute).GetConstructor (Type.EmptyTypes);
+ CustomAttribute attrDebugNonUserCode = new CustomAttribute (this.module.Import (attrDebugNonUserCodeCons));
+ method.CustomAttributes.Add (attrDebugNonUserCode);
+ var attrReliabilityContractCons = typeof (ReliabilityContractAttribute).GetConstructor (new [] { typeof (Consistency), typeof (Cer) });
+ // Blob for attribute: new ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)
+ byte [] blob = new byte [] { 1, 0, 3, 0, 0, 0, 1, 0, 0, 0 };
+ CustomAttribute attrReliabilityContract = new CustomAttribute (this.module.Import (attrReliabilityContractCons), blob);
+ method.CustomAttributes.Add (attrReliabilityContract);
+ // Store method
+ this.methodRequires = method;
+ }
+ return this.methodRequires;
+ }
+
+ }
+}
-//\r
-// Decompile.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-using Mono.Cecil;\r
-using Mono.Cecil.Cil;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
-\r
- class Decompile {\r
-\r
- public Decompile (ModuleDefinition module, MethodDefinition method)\r
- {\r
- this.method = method;\r
- this.exprs = new Stack<Expr> ();\r
- this.Instructions = new Dictionary<Expr, Instruction> ();\r
- this.methodInfo = new MethodInfo (module, method);\r
- this.gen = new ExprGen (this.methodInfo);\r
- }\r
-\r
- private MethodInfo methodInfo;\r
- private MethodDefinition method;\r
- private Stack<Expr> exprs;\r
- private ExprGen gen;\r
-\r
- public Dictionary<Expr, Instruction> Instructions { get; private set; }\r
-\r
- public Expr Go (bool failQuietly = true)\r
- {\r
- Instruction unknownInst = null;\r
- var insts = this.method.Body.Instructions;\r
- foreach (Instruction inst in insts) {\r
- if (failQuietly) {\r
- if (unknownInst == null) {\r
- try {\r
- Expr expr = this.ProcessInst (inst);\r
- this.Instructions.Add (expr, inst);\r
- this.exprs.Push (expr);\r
- } catch (NotSupportedException) {\r
- unknownInst = inst;\r
- }\r
- } else {\r
- // Met unknown instruction, so check that there are no more contracts\r
- if (inst.OpCode.OperandType == OperandType.InlineMethod) {\r
- MethodReference method = (MethodReference) inst.Operand;\r
- if (method.DeclaringType.FullName == "System.Diagnostics.Contracts.Contract") {\r
- throw new NotSupportedException ("Unknown instruction in contract: " + unknownInst);\r
- }\r
- }\r
- }\r
- } else {\r
- Expr expr = this.ProcessInst (inst);\r
- this.Instructions.Add (expr, inst);\r
- this.exprs.Push (expr);\r
- }\r
- }\r
-\r
- Expr decompiled = new ExprBlock (this.methodInfo, this.exprs.Reverse ().ToArray ());\r
- return decompiled;\r
- }\r
-\r
- private Expr ProcessInst (Instruction inst)\r
- {\r
- var opcode = inst.OpCode.Code;\r
- switch (opcode) {\r
- case Code.Nop:\r
- return this.gen.Nop ();\r
- case Code.Ldarg_0:\r
- case Code.Ldarg_1:\r
- case Code.Ldarg_2:\r
- case Code.Ldarg_3:\r
- return this.gen.LoadArg ((int) (opcode - Code.Ldarg_0));\r
- case Code.Ldarg_S:\r
- return this.gen.LoadArg ((ParameterDefinition) inst.Operand);\r
- case Code.Ldnull:\r
- return this.gen.LoadConstant (null);\r
- case Code.Ldc_I4_M1:\r
- case Code.Ldc_I4_0:\r
- case Code.Ldc_I4_1:\r
- case Code.Ldc_I4_2:\r
- case Code.Ldc_I4_3:\r
- case Code.Ldc_I4_4:\r
- case Code.Ldc_I4_5:\r
- case Code.Ldc_I4_6:\r
- case Code.Ldc_I4_7:\r
- case Code.Ldc_I4_8:\r
- return this.gen.LoadConstant ((int) (opcode - Code.Ldc_I4_0));\r
- case Code.Ldc_I4_S:\r
- return this.gen.LoadConstant ((int) (sbyte) inst.Operand);\r
- case Code.Ldc_I4:\r
- return this.gen.LoadConstant ((int) inst.Operand);\r
- case Code.Ldc_R4:\r
- case Code.Ldc_R8:\r
- case Code.Ldstr:\r
- return this.gen.LoadConstant(inst.Operand);\r
- case Code.Clt:\r
- case Code.Clt_Un:\r
- case Code.Cgt:\r
- case Code.Cgt_Un:\r
- case Code.Ceq:\r
- case Code.Add:\r
- case Code.Sub:\r
- return this.ProcessBinaryOp (opcode);\r
- case Code.Call:\r
- return this.ProcessCall ((MethodReference) inst.Operand);\r
- case Code.Ret:\r
- return this.gen.Return ();\r
- case Code.Conv_I4:\r
- return this.ProcessConv (TypeCode.Int32);\r
- case Code.Conv_I8:\r
- return this.ProcessConv (TypeCode.Int64);\r
- default:\r
- throw new NotSupportedException ("Cannot handle opcode: " + inst.OpCode);\r
- }\r
- }\r
-\r
- private Expr ProcessBinaryOp (Code opcode)\r
- {\r
- Expr right = this.exprs.Pop ();\r
- Expr left = this.exprs.Pop ();\r
- switch (opcode) {\r
- case Code.Ceq:\r
- return this.gen.CompareEqual (left, right);\r
- case Code.Clt:\r
- return this.gen.CompareLessThan (left, right, Sn.Signed);\r
- case Code.Clt_Un:\r
- return this.gen.CompareLessThan (left, right, Sn.Unsigned);\r
- case Code.Cgt:\r
- return this.gen.CompareGreaterThan (left, right, Sn.Signed);\r
- case Code.Cgt_Un:\r
- return this.gen.CompareGreaterThan (left, right, Sn.Unsigned);\r
- case Code.Add:\r
- return this.gen.Add (left, right, Sn.None, false);\r
- case Code.Sub:\r
- return this.gen.Sub (left, right, Sn.None, false);\r
- default:\r
- throw new NotSupportedException ("Unknown binary opcode: " + opcode);\r
- }\r
- }\r
-\r
- private Expr ProcessCall (MethodReference method)\r
- {\r
- int paramCount = method.Parameters.Count;\r
- Expr [] parameterExprs = new Expr [paramCount];\r
- for (int i = 0; i < paramCount; i++) {\r
- Expr parameter = this.exprs.Pop ();\r
- parameterExprs [paramCount - i - 1] = parameter;\r
- }\r
- return this.gen.Call(method, parameterExprs);\r
- }\r
-\r
- private Expr ProcessConv (TypeCode convToType)\r
- {\r
- Expr exprToConvert = this.exprs.Pop ();\r
- return this.gen.Conv(exprToConvert, convToType);\r
- }\r
-\r
- }\r
-}\r
+//
+// Decompile.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.Ast;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+namespace Mono.CodeContracts.Rewrite {
+
+ class Decompile {
+
+ public Decompile (ModuleDefinition module, MethodDefinition method)
+ {
+ this.method = method;
+ this.exprs = new Stack<Expr> ();
+ this.Instructions = new Dictionary<Expr, Instruction> ();
+ this.methodInfo = new MethodInfo (module, method);
+ this.gen = new ExprGen (this.methodInfo);
+ }
+
+ private MethodInfo methodInfo;
+ private MethodDefinition method;
+ private Stack<Expr> exprs;
+ private ExprGen gen;
+
+ public Dictionary<Expr, Instruction> Instructions { get; private set; }
+
+ public Expr Go (bool failQuietly = true)
+ {
+ Instruction unknownInst = null;
+ var insts = this.method.Body.Instructions;
+ foreach (Instruction inst in insts) {
+ if (failQuietly) {
+ if (unknownInst == null) {
+ try {
+ Expr expr = this.ProcessInst (inst);
+ this.Instructions.Add (expr, inst);
+ this.exprs.Push (expr);
+ } catch (NotSupportedException) {
+ unknownInst = inst;
+ }
+ } else {
+ // Met unknown instruction, so check that there are no more contracts
+ if (inst.OpCode.OperandType == OperandType.InlineMethod) {
+ MethodReference method = (MethodReference) inst.Operand;
+ if (method.DeclaringType.FullName == "System.Diagnostics.Contracts.Contract") {
+ throw new NotSupportedException ("Unknown instruction in contract: " + unknownInst);
+ }
+ }
+ }
+ } else {
+ Expr expr = this.ProcessInst (inst);
+ this.Instructions.Add (expr, inst);
+ this.exprs.Push (expr);
+ }
+ }
+
+ Expr decompiled = new ExprBlock (this.methodInfo, this.exprs.Reverse ().ToArray ());
+ return decompiled;
+ }
+
+ private Expr ProcessInst (Instruction inst)
+ {
+ var opcode = inst.OpCode.Code;
+ switch (opcode) {
+ case Code.Nop:
+ return this.gen.Nop ();
+ case Code.Ldarg_0:
+ case Code.Ldarg_1:
+ case Code.Ldarg_2:
+ case Code.Ldarg_3:
+ return this.gen.LoadArg ((int) (opcode - Code.Ldarg_0));
+ case Code.Ldarg_S:
+ return this.gen.LoadArg ((ParameterDefinition) inst.Operand);
+ case Code.Ldnull:
+ return this.gen.LoadConstant (null);
+ case Code.Ldc_I4_M1:
+ case Code.Ldc_I4_0:
+ case Code.Ldc_I4_1:
+ case Code.Ldc_I4_2:
+ case Code.Ldc_I4_3:
+ case Code.Ldc_I4_4:
+ case Code.Ldc_I4_5:
+ case Code.Ldc_I4_6:
+ case Code.Ldc_I4_7:
+ case Code.Ldc_I4_8:
+ return this.gen.LoadConstant ((int) (opcode - Code.Ldc_I4_0));
+ case Code.Ldc_I4_S:
+ return this.gen.LoadConstant ((int) (sbyte) inst.Operand);
+ case Code.Ldc_I4:
+ return this.gen.LoadConstant ((int) inst.Operand);
+ case Code.Ldc_R4:
+ case Code.Ldc_R8:
+ case Code.Ldstr:
+ return this.gen.LoadConstant(inst.Operand);
+ case Code.Clt:
+ case Code.Clt_Un:
+ case Code.Cgt:
+ case Code.Cgt_Un:
+ case Code.Ceq:
+ case Code.Add:
+ case Code.Sub:
+ return this.ProcessBinaryOp (opcode);
+ case Code.Call:
+ return this.ProcessCall ((MethodReference) inst.Operand);
+ case Code.Ret:
+ return this.gen.Return ();
+ case Code.Conv_I4:
+ return this.ProcessConv (TypeCode.Int32);
+ case Code.Conv_I8:
+ return this.ProcessConv (TypeCode.Int64);
+ default:
+ throw new NotSupportedException ("Cannot handle opcode: " + inst.OpCode);
+ }
+ }
+
+ private Expr ProcessBinaryOp (Code opcode)
+ {
+ Expr right = this.exprs.Pop ();
+ Expr left = this.exprs.Pop ();
+ switch (opcode) {
+ case Code.Ceq:
+ return this.gen.CompareEqual (left, right);
+ case Code.Clt:
+ return this.gen.CompareLessThan (left, right, Sn.Signed);
+ case Code.Clt_Un:
+ return this.gen.CompareLessThan (left, right, Sn.Unsigned);
+ case Code.Cgt:
+ return this.gen.CompareGreaterThan (left, right, Sn.Signed);
+ case Code.Cgt_Un:
+ return this.gen.CompareGreaterThan (left, right, Sn.Unsigned);
+ case Code.Add:
+ return this.gen.Add (left, right, Sn.None, false);
+ case Code.Sub:
+ return this.gen.Sub (left, right, Sn.None, false);
+ default:
+ throw new NotSupportedException ("Unknown binary opcode: " + opcode);
+ }
+ }
+
+ private Expr ProcessCall (MethodReference method)
+ {
+ int paramCount = method.Parameters.Count;
+ Expr [] parameterExprs = new Expr [paramCount];
+ for (int i = 0; i < paramCount; i++) {
+ Expr parameter = this.exprs.Pop ();
+ parameterExprs [paramCount - i - 1] = parameter;
+ }
+ return this.gen.Call(method, parameterExprs);
+ }
+
+ private Expr ProcessConv (TypeCode convToType)
+ {
+ Expr exprToConvert = this.exprs.Pop ();
+ return this.gen.Conv(exprToConvert, convToType);
+ }
+
+ }
+}
-//\r
-// ExprGen.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class ExprGen {\r
-\r
- public ExprGen (MethodInfo methodInfo)\r
- {\r
- this.methodInfo = methodInfo;\r
- }\r
-\r
- private MethodInfo methodInfo;\r
-\r
- public ExprBlock Block (IEnumerable<Expr> exprs)\r
- {\r
- return new ExprBlock (this.methodInfo, exprs);\r
- }\r
-\r
- public ExprReturn Return ()\r
- {\r
- return new ExprReturn (this.methodInfo);\r
- }\r
-\r
- public ExprBox Box (Expr exprToBox)\r
- {\r
- return new ExprBox (this.methodInfo, exprToBox);\r
- }\r
-\r
- public ExprNop Nop ()\r
- {\r
- return new ExprNop (this.methodInfo);\r
- }\r
-\r
- public ExprLoadArg LoadArg (int index)\r
- {\r
- return new ExprLoadArg (this.methodInfo, index);\r
- }\r
-\r
- public ExprLoadArg LoadArg (ParameterDefinition parameterDefinition)\r
- {\r
- return this.LoadArg (parameterDefinition.Sequence);\r
- }\r
-\r
- public ExprLoadConstant LoadConstant (object value)\r
- {\r
- return new ExprLoadConstant (this.methodInfo, value);\r
- }\r
-\r
- public ExprCall Call (MethodReference method, IEnumerable<Expr> parameters)\r
- {\r
- return new ExprCall (this.methodInfo, method, parameters);\r
- }\r
-\r
- public ExprCompareEqual CompareEqual (Expr left, Expr right)\r
- {\r
- return new ExprCompareEqual (this.methodInfo, left, right);\r
- }\r
-\r
- public ExprCompareLessThan CompareLessThan (Expr left, Expr right, Sn signage)\r
- {\r
- return new ExprCompareLessThan (this.methodInfo, left, right, signage);\r
- }\r
-\r
- public ExprCompareGreaterThan CompareGreaterThan (Expr left, Expr right, Sn signage)\r
- {\r
- return new ExprCompareGreaterThan (this.methodInfo, left, right, signage);\r
- }\r
-\r
- public ExprConv Conv (Expr exprToConvert, TypeCode convToType)\r
- {\r
- return new ExprConv (this.methodInfo, exprToConvert, convToType);\r
- }\r
-\r
- public ExprAdd Add (Expr left, Expr right, Sn signage, bool overflow)\r
- {\r
- return new ExprAdd (this.methodInfo, left, right, signage, overflow);\r
- }\r
-\r
- public ExprSub Sub (Expr left, Expr right, Sn signage, bool overflow)\r
- {\r
- return new ExprSub (this.methodInfo, left, right, signage, overflow);\r
- }\r
-\r
- }\r
-}\r
+//
+// ExprGen.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite.Ast;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite {
+ class ExprGen {
+
+ public ExprGen (MethodInfo methodInfo)
+ {
+ this.methodInfo = methodInfo;
+ }
+
+ private MethodInfo methodInfo;
+
+ public ExprBlock Block (IEnumerable<Expr> exprs)
+ {
+ return new ExprBlock (this.methodInfo, exprs);
+ }
+
+ public ExprReturn Return ()
+ {
+ return new ExprReturn (this.methodInfo);
+ }
+
+ public ExprBox Box (Expr exprToBox)
+ {
+ return new ExprBox (this.methodInfo, exprToBox);
+ }
+
+ public ExprNop Nop ()
+ {
+ return new ExprNop (this.methodInfo);
+ }
+
+ public ExprLoadArg LoadArg (int index)
+ {
+ return new ExprLoadArg (this.methodInfo, index);
+ }
+
+ public ExprLoadArg LoadArg (ParameterDefinition parameterDefinition)
+ {
+ return this.LoadArg (parameterDefinition.Sequence);
+ }
+
+ public ExprLoadConstant LoadConstant (object value)
+ {
+ return new ExprLoadConstant (this.methodInfo, value);
+ }
+
+ public ExprCall Call (MethodReference method, IEnumerable<Expr> parameters)
+ {
+ return new ExprCall (this.methodInfo, method, parameters);
+ }
+
+ public ExprCompareEqual CompareEqual (Expr left, Expr right)
+ {
+ return new ExprCompareEqual (this.methodInfo, left, right);
+ }
+
+ public ExprCompareLessThan CompareLessThan (Expr left, Expr right, Sn signage)
+ {
+ return new ExprCompareLessThan (this.methodInfo, left, right, signage);
+ }
+
+ public ExprCompareGreaterThan CompareGreaterThan (Expr left, Expr right, Sn signage)
+ {
+ return new ExprCompareGreaterThan (this.methodInfo, left, right, signage);
+ }
+
+ public ExprConv Conv (Expr exprToConvert, TypeCode convToType)
+ {
+ return new ExprConv (this.methodInfo, exprToConvert, convToType);
+ }
+
+ public ExprAdd Add (Expr left, Expr right, Sn signage, bool overflow)
+ {
+ return new ExprAdd (this.methodInfo, left, right, signage, overflow);
+ }
+
+ public ExprSub Sub (Expr left, Expr right, Sn signage, bool overflow)
+ {
+ return new ExprSub (this.methodInfo, left, right, signage, overflow);
+ }
+
+ }
+}
-//\r
-// MethodInfo.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class MethodInfo {\r
-\r
- public MethodInfo (ModuleDefinition module, MethodDefinition method)\r
- {\r
- this.Method = method;\r
- this.Module = module;\r
-\r
- this.typeVoid = new Lazy<TypeReference> (() => this.Module.Import (typeof (void)));\r
- this.typeObject = new Lazy<TypeReference> (() => this.Module.Import (typeof (object)));\r
- this.typeInt32 = new Lazy<TypeReference> (() => this.Module.Import (typeof (int)));\r
- this.typeInt64 = new Lazy<TypeReference> (() => this.Module.Import (typeof (long)));\r
- this.typeUInt32 = new Lazy<TypeReference> (() => this.Module.Import (typeof (uint)));\r
- this.typeBoolean = new Lazy<TypeReference> (() => this.Module.Import (typeof (bool)));\r
- this.typeString = new Lazy<TypeReference> (() => this.Module.Import (typeof (string)));\r
- }\r
-\r
- public MethodDefinition Method { get; private set; }\r
- public ModuleDefinition Module { get; private set; }\r
-\r
- private Lazy<TypeReference> typeVoid;\r
- private Lazy<TypeReference> typeObject;\r
- private Lazy<TypeReference> typeInt32;\r
- private Lazy<TypeReference> typeInt64;\r
- private Lazy<TypeReference> typeUInt32;\r
- private Lazy<TypeReference> typeBoolean;\r
- private Lazy<TypeReference> typeString;\r
-\r
- public TypeReference TypeVoid {\r
- get { return this.typeVoid.Value; }\r
- }\r
-\r
- public TypeReference TypeObject {\r
- get { return this.typeObject.Value; }\r
- }\r
-\r
- public TypeReference TypeInt32 {\r
- get { return this.typeInt32.Value; }\r
- }\r
-\r
- public TypeReference TypeInt64 {\r
- get { return this.typeInt64.Value; }\r
- }\r
-\r
- public TypeReference TypeUInt32 {\r
- get { return this.typeUInt32.Value; }\r
- }\r
-\r
- public TypeReference TypeBoolean {\r
- get { return this.typeBoolean.Value; }\r
- }\r
-\r
- public TypeReference TypeString {\r
- get { return this.typeString.Value; }\r
- }\r
-\r
- }\r
-}\r
+//
+// MethodInfo.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+
+namespace Mono.CodeContracts.Rewrite {
+ class MethodInfo {
+
+ public MethodInfo (ModuleDefinition module, MethodDefinition method)
+ {
+ this.Method = method;
+ this.Module = module;
+
+ this.typeVoid = new Lazy<TypeReference> (() => this.Module.Import (typeof (void)));
+ this.typeObject = new Lazy<TypeReference> (() => this.Module.Import (typeof (object)));
+ this.typeInt32 = new Lazy<TypeReference> (() => this.Module.Import (typeof (int)));
+ this.typeInt64 = new Lazy<TypeReference> (() => this.Module.Import (typeof (long)));
+ this.typeUInt32 = new Lazy<TypeReference> (() => this.Module.Import (typeof (uint)));
+ this.typeBoolean = new Lazy<TypeReference> (() => this.Module.Import (typeof (bool)));
+ this.typeString = new Lazy<TypeReference> (() => this.Module.Import (typeof (string)));
+ }
+
+ public MethodDefinition Method { get; private set; }
+ public ModuleDefinition Module { get; private set; }
+
+ private Lazy<TypeReference> typeVoid;
+ private Lazy<TypeReference> typeObject;
+ private Lazy<TypeReference> typeInt32;
+ private Lazy<TypeReference> typeInt64;
+ private Lazy<TypeReference> typeUInt32;
+ private Lazy<TypeReference> typeBoolean;
+ private Lazy<TypeReference> typeString;
+
+ public TypeReference TypeVoid {
+ get { return this.typeVoid.Value; }
+ }
+
+ public TypeReference TypeObject {
+ get { return this.typeObject.Value; }
+ }
+
+ public TypeReference TypeInt32 {
+ get { return this.typeInt32.Value; }
+ }
+
+ public TypeReference TypeInt64 {
+ get { return this.typeInt64.Value; }
+ }
+
+ public TypeReference TypeUInt32 {
+ get { return this.typeUInt32.Value; }
+ }
+
+ public TypeReference TypeBoolean {
+ get { return this.typeBoolean.Value; }
+ }
+
+ public TypeReference TypeString {
+ get { return this.typeString.Value; }
+ }
+
+ }
+}
-//\r
-// PerformRewrite.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil;\r
-using Mono.Cecil.Cil;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-using Mono.CodeContracts.Rewrite.AstVisitors;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class PerformRewrite {\r
-\r
- public PerformRewrite (ISymbolWriter sym, RewriterOptions options)\r
- {\r
- this.sym = sym;\r
- this.options = options;\r
- }\r
-\r
- private ISymbolWriter sym;\r
- private RewriterOptions options;\r
- private Dictionary<MethodDefinition, TransformContractsVisitor> rewrittenMethods = new Dictionary<MethodDefinition, TransformContractsVisitor> ();\r
-\r
- public void Rewrite (AssemblyDefinition assembly)\r
- {\r
- foreach (ModuleDefinition module in assembly.Modules) {\r
- ContractsRuntime contractsRuntime = new ContractsRuntime(module, this.options);\r
-\r
- var allMethods =\r
- from type in module.Types.Cast<TypeDefinition> ()\r
- from method in type.Methods.Cast<MethodDefinition> ()\r
- select method;\r
-\r
- foreach (MethodDefinition method in allMethods.ToArray ()) {\r
- this.RewriteMethod (module, method, contractsRuntime);\r
- }\r
- }\r
- }\r
-\r
- private void RewriteMethod (ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)\r
- {\r
- if (this.rewrittenMethods.ContainsKey (method)) {\r
- return;\r
- }\r
- var overridden = this.GetOverriddenMethod (method);\r
- if (overridden != null) {\r
- this.RewriteMethod (module, overridden, contractsRuntime);\r
- }\r
- bool anyRewrites = false;\r
- var baseMethod = this.GetBaseOverriddenMethod (method);\r
- if (baseMethod != method) {\r
- // Contract inheritance must be used\r
- var vOverriddenTransform = this.rewrittenMethods [baseMethod];\r
- // Can be null if overriding an abstract method\r
- if (vOverriddenTransform != null) {\r
- if (this.options.Level >= 2) {\r
- // Only insert re-written contracts if level >= 2\r
- foreach (var inheritedRequires in vOverriddenTransform.ContractRequiresInfo) {\r
- this.RewriteIL (method.Body, null, null, inheritedRequires.RewrittenExpr);\r
- anyRewrites = true;\r
- }\r
- }\r
- }\r
- }\r
-\r
- TransformContractsVisitor vTransform = null;\r
- if (method.HasBody) {\r
- vTransform = this.TransformContracts (module, method, contractsRuntime);\r
- if (this.sym != null) {\r
- this.sym.Write (method.Body);\r
- }\r
- if (vTransform.ContractRequiresInfo.Any ()) {\r
- anyRewrites = true;\r
- }\r
- }\r
- this.rewrittenMethods.Add (method, vTransform);\r
-\r
- if (anyRewrites) {\r
- Console.WriteLine (method);\r
- }\r
- }\r
-\r
- private TransformContractsVisitor TransformContracts (ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)\r
- {\r
- var body = method.Body;\r
- Decompile decompile = new Decompile (module, method);\r
- var decomp = decompile.Go ();\r
-\r
- TransformContractsVisitor vTransform = new TransformContractsVisitor (module, method, decompile.Instructions, contractsRuntime);\r
- vTransform.Visit (decomp);\r
-\r
- foreach (var replacement in vTransform.ContractRequiresInfo) {\r
- // Only insert re-written contracts if level >= 2\r
- Expr rewritten = this.options.Level >= 2 ? replacement.RewrittenExpr : null;\r
- this.RewriteIL (body, decompile.Instructions, replacement.OriginalExpr, rewritten);\r
- }\r
-\r
- return vTransform;\r
- }\r
-\r
- private void RewriteIL (MethodBody body, Dictionary<Expr,Instruction> instructionLookup, Expr remove, Expr insert)\r
- {\r
- var il = body.CilWorker;\r
- Instruction instInsertBefore;\r
- if (remove != null) {\r
- var vInstExtent = new InstructionExtentVisitor (instructionLookup);\r
- vInstExtent.Visit (remove);\r
- instInsertBefore = vInstExtent.Instructions.Last ().Next;\r
- foreach (var instRemove in vInstExtent.Instructions) {\r
- il.Remove (instRemove);\r
- }\r
- } else {\r
- instInsertBefore = body.Instructions [0];\r
- }\r
- if (insert != null) {\r
- var compiler = new CompileVisitor (il, instructionLookup, inst => il.InsertBefore (instInsertBefore, inst));\r
- compiler.Visit (insert);\r
- }\r
- }\r
-\r
- private MethodDefinition GetOverriddenMethod (MethodDefinition method)\r
- {\r
- if (method.IsNewSlot || !method.IsVirtual) {\r
- return null;\r
- }\r
- var baseType = method.DeclaringType.BaseType;\r
- if (baseType == null) {\r
- return null;\r
- }\r
- var overridden = baseType.Resolve ().Methods.Cast<MethodDefinition> ().FirstOrDefault (x => x.Name == method.Name);\r
- return overridden;\r
- }\r
-\r
- private MethodDefinition GetBaseOverriddenMethod (MethodDefinition method)\r
- {\r
- var overridden = method;\r
- while (true) {\r
- var overriddenTemp = this.GetOverriddenMethod (overridden);\r
- if (overriddenTemp == null) {\r
- return overridden;\r
- }\r
- overridden = overriddenTemp;\r
- }\r
- }\r
-\r
- }\r
-}\r
+//
+// PerformRewrite.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Mono.CodeContracts.Rewrite.Ast;
+using Mono.CodeContracts.Rewrite.AstVisitors;
+
+namespace Mono.CodeContracts.Rewrite {
+ class PerformRewrite {
+
+ public PerformRewrite (ISymbolWriter sym, RewriterOptions options)
+ {
+ this.sym = sym;
+ this.options = options;
+ }
+
+ private ISymbolWriter sym;
+ private RewriterOptions options;
+ private Dictionary<MethodDefinition, TransformContractsVisitor> rewrittenMethods = new Dictionary<MethodDefinition, TransformContractsVisitor> ();
+
+ public void Rewrite (AssemblyDefinition assembly)
+ {
+ foreach (ModuleDefinition module in assembly.Modules) {
+ ContractsRuntime contractsRuntime = new ContractsRuntime(module, this.options);
+
+ var allMethods =
+ from type in module.Types.Cast<TypeDefinition> ()
+ from method in type.Methods.Cast<MethodDefinition> ()
+ select method;
+
+ foreach (MethodDefinition method in allMethods.ToArray ()) {
+ this.RewriteMethod (module, method, contractsRuntime);
+ }
+ }
+ }
+
+ private void RewriteMethod (ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)
+ {
+ if (this.rewrittenMethods.ContainsKey (method)) {
+ return;
+ }
+ var overridden = this.GetOverriddenMethod (method);
+ if (overridden != null) {
+ this.RewriteMethod (module, overridden, contractsRuntime);
+ }
+ bool anyRewrites = false;
+ var baseMethod = this.GetBaseOverriddenMethod (method);
+ if (baseMethod != method) {
+ // Contract inheritance must be used
+ var vOverriddenTransform = this.rewrittenMethods [baseMethod];
+ // Can be null if overriding an abstract method
+ if (vOverriddenTransform != null) {
+ if (this.options.Level >= 2) {
+ // Only insert re-written contracts if level >= 2
+ foreach (var inheritedRequires in vOverriddenTransform.ContractRequiresInfo) {
+ this.RewriteIL (method.Body, null, null, inheritedRequires.RewrittenExpr);
+ anyRewrites = true;
+ }
+ }
+ }
+ }
+
+ TransformContractsVisitor vTransform = null;
+ if (method.HasBody) {
+ vTransform = this.TransformContracts (module, method, contractsRuntime);
+ if (this.sym != null) {
+ this.sym.Write (method.Body);
+ }
+ if (vTransform.ContractRequiresInfo.Any ()) {
+ anyRewrites = true;
+ }
+ }
+ this.rewrittenMethods.Add (method, vTransform);
+
+ if (anyRewrites) {
+ Console.WriteLine (method);
+ }
+ }
+
+ private TransformContractsVisitor TransformContracts (ModuleDefinition module, MethodDefinition method, ContractsRuntime contractsRuntime)
+ {
+ var body = method.Body;
+ Decompile decompile = new Decompile (module, method);
+ var decomp = decompile.Go ();
+
+ TransformContractsVisitor vTransform = new TransformContractsVisitor (module, method, decompile.Instructions, contractsRuntime);
+ vTransform.Visit (decomp);
+
+ foreach (var replacement in vTransform.ContractRequiresInfo) {
+ // Only insert re-written contracts if level >= 2
+ Expr rewritten = this.options.Level >= 2 ? replacement.RewrittenExpr : null;
+ this.RewriteIL (body, decompile.Instructions, replacement.OriginalExpr, rewritten);
+ }
+
+ return vTransform;
+ }
+
+ private void RewriteIL (MethodBody body, Dictionary<Expr,Instruction> instructionLookup, Expr remove, Expr insert)
+ {
+ var il = body.CilWorker;
+ Instruction instInsertBefore;
+ if (remove != null) {
+ var vInstExtent = new InstructionExtentVisitor (instructionLookup);
+ vInstExtent.Visit (remove);
+ instInsertBefore = vInstExtent.Instructions.Last ().Next;
+ foreach (var instRemove in vInstExtent.Instructions) {
+ il.Remove (instRemove);
+ }
+ } else {
+ instInsertBefore = body.Instructions [0];
+ }
+ if (insert != null) {
+ var compiler = new CompileVisitor (il, instructionLookup, inst => il.InsertBefore (instInsertBefore, inst));
+ compiler.Visit (insert);
+ }
+ }
+
+ private MethodDefinition GetOverriddenMethod (MethodDefinition method)
+ {
+ if (method.IsNewSlot || !method.IsVirtual) {
+ return null;
+ }
+ var baseType = method.DeclaringType.BaseType;
+ if (baseType == null) {
+ return null;
+ }
+ var overridden = baseType.Resolve ().Methods.Cast<MethodDefinition> ().FirstOrDefault (x => x.Name == method.Name);
+ return overridden;
+ }
+
+ private MethodDefinition GetBaseOverriddenMethod (MethodDefinition method)
+ {
+ var overridden = method;
+ while (true) {
+ var overriddenTemp = this.GetOverriddenMethod (overridden);
+ if (overriddenTemp == null) {
+ return overridden;
+ }
+ overridden = overriddenTemp;
+ }
+ }
+
+ }
+}
-//\r
-// Rewriter.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.Cecil.Cil;\r
-using Mono.Cecil;\r
-using System.IO;\r
-using Mono.CompilerServices.SymbolWriter;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- public class Rewriter {\r
-\r
- public static RewriterResults Rewrite (RewriterOptions options)\r
- {\r
- Rewriter rewriter = new Rewriter(options);\r
- return rewriter.RewriteImpl();\r
- }\r
- \r
- private Rewriter(RewriterOptions options)\r
- {\r
- this.options = options;\r
- }\r
- \r
- private RewriterOptions options;\r
- private List<string> warnings = new List<string> ();\r
- private List<string> errors = new List<string> ();\r
- private bool usingMdb = false;\r
- private bool usingPdb = false;\r
- \r
- private void LoadSymbolReader (AssemblyDefinition assembly) {\r
- if (this.options.Assembly.IsStream && this.options.Assembly.Streams.Symbols == null) {\r
- this.warnings.Add ("-debug specified, but no symbol stream provided.");\r
- } else {\r
- try {\r
- foreach (ModuleDefinition module in assembly.Modules) {\r
- module.LoadSymbols ();\r
- }\r
- this.usingMdb = true;\r
- } catch {\r
- }\r
- if (!this.usingMdb && !this.usingPdb) {\r
- this.warnings.Add ("-debug specified, but no MDB or PDB symbol file found.");\r
- }\r
- }\r
- }\r
- \r
- private ISymbolWriter LoadSymbolWriter(AssemblyDefinition assembly, AssemblyRef output)\r
- {\r
- // TODO: Get symbol writing to work.\r
-// ISymbolWriterProvider symProv = null;\r
-// if (this.usingMdb) {\r
-// symProv = new Mono.Cecil.Mdb.MdbWriterProvider ();\r
-// } else if (this.usingPdb) {\r
-// symProv = new Mono.Cecil.Pdb.PdbWriterProvider ();\r
-// } else {\r
-// this.warnings.Add ("-writePDBFile specified, but no symbol file found, cannot write symbols.");\r
-// }\r
-// if (symProv != null) {\r
-// return output.IsFilename ?\r
-// symProv.GetSymbolWriter (assembly.MainModule, output.Filename) :\r
-// symProv.GetSymbolWriter (assembly.MainModule, output.Streams.Symbols);\r
-// }\r
- return null;\r
- }\r
-\r
-\r
- private RewriterResults RewriteImpl ()\r
- {\r
- if (!this.options.Rewrite) {\r
- return RewriterResults.Warning ("Not asked to rewrite");\r
- }\r
-\r
- if (!this.options.Assembly.IsSet) {\r
- return RewriterResults.Error ("No assembly given to rewrite");\r
- }\r
- AssemblyDefinition assembly = this.options.Assembly.IsFilename ?\r
- AssemblyFactory.GetAssembly (this.options.Assembly.Filename) :\r
- AssemblyFactory.GetAssembly (this.options.Assembly.Streams.Assembly);\r
- \r
- if (this.options.ForceAssemblyRename != null) {\r
- assembly.Name.Name = this.options.ForceAssemblyRename;\r
- } else if (this.options.OutputFile.IsSet && this.options.OutputFile.IsFilename) {\r
- assembly.Name.Name = Path.GetFileNameWithoutExtension(this.options.OutputFile.Filename);\r
- }\r
-\r
- if (options.Debug) {\r
- this.LoadSymbolReader (assembly);\r
- }\r
-\r
- var output = this.options.OutputFile.IsSet ? this.options.OutputFile : this.options.Assembly;\r
- ISymbolWriter symWriter = null;\r
- if (options.WritePdbFile) {\r
- if (!options.Debug) {\r
- return RewriterResults.Error ("Must specify -debug if using -writePDBFile.");\r
- }\r
- if (output.IsStream && output.Streams.Symbols==null){\r
- return RewriterResults.Error ("-writePDFFile specified, but no output symbol stream provided.");\r
- }\r
- symWriter = this.LoadSymbolWriter (assembly, output);\r
- }\r
- \r
- try {\r
- PerformRewrite rewriter = new PerformRewrite (symWriter, this.options);\r
- rewriter.Rewrite (assembly);\r
-\r
- if (output.IsFilename) {\r
- AssemblyFactory.SaveAssembly(assembly, output.Filename);\r
- } else {\r
- AssemblyFactory.SaveAssembly(assembly, output.Streams.Assembly);\r
- }\r
- } finally {\r
- if (symWriter != null) {\r
- symWriter.Dispose ();\r
- }\r
- }\r
-\r
- return new RewriterResults (warnings, errors);\r
- }\r
- \r
- }\r
-}\r
+//
+// Rewriter.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.Cecil.Cil;
+using Mono.Cecil;
+using System.IO;
+using Mono.CompilerServices.SymbolWriter;
+
+namespace Mono.CodeContracts.Rewrite {
+ public class Rewriter {
+
+ public static RewriterResults Rewrite (RewriterOptions options)
+ {
+ Rewriter rewriter = new Rewriter(options);
+ return rewriter.RewriteImpl();
+ }
+
+ private Rewriter(RewriterOptions options)
+ {
+ this.options = options;
+ }
+
+ private RewriterOptions options;
+ private List<string> warnings = new List<string> ();
+ private List<string> errors = new List<string> ();
+ private bool usingMdb = false;
+ private bool usingPdb = false;
+
+ private void LoadSymbolReader (AssemblyDefinition assembly) {
+ if (this.options.Assembly.IsStream && this.options.Assembly.Streams.Symbols == null) {
+ this.warnings.Add ("-debug specified, but no symbol stream provided.");
+ } else {
+ try {
+ foreach (ModuleDefinition module in assembly.Modules) {
+ module.LoadSymbols ();
+ }
+ this.usingMdb = true;
+ } catch {
+ }
+ if (!this.usingMdb && !this.usingPdb) {
+ this.warnings.Add ("-debug specified, but no MDB or PDB symbol file found.");
+ }
+ }
+ }
+
+ private ISymbolWriter LoadSymbolWriter(AssemblyDefinition assembly, AssemblyRef output)
+ {
+ // TODO: Get symbol writing to work.
+// ISymbolWriterProvider symProv = null;
+// if (this.usingMdb) {
+// symProv = new Mono.Cecil.Mdb.MdbWriterProvider ();
+// } else if (this.usingPdb) {
+// symProv = new Mono.Cecil.Pdb.PdbWriterProvider ();
+// } else {
+// this.warnings.Add ("-writePDBFile specified, but no symbol file found, cannot write symbols.");
+// }
+// if (symProv != null) {
+// return output.IsFilename ?
+// symProv.GetSymbolWriter (assembly.MainModule, output.Filename) :
+// symProv.GetSymbolWriter (assembly.MainModule, output.Streams.Symbols);
+// }
+ return null;
+ }
+
+
+ private RewriterResults RewriteImpl ()
+ {
+ if (!this.options.Rewrite) {
+ return RewriterResults.Warning ("Not asked to rewrite");
+ }
+
+ if (!this.options.Assembly.IsSet) {
+ return RewriterResults.Error ("No assembly given to rewrite");
+ }
+ AssemblyDefinition assembly = this.options.Assembly.IsFilename ?
+ AssemblyFactory.GetAssembly (this.options.Assembly.Filename) :
+ AssemblyFactory.GetAssembly (this.options.Assembly.Streams.Assembly);
+
+ if (this.options.ForceAssemblyRename != null) {
+ assembly.Name.Name = this.options.ForceAssemblyRename;
+ } else if (this.options.OutputFile.IsSet && this.options.OutputFile.IsFilename) {
+ assembly.Name.Name = Path.GetFileNameWithoutExtension(this.options.OutputFile.Filename);
+ }
+
+ if (options.Debug) {
+ this.LoadSymbolReader (assembly);
+ }
+
+ var output = this.options.OutputFile.IsSet ? this.options.OutputFile : this.options.Assembly;
+ ISymbolWriter symWriter = null;
+ if (options.WritePdbFile) {
+ if (!options.Debug) {
+ return RewriterResults.Error ("Must specify -debug if using -writePDBFile.");
+ }
+ if (output.IsStream && output.Streams.Symbols==null){
+ return RewriterResults.Error ("-writePDFFile specified, but no output symbol stream provided.");
+ }
+ symWriter = this.LoadSymbolWriter (assembly, output);
+ }
+
+ try {
+ PerformRewrite rewriter = new PerformRewrite (symWriter, this.options);
+ rewriter.Rewrite (assembly);
+
+ if (output.IsFilename) {
+ AssemblyFactory.SaveAssembly(assembly, output.Filename);
+ } else {
+ AssemblyFactory.SaveAssembly(assembly, output.Streams.Assembly);
+ }
+ } finally {
+ if (symWriter != null) {
+ symWriter.Dispose ();
+ }
+ }
+
+ return new RewriterResults (warnings, errors);
+ }
+
+ }
+}
-//\r
-// RewriterOptions.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- public class RewriterOptions {\r
-\r
- public RewriterOptions ()\r
- {\r
- // Initialise to defaults\r
- this.Debug = true;\r
- this.Level = 4;\r
- this.WritePdbFile = true;\r
- this.Rewrite = true;\r
- this.BreakIntoDebugger = false;\r
- this.ThrowOnFailure = false;\r
- \r
- this.ForceAssemblyRename = null;\r
- }\r
-\r
- public AssemblyRef Assembly { get; set; }\r
- public bool Debug { get; set; }\r
- public int Level { get; set; }\r
- public bool WritePdbFile { get; set; }\r
- public bool Rewrite { get; set; }\r
- public bool BreakIntoDebugger { get; set; }\r
- public bool ThrowOnFailure { get; set; }\r
- public AssemblyRef OutputFile { get; set; }\r
- \r
- public string ForceAssemblyRename { get; set; }\r
-\r
- }\r
-}\r
+//
+// RewriterOptions.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite {
+ public class RewriterOptions {
+
+ public RewriterOptions ()
+ {
+ // Initialise to defaults
+ this.Debug = true;
+ this.Level = 4;
+ this.WritePdbFile = true;
+ this.Rewrite = true;
+ this.BreakIntoDebugger = false;
+ this.ThrowOnFailure = false;
+
+ this.ForceAssemblyRename = null;
+ }
+
+ public AssemblyRef Assembly { get; set; }
+ public bool Debug { get; set; }
+ public int Level { get; set; }
+ public bool WritePdbFile { get; set; }
+ public bool Rewrite { get; set; }
+ public bool BreakIntoDebugger { get; set; }
+ public bool ThrowOnFailure { get; set; }
+ public AssemblyRef OutputFile { get; set; }
+
+ public string ForceAssemblyRename { get; set; }
+
+ }
+}
-//\r
-// RewriterResults.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
-\r
- public class RewriterResults {\r
-\r
- internal static RewriterResults Warning (string warning)\r
- {\r
- return new RewriterResults (new [] { warning }, null);\r
- }\r
-\r
- internal static RewriterResults Error (string error)\r
- {\r
- return new RewriterResults (null, new [] { error });\r
- }\r
-\r
- internal RewriterResults (ICollection<string> warnings, ICollection<string> errors)\r
- {\r
- this.warnings = warnings;\r
- this.errors = errors;\r
- }\r
-\r
- private ICollection<string> warnings, errors;\r
-\r
- public bool AnyWarnings {\r
- get {\r
- return this.warnings != null && this.warnings.Count > 0;\r
- }\r
- }\r
-\r
- public bool AnyErrors {\r
- get {\r
- return this.errors != null && this.errors.Count > 0;\r
- }\r
- }\r
-\r
- public IEnumerable<string> Warnings {\r
- get {\r
- return this.warnings ?? Enumerable.Empty<string> ();\r
- }\r
- }\r
-\r
- public IEnumerable<string> Errors {\r
- get {\r
- return this.errors ?? Enumerable.Empty<string> ();\r
- }\r
- }\r
-\r
- }\r
-\r
-}\r
+//
+// RewriterResults.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+
+namespace Mono.CodeContracts.Rewrite {
+
+ public class RewriterResults {
+
+ internal static RewriterResults Warning (string warning)
+ {
+ return new RewriterResults (new [] { warning }, null);
+ }
+
+ internal static RewriterResults Error (string error)
+ {
+ return new RewriterResults (null, new [] { error });
+ }
+
+ internal RewriterResults (ICollection<string> warnings, ICollection<string> errors)
+ {
+ this.warnings = warnings;
+ this.errors = errors;
+ }
+
+ private ICollection<string> warnings, errors;
+
+ public bool AnyWarnings {
+ get {
+ return this.warnings != null && this.warnings.Count > 0;
+ }
+ }
+
+ public bool AnyErrors {
+ get {
+ return this.errors != null && this.errors.Count > 0;
+ }
+ }
+
+ public IEnumerable<string> Warnings {
+ get {
+ return this.warnings ?? Enumerable.Empty<string> ();
+ }
+ }
+
+ public IEnumerable<string> Errors {
+ get {
+ return this.errors ?? Enumerable.Empty<string> ();
+ }
+ }
+
+ }
+
+}
-//\r
-// TransformContractsVisitor.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using Mono.CodeContracts.Rewrite;\r
-using Mono.CodeContracts.Rewrite.Ast;\r
-using System.Diagnostics.Contracts;\r
-using Mono.Cecil;\r
-using Mono.CodeContracts.Rewrite.AstVisitors;\r
-using Mono.Cecil.Cil;\r
-\r
-namespace Mono.CodeContracts.Rewrite {\r
- class TransformContractsVisitor : ExprVisitor {\r
-\r
- public TransformContractsVisitor (ModuleDefinition module, MethodDefinition method, Dictionary<Expr, Instruction> instructionLookup, ContractsRuntime contractsRuntime)\r
- {\r
- //this.module = method.Module;\r
- this.instructionLookup = instructionLookup;\r
- this.contractsRuntime = contractsRuntime;\r
- this.methodInfo = new MethodInfo (module, method);\r
- }\r
-\r
- //private ModuleDefinition module;\r
- private Dictionary<Expr, Instruction> instructionLookup;\r
- private ContractsRuntime contractsRuntime;\r
- private MethodInfo methodInfo;\r
-\r
- private List<ContractRequiresInfo> contractRequiresInfo = new List<ContractRequiresInfo> ();\r
-\r
- public IEnumerable<ContractRequiresInfo> ContractRequiresInfo {\r
- get { return this.contractRequiresInfo; }\r
- }\r
-\r
- protected override Expr VisitCall (ExprCall e)\r
- {\r
- var call = (ExprCall)base.VisitCall (e);\r
-\r
- var method = e.Method;\r
- if (method.DeclaringType.FullName == "System.Diagnostics.Contracts.Contract") {\r
- switch (method.Name) {\r
- case "Requires":\r
- if (!method.HasGenericParameters) {\r
- switch (method.Parameters.Count) {\r
- case 1:\r
- return this.ProcessRequires1 (call);\r
- case 2:\r
- return this.ProcessRequires2 (call);\r
- default:\r
- throw new NotSupportedException ("Invalid number of parameters to Contract.Requires()");\r
- }\r
- } else {\r
- goto default;\r
- }\r
- default:\r
- throw new NotSupportedException ("Cannot handle Contract." + e.Method.Name + "()");\r
- }\r
- }\r
-\r
- return call;\r
- }\r
-\r
- private string GetConditionString (Expr e)\r
- {\r
- var vSource = new SourcePositionVisitor (this.instructionLookup);\r
- vSource.Visit (e);\r
- var extractor = new ConditionTextExtractor (vSource.SourceCodeFileName, vSource.StartPosition, vSource.EndPosition);\r
- return extractor.GetConditionText ();\r
- }\r
-\r
- private Expr ProcessRequires1 (ExprCall e)\r
- {\r
- MethodDefinition mRequires = this.contractsRuntime.GetRequires ();\r
- Expr conditionExpr = e.Parameters.First ();\r
- Expr nullArgExpr = new ExprLoadConstant (this.methodInfo, null);\r
- string conditionText = this.GetConditionString (e);\r
- Expr conditionStringExpr = new ExprLoadConstant (this.methodInfo, conditionText);\r
- var call = new ExprCall (this.methodInfo, mRequires, new Expr [] { conditionExpr, nullArgExpr, conditionStringExpr });\r
-\r
- this.contractRequiresInfo.Add (new ContractRequiresInfo (e, call));\r
-\r
- return call;\r
- }\r
-\r
- private Expr ProcessRequires2 (ExprCall e)\r
- {\r
- MethodDefinition mRequires = this.contractsRuntime.GetRequires ();\r
- Expr conditionExpr = e.Parameters.First ();\r
- Expr msgExpr = e.Parameters.ElementAt (1);\r
- string conditionText = this.GetConditionString (e);\r
- Expr conditionStringExpr = new ExprLoadConstant (this.methodInfo, conditionText);\r
- var call = new ExprCall (this.methodInfo, mRequires, new Expr [] { conditionExpr, msgExpr, conditionStringExpr });\r
-\r
- this.contractRequiresInfo.Add (new ContractRequiresInfo (e, call));\r
-\r
- return call;\r
- }\r
-\r
- }\r
-}\r
+//
+// TransformContractsVisitor.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using Mono.CodeContracts.Rewrite;
+using Mono.CodeContracts.Rewrite.Ast;
+using System.Diagnostics.Contracts;
+using Mono.Cecil;
+using Mono.CodeContracts.Rewrite.AstVisitors;
+using Mono.Cecil.Cil;
+
+namespace Mono.CodeContracts.Rewrite {
+ class TransformContractsVisitor : ExprVisitor {
+
+ public TransformContractsVisitor (ModuleDefinition module, MethodDefinition method, Dictionary<Expr, Instruction> instructionLookup, ContractsRuntime contractsRuntime)
+ {
+ //this.module = method.Module;
+ this.instructionLookup = instructionLookup;
+ this.contractsRuntime = contractsRuntime;
+ this.methodInfo = new MethodInfo (module, method);
+ }
+
+ //private ModuleDefinition module;
+ private Dictionary<Expr, Instruction> instructionLookup;
+ private ContractsRuntime contractsRuntime;
+ private MethodInfo methodInfo;
+
+ private List<ContractRequiresInfo> contractRequiresInfo = new List<ContractRequiresInfo> ();
+
+ public IEnumerable<ContractRequiresInfo> ContractRequiresInfo {
+ get { return this.contractRequiresInfo; }
+ }
+
+ protected override Expr VisitCall (ExprCall e)
+ {
+ var call = (ExprCall)base.VisitCall (e);
+
+ var method = e.Method;
+ if (method.DeclaringType.FullName == "System.Diagnostics.Contracts.Contract") {
+ switch (method.Name) {
+ case "Requires":
+ if (!method.HasGenericParameters) {
+ switch (method.Parameters.Count) {
+ case 1:
+ return this.ProcessRequires1 (call);
+ case 2:
+ return this.ProcessRequires2 (call);
+ default:
+ throw new NotSupportedException ("Invalid number of parameters to Contract.Requires()");
+ }
+ } else {
+ goto default;
+ }
+ default:
+ throw new NotSupportedException ("Cannot handle Contract." + e.Method.Name + "()");
+ }
+ }
+
+ return call;
+ }
+
+ private string GetConditionString (Expr e)
+ {
+ var vSource = new SourcePositionVisitor (this.instructionLookup);
+ vSource.Visit (e);
+ var extractor = new ConditionTextExtractor (vSource.SourceCodeFileName, vSource.StartPosition, vSource.EndPosition);
+ return extractor.GetConditionText ();
+ }
+
+ private Expr ProcessRequires1 (ExprCall e)
+ {
+ MethodDefinition mRequires = this.contractsRuntime.GetRequires ();
+ Expr conditionExpr = e.Parameters.First ();
+ Expr nullArgExpr = new ExprLoadConstant (this.methodInfo, null);
+ string conditionText = this.GetConditionString (e);
+ Expr conditionStringExpr = new ExprLoadConstant (this.methodInfo, conditionText);
+ var call = new ExprCall (this.methodInfo, mRequires, new Expr [] { conditionExpr, nullArgExpr, conditionStringExpr });
+
+ this.contractRequiresInfo.Add (new ContractRequiresInfo (e, call));
+
+ return call;
+ }
+
+ private Expr ProcessRequires2 (ExprCall e)
+ {
+ MethodDefinition mRequires = this.contractsRuntime.GetRequires ();
+ Expr conditionExpr = e.Parameters.First ();
+ Expr msgExpr = e.Parameters.ElementAt (1);
+ string conditionText = this.GetConditionString (e);
+ Expr conditionStringExpr = new ExprLoadConstant (this.methodInfo, conditionText);
+ var call = new ExprCall (this.methodInfo, mRequires, new Expr [] { conditionExpr, msgExpr, conditionStringExpr });
+
+ this.contractRequiresInfo.Add (new ContractRequiresInfo (e, call));
+
+ return call;
+ }
+
+ }
+}
-//\r
-// RewriteAndLoad.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using System.Reflection;\r
-using Mono.CodeContracts.Rewrite;\r
-using System.IO;\r
-using System.Linq.Expressions;\r
-\r
-namespace MonoTests.Mono.CodeContracts {\r
- class RewriteAndLoad : IDisposable {\r
-\r
- class Loader : MarshalByRefObject {\r
-\r
- private Assembly assembly;\r
-\r
- public void Load (byte [] rewrittenAssemblyBytes)\r
- {\r
- this.assembly = AppDomain.CurrentDomain.Load (rewrittenAssemblyBytes);\r
- }\r
-\r
- public object Call(string typeName, string methodName, object[] args)\r
- {\r
- Type type = this.assembly.GetType (typeName);\r
- if (type == null) {\r
- Console.WriteLine ("Cannot get type: " + typeName);\r
- }\r
- var method = type.GetMethod (methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);\r
- if (method == null) {\r
- Console.WriteLine ("Cannot get method: " + methodName);\r
- }\r
- try {\r
- return method.Invoke (null, args);\r
- } catch (TargetInvocationException e) {\r
- throw new Exception(e.InnerException.Message);\r
- }\r
- }\r
-\r
- }\r
-\r
- private AppDomain testDomain = null;\r
- private Loader loader = null;\r
-\r
- public void Load ()\r
- {\r
- Assembly assembly = Assembly.GetExecutingAssembly ();\r
- var appDomainSetup = new AppDomainSetup {\r
- ApplicationBase = Path.GetDirectoryName(assembly.Location)\r
- };\r
- this.testDomain = AppDomain.CreateDomain ("TestDomain", null, appDomainSetup);\r
- this.testDomain.AssemblyResolve += (s, e) => {\r
- return Assembly.LoadFrom (e.Name);\r
- };\r
- this.loader = (Loader) this.testDomain.CreateInstanceAndUnwrap (assembly.Location, typeof (Loader).FullName);\r
-\r
- using (var rewritten = new MemoryStream ()) {\r
- RewriterOptions options = new RewriterOptions {\r
- ForceAssemblyRename = "RewrittenForTest",\r
- Assembly = assembly.Location,\r
- OutputFile = rewritten,\r
- ThrowOnFailure = true,\r
- WritePdbFile = false,\r
- };\r
- Rewriter.Rewrite (options);\r
- byte [] bytes = rewritten.ToArray ();\r
- this.loader.Load (bytes);\r
- }\r
- }\r
-\r
- public void Dispose ()\r
- {\r
- this.loader = null;\r
- if (this.testDomain != null) {\r
- AppDomain.Unload (this.testDomain);\r
- this.testDomain = null;\r
- }\r
- }\r
-\r
- public void Call (Expression<Action> methodExpr)\r
- {\r
- var e = (MethodCallExpression) methodExpr.Body;\r
- if (e.Object != null) {\r
- throw new ArgumentException ("Method must be static");\r
- }\r
- var m = e.Method;\r
- var args = e.Arguments.Select (a => {\r
- while (a.CanReduce) {\r
- a = a.Reduce ();\r
- }\r
- switch (a.NodeType) {\r
- case ExpressionType.Constant:\r
- return ((ConstantExpression) a).Value;\r
- case ExpressionType.MemberAccess:\r
- return new object ();\r
- default:\r
- throw new ArgumentException ("Cannot transfer argument");\r
- }\r
- throw new NotImplementedException();\r
- }).ToArray ();\r
- this.loader.Call (m.DeclaringType.FullName, m.Name, args);\r
- }\r
-\r
- }\r
-}\r
+//
+// RewriteAndLoad.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 System.Linq;
+using System.Text;
+using System.Reflection;
+using Mono.CodeContracts.Rewrite;
+using System.IO;
+using System.Linq.Expressions;
+
+namespace MonoTests.Mono.CodeContracts {
+ class RewriteAndLoad : IDisposable {
+
+ class Loader : MarshalByRefObject {
+
+ private Assembly assembly;
+
+ public void Load (byte [] rewrittenAssemblyBytes)
+ {
+ this.assembly = AppDomain.CurrentDomain.Load (rewrittenAssemblyBytes);
+ }
+
+ public object Call(string typeName, string methodName, object[] args)
+ {
+ Type type = this.assembly.GetType (typeName);
+ if (type == null) {
+ Console.WriteLine ("Cannot get type: " + typeName);
+ }
+ var method = type.GetMethod (methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ if (method == null) {
+ Console.WriteLine ("Cannot get method: " + methodName);
+ }
+ try {
+ return method.Invoke (null, args);
+ } catch (TargetInvocationException e) {
+ throw new Exception(e.InnerException.Message);
+ }
+ }
+
+ }
+
+ private AppDomain testDomain = null;
+ private Loader loader = null;
+
+ public void Load ()
+ {
+ Assembly assembly = Assembly.GetExecutingAssembly ();
+ var appDomainSetup = new AppDomainSetup {
+ ApplicationBase = Path.GetDirectoryName(assembly.Location)
+ };
+ this.testDomain = AppDomain.CreateDomain ("TestDomain", null, appDomainSetup);
+ this.testDomain.AssemblyResolve += (s, e) => {
+ return Assembly.LoadFrom (e.Name);
+ };
+ this.loader = (Loader) this.testDomain.CreateInstanceAndUnwrap (assembly.Location, typeof (Loader).FullName);
+
+ using (var rewritten = new MemoryStream ()) {
+ RewriterOptions options = new RewriterOptions {
+ ForceAssemblyRename = "RewrittenForTest",
+ Assembly = assembly.Location,
+ OutputFile = rewritten,
+ ThrowOnFailure = true,
+ WritePdbFile = false,
+ };
+ Rewriter.Rewrite (options);
+ byte [] bytes = rewritten.ToArray ();
+ this.loader.Load (bytes);
+ }
+ }
+
+ public void Dispose ()
+ {
+ this.loader = null;
+ if (this.testDomain != null) {
+ AppDomain.Unload (this.testDomain);
+ this.testDomain = null;
+ }
+ }
+
+ public void Call (Expression<Action> methodExpr)
+ {
+ var e = (MethodCallExpression) methodExpr.Body;
+ if (e.Object != null) {
+ throw new ArgumentException ("Method must be static");
+ }
+ var m = e.Method;
+ var args = e.Arguments.Select (a => {
+ while (a.CanReduce) {
+ a = a.Reduce ();
+ }
+ switch (a.NodeType) {
+ case ExpressionType.Constant:
+ return ((ConstantExpression) a).Value;
+ case ExpressionType.MemberAccess:
+ return new object ();
+ default:
+ throw new ArgumentException ("Cannot transfer argument");
+ }
+ throw new NotImplementedException();
+ }).ToArray ();
+ this.loader.Call (m.DeclaringType.FullName, m.Name, args);
+ }
+
+ }
+}
-//\r
-// TestCCRewrite.cs\r
-//\r
-// Authors:\r
-// Chris Bacon (chrisbacon76@gmail.com)\r
-//\r
-// Copyright (C) 2010 Novell, Inc (http://www.novell.com)\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-#define CONTRACTS_FULL\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-using NUnit.Framework;\r
-using System.Diagnostics.Contracts;\r
-using System.Linq.Expressions;\r
-\r
-namespace MonoTests.Mono.CodeContracts {\r
-\r
- [TestFixture]\r
- public class TestCCRewrite {\r
-\r
- private RewriteAndLoad ral = null;\r
-\r
- [TestFixtureSetUp]\r
- public void FixtureSetup ()\r
- {\r
- this.ral = new RewriteAndLoad ();\r
- this.ral.Load ();\r
- }\r
-\r
- [TestFixtureTearDown]\r
- public void FixtureTearDown ()\r
- {\r
- if (this.ral != null) {\r
- this.ral.Dispose ();\r
- }\r
- }\r
-\r
- // ==\r
-\r
- private static void TestEqualsByte (byte value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsSByte (sbyte value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsUShort (ushort value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsShort (short value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsUInt (uint value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsInt (int value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsULong (ulong value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsLong (long value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsFloat (float value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- private static void TestEqualsDouble (double value)\r
- {\r
- Contract.Requires (value == 0);\r
- }\r
-\r
- // !=\r
-\r
- private static void TestNotEqualsByte (byte value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsSByte (sbyte value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsUShort (ushort value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsShort (short value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsUInt (uint value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsInt (int value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsULong (ulong value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsLong (long value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsFloat (float value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- private static void TestNotEqualsDouble (double value)\r
- {\r
- Contract.Requires (value != 0);\r
- }\r
-\r
- // <\r
-\r
- private static void TestLessThanInt (int value)\r
- {\r
- Contract.Requires (value < 10);\r
- }\r
-\r
- private static void TestLessThanUInt (uint value)\r
- {\r
- Contract.Requires (value < 10);\r
- }\r
-\r
- private static void TestLessThanLong (long value)\r
- {\r
- Contract.Requires (value < 10);\r
- }\r
-\r
- private static void TestLessThanULong (ulong value)\r
- {\r
- Contract.Requires (value < 10);\r
- }\r
-\r
- private static void TestLessThanFloat (float value)\r
- {\r
- Contract.Requires (value < 10);\r
- }\r
-\r
- private static void TestLessThanDouble (double value)\r
- {\r
- Contract.Requires (value < 10);\r
- }\r
-\r
- // <=\r
-\r
- private static void TestLessThanOrEqualInt (int value)\r
- {\r
- Contract.Requires (value <= 10);\r
- }\r
-\r
- private static void TestLessThanOrEqualUInt (uint value)\r
- {\r
- Contract.Requires (value <= 10);\r
- }\r
-\r
- private static void TestLessThanOrEqualLong (long value)\r
- {\r
- Contract.Requires (value <= 10);\r
- }\r
-\r
- private static void TestLessThanOrEqualULong (ulong value)\r
- {\r
- Contract.Requires (value <= 10);\r
- }\r
-\r
- private static void TestLessThanOrEqualFloat (float value)\r
- {\r
- Contract.Requires (value <= 10);\r
- }\r
-\r
- private static void TestLessThanOrEqualDouble (double value)\r
- {\r
- Contract.Requires (value <= 10);\r
- }\r
-\r
- // >\r
-\r
- private static void TestGreaterThanInt (int value)\r
- {\r
- Contract.Requires (value > 10);\r
- }\r
-\r
- private static void TestGreaterThanUInt (uint value)\r
- {\r
- Contract.Requires (value > 10);\r
- }\r
-\r
- private static void TestGreaterThanLong (long value)\r
- {\r
- Contract.Requires (value > 10);\r
- }\r
-\r
- private static void TestGreaterThanULong (ulong value)\r
- {\r
- Contract.Requires (value > 10);\r
- }\r
-\r
- private static void TestGreaterThanFloat (float value)\r
- {\r
- Contract.Requires (value > 10);\r
- }\r
-\r
- private static void TestGreaterThanDouble (double value)\r
- {\r
- Contract.Requires (value > 10);\r
- }\r
-\r
- // >=\r
-\r
- private static void TestGreaterThanOrEqualInt (int value)\r
- {\r
- Contract.Requires (value >= 10);\r
- }\r
-\r
- private static void TestGreaterThanOrEqualUInt (uint value)\r
- {\r
- Contract.Requires (value >= 10);\r
- }\r
-\r
- private static void TestGreaterThanOrEqualLong (long value)\r
- {\r
- Contract.Requires (value >= 10);\r
- }\r
-\r
- private static void TestGreaterThanOrEqualULong (ulong value)\r
- {\r
- Contract.Requires (value >= 10);\r
- }\r
-\r
- private static void TestGreaterThanOrEqualFloat (float value)\r
- {\r
- Contract.Requires (value >= 10);\r
- }\r
-\r
- private static void TestGreaterThanOrEqualDouble (double value)\r
- {\r
- Contract.Requires (value >= 10);\r
- }\r
-\r
- // object ==\r
-\r
- private static void TestObjectEquals (object value)\r
- {\r
- Contract.Requires (value == null);\r
- }\r
-\r
- // object !=\r
-\r
- private static void TestObjectNotEquals (object value)\r
- {\r
- Contract.Requires (value != null);\r
- }\r
-\r
-\r
-\r
- private void CheckException (Expression<Action> fnExpr, params string [] messageContains)\r
- {\r
- try {\r
- this.ral.Call (fnExpr);\r
- } catch (Exception e) {\r
- string m = e.Message.Split ('\n', '\r') [0].Trim ();\r
- foreach (var contains in messageContains) {\r
- StringAssert.Contains (contains, m);\r
- }\r
- return;\r
- }\r
- Assert.Fail ("Contract should have thrown an exception");\r
- }\r
-\r
- private void CheckTwice (Expression<Action> fnGood, Expression<Action> fnBad, string condition)\r
- {\r
- const string PreFail = "Precondition failed";\r
- this.ral.Call (fnGood);\r
- this.CheckException (fnBad, PreFail, condition);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_Equals ()\r
- {\r
- const string CondEquals = "value == 0";\r
-\r
- this.CheckTwice (() => TestEqualsByte (0), () => TestEqualsByte (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsSByte (0), () => TestEqualsSByte (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsUShort (0), () => TestEqualsUShort (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsShort (0), () => TestEqualsShort (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsUInt (0), () => TestEqualsUInt (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsInt (0), () => TestEqualsInt (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsULong (0), () => TestEqualsULong (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsLong (0), () => TestEqualsLong (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsDouble (0), () => TestEqualsDouble (1), CondEquals);\r
- this.CheckTwice (() => TestEqualsFloat (0), () => TestEqualsFloat (1), CondEquals);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_NotEquals()\r
- {\r
- const string CondNotEquals = "value != 0";\r
-\r
- this.CheckTwice (() => TestNotEqualsByte (1), () => TestNotEqualsByte (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsSByte (1), () => TestNotEqualsSByte (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsUShort (1), () => TestNotEqualsUShort (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsShort (1), () => TestNotEqualsShort (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsUInt (1), () => TestNotEqualsUInt (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsInt (1), () => TestNotEqualsInt (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsULong (1), () => TestNotEqualsULong (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsLong (1), () => TestNotEqualsLong (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsDouble (1), () => TestNotEqualsDouble (0), CondNotEquals);\r
- this.CheckTwice (() => TestNotEqualsFloat (1), () => TestNotEqualsFloat (0), CondNotEquals);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_LessThan()\r
- {\r
- const string CondLessThan = "value < 10";\r
-\r
- this.CheckTwice (() => TestLessThanInt (9), () => TestLessThanInt (10), CondLessThan);\r
- this.CheckTwice (() => TestLessThanUInt (9), () => TestLessThanUInt (10), CondLessThan);\r
- this.CheckTwice (() => TestLessThanLong (9), () => TestLessThanLong (10), CondLessThan);\r
- this.CheckTwice (() => TestLessThanULong (9), () => TestLessThanULong (10), CondLessThan);\r
- this.CheckTwice (() => TestLessThanFloat (9.9f), () => TestLessThanFloat (10), CondLessThan);\r
- this.CheckTwice (() => TestLessThanDouble (9.9), () => TestLessThanDouble (10), CondLessThan);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_LessThanOrEqual()\r
- {\r
- const string CondLessThanOrEqual = "value <= 10";\r
-\r
- this.CheckTwice (() => TestLessThanOrEqualInt (10), () => TestLessThanOrEqualInt (11), CondLessThanOrEqual);\r
- this.CheckTwice (() => TestLessThanOrEqualUInt (10), () => TestLessThanOrEqualUInt (11), CondLessThanOrEqual);\r
- this.CheckTwice (() => TestLessThanOrEqualLong (10), () => TestLessThanOrEqualLong (11), CondLessThanOrEqual);\r
- this.CheckTwice (() => TestLessThanOrEqualULong (10), () => TestLessThanOrEqualULong (11), CondLessThanOrEqual);\r
- this.CheckTwice (() => TestLessThanOrEqualFloat (10.0f), () => TestLessThanOrEqualFloat (10.1f), CondLessThanOrEqual);\r
- this.CheckTwice (() => TestLessThanOrEqualDouble (10.0), () => TestLessThanOrEqualDouble (10.1), CondLessThanOrEqual);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_GreaterThan()\r
- {\r
- const string CondGreaterThan = "value > 10";\r
-\r
- this.CheckTwice (() => TestGreaterThanInt (11), () => TestGreaterThanInt (10), CondGreaterThan);\r
- this.CheckTwice (() => TestGreaterThanUInt (11), () => TestGreaterThanUInt (10), CondGreaterThan);\r
- this.CheckTwice (() => TestGreaterThanLong (11), () => TestGreaterThanLong (10), CondGreaterThan);\r
- this.CheckTwice (() => TestGreaterThanULong (11), () => TestGreaterThanULong (10), CondGreaterThan);\r
- this.CheckTwice (() => TestGreaterThanFloat (10.1f), () => TestGreaterThanFloat (10), CondGreaterThan);\r
- this.CheckTwice (() => TestGreaterThanDouble (10.1), () => TestGreaterThanDouble (10), CondGreaterThan);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_GreaterThanOrEqual()\r
- {\r
- const string CondGreaterThanOrEqual = "value >= 10";\r
-\r
- this.CheckTwice (() => TestGreaterThanOrEqualInt (10), () => TestGreaterThanOrEqualInt (9), CondGreaterThanOrEqual);\r
- this.CheckTwice (() => TestGreaterThanOrEqualUInt (10), () => TestGreaterThanOrEqualUInt (9), CondGreaterThanOrEqual);\r
- this.CheckTwice (() => TestGreaterThanOrEqualLong (10), () => TestGreaterThanOrEqualLong (9), CondGreaterThanOrEqual);\r
- this.CheckTwice (() => TestGreaterThanOrEqualULong (10), () => TestGreaterThanOrEqualULong (9), CondGreaterThanOrEqual);\r
- this.CheckTwice (() => TestGreaterThanOrEqualFloat (10.0f), () => TestGreaterThanOrEqualFloat (9.9f), CondGreaterThanOrEqual);\r
- this.CheckTwice (() => TestGreaterThanOrEqualDouble (10.0), () => TestGreaterThanOrEqualDouble (9.9), CondGreaterThanOrEqual);\r
- }\r
-\r
- [Test]\r
- public void TestTrivial_ObjectEquality()\r
- {\r
- object o = new object ();\r
- this.CheckTwice (() => TestObjectEquals (null), () => TestObjectEquals (o), "value == null");\r
- this.CheckTwice (() => TestObjectNotEquals (o), () => TestObjectNotEquals (null), "value != null");\r
- }\r
-\r
- }\r
-\r
-}\r
+//
+// TestCCRewrite.cs
+//
+// Authors:
+// Chris Bacon (chrisbacon76@gmail.com)
+//
+// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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.
+//
+
+#define CONTRACTS_FULL
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.Diagnostics.Contracts;
+using System.Linq.Expressions;
+
+namespace MonoTests.Mono.CodeContracts {
+
+ [TestFixture]
+ public class TestCCRewrite {
+
+ private RewriteAndLoad ral = null;
+
+ [TestFixtureSetUp]
+ public void FixtureSetup ()
+ {
+ this.ral = new RewriteAndLoad ();
+ this.ral.Load ();
+ }
+
+ [TestFixtureTearDown]
+ public void FixtureTearDown ()
+ {
+ if (this.ral != null) {
+ this.ral.Dispose ();
+ }
+ }
+
+ // ==
+
+ private static void TestEqualsByte (byte value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsSByte (sbyte value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsUShort (ushort value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsShort (short value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsUInt (uint value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsInt (int value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsULong (ulong value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsLong (long value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsFloat (float value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ private static void TestEqualsDouble (double value)
+ {
+ Contract.Requires (value == 0);
+ }
+
+ // !=
+
+ private static void TestNotEqualsByte (byte value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsSByte (sbyte value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsUShort (ushort value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsShort (short value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsUInt (uint value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsInt (int value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsULong (ulong value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsLong (long value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsFloat (float value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ private static void TestNotEqualsDouble (double value)
+ {
+ Contract.Requires (value != 0);
+ }
+
+ // <
+
+ private static void TestLessThanInt (int value)
+ {
+ Contract.Requires (value < 10);
+ }
+
+ private static void TestLessThanUInt (uint value)
+ {
+ Contract.Requires (value < 10);
+ }
+
+ private static void TestLessThanLong (long value)
+ {
+ Contract.Requires (value < 10);
+ }
+
+ private static void TestLessThanULong (ulong value)
+ {
+ Contract.Requires (value < 10);
+ }
+
+ private static void TestLessThanFloat (float value)
+ {
+ Contract.Requires (value < 10);
+ }
+
+ private static void TestLessThanDouble (double value)
+ {
+ Contract.Requires (value < 10);
+ }
+
+ // <=
+
+ private static void TestLessThanOrEqualInt (int value)
+ {
+ Contract.Requires (value <= 10);
+ }
+
+ private static void TestLessThanOrEqualUInt (uint value)
+ {
+ Contract.Requires (value <= 10);
+ }
+
+ private static void TestLessThanOrEqualLong (long value)
+ {
+ Contract.Requires (value <= 10);
+ }
+
+ private static void TestLessThanOrEqualULong (ulong value)
+ {
+ Contract.Requires (value <= 10);
+ }
+
+ private static void TestLessThanOrEqualFloat (float value)
+ {
+ Contract.Requires (value <= 10);
+ }
+
+ private static void TestLessThanOrEqualDouble (double value)
+ {
+ Contract.Requires (value <= 10);
+ }
+
+ // >
+
+ private static void TestGreaterThanInt (int value)
+ {
+ Contract.Requires (value > 10);
+ }
+
+ private static void TestGreaterThanUInt (uint value)
+ {
+ Contract.Requires (value > 10);
+ }
+
+ private static void TestGreaterThanLong (long value)
+ {
+ Contract.Requires (value > 10);
+ }
+
+ private static void TestGreaterThanULong (ulong value)
+ {
+ Contract.Requires (value > 10);
+ }
+
+ private static void TestGreaterThanFloat (float value)
+ {
+ Contract.Requires (value > 10);
+ }
+
+ private static void TestGreaterThanDouble (double value)
+ {
+ Contract.Requires (value > 10);
+ }
+
+ // >=
+
+ private static void TestGreaterThanOrEqualInt (int value)
+ {
+ Contract.Requires (value >= 10);
+ }
+
+ private static void TestGreaterThanOrEqualUInt (uint value)
+ {
+ Contract.Requires (value >= 10);
+ }
+
+ private static void TestGreaterThanOrEqualLong (long value)
+ {
+ Contract.Requires (value >= 10);
+ }
+
+ private static void TestGreaterThanOrEqualULong (ulong value)
+ {
+ Contract.Requires (value >= 10);
+ }
+
+ private static void TestGreaterThanOrEqualFloat (float value)
+ {
+ Contract.Requires (value >= 10);
+ }
+
+ private static void TestGreaterThanOrEqualDouble (double value)
+ {
+ Contract.Requires (value >= 10);
+ }
+
+ // object ==
+
+ private static void TestObjectEquals (object value)
+ {
+ Contract.Requires (value == null);
+ }
+
+ // object !=
+
+ private static void TestObjectNotEquals (object value)
+ {
+ Contract.Requires (value != null);
+ }
+
+
+
+ private void CheckException (Expression<Action> fnExpr, params string [] messageContains)
+ {
+ try {
+ this.ral.Call (fnExpr);
+ } catch (Exception e) {
+ string m = e.Message.Split ('\n', '\r') [0].Trim ();
+ foreach (var contains in messageContains) {
+ StringAssert.Contains (contains, m);
+ }
+ return;
+ }
+ Assert.Fail ("Contract should have thrown an exception");
+ }
+
+ private void CheckTwice (Expression<Action> fnGood, Expression<Action> fnBad, string condition)
+ {
+ const string PreFail = "Precondition failed";
+ this.ral.Call (fnGood);
+ this.CheckException (fnBad, PreFail, condition);
+ }
+
+ [Test]
+ public void TestTrivial_Equals ()
+ {
+ const string CondEquals = "value == 0";
+
+ this.CheckTwice (() => TestEqualsByte (0), () => TestEqualsByte (1), CondEquals);
+ this.CheckTwice (() => TestEqualsSByte (0), () => TestEqualsSByte (1), CondEquals);
+ this.CheckTwice (() => TestEqualsUShort (0), () => TestEqualsUShort (1), CondEquals);
+ this.CheckTwice (() => TestEqualsShort (0), () => TestEqualsShort (1), CondEquals);
+ this.CheckTwice (() => TestEqualsUInt (0), () => TestEqualsUInt (1), CondEquals);
+ this.CheckTwice (() => TestEqualsInt (0), () => TestEqualsInt (1), CondEquals);
+ this.CheckTwice (() => TestEqualsULong (0), () => TestEqualsULong (1), CondEquals);
+ this.CheckTwice (() => TestEqualsLong (0), () => TestEqualsLong (1), CondEquals);
+ this.CheckTwice (() => TestEqualsDouble (0), () => TestEqualsDouble (1), CondEquals);
+ this.CheckTwice (() => TestEqualsFloat (0), () => TestEqualsFloat (1), CondEquals);
+ }
+
+ [Test]
+ public void TestTrivial_NotEquals()
+ {
+ const string CondNotEquals = "value != 0";
+
+ this.CheckTwice (() => TestNotEqualsByte (1), () => TestNotEqualsByte (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsSByte (1), () => TestNotEqualsSByte (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsUShort (1), () => TestNotEqualsUShort (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsShort (1), () => TestNotEqualsShort (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsUInt (1), () => TestNotEqualsUInt (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsInt (1), () => TestNotEqualsInt (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsULong (1), () => TestNotEqualsULong (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsLong (1), () => TestNotEqualsLong (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsDouble (1), () => TestNotEqualsDouble (0), CondNotEquals);
+ this.CheckTwice (() => TestNotEqualsFloat (1), () => TestNotEqualsFloat (0), CondNotEquals);
+ }
+
+ [Test]
+ public void TestTrivial_LessThan()
+ {
+ const string CondLessThan = "value < 10";
+
+ this.CheckTwice (() => TestLessThanInt (9), () => TestLessThanInt (10), CondLessThan);
+ this.CheckTwice (() => TestLessThanUInt (9), () => TestLessThanUInt (10), CondLessThan);
+ this.CheckTwice (() => TestLessThanLong (9), () => TestLessThanLong (10), CondLessThan);
+ this.CheckTwice (() => TestLessThanULong (9), () => TestLessThanULong (10), CondLessThan);
+ this.CheckTwice (() => TestLessThanFloat (9.9f), () => TestLessThanFloat (10), CondLessThan);
+ this.CheckTwice (() => TestLessThanDouble (9.9), () => TestLessThanDouble (10), CondLessThan);
+ }
+
+ [Test]
+ public void TestTrivial_LessThanOrEqual()
+ {
+ const string CondLessThanOrEqual = "value <= 10";
+
+ this.CheckTwice (() => TestLessThanOrEqualInt (10), () => TestLessThanOrEqualInt (11), CondLessThanOrEqual);
+ this.CheckTwice (() => TestLessThanOrEqualUInt (10), () => TestLessThanOrEqualUInt (11), CondLessThanOrEqual);
+ this.CheckTwice (() => TestLessThanOrEqualLong (10), () => TestLessThanOrEqualLong (11), CondLessThanOrEqual);
+ this.CheckTwice (() => TestLessThanOrEqualULong (10), () => TestLessThanOrEqualULong (11), CondLessThanOrEqual);
+ this.CheckTwice (() => TestLessThanOrEqualFloat (10.0f), () => TestLessThanOrEqualFloat (10.1f), CondLessThanOrEqual);
+ this.CheckTwice (() => TestLessThanOrEqualDouble (10.0), () => TestLessThanOrEqualDouble (10.1), CondLessThanOrEqual);
+ }
+
+ [Test]
+ public void TestTrivial_GreaterThan()
+ {
+ const string CondGreaterThan = "value > 10";
+
+ this.CheckTwice (() => TestGreaterThanInt (11), () => TestGreaterThanInt (10), CondGreaterThan);
+ this.CheckTwice (() => TestGreaterThanUInt (11), () => TestGreaterThanUInt (10), CondGreaterThan);
+ this.CheckTwice (() => TestGreaterThanLong (11), () => TestGreaterThanLong (10), CondGreaterThan);
+ this.CheckTwice (() => TestGreaterThanULong (11), () => TestGreaterThanULong (10), CondGreaterThan);
+ this.CheckTwice (() => TestGreaterThanFloat (10.1f), () => TestGreaterThanFloat (10), CondGreaterThan);
+ this.CheckTwice (() => TestGreaterThanDouble (10.1), () => TestGreaterThanDouble (10), CondGreaterThan);
+ }
+
+ [Test]
+ public void TestTrivial_GreaterThanOrEqual()
+ {
+ const string CondGreaterThanOrEqual = "value >= 10";
+
+ this.CheckTwice (() => TestGreaterThanOrEqualInt (10), () => TestGreaterThanOrEqualInt (9), CondGreaterThanOrEqual);
+ this.CheckTwice (() => TestGreaterThanOrEqualUInt (10), () => TestGreaterThanOrEqualUInt (9), CondGreaterThanOrEqual);
+ this.CheckTwice (() => TestGreaterThanOrEqualLong (10), () => TestGreaterThanOrEqualLong (9), CondGreaterThanOrEqual);
+ this.CheckTwice (() => TestGreaterThanOrEqualULong (10), () => TestGreaterThanOrEqualULong (9), CondGreaterThanOrEqual);
+ this.CheckTwice (() => TestGreaterThanOrEqualFloat (10.0f), () => TestGreaterThanOrEqualFloat (9.9f), CondGreaterThanOrEqual);
+ this.CheckTwice (() => TestGreaterThanOrEqualDouble (10.0), () => TestGreaterThanOrEqualDouble (9.9), CondGreaterThanOrEqual);
+ }
+
+ [Test]
+ public void TestTrivial_ObjectEquality()
+ {
+ object o = new object ();
+ this.CheckTwice (() => TestObjectEquals (null), () => TestObjectEquals (o), "value == null");
+ this.CheckTwice (() => TestObjectNotEquals (o), () => TestObjectNotEquals (null), "value != null");
+ }
+
+ }
+
+}
-#define CONTRACTS_FULL\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Diagnostics.Contracts;\r
-using System.Linq;\r
-using System.Text;\r
-using System.IO;\r
-using Mono.CodeContracts.Rewrite;\r
-using Mono.Options;\r
-\r
-namespace ccrewrite {\r
-\r
- class Program {\r
-\r
- static void Main (string [] args)\r
- {\r
- RewriterOptions options = new RewriterOptions ();\r
-\r
- bool showOptions = false;\r
- string showMsg = null;\r
-\r
- var optionSet = new OptionSet {\r
- { "help", "Show this help.", v => showOptions = v != null },\r
- { "debug", "Use MDB or PDB debug information (default=true).", v => options.Debug = v != null },\r
- { "level=", "Instrumentation level, 0 - 4 (default=4).", (int var) => options.Level = var},\r
- { "writePDBFile", "Write MDB or PDB file (default=true).", v => options.WritePdbFile = v != null },\r
- { "rewrite", "Rewrite the assembly (default=true).", v => options.Rewrite = v != null },\r
- { "assembly=", "Assembly to rewrite.", v => options.Assembly = v },\r
- { "breakIntoDebugger|break", "Break into debugger on contract failure.", v => options.BreakIntoDebugger = v != null },\r
- { "throwOnFailure|throw", "Throw ContractException on contract failure.", v => options.ThrowOnFailure = v != null },\r
- { "output|out=", "Output filename of rewritten file.", v => options.OutputFile = v },\r
- };\r
-\r
- try {\r
- optionSet.Parse (args);\r
- } catch (OptionException e) {\r
- showOptions = true;\r
- showMsg = e.Message;\r
- }\r
-\r
- if (showOptions) {\r
- Console.WriteLine ("ccrewrite");\r
- Console.WriteLine ();\r
- Console.WriteLine ("Options:");\r
- optionSet.WriteOptionDescriptions (Console.Out);\r
- Console.WriteLine ();\r
- if (showMsg != null) {\r
- Console.WriteLine (showMsg);\r
- Console.WriteLine ();\r
- }\r
- return;\r
- }\r
-\r
- var results = Rewriter.Rewrite (options);\r
-\r
- if (results.AnyErrors) {\r
- foreach (var error in results.Errors) {\r
- Console.WriteLine ("Error: " + error);\r
- }\r
- }\r
- if (results.AnyWarnings) {\r
- foreach (var warning in results.Warnings) {\r
- Console.WriteLine ("Warning: " + warning);\r
- }\r
- }\r
-\r
- Console.WriteLine ();\r
- Console.WriteLine ("*** done ***");\r
- //Console.ReadKey ();\r
- }\r
-\r
- }\r
-}\r
+#define CONTRACTS_FULL
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Contracts;
+using System.Linq;
+using System.Text;
+using System.IO;
+using Mono.CodeContracts.Rewrite;
+using Mono.Options;
+
+namespace ccrewrite {
+
+ class Program {
+
+ static void Main (string [] args)
+ {
+ RewriterOptions options = new RewriterOptions ();
+
+ bool showOptions = false;
+ string showMsg = null;
+
+ var optionSet = new OptionSet {
+ { "help", "Show this help.", v => showOptions = v != null },
+ { "debug", "Use MDB or PDB debug information (default=true).", v => options.Debug = v != null },
+ { "level=", "Instrumentation level, 0 - 4 (default=4).", (int var) => options.Level = var},
+ { "writePDBFile", "Write MDB or PDB file (default=true).", v => options.WritePdbFile = v != null },
+ { "rewrite", "Rewrite the assembly (default=true).", v => options.Rewrite = v != null },
+ { "assembly=", "Assembly to rewrite.", v => options.Assembly = v },
+ { "breakIntoDebugger|break", "Break into debugger on contract failure.", v => options.BreakIntoDebugger = v != null },
+ { "throwOnFailure|throw", "Throw ContractException on contract failure.", v => options.ThrowOnFailure = v != null },
+ { "output|out=", "Output filename of rewritten file.", v => options.OutputFile = v },
+ };
+
+ try {
+ optionSet.Parse (args);
+ } catch (OptionException e) {
+ showOptions = true;
+ showMsg = e.Message;
+ }
+
+ if (showOptions) {
+ Console.WriteLine ("ccrewrite");
+ Console.WriteLine ();
+ Console.WriteLine ("Options:");
+ optionSet.WriteOptionDescriptions (Console.Out);
+ Console.WriteLine ();
+ if (showMsg != null) {
+ Console.WriteLine (showMsg);
+ Console.WriteLine ();
+ }
+ return;
+ }
+
+ var results = Rewriter.Rewrite (options);
+
+ if (results.AnyErrors) {
+ foreach (var error in results.Errors) {
+ Console.WriteLine ("Error: " + error);
+ }
+ }
+ if (results.AnyWarnings) {
+ foreach (var warning in results.Warnings) {
+ Console.WriteLine ("Warning: " + warning);
+ }
+ }
+
+ Console.WriteLine ();
+ Console.WriteLine ("*** done ***");
+ //Console.ReadKey ();
+ }
+
+ }
+}