* *.cs: Add IResolveContext::IsStatic.
svn path=/trunk/mcs/; revision=140171
+2009-08-18 Marek Safar <marek.safar@gmail.com>
+
+ * *.cs: Add IResolveContext::IsStatic.
+
2009-08-18 Marek Safar <marek.safar@gmail.com>
* *.cs: Moved TopBlock's methods from EmitContext to TopBlock.
{
EmitContext aec = AnonymousMethod.aec;
aec.ig = ig;
- aec.IsStatic = (ModFlags & Modifiers.STATIC) != 0;
+ aec.AnonymousStatic = (ModFlags & Modifiers.STATIC) != 0;
return aec;
}
(ec.InUnsafe ? Modifiers.UNSAFE : 0), /* No constructor */ false);
aec.CurrentAnonymousMethod = this;
- aec.IsStatic = ec.IsStatic;
IDisposable aec_dispose = null;
EmitContext.Flags flags = 0;
// TODO: Use ResolveContext only
EmitContext f_ec = new EmitContext (rc, rc.GenericDeclContainer, null, TypeManager.void_type, 0, true);
- f_ec.IsStatic = ec.IsStatic;
f_ec.CurrentBlock = ec.CurrentBlock;
EmitContext.Flags flags = EmitContext.Flags.InFieldInitializer;
get { return tc.IsInUnsafeScope; }
}
+ public bool IsStatic {
+ get { return tc.IsStatic; }
+ }
+
public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
return null;
return true;
}
- bool IsStatic {
- get {
- return (ModFlags & Modifiers.STATIC) != 0;
- }
- }
-
//
// FIXME: How do we deal with the user specifying a different
// layout?
//
// Spec mandates that constructor initializer will not have `this' access
//
- ec.IsStatic = true;
- argument_list.Resolve (ec, out dynamic);
- ec.IsStatic = false;
+ using (ec.Set (EmitContext.Flags.BaseInitializer)) {
+ argument_list.Resolve (ec, out dynamic);
+ }
if (dynamic) {
SimpleName ctor = new SimpleName (ConstructorBuilder.ConstructorName, loc);
bool IsInObsoleteScope { get; }
bool IsInUnsafeScope { get; }
+ bool IsStatic { get; }
ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc);
FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104);
InCompoundAssignment = 1 << 10,
- OmitDebuggingInfo = 1 << 11
+ OmitDebuggingInfo = 1 << 11,
+
+ BaseInitializer = 1 << 12
}
Flags flags;
- /// <summary>
- /// Whether we are emitting code inside a static or instance method
- /// </summary>
- public bool IsStatic;
-
/// <summary>
/// The value that is allowed to be returned or NULL if there is no
/// return type.
if (return_type == null)
throw new ArgumentNullException ("return_type");
- IsStatic = (code_flags & Modifiers.STATIC) != 0;
ReturnType = return_type;
IsConstructor = is_constructor;
}
get { return (flags & Flags.InUnsafe) != 0 || ResolveContext.IsInUnsafeScope; }
}
+ // TODO: Hopefully temporary hack for anonyous methods, ResolveContext != EmitContext
+ public object AnonymousStatic;
+ public bool IsStatic {
+ get { return AnonymousStatic != null ? (bool) AnonymousStatic : ResolveContext.IsStatic; }
+ }
+
public bool IsAnonymousMethodAllowed {
get { return isAnonymousMethodAllowed; }
set { isAnonymousMethodAllowed = value; }
public bool IsInFieldInitializer {
get { return (flags & Flags.InFieldInitializer) != 0; }
}
+
+ public bool IsBaseInitializer {
+ get { return (flags & Flags.BaseInitializer) != 0; }
+ }
public bool IsInCompoundAssignment {
get { return (flags & Flags.InCompoundAssignment) != 0; }
get { return false; }
}
+ public bool IsStatic {
+ get { return false; }
+ }
+
public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
throw new NotImplementedException ();
}
}
+ public bool IsStatic {
+ get { return (ModFlags & Modifiers.STATIC) != 0; }
+ }
+
#endregion
}
Expression left;
if (me.IsInstance) {
- if (ec.IsStatic || ec.IsInFieldInitializer) {
+ if (ec.IsStatic || ec.IsInFieldInitializer || ec.IsBaseInitializer) {
//
// Note that an MemberExpr can be both IsInstance and IsStatic.
// An unresolved MethodGroupExpr can contain both kinds of methods
public static bool IsThisAvailable (EmitContext ec)
{
- if (ec.IsStatic || ec.IsInFieldInitializer)
+ if (ec.IsStatic || ec.IsInFieldInitializer || ec.IsBaseInitializer)
return false;
if (ec.CurrentAnonymousMethod == null)
if (!IsThisAvailable (ec)) {
if (ec.IsStatic) {
Error (26, "Keyword `this' is not valid in a static property, static method, or static field initializer");
- } else {
+ } else if (ec.CurrentAnonymousMethod != null) {
Report.Error (1673, loc,
"Anonymous methods inside structs cannot access instance members of `this'. " +
"Consider copying `this' to a local variable outside the anonymous method and using the local instead");
+ } else {
+ Error (27, "Keyword `this' is not available in the current context");
}
}
public override Expression DoResolve (EmitContext ec)
{
- if (!ResolveBase (ec))
- return null;
-
-
- if (ec.IsInFieldInitializer) {
- Error (27, "Keyword `this' is not available in the current context");
- return null;
- }
-
+ ResolveBase (ec);
return this;
}
get { return SlaveDeclSpace.IsInUnsafeScope; }
}
+ public bool IsStatic {
+ get { return SlaveDeclSpace.IsStatic; }
+ }
+
public DeclSpace GenericDeclContainer {
get { return SlaveDeclSpace; }
}