}
ParameterReference pr = Expr as ParameterReference;
- if ((pr != null) && (ec.capture_context != null) &&
- ec.capture_context.IsParameterCaptured (pr.Name)) {
+ if ((pr != null) && pr.Parameter.IsCaptured) {
AnonymousMethod.Error_AddressOfCapturedVar (pr.Name, loc);
return null;
}
StoreFromPtr (ec.ig, type);
- if (temporary != null)
+ if (temporary != null) {
temporary.Emit (ec);
+ temporary.Release (ec);
+ }
}
public void AddressOf (EmitContext ec, AddressOp Mode)
#region IVariable Members
public VariableInfo VariableInfo {
- get {
- return null;
- }
+ get { return null; }
}
public bool VerifyFixed ()
PostIncrement = IsPost,
PostDecrement = IsPost | IsDecrement
}
-
+
Mode mode;
bool is_expr = false;
bool recurse = false;
-
+
Expression expr;
//
// This is expensive for the simplest case.
//
StaticCallExpr method;
-
+
public UnaryMutator (Mode m, Expression e, Location l)
{
mode = m;
return (mode == Mode.PreIncrement || mode == Mode.PostIncrement) ?
"++" : "--";
}
-
+
/// <summary>
/// Returns whether an object of type `t' can be incremented
/// or decremented with add/sub (ie, basically whether we can
}
}
-
+
void EmitCode (EmitContext ec, bool is_expr)
{
recurse = true;
// having to allocate another expression
//
if (recurse) {
- ((IAssignMethod) expr).Emit (ec, is_expr && (mode == Mode.PostIncrement || mode == Mode.PostDecrement));
+ ((IAssignMethod) expr).Emit (ec, is_expr && (mode == Mode.PostIncrement || mode == Mode.PostDecrement));
if (method == null)
LoadOneAndEmitOp (ec, expr.Type);
else
recurse = false;
return;
}
-
+
EmitCode (ec, true);
}
-
+
public override void EmitStatement (EmitContext ec)
{
EmitCode (ec, false);
this.loc = loc;
if (target_type == TypeManager.system_void_expr)
- Report.Error (1547, loc, "Keyword `void' cannot be used in this context");
+ Error_VoidInvalidInTheContext (loc);
}
public Expression TargetType {
void Error_OperatorCannotBeApplied ()
{
- Error_OperatorCannotBeApplied (Location, OperName (oper), left.GetSignatureForError (), right.GetSignatureForError ());
+ Error_OperatorCannotBeApplied (Location, OperName (oper), TypeManager.CSharpName (left.Type),
+ TypeManager.CSharpName(right.Type));
}
static bool is_unsigned (Type t)
ig.MarkLabel (false_target);
op.Emit (ec);
ig.MarkLabel (end_target);
+
+ // We release 'left_temp' here since 'op' may refer to it too
+ left_temp.Release (ec);
}
}
}
+ public abstract class VariableReference : Expression, IAssignMethod, IMemoryLocation {
+ bool prepared;
+ LocalTemporary temp;
+
+ public abstract Variable Variable {
+ get;
+ }
+
+ public abstract bool IsRef {
+ get;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ Emit (ec, false);
+ }
+
+ //
+ // This method is used by parameters that are references, that are
+ // being passed as references: we only want to pass the pointer (that
+ // is already stored in the parameter, not the address of the pointer,
+ // and not the value of the variable).
+ //
+ public void EmitLoad (EmitContext ec)
+ {
+ Report.Debug (64, "VARIABLE EMIT LOAD", this, Variable, type, loc);
+ if (!prepared)
+ Variable.EmitInstance (ec);
+ Variable.Emit (ec);
+ }
+
+ public void Emit (EmitContext ec, bool leave_copy)
+ {
+ Report.Debug (64, "VARIABLE EMIT", this, Variable, type, IsRef, loc);
+
+ EmitLoad (ec);
+
+ if (IsRef) {
+ if (prepared)
+ ec.ig.Emit (OpCodes.Dup);
+
+ //
+ // If we are a reference, we loaded on the stack a pointer
+ // Now lets load the real value
+ //
+ LoadFromPtr (ec.ig, type);
+ }
+
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+
+ if (IsRef || Variable.NeedsTemporary) {
+ temp = new LocalTemporary (Type);
+ temp.Store (ec);
+ }
+ }
+ }
+
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy,
+ bool prepare_for_load)
+ {
+ Report.Debug (64, "VARIABLE EMIT ASSIGN", this, Variable, type, IsRef,
+ source, loc);
+
+ ILGenerator ig = ec.ig;
+ prepared = prepare_for_load;
+
+ Variable.EmitInstance (ec);
+ if (prepare_for_load && Variable.HasInstance)
+ ig.Emit (OpCodes.Dup);
+ else if (IsRef && !prepared)
+ Variable.Emit (ec);
+
+ source.Emit (ec);
+
+ if (leave_copy) {
+ ig.Emit (OpCodes.Dup);
+ if (IsRef || Variable.NeedsTemporary) {
+ temp = new LocalTemporary (Type);
+ temp.Store (ec);
+ }
+ }
+
+ if (IsRef)
+ StoreFromPtr (ig, type);
+ else
+ Variable.EmitAssign (ec);
+
+ if (temp != null) {
+ temp.Emit (ec);
+ temp.Release (ec);
+ }
+ }
+
+ public void AddressOf (EmitContext ec, AddressOp mode)
+ {
+ Variable.EmitInstance (ec);
+ Variable.EmitAddressOf (ec);
+ }
+ }
+
/// <summary>
/// Local variables
/// </summary>
- public class LocalVariableReference : Expression, IAssignMethod, IMemoryLocation, IVariable {
+ public class LocalVariableReference : VariableReference, IVariable {
public readonly string Name;
public readonly Block Block;
public LocalInfo local_info;
bool is_readonly;
- bool prepared;
- LocalTemporary temp;
+ Variable variable;
public LocalVariableReference (Block block, string name, Location l)
{
get { return local_info.VariableInfo; }
}
+ public override bool IsRef {
+ get { return false; }
+ }
+
public bool IsReadOnly {
get { return is_readonly; }
}
if (!VerifyAssigned (ec))
return null;
- if (ec.CurrentAnonymousMethod != null){
- //
- // If we are referencing a variable from the external block
- // flag it for capturing
- //
- if ((local_info.Block.Toplevel != ec.CurrentBlock.Toplevel) ||
- ec.CurrentAnonymousMethod.IsIterator)
- {
- if (local_info.AddressTaken){
- AnonymousMethod.Error_AddressOfCapturedVar (local_info.Name, loc);
- return null;
- }
- ec.CaptureVariable (local_info);
+ //
+ // If we are referencing a variable from the external block
+ // flag it for capturing
+ //
+ if (ec.MustCaptureVariable (local_info)) {
+ if (local_info.AddressTaken){
+ AnonymousMethod.Error_AddressOfCapturedVar (local_info.Name, loc);
+ return null;
}
+
+ ScopeInfo scope = local_info.Block.CreateScopeInfo ();
+ variable = scope.AddLocal (local_info);
+ type = variable.Type;
}
return this;
return Name == lvr.Name && Block == lvr.Block;
}
- public override void Emit (EmitContext ec)
- {
- ILGenerator ig = ec.ig;
-
- if (local_info.FieldBuilder == null){
- //
- // A local variable on the local CLR stack
- //
- ig.Emit (OpCodes.Ldloc, local_info.LocalBuilder);
- } else {
- //
- // A local variable captured by anonymous methods.
- //
- if (!prepared)
- ec.EmitCapturedVariableInstance (local_info);
-
- ig.Emit (OpCodes.Ldfld, local_info.FieldBuilder);
- }
- }
-
- public void Emit (EmitContext ec, bool leave_copy)
- {
- Emit (ec);
- if (leave_copy){
- ec.ig.Emit (OpCodes.Dup);
- if (local_info.FieldBuilder != null){
- temp = new LocalTemporary (Type);
- temp.Store (ec);
- }
- }
- }
-
- public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
- {
- ILGenerator ig = ec.ig;
- prepared = prepare_for_load;
-
- if (local_info.FieldBuilder == null){
- //
- // A local variable on the local CLR stack
- //
- if (local_info.LocalBuilder == null)
- throw new Exception ("This should not happen: both Field and Local are null");
-
- source.Emit (ec);
- if (leave_copy)
- ec.ig.Emit (OpCodes.Dup);
- ig.Emit (OpCodes.Stloc, local_info.LocalBuilder);
- } else {
- //
- // A local variable captured by anonymous methods or itereators.
- //
- ec.EmitCapturedVariableInstance (local_info);
-
- if (prepare_for_load)
- ig.Emit (OpCodes.Dup);
- source.Emit (ec);
- if (leave_copy){
- ig.Emit (OpCodes.Dup);
- temp = new LocalTemporary (Type);
- temp.Store (ec);
- }
- ig.Emit (OpCodes.Stfld, local_info.FieldBuilder);
- if (temp != null)
- temp.Emit (ec);
- }
- }
-
- public void AddressOf (EmitContext ec, AddressOp mode)
- {
- ILGenerator ig = ec.ig;
-
- if (local_info.FieldBuilder == null){
- //
- // A local variable on the local CLR stack
- //
- ig.Emit (OpCodes.Ldloca, local_info.LocalBuilder);
- } else {
- //
- // A local variable captured by anonymous methods or iterators
- //
- ec.EmitCapturedVariableInstance (local_info);
- ig.Emit (OpCodes.Ldflda, local_info.FieldBuilder);
- }
+ public override Variable Variable {
+ get { return variable != null ? variable : local_info.Variable; }
}
public override string ToString ()
/// This represents a reference to a parameter in the intermediate
/// representation.
/// </summary>
- public class ParameterReference : Expression, IAssignMethod, IMemoryLocation, IVariable {
+ public class ParameterReference : VariableReference, IVariable {
Parameter par;
string name;
int idx;
Block block;
VariableInfo vi;
- public bool is_ref, is_out, prepared;
+ public bool is_ref, is_out;
public bool IsOut {
get {
}
}
- public bool IsRef {
+ public override bool IsRef {
get {
return is_ref;
}
}
}
- LocalTemporary temp;
+ public Parameter Parameter {
+ get {
+ return par;
+ }
+ }
+
+ Variable variable;
public ParameterReference (Parameter par, Block block, int idx, Location loc)
{
get { return vi; }
}
+ public override Variable Variable {
+ get { return variable != null ? variable : par.Variable; }
+ }
+
public bool VerifyFixed ()
{
// A parameter is fixed if it's a value parameter (i.e., no modifier like out, ref, param).
if (is_out)
vi = block.ParameterMap [idx];
- if (ec.CurrentAnonymousMethod != null){
- if (is_ref && !block.Toplevel.IsLocalParameter (name)){
- Report.Error (1628, Location, "Cannot use ref or out parameter `{0}' inside an anonymous method block",
- par.Name);
- return false;
- }
+ AnonymousContainer am = ec.CurrentAnonymousMethod;
+ if (am == null)
+ return true;
- //
- // If we are referencing the parameter from the external block
- // flag it for capturing
- //
- //Console.WriteLine ("Is parameter `{0}' local? {1}", name, block.IsLocalParameter (name));
- if (!block.Toplevel.IsLocalParameter (name)){
- ec.CaptureParameter (name, type, idx);
+ if (is_ref && !block.Toplevel.IsLocalParameter (name)){
+ Report.Error (1628, Location,
+ "Cannot use ref or out parameter `{0}' inside an " +
+ "anonymous method block", par.Name);
+ return false;
+ }
+
+ if (!am.IsIterator && block.Toplevel.IsLocalParameter (name))
+ return true;
+
+ AnonymousMethodHost host = null;
+ ToplevelBlock toplevel = block.Toplevel;
+ while (toplevel != null) {
+ if (toplevel.IsLocalParameter (name)) {
+ host = toplevel.AnonymousMethodHost;
+ break;
}
+
+ toplevel = toplevel.Container;
}
+ variable = host.AddParameter (par, idx);
+ type = variable.Type;
return true;
}
if (!DoResolveBase (ec))
return null;
- if (is_out && ec.DoFlowAnalysis && (!ec.OmitStructFlowAnalysis || !vi.TypeInfo.IsStruct) && !IsAssigned (ec, loc))
+ if (is_out && ec.DoFlowAnalysis &&
+ (!ec.OmitStructFlowAnalysis || !vi.TypeInfo.IsStruct) && !IsAssigned (ec, loc))
return null;
return this;
ig.Emit (OpCodes.Ldarg, x);
}
- //
- // This method is used by parameters that are references, that are
- // being passed as references: we only want to pass the pointer (that
- // is already stored in the parameter, not the address of the pointer,
- // and not the value of the variable).
- //
- public void EmitLoad (EmitContext ec)
- {
- ILGenerator ig = ec.ig;
- int arg_idx = idx;
-
- if (!ec.MethodIsStatic)
- arg_idx++;
-
- EmitLdArg (ig, arg_idx);
-
- //
- // FIXME: Review for anonymous methods
- //
- }
-
- public override void Emit (EmitContext ec)
- {
- Emit (ec, false);
- }
-
- public void Emit (EmitContext ec, bool leave_copy)
- {
- ILGenerator ig = ec.ig;
- int arg_idx = idx;
-
- if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
- ec.EmitParameter (name, leave_copy, prepared, ref temp);
- return;
- }
-
- if (!ec.MethodIsStatic)
- arg_idx++;
-
- EmitLdArg (ig, arg_idx);
-
- if (is_ref) {
- if (prepared)
- ec.ig.Emit (OpCodes.Dup);
-
- //
- // If we are a reference, we loaded on the stack a pointer
- // Now lets load the real value
- //
- LoadFromPtr (ig, type);
- }
-
- if (leave_copy) {
- ec.ig.Emit (OpCodes.Dup);
-
- if (is_ref) {
- temp = new LocalTemporary (type);
- temp.Store (ec);
- }
- }
- }
-
- public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
- {
- prepared = prepare_for_load;
- if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
- ec.EmitAssignParameter (name, source, leave_copy, prepare_for_load, ref temp);
- return;
- }
-
- ILGenerator ig = ec.ig;
- int arg_idx = idx;
-
-
-
- if (!ec.MethodIsStatic)
- arg_idx++;
-
- if (is_ref && !prepared)
- EmitLdArg (ig, arg_idx);
-
- source.Emit (ec);
-
- if (leave_copy)
- ec.ig.Emit (OpCodes.Dup);
-
- if (is_ref) {
- if (leave_copy) {
- temp = new LocalTemporary (type);
- temp.Store (ec);
- }
-
- StoreFromPtr (ig, type);
-
- if (temp != null)
- temp.Emit (ec);
- } else {
- if (arg_idx <= 255)
- ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
- else
- ig.Emit (OpCodes.Starg, arg_idx);
- }
- }
-
- public void AddressOf (EmitContext ec, AddressOp mode)
- {
- if (ec.HaveCaptureInfo && ec.IsParameterCaptured (name)){
- ec.EmitAddressOfParameter (name);
- return;
- }
-
- int arg_idx = idx;
-
- if (!ec.MethodIsStatic)
- arg_idx++;
-
- if (is_ref){
- if (arg_idx <= 255)
- ec.ig.Emit (OpCodes.Ldarg_S, (byte) arg_idx);
- else
- ec.ig.Emit (OpCodes.Ldarg, arg_idx);
- } else {
- if (arg_idx <= 255)
- ec.ig.Emit (OpCodes.Ldarga_S, (byte) arg_idx);
- else
- ec.ig.Emit (OpCodes.Ldarga, arg_idx);
- }
- }
-
public override string ToString ()
{
return "ParameterReference[" + name + "]";
public bool Resolve (EmitContext ec, Location loc)
{
- bool old_do_flow_analysis = ec.DoFlowAnalysis;
- ec.DoFlowAnalysis = true;
-
- // Verify that the argument is readable
- if (ArgType != AType.Out)
- Expr = Expr.Resolve (ec);
+ using (ec.With (EmitContext.Flags.DoFlowAnalysis, true)) {
+ // Verify that the argument is readable
+ if (ArgType != AType.Out)
+ Expr = Expr.Resolve (ec);
- // Verify that the argument is writeable
- if (Expr != null && (ArgType == AType.Out || ArgType == AType.Ref))
- Expr = Expr.ResolveLValue (ec, EmptyExpression.OutAccess, loc);
+ // Verify that the argument is writeable
+ if (Expr != null && (ArgType == AType.Out || ArgType == AType.Ref))
+ Expr = Expr.ResolveLValue (ec, EmptyExpression.OutAccess, loc);
- ec.DoFlowAnalysis = old_do_flow_analysis;
-
- return Expr != null;
+ return Expr != null;
+ }
}
public void Emit (EmitContext ec)
if (!p.IsGenericParameter && q.IsGenericParameter)
return p;
- if (p.IsGenericType) {
+ if (TypeManager.HasElementType (p)) {
+ Type pe = TypeManager.GetElementType (p);
+ Type qe = TypeManager.GetElementType (q);
+ Type specific = MoreSpecific (pe, qe);
+ if (specific == pe)
+ return p;
+ if (specific == qe)
+ return q;
+ } else if (p.IsGenericType) {
Type[] pargs = TypeManager.GetTypeArguments (p);
Type[] qargs = TypeManager.GetTypeArguments (q);
return p;
if (!p_specific_at_least_once && q_specific_at_least_once)
return q;
- } else if (TypeManager.HasElementType (p)) {
- Type pe = TypeManager.GetElementType (p);
- Type qe = TypeManager.GetElementType (q);
- Type specific = MoreSpecific (pe, qe);
- if (specific == pe)
- return p;
- if (specific == qe)
- return q;
}
return null;
if (this_arg != null)
this_arg.Emit (ec);
- for (int i = 0; i < top; i ++)
+ for (int i = 0; i < top; i ++) {
temps [i].Emit (ec);
+ temps [i].Release (ec);
+ }
}
if (pd != null && pd.Count > top &&
{
eclass = ExprClass.Variable;
type = ec.ContainerType;
+ variable = new SimpleThis (type);
return this;
}
}
/// <summary>
/// Represents the `this' construct
/// </summary>
- public class This : Expression, IAssignMethod, IMemoryLocation, IVariable {
+ public class This : VariableReference, IVariable
+ {
Block block;
VariableInfo variable_info;
-
+ protected Variable variable;
+ bool is_struct;
+
public This (Block block, Location loc)
{
this.loc = loc;
return !TypeManager.IsValueType (Type);
}
+ public override bool IsRef {
+ get { return is_struct; }
+ }
+
+ public override Variable Variable {
+ get { return variable; }
+ }
+
public bool ResolveBase (EmitContext ec)
{
eclass = ExprClass.Variable;
else
type = ec.ContainerType;
+ is_struct = ec.TypeContainer is Struct;
+
if (ec.IsStatic) {
- Error (26, "Keyword `this' is not valid in a static property, static method, or static field initializer");
+ Error (26, "Keyword `this' is not valid in a static property, " +
+ "static method, or static field initializer");
return false;
}
- if (block != null && block.Toplevel.ThisVariable != null)
- variable_info = block.Toplevel.ThisVariable.VariableInfo;
+ if (block != null) {
+ if (block.Toplevel.ThisVariable != null)
+ variable_info = block.Toplevel.ThisVariable.VariableInfo;
+
+ AnonymousContainer am = ec.CurrentAnonymousMethod;
+ if (is_struct && (am != null) && !am.IsIterator) {
+ 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.");
+ return false;
+ }
+
+ AnonymousMethodHost host = block.Toplevel.AnonymousMethodHost;
+ if ((host != null) && (!is_struct || host.IsIterator)) {
+ variable = host.CaptureThis ();
+ type = variable.Type;
+ is_struct = false;
+ }
+ }
- if (ec.CurrentAnonymousMethod != null)
- ec.CaptureThis ();
+ if (variable == null)
+ variable = new SimpleThis (type);
return true;
}
if (!ResolveBase (ec))
return null;
- if ((variable_info != null) && !(type.IsValueType && ec.OmitStructFlowAnalysis) && !variable_info.IsAssigned (ec)) {
- Error (188, "The `this' object cannot be used before all of its fields are assigned to");
+ if ((variable_info != null) && !(type.IsValueType && ec.OmitStructFlowAnalysis) &&
+ !variable_info.IsAssigned (ec)) {
+ Error (188, "The `this' object cannot be used before all of its " +
+ "fields are assigned to");
variable_info.SetAssigned (ec);
return this;
}
return this;
}
-
- public void Emit (EmitContext ec, bool leave_copy)
- {
- Emit (ec);
- if (leave_copy)
- ec.ig.Emit (OpCodes.Dup);
- }
-
- public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
- {
- ILGenerator ig = ec.ig;
-
- if (ec.TypeContainer is Struct){
- ec.EmitThis (false);
- source.Emit (ec);
-
- LocalTemporary t = null;
- if (leave_copy) {
- t = new LocalTemporary (type);
- ec.ig.Emit (OpCodes.Dup);
- t.Store (ec);
- }
-
- ig.Emit (OpCodes.Stobj, type);
-
- if (leave_copy)
- t.Emit (ec);
- } else {
- throw new Exception ("how did you get here");
- }
- }
-
- public override void Emit (EmitContext ec)
- {
- ILGenerator ig = ec.ig;
-
- ec.EmitThis (false);
- if (ec.TypeContainer is Struct)
- ig.Emit (OpCodes.Ldobj, type);
- }
-
public override int GetHashCode()
{
return block.GetHashCode ();
return block == t.block;
}
- public void AddressOf (EmitContext ec, AddressOp mode)
+ protected class SimpleThis : Variable
{
- ec.EmitThis (true);
+ Type type;
- // FIMXE
- // FIGURE OUT WHY LDARG_S does not work
- //
- // consider: struct X { int val; int P { set { val = value; }}}
- //
- // Yes, this looks very bad. Look at `NOTAS' for
- // an explanation.
- // ec.ig.Emit (OpCodes.Ldarga_S, (byte) 0);
+ public SimpleThis (Type type)
+ {
+ this.type = type;
+ }
+
+ public override Type Type {
+ get { return type; }
+ }
+
+ public override bool HasInstance {
+ get { return false; }
+ }
+
+ public override bool NeedsTemporary {
+ get { return false; }
+ }
+
+ public override void EmitInstance (EmitContext ec)
+ {
+ // Do nothing.
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ ec.ig.Emit (OpCodes.Ldarg_0);
+ }
+
+ public override void EmitAssign (EmitContext ec)
+ {
+ throw new InvalidOperationException ();
+ }
+
+ public override void EmitAddressOf (EmitContext ec)
+ {
+ ec.ig.Emit (OpCodes.Ldarg_0);
+ }
}
}
public override bool GetAttributableValue (Type valueType, out object value)
{
+ if (typearg.ContainsGenericParameters) {
+ Report.SymbolRelatedToPreviousError(typearg);
+ Report.Error(416, loc, "`{0}': an attribute argument cannot use type parameters",
+ TypeManager.CSharpName(typearg));
+ value = null;
+ return false;
+ }
+
if (valueType == TypeManager.object_type) {
value = (object)typearg;
return true;
}
type_queried = texpr.Type;
+ if (type_queried.IsEnum)
+ type_queried = TypeManager.EnumToUnderlying (type_queried);
+
+ if (type_queried == TypeManager.void_type) {
+ Expression.Error_VoidInvalidInTheContext (loc);
+ return null;
+ }
int size_of = GetTypeSize (type_queried);
if (size_of > 0) {
public override Expression DoResolve (EmitContext ec)
{
- using (ec.WithCheckState (true, true))
+ using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
Expr = Expr.Resolve (ec);
if (Expr == null)
public override void Emit (EmitContext ec)
{
- using (ec.WithCheckState (true, true))
+ using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
Expr.Emit (ec);
}
public override void EmitBranchable (EmitContext ec, Label target, bool onTrue)
{
- using (ec.WithCheckState (true, true))
+ using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
Expr.EmitBranchable (ec, target, onTrue);
}
}
public override Expression DoResolve (EmitContext ec)
{
- using (ec.WithCheckState (false, false))
+ using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
Expr = Expr.Resolve (ec);
if (Expr == null)
public override void Emit (EmitContext ec)
{
- using (ec.WithCheckState (false, false))
+ using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
Expr.Emit (ec);
}
public override void EmitBranchable (EmitContext ec, Label target, bool onTrue)
{
- using (ec.WithCheckState (false, false))
+ using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
Expr.EmitBranchable (ec, target, onTrue);
}
}
}
StoreFromPtr (ec.ig, t);
- if (temp != null)
+ if (temp != null) {
temp.Emit (ec);
+ temp.Release (ec);
+ }
return;
}
ig.Emit (OpCodes.Call, set);
}
- if (temp != null)
+ if (temp != null) {
temp.Emit (ec);
+ temp.Release (ec);
+ }
}
public void AddressOf (EmitContext ec, AddressOp mode)
public override Expression DoResolve (EmitContext ec)
{
- ArrayList AllGetters = new ArrayList();
if (!CommonResolve (ec))
return null;
//
// This is a group of properties, piles of them.
- bool found_any = false, found_any_getters = false;
- Type lookup_type = indexer_type;
+ ArrayList AllGetters = null;
- Indexers ilist = Indexers.GetIndexersForType (current_type, lookup_type);
+ Indexers ilist = Indexers.GetIndexersForType (current_type, indexer_type);
if (ilist.Properties != null) {
- found_any = true;
+ AllGetters = new ArrayList(ilist.Properties.Count);
foreach (Indexers.Indexer ix in ilist.Properties) {
if (ix.Getter != null)
AllGetters.Add (ix.Getter);
}
}
- if (AllGetters.Count > 0) {
- found_any_getters = true;
- get = (MethodInfo) Invocation.OverloadResolve (
- ec, new MethodGroupExpr (AllGetters, loc),
- arguments, false, loc);
- }
-
- if (!found_any) {
+ if (AllGetters == null) {
Report.Error (21, loc, "Cannot apply indexing with [] to an expression of type `{0}'",
- TypeManager.CSharpName (indexer_type));
+ TypeManager.CSharpName (indexer_type));
return null;
}
- if (!found_any_getters) {
+ if (AllGetters.Count == 0) {
+ // FIXME: we cannot simply select first one as the error message is missleading when
+ // multiple indexers exist
+ Indexers.Indexer first_indexer = (Indexers.Indexer)ilist.Properties[ilist.Properties.Count - 1];
Report.Error (154, loc, "The property or indexer `{0}' cannot be used in this context because it lacks the `get' accessor",
- "XXXXXXXX");
+ TypeManager.GetFullNameSignature (first_indexer.PropertyInfo));
return null;
}
+ get = (MethodInfo)Invocation.OverloadResolve (ec, new MethodGroupExpr (AllGetters, loc),
+ arguments, false, loc);
+
if (get == null) {
Invocation.Error_WrongNumArguments (loc, "this", arguments.Count);
return null;
Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, set, set_arguments, loc, false, prepared);
- if (temp != null)
+ if (temp != null) {
temp.Emit (ec);
+ temp.Release (ec);
+ }
}
Type ltype = lexpr.Type;
if ((ltype == TypeManager.void_type) && (dim != "*")) {
- Report.Error (1547, Location,
- "Keyword 'void' cannot be used in this context");
+ Error_VoidInvalidInTheContext (loc);
return null;
}