-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
858184b
commit 857a397
Showing
41 changed files
with
411 additions
and
194 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
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,60 @@ | ||
#include "Compilation.h" | ||
|
||
#include <memory> | ||
|
||
#include <fast_io.h> | ||
#include <ranges> | ||
|
||
#include "MambaCore.h" | ||
#include "Parser.h" | ||
#include "SourceText.h" | ||
#include "SyntaxTree.h" | ||
|
||
namespace Mamba | ||
{ | ||
std::vector<std::shared_ptr<const SourceText>> TransformToSource(const std::vector<StringView>& Sources) noexcept | ||
{ | ||
auto SourceTexts = std::vector<std::shared_ptr<const SourceText>>(); | ||
SourceTexts.reserve(Sources.size()); | ||
for (auto&& Source : Sources) | ||
{ | ||
const auto SharedSource = std::make_shared<String>(Source); | ||
SourceTexts.emplace_back(std::make_shared<SourceText>(SharedSource)); | ||
} | ||
return SourceTexts; | ||
} | ||
|
||
void Compilation::Compile(const std::shared_ptr<class SyntaxTree> SyntaxTree) noexcept | ||
{ | ||
auto Parser = ::Mamba::Parser(SyntaxTree); | ||
SyntaxTree->PrivateRoot = Parser.ParseCompilationUnit(); | ||
SyntaxTree->PrivateDiagnostics = std::move(Parser.Diagnostics); | ||
} | ||
|
||
void Compilation::Compile() noexcept | ||
{ | ||
for (auto&& SyntaxTree : SyntaxTrees) | ||
{ | ||
Compilation::Compile(SyntaxTree); | ||
} | ||
} | ||
|
||
std::vector<std::shared_ptr<const class Diagnostic>> Compilation::Diagnostics() const noexcept | ||
{ | ||
return SyntaxTrees | std::views::transform([](auto&& SyntaxTree) { return SyntaxTree->PrivateDiagnostics; }) | ||
| std::views::join | std::ranges::to<std::vector>(); | ||
} | ||
|
||
Compilation::Compilation(const std::vector<StringView>& Sources) noexcept : Compilation(TransformToSource(Sources)) | ||
{ | ||
} | ||
|
||
Compilation::Compilation(const std::vector<std::shared_ptr<const SourceText>>& SourceTexts) noexcept | ||
{ | ||
for (auto&& SourceText : SourceTexts) | ||
{ | ||
const auto SyntaxTree = std::make_shared<::Mamba::SyntaxTree>(SourceText); | ||
SyntaxTrees.emplace_back(SyntaxTree); | ||
} | ||
} | ||
} // namespace Mamba |
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,25 @@ | ||
#pragma once | ||
|
||
#include "SourceText.h" | ||
#include <memory> | ||
|
||
namespace Mamba | ||
{ | ||
// | ||
class Compilation final | ||
{ | ||
std::vector<std::shared_ptr<class SyntaxTree>> SyntaxTrees; | ||
|
||
public: | ||
[[nodiscard]] Compilation(const std::vector<StringView>& Sources) noexcept; | ||
[[nodiscard]] Compilation(const std::vector<std::shared_ptr<const SourceText>>& Sources) noexcept; | ||
|
||
private: | ||
static void Compile(const std::shared_ptr<class SyntaxTree> SyntaxTree) noexcept; | ||
|
||
public: | ||
void Compile() noexcept; | ||
|
||
std::vector<std::shared_ptr<const class Diagnostic>> Diagnostics() const noexcept; | ||
}; | ||
} // namespace Mamba |
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
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
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
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
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
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
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
Oops, something went wrong.