mirror of https://github.com/icsharpcode/ILSpy.git
578 changed files with 53286 additions and 10772 deletions
@ -1,2 +1,5 @@
@@ -1,2 +1,5 @@
|
||||
bin |
||||
obj |
||||
/lib/*.dll |
||||
/ICSharpCode.NRefactory.Tests/PartCover/* |
||||
/ICSharpCode.NRefactory.Tests/PartCover/* |
||||
_ReSharper*/* |
||||
|
@ -1,3 +0,0 @@
@@ -1,3 +0,0 @@
|
||||
|
||||
bin/ |
||||
obj/ |
@ -1,49 +1,69 @@
@@ -1,49 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>10.0.0</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{961DADFA-7CE6-429F-BC22-47630D6DB826}</ProjectGuid> |
||||
<OutputType>Exe</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.CSharp.AstVerifier</RootNamespace> |
||||
<AssemblyName>AstVerifier</AssemblyName> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Debug</OutputPath> |
||||
<DefineConstants>DEBUG;</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<Externalconsole>true</Externalconsole> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>none</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Release</OutputPath> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<Externalconsole>true</Externalconsole> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Main.cs" /> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj"> |
||||
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project> |
||||
<Name>ICSharpCode.NRefactory.CSharp</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>10.0.0</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{961DADFA-7CE6-429F-BC22-47630D6DB826}</ProjectGuid> |
||||
<OutputType>Exe</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.CSharp.AstVerifier</RootNamespace> |
||||
<AssemblyName>AstVerifier</AssemblyName> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Debug</OutputPath> |
||||
<DefineConstants>DEBUG;</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<Externalconsole>true</Externalconsole> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>none</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Release</OutputPath> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<Externalconsole>true</Externalconsole> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Debug</OutputPath> |
||||
<DefineConstants>DEBUG;</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<Externalconsole>true</Externalconsole> |
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Release|AnyCPU' "> |
||||
<DebugType>none</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Release</OutputPath> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
<Externalconsole>true</Externalconsole> |
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Main.cs" /> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj"> |
||||
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project> |
||||
<Name>ICSharpCode.NRefactory.CSharp</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
</Project> |
@ -1,3 +0,0 @@
@@ -1,3 +0,0 @@
|
||||
|
||||
bin/ |
||||
obj/ |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,213 @@
@@ -0,0 +1,213 @@
|
||||
//
|
||||
// IMemberProvider.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Completion |
||||
{ |
||||
public interface ICompletionContextProvider |
||||
{ |
||||
IList<string> ConditionalSymbols { |
||||
get; |
||||
} |
||||
|
||||
void GetCurrentMembers (int offset, out IUnresolvedTypeDefinition currentType, out IUnresolvedMember currentMember); |
||||
|
||||
Tuple<string, TextLocation> GetMemberTextToCaret(int caretOffset, IUnresolvedTypeDefinition currentType, IUnresolvedMember currentMember); |
||||
|
||||
CSharpAstResolver GetResolver (CSharpResolver resolver, AstNode rootNode); |
||||
} |
||||
|
||||
public class DefaultCompletionContextProvider : ICompletionContextProvider |
||||
{ |
||||
readonly IDocument document; |
||||
readonly CSharpUnresolvedFile unresolvedFile; |
||||
readonly List<string> symbols = new List<string> (); |
||||
|
||||
public IList<string> ConditionalSymbols { |
||||
get { |
||||
return symbols; |
||||
} |
||||
} |
||||
|
||||
public DefaultCompletionContextProvider (IDocument document, CSharpUnresolvedFile unresolvedFile) |
||||
{ |
||||
if (document == null) |
||||
throw new ArgumentNullException("document"); |
||||
if (unresolvedFile == null) |
||||
throw new ArgumentNullException("unresolvedFile"); |
||||
this.document = document; |
||||
this.unresolvedFile = unresolvedFile; |
||||
} |
||||
|
||||
public void AddSymbol (string sym) |
||||
{ |
||||
symbols.Add (sym); |
||||
} |
||||
public void GetCurrentMembers(int offset, out IUnresolvedTypeDefinition currentType, out IUnresolvedMember currentMember) |
||||
{ |
||||
//var document = engine.document;
|
||||
var location = document.GetLocation(offset); |
||||
|
||||
currentType = null; |
||||
|
||||
foreach (var type in unresolvedFile.TopLevelTypeDefinitions) { |
||||
if (type.Region.Begin < location) |
||||
currentType = type; |
||||
} |
||||
currentType = FindInnerType (currentType, location); |
||||
|
||||
// location is beyond last reported end region, now we need to check, if the end region changed
|
||||
if (currentType != null && currentType.Region.End < location) { |
||||
if (!IsInsideType (currentType, location)) |
||||
currentType = null; |
||||
} |
||||
currentMember = null; |
||||
if (currentType != null) { |
||||
foreach (var member in currentType.Members) { |
||||
if (member.Region.Begin < location && (currentMember == null || currentMember.Region.Begin < member.Region.Begin)) |
||||
currentMember = member; |
||||
} |
||||
} |
||||
|
||||
// location is beyond last reported end region, now we need to check, if the end region changed
|
||||
// NOTE: Enums are a special case, there the "last" field needs to be treated as current member
|
||||
if (currentMember != null && currentMember.Region.End < location && currentType.Kind != TypeKind.Enum) { |
||||
if (!IsInsideType (currentMember, location)) |
||||
currentMember = null; |
||||
}/* |
||||
var stack = GetBracketStack (engine.GetMemberTextToCaret ().Item1); |
||||
if (stack.Count == 0) |
||||
currentMember = null;*/ |
||||
} |
||||
|
||||
IUnresolvedTypeDefinition FindInnerType (IUnresolvedTypeDefinition parent, TextLocation location) |
||||
{ |
||||
if (parent == null) |
||||
return null; |
||||
var currentType = parent; |
||||
foreach (var type in parent.NestedTypes) { |
||||
if (type.Region.Begin < location && location < type.Region.End) |
||||
currentType = FindInnerType (type, location); |
||||
} |
||||
|
||||
return currentType; |
||||
} |
||||
|
||||
bool IsInsideType (IUnresolvedEntity currentType, TextLocation location) |
||||
{ |
||||
int startOffset = document.GetOffset (currentType.Region.Begin); |
||||
int endOffset = document.GetOffset (location); |
||||
//bool foundEndBracket = false;
|
||||
|
||||
var bracketStack = new Stack<char> (); |
||||
|
||||
bool isInString = false, isInChar = false; |
||||
bool isInLineComment = false, isInBlockComment = false; |
||||
|
||||
for (int i = startOffset; i < endOffset; i++) { |
||||
char ch = document.GetCharAt (i); |
||||
switch (ch) { |
||||
case '(': |
||||
case '[': |
||||
case '{': |
||||
if (!isInString && !isInChar && !isInLineComment && !isInBlockComment) |
||||
bracketStack.Push (ch); |
||||
break; |
||||
case ')': |
||||
case ']': |
||||
case '}': |
||||
if (!isInString && !isInChar && !isInLineComment && !isInBlockComment) |
||||
if (bracketStack.Count > 0) |
||||
bracketStack.Pop (); |
||||
break; |
||||
case '\r': |
||||
case '\n': |
||||
isInLineComment = false; |
||||
break; |
||||
case '/': |
||||
if (isInBlockComment) { |
||||
if (i > 0 && document.GetCharAt (i - 1) == '*') |
||||
isInBlockComment = false; |
||||
} else if (!isInString && !isInChar && i + 1 < document.TextLength) { |
||||
char nextChar = document.GetCharAt (i + 1); |
||||
if (nextChar == '/') |
||||
isInLineComment = true; |
||||
if (!isInLineComment && nextChar == '*') |
||||
isInBlockComment = true; |
||||
} |
||||
break; |
||||
case '"': |
||||
if (!(isInChar || isInLineComment || isInBlockComment)) |
||||
isInString = !isInString; |
||||
break; |
||||
case '\'': |
||||
if (!(isInString || isInLineComment || isInBlockComment)) |
||||
isInChar = !isInChar; |
||||
break; |
||||
default : |
||||
break; |
||||
} |
||||
} |
||||
return bracketStack.Any (t => t == '{'); |
||||
} |
||||
|
||||
public Tuple<string, TextLocation> GetMemberTextToCaret(int caretOffset, IUnresolvedTypeDefinition currentType, IUnresolvedMember currentMember) |
||||
{ |
||||
int startOffset; |
||||
if (currentMember != null && currentType != null && currentType.Kind != TypeKind.Enum) { |
||||
startOffset = document.GetOffset(currentMember.Region.Begin); |
||||
} else if (currentType != null) { |
||||
startOffset = document.GetOffset(currentType.Region.Begin); |
||||
} else { |
||||
startOffset = 0; |
||||
} |
||||
while (startOffset > 0) { |
||||
char ch = document.GetCharAt(startOffset - 1); |
||||
if (ch != ' ' && ch != '\t') { |
||||
break; |
||||
} |
||||
--startOffset; |
||||
} |
||||
|
||||
return Tuple.Create (document.GetText (startOffset, caretOffset - startOffset), document.GetLocation (startOffset)); |
||||
} |
||||
|
||||
|
||||
public CSharpAstResolver GetResolver (CSharpResolver resolver, AstNode rootNode) |
||||
{ |
||||
return new CSharpAstResolver (resolver, rootNode, unresolvedFile); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// C# compiler settings.
|
||||
/// </summary>
|
||||
[Serializable] |
||||
public class CompilerSettings : AbstractFreezable |
||||
{ |
||||
protected override void FreezeInternal() |
||||
{ |
||||
conditionalSymbols = FreezableHelper.FreezeList(conditionalSymbols); |
||||
specificWarningsAsErrors = FreezableHelper.FreezeList(specificWarningsAsErrors); |
||||
disabledWarnings = FreezableHelper.FreezeList(disabledWarnings); |
||||
base.FreezeInternal(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new CompilerSettings instance.
|
||||
/// </summary>
|
||||
public CompilerSettings() |
||||
{ |
||||
} |
||||
|
||||
bool allowUnsafeBlocks = true; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether <c>unsafe</c> code is allowed.
|
||||
/// The default is <c>true</c>. If set to false, parsing unsafe code will result in parser errors.
|
||||
/// </summary>
|
||||
public bool AllowUnsafeBlocks { |
||||
get { return allowUnsafeBlocks; } |
||||
set { |
||||
FreezableHelper.ThrowIfFrozen(this); |
||||
allowUnsafeBlocks = value; |
||||
} |
||||
} |
||||
|
||||
bool checkForOverflow; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether overflow checking is enabled.
|
||||
/// The default is <c>false</c>. This setting effects semantic analysis.
|
||||
/// </summary>
|
||||
public bool CheckForOverflow { |
||||
get { return checkForOverflow; } |
||||
set { checkForOverflow = value; } |
||||
} |
||||
|
||||
Version languageVersion = new Version((int)Mono.CSharp.LanguageVersion.Default, 0); |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the language version used by the parser.
|
||||
/// Using language constructs newer than the supplied version will result in parser errors.
|
||||
/// </summary>
|
||||
public Version LanguageVersion { |
||||
get { return languageVersion; } |
||||
set { |
||||
FreezableHelper.ThrowIfFrozen(this); |
||||
if (value == null) |
||||
throw new ArgumentNullException(); |
||||
languageVersion = value; |
||||
} |
||||
} |
||||
|
||||
IList<string> conditionalSymbols = new List<string>(); |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the list of conditional symbols that are defined project-wide.
|
||||
/// </summary>
|
||||
public IList<string> ConditionalSymbols { |
||||
get { return conditionalSymbols; } |
||||
} |
||||
|
||||
bool treatWarningsAsErrors; |
||||
|
||||
public bool TreatWarningsAsErrors { |
||||
get { return treatWarningsAsErrors; } |
||||
set { |
||||
FreezableHelper.ThrowIfFrozen(this); |
||||
treatWarningsAsErrors = value; |
||||
} |
||||
} |
||||
|
||||
IList<int> specificWarningsAsErrors = new List<int>(); |
||||
|
||||
/// <summary>
|
||||
/// Allows treating specific warnings as errors without setting <see cref="TreatWarningsAsErrors"/> to true.
|
||||
/// </summary>
|
||||
public IList<int> SpecificWarningsAsErrors { |
||||
get { return specificWarningsAsErrors; } |
||||
} |
||||
|
||||
int warningLevel = 4; |
||||
|
||||
public int WarningLevel { |
||||
get { return warningLevel; } |
||||
set { |
||||
FreezableHelper.ThrowIfFrozen(this); |
||||
warningLevel = value; |
||||
} |
||||
} |
||||
|
||||
IList<int> disabledWarnings = new List<int>(); |
||||
|
||||
/// <summary>
|
||||
/// Allows treating specific warnings as errors without setting <see cref="TreatWarningsAsErrors"/> to true.
|
||||
/// </summary>
|
||||
public IList<int> DisabledWarnings { |
||||
get { return disabledWarnings; } |
||||
} |
||||
|
||||
internal Mono.CSharp.CompilerSettings ToMono() |
||||
{ |
||||
var s = new Mono.CSharp.CompilerSettings(); |
||||
s.Unsafe = allowUnsafeBlocks; |
||||
s.Checked = checkForOverflow; |
||||
s.Version = (Mono.CSharp.LanguageVersion)languageVersion.Major; |
||||
s.WarningsAreErrors = treatWarningsAsErrors; |
||||
s.WarningLevel = warningLevel; |
||||
foreach (int code in disabledWarnings) |
||||
s.SetIgnoreWarning(code); |
||||
foreach (int code in specificWarningsAsErrors) |
||||
s.AddWarningAsError(code); |
||||
foreach (string sym in conditionalSymbols) |
||||
s.AddConditionalSymbol(sym); |
||||
return s; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// SeekableStreamReader.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace Mono.CSharp |
||||
{ |
||||
public class SeekableStreamReader : IDisposable |
||||
{ |
||||
public const int DefaultReadAheadSize = 2048; |
||||
|
||||
readonly ITextSource textSource; |
||||
|
||||
int pos; |
||||
|
||||
static string GetAllText(Stream stream, Encoding encoding) { |
||||
using (var rdr = new StreamReader(stream, encoding)) { |
||||
return rdr.ReadToEnd(); |
||||
} |
||||
} |
||||
|
||||
public SeekableStreamReader (Stream stream, Encoding encoding, char[] sharedBuffer = null) : this(new StringTextSource(GetAllText(stream, encoding))) |
||||
{ |
||||
} |
||||
|
||||
public SeekableStreamReader (ITextSource source) |
||||
{ |
||||
this.textSource = source; |
||||
} |
||||
|
||||
|
||||
public void Dispose () |
||||
{ |
||||
} |
||||
|
||||
/// <remarks>
|
||||
/// This value corresponds to the current position in a stream of characters.
|
||||
/// The StreamReader hides its manipulation of the underlying byte stream and all
|
||||
/// character set/decoding issues. Thus, we cannot use this position to guess at
|
||||
/// the corresponding position in the underlying byte stream even though there is
|
||||
/// a correlation between them.
|
||||
/// </remarks>
|
||||
public int Position { |
||||
get { |
||||
return pos; |
||||
} |
||||
|
||||
set { |
||||
pos = value; |
||||
} |
||||
} |
||||
|
||||
public char GetChar (int position) |
||||
{ |
||||
return textSource.GetCharAt (position); |
||||
} |
||||
|
||||
public char[] ReadChars (int fromPosition, int toPosition) |
||||
{ |
||||
return textSource.GetText (fromPosition, toPosition - fromPosition).ToCharArray (); |
||||
} |
||||
|
||||
public int Peek () |
||||
{ |
||||
if (pos >= textSource.TextLength) |
||||
return -1; |
||||
return textSource.GetCharAt (pos); |
||||
} |
||||
|
||||
public int Read () |
||||
{ |
||||
if (pos >= textSource.TextLength) |
||||
return -1; |
||||
return textSource.GetCharAt (pos++); |
||||
} |
||||
} |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue