Author: marek
Date: 2007-07-13 09:43:14 -0400 (Fri, 13 Jul 2007)
New Revision: 81943
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/anonymous.cs
trunk/mcs/mcs/codegen.cs
trunk/mcs/mcs/delegate.cs
trunk/mcs/mcs/driver.cs
trunk/mcs/mcs/ecore.cs
trunk/mcs/mcs/expression.cs
trunk/mcs/mcs/lambda.cs
trunk/mcs/mcs/report.cs
trunk/mcs/mcs/rootcontext.cs
trunk/mcs/mcs/statement.cs
Log:
2007-07-13 Marek Safar <[EMAIL PROTECTED]>
* anonymous.cs (AnonymousMethodExpression): Parameters are r/o.
(AnonymousContainer.ResolveNoDefine): Another ec to aec flag conversion.
* codegen.cs(EmitContext): Add ProbingMode flag.
* delegate.cs (DelegateInvocation): Set few instance variables as r/o.
* driver.cs: For now set both warning values.
* ecore.cs (SimpleName): Name is readonly.
(MethodGroup.OverloadResolve): One quick path for probing.
* expression.cs (Unary): Set Oper r/o.
(Binary): Set Oper r/o.
(ParameterReference): Set few instance variables as r/o.
(ParameterReference.DoResolveBase): Don't capture aruments when
the probing is on.
(Invocation.CloneTo): Fixed typo, looks easy, yeah.
(Arglist): arguments are private.
(SizeOf): type is private and r/o.
(MemberAccess): arguments are private.
* report.cs: Enhanced reporting on/off capabilities.
* lambda.cs: Uses ec.IsInProbingMode.
(ContextualReturn): Derives from return.
* rootcontext.cs: For now set both warning values.
* statement.cs (CloneContext.RemapBlockCopy): Remaps block to cloned
copy if one exists.
(Return.Resolve): Don't die immediately.
(Block.Resolve): Speed-up probing.
(Block.CloneTo): Clone only child blocks.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/ChangeLog 2007-07-13 13:43:14 UTC (rev 81943)
@@ -1,4 +1,40 @@
+2007-07-13 Marek Safar <[EMAIL PROTECTED]>
+ * anonymous.cs (AnonymousMethodExpression): Parameters are r/o.
+ (AnonymousContainer.ResolveNoDefine): Another ec to aec flag conversion.
+
+ * codegen.cs(EmitContext): Add ProbingMode flag.
+
+ * delegate.cs (DelegateInvocation): Set few instance variables as r/o.
+
+ * driver.cs: For now set both warning values.
+
+ * ecore.cs (SimpleName): Name is readonly.
+ (MethodGroup.OverloadResolve): One quick path for probing.
+
+ * expression.cs (Unary): Set Oper r/o.
+ (Binary): Set Oper r/o.
+ (ParameterReference): Set few instance variables as r/o.
+ (ParameterReference.DoResolveBase): Don't capture aruments when
+ the probing is on.
+ (Invocation.CloneTo): Fixed typo, looks easy, yeah.
+ (Arglist): arguments are private.
+ (SizeOf): type is private and r/o.
+ (MemberAccess): arguments are private.
+
+ * report.cs: Enhanced reporting on/off capabilities.
+
+ * lambda.cs: Uses ec.IsInProbingMode.
+ (ContextualReturn): Derives from return.
+
+ * rootcontext.cs: For now set both warning values.
+
+ * statement.cs (CloneContext.RemapBlockCopy): Remaps block to cloned
+ copy if one exists.
+ (Return.Resolve): Don't die immediately.
+ (Block.Resolve): Speed-up probing.
+ (Block.CloneTo): Clone only child blocks.
+
Fri Jul 13 11:19:28 CEST 2007 Paolo Molaro <[EMAIL PROTECTED]>
* iterators.cs: reverted Miguel's latest change (r81925) as it
Modified: trunk/mcs/mcs/anonymous.cs
===================================================================
--- trunk/mcs/mcs/anonymous.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/anonymous.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -184,8 +184,13 @@
protected readonly RootScopeInfo RootScope;
new public readonly DeclSpace Parent;
public readonly int ID = ++next_id;
- public Block ScopeBlock;
+ public readonly Block ScopeBlock;
+ protected ScopeInitializer scope_initializer;
+ readonly Hashtable locals = new Hashtable ();
+ readonly Hashtable captured_scopes = new Hashtable ();
+ Hashtable captured_params;
+
static int next_id;
public static ScopeInfo CreateScope (Block block)
@@ -251,12 +256,6 @@
Report.Debug (128, "NEW ROOT SCOPE", this, toplevel,
loc);
}
- protected ScopeInitializer scope_initializer;
-
- Hashtable locals = new Hashtable ();
- Hashtable captured_scopes = new Hashtable ();
- Hashtable captured_params;
-
protected CapturedScope[] CapturedScopes {
get {
CapturedScope[] list = new CapturedScope
[captured_scopes.Count];
@@ -390,13 +389,6 @@
return null;
}
- public bool IsParameterCaptured (string name)
- {
- if (captured_params != null)
- return captured_params [name] != null;
- return false;
- }
-
public Variable AddParameter (Parameter par, int idx)
{
if (captured_params == null)
@@ -1069,7 +1061,7 @@
{
public readonly AnonymousMethodExpression Parent;
public readonly TypeContainer Host;
- public Parameters Parameters;
+ public readonly Parameters Parameters;
public ToplevelBlock Block;
protected AnonymousMethod anonymous;
@@ -1417,7 +1409,7 @@
{
return ExprClassName;
}
-
+
public bool IsIterator {
get { return false; }
}
@@ -1428,7 +1420,6 @@
target.Block = (ToplevelBlock) clonectx.LookupBlock
(Block);
target.container = clonectx.LookupBlock (Block);
- target.Parameters = Parameters.Clone ();
}
}
@@ -1527,14 +1518,20 @@
aec.IsStatic = ec.IsStatic;
aec.InferReturnType = ec.InferReturnType;
+ IDisposable aec_dispose = null;
+ if (ec.IsInProbingMode)
+ aec_dispose = aec.Set
(EmitContext.Flags.ProbingMode);
+
Report.Debug (64, "RESOLVE ANONYMOUS METHOD #1", this,
Location, ec, aec,
RootScope, Parameters, Block);
bool unreachable;
- if (!aec.ResolveTopBlock (ec, Block, Parameters, null,
out unreachable))
- return false;
+ bool res = aec.ResolveTopBlock (ec, Block, Parameters,
null, out unreachable);
- return true;
+ if (aec_dispose != null)
+ aec_dispose.Dispose ();
+
+ return res;
}
public virtual bool Resolve (EmitContext ec)
@@ -1859,7 +1856,7 @@
constructor_method = ((MethodGroupExpr) ml).Methods [0];
#if MS_COMPATIBLE
- if (type.IsGenericType)
+ if (type.IsGenericType && type is TypeBuilder)
constructor_method = TypeBuilder.GetConstructor
(type, (ConstructorInfo)constructor_method);
#endif
Modified: trunk/mcs/mcs/codegen.cs
===================================================================
--- trunk/mcs/mcs/codegen.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/codegen.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -265,7 +265,12 @@
/// Whether control flow analysis is disabled on
structs
/// (only meaningful when DoFlowAnalysis is set)
/// </summary>
- OmitStructFlowAnalysis = 1 << 6
+ OmitStructFlowAnalysis = 1 << 6,
+
+ ///
+ /// Indicates the current context is in probing mode,
no errors are reported.
+ ///
+ ProbingMode = 1 << 7
}
Flags flags;
@@ -495,21 +500,39 @@
public struct FlagsHandle : IDisposable
{
EmitContext ec;
- Flags invmask, oldval;
+ readonly Flags invmask, oldval;
+
+ public FlagsHandle (EmitContext ec, Flags flagsToSet)
+ : this (ec, flagsToSet, flagsToSet)
+ {
+ }
+
internal FlagsHandle (EmitContext ec, Flags mask, Flags
val)
{
this.ec = ec;
invmask = ~mask;
oldval = ec.flags & mask;
ec.flags = (ec.flags & invmask) | (val & mask);
+
+ if ((mask & Flags.ProbingMode) != 0)
+ Report.DisableReporting ();
}
+
public void Dispose ()
{
+ if ((invmask & Flags.ProbingMode) == 0)
+ Report.EnableReporting ();
+
ec.flags = (ec.flags & invmask) | oldval;
}
}
// Temporarily set all the given flags to the given value.
Should be used in an 'using' statement
+ public FlagsHandle Set (Flags flagsToSet)
+ {
+ return new FlagsHandle (this, flagsToSet);
+ }
+
public FlagsHandle With (Flags bits, bool enable)
{
return new FlagsHandle (this, bits, enable ? bits : 0);
@@ -524,9 +547,16 @@
}
public bool IsInObsoleteScope {
- get { return ResolveContext.IsInObsoleteScope; }
+ get {
+ // Disables obsolete checks when probing is on
+ return IsInProbingMode ||
ResolveContext.IsInObsoleteScope;
+ }
}
+ public bool IsInProbingMode {
+ get { return (flags & Flags.ProbingMode) != 0; }
+ }
+
public bool IsInUnsafeScope {
get { return InUnsafe ||
ResolveContext.IsInUnsafeScope; }
}
Modified: trunk/mcs/mcs/delegate.cs
===================================================================
--- trunk/mcs/mcs/delegate.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/delegate.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -888,8 +888,8 @@
public class DelegateInvocation : ExpressionStatement {
- public Expression InstanceExpr;
- public ArrayList Arguments;
+ readonly Expression InstanceExpr;
+ readonly ArrayList Arguments;
MethodBase method;
Modified: trunk/mcs/mcs/driver.cs
===================================================================
--- trunk/mcs/mcs/driver.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/driver.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -697,7 +697,7 @@
Report.Error (1900, "Warning level must be in
the range 0-4");
return;
}
- RootContext.WarningLevel = level;
+ Report.WarningLevel = RootContext.WarningLevel = level;
}
static void SetupV2 ()
Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/ecore.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -412,8 +412,7 @@
return
ResolveFlags.VariableOrValue;
default:
- throw new Exception
("Expression " + GetType () +
- " ExprClass is Invalid
after resolve");
+ throw new
InternalErrorException (loc.ToString () + " " + GetType () + " ExprClass is
Invalid after resolve");
}
}
}
@@ -1969,7 +1968,7 @@
/// of a dotted-name.
/// </summary>
public class SimpleName : Expression {
- public string Name;
+ public readonly string Name;
public readonly TypeArguments Arguments;
bool in_transit;
@@ -2209,7 +2208,7 @@
if (in_transit)
return null;
- in_transit = true;
+ in_transit = true;
Expression e = DoSimpleNameResolve (ec, right_side,
intermediate);
in_transit = false;
@@ -3684,6 +3683,9 @@
int candidate_top = candidates.Count;
if (applicable_type == null) {
+ if (ec.IsInProbingMode)
+ return null;
+
//
// Okay so we have failed to find anything so we
// return by providing info about the closest
match
@@ -3926,9 +3928,12 @@
#if MS_COMPATIBLE
// MS implementation throws
NotSupportedException for GetParameters
// on unbaked generic method
- Parameters p =
((Parameters)TypeManager.GetParameterData (mi)).Clone ();
- p.InflateTypes (gen_params, atypes);
- TypeManager.RegisterMethod (mi, p);
+ Parameters p = TypeManager.GetParameterData
(mi) as Parameters;
+ if (p != null) {
+ p = p.Clone ();
+ p.InflateTypes (gen_params, atypes);
+ TypeManager.RegisterMethod (mi, p);
+ }
#endif
}
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/expression.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -136,9 +136,9 @@
Indirection, AddressOf, TOP
}
- public Operator Oper;
+ public readonly Operator Oper;
public Expression Expr;
-
+
public Unary (Operator op, Expression expr, Location loc)
{
this.Oper = op;
@@ -588,7 +588,7 @@
}
else
Expr = Expr.Resolve (ec);
-
+
if (Expr == null)
return null;
@@ -1377,7 +1377,6 @@
public Expression Expr {
get { return expr; }
- set { expr = value; }
}
public override Expression DoResolve (EmitContext ec)
@@ -1446,7 +1445,7 @@
TOP
}
- Operator oper;
+ readonly Operator oper;
Expression left, right;
// This must be kept in sync with Operator!!!
@@ -1488,30 +1487,8 @@
get {
return oper;
}
- set {
- oper = value;
- }
}
- public Expression Left {
- get {
- return left;
- }
- set {
- left = value;
- }
- }
-
- public Expression Right {
- get {
- return right;
- }
- set {
- right = value;
- }
- }
-
-
/// <summary>
/// Returns a stringified representation of the Operator
/// </summary>
@@ -1891,9 +1868,7 @@
Unary right_unary = (Unary) right;
if (right_unary.Oper ==
Unary.Operator.UnaryNegation){
- oper = Operator.Subtraction;
- right = right_unary.Expr;
- r = right.Type;
+ return new Binary
(Operator.Subtraction, left, right).Resolve (ec);
}
}
}
@@ -3719,8 +3694,9 @@
/// representation.
/// </summary>
public class ParameterReference : VariableReference, IVariable {
- ToplevelParameterInfo pi;
- ToplevelBlock referenced;
+ readonly ToplevelParameterInfo pi;
+ readonly ToplevelBlock referenced;
+ Variable variable;
public bool is_ref, is_out;
@@ -3740,8 +3716,6 @@
get { return pi.Parameter; }
}
- Variable variable;
-
public ParameterReference (ToplevelBlock referenced,
ToplevelParameterInfo pi, Location loc)
{
this.pi = pi;
@@ -3807,12 +3781,11 @@
is_out = (mod & Parameter.Modifier.OUT) ==
Parameter.Modifier.OUT;
eclass = ExprClass.Variable;
- ToplevelBlock declared = pi.Block;
-
AnonymousContainer am = ec.CurrentAnonymousMethod;
if (am == null)
return true;
+ ToplevelBlock declared = pi.Block;
if (is_ref && declared != referenced) {
Report.Error (1628, Location,
"Cannot use ref or out parameter
`{0}' inside an " +
@@ -3823,9 +3796,12 @@
if (!am.IsIterator && declared == referenced)
return true;
- ScopeInfo scope = declared.CreateScopeInfo ();
- variable = scope.AddParameter (par, pi.Index);
- type = variable.Type;
+ // Don't capture aruments when the probing is on
+ if (!ec.IsInProbingMode) {
+ ScopeInfo scope = declared.CreateScopeInfo ();
+ variable = scope.AddParameter (par, pi.Index);
+ type = variable.Type;
+ }
return true;
}
@@ -4810,13 +4786,13 @@
{
Invocation target = (Invocation) t;
- if (Arguments != null){
- target.Arguments = new ArrayList ();
+ if (Arguments != null) {
+ target.Arguments = new ArrayList
(Arguments.Count);
foreach (Argument a in Arguments)
target.Arguments.Add (a.Clone
(clonectx));
}
- expr = expr.Clone (clonectx);
+ target.expr = expr.Clone (clonectx);
}
}
@@ -6379,7 +6355,7 @@
/// </summary>
public class Arglist : Expression
{
- public Argument[] Arguments;
+ Argument[] Arguments;
public Arglist (Location loc)
: this (Argument.Empty, loc)
@@ -6554,7 +6530,7 @@
/// Implements the sizeof expression
/// </summary>
public class SizeOf : Expression {
- public Expression QueriedType;
+ readonly Expression QueriedType;
Type type_queried;
public SizeOf (Expression queried_type, Location l)
@@ -6617,9 +6593,6 @@
protected override void CloneTo (CloneContext clonectx,
Expression t)
{
- SizeOf target = (SizeOf) t;
-
- target.QueriedType = QueriedType.Clone (clonectx);
}
}
@@ -6720,6 +6693,7 @@
public class MemberAccess : Expression {
public readonly string Identifier;
Expression expr;
+ readonly TypeArguments args;
public MemberAccess (Expression expr, string id)
: this (expr, id, expr.Location)
@@ -6739,8 +6713,6 @@
this.args = args;
}
- TypeArguments args;
-
protected string LookupIdentifier {
get { return MemberName.MakeName (Identifier, args); }
}
@@ -6812,8 +6784,9 @@
return ex_method_lookup.DoResolve (ec);
}
- MemberLookupFailed (
- ec.ContainerType, expr_type, expr_type,
Identifier, null, true, loc);
+ if (!ec.IsInProbingMode)
+ MemberLookupFailed (
+ ec.ContainerType, expr_type,
expr_type, Identifier, null, true, loc);
return null;
}
@@ -7127,9 +7100,6 @@
{
Expr = Expr.Resolve (ec);
- if (Expr == null)
- return false;
-
if (Arguments == null)
return false;
@@ -7138,7 +7108,7 @@
return false;
}
- return true;
+ return Expr != null;
}
Expression MakePointerAccess (EmitContext ec, Type t)
@@ -7180,7 +7150,7 @@
if (t.IsArray)
return (new ArrayAccess (this, loc)).Resolve
(ec);
if (t.IsPointer)
- return MakePointerAccess (ec, Expr.Type);
+ return MakePointerAccess (ec, t);
FieldExpr fe = Expr as FieldExpr;
if (fe != null) {
@@ -7202,7 +7172,7 @@
return (new ArrayAccess (this,
loc)).DoResolveLValue (ec, right_side);
if (t.IsPointer)
- return MakePointerAccess (ec, Expr.Type);
+ return MakePointerAccess (ec, t);
FieldExpr fe = Expr as FieldExpr;
if (fe != null) {
@@ -7233,7 +7203,7 @@
ElementAccess target = (ElementAccess) t;
target.Expr = Expr.Clone (clonectx);
- target.Arguments = new ArrayList ();
+ target.Arguments = new ArrayList (Arguments.Count);
foreach (Argument a in Arguments)
target.Arguments.Add (a.Clone (clonectx));
}
Modified: trunk/mcs/mcs/lambda.cs
===================================================================
--- trunk/mcs/mcs/lambda.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/lambda.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -52,23 +52,22 @@
return this;
}
+ //
+ // Returns true if the body of lambda expression can be
implicitly
+ // converted to the delegate of type `delegate_type'
+ //
public override bool ImplicitStandardConversionExists (Type
delegate_type)
{
EmitContext ec = EmitContext.TempEc;
- bool result;
+ using (ec.Set (EmitContext.Flags.ProbingMode)) {
+ bool r = DoImplicitStandardConversion (ec,
delegate_type) != null;
- try {
- Report.DisableErrors ();
- result = DoCompatibleTest (ec, delegate_type,
true) != null;
- } finally {
- Report.EnableErrors ();
- }
-
- // Ignore the result
- anonymous = null;
+ // Ignore the result
+ anonymous = null;
- return result;
+ return r;
+ }
}
//
@@ -77,14 +76,14 @@
//
public override Expression Compatible (EmitContext ec, Type
delegate_type)
{
- return DoCompatibleTest (ec, delegate_type, false);
- }
-
- Expression DoCompatibleTest (EmitContext ec, Type
delegate_type, bool clone)
- {
if (anonymous != null)
return anonymous.AnonymousDelegate;
+ return DoImplicitStandardConversion (ec, delegate_type);
+ }
+
+ Expression DoImplicitStandardConversion (EmitContext ec, Type
delegate_type)
+ {
if (CompatibleChecks (ec, delegate_type) == null)
return null;
@@ -113,26 +112,26 @@
return null;
} else {
//
- // If L has an implicitly typed parameter list,
D has no ref or
- // out parameters
+ // If L has an implicitly typed parameter list
//
- // Note: We currently do nothing, because the
preview does not
- // follow the above rule.
+ for (int i = 0; i < invoke_pd.Count; i++) {
+ // D has no ref or out parameters
+ if ((invoke_pd.ParameterModifier (i) &
Parameter.Modifier.ISBYREF) != 0)
+ return null;
- //
- // each parameter of L is given the type of the
corresponding parameter in D
- //
-
- for (int i = 0; i < invoke_pd.Count; i++)
- Parameters [i].TypeName = new
TypeExpression (
- invoke_pd.ParameterType (i),
- Parameters [i].Location);
+ //
+ // Makes implicit parameters explicit
+ // Set each parameter of L is given the
type of the corresponding parameter in D
+ //
+ Parameters[i].ParameterType =
invoke_pd.Types[i];
+
+ }
}
- return CoreCompatibilityTest (ec, clone,
invoke_mb.ReturnType, delegate_type);
+ return CoreCompatibilityTest (ec, invoke_mb.ReturnType,
delegate_type);
}
- Expression CoreCompatibilityTest (EmitContext ec, bool clone,
Type return_type, Type delegate_type)
+ Expression CoreCompatibilityTest (EmitContext ec, Type
return_type, Type delegate_type)
{
//
// The return type of the delegate must be compatible
with
@@ -141,15 +140,15 @@
// to be the delegate type return type.
//
- ToplevelBlock b = clone ? (ToplevelBlock)
Block.PerformClone () : Block;
-
+ ToplevelBlock b = ec.IsInProbingMode ? (ToplevelBlock)
Block.PerformClone () : Block;
+
anonymous = new AnonymousMethod (
Parent != null ? Parent.AnonymousMethod : null,
RootScope, Host,
GenericMethod, Parameters, Container, b,
return_type,
delegate_type, loc);
bool r;
- if (clone)
+ if (ec.IsInProbingMode)
r = anonymous.ResolveNoDefine (ec);
else
r = anonymous.Resolve (ec);
@@ -179,12 +178,12 @@
for (int i = 0; i < types.Length; i++)
Parameters [i].TypeName = new TypeExpression
(types [i], Parameters [i].Location);
+ // TODO: temporary hack
+ ec.InferReturnType = true;
+
Expression e;
- try {
- Report.DisableErrors ();
- e = CoreCompatibilityTest (ec, true, null,
null);
- } finally {
- Report.EnableErrors ();
+ using (ec.Set (EmitContext.Flags.ProbingMode)) {
+ e = CoreCompatibilityTest (ec, null, null);
}
if (e == null)
@@ -198,71 +197,12 @@
// This is a return statement that is prepended lambda expression
bodies that happen
// to be expressions. Depending on the return type of the delegate
this will behave
// as either { expr (); return (); } or { return expr (); }
- //
- public class ContextualReturn : Statement {
- public Expression Expr;
-
- public ContextualReturn (Expression e)
- {
- Expr = e;
- loc = Expr.Location;
- }
- bool unwind_protect;
-
- public override bool Resolve (EmitContext ec)
+ public class ContextualReturn : Return
+ {
+ public ContextualReturn (Expression expr)
+ : base (expr, expr.Location)
{
- AnonymousContainer am = ec.CurrentAnonymousMethod;
- if ((am != null) && am.IsIterator && ec.InIterator) {
- Report.Error (1622, loc, "Cannot return a value
from iterators. Use the yield return " +
- "statement to return a value, or
yield break to end the iteration");
- return false;
- }
-
- Expr = Expr.Resolve (ec);
- if (Expr == null)
- return false;
-
- if (ec.ReturnType == null){
- ec.ReturnType = Expr.Type;
- } else {
- if (Expr.Type != ec.ReturnType) {
- Expression nExpr =
Convert.ImplicitConversionRequired (
- ec, Expr, ec.ReturnType, loc);
- if (nExpr == null){
- Report.Error (1662, loc, "Could
not implicitly convert from {0} to {1}",
-
TypeManager.CSharpName (Expr.Type),
-
TypeManager.CSharpName (ec.ReturnType));
- return false;
- }
- Expr = nExpr;
- }
- }
-
- int errors = Report.Errors;
- unwind_protect = ec.CurrentBranching.AddReturnOrigin
(ec.CurrentBranching.CurrentUsageVector, loc);
- if (unwind_protect)
- ec.NeedReturnLabel ();
- ec.CurrentBranching.CurrentUsageVector.Goto ();
- return errors == Report.Errors;
}
-
- protected override void DoEmit (EmitContext ec)
- {
- Expr.Emit (ec);
-
- if (unwind_protect){
- ec.ig.Emit (OpCodes.Stloc, ec.TemporaryReturn
());
- ec.ig.Emit (OpCodes.Leave, ec.ReturnLabel);
- }
- ec.ig.Emit (OpCodes.Ret);
- }
-
- protected override void CloneTo (CloneContext clonectx,
Statement t)
- {
- ContextualReturn cr = (ContextualReturn) t;
-
- cr.Expr = Expr.Clone (clonectx);
- }
}
}
Modified: trunk/mcs/mcs/report.cs
===================================================================
--- trunk/mcs/mcs/report.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/report.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -42,6 +42,7 @@
/// </summary>
static public bool WarningsAreErrors;
+
/// <summary>
/// Whether to dump a stack trace on errors.
/// </summary>
@@ -69,9 +70,13 @@
// error stack contains elements, warnings and errors are not
// reported to the user. This is used by the Lambda expression
// support to compile the code with various parameter values.
+ // A stack because of `Report.Errors == errors;'
//
static Stack error_stack;
+ static bool reporting_disabled;
+ static int warning_level;
+
/// <summary>
/// List of symbols related to reported error/warning. You have
to fill it before error/warning is reported.
/// </summary>
@@ -111,18 +116,23 @@
WarningsAreErrors = false;
warning_ignore_table = null;
warning_regions_table = null;
+ reporting_disabled = false;
}
- public static void DisableErrors ()
+ public static void DisableReporting ()
{
if (error_stack == null)
error_stack = new Stack ();
error_stack.Push (Errors);
+ reporting_disabled = true;
}
- public static void EnableErrors ()
+ public static void EnableReporting ()
{
Errors = (int) error_stack.Pop ();
+ if (error_stack.Count == 0) {
+ reporting_disabled = false;
+ }
}
abstract class AbstractMessage {
@@ -138,9 +148,9 @@
public abstract string MessageType { get; }
- public virtual void Print (int code, string location,
string text)
+ public virtual void Print (int code, Location location,
string text)
{
- if (error_stack != null && error_stack.Count !=
0){
+ if (reporting_disabled) {
//
// This line is useful when debugging
the inner working of
// Lambdas when various compilation
attempts are done.
@@ -153,8 +163,8 @@
code = 8000-code;
StringBuilder msg = new StringBuilder ();
- if (location.Length != 0) {
- msg.Append (location);
+ if (!location.IsNull) {
+ msg.Append (location.ToString ());
msg.Append (' ');
}
msg.AppendFormat ("{0} CS{1:0000}: {2}",
MessageType, code, text);
@@ -175,15 +185,9 @@
Check (code);
}
-
- public virtual void Print (int code, Location location,
string text)
- {
- Print (code, location.IsNull ? "" :
location.ToString (), text);
- }
}
sealed class WarningMessage : AbstractMessage {
- Location loc = Location.Null;
readonly int Level;
public WarningMessage (int level)
@@ -195,9 +199,9 @@
get { return true; }
}
- bool IsEnabled (int code)
+ bool IsEnabled (int code, Location loc)
{
- if (RootContext.WarningLevel < Level)
+ if (WarningLevel < Level)
return false;
if (warning_ignore_table != null) {
@@ -206,7 +210,7 @@
}
}
- if (warning_regions_table == null || loc.Equals
(Location.Null))
+ if (warning_regions_table == null || loc.IsNull)
return true;
WarningRegions regions =
(WarningRegions)warning_regions_table [loc.Name];
@@ -216,9 +220,9 @@
return regions.IsWarningEnabled (code, loc.Row);
}
- public override void Print(int code, string location,
string text)
+ public override void Print (int code, Location
location, string text)
{
- if (!IsEnabled (code)) {
+ if (!IsEnabled (code, location)) {
extra_information.Clear ();
return;
}
@@ -232,12 +236,6 @@
base.Print (code, location, text);
}
- public override void Print(int code, Location location,
string text)
- {
- loc = location;
- base.Print (code, location, text);
- }
-
public override string MessageType {
get {
return "warning";
@@ -247,7 +245,7 @@
sealed class ErrorMessage : AbstractMessage {
- public override void Print(int code, string location,
string text)
+ public override void Print(int code, Location location,
string text)
{
Errors++;
base.Print (code, location, text);
@@ -345,6 +343,9 @@
static public void SymbolRelatedToPreviousError (MemberInfo mi)
{
+ if (reporting_disabled)
+ return;
+
Type dt = TypeManager.DropGenericTypeArguments
(mi.DeclaringType);
DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
if (temp_ds == null) {
@@ -370,6 +371,9 @@
static public void SymbolRelatedToPreviousError (Type type)
{
+ if (reporting_disabled)
+ return;
+
type = TypeManager.DropGenericTypeArguments (type);
if (TypeManager.IsGenericParameter (type)) {
@@ -397,6 +401,9 @@
public static void ExtraInformation (Location loc, string msg)
{
+ if (reporting_disabled)
+ return;
+
extra_information.Add (String.Format ("{0} {1}", loc,
msg));
}
@@ -513,6 +520,18 @@
return expected_error;
}
}
+
+ public static int WarningLevel {
+ get {
+ if (reporting_disabled)
+ return 0;
+
+ return warning_level;
+ }
+ set {
+ warning_level = value;
+ }
+ }
public static int DebugFlags = 0;
Modified: trunk/mcs/mcs/rootcontext.cs
===================================================================
--- trunk/mcs/mcs/rootcontext.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/rootcontext.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -107,7 +107,7 @@
root = new RootTypes ();
type_container_resolve_order = new ArrayList ();
EntryPoint = null;
- WarningLevel = 3;
+ Report.WarningLevel = WarningLevel = 3;
Checked = false;
Unsafe = false;
StdLib = true;
@@ -177,9 +177,9 @@
static Type BootstrapCorlib_ResolveType (TypeContainer root,
string name, VerifyBootstrapType typeVerifier)
{
TypeLookupExpression tle = new TypeLookupExpression
(name);
- Report.DisableErrors ();
+ Report.DisableReporting ();
TypeExpr te = tle.ResolveAsTypeTerminal (root, false);
- Report.EnableErrors ();
+ Report.EnableReporting ();
if (te == null) {
Report.Error (518, "The predefined type `{0}'
is not defined or imported", name);
return null;
Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs 2007-07-13 13:08:28 UTC (rev 81942)
+++ trunk/mcs/mcs/statement.cs 2007-07-13 13:43:14 UTC (rev 81943)
@@ -93,9 +93,9 @@
//
protected virtual void CloneTo (CloneContext clonectx,
Statement target)
{
- throw new Exception (String.Format ("Statement.CloneTo
not implemented for {0}", this.GetType ()));
+ throw new InternalErrorException ("{0} does not
implement Statement.CloneTo", this.GetType ());
}
-
+
public Statement Clone (CloneContext clonectx)
{
Statement s = (Statement) this.MemberwiseClone ();
@@ -143,6 +143,18 @@
return result;
}
+ ///
+ /// Remaps block to cloned copy if one exists.
+ ///
+ public Block RemapBlockCopy (Block from)
+ {
+ Block mapped_to = (Block)block_map[from];
+ if (mapped_to == null)
+ return from;
+
+ return mapped_to;
+ }
+
public void AddVariableMap (LocalInfo from, LocalInfo to)
{
if (variable_map == null)
@@ -697,7 +709,8 @@
/// Implements the return statement
/// </summary>
public class Return : Statement {
- public Expression Expr;
+ Expression Expr;
+ bool unwind_protect;
public Return (Expression expr, Location l)
{
@@ -705,18 +718,15 @@
loc = l;
}
- bool unwind_protect;
-
public override bool Resolve (EmitContext ec)
{
AnonymousContainer am = ec.CurrentAnonymousMethod;
if ((am != null) && am.IsIterator && ec.InIterator) {
Report.Error (1622, loc, "Cannot return a value
from iterators. Use the yield return " +
"statement to return a value, or
yield break to end the iteration");
- return false;
}
-
- if (ec.ReturnType == null){
+
+ if (ec.ReturnType == null && !ec.InferReturnType){
if (Expr != null){
if (am != null){
Report.Error (1662, loc,
@@ -750,12 +760,11 @@
}
}
- int errors = Report.Errors;
unwind_protect = ec.CurrentBranching.AddReturnOrigin
(ec.CurrentBranching.CurrentUsageVector, loc);
if (unwind_protect)
ec.NeedReturnLabel ();
ec.CurrentBranching.CurrentUsageVector.Goto ();
- return errors == Report.Errors;
+ return true;
}
protected override void DoEmit (EmitContext ec)
@@ -1491,6 +1500,11 @@
protected static int id;
int this_id;
+
+ int assignable_slots;
+ protected ScopeInfo scope_info;
+ bool unreachable_shown;
+ bool unreachable;
public Block (Block parent)
: this (parent, (Flags) 0, Location.Null, Location.Null)
@@ -1852,7 +1866,6 @@
flags |= Flags.IsDestructor;
}
- int assignable_slots;
public int AssignableSlots {
get {
if ((flags & Flags.VariablesInitialized) == 0)
@@ -1861,8 +1874,6 @@
}
}
- protected ScopeInfo scope_info;
-
public ScopeInfo ScopeInfo {
get { return scope_info; }
}
@@ -2024,9 +2035,6 @@
}
}
- bool unreachable_shown;
- bool unreachable;
-
private void CheckPossibleMistakenEmptyStatement (Statement s)
{
Statement body;
@@ -2078,7 +2086,7 @@
for (current_statement = 0; current_statement <
statements.Count; current_statement++) {
Statement s = (Statement) statements
[current_statement];
// Check possible empty statement (CS0642)
- if (RootContext.WarningLevel >= 3 &&
+ if (Report.WarningLevel >= 3 &&
current_statement + 1 <
statements.Count &&
statements [current_statement +
1] is Block)
CheckPossibleMistakenEmptyStatement (s);
@@ -2108,6 +2116,9 @@
//
if (!s.Resolve (ec)) {
+ if (ec.IsInProbingMode)
+ return false;
+
ok = false;
statements [current_statement] =
EmptyStatement.Value;
continue;
@@ -2231,12 +2242,11 @@
clonectx.AddBlockMap (this, target);
- target.Toplevel = (ToplevelBlock) clonectx.LookupBlock
(Toplevel);
+ //target.Toplevel = (ToplevelBlock)
clonectx.LookupBlock (Toplevel);
target.Explicit = (ExplicitBlock) clonectx.LookupBlock
(Explicit);
- if (Parent != null)
- target.Parent = clonectx.LookupBlock (Parent);
+ target.Parent = clonectx.RemapBlockCopy (Parent);
- target.statements = new ArrayList ();
+ target.statements = new ArrayList (statements.Count);
if (target.children != null){
target.children = new ArrayList ();
foreach (Block b in children){
@@ -2344,6 +2354,8 @@
FlowBranchingToplevel top_level_branching;
AnonymousContainer anonymous_container;
RootScopeInfo root_scope;
+ Parameters parameters;
+ ToplevelParameterInfo[] parameter_info;
public bool HasVarargs {
get { return (flags & Flags.HasVarargs) != 0; }
@@ -2357,7 +2369,6 @@
//
// The parameters for the block.
//
- Parameters parameters;
public Parameters Parameters {
get { return parameters; }
}
@@ -2467,7 +2478,6 @@
return true;
}
- ToplevelParameterInfo [] parameter_info;
void ProcessParameters ()
{
int n = parameters.Count;
@@ -2719,7 +2729,7 @@
Block block = new ExplicitBlock (this, StartLocation,
EndLocation);
foreach (Statement stmt in statements)
block.AddStatement (stmt);
- statements = new ArrayList ();
+ statements.Clear ();
statements.Add (new MoveNextStatement (iterator,
block));
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches