Author: rolf
Date: 2008-02-12 10:50:14 -0500 (Tue, 12 Feb 2008)
New Revision: 95521
Modified:
branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Descriptors/MethodDescriptor.vb
branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Compiler.vb
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/Statements/EndStatement.vb
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/ForStatement.vb
branches/rolf/cecil-vbnc/vbnc/vbnc/source/TypeDeclarations/AssemblyDeclaration.vb
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/ImportsNamespaceClause.vb
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/TypeParameter.vb
Log:
* Statements/ForStatement.vb, Statements/EndStatement.vb,
Members/Attribute.vb, Descriptors/MethodDescriptor.vb,
Types/TypeParameter.vb, Types/ImportsNamespaceClause.vb,
TypeDeclarations/AssemblyDeclaration.vb, General/Helper.vb,
General/Compiler.vb: More cecil fixes.
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog 2008-02-12 15:47:11 UTC
(rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/ChangeLog 2008-02-12 15:50:14 UTC
(rev 95521)
@@ -1,3 +1,11 @@
+2008-02-12 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
+
+ * Statements/ForStatement.vb, Statements/EndStatement.vb,
+ Members/Attribute.vb, Descriptors/MethodDescriptor.vb,
+ Types/TypeParameter.vb, Types/ImportsNamespaceClause.vb,
+ TypeDeclarations/AssemblyDeclaration.vb, General/Helper.vb,
+ General/Compiler.vb: More cecil fixes.
+
2007-12-14 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* Members/Attribute.vb: Don't pass XDescriptors to SRE.
Modified:
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Descriptors/MethodDescriptor.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Descriptors/MethodDescriptor.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Descriptors/MethodDescriptor.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -163,6 +163,9 @@
result = result Or MethodAttributes.SpecialName
End If
+ If
m_Declaration.CustomAttributes.IsDefined(Compiler.TypeCache.System_Runtime_InteropServices_DllImportAttribute)
Then
+ result = result Or MethodAttributes.PinvokeImpl
+ End If
DumpMethodInfo(result)
Return result
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Compiler.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Compiler.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Compiler.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -349,7 +349,6 @@
End Select
AssemblyBuilderCecil =
Mono.Cecil.AssemblyFactory.DefineAssembly(assemblyName.Name,
Mono.Cecil.TargetRuntime.NET_2_0, kind)
ModuleBuilderCecil = AssemblyBuilderCecil.MainModule
- Me.Assembly.SetCecilName(AssemblyBuilderCecil.Name)
#End If
Return Compiler.Report.Errors = 0
@@ -581,6 +580,7 @@
result = Compile_Resolve() AndAlso result
If Report.Errors > 0 Then GoTo ShowErrors
+ result = Me.Assembly.SetCecilName(AssemblyBuilderCecil.Name)
AndAlso result
result = AddResources() AndAlso result
If result = False Then GoTo ShowErrors
@@ -958,7 +958,9 @@
'Find the main function
Dim lstMethods As New Generic.List(Of MethodInfo)
Dim mainClass As TypeDeclaration = Nothing
-
+#If ENABLECECIL Then
+ Dim mainCecil As Mono.Cecil.MethodDefinition = Nothing
+#End If
result = FindMainClass(mainClass) AndAlso result
result = FindMainMethod(mainClass, lstMethods) AndAlso result
@@ -980,6 +982,13 @@
ilGen.Emit(OpCodes.Call,
TypeCache.System_Windows_Forms_Application__Run)
ilGen.Emit(OpCodes.Ret)
lstMethods.Add(mainBuilder)
+#If ENABLECECIL Then
+ mainCecil = New Mono.Cecil.MethodDefinition("Main",
Mono.Cecil.MethodAttributes.Public Or Mono.Cecil.MethodAttributes.Static Or
Mono.Cecil.MethodAttributes.HideBySig, Helper.GetTypeOrTypeReference(Me,
CecilTypeCache.System_Void))
+
mainCecil.Body.CilWorker.Emit(Mono.Cecil.Cil.OpCodes.Newobj,
formConstructor.CecilBuilder)
+ mainCecil.Body.CilWorker.Emit(Mono.Cecil.Cil.OpCodes.Call,
Helper.GetMethodOrMethodReference(Me,
TypeCache.System_Windows_Forms_Application__Run))
+ mainCecil.Body.CilWorker.Emit(Mono.Cecil.Cil.OpCodes.Ret)
+ mainClass.CecilType.Methods.Add(mainCecil)
+#End If
End If
End If
@@ -1007,7 +1016,11 @@
entryMethod.SetCustomAttribute(TypeCache.System_STAThreadAttribute__ctor, New
Byte() {})
AssemblyBuilder.SetEntryPoint(entryMethod)
#If ENABLECECIL Then
- AssemblyBuilderCecil.EntryPoint =
CecilHelper.FindDefinition(Helper.GetMethodOrMethodReference(Me, entryMethod))
+ If mainCecil Is Nothing Then
+ mainCecil =
CecilHelper.FindDefinition(Helper.GetMethodOrMethodReference(Me, entryMethod))
+ End If
+ mainCecil.CustomAttributes.Add(New
Mono.Cecil.CustomAttribute(Helper.GetMethodOrMethodReference(Compiler,
CecilTypeCache.System_STAThreadAttribute__ctor)))
+ AssemblyBuilderCecil.EntryPoint = mainCecil
#End If
End If
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb 2008-02-12
15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/General/Helper.vb 2008-02-12
15:50:14 UTC (rev 95521)
@@ -3157,7 +3157,7 @@
Dim result As Mono.Cecil.MethodReference = Nothing
If m_MethodRefCache.TryGetValue(Method, result) = False Then
Try
- If TypeOf Method Is MethodBuilder Then Stop
+ If TypeOf Method Is MethodBuilder Then Helper.Stop()
If
Method.GetType().FullName.Contains("System.Reflection.Emit") AndAlso
Method.DeclaringType.GetElementType IsNot Nothing AndAlso
Method.DeclaringType.IsArray Then
'Stop
Dim retType As Mono.Cecil.TypeReference = Nothing
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Members/Attribute.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -277,7 +277,7 @@
builder = GetAttributeBuilder()
Me.Compiler.AssemblyBuilder.SetCustomAttribute(builder)
#If ENABLECECIL Then
-
Me.Compiler.AssemblyBuilderCecil.MainModule.CustomAttributes.Add(cecilBuilder)
+ Me.Compiler.AssemblyBuilderCecil.CustomAttributes.Add(cecilBuilder)
#End If
ElseIf m_IsModule Then
Dim builder As CustomAttributeBuilder
@@ -356,11 +356,14 @@
m_ResolvedTypeConstructor =
Helper.GetCtorOrCtorBuilder(m_ResolvedTypeConstructor)
- For i As Integer = 0 To m_Arguments.Length - 1
+ Dim cecilArguments As Object()
+ ReDim cecilArguments(m_Arguments.Length - 1)
+ Array.Copy(m_Arguments, cecilArguments, m_Arguments.Length)
+ For i As Integer = 0 To cecilArguments.Length - 1
Dim type As Type
- type = TryCast(m_Arguments(i), Type)
+ type = TryCast(cecilArguments(i), Type)
If type IsNot Nothing Then
- m_Arguments(i) = Helper.GetTypeOrTypeReference(Compiler, type)
+ cecilArguments(i) = Helper.GetTypeOrTypeReference(Compiler,
type)
End If
Next
@@ -374,8 +377,8 @@
result.Properties.Add(m_Properties(i).Name,
m_PropertyValues(i))
result.SetPropertyType(m_Properties(i).Name,
Helper.GetTypeOrTypeReference(Compiler, m_Properties(i).PropertyType))
Next
- For i As Integer = 0 To m_Arguments.Length - 1
- result.ConstructorParameters.Add(m_Arguments(i))
+ For i As Integer = 0 To cecilArguments.Length - 1
+ result.ConstructorParameters.Add(cecilArguments(i))
Next
Catch ex As Exception
Throw
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/EndStatement.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/EndStatement.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/EndStatement.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -35,8 +35,7 @@
Friend Overrides Function GenerateCode(ByVal Info As EmitInfo) As Boolean
Dim result As Boolean = True
- Dim ilgen As ILGenerator = Me.FindFirstParent(Of IMethod).ILGenerator
- ilgen.EmitCall(OpCodes.Call,
Compiler.TypeCache.MS_VB_CS_ProjectData__EndApp, Nothing)
+ Emitter.EmitCall(Info, Compiler.TypeCache.MS_VB_CS_ProjectData__EndApp)
Return result
End Function
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/ForStatement.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/ForStatement.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Statements/ForStatement.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -421,6 +421,8 @@
result = m_LoopStartExpression.ResolveExpression(Info) AndAlso result
result = m_LoopEndExpression.ResolveExpression(Info) AndAlso result
+ If result = False Then Return result
+
If m_LoopControlVariable.Expression IsNot Nothing Then
If
m_LoopControlVariable.Expression.Classification.IsVariableClassification =
False Then
Return Helper.ShowClassificationError(Compiler, Me.Location,
m_LoopControlVariable.Expression.Classification, "Variable")
Modified:
branches/rolf/cecil-vbnc/vbnc/vbnc/source/TypeDeclarations/AssemblyDeclaration.vb
===================================================================
---
branches/rolf/cecil-vbnc/vbnc/vbnc/source/TypeDeclarations/AssemblyDeclaration.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++
branches/rolf/cecil-vbnc/vbnc/vbnc/source/TypeDeclarations/AssemblyDeclaration.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -561,7 +561,8 @@
End Sub
#If ENABLECECIL Then
- Public Sub SetCecilName(ByVal Name As Mono.Cecil.AssemblyNameDefinition)
+ Public Function SetCecilName(ByVal Name As
Mono.Cecil.AssemblyNameDefinition) As Boolean
+ Dim result As Boolean = True
Dim keyfile As String = Nothing
Dim keyname As String = Nothing
Dim delaysign As Boolean = False
@@ -582,7 +583,7 @@
attribType = attri.ResolvedType
If Helper.CompareType(attribType,
Compiler.TypeCache.System_Reflection_AssemblyVersionAttribute) Then
- SetVersion(Name, attri, attri.Location)
+ result = SetVersion(Name, attri, attri.Location) AndAlso result
ElseIf Helper.CompareType(attribType,
Compiler.TypeCache.System_Reflection_AssemblyKeyFileAttribute) Then
If keyfile = String.Empty Then keyfile =
TryCast(attri.Arguments()(0), String)
ElseIf Helper.CompareType(attribType,
Compiler.TypeCache.System_Reflection_AssemblyKeyNameAttribute) Then
@@ -594,10 +595,12 @@
If keyfile <> String.Empty Then
If SignWithKeyFile(Name, keyfile, delaysign) = False Then
- Return
+ Return result
End If
End If
- End Sub
+
+ Return result
+ End Function
#End If
Public Function GetName() As AssemblyName
Modified:
branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/ImportsNamespaceClause.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/ImportsNamespaceClause.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/ImportsNamespaceClause.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -92,8 +92,7 @@
result = nri.Resolve AndAlso result
If nri.FoundOnlyOneObject = False Then
- Compiler.Report.ShowMessage(Messages.VBNC40056, Location, Name)
- Return result
+ Return Compiler.Report.ShowMessage(Messages.VBNC40056, Location,
Name)
End If
If nri.FoundIs(Of [Namespace])() Then
Modified: branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/TypeParameter.vb
===================================================================
--- branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/TypeParameter.vb
2008-02-12 15:47:11 UTC (rev 95520)
+++ branches/rolf/cecil-vbnc/vbnc/vbnc/source/Types/TypeParameter.vb
2008-02-12 15:50:14 UTC (rev 95521)
@@ -185,6 +185,9 @@
If basetype IsNot Nothing Then
basetype = Helper.GetTypeOrTypeBuilder(basetype)
m_Builder.SetBaseTypeConstraint(basetype)
+#If ENABLECECIL Then
+
m_CecilBuilder.Constraints.Add(Helper.GetTypeOrTypeReference(Compiler,
basetype))
+#End If
#If DEBUGREFLECTION Then
Helper.DebugReflection_AppendLine("{0}.SetBaseTypeConstraint({1})", m_Builder,
basetype)
#End If
@@ -192,6 +195,11 @@
If interfaces.Count > 0 Then
Dim types As Type() =
Helper.GetTypeOrTypeBuilders(interfaces.ToArray)
m_Builder.SetInterfaceConstraints(types)
+#If ENABLECECIL Then
+ For i As Integer = 0 To interfaces.Count - 1
+
m_CecilBuilder.Constraints.Add(Helper.GetTypeOrTypeReference(Compiler,
interfaces(i)))
+ Next
+#End If
#If DEBUGREFLECTION Then
types = Helper.DebugReflection_BuildArray(Of Type)(types)
Helper.DebugReflection_AppendLine("{0}.SetInterfaceConstraints({1})",
m_Builder, types)
@@ -203,6 +211,9 @@
End If
m_Builder.SetGenericParameterAttributes(attributes)
+#If ENABLECECIL Then
+ m_CecilBuilder.Attributes = CType(attributes,
Mono.Cecil.GenericParameterAttributes)
+#End If
#If DEBUGREFLECTION Then
Helper.DebugReflection_AppendLine("{0}.SetGenericParameterAttributes(System.Reflection.GenericParameterAttributes.{1})",
m_Builder, attributes.ToString)
#End If
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches