Author: rolf
Date: 2008-02-12 19:01:15 -0500 (Tue, 12 Feb 2008)
New Revision: 95556

Modified:
   branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog
   branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb
   branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb
   branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/MemberImplementsClause.vb
Log:
* Members/Attribute.vb: Implement pinvokes.
* Members/MemberImplementsClause.vb: Implement event interface
  implementations.
* General/Helper.vb: Do some more checking when comparing types.

Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog 2008-02-12 23:53:53 UTC 
(rev 95555)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog 2008-02-13 00:01:15 UTC 
(rev 95556)
@@ -1,3 +1,10 @@
+2008-02-13  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
+
+       * Members/Attribute.vb: Implement pinvokes.
+       * Members/MemberImplementsClause.vb: Implement event interface
+         implementations.
+       * General/Helper.vb: Do some more checking when comparing types.
+
 2008-02-12  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
 
        * Statements/ForStatement.vb, Statements/EndStatement.vb,

Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb 2008-02-12 
23:53:53 UTC (rev 95555)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb 2008-02-13 
00:01:15 UTC (rev 95556)
@@ -3513,6 +3513,8 @@
 #If ENABLECECIL Then
     Shared Function CompareType(ByVal t1 As Mono.Cecil.TypeReference, ByVal t2 
As Mono.Cecil.TypeReference) As Boolean
         If t1 Is t2 Then Return True
+        If CecilHelper.FindDefinition(t1) Is CecilHelper.FindDefinition(t2) 
Then Return True
+        If t1.FullName IsNot Nothing AndAlso t2.FullName IsNot Nothing AndAlso 
Helper.CompareNameOrdinal(t1.FullName, t2.FullName) Then Return True
         Helper.Assert(t1.FullName.Equals(t2.FullName) = False)
         Return False
     End Function

Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb      
2008-02-12 23:53:53 UTC (rev 95555)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb      
2008-02-13 00:01:15 UTC (rev 95556)
@@ -311,7 +311,66 @@
                 ElseIf mthd IsNot Nothing Then
                     mthd.MethodBuilder.SetCustomAttribute(GetAttributeBuilder)
 #If ENABLECECIL Then
-                    mthd.CecilBuilder.CustomAttributes.Add(cecilBuilder)
+                    If 
Helper.CompareType(cecilBuilder.Constructor.DeclaringType, 
Compiler.CecilTypeCache.System_Runtime_InteropServices_DllImportAttribute) Then
+                        Dim values As IDictionary = cecilBuilder.Fields
+                        Dim entry As String = DirectCast(values("EntryPoint"), 
String)
+                        Dim modRef As Mono.Cecil.ModuleReference = New 
Mono.Cecil.ModuleReference(DirectCast(cecilBuilder.ConstructorParameters(0), 
String))
+
+                        If entry = String.Empty Then entry = mthd.Name
+                        
Compiler.AssemblyBuilderCecil.MainModule.ModuleReferences.Add(modRef)
+                        mthd.CecilBuilder.PInvokeInfo = New 
Mono.Cecil.PInvokeInfo(mthd.CecilBuilder)
+                        mthd.CecilBuilder.PInvokeInfo.EntryPoint = entry
+                        mthd.CecilBuilder.PInvokeInfo.Module = modRef
+
+                        Dim charset As System.Runtime.InteropServices.CharSet
+                        If values.Contains("CharSet") Then
+                            charset = DirectCast(values("CharSet"), 
System.Runtime.InteropServices.CharSet)
+                        Else
+                            charset = Runtime.InteropServices.CharSet.Auto
+                        End If
+                        Select Case charset
+                            Case Runtime.InteropServices.CharSet.Ansi
+                                mthd.CecilBuilder.PInvokeInfo.IsCharSetAnsi = 
True
+                            Case Runtime.InteropServices.CharSet.Auto
+                                mthd.CecilBuilder.PInvokeInfo.IsCharSetAuto = 
True
+                            Case Runtime.InteropServices.CharSet.None
+                                mthd.CecilBuilder.PInvokeInfo.IsCharSetNotSpec 
= True
+                            Case Runtime.InteropServices.CharSet.Unicode
+                                mthd.CecilBuilder.PInvokeInfo.IsCharSetUnicode 
= True
+                            Case Else
+                                result = 
Compiler.Report.ShowMessage(Messages.VBNC99999, Me.Location, "Invalid charset: 
" & charset.ToString()) AndAlso result
+                        End Select
+
+                        Dim callingconv As 
System.Runtime.InteropServices.CallingConvention
+                        If values.Contains("CallingConvention") Then
+                            callingconv = 
DirectCast(values("CallingConvention"), 
System.Runtime.InteropServices.CallingConvention)
+                        Else
+                            callingconv = 
Runtime.InteropServices.CallingConvention.StdCall
+                        End If
+                        Select Case callingconv
+                            Case 
Runtime.InteropServices.CallingConvention.Cdecl
+                                mthd.CecilBuilder.PInvokeInfo.IsCallConvCdecl 
= True
+                            Case 
Runtime.InteropServices.CallingConvention.FastCall
+                                
mthd.CecilBuilder.PInvokeInfo.IsCallConvFastcall = True
+                            Case 
Runtime.InteropServices.CallingConvention.StdCall
+                                
mthd.CecilBuilder.PInvokeInfo.IsCallConvStdCall = True
+                            Case 
Runtime.InteropServices.CallingConvention.ThisCall
+                                
mthd.CecilBuilder.PInvokeInfo.IsCallConvThiscall = True
+                            Case 
Runtime.InteropServices.CallingConvention.Winapi
+                                mthd.CecilBuilder.PInvokeInfo.IsCallConvWinapi 
= True
+                            Case Else
+                                result = 
Compiler.Report.ShowMessage(Messages.VBNC99999, Me.Location, "Invalid calling 
convention: " & callingconv.ToString()) AndAlso result
+                        End Select
+
+                        Dim setlasterror As Boolean = True
+                        If values.Contains("SetLastError") Then
+                            setlasterror = DirectCast(values("SetLastError"), 
Boolean)
+                        End If
+                        mthd.CecilBuilder.PInvokeInfo.SupportsLastError = 
setlasterror
+                        mthd.CecilBuilder.PInvokeInfo.IsNoMangle = True
+                    Else
+                        mthd.CecilBuilder.CustomAttributes.Add(cecilBuilder)
+                    End If
 #End If
                 ElseIf ctro IsNot Nothing Then
                     
ctro.ConstructorBuilder.SetCustomAttribute(GetAttributeBuilder)

Modified: 
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/MemberImplementsClause.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/MemberImplementsClause.vb 
2008-02-12 23:53:53 UTC (rev 95555)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/MemberImplementsClause.vb 
2008-02-13 00:01:15 UTC (rev 95556)
@@ -71,12 +71,30 @@
             Helper.Assert((raiseMethodI Is Nothing Xor raiseMethod Is Nothing) 
= False)
 
             If addMethod IsNot Nothing AndAlso addMethodI IsNot Nothing Then
+#If ENABLECECIL Then
+                Dim methodDef As Mono.Cecil.MethodDefinition
+                Dim mD As MethodDescriptor = 
TryCast(Compiler.TypeManager.GetRegisteredMember(Compiler, addMethod), 
MethodDescriptor)
+                methodDef = TryCast(mD.MethodInCecil, 
Mono.Cecil.MethodDefinition)
+                
methodDef.Overrides.Add(Helper.GetMethodOrMethodReference(Compiler, addMethodI))
+#End If
                 declType.DefineMethodOverride(addMethod, addMethodI)
             End If
             If removeMethod IsNot Nothing AndAlso removeMethodI IsNot Nothing 
Then
+#If ENABLECECIL Then
+                Dim methodDef As Mono.Cecil.MethodDefinition
+                Dim mD As MethodDescriptor = 
TryCast(Compiler.TypeManager.GetRegisteredMember(Compiler, removeMethod), 
MethodDescriptor)
+                methodDef = TryCast(mD.MethodInCecil, 
Mono.Cecil.MethodDefinition)
+                
methodDef.Overrides.Add(Helper.GetMethodOrMethodReference(Compiler, 
removeMethodI))
+#End If
                 declType.DefineMethodOverride(removeMethod, removeMethodI)
             End If
             If raiseMethod IsNot Nothing AndAlso raiseMethodI IsNot Nothing 
Then
+#If ENABLECECIL Then
+                Dim methodDef As Mono.Cecil.MethodDefinition
+                Dim mD As MethodDescriptor = 
TryCast(Compiler.TypeManager.GetRegisteredMember(Compiler, raiseMethod), 
MethodDescriptor)
+                methodDef = TryCast(mD.MethodInCecil, 
Mono.Cecil.MethodDefinition)
+                
methodDef.Overrides.Add(Helper.GetMethodOrMethodReference(Compiler, 
raiseMethodI))
+#End If
                 declType.DefineMethodOverride(raiseMethod, raiseMethodI)
             End If
         Next

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

Reply via email to