2001-12-20 Miguel de Icaza <miguel@ximian.com>
+ * literal.cs: Revert code from ravi that checked the bounds. The
+ bounds are sane by the definition of the type itself.
+
+ * typemanager.cs: Fix implementation of ImplementsInterface. We
+ need to actually look up in our parent hierarchy for interfaces
+ implemented.
+
* const.cs: Use the underlying type for enumerations
* delegate.cs: Compute the basename for the delegate creation,
//
//
+//
+// This is needed because the following situation arises:
+//
+// The FieldBuilder is declared with the real type for an enumeration
+//
+// When we attempt to set the value for the constant, the FieldBuilder.SetConstant
+// function aborts because it requires its argument to be of the same type
+//
+
namespace Mono.CSharp {
using System;
}
}
+ void dump_tree (Type t)
+ {
+ Console.WriteLine ("Dumping hierarchy");
+ while (t != null){
+ Console.WriteLine (" " + t.FullName + " " +
+ (t.GetType ().IsEnum ? "yes" : "no"));
+ t = t.BaseType;
+ }
+ }
+
/// <summary>
/// Defines the constant in the @parent
/// </summary>
} else if ((ModFlags & Modifiers.NEW) != 0)
WarningNotHiding (parent);
- if (type.IsSubclassOf (TypeManager.enum_type)){
- type = System.Enum.GetUnderlyingType (type);
- }
-
FieldBuilder = parent.TypeBuilder.DefineField (Name, type, FieldAttr);
TypeManager.RegisterConstant (FieldBuilder, this);
}
ConstantValue = ((Literal) Expr).GetValue ();
+
+ if (type.IsEnum){
+ //
+ // This sadly does not work for our user-defined enumerations types ;-(
+ //
+ ConstantValue = System.Enum.ToObject (
+ type, ConstantValue);
+ }
FieldBuilder.SetConstant (ConstantValue);
" --checked Set default context to checked\n" +
" --define SYM Defines the symbol SYM\n" +
" --fatal Makes errors fatal\n" +
+ " --stacktrace Shows stack trace at error location\n" +
" -L PATH Adds PATH to the assembly link path\n" +
" --nostdlib Does not load core libraries\n" +
" --nowarn XXX Ignores warning number XXX\n" +
static public int LoadReferences ()
{
int errors = 0;
-
- foreach (string r in references){
+
+ foreach (string r in references)
errors += LoadAssembly (r);
- }
return errors;
}
if (arg.StartsWith ("@")){
string [] new_args, extra_args;
-
- extra_args = LoadArgs (arg.Substring (1));
+ string response_file = arg.Substring (1);
+
+ extra_args = LoadArgs (response_file);
if (extra_args == null){
- Usage (true);
+ Report.Error (2011, "Unable to open response file: " +
+ response_file);
return;
}
case "--checked":
RootContext.Checked = true;
continue;
+
+ case "--stacktrace":
+ Report.Stacktrace = true;
+ continue;
case "--target":
if ((i + 1) >= argc){
return new IntLiteral ((int) ((byte)v));
else if (t == TypeManager.char_type)
return new IntLiteral ((int) ((char)v));
- else
+ else if (TypeManager.IsEnumType (t)){
+ Expression e = Literalize (v, v.GetType ());
+
+ return new EnumLiteral (e, t);
+ } else
throw new Exception ("Unknown type for literal (" + t +
"), details: " + v);
}
else if (mi is PropertyInfo)
return new PropertyExpr ((PropertyInfo) mi, loc);
else if (mi is Type){
- return new TypeExpr ((Type) mi);
+ return new TypeExpr ((System.Type) mi);
}
return null;
throw new Exception ("Invalid enumeration underlying type: " + t);
}
+ //
+ // Extracts the value in the enumeration on its native representation
+ //
+ public object GetPlainValue ()
+ {
+ Type t = Child.Type.UnderlyingSystemType;
+ object v = ((Literal) Child).GetValue ();;
+
+ if (t == TypeManager.int32_type)
+ return (int) v;
+ if (t == TypeManager.uint32_type)
+ return (uint) v;
+ if (t == TypeManager.int64_type)
+ return (long) v;
+ if (t == TypeManager.uint64_type)
+ return (ulong) v;
+ if (t == TypeManager.short_type)
+ return (short) v;
+ if (t == TypeManager.ushort_type)
+ return (ushort) v;
+ if (t == TypeManager.byte_type)
+ return (byte) v;
+ if (t == TypeManager.sbyte_type)
+ return (sbyte) v;
+
+ return null;
+ }
+
public override string AsString ()
{
return ((Literal) Child).AsString ();
if (c != null) {
object o = c.LookupConstantValue (ec);
- Expression l = Literalize (o, fi.FieldType);
+ object real_value = ((Literal)c.Expr).GetValue ();
+ Expression l = Literalize (real_value, fi.FieldType);
l = l.Resolve (ec);
return ((Literal) l);
}
return new StringLiteral (ls.Value + rs.Value);
}
- if (left is EnumLiteral)
- left = ((EnumLiteral) left).WidenToCompilerLiteral ();
- if (right is EnumLiteral)
- right = ((EnumLiteral) right).WidenToCompilerLiteral ();
+ Type result_type = null;
+ object l, r;
+ //
+ // Enumerator folding
+ //
+ if (left.Type == right.Type && left is EnumLiteral){
+ result_type = left.Type;
+
+ l = ((EnumLiteral)left).GetPlainValue ();
+ r = ((EnumLiteral)right).GetPlainValue ();
+ } else {
+ l = left;
+ r = right;
+ }
+
switch (oper){
- case Operator.BitwiseOr:
- if (left is IntLiteral && right is IntLiteral){
- IntLiteral ll = (IntLiteral) left;
- IntLiteral rl = (IntLiteral) right;
-
- return new IntLiteral (ll.Value | rl.Value).Resolve (ec);
- }
- break;
+ case Operator.BitwiseOr:
+ if ((l is int) && (r is int)){
+ IntLiteral v;
+ int res = (int)l | (int)r;
+
+ v = new IntLiteral (res);
+ if (result_type == null)
+ return v.Resolve (ec);
+ else
+ return new EnumLiteral (v.Resolve (ec), result_type);
+ }
+ break;
+
+ case Operator.BitwiseAnd:
+ if ((l is int) && (r is int)){
+ IntLiteral v;
+ int res = (int)l & (int)r;
+
+ v = new IntLiteral (res);
+ if (result_type == null)
+ return v.Resolve (ec);
+ else
+ return new EnumLiteral (v.Resolve (ec), result_type);
+ }
+ break;
}
return null;
return ee;
}
}
-
- Console.WriteLine ("Support for [" + member_lookup + "] is not present yet");
+
+ Report.Error (-100, loc, "Support for [" + member_lookup + "] is not present yet");
Environment.Exit (0);
return null;
}
public override object GetValue ()
{
- if (Value <= System.Int32.MaxValue &&
- Value >= System.Int32.MinValue)
- return (object) Value;
- else
- return null;
+ return (object) Value;
}
public override Expression DoResolve (EmitContext ec)
public override object GetValue ()
{
- if (Value <= System.UInt32.MaxValue &&
- Value >= System.UInt32.MinValue)
- return (object) Value;
- else
- return null;
-
+ return (object) Value;
}
public override Expression DoResolve (EmitContext ec)
public override object GetValue ()
{
- if (Value <= System.Int64.MaxValue &&
- Value >= System.Int64.MinValue)
- return (object) Value;
- else
- return null;
+ return (object) Value;
}
public override Expression DoResolve (EmitContext ec)
public override object GetValue ()
{
- if (Value <= System.UInt64.MaxValue &&
- Value >= System.UInt64.MinValue)
- return (object) Value;
- else
- return null;
+ return (object) Value;
}
public override Expression DoResolve (EmitContext ec)
using System;
using System.Collections;
+using System.Diagnostics;
namespace Mono.CSharp {
/// This class is used to report errors and warnings t te user.
/// </summary>
public class Report {
- static int errors;
- static int warnings;
-
- // whether errors are fatal (they throw an exception), useful
- // for debugging the compiler
- static bool fatal;
-
- // whether we consider warnings to be errors.
- static bool warnings_are_errors;
+ /// <summary>
+ /// Errors encountered so far
+ /// </summary>
+ static public int Errors;
+
+ /// <summary>
+ /// Warnings encountered so far
+ /// </summary>
+ static public int Warnings;
+
+ /// <summary>
+ /// Whether errors should be throw an exception
+ /// </summary>
+ static public bool Fatal;
+
+ /// <summary>
+ /// Whether warnings should be considered errors
+ /// </summary>
+ static public bool WarningsAreErrors;
+
+ /// <summary>
+ /// Whether to dump a stack trace on errors.
+ /// </summary>
+ static public bool Stacktrace;
//
// If the error code is reported on the given line,
static public void RealError (string msg)
{
- errors++;
+ Errors++;
Console.WriteLine (msg);
- if (fatal)
+ if (Stacktrace)
+ Console.WriteLine (new StackTrace ().ToString ());
+ if (Fatal)
throw new Exception (msg);
}
return;
}
- if (warnings_are_errors)
+ if (WarningsAreErrors)
Error (code, l, text);
else {
string row;
row = l.Row.ToString ();
Console.WriteLine (l.Name + "(" + row + "): warning CS"+code+": " + text);
- warnings++;
+ Warnings++;
Check (code);
}
}
return probe_error;
}
}
-
- static public int Errors {
- get {
- return errors;
- }
- }
-
- static public int Warnings {
- get {
- return warnings;
- }
- }
-
- static public bool Fatal {
- set {
- fatal = true;
- }
-
- get {
- return fatal;
- }
- }
-
- static public bool WarningsAreErrors {
- set {
- warnings_are_errors = true;
- }
- }
}
public class Message {
{
Type t = LookupType (name);
- if (t == null)
- throw new Exception ("Can not find core type " + name);
+ if (t == null){
+ Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
+ Environment.Exit (0);
+ }
return t;
}
// </remarks>
static Hashtable type_interface_cache;
-
public static bool ImplementsInterface (Type t, Type iface)
{
- Type [] interfaces = (Type []) type_interface_cache [t];
+ Type [] interfaces;
- if (interfaces == null) {
- if (type_interface_cache.Contains (t))
- return false;
-
+ do {
interfaces = t.GetInterfaces ();
- type_interface_cache [t] = interfaces;
- }
-
- if (interfaces == null)
- return false;
-
- for (int i = interfaces.Length; i > 0; ) {
- i--;
- if (interfaces [i] == iface)
- return true;
- }
-
+ for (int i = interfaces.Length; i > 0; ){
+ i--;
+ if (interfaces [i] == iface)
+ return true;
+ }
+ t = t.BaseType;
+ } while (t != null);
+
return false;
}