Example #1
0
            internal override ScopeBounds GetLocalScopes(ArrayBuilder <Cci.LocalScope> result, bool edgeInclusive)
            {
                uint begin = uint.MaxValue;
                uint end   = 0;

                // It may seem overkill to scan all blocks,
                // but blocks may be reordered so we cannot be sure which ones are first/last.
                if (Blocks != null)
                {
                    for (int i = 0; i < Blocks.Count; i++)
                    {
                        var block = Blocks[i];

                        if (block.Reachability != Reachability.NotReachable)
                        {
                            begin = Math.Min(begin, (uint)block.Start);
                            end   = Math.Max(end, (uint)(block.Start + block.TotalSize));
                        }
                    }
                }

                // if there are nested scopes, dump them too
                // also may need to adjust current scope bounds.
                if (_nestedScopes != null)
                {
                    ScopeBounds nestedBounds = GetLocalScopes(result, _nestedScopes, edgeInclusive);
                    begin = Math.Min(begin, nestedBounds.Begin);
                    end   = Math.Max(end, nestedBounds.End);
                }

                // we are not interested in scopes with no variables or no code in them.
                if ((_localVariables != null || _localConstants != null) && end > begin)
                {
                    uint endAdjusted = edgeInclusive ? end - 1 : end;

                    var newScope = new Cci.LocalScope(
                        begin,
                        endAdjusted - begin,
                        _localConstants.AsImmutableOrEmpty <Cci.ILocalDefinition>(),
                        _localVariables.AsImmutableOrEmpty <Cci.ILocalDefinition>());

                    result.Add(newScope);
                }

                return(new ScopeBounds(begin, end));
            }
Example #2
0
        internal DiagnosticDescriptor(
            string id,
            LocalizableString title,
            LocalizableString messageFormat,
            string category,
            DiagnosticSeverity defaultSeverity,
            bool isEnabledByDefault,
            LocalizableString description,
            string helpLinkUri,
            ImmutableArray <string> customTags)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException(CodeAnalysisResources.DiagnosticIdCantBeNullOrWhitespace, nameof(id));
            }

            if (messageFormat == null)
            {
                throw new ArgumentNullException(nameof(messageFormat));
            }

            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }

            this.Id                 = id;
            this.Title              = title;
            this.Category           = category;
            this.MessageFormat      = messageFormat;
            this.DefaultSeverity    = defaultSeverity;
            this.IsEnabledByDefault = isEnabledByDefault;
            this.Description        = description ?? string.Empty;
            this.HelpLinkUri        = helpLinkUri ?? string.Empty;
            this.CustomTags         = customTags.AsImmutableOrEmpty();
        }