Skip to content

Commit

Permalink
reorganized code and clean up syntax tree
Browse files Browse the repository at this point in the history
  • Loading branch information
WalkerCodeRanger committed Aug 15, 2024
1 parent 05afdde commit 69d1c2f
Show file tree
Hide file tree
Showing 110 changed files with 367 additions and 374 deletions.
1 change: 1 addition & 0 deletions Compiler.API/AzothCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.CST;
using Azoth.Tools.Bootstrap.Compiler.Lexing;
using Azoth.Tools.Bootstrap.Compiler.Names;
Expand Down
4 changes: 2 additions & 2 deletions Compiler.CST/IPackageSyntax.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.Names;
using Azoth.Tools.Bootstrap.Framework;

Expand All @@ -11,5 +11,5 @@ public interface IPackageSyntax : ISyntax
IFixedSet<ICompilationUnitSyntax> TestingCompilationUnits { get; }
IFixedSet<IPackageReferenceSyntax> References { get; }

Diagnostics Diagnostics { get; }
DiagnosticsCollection Diagnostics { get; }
}
9 changes: 0 additions & 9 deletions Compiler.CST/ITypeSyntax.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Compiler.CST/PackageSyntax.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.Names;
using Azoth.Tools.Bootstrap.Framework;

Expand All @@ -20,7 +21,7 @@ public class PackageSyntax : IPackageSyntax
public IFixedSet<ICompilationUnitSyntax> CompilationUnits { get; }
public IFixedSet<ICompilationUnitSyntax> TestingCompilationUnits { get; }
public IFixedSet<IPackageReferenceSyntax> References { get; }
public Diagnostics Diagnostics { get; }
public DiagnosticsCollection Diagnostics { get; }

public PackageSyntax(
IdentifierName name,
Expand Down
4 changes: 2 additions & 2 deletions Compiler.CST/SyntaxTree.tree
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
◊suffix Syntax;
◊using System.Numerics;
◊using Azoth.Tools.Bootstrap.Compiler.Core;
◊using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
◊using Azoth.Tools.Bootstrap.Compiler.Core.Operators;
◊using Azoth.Tools.Bootstrap.Compiler.Names;
◊using Azoth.Tools.Bootstrap.Compiler.Tokens;
◊using Azoth.Tools.Bootstrap.Compiler.Types;
◊using Azoth.Tools.Bootstrap.Compiler.Types.Capabilities;
◊using Azoth.Tools.Bootstrap.Framework;

Expand All @@ -18,7 +18,7 @@
// `SpecialTypeNameExpression` should be the same type.

Code = Span:`TextSpan`;
CompilationUnit = File:`CodeFile` ImplicitNamespaceName:`NamespaceName` Diagnostics:`Diagnostics`
CompilationUnit = File:`CodeFile` ImplicitNamespaceName:`NamespaceName` Diagnostics:`DiagnosticsCollection`
UsingDirectives:UsingDirective* Definitions:NonMemberDefinition*;
UsingDirective = Name:`NamespaceName`;

Expand Down
4 changes: 2 additions & 2 deletions Compiler.CST/SyntaxTree.tree.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Numerics;
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.Core.Operators;
using Azoth.Tools.Bootstrap.Compiler.Names;
using Azoth.Tools.Bootstrap.Compiler.Tokens;
using Azoth.Tools.Bootstrap.Compiler.Types;
using Azoth.Tools.Bootstrap.Compiler.Types.Capabilities;
using Azoth.Tools.Bootstrap.Framework;
using ExhaustiveMatching;
Expand Down Expand Up @@ -40,7 +40,7 @@ public partial interface ICompilationUnitSyntax : ICodeSyntax
{
CodeFile File { get; }
NamespaceName ImplicitNamespaceName { get; }
Diagnostics Diagnostics { get; }
DiagnosticsCollection Diagnostics { get; }
IFixedList<IUsingDirectiveSyntax> UsingDirectives { get; }
IFixedList<INonMemberDefinitionSyntax> Definitions { get; }
}
Expand Down
1 change: 1 addition & 0 deletions Compiler.Core/CompilerResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Framework;

namespace Azoth.Tools.Bootstrap.Compiler.Core;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Azoth.Tools.Bootstrap.Framework;

namespace Azoth.Tools.Bootstrap.Compiler.Core;
namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

public class Diagnostic
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Azoth.Tools.Bootstrap.Compiler.Core;
namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

public enum DiagnosticLevel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Azoth.Tools.Bootstrap.Compiler.Core;
namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

public enum DiagnosticPhase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Diagnostics;
using Azoth.Tools.Bootstrap.Framework;

namespace Azoth.Tools.Bootstrap.Compiler.Core;
namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

// TODO rename to DiagnosticsBuilder (and maybe introduce an immutable diagnostics class)
[DebuggerDisplay("Count = {items.Count}")]
Expand All @@ -22,7 +22,7 @@ public void Add(Diagnostic diagnostic)
UpdateFatalErrorCount(diagnostic);
}

public void Add(Diagnostics diagnostics)
public void Add(DiagnosticsCollection diagnostics)
{
items.AddRange(diagnostics);
FatalErrorCount += diagnostics.FatalErrorCount;
Expand All @@ -37,7 +37,7 @@ private void UpdateFatalErrorCount(Diagnostic diagnostic)
FatalErrorCount++;
}

public Diagnostics Build() => new(this);
public DiagnosticsCollection Build() => new(this);

public IEnumerator<Diagnostic> GetEnumerator() => items.GetEnumerator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
using System.Collections.Generic;
using System.Linq;

namespace Azoth.Tools.Bootstrap.Compiler.Core;
namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

public sealed class Diagnostics : IReadOnlyList<Diagnostic>
public sealed class DiagnosticsCollection : IReadOnlyList<Diagnostic>
{
public static readonly Diagnostics Empty = new();
public static readonly DiagnosticsCollection Empty = new();

private readonly IReadOnlyList<Diagnostic> diagnostics;

public int Count => diagnostics.Count;
public int FatalErrorCount { get; }

public Diagnostics(DiagnosticsBuilder diagnostics)
public DiagnosticsCollection(DiagnosticsBuilder diagnostics)
{
FatalErrorCount = diagnostics.FatalErrorCount;
// Don't wrap in read only list, as this class is the wrapper
Expand All @@ -22,7 +22,7 @@ public Diagnostics(DiagnosticsBuilder diagnostics)
.ToList();
}

private Diagnostics()
private DiagnosticsCollection()
{
diagnostics = [];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Azoth.Tools.Bootstrap.Compiler.Core;
namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

public static class ErrorCodeRange
{
Expand Down
13 changes: 13 additions & 0 deletions Compiler.Core/Diagnostics/FatalCompilationErrorException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

public class FatalCompilationErrorException : Exception
{
public DiagnosticsCollection Diagnostics { get; }

public FatalCompilationErrorException(DiagnosticsCollection diagnostics)
{
Diagnostics = diagnostics;
}
}
13 changes: 0 additions & 13 deletions Compiler.Core/FatalCompilationErrorException.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ExhaustiveMatching;

namespace Azoth.Tools.Bootstrap.Compiler.Types;
namespace Azoth.Tools.Bootstrap.Compiler.Core;

public enum ParameterIndependence
{
Expand Down
2 changes: 2 additions & 0 deletions Compiler.Core/ParseContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

namespace Azoth.Tools.Bootstrap.Compiler.Core;

public class ParseContext
Expand Down
45 changes: 23 additions & 22 deletions Compiler.Lexing/LexError.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;

namespace Azoth.Tools.Bootstrap.Compiler.Lexing;

Expand All @@ -7,67 +8,67 @@ internal static class LexError
{
public static Diagnostic UnclosedBlockComment(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1001, "End-of-file found, expected `*/`");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1001, (string)"End-of-file found, expected `*/`");
}

public static Diagnostic UnclosedStringLiteral(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1002, "End-of-file in string constant");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1002, (string)"End-of-file in string constant");
}

public static Diagnostic InvalidEscapeSequence(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1003, "Unrecognized escape sequence");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1003, (string)"Unrecognized escape sequence");
}

public static Diagnostic CStyleNotEquals(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1004, "Use `≠` or `=/=` for not equal instead of `!=`");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1004, (string)"Use `≠` or `=/=` for not equal instead of `!=`");
}

public static Diagnostic UnexpectedCharacter(CodeFile file, TextSpan span, char character)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1005, $"Unexpected character `{character}`");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1005, (string)$"Unexpected character `{character}`");
}

public static Diagnostic ReservedWord(CodeFile file, TextSpan span, string word)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1006, $"Reserved word `{word}` used as an identifier");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1006, (string)$"Reserved word `{word}` used as an identifier");
}

public static Diagnostic ContinueInsteadOfNext(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1007, "The word `continue` is a reserved word. Use the `next` keyword or escape the identifier as `\\continue` instead");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1007, (string)"The word `continue` is a reserved word. Use the `next` keyword or escape the identifier as `\\continue` instead");
}

public static Diagnostic EscapedIdentifierShouldNotBeEscaped(CodeFile file, TextSpan span, string identifier)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1008, $"The word `{identifier}` is not a keyword or reserved word, it should not be escaped");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1008, (string)$"The word `{identifier}` is not a keyword or reserved word, it should not be escaped");
}

public static Diagnostic ReservedOperator(CodeFile file, TextSpan span, string op)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1009, $"Unexpected character(s) `{op}`, reserved for operator or punctuators");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1009, (string)$"Unexpected character(s) `{op}`, reserved for operator or punctuators");
}

public static Diagnostic UInt8InsteadOfByte(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1010, "The word `uint8` is a reserved word. Use the `byte` keyword instead");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1010, (string)"The word `uint8` is a reserved word. Use the `byte` keyword instead");
}

public static Diagnostic UnclosedStringIdentifier(CodeFile file, TextSpan span)
{
return new(file, span, DiagnosticLevel.CompilationError, DiagnosticPhase.Lexing,
1011, "End-of-file in string identifier");
return new(file, span, (DiagnosticLevel)DiagnosticLevel.CompilationError, (DiagnosticPhase)DiagnosticPhase.Lexing,
(int)1011, (string)"End-of-file in string identifier");
}
}
1 change: 1 addition & 0 deletions Compiler.Lexing/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.Tokens;

namespace Azoth.Tools.Bootstrap.Compiler.Lexing;
Expand Down
1 change: 1 addition & 0 deletions Compiler.Parsing/CompilationUnitParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.CST;
using Azoth.Tools.Bootstrap.Compiler.Lexing;
using Azoth.Tools.Bootstrap.Compiler.Names;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Azoth.Tools.Bootstrap.Compiler.Core;
using Azoth.Tools.Bootstrap.Compiler.Core.Diagnostics;
using Azoth.Tools.Bootstrap.Compiler.CST;
using Azoth.Tools.Bootstrap.Compiler.CST.Walkers;
using Azoth.Tools.Bootstrap.Compiler.Parsing.Tree;
Expand Down
Loading

0 comments on commit 69d1c2f

Please sign in to comment.