📄 zcompilercodegenerator.vb
字号:
For k As Integer = 0 To VB.UBound(ASSIGNMENTOPERATORS) Dim assignmentop As String = ASSIGNMENTOPERATORS(k) Dim assignmentopname As String = ASSIGNMENTOPERATORSNAME(k) Dim assignmentname As String = "AssignmentOperator_" & assignmentopname & "Assign_" & lefttype & "_" & righttype Dim resulttypecode As TypeCode = TypeConverter.GetBinaryResultType(BINARYOPERATORSKS(k), lefttypecode, righttypecode) Dim resulttype As String If resulttypecode = TypeCode.Empty Then resulttype = "Object" 'This test is supposed to fail. errname = "30452 " Else errname = "" resulttype = lefttype End If code.Length = 0 code.AppendLine("Public Module " & assignmentname & "1") code.AppendLine(vbTab & "Public Function Main() As Integer") code.AppendLine(vbTab & vbTab & "Dim rightvalue As " & righttype) code.AppendLine(vbTab & vbTab & "Dim result As " & lefttype) code.AppendLine() code.AppendLine(vbTab & vbTab & "result = " & TYPEVALUES3(i)) code.AppendLine(vbTab & vbTab & "rightvalue = " & TYPEVALUES3(j)) code.AppendLine() code.AppendLine(vbTab & vbTab & "result " & assignmentop & " rightvalue") code.AppendLine(vbTab & "End Function") code.AppendLine("End Module") WriteFile(IO.Path.Combine(path, "Assignment"), errname & assignmentname & "1.vb", code.ToString) Next Next Next End Sub Function TypeCodeToType(ByVal Code As TypeCode) As Type Select Case Code Case TypeCode.Boolean Return GetType(Boolean) Case TypeCode.Byte Return GetType(Byte) Case TypeCode.Char Return GetType(Char) Case TypeCode.DateTime Return GetType(Date) Case TypeCode.DBNull Throw New InternalException("") Case TypeCode.Decimal Return GetType(Decimal) Case TypeCode.Double Return GetType(Double) Case TypeCode.Empty Throw New InternalException("") Case TypeCode.Int16 Return GetType(Short) Case TypeCode.Int32 Return GetType(Integer) Case TypeCode.Int64 Return GetType(Long) Case TypeCode.Object Return GetType(Object) Case TypeCode.SByte Return GetType(SByte) Case TypeCode.Single Return GetType(Single) Case TypeCode.String Return GetType(String) Case TypeCode.UInt16 Return GetType(UShort) Case TypeCode.UInt32 Return GetType(UInteger) Case TypeCode.UInt64 Return GetType(ULong) Case Else Throw New InternalException("") End Select End Function Sub GenConversions() GenConversions(True) GenConversions(False) End Sub Sub GenConversions(ByVal Explicit As Boolean) Const path As String = BASEPATHTESTS & "Conversions" For i As Integer = 0 To TYPES.GetUpperBound(0) For j As Integer = 0 To TYPES.GetUpperBound(0) Dim tp1, tp2, conv As String Dim val1 As String If i = j Then Continue For tp1 = TYPES(i) tp2 = TYPES(j) val1 = TYPEVALUES(j) Dim Test As System.Text.StringBuilder = New System.Text.StringBuilder Dim name As String If Explicit Then name = "ExplicitConversion" & tp2 & "To" & tp1 & "1" conv = CONVERSIONS(i) Else name = "ImplicitConversion" & tp2 & "To" & tp1 & "1" conv = "" End If Test.AppendLine("Module " & name) Test.AppendLine(" Function Main() As Integer") Test.AppendLine(" Dim result As Boolean") Test.AppendLine(" Dim value1 As " & tp2) Test.AppendLine(" Dim value2 As " & tp1) Test.AppendLine(" Dim const2 As " & tp1) Test.AppendLine("") Test.AppendLine(" value1 = " & val1) Test.AppendLine(" value2 = " & conv & VB.IIf(Explicit, "(value1)", "value1").ToString) Test.AppendLine(" const2 = " & conv & VB.IIf(Explicit, "(" & val1 & ")", val1).ToString) Test.AppendLine("") If tp1 = "Object" Then Test.AppendLine(" result = Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(value2, const2, False)") Else Test.AppendLine(" result = value2 = const2") End If Test.AppendLine("") Test.AppendLine(" If result = False Then") Test.AppendLine(" System.Console.WriteLine(""FAIL " & name & """)") Test.AppendLine(" Return 1") Test.AppendLine(" End If") Test.AppendLine(" End Function") Test.AppendLine("End Module") Test.AppendLine() If IO.Directory.Exists(path) = False OrElse IO.Directory.GetFiles(path, "3*" & name & ".vb").Length = 0 Then 'Only write the file if it is a correct conversion. WriteFile(path, name & ".vb", Test.ToString) End If Next Next End Sub Sub GenConversions2() GenConversions2(True) GenConversions2(False) End Sub Sub GenConversions2(ByVal Explicit As Boolean) Const path As String = BASEPATHTESTS & "Conversions" Dim file As New System.Text.StringBuilder Dim name As String If Explicit Then name = "ExplicitConversion1" Else name = "ImplicitConversion1" End If file.AppendLine("Module " & name) For i As Integer = 0 To TYPES.GetUpperBound(0) For j As Integer = 0 To TYPES.GetUpperBound(0) Dim tp1, tp2, conv As String Dim val1 As String If i = j Then Continue For Dim funcname As String tp1 = TYPES(i) tp2 = TYPES(j) val1 = TYPEVALUES(j) Dim Test As System.Text.StringBuilder = New System.Text.StringBuilder If Explicit Then funcname = "ExplicitConversion" & tp2 & "To" & tp1 & "1" conv = CONVERSIONS(i) Else funcname = "ImplicitConversion" & tp2 & "To" & tp1 & "1" conv = "" End If Test.AppendLine(" Function " & funcname & "() As Integer") Test.AppendLine(" Dim result As Boolean") Test.AppendLine(" Dim value1 As " & tp2) Test.AppendLine(" Dim value2 As " & tp1) Test.AppendLine(" Dim const2 As " & tp1) Test.AppendLine("") Test.AppendLine(" value1 = " & val1) Test.AppendLine(" value2 = " & conv & VB.IIf(Explicit, "(value1)", "value1").ToString) Test.AppendLine(" const2 = " & conv & VB.IIf(Explicit, "(" & val1 & ")", val1).ToString) Test.AppendLine("") Test.AppendLine(" result = value2 = const2") Test.AppendLine("") Test.AppendLine(" If result = False Then") Test.AppendLine(" System.Console.WriteLine(""FAIL " & funcname & """)") Test.AppendLine(" Return 1") Test.AppendLine(" End If") Test.AppendLine(" End Function") file.Append(Test) Next Next file.AppendLine("End Module") file.AppendLine() WriteFile(path, name & ".vb", file.ToString) End Sub Sub GenByRefs() Const path As String = BASEPATHTESTS & "ByRefs" Dim all As New System.Text.StringBuilder Dim test As System.Text.StringBuilder For i As Integer = 0 To VB.UBound(TYPES) test = New System.Text.StringBuilder Dim type As String = TYPES(i) Dim value As String = TYPEVALUES(i) Dim value2 As String = TYPEVALUES2(i) Dim name As String = "ByRef" & type & "1" test.AppendLine("Module " & name) test.AppendLine(" Function Main() As Integer") test.AppendLine(" Dim result As Boolean") test.AppendLine(" Dim testvalue As " & type) test.AppendLine("") test.AppendLine(" testvalue = " & value2) test.AppendLine(" Tester(testvalue)") test.AppendLine(" result = testvalue = " & value) test.AppendLine("") test.AppendLine(" If result = False Then") test.AppendLine(" System.Console.WriteLine(""FAIL " & name & """)") test.AppendLine(" Return 1")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -