Author: miguel
Date: 2005-04-13 22:13:10 -0400 (Wed, 13 Apr 2005)
New Revision: 42975
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/class.cs
trunk/mcs/mcs/codegen.cs
trunk/mcs/mcs/decl.cs
trunk/mcs/mcs/expression.cs
trunk/mcs/mcs/flowanalysis.cs
trunk/mcs/mcs/iterators.cs
trunk/mcs/mcs/statement.cs
trunk/mcs/mcs/typemanager.cs
Log:
Revert patch from revision 42775, it introduced a regression
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/ChangeLog 2005-04-14 02:13:10 UTC (rev 42975)
@@ -67,35 +67,6 @@
* typemanager.cs (IsUnmanagedType): Arrays are allowed.
-2005-04-11 Marek Safar <[EMAIL PROTECTED]>
-
- Fix# 74565
- * class.cs (TypeContainer.CircularDepException) New nested
- exception class.
- (GetPartialBases, GetNormalBases, GetClassBases): Removed error.
- (TypeContainer.DefineType): Removed error, reset InTransit before
- exit.
- (Class.DefineType): Throw exception when is in Transit.
- Catch exception and report error.
- (Struct.DefineType): Throw exception when is in Transit.
- Catch exception and report error.
- (Interface.DefineType): Throw exception when is in Transit.
- Catch exception and report error.
-
- * codegen.cs: Add InCatch,InFinally to EmitContext to easily
- handle nested exception handlers.
-
- * flowanalysis.cs (InTryWithCatch): New method, search for try with
- a catch.
-
- * iterators.cs (Yield.CheckContext): Add CS1626 report. Updated
- InFinally and InCatch storage.
-
- * statement.cs (Throw.Resolve): Use InCatch, InFinally from ec.
- (Catch.Resolve): Set and Restore ec.InCatch.
- (Try.Resolve): Set and Restore ec.InFinally.
- (Try.HasCatch): True when try has catch.
-
2005-04-10 Miguel de Icaza <[EMAIL PROTECTED]>
* driver.cs (MainDriver): Stop processing if the CLS stage found
Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/class.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -64,15 +64,6 @@
/// </summary>
public abstract class TypeContainer : DeclSpace, IMemberContainer {
- protected class CircularDepException: Exception
- {
- public TypeContainer Container;
- public CircularDepException (TypeContainer tc)
- {
- Container = tc;
- }
- }
-
public class MemberCoreArrayList: ArrayList
{
/// <summary>
@@ -473,9 +464,6 @@
MemberCache member_cache;
public const string DefaultIndexerName = "Item";
-
- // This is used to catch recursive definitions in declarations.
- protected bool InTransit;
public TypeContainer (NamespaceEntry ns, TypeContainer parent,
MemberName name,
Attributes attrs, Kind kind, Location l)
@@ -945,7 +933,7 @@
public abstract PendingImplementation GetPendingImplementations
();
- TypeExpr[] GetPartialBases (out TypeExpr base_class)
+ TypeExpr[] GetPartialBases (out TypeExpr base_class, out bool
error)
{
ArrayList ifaces = new ArrayList ();
@@ -956,8 +944,8 @@
TypeExpr new_base_class;
TypeExpr[] new_ifaces;
- new_ifaces = part.GetClassBases (out
new_base_class);
- if (new_ifaces == null && base_type != null)
+ new_ifaces = part.GetClassBases (out
new_base_class, out error);
+ if (error)
return null;
if ((base_class != null) && (new_base_class !=
null) &&
@@ -970,6 +958,7 @@
if (!Location.IsNull (base_loc))
Report.LocationOfPreviousError
(base_loc);
+ error = true;
return null;
}
@@ -995,12 +984,14 @@
}
}
+ error = false;
+
TypeExpr[] retval = new TypeExpr [ifaces.Count];
ifaces.CopyTo (retval, 0);
return retval;
}
- TypeExpr[] GetNormalBases (out TypeExpr base_class)
+ TypeExpr[] GetNormalBases (out TypeExpr base_class, out bool
error)
{
base_class = null;
@@ -1012,6 +1003,7 @@
(Expression) Bases [0], false,
Location);
if (name == null){
+ error = true;
return null;
}
@@ -1028,12 +1020,14 @@
for (i = start, j = 0; i < count; i++, j++){
TypeExpr resolved = ResolveBaseTypeExpr
((Expression) Bases [i], false, Location);
if (resolved == null) {
+ error = true;
return null;
}
ifaces [j] = resolved;
}
+ error = false;
return ifaces;
}
@@ -1047,31 +1041,35 @@
/// The @base_class argument is set to the base object or null
/// if this is `System.Object'.
/// </summary>
- TypeExpr [] GetClassBases (out TypeExpr base_class)
+ TypeExpr [] GetClassBases (out TypeExpr base_class, out bool
error)
{
int i;
+ error = false;
+
TypeExpr[] ifaces;
if (parts != null)
- ifaces = GetPartialBases (out base_class);
+ ifaces = GetPartialBases (out base_class, out
error);
else if (Bases == null){
base_class = null;
return null;
} else
- ifaces = GetNormalBases (out base_class);
+ ifaces = GetNormalBases (out base_class, out
error);
- if (ifaces == null)
+ if (error)
return null;
if ((base_class != null) && (Kind == Kind.Class)){
if (base_class.Type.IsArray ||
base_class.Type.IsPointer) {
Report.Error (1521,
base_class.Location, "Invalid base type");
+ error = true;
return null;
}
if (base_class.IsSealed){
+ error = true;
Report.SymbolRelatedToPreviousError
(base_class.Type);
if (base_class.Type.IsAbstract) {
Report.Error (709, Location,
"'{0}': Cannot derive from static class", GetSignatureForError ());
@@ -1085,6 +1083,7 @@
Report.Error (644, Location,
"`{0}' cannot inherit
from special class `{1}'",
Name, base_class.Name);
+ error = true;
return null;
}
@@ -1107,9 +1106,13 @@
TypeExpr iface = (TypeExpr) ifaces [i];
if (!iface.IsInterface) {
+ error = true;
if (Kind != Kind.Class) {
- // TODO: location of symbol
related ....
- Error_TypeInListIsNotInterface
(Location, iface.FullName);
+ string what = Kind ==
Kind.Struct ? "Struct" : "Interface";
+
+ Report.Error (527, Location,
+ "In {0} `{1}',
type `{2}' is not "+
+ "an interface",
what, Name, iface.Name);
}
else if (base_class != null)
Report.Error (1721, Location,
@@ -1120,7 +1123,7 @@
"In Class `{0}',
`{1}' is not " +
"an interface, a
base class must be listed first", Name, iface.Name);
}
- return null;
+ continue;
}
for (int x = 0; x < i; x++) {
@@ -1128,7 +1131,7 @@
Report.Error (528, Location,
"`{0}' is already
listed in " +
"interface list",
iface.Name);
- return null;
+ error = true;
}
}
@@ -1139,17 +1142,18 @@
"interface `{0}' is less
accessible " +
"than interface `{1}'",
iface.Name,
Name);
- return null;
+ error = true;
}
}
+
+ if (error)
+ return null;
+
return ifaces;
}
- protected void Error_TypeInListIsNotInterface (Location loc,
string type)
- {
- Report.Error (527, loc, "'{0}': type in interface list
is not an interface", type);
- }
-
+ bool error = false;
+
//
// Defines the type in the appropriate ModuleBuilder or
TypeBuilder.
//
@@ -1157,14 +1161,21 @@
{
if (TypeBuilder != null)
return TypeBuilder;
+
+ if (error)
+ return null;
+
+ if (InTransit) {
+ Report.Error (146, Location, "Class definition
is circular: `{0}'", Name);
+ error = true;
+ return null;
+ }
InTransit = true;
- TypeExpr[] iface_exprs = GetClassBases (out base_type);
- if (iface_exprs == null && base_type != null) {
- InTransit = false;
+ TypeExpr[] iface_exprs = GetClassBases (out base_type,
out error);
+ if (error)
return null;
- }
if (base_type == null) {
if (Kind == Kind.Class){
@@ -1195,7 +1206,7 @@
// However, if Parent ==
RootContext.Tree.Types, its NamespaceEntry will be null.
ptype = base_type.ResolveType
(TypeResolveEmitContext);
if (ptype == null) {
- InTransit = false;
+ error = true;
return null;
}
}
@@ -1203,7 +1214,7 @@
try {
if (IsTopLevel){
if (TypeManager.NamespaceClash (Name,
Location)) {
- InTransit = false;
+ error = true;
return null;
}
@@ -1213,10 +1224,8 @@
} else {
TypeBuilder builder =
Parent.TypeBuilder;
- if (builder == null) {
- InTransit = false;
+ if (builder == null)
return null;
- }
TypeBuilder = builder.DefineNestedType (
Basename, type_attributes,
ptype, null);
@@ -1224,7 +1233,6 @@
}
catch (ArgumentException) {
Report.RuntimeMissingSupport (Location, "static
classes");
- InTransit = false;
return null;
}
@@ -1261,7 +1269,7 @@
TypeResolveEmitContext.ContainerType =
TypeBuilder;
ifaces = TypeManager.ExpandInterfaces
(TypeResolveEmitContext, iface_exprs);
if (ifaces == null) {
- InTransit = false;
+ error = true;
return null;
}
@@ -1276,12 +1284,12 @@
if (!(this is Iterator))
RootContext.RegisterOrder (this);
- InTransit = false;
-
if (!DefineNestedTypes ()) {
+ error = true;
return null;
}
+ InTransit = false;
return TypeBuilder;
}
@@ -2785,8 +2793,6 @@
Modifiers.SEALED |
Modifiers.UNSAFE;
- bool WasTransitError;
-
public Class (NamespaceEntry ns, TypeContainer parent,
MemberName name, int mod,
Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Class, l)
@@ -2826,12 +2832,6 @@
public override TypeBuilder DefineType()
{
- if (InTransit) {
- if (WasTransitError)
- return null;
- throw new CircularDepException (this);
- }
-
if ((ModFlags & Modifiers.ABSTRACT) ==
Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
Report.Error (418, Location, "'{0}': an
abstract class cannot be sealed or static", GetSignatureForError ());
return null;
@@ -2840,16 +2840,7 @@
int accmods = Parent.Parent == null ?
Modifiers.INTERNAL : Modifiers.PRIVATE;
ModFlags = Modifiers.Check (AllowedModifiersProp,
ModFlags, accmods, Location);
- try {
- return base.DefineType ();
- }
- catch (CircularDepException e) {
- Report.SymbolRelatedToPreviousError
(e.Container);
- Report.Error (146, Location, "Circular base
class dependency involving '{0}' and '{1}'",
- GetSignatureForError (),
e.Container.GetSignatureForError ());
- WasTransitError = true;
- return null;
- }
+ return base.DefineType ();
}
/// Search for at least one defined condition in
ConditionalAttribute of attribute class
@@ -2933,33 +2924,12 @@
return base.TypeAttr | DefaultTypeAttributes;
}
}
-
- public override TypeBuilder DefineType()
- {
- if (InTransit) {
- InTransit = false;
- throw new CircularDepException (this);
- }
-
- try {
- return base.DefineType ();
- }
- catch (CircularDepException e) {
- InTransit = false;
- Report.SymbolRelatedToPreviousError (this);
- Error_TypeInListIsNotInterface
(e.Container.Location, GetSignatureForError ());
- return null;
- }
- }
}
/// <summary>
/// Interfaces
/// </summary>
public class Interface : TypeContainer, IMemberContainer {
-
- bool WasTransitError;
-
/// <summary>
/// Modifiers allowed in a class declaration
/// </summary>
@@ -3000,27 +2970,6 @@
return base.TypeAttr | DefaultTypeAttributes;
}
}
-
- public override TypeBuilder DefineType()
- {
- if (InTransit) {
- if (WasTransitError)
- return null;
- throw new CircularDepException (this);
- }
-
- try {
- return base.DefineType ();
- }
- catch (CircularDepException e) {
- Report.SymbolRelatedToPreviousError
(e.Container);
- Report.Error (529, Location, "Inherited
interface '{0}' causes a cycle in the interface hierarchy of '{1}'",
- e.Container.GetSignatureForError (),
GetSignatureForError ());
- WasTransitError = true;
- return null;
- }
- }
-
}
public abstract class MethodCore : MemberBase {
Modified: trunk/mcs/mcs/codegen.cs
===================================================================
--- trunk/mcs/mcs/codegen.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/codegen.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -383,9 +383,6 @@
/// </summary>
public bool InFixedInitializer;
- public bool InCatch;
- public bool InFinally;
-
/// <summary>
/// Whether we are inside an anonymous method.
/// </summary>
Modified: trunk/mcs/mcs/decl.cs
===================================================================
--- trunk/mcs/mcs/decl.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/decl.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -585,6 +585,22 @@
return (MemberCore)defined_names [name];
}
+ bool in_transit = false;
+
+ /// <summary>
+ /// This function is used to catch recursive definitions
+ /// in declarations.
+ /// </summary>
+ public bool InTransit {
+ get {
+ return in_transit;
+ }
+
+ set {
+ in_transit = value;
+ }
+ }
+
//
// root_types contains all the types. All TopLevel types
// hence have a parent that points to `root_types', that is
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/expression.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -8643,7 +8643,8 @@
return null;
}
- if (ec.InCatch || ec.InFinally) {
+ if (ec.CurrentBranching.InCatch () ||
+ ec.CurrentBranching.InFinally (true)) {
Error (255,
"stackalloc can not be used in a catch
or finally block");
return null;
Modified: trunk/mcs/mcs/flowanalysis.cs
===================================================================
--- trunk/mcs/mcs/flowanalysis.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/flowanalysis.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -1171,13 +1171,31 @@
return false;
}
- public virtual bool InTryWithCatch ()
+ //
+ // Checks whether we're in a `catch' block.
+ //
+ public virtual bool InCatch ()
{
if (Parent != null)
- return Parent.InTryWithCatch ();
- return false;
+ return Parent.InCatch ();
+ else
+ return false;
}
+ //
+ // Checks whether we're in a `finally' block.
+ //
+ public virtual bool InFinally (bool is_return)
+ {
+ if (!is_return &&
+ ((Type == BranchingType.Loop) || (Type ==
BranchingType.Switch)))
+ return false;
+ else if (Parent != null)
+ return Parent.InFinally (is_return);
+ else
+ return false;
+ }
+
public virtual bool InLoop ()
{
if (Type == BranchingType.Loop)
@@ -1365,6 +1383,7 @@
UsageVector finally_vector;
UsageVector finally_origins;
bool emit_finally;
+ bool in_try;
public FlowBranchingException (FlowBranching parent,
ExceptionStatement stmt)
@@ -1380,12 +1399,15 @@
if (sibling.Type == SiblingType.Try) {
sibling.Next = catch_vectors;
catch_vectors = sibling;
+ in_try = true;
} else if (sibling.Type == SiblingType.Catch) {
sibling.Next = catch_vectors;
catch_vectors = sibling;
+ in_try = false;
} else if (sibling.Type == SiblingType.Finally) {
sibling.MergeFinallyOrigins (finally_origins);
finally_vector = sibling;
+ in_try = false;
} else
throw new InvalidOperationException ();
@@ -1401,18 +1423,14 @@
return finally_vector == null;
}
- public override bool InTryWithCatch ()
+ public override bool InCatch ()
{
- if (finally_vector == null) {
- Try t = stmt as Try;
- if (t != null && t.HasCatch)
- return true;
- }
+ return !in_try && (finally_vector == null);
+ }
- if (Parent != null)
- return Parent.InTryWithCatch ();
-
- return false;
+ public override bool InFinally (bool is_return)
+ {
+ return finally_vector != null;
}
public override bool BreakCrossesTryCatchBoundary ()
Modified: trunk/mcs/mcs/iterators.cs
===================================================================
--- trunk/mcs/mcs/iterators.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/iterators.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -41,7 +41,7 @@
public static bool CheckContext (EmitContext ec, Location loc)
{
- if (ec.InFinally) {
+ if (ec.CurrentBranching.InFinally (true)){
Report.Error (1625, loc, "Cannot yield in the
body of a " +
"finally clause");
return false;
@@ -51,21 +51,19 @@
Report.Error (1629, loc, "Unsafe code may not
appear in iterators");
return false;
}
- if (ec.InCatch){
+ if (ec.CurrentBranching.InCatch ()){
Report.Error (1631, loc, "Cannot yield in the
body of a " +
"catch clause");
return false;
}
if (ec.CurrentAnonymousMethod != null){
- Report.Error (1621, loc, "The yield statement
cannot be used inside anonymous method blocks");
+ Report.Error (1621, loc, "yield statement can
not appear inside an anonymoud method");
return false;
}
- if (ec.CurrentBranching.InTryWithCatch ()) {
- Report.Error (1626, loc, "Cannot yield a value
in the body of a " +
- "try block with a catch clause");
- return false;
- }
+ //
+ // FIXME: Missing check for Yield inside try block that
contains catch clauses
+ //
return true;
}
Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/statement.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -611,7 +611,7 @@
if (ec.CurrentBranching.InTryOrCatch (true)) {
ec.CurrentBranching.AddFinallyVector (vector);
in_exc = true;
- } else if (ec.InFinally) {
+ } else if (ec.CurrentBranching.InFinally (true)) {
Error (157, "Control can not leave the body of
the finally block");
return false;
} else
@@ -871,13 +871,13 @@
return true;
}
- if (!ec.InCatch) {
- Error (156, "A throw statement with no
arguments is not allowed outside of a catch clause");
+ if (ec.CurrentBranching.InFinally (true)) {
+ Error (724, "A throw statement with no argument
is only allowed in a catch clause nested inside of the innermost catch clause");
return false;
}
- if (ec.InFinally) {
- Error (724, "A throw statement with no argument
is only allowed in a catch clause nested inside of the innermost catch clause");
+ if (!ec.CurrentBranching.InCatch ()) {
+ Error (156, "A throw statement with no argument
is only allowed in a catch clause");
return false;
}
return true;
@@ -909,7 +909,7 @@
if (!ec.CurrentBranching.InLoop () &&
!ec.CurrentBranching.InSwitch ()){
Error (139, "No enclosing loop or switch to
continue to");
return false;
- } else if (ec.InFinally) {
+ } else if (ec.CurrentBranching.InFinally (false)) {
Error (157, "Control can not leave the body of
the finally block");
return false;
} else if (ec.CurrentBranching.InTryOrCatch (false))
@@ -954,7 +954,7 @@
if (!ec.CurrentBranching.InLoop () &&
!ec.CurrentBranching.InSwitch ()){
Error (139, "No enclosing loop to continue to");
return false;
- } else if (ec.InFinally) {
+ } else if (ec.CurrentBranching.InFinally (false)) {
Error (157, "Control can not leave the body of
the finally block");
return false;
} else if (ec.CurrentBranching.InTryOrCatch (false))
@@ -3587,30 +3587,23 @@
public override bool Resolve (EmitContext ec)
{
- bool was_catch = ec.InCatch;
- ec.InCatch = true;
- try {
- if (type_expr != null) {
- TypeExpr te =
type_expr.ResolveAsTypeTerminal (ec, false);
- if (te == null)
- return false;
+ if (type_expr != null) {
+ TypeExpr te = type_expr.ResolveAsTypeTerminal
(ec, false);
+ if (te == null)
+ return false;
- type = te.ResolveType (ec);
+ type = te.ResolveType (ec);
- CheckObsolete (type);
+ CheckObsolete (type);
- if (type != TypeManager.exception_type
&& !type.IsSubclassOf (TypeManager.exception_type)){
- Error (155, "The type caught or
thrown must be derived from System.Exception");
- return false;
- }
- } else
- type = null;
+ if (type != TypeManager.exception_type &&
!type.IsSubclassOf (TypeManager.exception_type)){
+ Error (155, "The type caught or thrown
must be derived from System.Exception");
+ return false;
+ }
+ } else
+ type = null;
- return Block.Resolve (ec);
- }
- finally {
- ec.InCatch = was_catch;
- }
+ return Block.Resolve (ec);
}
}
@@ -3705,11 +3698,9 @@
Fini,
FlowBranching.SiblingType.Finally);
Report.Debug (1, "STARTED SIBLING FOR FINALLY",
ec.CurrentBranching, vector);
- bool was_finally = ec.InFinally;
- ec.InFinally = true;
+
if (!Fini.Resolve (ec))
ok = false;
- ec.InFinally = was_finally;
}
ResolveFinally (branching);
@@ -3775,13 +3766,6 @@
Fini.Emit (ec);
}
}
-
- public bool HasCatch
- {
- get {
- return General != null || Specific.Count > 0;
- }
- }
}
public class Using : ExceptionStatement {
Modified: trunk/mcs/mcs/typemanager.cs
===================================================================
--- trunk/mcs/mcs/typemanager.cs 2005-04-14 02:13:02 UTC (rev 42974)
+++ trunk/mcs/mcs/typemanager.cs 2005-04-14 02:13:10 UTC (rev 42975)
@@ -1523,8 +1523,10 @@
public static bool IsUnmanagedType (Type t)
{
// builtins that are not unmanaged types
- if (t == TypeManager.object_type || t ==
TypeManager.string_type)
+ if (t == TypeManager.object_type || t ==
TypeManager.string_type){
+ Console.WriteLine ("A fucking string");
return false;
+ }
if (IsBuiltinOrEnum (t))
return true;
@@ -1535,8 +1537,13 @@
if (t.IsArray)
return IsUnmanagedType (t.GetElementType ());
- if (!IsValueType (t))
+ if (IsDelegateType (t))
+ return true;
+
+ if (!IsValueType (t)){
+ Console.WriteLine ("No value type: " + t.FullName);
return false;
+ }
if (t is TypeBuilder){
TypeContainer tc = LookupTypeContainer (t);
@@ -1548,8 +1555,10 @@
continue;
if (f.MemberType == null)
continue;
- if (!IsUnmanagedType (f.MemberType))
+ if (!IsUnmanagedType (f.MemberType)){
+ Console.WriteLine ("RECU on F: " +
f.MemberType.FullName + " On " + t.FullName);
return false;
+ }
}
return true;
}
@@ -1557,8 +1566,11 @@
FieldInfo [] fields = t.GetFields (BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance);
foreach (FieldInfo f in fields)
- if (!IsUnmanagedType (f.FieldType))
+ if (!IsUnmanagedType (f.FieldType)){
+ Console.WriteLine ("No value type Field: " +
f.FieldType.FullName);
+
return false;
+ }
return true;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches