Skip to content

Commit

Permalink
Remove CodeContracts usages.
Browse files Browse the repository at this point in the history
Recently the code contracts team indicated that that it may not remain
being supported (microsoft/CodeContracts#409).  In addition, it has
not been ported to support .Net Core.  To prepare for porting to
.Net Core, this removes al references to CodeContacts.
  • Loading branch information
TheModMaker committed Jan 6, 2017
1 parent 6035eaf commit 03e4947
Show file tree
Hide file tree
Showing 24 changed files with 1 addition and 620 deletions.
44 changes: 0 additions & 44 deletions Example Project/Example Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<CodeContractsAssemblyMode>0</CodeContractsAssemblyMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -29,49 +28,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<CodeContractsEnableRuntimeChecking>False</CodeContractsEnableRuntimeChecking>
<CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
<CodeContractsRuntimeThrowOnFailure>True</CodeContractsRuntimeThrowOnFailure>
<CodeContractsRuntimeCallSiteRequires>False</CodeContractsRuntimeCallSiteRequires>
<CodeContractsRuntimeSkipQuantifiers>False</CodeContractsRuntimeSkipQuantifiers>
<CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>
<CodeContractsNonNullObligations>True</CodeContractsNonNullObligations>
<CodeContractsBoundsObligations>True</CodeContractsBoundsObligations>
<CodeContractsArithmeticObligations>True</CodeContractsArithmeticObligations>
<CodeContractsEnumObligations>True</CodeContractsEnumObligations>
<CodeContractsRedundantAssumptions>True</CodeContractsRedundantAssumptions>
<CodeContractsAssertsToContractsCheckBox>True</CodeContractsAssertsToContractsCheckBox>
<CodeContractsRedundantTests>True</CodeContractsRedundantTests>
<CodeContractsMissingPublicRequiresAsWarnings>True</CodeContractsMissingPublicRequiresAsWarnings>
<CodeContractsMissingPublicEnsuresAsWarnings>False</CodeContractsMissingPublicEnsuresAsWarnings>
<CodeContractsInferRequires>True</CodeContractsInferRequires>
<CodeContractsInferEnsures>False</CodeContractsInferEnsures>
<CodeContractsInferEnsuresAutoProperties>True</CodeContractsInferEnsuresAutoProperties>
<CodeContractsInferObjectInvariants>False</CodeContractsInferObjectInvariants>
<CodeContractsSuggestAssumptions>False</CodeContractsSuggestAssumptions>
<CodeContractsSuggestAssumptionsForCallees>False</CodeContractsSuggestAssumptionsForCallees>
<CodeContractsSuggestRequires>False</CodeContractsSuggestRequires>
<CodeContractsNecessaryEnsures>True</CodeContractsNecessaryEnsures>
<CodeContractsSuggestObjectInvariants>False</CodeContractsSuggestObjectInvariants>
<CodeContractsSuggestReadonly>True</CodeContractsSuggestReadonly>
<CodeContractsRunInBackground>True</CodeContractsRunInBackground>
<CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
<CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
<CodeContractsEmitXMLDocs>False</CodeContractsEmitXMLDocs>
<CodeContractsCustomRewriterAssembly />
<CodeContractsCustomRewriterClass />
<CodeContractsLibPaths />
<CodeContractsExtraRewriteOptions />
<CodeContractsExtraAnalysisOptions />
<CodeContractsSQLServerOption />
<CodeContractsBaseLineFile />
<CodeContractsCacheAnalysisResults>True</CodeContractsCacheAnalysisResults>
<CodeContractsSkipAnalysisIfCannotConnectToCache>False</CodeContractsSkipAnalysisIfCannotConnectToCache>
<CodeContractsFailBuildOnWarnings>False</CodeContractsFailBuildOnWarnings>
<CodeContractsBeingOptimisticOnExternal>True</CodeContractsBeingOptimisticOnExternal>
<CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
<CodeContractsReferenceAssembly>%28none%29</CodeContractsReferenceAssembly>
<CodeContractsAnalysisWarningLevel>0</CodeContractsAnalysisWarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand Down
3 changes: 0 additions & 3 deletions ModMaker.Lua.Net/Runtime/LuaClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.ObjectModel;
using System.Reflection;
using ModMaker.Lua.Runtime.LuaValues;
using System.Diagnostics.Contracts;

namespace ModMaker.Lua.Runtime
{
Expand Down Expand Up @@ -179,8 +178,6 @@ public void CreateType()
/// <returns>An instance of the type.</returns>
public object CreateInstance(params ILuaValue[] args)
{
Contract.Requires(args != null);

if (_created == null)
CreateType();

Expand Down
1 change: 0 additions & 1 deletion ModMaker.Lua.Net/Runtime/ThreadPool.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ModMaker.Lua.Runtime.LuaValues;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

Expand Down
56 changes: 0 additions & 56 deletions ModMaker.Lua/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -33,7 +32,6 @@ sealed class DisposableHelper : IDisposable

public DisposableHelper(Action act)
{
Contract.Requires(act != null);
this.act = act;
}

Expand Down Expand Up @@ -200,20 +198,6 @@ sealed class OverloadInfo<T> where T : MethodBase
/// </summary>
public readonly bool IsParams;

[ContractInvariantMethod]
void Invariant()
{
Contract.Invariant(Arguments != null);
Contract.Invariant(Method != null);
Contract.Invariant(ConversionAmounts != null);
Contract.Invariant(ConversionTypes != null);

Contract.Invariant(ConversionAmounts.Length == ConversionTypes.Length);
Contract.Invariant(Contract.ForAll(ConversionAmounts, i => i >= 0));
Contract.Invariant(ParamsOrOptional >= 0);
Contract.Invariant(LuaValueCount >= 0);
}

/// <summary>
/// Creates a new OverloadInfo object from the given method.
/// </summary>
Expand All @@ -224,11 +208,6 @@ void Invariant()
/// not valid.</returns>
public static OverloadInfo<T> Create(T method, object target, ILuaMultiValue args)
{
Contract.Requires(method != null);
Contract.Requires(args != null);
Contract.Ensures(Contract.Result<OverloadInfo<T>>() == null ||
Contract.Result<OverloadInfo<T>>().Arguments == args);

// Ignore any methods marked with LuaIgnore.
if (method.GetCustomAttributes(typeof(LuaIgnoreAttribute), true).Length > 0)
return null;
Expand Down Expand Up @@ -260,8 +239,6 @@ public static OverloadInfo<T> Create(T method, object target, ILuaMultiValue arg
// Provide support for a params array.
if (param.Length > 0 && param[param.Length - 1].GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
{
Contract.Assert(param[param.Length - 1].ParameterType.IsArray);

isParams = true;
paramsOrOptional = args.Count - param.Length;

Expand Down Expand Up @@ -370,9 +347,6 @@ public static OverloadInfo<T> Create(T method, object target, ILuaMultiValue arg
/// <returns>A value that defines which overload is better.</returns>
public int Compare(OverloadInfo<T> other)
{
Contract.Requires(other != null);
Contract.Requires(other.Arguments == Arguments);

int ret;
if (CompareFormalParameters(other, out ret))
return ret;
Expand Down Expand Up @@ -501,7 +475,6 @@ static LuaCastType CombineType(LuaCastType typeA, LuaCastType typeB)
case LuaCastType.SameType:
return typeB;
case LuaCastType.Interface:
Contract.Assert(typeB == LuaCastType.Interface);
return typeB;
case LuaCastType.BaseClass:
if (typeB == LuaCastType.UserDefined || typeB == LuaCastType.ExplicitUserDefined)
Expand All @@ -516,7 +489,6 @@ static LuaCastType CombineType(LuaCastType typeA, LuaCastType typeB)
else
return typeA;
default:
Contract.Assert(false);
throw new NotImplementedException();
}
}
Expand All @@ -531,11 +503,6 @@ static LuaCastType CombineType(LuaCastType typeA, LuaCastType typeB)
/// <param name="amount">Will contain the amount of the cast.</param>
static void GetCastInfo(MethodInfo getCastInfo, ILuaValue target, Type destType, out LuaCastType castType, out int amount)
{
Contract.Requires(getCastInfo != null);
Contract.Requires(target != null);
Contract.Requires(destType != null);
Contract.Ensures(Contract.ValueAtReturn(out amount) >= 0);

try
{
// These are out args, so the initial value can be null
Expand All @@ -546,7 +513,6 @@ static void GetCastInfo(MethodInfo getCastInfo, ILuaValue target, Type destType,
// Out arguments modify the args array.
castType = (LuaCastType)args[0];
amount = (int)args[1];
Contract.Assume(amount >= 0);
}
catch (NotSupportedException)
{
Expand Down Expand Up @@ -574,8 +540,6 @@ static void GetCastInfo(MethodInfo getCastInfo, ILuaValue target, Type destType,
/// <returns>An IDisposable object.</returns>
public static IDisposable Disposable(Action act)
{
Contract.Requires(act != null);
Contract.Ensures(Contract.Result<IDisposable>() != null);
return new DisposableHelper(act);
}

Expand All @@ -594,7 +558,6 @@ public static IDisposable Disposable(Action act)
/// <exception cref="System.TypeLoadException">A custom attribute type cannot be loaded.</exception>
public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribute
{
Contract.Requires(element != null);
return (T)Attribute.GetCustomAttribute(element, typeof(T));
}
/// <summary>
Expand All @@ -612,7 +575,6 @@ public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribu
/// <exception cref="System.TypeLoadException">A custom attribute type cannot be loaded.</exception>
public static T GetCustomAttribute<T>(this MemberInfo element, bool inherit) where T : Attribute
{
Contract.Requires(element != null);
return (T)Attribute.GetCustomAttribute(element, typeof(T), inherit);
}

Expand Down Expand Up @@ -657,10 +619,6 @@ public static object As(this ILuaMultiValue args, int start, Type type)
/// <returns>The cast type that is used.</returns>
public static LuaCastType TypesCompatible(Type sourceType, Type destType, out MethodInfo method, out int amount)
{
Contract.Requires(sourceType != null);
Contract.Requires(destType != null);
Contract.Ensures(Contract.ValueAtReturn(out amount) >= 0);

method = null;
amount = 0;

Expand Down Expand Up @@ -733,7 +691,6 @@ public static LuaCastType TypesCompatible(Type sourceType, Type destType, out Me
.ToArray();

// check the possible choices
Contract.Assert(possible != null);
if (possible.Length > 0)
{
for (int i = 0; i < possible.Length; i++)
Expand Down Expand Up @@ -766,10 +723,6 @@ public static LuaCastType TypesCompatible(Type sourceType, Type destType, out Me
public static bool GetCompatibleMethod<T>(IEnumerable<Tuple<T, object>> methods, ILuaMultiValue args,
out T resultMethod, out object resultTarget) where T : MethodBase
{
Contract.Requires(methods != null);
Contract.Requires(Contract.ForAll(methods, m => m != null && m.Item1 != null));
Contract.Requires(args != null);

resultMethod = null;
resultTarget = null;

Expand Down Expand Up @@ -815,7 +768,6 @@ public static bool GetCompatibleMethod<T>(IEnumerable<Tuple<T, object>> methods,
public static object[] ConvertForArgs(ILuaMultiValue args, MethodBase method)
{
var param = method.GetParameters();
Contract.Assert(param != null);

var ret = new object[param.Length];
var min = Math.Min(param.Length, args.Count);
Expand Down Expand Up @@ -852,7 +804,6 @@ public static object[] ConvertForArgs(ILuaMultiValue args, MethodBase method)
// Get optional parameters.
for (int i = min; i < param.Length; i++)
{
Contract.Assert(param[i].IsOptional || hasParams);
ret[i] = param[i].DefaultValue;
}

Expand Down Expand Up @@ -907,9 +858,6 @@ public static object DynamicInvoke(MethodBase method, object target, object[] ar
public static ILuaValue GetSetMember(Type targetType, object target, ILuaValue index,
ILuaValue value = null)
{
Contract.Requires(index != null);
Contract.Requires(targetType != null);

// TODO: Consider how to get settings here.
/*if (!E.Settings.AllowReflection &&
typeof(MemberInfo).IsAssignableFrom(targetType))
Expand Down Expand Up @@ -1084,10 +1032,6 @@ static ILuaValue GetSetValue(MemberInfo[] members, int over, object target,
static ILuaValue GetSetIndex(Type targetType, object target, ILuaMultiValue indicies,
ILuaValue value = null)
{
Contract.Requires(targetType != null);
Contract.Requires(indicies != null);
Contract.Ensures(Contract.Result<ILuaValue>() != null);

// Arrays do not actually define an 'Item' method so we need to access the indexer
// directly.
Array targetArray = target as Array;
Expand Down
Loading

0 comments on commit 03e4947

Please sign in to comment.