Пример #1
0
        internal static string MakeTemporaryName(TempKind kind, int uniqueId)
        {
            Debug.Assert((int)kind >= 0); // Negative kinds should not be named.

            // Matches names generated by Dev11.
            return(string.Format(TemporaryNamePrefix + "{0}${1:0000}", (int)kind, uniqueId));
        }
Пример #2
0
        internal SynthesizedLocal(
            MethodSymbol containingMethod,
            TypeSymbol type,
            string name             = null,
            CSharpSyntaxNode syntax = null,
            bool isPinned           = false,
            RefKind refKind         = RefKind.None,
            LocalDeclarationKind declarationKind = LocalDeclarationKind.CompilerGenerated,
            TempKind tempKind = TempKind.None)
        {
            this.containingMethod = containingMethod;
            Debug.Assert(type.SpecialType != SpecialType.System_Void);
            Debug.Assert((tempKind == TempKind.None) == (syntax == null));
#if NAME_TEMPS
            if (string.IsNullOrEmpty(name))
            {
                name = "temp_" + Interlocked.Increment(ref nextDebugTempNumber);
            }
#endif
            this.name            = name;
            this.type            = type;
            this.syntax          = syntax;
            this.isPinned        = isPinned;
            this.declarationKind = declarationKind;
            this.refKind         = refKind;
            this.tempKind        = tempKind;
        }
            private void AddLocal(TempKind tempKind)
            {
                var info = this.localInfo[this.slotIndex];

                // We do not emit custom modifiers on locals so ignore the
                // previous version of the local if it had custom modifiers.
                if (info.CustomModifiers.IsDefaultOrEmpty)
                {
                    var constraints = GetConstraints(info);
                    var local       = new EncLocalInfo(this.offset, (Cci.ITypeReference)info.Type, constraints, (int)tempKind);
                    this.locals.Add(local, this.slotIndex);
                }

                this.slotIndex++;
            }
Пример #4
0
        internal static bool TryParseTemporaryName(string name, out TempKind kind, out int uniqueId)
        {
            if (name.StartsWith(TemporaryNamePrefix, StringComparison.Ordinal))
            {
                name = name.Substring(TemporaryNamePrefix.Length);
                int separator = name.IndexOf('$');
                if (separator > 0)
                {
                    int k;
                    int n;
                    if (int.TryParse(name.Substring(0, separator), out k) && int.TryParse(name.Substring(separator + 1), out n))
                    {
                        kind     = (TempKind)k;
                        uniqueId = n;
                        return(true);
                    }
                }
            }

            kind     = TempKind.None;
            uniqueId = 0;
            return(false);
        }
Пример #5
0
        internal SynthesizedLocal(
            MethodSymbol containingMethod,
            TypeSymbol type,
            string name = null,
            CSharpSyntaxNode syntax = null,
            bool isPinned = false,
            RefKind refKind = RefKind.None,
            LocalDeclarationKind declarationKind = LocalDeclarationKind.CompilerGenerated,
            TempKind tempKind = TempKind.None)
        {
            this.containingMethod = containingMethod;
            Debug.Assert(type.SpecialType != SpecialType.System_Void);
            Debug.Assert((tempKind == TempKind.None) == (syntax == null));
#if NAME_TEMPS
            if (string.IsNullOrEmpty(name)) name = "temp_" + Interlocked.Increment(ref nextDebugTempNumber);
#endif
            this.name = name;
            this.type = type;
            this.syntax = syntax;
            this.isPinned = isPinned;
            this.declarationKind = declarationKind;
            this.refKind = refKind;
            this.tempKind = tempKind;
        }
Пример #6
0
 public LocalSymbol SynthesizedLocal(TypeSymbol type, string name = null, CSharpSyntaxNode syntax = null, bool isPinned = false, RefKind refKind = RefKind.None, TempKind tempKind = TempKind.None)
 {
     return new SynthesizedLocal(CurrentMethod, type, name, syntax, isPinned: isPinned, refKind: refKind, tempKind: tempKind);
 }
Пример #7
0
 /// <summary>
 /// Takes an expression and returns the bound local expression "temp" 
 /// and the bound assignment expression "temp = expr".
 /// </summary>
 public BoundLocal StoreToTemp(BoundExpression argument, out BoundAssignmentOperator store, RefKind refKind = RefKind.None, TempKind tempKind = TempKind.None)
 {
     MethodSymbol containingMethod = this.CurrentMethod;
     var syntax = argument.Syntax;
     var type = argument.Type;
     var local = new BoundLocal(
         syntax,
         new SynthesizedLocal(containingMethod, type, syntax: (tempKind == TempKind.None) ? null : syntax, refKind: refKind, tempKind: tempKind),
         null,
         type);
     store = new BoundAssignmentOperator(
         syntax,
         local,
         argument,
         refKind,
         type);
     return local;
 }
 public LocalName(string name, TempKind kind, int uniqueId)
 {
     this.Name     = name;
     this.Kind     = kind;
     this.UniqueId = uniqueId;
 }
Пример #9
0
        internal static bool TryParseTemporaryName(string name, out TempKind kind, out int uniqueId)
        {
            if (name.StartsWith(TemporaryNamePrefix, StringComparison.Ordinal))
            {
                name = name.Substring(TemporaryNamePrefix.Length);
                int separator = name.IndexOf('$');
                if (separator > 0)
                {
                    int k;
                    int n;
                    if (int.TryParse(name.Substring(0, separator), out k) && int.TryParse(name.Substring(separator + 1), out n))
                    {
                        kind = (TempKind)k;
                        uniqueId = n;
                        return true;
                    }
                }
            }

            kind = TempKind.None;
            uniqueId = 0;
            return false;
        }
Пример #10
0
        internal static string MakeTemporaryName(TempKind kind, int uniqueId)
        {
            Debug.Assert((int)kind >= 0); // Negative kinds should not be named.

            // Matches names generated by Dev11.
            return string.Format(TemporaryNamePrefix + "{0}${1:0000}", (int)kind, uniqueId);
        }
 public LocalName(string name, TempKind kind, int uniqueId)
 {
     this.Name = name;
     this.Kind = kind;
     this.UniqueId = uniqueId;
 }
            private void AddLocal(TempKind tempKind)
            {
                var info = this.localInfo[this.slotIndex];

                // We do not emit custom modifiers on locals so ignore the
                // previous version of the local if it had custom modifiers.
                if (info.CustomModifiers.IsDefaultOrEmpty)
                {
                    var constraints = GetConstraints(info);
                    var local = new EncLocalInfo(this.offset, (Cci.ITypeReference)info.Type, constraints, (int)tempKind);
                    this.locals.Add(local, this.slotIndex);
                }

                this.slotIndex++;
            }
Пример #13
0
 public LocalSymbol SynthesizedLocal(TypeSymbol type, string name = null, CSharpSyntaxNode syntax = null, bool isPinned = false, RefKind refKind = RefKind.None, TempKind tempKind = TempKind.None)
 {
     return(new SynthesizedLocal(CurrentMethod, type, name, syntax, isPinned: isPinned, refKind: refKind, tempKind: tempKind));
 }
Пример #14
0
        /// <summary>
        /// Takes an expression and returns the bound local expression "temp"
        /// and the bound assignment expression "temp = expr".
        /// </summary>
        public BoundLocal StoreToTemp(BoundExpression argument, out BoundAssignmentOperator store, RefKind refKind = RefKind.None, TempKind tempKind = TempKind.None)
        {
            MethodSymbol containingMethod = this.CurrentMethod;
            var          syntax           = argument.Syntax;
            var          type             = argument.Type;
            var          local            = new BoundLocal(
                syntax,
                new SynthesizedLocal(containingMethod, type, syntax: (tempKind == TempKind.None) ? null : syntax, refKind: refKind, tempKind: tempKind),
                null,
                type);

            store = new BoundAssignmentOperator(
                syntax,
                local,
                argument,
                refKind,
                type);
            return(local);
        }