Skip to content

Commit

Permalink
feat: 支持 Dispose 接口。
Browse files Browse the repository at this point in the history
  • Loading branch information
CYJB committed Mar 14, 2024
1 parent c40f0d8 commit b35874a
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Compilers/Cyjb.Compilers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<NeutralLanguage>en</NeutralLanguage>
<Version>$(VersionPrefix)</Version>
<VersionPrefix>1.0.16</VersionPrefix>
<VersionPrefix>1.0.17</VersionPrefix>
<RootNamespace>Cyjb.Compilers</RootNamespace>
<Authors>CYJB</Authors>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
5 changes: 4 additions & 1 deletion Compilers/Parsers/Parser`2.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public partial class Parser<T, TController>
/// </summary>
private readonly List<LRState<T>> states = new();
/// <summary>
/// GOTO 表的个数。
/// </summary>
private int gotoCount = 0;
/// <summary>
/// 非终结符号的 FIRST 集。
/// </summary>
private readonly Dictionary<Symbol<T>, HashSet<Symbol<T>>> firstSet = new();
Expand Down Expand Up @@ -139,7 +143,6 @@ public ParserData<T> GetData()
}
// 提取产生式数据
List<ProductionData<T>> productionData = new();
int gotoCount = 0;
foreach (Production<T> production in productions)
{
// 只有产生式头才会有 goto 数据。
Expand Down
2 changes: 1 addition & 1 deletion Design/Cyjb.Compilers.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<NeutralLanguage>en</NeutralLanguage>
<Version>$(VersionPrefix)</Version>
<VersionPrefix>1.0.16</VersionPrefix>
<VersionPrefix>1.0.17</VersionPrefix>
<RootNamespace>Cyjb.Compilers</RootNamespace>
<OutputType>Library</OutputType>
<DevelopmentDependency>true</DevelopmentDependency>
Expand Down
Binary file modified Design/Tools/Cyjb.Compilers.Design.dll
Binary file not shown.
Binary file modified Design/Tools/Cyjb.Compilers.Runtime.dll
Binary file not shown.
Binary file modified Design/Tools/Cyjb.Compilers.dll
Binary file not shown.
20 changes: 10 additions & 10 deletions Design/Tools/Generator.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"Generator/1.0.0": {
"dependencies": {
"Cyjb": "1.0.22",
"Cyjb.Compilers": "1.0.16",
"Cyjb.Compilers.Design": "1.0.16",
"Cyjb.Compilers": "1.0.17",
"Cyjb.Compilers.Design": "1.0.17",
"Microsoft.CodeAnalysis.CSharp": "4.8.0"
},
"runtime": {
Expand Down Expand Up @@ -166,10 +166,10 @@
}
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {},
"Cyjb.Compilers/1.0.16": {
"Cyjb.Compilers/1.0.17": {
"dependencies": {
"Cyjb": "1.0.22",
"Cyjb.Compilers.Runtime": "1.0.16"
"Cyjb.Compilers.Runtime": "1.0.17"
},
"runtime": {
"Cyjb.Compilers.dll": {}
Expand All @@ -180,15 +180,15 @@
}
}
},
"Cyjb.Compilers.Design/1.0.16": {
"Cyjb.Compilers.Design/1.0.17": {
"dependencies": {
"Cyjb.Compilers.Runtime": "1.0.16"
"Cyjb.Compilers.Runtime": "1.0.17"
},
"runtime": {
"Cyjb.Compilers.Design.dll": {}
}
},
"Cyjb.Compilers.Runtime/1.0.16": {
"Cyjb.Compilers.Runtime/1.0.17": {
"dependencies": {
"Cyjb": "1.0.22"
},
Expand Down Expand Up @@ -258,17 +258,17 @@
"path": "system.runtime.compilerservices.unsafe/6.0.0",
"hashPath": "system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512"
},
"Cyjb.Compilers/1.0.16": {
"Cyjb.Compilers/1.0.17": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Cyjb.Compilers.Design/1.0.16": {
"Cyjb.Compilers.Design/1.0.17": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Cyjb.Compilers.Runtime/1.0.16": {
"Cyjb.Compilers.Runtime/1.0.17": {
"type": "project",
"serviceable": false,
"sha512": ""
Expand Down
Binary file modified Design/Tools/Generator.dll
Binary file not shown.
Binary file modified Design/Tools/zh-Hans/Cyjb.Compilers.Runtime.resources.dll
Binary file not shown.
Binary file modified Design/Tools/zh-Hans/Cyjb.Compilers.resources.dll
Binary file not shown.
Binary file modified Design/Tools/zh-Hans/Generator.resources.dll
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Runtime/Cyjb.Compilers.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<NeutralLanguage>en</NeutralLanguage>
<Version>$(VersionPrefix)</Version>
<VersionPrefix>1.0.16</VersionPrefix>
<VersionPrefix>1.0.17</VersionPrefix>
<RootNamespace>Cyjb.Compilers</RootNamespace>
<Authors>CYJB</Authors>
<PackageTags>Compiler</PackageTags>
Expand Down
28 changes: 27 additions & 1 deletion Runtime/Lexers/LexerController`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Cyjb.Compilers.Lexers;
/// 表示词法分析器的控制器。
/// </summary>
/// <typeparam name="T">词法单元标识符的类型,一般是一个枚举类型。</typeparam>
public class LexerController<T>
public class LexerController<T> : IDisposable
where T : struct
{
/// <summary>
Expand Down Expand Up @@ -303,6 +303,32 @@ public void More()
IsMore = true;
}

#region IDisposable 成员

/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// <overloads>
/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// </overloads>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// <param name="disposing">是否释放托管资源。</param>
protected virtual void Dispose(bool disposing)
{
}

#endregion // IDisposable 成员

#region 上下文切换

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Runtime/Lexers/TokenizerBase`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
source.Dispose();
controller.Dispose();
}
}

Expand Down
20 changes: 20 additions & 0 deletions Runtime/Parsers/LRParser`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,24 @@ private void CancelStates()
Reduce(production, start);
}
}

#region IDisposable 成员

/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// <overloads>
/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// </overloads>
public void Dispose()
{
tokenizer.Dispose();
controller.Dispose();
GC.SuppressFinalize(this);
}

#endregion // IDisposable 成员

}
28 changes: 27 additions & 1 deletion Runtime/Parsers/ParserController`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Cyjb.Compilers.Parsers;
/// 表示语法分析器的控制器。
/// </summary>
/// <typeparam name="T">语法节点标识符的类型,必须是一个枚举类型。</typeparam>
public class ParserController<T> : ReadOnlyListBase<ParserNode<T>>
public class ParserController<T> : ReadOnlyListBase<ParserNode<T>>, IDisposable
where T : struct
{
/// <summary>
Expand Down Expand Up @@ -474,4 +474,30 @@ public override IEnumerator<ParserNode<T>> GetEnumerator()

#endregion // ReadOnlyListBase<Token<T>> 成员

#region IDisposable 成员

/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// <overloads>
/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// </overloads>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// 执行与释放或重置非托管资源相关的应用程序定义的任务。
/// </summary>
/// <param name="disposing">是否释放托管资源。</param>
protected virtual void Dispose(bool disposing)
{
}

#endregion // IDisposable 成员

}
2 changes: 1 addition & 1 deletion Runtime/Text/ITokenParser`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public delegate void TokenParseErrorHandler<T>(ITokenParser<T> parser, TokenPars
/// 表示语法分析器。
/// </summary>
/// <typeparam name="T">词法单元标识符的类型,一般是一个枚举类型。</typeparam>
public interface ITokenParser<T>
public interface ITokenParser<T> : IDisposable
where T : struct
{
/// <summary>
Expand Down

0 comments on commit b35874a

Please sign in to comment.