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

            var local = variable as LocalSymbol;

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

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

                if (local.SynthesizedKind == SynthesizedLocalKind.InstrumentationPayload)
                {
                    return(GeneratedNames.MakeSynthesizedInstrumentationPayloadLocalFieldName(uniqueId++));
                }

                if (local.SynthesizedKind == SynthesizedLocalKind.UserDefined && local.ScopeDesignatorOpt?.Kind() == SyntaxKind.SwitchSection)
                {
                    return(GeneratedNames.MakeHoistedLocalFieldName(local.SynthesizedKind, uniqueId++, local.Name));
                }
            }

            Debug.Assert(variable.Name != null);
            return(variable.Name);
        }
Exemple #2
0
        private static string GetCapturedVariableFieldName(Symbol variable, ref int uniqueId)
        {
            if (IsThis(variable))
            {
                return(GeneratedNames.ThisProxyFieldName());
            }

            var local = variable as LocalSymbol;

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

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

            Debug.Assert(variable.Name != null);
            return(variable.Name);
        }
Exemple #3
0
        private static string GetCapturedVariableFieldName(Symbol variable, ref int uniqueId)
        {
            if (IsThis(variable))
            {
                return(GeneratedNames.ThisProxyFieldName());
            }

            var local = variable as LocalSymbol;

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

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

                if (local.SynthesizedKind == SynthesizedLocalKind.InstrumentationPayload)
                {
                    return(GeneratedNames.MakeSynthesizedInstrumentationPayloadLocalFieldName(
                               uniqueId++
                               ));
                }

                if (
                    local.SynthesizedKind == SynthesizedLocalKind.UserDefined &&
                    (
                        local.ScopeDesignatorOpt?.Kind() == SyntaxKind.SwitchSection ||
                        local.ScopeDesignatorOpt?.Kind() == SyntaxKind.SwitchExpressionArm
                    )
                    )
                {
                    // The programmer can use the same identifier for pattern variables in different
                    // sections of a switch statement, but they are all hoisted into
                    // the same frame for the enclosing switch statement and must be given
                    // unique field names.
                    return(GeneratedNames.MakeHoistedLocalFieldName(
                               local.SynthesizedKind,
                               uniqueId++,
                               local.Name
                               ));
                }
            }

            Debug.Assert(variable.Name != null);
            return(variable.Name);
        }
Exemple #4
0
        private static string GetCapturedVariableFieldName(Symbol variable, ref int uniqueId)
        {
            if (IsThis(variable))
            {
                return(GeneratedNames.ThisProxyFieldName());
            }

            var local = variable as LocalSymbol;

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

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

                if (local.SynthesizedKind == SynthesizedLocalKind.InstrumentationPayload)
                {
                    return(GeneratedNames.MakeSynthesizedInstrumentationPayloadLocalFieldName(uniqueId++));
                }

                if (local.SynthesizedKind == SynthesizedLocalKind.UserDefined && local.ScopeDesignatorOpt?.Kind() == SyntaxKind.SwitchSection)
                {
                    return(GeneratedNames.MakeHoistedLocalFieldName(local.SynthesizedKind, uniqueId++, local.Name));
                }

                //
                // @MattWindsor91 (Concept-C# 2017)
                //
                // We added a new type of synthesised variable to represent
                // concept witness dictionaries, so we must generate names for
                // them.

                if (local.SynthesizedKind == SynthesizedLocalKind.ConceptDictionary)
                {
                    return(GeneratedNames.MakeConceptDictionaryLocalFieldName(uniqueId++));
                }
            }

            Debug.Assert(variable.Name != null);
            return(variable.Name);
        }