Author: martin
Date: 2005-04-20 07:16:05 -0400 (Wed, 20 Apr 2005)
New Revision: 43323
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/class.cs
trunk/mcs/gmcs/codegen.cs
trunk/mcs/gmcs/decl.cs
trunk/mcs/gmcs/expression.cs
trunk/mcs/gmcs/flowanalysis.cs
trunk/mcs/gmcs/iterators.cs
trunk/mcs/gmcs/statement.cs
Log:
**** Merged r43204 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-20 11:16:05 UTC (rev 43323)
@@ -1,3 +1,32 @@
+2005-04-18 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-17 Atsushi Enomoto <[EMAIL PROTECTED]>
* doc.cs : In some cases FilterName returns MonoEvent and MonoField
Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/class.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -59,6 +59,15 @@
/// </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>
@@ -462,6 +471,9 @@
Type GenericType;
+ // 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)
: base (ns, parent, name, attrs, l)
@@ -927,7 +939,7 @@
public abstract PendingImplementation GetPendingImplementations
();
- TypeExpr[] GetPartialBases (out TypeExpr base_class, out bool
error)
+ TypeExpr[] GetPartialBases (out TypeExpr base_class)
{
ArrayList ifaces = new ArrayList ();
@@ -938,8 +950,8 @@
TypeExpr new_base_class;
TypeExpr[] new_ifaces;
- new_ifaces = part.GetClassBases (out
new_base_class, out error);
- if (error)
+ new_ifaces = part.GetClassBases (out
new_base_class);
+ if (new_ifaces == null && base_type != null)
return null;
if ((base_class != null) && (new_base_class !=
null) &&
@@ -952,7 +964,6 @@
if (!Location.IsNull (base_loc))
Report.LocationOfPreviousError
(base_loc);
- error = true;
return null;
}
@@ -978,14 +989,12 @@
}
}
- error = false;
-
TypeExpr[] retval = new TypeExpr [ifaces.Count];
ifaces.CopyTo (retval, 0);
return retval;
}
- TypeExpr[] GetNormalBases (out TypeExpr base_class, out bool
error)
+ TypeExpr[] GetNormalBases (out TypeExpr base_class)
{
base_class = null;
@@ -997,7 +1006,6 @@
(Expression) Bases [0], false,
Location);
if (name == null){
- error = true;
return null;
}
@@ -1014,14 +1022,12 @@
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;
}
@@ -1035,23 +1041,21 @@
/// The @base_class argument is set to the base object or null
/// if this is `System.Object'.
/// </summary>
- TypeExpr [] GetClassBases (out TypeExpr base_class, out bool
error)
+ TypeExpr [] GetClassBases (out TypeExpr base_class)
{
int i;
- error = false;
-
TypeExpr[] ifaces;
if (parts != null)
- ifaces = GetPartialBases (out base_class, out
error);
+ ifaces = GetPartialBases (out base_class);
else if (Bases == null){
base_class = null;
return null;
} else
- ifaces = GetNormalBases (out base_class, out
error);
+ ifaces = GetNormalBases (out base_class);
- if (error)
+ if (ifaces == null)
return null;
if ((base_class != null) && (Kind == Kind.Class)){
@@ -1076,12 +1080,10 @@
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 ());
@@ -1095,7 +1097,6 @@
Report.Error (644, Location,
"`{0}' cannot inherit
from special class `{1}'",
Name, base_class.Name);
- error = true;
return null;
}
@@ -1118,13 +1119,9 @@
TypeExpr iface = (TypeExpr) ifaces [i];
if (!iface.IsInterface) {
- error = true;
if (Kind != Kind.Class) {
- string what = Kind ==
Kind.Struct ? "Struct" : "Interface";
-
- Report.Error (527, Location,
- "In {0} `{1}',
type `{2}' is not "+
- "an interface",
what, Name, iface.Name);
+ // TODO: location of symbol
related ....
+ Error_TypeInListIsNotInterface
(Location, iface.FullName);
}
else if (base_class != null)
Report.Error (1721, Location,
@@ -1135,7 +1132,7 @@
"In Class `{0}',
`{1}' is not " +
"an interface, a
base class must be listed first", Name, iface.Name);
}
- continue;
+ return null;
}
for (int x = 0; x < i; x++) {
@@ -1143,7 +1140,7 @@
Report.Error (528, Location,
"`{0}' is already
listed in " +
"interface list",
iface.Name);
- error = true;
+ return null;
}
}
@@ -1154,13 +1151,9 @@
"interface `{0}' is less
accessible " +
"than interface `{1}'",
iface.Name,
Name);
- error = true;
+ return null;
}
}
-
- if (error)
- return null;
-
return ifaces;
}
@@ -1196,6 +1189,11 @@
bool error = false;
+ protected void Error_TypeInListIsNotInterface (Location loc,
string type)
+ {
+ Report.Error (527, loc, "'{0}': type in interface list
is not an interface", type);
+ }
+
//
// Defines the type in the appropriate ModuleBuilder or
TypeBuilder.
//
@@ -1212,7 +1210,7 @@
try {
if (IsTopLevel){
if (TypeManager.NamespaceClash (Name,
Location)) {
- error = true;
+ InTransit = false;
return null;
}
@@ -1220,24 +1218,18 @@
TypeBuilder = builder.DefineType (
Name, type_attributes, null,
null);
} else {
- TypeBuilder builder;
- if (Parent.TypeBuilder != null)
- builder = Parent.TypeBuilder;
- else
- builder = Parent.DefineType ();
-
+ TypeBuilder builder =
Parent.TypeBuilder;
if (builder == null) {
- error = true;
+ InTransit = false;
return null;
}
-
+
TypeBuilder = builder.DefineNestedType (
- MemberName.Basename,
type_attributes,
- null, null);
+ Basename, type_attributes,
ptype, null);
}
- }
- catch (ArgumentException) {
+ } catch (ArgumentException) {
Report.RuntimeMissingSupport (Location, "static
classes");
+ InTransit = false;
return null;
}
@@ -1305,12 +1297,11 @@
return null;
}
- if ((Kind == Kind.Struct) && TypeManager.value_type ==
null)
- throw new Exception ();
-
- TypeExpr[] iface_exprs = GetClassBases (out base_type,
out error);
- if (error)
+ TypeExpr[] iface_exprs = GetClassBases (out base_type);
+ if (iface_exprs == null && base_type != null) {
+ InTransit = false;
return null;
+ }
if (base_type == null) {
if (Kind == Kind.Class){
@@ -1336,7 +1327,7 @@
// However, if Parent ==
RootContext.Tree.Types, its NamespaceEntry will be null.
ptype = base_type.ResolveType
(TypeResolveEmitContext);
if (ptype == null) {
- error = true;
+ InTransit = false;
return null;
}
@@ -1344,7 +1335,7 @@
}
if (!CheckRecursiveDefinition ()) {
- error = true;
+ InTransit = false;
return null;
}
@@ -1358,7 +1349,7 @@
TypeResolveEmitContext.ContainerType =
TypeBuilder;
ifaces = TypeManager.ExpandInterfaces
(TypeResolveEmitContext, iface_exprs);
if (ifaces == null) {
- error = true;
+ InTransit = false;
return null;
}
@@ -1394,8 +1385,9 @@
if (!(this is Iterator))
RootContext.RegisterOrder (this);
+ InTransit = false;
+
if (!DefineNestedTypes ()) {
- error = true;
return null;
}
@@ -3047,6 +3039,8 @@
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)
@@ -3087,6 +3081,12 @@
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;
@@ -3095,7 +3095,16 @@
int accmods = Parent.Parent == null ?
Modifiers.INTERNAL : Modifiers.PRIVATE;
ModFlags = Modifiers.Check (AllowedModifiersProp,
ModFlags, accmods, Location);
- return base.DefineType ();
+ 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;
+ }
}
/// Search for at least one defined condition in
ConditionalAttribute of attribute class
@@ -3179,12 +3188,33 @@
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>
@@ -3225,6 +3255,27 @@
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/gmcs/codegen.cs
===================================================================
--- trunk/mcs/gmcs/codegen.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/codegen.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -383,6 +383,9 @@
/// </summary>
public bool InFixedInitializer;
+ public bool InCatch;
+ public bool InFinally;
+
/// <summary>
/// Whether we are inside an anonymous method.
/// </summary>
Modified: trunk/mcs/gmcs/decl.cs
===================================================================
--- trunk/mcs/gmcs/decl.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/decl.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -713,22 +713,6 @@
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/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/expression.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -8897,8 +8897,7 @@
return null;
}
- if (ec.CurrentBranching.InCatch () ||
- ec.CurrentBranching.InFinally (true)) {
+ if (ec.InCatch || ec.InFinally) {
Error (255,
"stackalloc can not be used in a
catch or finally block");
return null;
Modified: trunk/mcs/gmcs/flowanalysis.cs
===================================================================
--- trunk/mcs/gmcs/flowanalysis.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/flowanalysis.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -1168,31 +1168,13 @@
return false;
}
- //
- // Checks whether we're in a `catch' block.
- //
- public virtual bool InCatch ()
+ public virtual bool InTryWithCatch ()
{
if (Parent != null)
- return Parent.InCatch ();
- else
- return false;
+ return Parent.InTryWithCatch ();
+ 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)
@@ -1380,7 +1362,6 @@
UsageVector finally_vector;
UsageVector finally_origins;
bool emit_finally;
- bool in_try;
public FlowBranchingException (FlowBranching parent,
ExceptionStatement stmt)
@@ -1396,15 +1377,12 @@
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 ();
@@ -1420,14 +1398,18 @@
return finally_vector == null;
}
- public override bool InCatch ()
+ public override bool InTryWithCatch ()
{
- return !in_try && (finally_vector == null);
- }
+ if (finally_vector == null) {
+ Try t = stmt as Try;
+ if (t != null && t.HasCatch)
+ return true;
+ }
- public override bool InFinally (bool is_return)
- {
- return finally_vector != null;
+ if (Parent != null)
+ return Parent.InTryWithCatch ();
+
+ return false;
}
public override bool BreakCrossesTryCatchBoundary ()
Modified: trunk/mcs/gmcs/iterators.cs
===================================================================
--- trunk/mcs/gmcs/iterators.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/iterators.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -41,7 +41,7 @@
public static bool CheckContext (EmitContext ec, Location loc)
{
- if (ec.CurrentBranching.InFinally (true)){
+ if (ec.InFinally) {
Report.Error (1625, loc, "Cannot yield in the
body of a " +
"finally clause");
return false;
@@ -51,19 +51,21 @@
Report.Error (1629, loc, "Unsafe code may not
appear in iterators");
return false;
}
- if (ec.CurrentBranching.InCatch ()){
+ if (ec.InCatch){
Report.Error (1631, loc, "Cannot yield in the
body of a " +
"catch clause");
return false;
}
if (ec.CurrentAnonymousMethod != null){
- Report.Error (1621, loc, "yield statement can
not appear inside an anonymoud method");
+ Report.Error (1621, loc, "The yield statement
cannot be used inside anonymous method blocks");
return false;
}
- //
- // FIXME: Missing check for Yield inside try block that
contains catch clauses
- //
+ 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;
+ }
return true;
}
Modified: trunk/mcs/gmcs/statement.cs
===================================================================
--- trunk/mcs/gmcs/statement.cs 2005-04-20 08:55:29 UTC (rev 43322)
+++ trunk/mcs/gmcs/statement.cs 2005-04-20 11:16:05 UTC (rev 43323)
@@ -611,7 +611,7 @@
if (ec.CurrentBranching.InTryOrCatch (true)) {
ec.CurrentBranching.AddFinallyVector (vector);
in_exc = true;
- } else if (ec.CurrentBranching.InFinally (true)) {
+ } else if (ec.InFinally) {
Error (157, "Control can not leave the body of
the finally block");
return false;
} else
@@ -871,13 +871,13 @@
return true;
}
- 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");
+ if (!ec.InCatch) {
+ Error (156, "A throw statement with no
arguments is not allowed outside of a catch clause");
return false;
}
- if (!ec.CurrentBranching.InCatch ()) {
- Error (156, "A throw statement with no argument
is only allowed in a catch clause");
+ 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");
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.CurrentBranching.InFinally (false)) {
+ } else if (ec.InFinally &&
ec.CurrentBranching.BreakCrossesTryCatchBoundary()) {
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.CurrentBranching.InFinally (false)) {
+ } else if (ec.InFinally) {
Error (157, "Control can not leave the body of
the finally block");
return false;
} else if (ec.CurrentBranching.InTryOrCatch (false))
@@ -3587,23 +3587,30 @@
public override bool Resolve (EmitContext ec)
{
- if (type_expr != null) {
- TypeExpr te = type_expr.ResolveAsTypeTerminal
(ec);
- if (te == null)
- return false;
+ bool was_catch = ec.InCatch;
+ ec.InCatch = true;
+ try {
+ if (type_expr != null) {
+ TypeExpr te =
type_expr.ResolveAsTypeTerminal (ec);
+ if (te == null)
+ return false;
- type = te.Type;
+ 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);
+ return Block.Resolve (ec);
+ }
+ finally {
+ ec.InCatch = was_catch;
+ }
}
}
@@ -3698,9 +3705,11 @@
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);
@@ -3766,6 +3775,13 @@
Fini.Emit (ec);
}
}
+
+ public bool HasCatch
+ {
+ get {
+ return General != null || Specific.Count > 0;
+ }
+ }
}
public class Using : ExceptionStatement {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches