String constants for CppCheck from an XmlNameTable.
示例#1
0
        /// <summary>
        /// Parses the element on which an <see cref="XmlReader"/> is positioned as a CppCheck error node.
        /// </summary>
        /// <param name="reader">The reader from which a CppCheck error shall be read.</param>
        /// <param name="strings">Strings used to parse the CppCheck log.</param>
        /// <returns>
        /// A <see cref="CppCheckError"/> parsed from the XML on which <paramref name="reader"/> is
        /// positioned.
        /// </returns>
        /// <exception cref="XmlException">The xml on which <paramref name="reader"/> is placed is
        /// in an incorrect format.</exception>
        public static CppCheckError Parse(XmlReader reader, CppCheckStrings strings)
        {
            if (!reader.IsStartElement(strings.Error))
            {
                throw reader.CreateException(ConverterResources.CppCheckElementNotError);
            }

            string id             = null;
            string message        = null;
            string verboseMessage = null;
            string severity       = null;

            while (reader.MoveToNextAttribute())
            {
                string attributeName = reader.LocalName;
                if (StringReference.AreEqual(attributeName, strings.Id))
                {
                    id = reader.Value;
                }
                else if (StringReference.AreEqual(attributeName, strings.Msg))
                {
                    message = reader.Value;
                }
                else if (StringReference.AreEqual(attributeName, strings.Verbose))
                {
                    verboseMessage = reader.Value;
                }
                else if (StringReference.AreEqual(attributeName, strings.Severity))
                {
                    severity = reader.Value;
                }
            }

            reader.MoveToElement();
            ImmutableArray <CppCheckLocation> locations = ParseLocationsSubtree(reader, strings);

            reader.Read(); // Consumes the end element or self closing element and positions the reader on the next node

            try
            {
                return(new CppCheckError(
                           id,
                           message,
                           verboseMessage,
                           severity,
                           locations
                           ));
            }
            catch (ArgumentException ex)
            {
                throw reader.CreateException(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// Parses the element on which an <see cref="XmlReader"/> is positioned as a CppCheck error node.
        /// </summary>
        /// <param name="reader">The reader from which a CppCheck error shall be read.</param>
        /// <param name="strings">Strings used to parse the CppCheck log.</param>
        /// <returns>
        /// A <see cref="CppCheckError"/> parsed from the XML on which <paramref name="reader"/> is
        /// positioned.
        /// </returns>
        /// <exception cref="XmlException">The xml on which <paramref name="reader"/> is placed is
        /// in an incorrect format.</exception>
        public static CppCheckError Parse(XmlReader reader, CppCheckStrings strings)
        {
            if (!reader.IsStartElement(strings.Error))
            {
                throw reader.CreateException(ConverterResources.CppCheckElementNotError);
            }

            string id = null;
            string message = null;
            string verboseMessage = null;
            string severity = null;
            while (reader.MoveToNextAttribute())
            {
                string attributeName = reader.LocalName;
                if (Ref.Equal(attributeName, strings.Id))
                {
                    id = reader.Value;
                }
                else if (Ref.Equal(attributeName, strings.Msg))
                {
                    message = reader.Value;
                }
                else if (Ref.Equal(attributeName, strings.Verbose))
                {
                    verboseMessage = reader.Value;
                }
                else if (Ref.Equal(attributeName, strings.Severity))
                {
                    severity = reader.Value;
                }
            }

            reader.MoveToElement();
            ImmutableArray<CppCheckLocation> locations = ParseLocationsSubtree(reader, strings);

            reader.Read(); // Consumes the end element or self closing element and positions the reader on the next node

            try
            {
                return new CppCheckError(
                    id,
                    message,
                    verboseMessage,
                    severity,
                    locations
                    );
            }
            catch (ArgumentException ex)
            {
                throw reader.CreateException(ex.Message);
            }
        }
        public void CppCheckStrings_PutsStringsInNameTable()
        {
            var nameTable = new NameTable();
            var uut = new CppCheckStrings(nameTable);
            Assert.AreSame(nameTable.Add("results"), uut.Results);

            Assert.AreSame(nameTable.Add("cppcheck"), uut.CppCheck);
            Assert.AreSame(nameTable.Add("version"), uut.Version);
            Assert.AreSame(nameTable.Add("errors"), uut.Errors);
            Assert.AreSame(nameTable.Add("error"), uut.Error);

            Assert.AreSame(nameTable.Add("id"), uut.Id);
            Assert.AreSame(nameTable.Add("msg"), uut.Msg);
            Assert.AreSame(nameTable.Add("verbose"), uut.Verbose);
            Assert.AreSame(nameTable.Add("severity"), uut.Severity);

            Assert.AreSame(nameTable.Add("location"), uut.Location);
            Assert.AreSame(nameTable.Add("file"), uut.File);
            Assert.AreSame(nameTable.Add("line"), uut.Line);
        }
示例#4
0
        public void CppCheckStrings_PutsStringsInNameTable()
        {
            var nameTable = new NameTable();
            var uut       = new CppCheckStrings(nameTable);

            Assert.AreSame(nameTable.Add("results"), uut.Results);

            Assert.AreSame(nameTable.Add("cppcheck"), uut.CppCheck);
            Assert.AreSame(nameTable.Add("version"), uut.Version);
            Assert.AreSame(nameTable.Add("errors"), uut.Errors);
            Assert.AreSame(nameTable.Add("error"), uut.Error);

            Assert.AreSame(nameTable.Add("id"), uut.Id);
            Assert.AreSame(nameTable.Add("msg"), uut.Msg);
            Assert.AreSame(nameTable.Add("verbose"), uut.Verbose);
            Assert.AreSame(nameTable.Add("severity"), uut.Severity);

            Assert.AreSame(nameTable.Add("location"), uut.Location);
            Assert.AreSame(nameTable.Add("file"), uut.File);
            Assert.AreSame(nameTable.Add("line"), uut.Line);
        }
示例#5
0
        /// <summary>
        /// Parses a "location" node from the supplied instance of <see cref="XmlReader"/>.
        /// </summary>
        /// <exception cref="XmlException">Thrown if <paramref name="reader"/> points to XML of an
        /// incorrect format.</exception>
        /// <param name="reader">The reader from which XML will be parsed. Upon entry to this method, this
        /// XML reader must be positioned on the location node to parse. Upon completion of this method,
        /// the reader will be positioned on the node following the location node.</param>
        /// <param name="strings">Strings used to parse the CppCheck log.</param>
        /// <returns>
        /// A <see cref="CppCheckLocation"/> instance containing data from the current node of
        /// <paramref name="reader"/>.
        /// </returns>
        public static CppCheckLocation Parse(XmlReader reader, CppCheckStrings strings)
        {
            if (!reader.IsStartElement(strings.Location))
            {
                throw reader.CreateException(ConverterResources.CppCheckLocationElementNameIncorrect);
            }

            string file     = null;
            string lineText = null;

            while (reader.MoveToNextAttribute())
            {
                string name = reader.LocalName;
                if (StringReference.AreEqual(name, strings.File))
                {
                    file = reader.Value;
                }
                else if (StringReference.AreEqual(name, strings.Line))
                {
                    lineText = reader.Value;
                }
            }

            if (file == null)
            {
                throw reader.CreateException(ConverterResources.CppCheckLocationMissingName);
            }

            if (lineText == null)
            {
                throw reader.CreateException(ConverterResources.CppCheckLocationMissingLine);
            }

            int line = XmlConvert.ToInt32(lineText);

            reader.MoveToElement();
            reader.Skip();

            return(new CppCheckLocation(file, line));
        }
示例#6
0
        private static ImmutableArray <CppCheckLocation> ParseLocationsSubtree(XmlReader reader, CppCheckStrings strings)
        {
            ImmutableArray <CppCheckLocation> .Builder locationBuilder = ImmutableArray.CreateBuilder <CppCheckLocation>();

            if (!reader.IsEmptyElement)
            {
                int startingDepth = reader.Depth;
                reader.Read();
                while (reader.Depth > startingDepth)
                {
                    Debug.Assert(reader.Depth == startingDepth + 1);
                    if (reader.NodeType == XmlNodeType.Whitespace)
                    {
                        reader.Read();
                    }
                    else
                    {
                        locationBuilder.Add(CppCheckLocation.Parse(reader, strings));
                    }
                }
            }

            ImmutableArray <CppCheckLocation> locations = locationBuilder.ToImmutable();

            return(locations);
        }
 /// <summary>Initializes a new instance of the <see cref="CppCheckConverter"/> class.</summary>
 public CppCheckConverter()
 {
     _nameTable = new NameTable();
     _strings   = new CppCheckStrings(_nameTable);
 }
示例#8
0
        private static ImmutableArray<CppCheckLocation> ParseLocationsSubtree(XmlReader reader, CppCheckStrings strings)
        {
            var locationBuilder = ImmutableArray.CreateBuilder<CppCheckLocation>();

            if (!reader.IsEmptyElement)
            {
                int startingDepth = reader.Depth;
                reader.Read();
                while (reader.Depth > startingDepth)
                {
                    Debug.Assert(reader.Depth == startingDepth + 1);
                    if (reader.NodeType == XmlNodeType.Whitespace)
                    {
                        reader.Read();
                    }
                    else
                    {
                        locationBuilder.Add(CppCheckLocation.Parse(reader, strings));
                    }
                }
            }

            ImmutableArray<CppCheckLocation> locations = locationBuilder.ToImmutable();
            return locations;
        }
示例#9
0
 /// <summary>Initializes a new instance of the <see cref="CppCheckConverter"/> class.</summary>
 public CppCheckConverter()
 {
     _nameTable = new NameTable();
     _strings = new CppCheckStrings(_nameTable);
 }
        private static ImmutableArray <CppCheckLocation> ParseLocationsSubtree(XmlReader reader, CppCheckStrings strings)
        {
            ImmutableArray <CppCheckLocation> .Builder locationBuilder = ImmutableArray.CreateBuilder <CppCheckLocation>();

            if (!reader.IsEmptyElement)
            {
                int startingDepth = reader.Depth;
                reader.Read();
                while (reader.Depth > startingDepth)
                {
                    if (reader.NodeType == XmlNodeType.Whitespace)
                    {
                        reader.Read();
                    }
                    else
                    {
                        if (!reader.LocalName.Equals("location", StringComparison.OrdinalIgnoreCase))
                        {
                            reader.Read();
                            continue;
                        }

                        locationBuilder.Add(CppCheckLocation.Parse(reader, strings));
                    }
                }
            }

            return(locationBuilder.ToImmutable());
        }