예제 #1
0
        private SynthesizedFieldSymbolBase MakeHoistedField(TypeMap TypeMap, LocalSymbol local, TypeSymbol type)
        {
            Debug.Assert(local.DeclarationKind != LocalDeclarationKind.CompilerGenerated);
            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.DeclarationKind == LocalDeclarationKind.CompilerGeneratedLambdaDisplayClassLocal
                ? local.Name
                : GeneratedNames.MakeIteratorLocalName(local.Name, index);

            return(F.SynthesizeField(TypeMap.SubstituteType(type), fieldName, index, isPublic: true));
        }
            public void HoistLocal(LocalSymbol local, SyntheticBoundNodeFactory F)
            {
                if (!hoistedLocals.Keys.Any(l => l.Name == local.Name && l.Type == local.Type))
                {
                    hoistedLocals.Add(local, local);
                    return;
                }

                // code uses "await" in two sibling catches with exception filters
                // locals with same names and types may cause problems if they are lifted
                // and become fields with identical signatures.
                // To avoid such problems we will mangle the name of the second local.
                // This will only affect debugging of this extremely rare case.
                var newName  = GeneratedNames.MakeIteratorLocalName(local.Name, hoistedLocals.Count);
                var newLocal = F.SynthesizedLocal(local.Type, newName);

                hoistedLocals.Add(local, newLocal);
            }