From c1a807a6e19e6bb3e459f4fcc2fefbaa90957a16 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Sat, 2 Apr 2005 13:55:00 +0000 Subject: [PATCH] * Makefile: Added '/r:Microsoft.VisualBasic.dll' to the compile command line. * driver.cs (UnixParseOption, CSCParseOption): Added '/optioncompare:[text|binary]' command line option. * rootcontext.cs (StringComparisonMode): Added. Keeps track of the '/optioncompare:' command line option. * typemanager.cs (InitVisualBasicHelperTypes, InitVisualBasicCodeHelpers): New routines that preload frequently used types and helper methods available in Microsoft.Visualbasic.dll. (IsFixedNumericType, IsFloatingNumericType,IsNumericType): New VB.NET specific helper routines. Added in anticipation of a future use. * ecore.cs (HelperMethodInvocation): Added. Implements the same functionality as the earlier vaguely named class 'ImplicitInvocation'. This class uses the 'type cache' of Microsoft.VisualBasic helper methods now available in the TypeManager. * convert.cs (WideningConstantConversions): Reimplemented. The earlier implementation was completely topsy-turvy. Propagated the changes relating to the introduction of 'HelperMethodInvocation'. * mb-parser.jay: Added rule and action for 'Like' expression. * mb-tokenizer.cs (keywords): Cleaned up the extra space in the 'let', 'lib' and 'like' entries. svn path=/trunk/mcs/; revision=42488 --- mcs/bmcs/ChangeLog | 35 ++++++ mcs/bmcs/Makefile | 2 +- mcs/bmcs/convert.cs | 86 +++++++-------- mcs/bmcs/driver.cs | 34 ++++++ mcs/bmcs/ecore.cs | 33 +++--- mcs/bmcs/mb-parser.jay | 5 + mcs/bmcs/mb-tokenizer.cs | 6 +- mcs/bmcs/rootcontext.cs | 7 ++ mcs/bmcs/typemanager.cs | 232 ++++++++++++++++++++++++++++++++++++++- 9 files changed, 371 insertions(+), 69 deletions(-) diff --git a/mcs/bmcs/ChangeLog b/mcs/bmcs/ChangeLog index 07b10bbadbf..67153e8f457 100644 --- a/mcs/bmcs/ChangeLog +++ b/mcs/bmcs/ChangeLog @@ -1,3 +1,38 @@ +2005-04-02 Jambunathan K + + * Makefile: Added '/r:Microsoft.VisualBasic.dll' to the compile + command line. + + * driver.cs (UnixParseOption, CSCParseOption): Added + '/optioncompare:[text|binary]' command line option. + + * rootcontext.cs (StringComparisonMode): Added. Keeps track of the + '/optioncompare:' command line option. + + * typemanager.cs (InitVisualBasicHelperTypes, + InitVisualBasicCodeHelpers): New routines that preload frequently + used types and helper methods available in + Microsoft.Visualbasic.dll. + + (IsFixedNumericType, IsFloatingNumericType,IsNumericType): New + VB.NET specific helper routines. Added in anticipation of a future + use. + + * ecore.cs (HelperMethodInvocation): Added. Implements the same + functionality as the earlier vaguely named class + 'ImplicitInvocation'. This class uses the 'type cache' of + Microsoft.VisualBasic helper methods now available in the + TypeManager. + + * convert.cs (WideningConstantConversions): Reimplemented. The + earlier implementation was completely topsy-turvy. Propagated the + changes relating to the introduction of 'HelperMethodInvocation'. + + * mb-parser.jay: Added rule and action for 'Like' expression. + + * mb-tokenizer.cs (keywords): Cleaned up the extra space in the + 'let', 'lib' and 'like' entries. + 2005-03-26 Jambunathan K * constant.cs: Added conversions between various constants diff --git a/mcs/bmcs/Makefile b/mcs/bmcs/Makefile index 28293c298ee..5be4f21bdaa 100644 --- a/mcs/bmcs/Makefile +++ b/mcs/bmcs/Makefile @@ -28,7 +28,7 @@ mb-parser.cs: mb-parser.jay $(topdir)/jay/skeleton.cs include ../build/executable.make bmcs.exe: mb-parser.cs - gmcs -d:NET_1_1 -d:ONLY_1_1 -debug /target:exe /out:bmcs.exe mb-parser.cs @bmcs.exe.sources -nowarn:219 -nowarn:162 + gmcs -d:NET_1_1 -d:ONLY_1_1 -debug /target:exe /out:bmcs.exe /r:Microsoft.VisualBasic.dll mb-parser.cs @bmcs.exe.sources -nowarn:219 -nowarn:162 winstall: all cp bmcs.exe $(prefix)/lib/mono/2.0/ diff --git a/mcs/bmcs/convert.cs b/mcs/bmcs/convert.cs index c30d96b0cca..7a2edb02733 100644 --- a/mcs/bmcs/convert.cs +++ b/mcs/bmcs/convert.cs @@ -572,9 +572,9 @@ namespace Mono.CSharp { // From decimal to float, double // if (real_target_type == TypeManager.double_type) - return new ImplicitInvocation (ec, "System", "Convert", "ToDouble", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.double_type, TypeManager.convert_to_double_decimal, expr); if (real_target_type == TypeManager.float_type) - return new ImplicitInvocation (ec, "System", "Convert" ,"ToSingle", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.float_type, TypeManager.convert_to_single_decimal, expr); } return null; @@ -1450,26 +1450,26 @@ namespace Mono.CSharp { Type const_expr_type = const_expr.Type; Location loc = const_expr.Location; + if (target_type == TypeManager.byte_type){ + if (const_expr_type == TypeManager.short_type || + const_expr_type == TypeManager.int32_type || + const_expr_type == TypeManager.int64_type) + return const_expr.ToByte (loc); + } + if (target_type == TypeManager.short_type){ - if (const_expr_type == TypeManager.byte_type) - return const_expr.ToShort (loc); + if (const_expr_type == TypeManager.int32_type || + const_expr_type == TypeManager.int64_type) + return const_expr.ToShort (loc); } if (target_type == TypeManager.int32_type){ - if (const_expr_type == TypeManager.byte_type || - const_expr_type == TypeManager.short_type) + if (const_expr_type == TypeManager.int64_type) return const_expr.ToInt (loc); } - if (target_type == TypeManager.int64_type){ - if (const_expr_type == TypeManager.byte_type || - const_expr_type == TypeManager.short_type || - const_expr_type == TypeManager.int32_type) - return const_expr.ToLong (loc); - } - - if (target_type == TypeManager.double_type) { - if (const_expr_type == TypeManager.float_type) + if (target_type == TypeManager.float_type) { + if (const_expr_type == TypeManager.double_type) return const_expr.ToDouble (loc); } @@ -1774,13 +1774,13 @@ namespace Mono.CSharp { // From decimal to byte, short, int, long // if (real_target_type == TypeManager.byte_type) - return new ImplicitInvocation (ec, "System", "Convert" , "ToByte", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.byte_type, TypeManager.convert_to_byte_decimal, expr); if (real_target_type == TypeManager.short_type) - return new ImplicitInvocation (ec, "System", "Convert", "ToInt16", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.short_type, TypeManager.convert_to_int16_decimal, expr); if (real_target_type == TypeManager.int32_type) - return new ImplicitInvocation (ec, "System", "Convert", "ToInt32", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.int32_type, TypeManager.convert_to_int32_decimal, expr); if (real_target_type == TypeManager.int64_type) - return new ImplicitInvocation (ec, "System", "Convert", "ToInt64", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.int64_type, TypeManager.convert_to_int64_decimal, expr); } return null; @@ -1816,7 +1816,7 @@ namespace Mono.CSharp { if (real_target_type == TypeManager.double_type) return new BooleanToNumericCast (expr, target_type, OpCodes.Conv_R8); if (real_target_type == TypeManager.decimal_type) { - return new ImplicitInvocation (ec, "DecimalType", "FromBoolean", loc, expr); + return new HelperMethodInvocation (ec, expr.Location, TypeManager.decimal_type, TypeManager.msvbcs_decimaltype_from_boolean, expr); } } if (real_target_type == TypeManager.bool_type) { @@ -1833,7 +1833,7 @@ namespace Mono.CSharp { expr_type == TypeManager.double_type) return new NumericToBooleanCast (expr, expr_type); if (expr_type == TypeManager.decimal_type) { - return new ImplicitInvocation (ec, "System", "Convert", "ToBoolean", loc, expr); + return new HelperMethodInvocation (ec, expr.Location, TypeManager.bool_type, TypeManager.convert_to_boolean_decimal, expr); } } @@ -1856,7 +1856,7 @@ namespace Mono.CSharp { // From char to string // if (expr_type == TypeManager.char_type) - return new ImplicitInvocation (ec, "StringType", "FromChar", loc, expr); + return new HelperMethodInvocation (ec, expr.Location, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_char, expr); } if(expr_type.IsArray && (expr_type.GetElementType() == TypeManager.char_type)) { @@ -1889,28 +1889,28 @@ namespace Mono.CSharp { // float, double, decimal and date // - if (real_target_type.IsArray && (real_target_type.GetElementType() == TypeManager.char_type)) - return new ImplicitInvocation (ec, "CharArrayType", "FromString", loc, expr); +// if (real_target_type.IsArray && (real_target_type.GetElementType() == TypeManager.char_type)) +// return new HelperMethodInvocation (ec, loc, TypeManager.char_array_type, TypeManager.msvbcs_char_array_type_from_string, loc, expr); if (real_target_type == TypeManager.bool_type) - return new ImplicitInvocation (ec, "BooleanType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.bool_type, TypeManager.msvbcs_booleantype_from_string, expr); if (real_target_type == TypeManager.byte_type) - return new ImplicitInvocation (ec, "ByteType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.byte_type, TypeManager.msvbcs_bytetype_from_string, expr); if (real_target_type == TypeManager.short_type) - return new ImplicitInvocation (ec, "ShortType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.short_type, TypeManager.msvbcs_shorttype_from_string, expr); if (real_target_type == TypeManager.char_type) - return new ImplicitInvocation (ec, "CharType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.char_type, TypeManager.msvbcs_chartype_from_string, expr); if (real_target_type == TypeManager.int32_type) - return new ImplicitInvocation (ec, "IntegerType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.int32_type, TypeManager.msvbcs_integertype_from_string, expr); if (real_target_type == TypeManager.int64_type) - return new ImplicitInvocation (ec, "LongType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.int64_type, TypeManager.msvbcs_longtype_from_string, expr); if (real_target_type == TypeManager.float_type) - return new ImplicitInvocation (ec, "SingleType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.float_type, TypeManager.msvbcs_singletype_from_string, expr); if (real_target_type == TypeManager.double_type) - return new ImplicitInvocation (ec, "DoubleType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.double_type, TypeManager.msvbcs_doubletype_from_string, expr); if (real_target_type == TypeManager.decimal_type) - return new ImplicitInvocation (ec, "DecimalType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.decimal_type, TypeManager.msvbcs_decimaltype_from_string, expr); if (real_target_type == TypeManager.date_type) - return new ImplicitInvocation (ec, "DateType", "FromString", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.date_type, TypeManager.msvbcs_datetype_from_string, expr); } if (real_target_type == TypeManager.string_type) { // @@ -1920,23 +1920,23 @@ namespace Mono.CSharp { // if (expr_type == TypeManager.bool_type) - return new ImplicitInvocation (ec, "StringType", "FromBoolean", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_boolean, expr); if (expr_type == TypeManager.byte_type) - return new ImplicitInvocation (ec, "StringType", "FromByte", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_byte, expr); if (expr_type == TypeManager.short_type) - return new ImplicitInvocation (ec, "StringType", "FromShort", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_short, expr); if (expr_type == TypeManager.int32_type) - return new ImplicitInvocation (ec, "StringType", "FromInteger", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_integer, expr); if (expr_type == TypeManager.int64_type) - return new ImplicitInvocation (ec, "StringType", "FromLong", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_long, expr); if (expr_type == TypeManager.float_type) - return new ImplicitInvocation (ec, "StringType", "FromSingle", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_single, expr); if (expr_type == TypeManager.double_type) - return new ImplicitInvocation (ec, "StringType", "FromDouble", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_double, expr); if (expr_type == TypeManager.decimal_type) - return new ImplicitInvocation (ec, "StringType", "FromDecimal", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_decimal, expr); if (expr_type == TypeManager.date_type) - return new ImplicitInvocation (ec, "StringType", "FromDate", loc, expr); + return new HelperMethodInvocation (ec, loc, TypeManager.string_type, TypeManager.msvbcs_stringtype_from_date, expr); } return null; diff --git a/mcs/bmcs/driver.cs b/mcs/bmcs/driver.cs index e348b92d7b7..2e2d2d3d692 100644 --- a/mcs/bmcs/driver.cs +++ b/mcs/bmcs/driver.cs @@ -20,6 +20,7 @@ namespace Mono.CSharp using System.Text; using System.Globalization; using System.Xml; + using Microsoft.VisualBasic; public enum Target { Library, Exe, Module, WinExe @@ -237,6 +238,7 @@ namespace Mono.CSharp // " -removeintchecks[+|-] Set default context to unchecked\n" + " -optionstrict[+|-] Enables stricter type checking\n" + + " -optioncompare:[text|binary] Specifies the default mode for character comparisons\n" + "\n" + "Resources:\n" + @@ -905,6 +907,23 @@ namespace Mono.CSharp case "--optionstrict": RootContext.StricterTypeChecking= true; return true; + + case "--optioncompare": + if ((i + 1) >= args.Length){ + Usage (); + Environment.Exit (1); + } + + if (args [++i].Equals ("text")) + RootContext.StringComparisonMode = CompareMethod.Text; + else if (args[++i].Equals ("binary")) + RootContext.StringComparisonMode = CompareMethod.Binary; + else { + Report.Error (5, "Invalid argument to --optioncompare"); + Environment.Exit (1); + } + + return true; } @@ -1345,6 +1364,21 @@ namespace Mono.CSharp RootContext.StricterTypeChecking = false; return true; + case "/optioncompare": + if (value == ""){ + Report.Error (5, arg + " requires an argument"); + Environment.Exit (1); + } + if (value.Equals ("text")) + RootContext.StringComparisonMode = CompareMethod.Text; + else if (value.Equals ("binary")) + RootContext.StringComparisonMode = CompareMethod.Binary; + else { + Report.Error (5, "Invalid argument to /optioncompare"); + Environment.Exit (1); + } + return true; + } //Report.Error (2007, String.Format ("Unrecognized command-line option: '{0}'", option)); //Environment.Exit (1); diff --git a/mcs/bmcs/ecore.cs b/mcs/bmcs/ecore.cs index cac8e71c8f7..51ca97ab8f1 100644 --- a/mcs/bmcs/ecore.cs +++ b/mcs/bmcs/ecore.cs @@ -1500,33 +1500,27 @@ namespace Mono.CSharp { /// - /// ImplicitInvocation of methods or delegates. Used by the + /// HelperMethodInvocation of methods or delegates. Used by the /// VB.NET compiler specifically to emit calls to the /// Microsoft.VisualBasic.CompilerServices helper routines /// - public class ImplicitInvocation : Expression + public class HelperMethodInvocation : Expression { - const string DEFAULT_NS_PREFIX = "Microsoft.VisualBasic.CompilerServices"; - - Expression child; + ArrayList args; + MethodInfo method; - public ImplicitInvocation (EmitContext ec, string klass, string method, Location l, params Expression [] exprs) - : this (ec, DEFAULT_NS_PREFIX, klass, method, l, exprs) - { - } - - public ImplicitInvocation (EmitContext ec, string ns, string klass, string method, Location l, params Expression [] exprs) + public HelperMethodInvocation (EmitContext ec, Location l, Type return_type, MethodInfo method, params Expression [] exprs) { - ArrayList args = new ArrayList (); - string name = ns + "." + klass + "." + method; - + args = new ArrayList (); foreach (Expression expr in exprs) args.Add (new Argument (expr, Argument.AType.Expression)); - child = new Invocation (StringToExpression (name, l), args, l).Resolve (ec); - eclass = child.eclass; - type = child.Type; + + this.loc = l; + this.method = method; + type = return_type; + eclass = ExprClass.Value; } public override Expression DoResolve (EmitContext ec) @@ -1536,7 +1530,8 @@ namespace Mono.CSharp { public override void Emit (EmitContext ec) { - child.Emit (ec); + Invocation.EmitArguments (ec, method, args, false, null); + ec.ig.Emit (OpCodes.Call, method); } } @@ -2214,7 +2209,7 @@ namespace Mono.CSharp { // public class FloatingToFixedCast : ConvCast { public FloatingToFixedCast (EmitContext ec, Expression child, Type return_type, Mode mode) - : base (ec, new ImplicitInvocation (ec, "System", "Math", "Round", child.Location, + : base (ec, new HelperMethodInvocation (ec, child.Location, TypeManager.double_type, TypeManager.math_round_double, (child.Type == TypeManager.float_type) ? new OpcodeCast (child, TypeManager.double_type, OpCodes.Conv_R8) : child), return_type, mode) diff --git a/mcs/bmcs/mb-parser.jay b/mcs/bmcs/mb-parser.jay index fd5d941f977..98c17d372dd 100644 --- a/mcs/bmcs/mb-parser.jay +++ b/mcs/bmcs/mb-parser.jay @@ -4578,6 +4578,11 @@ relational_expression $$ = new Binary (Binary.Operator.Is, (Expression) $1, (Expression) $3, lexer.Location); } + | relational_expression LIKE shift_expression + { + $$ = new Binary (Binary.Operator.Like, + (Expression) $1, (Expression) $3, lexer.Location); + } | TYPEOF shift_expression IS type { $$ = new Is ((Expression) $2, (Expression) $4, lexer.Location); diff --git a/mcs/bmcs/mb-tokenizer.cs b/mcs/bmcs/mb-tokenizer.cs index b0127adf3be..79755b7ab12 100644 --- a/mcs/bmcs/mb-tokenizer.cs +++ b/mcs/bmcs/mb-tokenizer.cs @@ -207,9 +207,9 @@ namespace Mono.CSharp keywords.Add ("integer", Token.INTEGER); keywords.Add ("interface", Token.INTERFACE); keywords.Add ("is", Token.IS); - keywords.Add ("let ", Token.LET ); // An unused VB.NET keyword - keywords.Add ("lib ", Token.LIB ); - keywords.Add ("like ", Token.LIKE ); + keywords.Add ("let", Token.LET ); // An unused VB.NET keyword + keywords.Add ("lib", Token.LIB ); + keywords.Add ("like", Token.LIKE ); keywords.Add ("long", Token.LONG); keywords.Add ("loop", Token.LOOP); keywords.Add ("me", Token.ME); diff --git a/mcs/bmcs/rootcontext.cs b/mcs/bmcs/rootcontext.cs index 285889ffe09..de8707c8117 100644 --- a/mcs/bmcs/rootcontext.cs +++ b/mcs/bmcs/rootcontext.cs @@ -15,6 +15,7 @@ using System.Reflection; using System.Reflection.Emit; using System.Diagnostics; using System.Xml; +using Microsoft.VisualBasic; namespace Mono.CSharp { @@ -141,6 +142,12 @@ namespace Mono.CSharp { // The default type checking state // static public bool StricterTypeChecking = false; + + // + // The default character comparison mode + // + + static public CompareMethod StringComparisonMode = CompareMethod.Binary; static string MakeFQN (string nsn, string name) { diff --git a/mcs/bmcs/typemanager.cs b/mcs/bmcs/typemanager.cs index 19895fa4256..f25ccdb1d2b 100644 --- a/mcs/bmcs/typemanager.cs +++ b/mcs/bmcs/typemanager.cs @@ -100,6 +100,31 @@ public partial class TypeManager { static public Type security_attr_type; static public Type date_type; + // + // Used with VB.NET + // + static public Type convert_type; + static public Type math_type; + + // + // Type cache of helper classes in Microsoft.VisualBasic.dll + // + + static public Type msvbcs_boolean_type; + static public Type msvbcs_byte_type; + static public Type msvbcs_short_type; + static public Type msvbcs_integer_type; + static public Type msvbcs_long_type; + static public Type msvbcs_decimal_type; + static public Type msvbcs_single_type; + static public Type msvbcs_double_type; + static public Type msvbcs_string_type; + static public Type msvbcs_char_type; + static public Type msvbcs_chararray_type; + static public Type msvbcs_date_type; + + static public Type msvbcs_comparemethod_type; + // // Unlike C#, VB.NET doesn't understand "signed byte", // "unsigned short" and "unsigned int" as primitive types. The @@ -231,9 +256,47 @@ public partial class TypeManager { static public ConstructorInfo decimal_constant_attribute_ctor; // - // VB.NET specific - // - + // Type cache of helper methods in Microsoft.VisualBasic.dll + // + static public MethodInfo convert_to_byte_decimal; + static public MethodInfo convert_to_int16_decimal; + static public MethodInfo convert_to_int32_decimal; + static public MethodInfo convert_to_int64_decimal; + static public MethodInfo convert_to_single_decimal; + static public MethodInfo convert_to_double_decimal; + static public MethodInfo convert_to_boolean_decimal; + + static public MethodInfo decimal_compare_decimal_decimal; + static public MethodInfo datetime_compare_datetime_datetime; + static public MethodInfo math_round_double; + + static public MethodInfo msvbcs_booleantype_from_string; + static public MethodInfo msvbcs_bytetype_from_string; + static public MethodInfo msvbcs_shorttype_from_string; + static public MethodInfo msvbcs_integertype_from_string; + static public MethodInfo msvbcs_longtype_from_string; + static public MethodInfo msvbcs_decimaltype_from_string; + static public MethodInfo msvbcs_singletype_from_string; + static public MethodInfo msvbcs_doubletype_from_string; + static public MethodInfo msvbcs_chartype_from_string; + static public MethodInfo msvbcs_datetype_from_string; + + static public MethodInfo msvbcs_stringtype_from_boolean; + static public MethodInfo msvbcs_stringtype_from_byte; + static public MethodInfo msvbcs_stringtype_from_short; + static public MethodInfo msvbcs_stringtype_from_integer; + static public MethodInfo msvbcs_stringtype_from_long; + static public MethodInfo msvbcs_stringtype_from_decimal; + static public MethodInfo msvbcs_stringtype_from_single; + static public MethodInfo msvbcs_stringtype_from_double; + static public MethodInfo msvbcs_stringtype_from_date; + static public MethodInfo msvbcs_stringtype_from_char; + + static public MethodInfo msvbcs_decimaltype_from_boolean; + + static public MethodInfo msvbcs_stringtype_strcmp_string_string_boolean; + static public MethodInfo msvbcs_stringtype_strlike_string_string_comparemethod; + static public ConstructorInfo void_datetime_ctor_ticks_arg; // @@ -1164,7 +1227,9 @@ public partial class TypeManager { // // VB.NET Specific // + convert_type = CoreLookupType ("System.Convert"); date_type = CoreLookupType ("System.DateTime"); + math_type = CoreLookupType ("System.Math"); multicast_delegate_type = CoreLookupType ("System.MulticastDelegate"); delegate_type = CoreLookupType ("System.Delegate"); @@ -1326,6 +1391,30 @@ public partial class TypeManager { // anonymous_method_type = typeof (AnonymousMethod); null_type = typeof (NullType); + + InitVisualBasicHelperTypes (); + } + + // + // This method preloads helper types in Microsoft.VisualBasic.dll for later use + // + public static void InitVisualBasicHelperTypes () + { + msvbcs_boolean_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.BooleanType"); + msvbcs_byte_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.ByteType"); + msvbcs_short_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.ShortType"); + msvbcs_integer_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.IntegerType"); + msvbcs_long_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.LongType"); + msvbcs_decimal_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.DecimalType"); + msvbcs_single_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.SingleType"); + msvbcs_double_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.DoubleType"); + + msvbcs_char_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.CharType"); + msvbcs_chararray_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.CharArrayType"); + msvbcs_date_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.DateType"); + msvbcs_string_type = CoreLookupType ("Microsoft.VisualBasic.CompilerServices.StringType"); + + msvbcs_comparemethod_type = CoreLookupType ("Microsoft.VisualBasic.CompareMethod"); } // @@ -1374,6 +1463,39 @@ public partial class TypeManager { delegate_remove_delegate_delegate = GetMethod ( delegate_type, "Remove", delegate_delegate); + // + // VB.NET specific + // + + Type [] decimal_arg = { decimal_type }; + convert_to_byte_decimal = GetMethod ( + convert_type, "ToByte", decimal_arg); + convert_to_int16_decimal = GetMethod ( + convert_type, "ToInt16", decimal_arg); + convert_to_int32_decimal = GetMethod ( + convert_type, "ToInt32", decimal_arg); + convert_to_int64_decimal = GetMethod ( + convert_type, "ToInt64", decimal_arg); + convert_to_single_decimal = GetMethod ( + convert_type, "ToSingle", decimal_arg); + convert_to_double_decimal = GetMethod ( + convert_type, "ToDouble", decimal_arg); + convert_to_boolean_decimal = GetMethod ( + convert_type, "ToBoolean", decimal_arg); + + Type [] decimal_decimal = { decimal_type, decimal_type }; + decimal_compare_decimal_decimal = GetMethod ( + decimal_type, "Compare", decimal_decimal); + + Type [] datetime_datetime = { date_type, date_type }; + datetime_compare_datetime_datetime = GetMethod ( + date_type, "Compare", datetime_datetime); + + Type [] double_arg = { double_type }; + math_round_double = GetMethod ( + math_type, "Round", double_arg); + + // // Void arguments // @@ -1475,6 +1597,80 @@ public partial class TypeManager { object_ctor = GetConstructor (object_type, void_arg); InitGenericCodeHelpers (); + InitVisualBasicCodeHelpers (); + } + + + // + // This method preloads helper methods that are used by the VB.NET compiler + // + public static void InitVisualBasicCodeHelpers () + { + Type [] boolean_arg = { bool_type }; + Type [] byte_arg = { byte_type }; + Type [] short_arg = { short_type }; + Type [] integer_arg = { int32_type }; + Type [] long_arg = { int64_type }; + Type [] decimal_arg = { decimal_type }; + Type [] single_arg = { float_type }; + Type [] double_arg = { double_type }; + Type [] char_arg = { char_type }; + Type [] string_arg = { string_type }; + Type [] date_arg = { date_type }; + + msvbcs_booleantype_from_string = GetMethod ( + msvbcs_boolean_type, "FromString", string_arg); + msvbcs_bytetype_from_string = GetMethod ( + msvbcs_byte_type, "FromString", string_arg); + msvbcs_shorttype_from_string = GetMethod ( + msvbcs_short_type, "FromString", string_arg); + msvbcs_integertype_from_string = GetMethod ( + msvbcs_integer_type, "FromString", string_arg); + msvbcs_longtype_from_string = GetMethod ( + msvbcs_long_type, "FromString", string_arg); + msvbcs_decimaltype_from_string = GetMethod ( + msvbcs_decimal_type, "FromString", string_arg); + msvbcs_singletype_from_string = GetMethod ( + msvbcs_single_type, "FromString", string_arg); + msvbcs_doubletype_from_string = GetMethod ( + msvbcs_double_type, "FromString", string_arg); + msvbcs_chartype_from_string = GetMethod ( + msvbcs_char_type, "FromString", string_arg); + msvbcs_datetype_from_string = GetMethod ( + msvbcs_date_type, "FromString", string_arg); + + msvbcs_stringtype_from_boolean = GetMethod ( + msvbcs_string_type, "FromBoolean", boolean_arg); + msvbcs_stringtype_from_byte = GetMethod ( + msvbcs_string_type, "FromByte", byte_arg); + msvbcs_stringtype_from_short = GetMethod ( + msvbcs_string_type, "FromShort", short_arg); + msvbcs_stringtype_from_integer = GetMethod ( + msvbcs_string_type, "FromInteger", integer_arg); + msvbcs_stringtype_from_long = GetMethod ( + msvbcs_string_type, "FromLong", long_arg); + msvbcs_stringtype_from_decimal = GetMethod ( + msvbcs_string_type, "FromDecimal", decimal_arg); + msvbcs_stringtype_from_single = GetMethod ( + msvbcs_string_type, "FromSingle", single_arg); + msvbcs_stringtype_from_double = GetMethod ( + msvbcs_string_type, "FromDouble", double_arg); + msvbcs_stringtype_from_date = GetMethod ( + msvbcs_string_type, "FromDate", date_arg); + msvbcs_stringtype_from_char = GetMethod ( + msvbcs_string_type, "FromChar", char_arg); + + msvbcs_decimaltype_from_boolean = GetMethod ( + msvbcs_decimal_type, "FromBoolean", boolean_arg); + + Type [] string_string_boolean_arg = { string_type, string_type, bool_type }; + msvbcs_stringtype_strcmp_string_string_boolean = GetMethod ( + msvbcs_string_type, "StrCmp", string_string_boolean_arg); + + Type [] string_string_comparemethod_arg = { string_type, string_type, msvbcs_comparemethod_type }; + msvbcs_stringtype_strlike_string_string_comparemethod = GetMethod ( + msvbcs_string_type, "StrLike", string_string_comparemethod_arg); + } const BindingFlags instance_and_static = BindingFlags.Static | BindingFlags.Instance; @@ -1661,6 +1857,36 @@ public partial class TypeManager { return false; } + // + // The following three methods are used by the VB.NET compiler + // + + public static bool IsFixedNumericType (Type type) + { + if (type == byte_type || type == short_type || + type == int32_type || type == int64_type) + return true; + + return false; + } + + public static bool IsFloatingNumericType (Type type) + { + if (type == decimal_type || + type == float_type || type == double_type) + return true; + + return false; + } + + public static bool IsNumericType (Type type) + { + if (IsFixedNumericType (type) || IsFloatingNumericType(type)) + return true; + + return false; + } + public static bool IsDelegateType (Type t) { if (t.IsGenericInstance) -- 2.25.1