Fix compile errors
This commit is contained in:
parent
e01a970377
commit
88134802fa
2 changed files with 82 additions and 12 deletions
67
bootstrap/cxx/include/bolt/Program.hpp
Normal file
67
bootstrap/cxx/include/bolt/Program.hpp
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "bolt/Common.hpp"
|
||||||
|
#include "bolt/Checker.hpp"
|
||||||
|
#include "bolt/DiagnosticEngine.hpp"
|
||||||
|
|
||||||
|
class SourceFile;
|
||||||
|
|
||||||
|
namespace bolt {
|
||||||
|
|
||||||
|
class Program {
|
||||||
|
|
||||||
|
DiagnosticEngine& DE;
|
||||||
|
LanguageConfig Config;
|
||||||
|
|
||||||
|
std::unordered_map<std::filesystem::path, SourceFile*> SourceFiles;
|
||||||
|
std::unordered_map<SourceFile*, Checker> TCs;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Program(DiagnosticEngine& DE, LanguageConfig Config = {}):
|
||||||
|
DE(DE), Config(Config) {}
|
||||||
|
|
||||||
|
auto getSourceFiles() {
|
||||||
|
return zen::make_iterator_range(SourceFiles.begin(), SourceFiles.end()).map_second();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addSourceFile(std::filesystem::path Path, SourceFile* SF) {
|
||||||
|
SourceFiles.emplace(Path, SF);
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagnosticEngine& getDiagnostics() {
|
||||||
|
return DE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDiagnostics(DiagnosticEngine& New) {
|
||||||
|
DE = New;
|
||||||
|
}
|
||||||
|
|
||||||
|
Checker& getTypeChecker(SourceFile* SF) {
|
||||||
|
auto Match = TCs.find(SF);
|
||||||
|
if (Match != TCs.end()) {
|
||||||
|
return Match->second;
|
||||||
|
}
|
||||||
|
return TCs.emplace(SF, Checker { Config, DE }).first->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void check() {
|
||||||
|
for (auto SF: getSourceFiles()) {
|
||||||
|
getTypeChecker(SF).check(SF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~Program() {
|
||||||
|
// for (auto [SF, TC]: TCs) {
|
||||||
|
// delete TC;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
#include "bolt/Parser.hpp"
|
#include "bolt/Parser.hpp"
|
||||||
#include "bolt/Checker.hpp"
|
#include "bolt/Checker.hpp"
|
||||||
#include "bolt/Evaluator.hpp"
|
#include "bolt/Evaluator.hpp"
|
||||||
|
#include "bolt/Program.hpp"
|
||||||
|
|
||||||
using namespace bolt;
|
using namespace bolt;
|
||||||
|
|
||||||
|
@ -72,9 +73,10 @@ int main(int Argc, const char* Argv[]) {
|
||||||
|
|
||||||
ConsolePrinter ThePrinter;
|
ConsolePrinter ThePrinter;
|
||||||
ConsoleDiagnostics DE(ThePrinter);
|
ConsoleDiagnostics DE(ThePrinter);
|
||||||
|
DiagnosticStore DS;
|
||||||
LanguageConfig Config;
|
LanguageConfig Config;
|
||||||
|
|
||||||
std::vector<SourceFile*> SourceFiles;
|
Program Prog { DirectDiagnostics ? static_cast<DiagnosticEngine&>(DE) : DS, Config };
|
||||||
|
|
||||||
for (auto Filename: Submatch->get_pos_args()) {
|
for (auto Filename: Submatch->get_pos_args()) {
|
||||||
|
|
||||||
|
@ -92,15 +94,10 @@ int main(int Argc, const char* Argv[]) {
|
||||||
|
|
||||||
SF->setParents();
|
SF->setParents();
|
||||||
|
|
||||||
SourceFiles.push_back(SF);
|
Prog.addSourceFile(Filename, SF);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiagnosticStore DS;
|
Prog.check();
|
||||||
Checker TheChecker { Config, DirectDiagnostics ? static_cast<DiagnosticEngine&>(DE) : static_cast<DiagnosticEngine&>(DS) };
|
|
||||||
|
|
||||||
for (auto SF: SourceFiles) {
|
|
||||||
TheChecker.check(SF);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsVerify) {
|
if (IsVerify) {
|
||||||
|
|
||||||
|
@ -109,8 +106,10 @@ int main(int Argc, const char* Argv[]) {
|
||||||
bool HasError = 0;
|
bool HasError = 0;
|
||||||
|
|
||||||
struct AssertVisitor : public CSTVisitor<AssertVisitor> {
|
struct AssertVisitor : public CSTVisitor<AssertVisitor> {
|
||||||
|
|
||||||
Checker& C;
|
Checker& C;
|
||||||
DiagnosticEngine& DE;
|
DiagnosticEngine& DE;
|
||||||
|
|
||||||
void visitExpression(Expression* N) {
|
void visitExpression(Expression* N) {
|
||||||
for (auto A: N->Annotations) {
|
for (auto A: N->Annotations) {
|
||||||
if (A->getKind() == NodeKind::TypeAssertAnnotation) {
|
if (A->getKind() == NodeKind::TypeAssertAnnotation) {
|
||||||
|
@ -124,15 +123,18 @@ int main(int Argc, const char* Argv[]) {
|
||||||
}
|
}
|
||||||
visitEachChild(N);
|
visitEachChild(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AssertVisitor V { {}, TheChecker, DE };
|
for (auto SF: Prog.getSourceFiles()) {
|
||||||
for (auto SF: SourceFiles) {
|
AssertVisitor V { {}, Prog.getTypeChecker(SF), DE };
|
||||||
V.visit(SF);
|
V.visit(SF);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExpectDiagnosticVisitor : public CSTVisitor<ExpectDiagnosticVisitor> {
|
struct ExpectDiagnosticVisitor : public CSTVisitor<ExpectDiagnosticVisitor> {
|
||||||
|
|
||||||
std::multimap<std::size_t, unsigned> Expected;
|
std::multimap<std::size_t, unsigned> Expected;
|
||||||
|
|
||||||
void visitExpressionAnnotation(ExpressionAnnotation* N) {
|
void visitExpressionAnnotation(ExpressionAnnotation* N) {
|
||||||
if (N->getExpression()->is<CallExpression>()) {
|
if (N->getExpression()->is<CallExpression>()) {
|
||||||
auto CE = static_cast<CallExpression*>(N->getExpression());
|
auto CE = static_cast<CallExpression*>(N->getExpression());
|
||||||
|
@ -145,10 +147,11 @@ int main(int Argc, const char* Argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpectDiagnosticVisitor V1;
|
ExpectDiagnosticVisitor V1;
|
||||||
for (auto SF: SourceFiles) {
|
for (auto SF: Prog.getSourceFiles()) {
|
||||||
V1.visit(SF);
|
V1.visit(SF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +195,7 @@ int main(int Argc, const char* Argv[]) {
|
||||||
std::cerr << Args[0].asString() << "\n";
|
std::cerr << Args[0].asString() << "\n";
|
||||||
return Value::unit();
|
return Value::unit();
|
||||||
}));
|
}));
|
||||||
for (auto SF: SourceFiles) {
|
for (auto SF: Prog.getSourceFiles()) {
|
||||||
// TODO add a SourceFile-local env that inherits from GlobalEnv
|
// TODO add a SourceFile-local env that inherits from GlobalEnv
|
||||||
E.evaluate(SF, GlobalEnv);
|
E.evaluate(SF, GlobalEnv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue