Author: atomb
Date: 2005-12-09 14:53:37 -0500 (Fri, 09 Dec 2005)
New Revision: 54169

Added:
   trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/DoubleCheckLockingRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
   trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am
   trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/DoubleCheckLockingTest.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/Makefile.am
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/BadRecursiveInvocationRule.cs
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/NonNullAttribute.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/OpCodeConstants.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/BadRecursiveInvocationTest.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Makefile.am
Modified:
   trunk/cecil/gendarme/ChangeLog
   trunk/cecil/gendarme/configure.ac
   trunk/cecil/gendarme/rules/Makefile.am
   trunk/cecil/gendarme/rules/rules.xml
Log:
Merged rules for bad recursive invocation and double-check locking
detection. Null dereference analysis will come soon.


Modified: trunk/cecil/gendarme/ChangeLog
===================================================================
--- trunk/cecil/gendarme/ChangeLog      2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/ChangeLog      2005-12-09 19:53:37 UTC (rev 54169)
@@ -1,3 +1,8 @@
+2005-12-09  Aaron Tomb  <[EMAIL PROTECTED]>
+
+       * Merged rules for double-check locking and bad recursive
+       invocation checking.
+
 2005-11-02  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * Initial import into SVN.

Modified: trunk/cecil/gendarme/configure.ac
===================================================================
--- trunk/cecil/gendarme/configure.ac   2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/configure.ac   2005-12-09 19:53:37 UTC (rev 54169)
@@ -58,4 +58,10 @@
 rules/Gendarme.Rules.Performance/Makefile
 rules/Gendarme.Rules.Performance/Gendarme.Rules.Performance.xml
 rules/Gendarme.Rules.Performance/Test/Makefile
+rules/Gendarme.Rules.Concurrency/Makefile
+rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml
+rules/Gendarme.Rules.Concurrency/Test/Makefile
+rules/Gendarme.Rules.Correctness/Makefile
+rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml
+rules/Gendarme.Rules.Correctness/Test/Makefile
 ])

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/DoubleCheckLockingRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/DoubleCheckLockingRule.cs 
    2005-12-09 18:16:07 UTC (rev 54168)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/DoubleCheckLockingRule.cs 
    2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,112 @@
+/*
+ * DCLChecker.cs: looks for instances of double-check locking.
+ *
+ * Authors:
+ *   Aaron Tomb <[EMAIL PROTECTED]>
+ *
+ * Copyright (c) 2005 Aaron Tomb and the contributors listed
+ * in the ChangeLog.
+ *
+ * This is free software, distributed under the MIT/X11 license.
+ * See the included MIT.X11 file for details.
+ **********************************************************************/
+
+using System;
+using System.Collections;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Gendarme.Framework;
+
+public class DoubleCheckLockingRule : IMethodRule {
+
+    public bool CheckMethod (IAssemblyDefinition assembly, IModuleDefinition 
module,
+            ITypeDefinition type, IMethodDefinition method)
+    {
+        Hashtable comparisons = new Hashtable();
+
+        if(method.Body == null)
+            return true;
+
+        IInstructionCollection insns = method.Body.Instructions;
+
+        ArrayList monitorOffsetList = new ArrayList(10);
+        for(int i = 0; i < insns.Count; i++) {
+            int mcount = monitorOffsetList.Count;
+            IInstruction[] twoBefore = TwoBeforeBranch(insns[i]);
+            if(twoBefore != null) {
+                if(monitorOffsetList.Count > 0) {
+                    /* If there's a comparison in the list matching this
+                     * one, we have double-check locking. */
+                    foreach(IInstruction insn in comparisons.Keys) {
+                        IInstruction[] twoBeforeI =
+                            (IInstruction[])comparisons[insn];
+                        if(EffectivelyEqual(insn, insns[i]) &&
+                           EffectivelyEqual(twoBeforeI[0], twoBefore[0]) &&
+                           EffectivelyEqual(twoBeforeI[1], twoBefore[1]) &&
+                           mcount > 0 &&
+                           insn.Offset < (int)monitorOffsetList[mcount - 1]) {
+                            return false;
+                            /* TODO: restore messages */
+                            /*
+                            string etype = method.DeclaringType.FullName;
+                            Location loc = new Location(etype, method.Name,
+                                    insn.Offset);
+                            report.AddMessage(new Message(
+                                        "possible double-check locking",
+                                        loc, MessageType.Warning));
+                                        */
+                        }
+                    }
+                }
+                comparisons[insns[i]] = twoBefore;
+            }
+            if(IsMonitorMethod(insns[i], "Enter"))
+                monitorOffsetList.Add(insns[i].Offset);
+            if(IsMonitorMethod(insns[i], "Exit"))
+                if(mcount > 0)
+                    monitorOffsetList.RemoveAt(monitorOffsetList.Count - 1);
+        }
+        return true;
+    }
+
+    private bool IsMonitorMethod(IInstruction insn, string methodName)
+    {
+        if(!insn.OpCode.Name.Equals("call"))
+            return false;
+        IMethodReference method = (IMethodReference)insn.Operand;
+        if(!method.Name.Equals(methodName))
+            return false;
+        if(!method.DeclaringType.FullName.Equals("System.Threading.Monitor"))
+            return false;
+        return true;
+    }
+
+    private IInstruction[] TwoBeforeBranch(IInstruction insn)
+    {
+        if(insn.OpCode.FlowControl != FlowControl.Cond_Branch)
+            return null;
+        if(insn.Previous == null || insn.Previous.Previous == null)
+            return null;
+        IInstruction[] twoInsns = new IInstruction[2];
+        twoInsns[0] = insn.Previous;
+        twoInsns[1] = insn.Previous.Previous;
+        return twoInsns;
+    }
+
+    private bool EffectivelyEqual(IInstruction insn1, IInstruction insn2)
+    {
+        if(!insn1.OpCode.Equals(insn2.OpCode))
+            return false;
+        /* If both are branch instructions, we don't care about their
+         * targets, only their opcodes. */
+        if(insn1.OpCode.FlowControl == FlowControl.Cond_Branch)
+            return true;
+        /* For other instructions, their operands must also be equal. */
+        if(insn1.Operand == null && insn2.Operand == null)
+            return true;
+        if(insn1.Operand != null && insn2.Operand != null)
+            if(insn1.Operand.Equals(insn2.Operand))
+                return true;
+        return false;
+    }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
     2005-12-09 18:16:07 UTC (rev 54168)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
     2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,8 @@
+<rules>
+       <rule   Name="DoubleCheckLockingRule" 
+               Type="Gendarme.Rules.Concurrency.DoubleCheckLockingRule, 
Gendarme.Rules.Concurrency, [EMAIL PROTECTED]@, Culture=neutral, 
PublicKeyToken=null"
+               Uri="http://www.mono-project.com/Gendarme"; >
+               <problem></problem>
+               <solution></solution>
+       </rule>
+</rules>

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am   
2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am   
2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,43 @@
+SUBDIRS=Test
+
+concurrency_rulesdir=$(pkglibdir)
+concurrency_rules_SCRIPTS = Gendarme.Rules.Concurrency.dll
+EXTRA_DIST = $(concurrency_rules_sources) $(concurrency_rules_sources_in) 
Gendarme.Rules.Concurrency.xml
+CLEANFILES = Gendarme.Rules.Concurrency.dll Test.Rules.Concurrency.dll
+DISTCLEANFILES = Makefile.in Gendarme.Rules.Concurrency.xml TestResult.xml
+
+concurrency_rules_sources_in = ../../AssemblyInfo.cs.in
+concurrency_rules_generated_sources = $(concurrency_rules_sources_in:.in=)
+concurrency_rules_sources = DoubleCheckLockingRule.cs
+
+concurrency_rules_build_sources = $(addprefix $(srcdir)/, 
$(concurrency_rules_sources))
+concurrency_rules_build_sources += $(concurrency_rules_generated_sources)
+
+Gendarme.Rules.Concurrency.dll: $(concurrency_rules_build_sources)
+       $(MCS) -target:library -pkg:mono-cecil 
-r:../../framework/Gendarme.Framework.dll -out:$@ 
$(concurrency_rules_build_sources)
+
+# Install Unstable Mono Libraries (see configure.ac)
+
+install-data-hook:
+       $(INSTALL) -c -m 0644 Gendarme.Rules.Concurrency.xml 
$(DESTDIR)$(pkglibdir);
+       for ASM in $(INSTALLED_ASSEMBLIES); do \
+               $(INSTALL) -c -m 0755 $$ASM $(DESTDIR)$(pkglibdir); \
+       done;
+
+uninstall-hook:
+       $(INSTALL) -c -m 0644 Gendarme.Rules.Concurrency.xml 
$(DESTDIR)$(pkglibdir);
+       for ASM in $(INSTALLED_ASSEMBLIES); do \
+               rm -f $(DESTDIR)$(pkglibdir)/`basename $$ASM`; \
+       done;
+
+concurrency_test_sources = DoubleCheckLockingTest.cs
+concurrency_test_build_sources = $(addprefix $(srcdir)/Test/, 
$(concurrency_test_sources))
+
+Test.Rules.Concurrency.dll: $(concurrency_rules_build_sources)
+       $(MCS) -target:library -pkg:mono-cecil -r:nunit.framework.dll 
-r:../../framework/Gendarme.Framework.dll \
+               -r:Gendarme.Rules.Concurrency.dll -out:$@ 
$(concurrency_test_build_sources)
+
+test: Gendarme.Rules.Concurrency.dll Test.Rules.Concurrency.dll
+
+run-test: Test.Rules.Concurrency.dll
+       MONO_PATH=../../framework/:$(CECIL_PATH):$(MONO_PATH) nunit-console 
Test.Rules.Concurrency.dll

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/DoubleCheckLockingTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/DoubleCheckLockingTest.cs
        2005-12-09 18:16:07 UTC (rev 54168)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/DoubleCheckLockingTest.cs
        2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,30 @@
+using System;
+
+public class Singleton
+{
+     private static volatile Singleton instance;
+     private static object syncRoot = new Object();
+
+     private Singleton()
+     {
+     }
+
+     public static Singleton Instance
+     {
+        get {
+            if (instance == null) {
+                lock (syncRoot) {
+                    if (instance == null) 
+                        instance = new Singleton();
+                }
+            }
+            return instance;
+        }
+    }
+}
+
+public class Wrapper {
+    public static void Main(string[] args)
+    {
+    }
+}

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/Makefile.am      
2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Test/Makefile.am      
2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,4 @@
+EXTRA_DIST = *.cs
+DISTCLEANFILES = Makefile.in
+
+all:

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/BadRecursiveInvocationRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/BadRecursiveInvocationRule.cs
 2005-12-09 18:16:07 UTC (rev 54168)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/BadRecursiveInvocationRule.cs
 2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,107 @@
+/*
+ * BadRecChecker.cs: looks for instances of problematic recursive
+ * invocations.
+ *
+ * Authors:
+ *   Aaron Tomb <[EMAIL PROTECTED]>
+ *
+ * Copyright (c) 2005 Aaron Tomb and the contributors listed
+ * in the ChangeLog.
+ *
+ * This is free software, distributed under the MIT/X11 license.
+ * See the included MIT.X11 file for details.
+ **********************************************************************/
+
+using System;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Gendarme.Framework;
+
+public class BadRecursiveInvocationRule : IMethodRule {
+
+    public bool CheckMethod (IAssemblyDefinition assembly, IModuleDefinition 
module,
+            ITypeDefinition type, IMethodDefinition method)
+    {
+        if(method.Body == null)
+            return true;
+
+        IInstructionCollection instructions = method.Body.Instructions;
+
+        for(int i = 0; i < instructions.Count; i++) {
+            IInstruction insn = instructions[i];
+            if(insn.OpCode.Value == OpCodeConstants.Call ||
+               insn.OpCode.Value == OpCodeConstants.Callvirt) {
+                IMethodReference mref = (IMethodReference)insn.Operand;
+                string rName = mref.Name;
+                string rDecl = mref.DeclaringType.Name;
+                string mName = method.Name;
+                string mDecl = method.DeclaringType.Name;
+                bool argsEqual = 
+                    (mref.Parameters.Count == method.Parameters.Count);
+                if(argsEqual) {
+                    for(int j = 0; j < mref.Parameters.Count; j++) {
+                        IParameterDefinition p1 =
+                            (IParameterDefinition)mref.Parameters[j];
+                        IParameterDefinition p2 =
+                            (IParameterDefinition)method.Parameters[j];
+
+                        if(!p1.Name.Equals(p2.Name))
+                            argsEqual = false;
+
+                        string tn1 = p1.ParameterType.FullName;
+                        string tn2 = p2.ParameterType.FullName;
+                        if(!tn1.Equals(tn2))
+                            argsEqual = false;
+                    }
+                }
+                if(rName.Equals(mName) && rDecl.Equals(mDecl) && argsEqual) {
+                    if(LoadsVerbatimArgs(method, i)) {
+                        return false;
+                        /* TODO: restore the ability to generate
+                         * messages. */
+                        /*
+                        string etype = method.DeclaringType.FullName;
+                        Location loc = new Location(etype, method.Name,
+                                insn.Offset);
+                        report.AddMessage(new Message("suspicious recursive 
call",
+                                    loc, MessageType.Warning));
+                                    */
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+    private bool LoadsVerbatimArgs([NonNull] IMethodDefinition method,
+            int callIndex)
+    {
+        int pcount = method.Parameters.Count;
+        IInstructionCollection instructions = method.Body.Instructions;
+
+        if(callIndex <= pcount)
+            return false;
+        if(method.HasThis)
+            pcount++;
+
+        for(int i = 0; i < pcount; i++)
+           if(!IsLoadParam(instructions[(callIndex - pcount) + i], i))
+               return false;
+        return true;
+    }
+
+    private bool IsLoadParam([NonNull] IInstruction insn, int paramNum)
+    {
+        switch((int)insn.OpCode.Value) {
+            case OpCodeConstants.Ldarg:
+                if((int)insn.Operand == paramNum) return true; break;
+            case OpCodeConstants.Ldarg_S:
+                if((byte)insn.Operand == paramNum) return true; break;
+            case OpCodeConstants.Ldarg_0: if(paramNum == 0) return true; break;
+            case OpCodeConstants.Ldarg_1: if(paramNum == 1) return true; break;
+            case OpCodeConstants.Ldarg_2: if(paramNum == 2) return true; break;
+            case OpCodeConstants.Ldarg_3: if(paramNum == 3) return true; break;
+        }
+        return false;
+    }
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
     2005-12-09 18:16:07 UTC (rev 54168)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Gendarme.Rules.Correctness.xml.in
     2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,8 @@
+<rules>
+       <rule   Name="BadRecursiveInvocationRule" 
+               Type="Gendarme.Rules.Correctness.BadRecursiveInvocationRule, 
Gendarme.Rules.Correctness, [EMAIL PROTECTED]@, Culture=neutral, 
PublicKeyToken=null"
+               Uri="http://www.mono-project.com/Gendarme"; >
+               <problem></problem>
+               <solution></solution>
+       </rule>
+</rules>

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am   
2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Makefile.am   
2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,43 @@
+SUBDIRS=Test
+
+correctness_rulesdir=$(pkglibdir)
+correctness_rules_SCRIPTS = Gendarme.Rules.Correctness.dll
+EXTRA_DIST = $(correctness_rules_sources) $(correctness_rules_sources_in) 
Gendarme.Rules.Correctness.xml
+CLEANFILES = Gendarme.Rules.Correctness.dll Test.Rules.Correctness.dll
+DISTCLEANFILES = Makefile.in Gendarme.Rules.Correctness.xml TestResult.xml
+
+correctness_rules_sources_in = ../../AssemblyInfo.cs.in
+correctness_rules_generated_sources = $(correctness_rules_sources_in:.in=)
+correctness_rules_sources = BadRecursiveInvocationRule.cs OpCodeConstants.cs 
NonNullAttribute.cs
+
+correctness_rules_build_sources = $(addprefix $(srcdir)/, 
$(correctness_rules_sources))
+correctness_rules_build_sources += $(correctness_rules_generated_sources)
+
+Gendarme.Rules.Correctness.dll: $(correctness_rules_build_sources)
+       $(MCS) -target:library -pkg:mono-cecil 
-r:../../framework/Gendarme.Framework.dll -out:$@ 
$(correctness_rules_build_sources)
+
+# Install Unstable Mono Libraries (see configure.ac)
+
+install-data-hook:
+       $(INSTALL) -c -m 0644 Gendarme.Rules.Correctness.xml 
$(DESTDIR)$(pkglibdir);
+       for ASM in $(INSTALLED_ASSEMBLIES); do \
+               $(INSTALL) -c -m 0755 $$ASM $(DESTDIR)$(pkglibdir); \
+       done;
+
+uninstall-hook:
+       $(INSTALL) -c -m 0644 Gendarme.Rules.Correctness.xml 
$(DESTDIR)$(pkglibdir);
+       for ASM in $(INSTALLED_ASSEMBLIES); do \
+               rm -f $(DESTDIR)$(pkglibdir)/`basename $$ASM`; \
+       done;
+
+correctness_test_sources = BadRecursiveInvocationTest.cs
+correctness_test_build_sources = $(addprefix $(srcdir)/Test/, 
$(correctness_test_sources))
+
+Test.Rules.Correctness.dll: $(correctness_rules_build_sources)
+       $(MCS) -target:library -pkg:mono-cecil -r:nunit.framework.dll 
-r:../../framework/Gendarme.Framework.dll \
+               -r:Gendarme.Rules.Correctness.dll -out:$@ 
$(correctness_test_build_sources)
+
+test: Gendarme.Rules.Correctness.dll Test.Rules.Correctness.dll
+
+run-test: Test.Rules.Correctness.dll
+       MONO_PATH=../../framework/:$(CECIL_PATH):$(MONO_PATH) nunit-console 
Test.Rules.Correctness.dll

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/NonNullAttribute.cs
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/NonNullAttribute.cs   
2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/NonNullAttribute.cs   
2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,24 @@
+/*
+ * NonNullAttribute.cs: a custom attribute that can be placed on a
+ * method, field, property, or parameter, to indicate that it should
+ * never be null.
+ *
+ * Authors:
+ *   Aaron Tomb <[EMAIL PROTECTED]>
+ *
+ * Copyright (c) 2005 Aaron Tomb and the contributors listed
+ * in the ChangeLog.
+ *
+ * This is free software, distributed under the MIT/X11 license.
+ * See the included LICENSE.MIT file for details.
+ **********************************************************************/
+
+using System;
+
+[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field |
+        AttributeTargets.Property | AttributeTargets.Parameter)]
+public class NonNullAttribute : System.Attribute {
+    public NonNullAttribute()
+    {
+    }
+}

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/OpCodeConstants.cs
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/OpCodeConstants.cs    
2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/OpCodeConstants.cs    
2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,236 @@
+/*
+ * OpCodeConstants.cs: a temporary hack that should eventually go into
+ * Cecil in some way or another.
+ *
+ * Authors:
+ *   Aaron Tomb <[EMAIL PROTECTED]>
+ *
+ * Copyright (c) 2005 Aaron Tomb and the contributors listed
+ * in the ChangeLog.
+ *
+ * This is free software, distributed under the MIT/X11 license.
+ * See the included LICENSE.MIT file for details.
+ **********************************************************************/
+
+public class OpCodeConstants {
+
+    /* Opcodes starting with 0x00FF */
+    public const int Nop = 0x0000;
+    public const int Break = 0x0001;
+    public const int Ldarg_0 = 0x0002;
+    public const int Ldarg_1 = 0x0003;
+    public const int Ldarg_2 = 0x0004;
+    public const int Ldarg_3 = 0x0005;
+    public const int Ldloc_0 = 0x0006;
+    public const int Ldloc_1 = 0x0007;
+    public const int Ldloc_2 = 0x0008;
+    public const int Ldloc_3 = 0x0009;
+    public const int Stloc_0 = 0x000A;
+    public const int Stloc_1 = 0x000B;
+    public const int Stloc_2 = 0x000C;
+    public const int Stloc_3 = 0x000D;
+    public const int Ldarg_S = 0x000E;
+    public const int Ldarga_S = 0x000F;
+    public const int Starg_S = 0x0010;
+    public const int Ldloc_S = 0x0011;
+    public const int Ldloca_S = 0x0012;
+    public const int Stloc_S = 0x0013;
+    public const int Ldnull = 0x0014;
+    public const int Ldc_I4_M1 = 0x0015;
+    public const int Ldc_I4_0 = 0x0016;
+    public const int Ldc_I4_1 = 0x0017;
+    public const int Ldc_I4_2 = 0x0018;
+    public const int Ldc_I4_3 = 0x0019;
+    public const int Ldc_I4_4 = 0x001A;
+    public const int Ldc_I4_5 = 0x001B;
+    public const int Ldc_I4_6 = 0x001C;
+    public const int Ldc_I4_7 = 0x001D;
+    public const int Ldc_I4_8 = 0x001E;
+    public const int Ldc_I4_S = 0x001F;
+    public const int Ldc_I4 = 0x0020;
+    public const int Ldc_I8 = 0x0021;
+    public const int Ldc_R4 = 0x0022;
+    public const int Ldc_R8 = 0x0023;
+    public const int Dup = 0x0025;
+    public const int Pop = 0x0026;
+    public const int Jmp = 0x0027;
+    public const int Call = 0x0028;
+    public const int Calli = 0x0029;
+    public const int Ret = 0x002A;
+    public const int Br_S = 0x002B;
+    public const int Brfalse_S = 0x002C;
+    public const int Brtrue_S = 0x002D;
+    public const int Beq_S = 0x002E;
+    public const int Bge_S = 0x002F;
+    public const int Bgt_S = 0x0030;
+    public const int Ble_S = 0x0031;
+    public const int Blt_S = 0x0032;
+    public const int Bne_Un_S = 0x0033;
+    public const int Bge_Un_S = 0x0034;
+    public const int Bgt_Un_S = 0x0035;
+    public const int Ble_Un_S = 0x0036;
+    public const int Blt_Un_S = 0x0037;
+    public const int Br = 0x0038;
+    public const int Brfalse = 0x0039;
+    public const int Brtrue = 0x003A;
+    public const int Beq = 0x003B;
+    public const int Bge = 0x003C;
+    public const int Bgt = 0x003D;
+    public const int Ble = 0x003E;
+    public const int Blt = 0x003F;
+    public const int Bne_Un = 0x0040;
+    public const int Bge_Un = 0x0041;
+    public const int Bgt_Un = 0x0042;
+    public const int Ble_Un = 0x0043;
+    public const int Blt_Un = 0x0044;
+    public const int Switch = 0x0045;
+    public const int Ldind_I1 = 0x0046;
+    public const int Ldind_U1 = 0x0047;
+    public const int Ldind_I2 = 0x0048;
+    public const int Ldind_U2 = 0x0049;
+    public const int Ldind_I4 = 0x004A;
+    public const int Ldind_U4 = 0x004B;
+    public const int Ldind_I8 = 0x004C;
+    public const int Ldind_I = 0x004D;
+    public const int Ldind_R4 = 0x004E;
+    public const int Ldind_R8 = 0x004F;
+    public const int Ldind_Ref = 0x0050;
+    public const int Stind_Ref = 0x0051;
+    public const int Stind_I1 = 0x0052;
+    public const int Stind_I2 = 0x0053;
+    public const int Stind_I4 = 0x0054;
+    public const int Stind_I8 = 0x0055;
+    public const int Stind_R4 = 0x0056;
+    public const int Stind_R8 = 0x0057;
+    public const int Add = 0x0058;
+    public const int Sub = 0x0059;
+    public const int Mul = 0x005A;
+    public const int Div = 0x005B;
+    public const int Div_Un = 0x005C;
+    public const int Rem = 0x005D;
+    public const int Rem_Un = 0x005E;
+    public const int And = 0x005F;
+    public const int Or = 0x0060;
+    public const int Xor = 0x0061;
+    public const int Shl = 0x0062;
+    public const int Shr = 0x0063;
+    public const int Shr_Un = 0x0064;
+    public const int Neg = 0x0065;
+    public const int Not = 0x0066;
+    public const int Conv_I1 = 0x0067;
+    public const int Conv_I2 = 0x0068;
+    public const int Conv_I4 = 0x0069;
+    public const int Conv_I8 = 0x006A;
+    public const int Conv_R4 = 0x006B;
+    public const int Conv_R8 = 0x006C;
+    public const int Conv_U4 = 0x006D;
+    public const int Conv_U8 = 0x006E;
+    public const int Callvirt = 0x006F;
+    public const int Cpobj = 0x0070;
+    public const int Ldobj = 0x0071;
+    public const int Ldstr = 0x0072;
+    public const int Newobj = 0x0073;
+    public const int Castclass = 0x0074;
+    public const int Isinst = 0x0075;
+    public const int Conv_R_Un = 0x0076;
+    public const int Unbox = 0x0079;
+    public const int Throw = 0x007A;
+    public const int Ldfld = 0x007B;
+    public const int Ldflda = 0x007C;
+    public const int Stfld = 0x007D;
+    public const int Ldsfld = 0x007E;
+    public const int Ldsflda = 0x007F;
+    public const int Stsfld = 0x0080;
+    public const int Stobj = 0x0081;
+    public const int Conv_Ovf_I1_Un = 0x0082;
+    public const int Conv_Ovf_I2_Un = 0x0083;
+    public const int Conv_Ovf_I4_Un = 0x0084;
+    public const int Conv_Ovf_I8_Un = 0x0085;
+    public const int Conv_Ovf_U1_Un = 0x0086;
+    public const int Conv_Ovf_U2_Un = 0x0087;
+    public const int Conv_Ovf_U4_Un = 0x0088;
+    public const int Conv_Ovf_U8_Un = 0x0089;
+    public const int Conv_Ovf_I_Un = 0x008A;
+    public const int Conv_Ovf_U_Un = 0x008B;
+    public const int Box = 0x008C;
+    public const int Newarr = 0x008D;
+    public const int Ldlen = 0x008E;
+    public const int Ldelema = 0x008F;
+    public const int Ldelem_I1 = 0x0090;
+    public const int Ldelem_U1 = 0x0091;
+    public const int Ldelem_I2 = 0x0092;
+    public const int Ldelem_U2 = 0x0093;
+    public const int Ldelem_I4 = 0x0094;
+    public const int Ldelem_U4 = 0x0095;
+    public const int Ldelem_I8 = 0x0096;
+    public const int Ldelem_I = 0x0097;
+    public const int Ldelem_R4 = 0x0098;
+    public const int Ldelem_R8 = 0x0099;
+    public const int Ldelem_Ref = 0x009A;
+    public const int Stelem_I = 0x009B;
+    public const int Stelem_I1 = 0x009C;
+    public const int Stelem_I2 = 0x009D;
+    public const int Stelem_I4 = 0x009E;
+    public const int Stelem_I8 = 0x009F;
+    public const int Stelem_R4 = 0x00A0;
+    public const int Stelem_R8 = 0x00A1;
+    public const int Stelem_Ref = 0x00A2;
+    public const int Ldelem_Any = 0x00A3;
+    public const int Stelem_Any = 0x00A4;
+    public const int Unbox_Any = 0x00A5;
+    public const int Conv_Ovf_I1 = 0x00B3;
+    public const int Conv_Ovf_U1 = 0x00B4;
+    public const int Conv_Ovf_I2 = 0x00B5;
+    public const int Conv_Ovf_U2 = 0x00B6;
+    public const int Conv_Ovf_I4 = 0x00B7;
+    public const int Conv_Ovf_U4 = 0x00B8;
+    public const int Conv_Ovf_I8 = 0x00B9;
+    public const int Conv_Ovf_U8 = 0x00BA;
+    public const int Refanyval = 0x00C2;
+    public const int Ckfinite = 0x00C3;
+    public const int Mkrefany = 0x00C6;
+    public const int Ldtoken = 0x00D0;
+    public const int Conv_U2 = 0x00D1;
+    public const int Conv_U1 = 0x00D2;
+    public const int Conv_I = 0x00D3;
+    public const int Conv_Ovf_I = 0x00D4;
+    public const int Conv_Ovf_U = 0x00D5;
+    public const int Add_Ovf = 0x00D6;
+    public const int Add_Ovf_Un = 0x00D7;
+    public const int Mul_Ovf = 0x00D8;
+    public const int Mul_Ovf_Un = 0x00D9;
+    public const int Sub_Ovf = 0x00DA;
+    public const int Sub_Ovf_Un = 0x00DB;
+    public const int Endfinally = 0x00DC;
+    public const int Leave = 0x00DD;
+    public const int Leave_S = 0x00DE;
+    public const int Stind_I = 0x00DF;
+    public const int Conv_U = 0x00E0;
+
+    /* Opcodes starting with 0xFE */
+    public const int Arglist = 0xFE00;
+    public const int Ceq = 0xFE01;
+    public const int Cgt = 0xFE02;
+    public const int Cgt_Un = 0xFE03;
+    public const int Clt = 0xFE04;
+    public const int Clt_Un = 0xFE05;
+    public const int Ldftn = 0xFE06;
+    public const int Ldvirtftn = 0xFE07;
+    public const int Ldarg = 0xFE09;
+    public const int Ldarga = 0xFE0A;
+    public const int Starg = 0xFE0B;
+    public const int Ldloc = 0xFE0C;
+    public const int Ldloca = 0xFE0D;
+    public const int Stloc = 0xFE0E;
+    public const int Localloc = 0xFE0F;
+    public const int Endfilter = 0xFE11;
+    public const int Unaligned = 0xFE12;
+    public const int Volatile = 0xFE13;
+    public const int Tail = 0xFE14;
+    public const int Initobj = 0xFE15;
+    public const int Cpblk = 0xFE17;
+    public const int Initblk = 0xFE18;
+    public const int Rethrow = 0xFE1A;
+    public const int Sizeof = 0xFE1C;
+    public const int Refanytype = 0xFE1D;
+}

Added: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/BadRecursiveInvocationTest.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/BadRecursiveInvocationTest.cs
    2005-12-09 18:16:07 UTC (rev 54168)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/BadRecursiveInvocationTest.cs
    2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,17 @@
+class BadRec {
+
+    /* This should be an error. */
+    public int Foo {
+        get { return Foo; }
+    }
+
+    /* This should be fine, as it uses 'base.' */
+    public override int GetHashCode()
+    {
+        return base.GetHashCode();
+    }
+
+    public static void Main(string[] args)
+    {
+    }
+}

Added: trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Makefile.am      
2005-12-09 18:16:07 UTC (rev 54168)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Correctness/Test/Makefile.am      
2005-12-09 19:53:37 UTC (rev 54169)
@@ -0,0 +1,4 @@
+EXTRA_DIST = *.cs
+DISTCLEANFILES = Makefile.in
+
+all:

Modified: trunk/cecil/gendarme/rules/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Makefile.am      2005-12-09 18:16:07 UTC (rev 
54168)
+++ trunk/cecil/gendarme/rules/Makefile.am      2005-12-09 19:53:37 UTC (rev 
54169)
@@ -1,4 +1,5 @@
-SUBDIRS= Gendarme.Rules.Performance Gendarme.Rules.Security
+SUBDIRS= Gendarme.Rules.Performance Gendarme.Rules.Security \
+        Gendarme.Rules.Correctness Gendarme.Rules.Concurrency
 EXTRA_DIST = rules.xml
 DISTCLEANFILES = Makefile.in
 

Modified: trunk/cecil/gendarme/rules/rules.xml
===================================================================
--- trunk/cecil/gendarme/rules/rules.xml        2005-12-09 18:16:07 UTC (rev 
54168)
+++ trunk/cecil/gendarme/rules/rules.xml        2005-12-09 19:53:37 UTC (rev 
54169)
@@ -1,8 +1,16 @@
 <gendarme>
        <ruleset name="default">
+               <rules include="*" from="Gendarme.Rules.Concurrency.dll" />
+               <rules include="*" from="Gendarme.Rules.Correctness.dll" />
                <rules include="*" from="Gendarme.Rules.Performance.dll" />
                <rules include="*" from="Gendarme.Rules.Security.dll" />
        </ruleset>
+       <ruleset name="concurrency">
+               <rules include="*" from="Gendarme.Rules.Concurrency.dll" />
+       </ruleset>
+       <ruleset name="correctness">
+               <rules include="*" from="Gendarme.Rules.Correctness.dll" />
+       </ruleset>
        <ruleset name="security">
                <rules include="*" from="Gendarme.Rules.Security.dll" />
        </ruleset>

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to