예제 #1
0
 public CppDiagnosticMessage(CppLogMessageType type, string text, CppSourceLocation location)
 {
     if (text == null)
     {
         throw new ArgumentNullException(nameof(text));
     }
     Type     = type;
     Text     = text;
     Location = location;
 }
예제 #2
0
파일: CppParser.cs 프로젝트: xen2/CppAst
        private static string GetMessageAndLocation(string rootContent, CXDiagnostic diagnostic, out CppSourceLocation location)
        {
            var builder = new StringBuilder();

            builder.Append(diagnostic.ToString());
            location = CppModelBuilder.GetSourceLocation(diagnostic.Location);
            if (location.File == CppAstRootFileName)
            {
                var    reader = new StringReader(rootContent);
                var    lines  = new List <string>();
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                }

                var lineIndex = location.Line - 1;
                if (lineIndex < lines.Count)
                {
                    builder.AppendLine();
                    builder.AppendLine(lines[lineIndex]);
                    for (int i = 0; i < location.Column - 1; i++)
                    {
                        builder.Append(i + 1 == location.Column - 1 ? "-" : " ");
                    }

                    builder.AppendLine("^-");
                }
            }

            return(builder.ToString());
        }