-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Parsing and SemanticCheck Stage
- Loading branch information
Showing
118 changed files
with
128 additions
and
5,601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...Backlang.Contracts/LNodeDeconstructors.cs → ...rce/BacklangC/Core/LNodeDeconstructors.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
...acklang.Contracts/Semantic/ImportCheck.cs → .../BacklangC/Semantic/Checks/ImportCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
....Contracts/Semantic/InterfaceNameCheck.cs → ...ngC/Semantic/Checks/InterfaceNameCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
...ntracts/Semantic/ModuleDefinitionCheck.cs → .../Semantic/Checks/ModuleDefinitionCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
...klang.Contracts/Semantic/TypenameCheck.cs → ...acklangC/Semantic/Checks/TypenameCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Backlang.Codeanalysis.Parsing.AST; | ||
|
||
namespace BacklangC.Semantic; | ||
|
||
public interface ISemanticCheck | ||
{ | ||
void Check(CompilationUnit tree, Driver context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Backlang.Codeanalysis.Parsing.AST; | ||
using BacklangC.Semantic.Checks; | ||
|
||
namespace BacklangC.Semantic; | ||
|
||
public static class SemanticChecker | ||
{ | ||
private static readonly List<ISemanticCheck> SemanticChecks = | ||
[ | ||
new ModuleDefinitionCheck(), | ||
new ImportCheck(), | ||
new TypenameCheck(), | ||
new ModifierCheck(), | ||
new InterfaceNameCheck() | ||
]; | ||
|
||
public static void Do(CompilationUnit tree, Driver context) | ||
{ | ||
foreach (var check in SemanticChecks) | ||
{ | ||
check.Check(tree, context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Backlang.Codeanalysis.Parsing; | ||
using Backlang.Codeanalysis.Parsing.AST; | ||
using Flo; | ||
using Loyc.Syntax; | ||
|
||
namespace BacklangC.Stages; | ||
|
||
public sealed class ParsingStage : IHandler<Driver, Driver> | ||
{ | ||
public async Task<Driver> HandleAsync(Driver context, | ||
Func<Driver, Task<Driver>> next) | ||
{ | ||
ParseSourceFiles(context); | ||
|
||
return await next.Invoke(context); | ||
} | ||
|
||
private static void ParseSourceFiles(Driver context) | ||
{ | ||
Parallel.ForEachAsync(context.Settings.Sources, (filename, ct) => { | ||
if (File.Exists(filename)) | ||
{ | ||
var tree = CompilationUnit.FromFile(filename); | ||
|
||
ApplyTree(context, tree); | ||
} | ||
else | ||
{ | ||
context.Messages.Add(Message.Error($"File '{filename}' does not exists", SourceRange.Synthetic)); | ||
} | ||
|
||
return ValueTask.CompletedTask; | ||
}).Wait(); | ||
} | ||
|
||
private static void ApplyTree(Driver context, CompilationUnit tree) | ||
{ | ||
context.Trees.Add(tree); | ||
|
||
context.Messages.AddRange(tree.Messages); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using BacklangC.Semantic; | ||
using Flo; | ||
|
||
namespace BacklangC.Stages; | ||
|
||
public sealed class SemanticCheckStage : IHandler<Driver, Driver> | ||
{ | ||
public async Task<Driver> HandleAsync(Driver context, Func<Driver, Task<Driver>> next) | ||
{ | ||
Parallel.ForEachAsync(context.Trees, (tree, ct) => { | ||
SemanticChecker.Do(tree, context); | ||
|
||
return ValueTask.CompletedTask; | ||
}).Wait(); | ||
|
||
return await next.Invoke(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
func main() { | ||
|
||
} |
File renamed without changes
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
Source/Backlang.Codeanalysis/Core/Attributes/BinaryOperatorInfoAttribute.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
Source/Backlang.Codeanalysis/Core/Attributes/KeywordAttribute.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
Source/Backlang.Codeanalysis/Core/Attributes/LexemeAttribute.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
Source/Backlang.Codeanalysis/Core/Attributes/OperatorInfoAttribute.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
Source/Backlang.Codeanalysis/Core/Attributes/PostUnaryOperatorInfoAttribute.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
Source/Backlang.Codeanalysis/Core/Attributes/PreUnaryOperatorInfoAttribute.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.