Browse Source

HACK: avoid crash in multiline comments where the parser returns incorrect comment.Content

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
ecf6c67f8f
  1. 13
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  2. 17
      src/Main/Core/Project/Src/Services/StringParser/StringParser.cs
  3. 24
      src/Main/SharpDevelop/Parser/ParserServiceEntry.cs

13
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -98,16 +98,21 @@ namespace CSharpBinding.Parser @@ -98,16 +98,21 @@ namespace CSharpBinding.Parser
if (index > -1) {
if (document == null)
document = new ReadOnlyDocument(fileContent);
int startOffset = document.GetOffset(comment.StartLocation);
int commentSignLength = comment.CommentType == CommentType.Documentation || comment.CommentType == CommentType.MultiLineDocumentation ? 3 : 2;
int commentEndSignLength = comment.CommentType == CommentType.MultiLine || comment.CommentType == CommentType.MultiLineDocumentation ? 2 : 0;
int commentStartOffset = document.GetOffset(comment.StartLocation) + commentSignLength;
int commentEndOffset = document.GetOffset(comment.EndLocation) - commentEndSignLength;
do {
int absoluteOffset = startOffset + index + commentSignLength;
int absoluteOffset = commentStartOffset + index;
var startLocation = document.GetLocation(absoluteOffset);
int endOffset = Math.Min(document.GetLineByNumber(startLocation.Line).EndOffset, document.GetOffset(comment.EndLocation) - commentEndSignLength);
int endOffset = Math.Min(document.GetLineByNumber(startLocation.Line).EndOffset, commentEndOffset);
string content = document.GetText(absoluteOffset, endOffset - absoluteOffset);
if (content.Length < matchLength) {
// HACK: workaround parser bug with multi-line documentation comments
break;
}
tagComments.Add(new TagComment(content.Substring(0, matchLength), new DomRegion(cu.FileName, startLocation.Line, startLocation.Column), content.Substring(matchLength)));
index = comment.Content.IndexOfAny(TaskListTokens, endOffset - startOffset - commentSignLength, out matchLength);
index = comment.Content.IndexOfAny(TaskListTokens, endOffset - commentStartOffset, out matchLength);
} while (index > -1);
}
}

17
src/Main/Core/Project/Src/Services/StringParser/StringParser.cs

@ -118,23 +118,6 @@ namespace ICSharpCode.Core @@ -118,23 +118,6 @@ namespace ICSharpCode.Core
return output.ToString();
}
/// <summary>
/// For new code, please use the overload taking StringTagPair[]!
/// </summary>
[Obsolete("Please use the overload taking StringTagPair[]!")]
public static string Parse(string input, string[,] customTags)
{
if (customTags == null)
return Parse(input);
if (customTags.GetLength(1) != 2)
throw new ArgumentException("incorrect dimension");
StringTagPair[] pairs = new StringTagPair[customTags.GetLength(0)];
for (int i = 0; i < pairs.Length; i++) {
pairs[i] = new StringTagPair(customTags[i, 0], customTags[i, 1]);
}
return Parse(input, pairs);
}
/// <summary>
/// Evaluates a property using the StringParser. Equivalent to StringParser.Parse("${" + propertyName + "}");
/// </summary>

24
src/Main/SharpDevelop/Parser/ParserServiceEntry.cs

@ -195,7 +195,7 @@ namespace ICSharpCode.SharpDevelop.Parser @@ -195,7 +195,7 @@ namespace ICSharpCode.SharpDevelop.Parser
if (versionComparison > 0 || index < 0) {
// We're going backwards in time, or are requesting a project that is not an owner
// for this entry.
var parseInfo = parser.Parse(fileName, fileContent, fullParseInformationRequested, parentProject, cancellationToken);
var parseInfo = ParseWithExceptionHandling(fileContent, fullParseInformationRequested, parentProject, cancellationToken);
FreezableHelper.Freeze(parseInfo.ParsedFile);
return new ProjectEntry(parentProject, parseInfo.ParsedFile, parseInfo);
} else {
@ -210,13 +210,7 @@ namespace ICSharpCode.SharpDevelop.Parser @@ -210,13 +210,7 @@ namespace ICSharpCode.SharpDevelop.Parser
ParseInformationEventArgs[] results = new ParseInformationEventArgs[entries.Count];
for (int i = 0; i < entries.Count; i++) {
ParseInformation parseInfo;
try {
parseInfo = parser.Parse(fileName, fileContent, fullParseInformationRequested, entries[i].Project, cancellationToken);
} catch (Exception ex) {
SD.LoggingService.Error("Got " + ex.GetType().Name + " while parsing " + fileName);
throw;
}
var parseInfo = ParseWithExceptionHandling(fileContent, fullParseInformationRequested, entries[i].Project, cancellationToken);
if (parseInfo == null)
throw new NullReferenceException(parser.GetType().Name + ".Parse() returned null");
if (fullParseInformationRequested && !parseInfo.IsFullParseInformation)
@ -244,6 +238,20 @@ namespace ICSharpCode.SharpDevelop.Parser @@ -244,6 +238,20 @@ namespace ICSharpCode.SharpDevelop.Parser
parserService.RegisterForCacheExpiry(this);
return result;
}
ParseInformation ParseWithExceptionHandling(ITextSource fileContent, bool fullParseInformationRequested, IProject project, CancellationToken cancellationToken)
{
#if DEBUG
if (Debugger.IsAttached)
return parser.Parse(fileName, fileContent, fullParseInformationRequested, project, cancellationToken);
#endif
try {
return parser.Parse(fileName, fileContent, fullParseInformationRequested, project, cancellationToken);
} catch (Exception ex) {
SD.LoggingService.Error("Got " + ex.GetType().Name + " while parsing " + fileName);
throw;
}
}
#endregion
#region ParseAsync

Loading…
Cancel
Save