private static string GetCapturedVariableFieldName(Symbol variable, ref int uniqueId)
        {
            if (IsThis(variable))
            {
                return(GeneratedNames.ThisProxyName());
            }

            var local = variable as LocalSymbol;

            if ((object)local != null)
            {
                if (local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass)
                {
                    return(GeneratedNames.MakeLambdaDisplayClassStorageName(uniqueId++));
                }

                if (local.SynthesizedLocalKind == SynthesizedLocalKind.ExceptionFilterAwaitHoistedExceptionLocal)
                {
                    return(GeneratedNames.MakeHoistedLocalFieldName(string.Empty, uniqueId++));
                }
            }

            Debug.Assert(variable.Name != null);
            return(variable.Name);
        }
示例#2
0
        private SynthesizedFieldSymbolBase MakeHoistedLocalField(TypeMap TypeMap, LocalSymbol local, TypeSymbol type)
        {
            Debug.Assert(local.SynthesizedLocalKind == SynthesizedLocalKind.None ||
                         local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass);

            int index = nextLocalNumber++;

            // Special Case: There's logic in the EE to recognize locals that have been captured by a lambda
            // and would have been hoisted for the state machine.  Basically, we just hoist the local containing
            // the instance of the lambda display class and retain its original name (rather than using an
            // iterator local name).  See FUNCBRECEE::ImportIteratorMethodInheritedLocals.
            string fieldName = (local.SynthesizedLocalKind == SynthesizedLocalKind.LambdaDisplayClass)
                ? GeneratedNames.MakeLambdaDisplayClassStorageName(index)
                : GeneratedNames.MakeHoistedLocalFieldName(local.Name, index);

            return(F.StateMachineField(TypeMap.SubstituteType(type), fieldName, index));
        }