Rename Semantic Context to Serene Context to be used in other phases too
This commit is contained in:
parent
ac2814154c
commit
499852c48f
|
@ -73,7 +73,7 @@ int main(int argc, char *argv[]) {
|
|||
throw std::move(maybeAst.getError());
|
||||
}
|
||||
auto &ast = maybeAst.getValue();
|
||||
auto ctx = reader::makeSemanticContext();
|
||||
auto ctx = reader::makeSereneContext();
|
||||
auto afterAst = reader::analyze(ctx, ast);
|
||||
|
||||
if (afterAst) {
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
static bool classof(const serene::exprs::Expression *e);
|
||||
|
||||
serene::exprs::maybe_node analyze(reader::SemanticContext &);
|
||||
serene::exprs::maybe_node analyze(reader::SereneContext &);
|
||||
|
||||
~Error() = default;
|
||||
};
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
ExprType getType() const;
|
||||
std::string toString() const;
|
||||
maybe_node analyze(reader::SemanticContext &);
|
||||
maybe_node analyze(reader::SereneContext &);
|
||||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
///
|
||||
/// \param ctx The semantic analysis context object.
|
||||
/// \param list the list containing the `def` form
|
||||
static maybe_node make(reader::SemanticContext &ctx, List *list);
|
||||
static maybe_node make(reader::SereneContext &ctx, List *list);
|
||||
~Def() = default;
|
||||
};
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
namespace serene {
|
||||
|
||||
namespace reader {
|
||||
class SemanticContext;
|
||||
class SereneContext;
|
||||
}
|
||||
|
||||
/// Contains all the builtin AST expressions including those which do not appear
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
/// to a `Def` node that represents defining a new binding.
|
||||
///
|
||||
/// \param ctx is the context object of the semantic analyzer.
|
||||
virtual maybe_node analyze(reader::SemanticContext &ctx) = 0;
|
||||
virtual maybe_node analyze(reader::SereneContext &ctx) = 0;
|
||||
};
|
||||
|
||||
/// Create a new `node` of type `T` and forwards any given parameter
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
ExprType getType() const;
|
||||
std::string toString() const;
|
||||
maybe_node analyze(reader::SemanticContext &);
|
||||
maybe_node analyze(reader::SereneContext &);
|
||||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
///
|
||||
/// \param ctx The semantic analysis context object.
|
||||
/// \param list the list containing the `fn` form
|
||||
static maybe_node make(reader::SemanticContext &ctx, List *list);
|
||||
static maybe_node make(reader::SereneContext &ctx, List *list);
|
||||
|
||||
~Fn() = default;
|
||||
};
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
std::vector<node>::iterator begin();
|
||||
std::vector<node>::iterator end();
|
||||
|
||||
maybe_node analyze(reader::SemanticContext &);
|
||||
maybe_node analyze(reader::SereneContext &);
|
||||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ struct Number : public Expression {
|
|||
|
||||
ExprType getType() const;
|
||||
std::string toString() const;
|
||||
maybe_node analyze(reader::SemanticContext &ctx);
|
||||
maybe_node analyze(reader::SereneContext &ctx);
|
||||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
maybe_node analyze(reader::SemanticContext &);
|
||||
maybe_node analyze(reader::SereneContext &);
|
||||
|
||||
~Symbol() = default;
|
||||
};
|
||||
|
|
|
@ -29,20 +29,20 @@
|
|||
|
||||
namespace serene::reader {
|
||||
|
||||
class SemanticContext {
|
||||
class SereneContext {
|
||||
public:
|
||||
SemanticContext(){};
|
||||
SereneContext(){};
|
||||
};
|
||||
|
||||
/// Creates a new semantic analysis context
|
||||
SemanticContext makeSemanticContext();
|
||||
SereneContext makeSereneContext();
|
||||
/// This function is the entrypoint to the Semantic Analysis phase of **Serene**
|
||||
/// It will call the `analyze` method on every node in the given AST and
|
||||
/// returns a new AST as the result of the semantic analysis.
|
||||
///
|
||||
/// \param ctx The analysis context
|
||||
/// \prama tree The raw AST to analyze
|
||||
exprs::maybe_ast analyze(SemanticContext &ctx, exprs::ast &tree);
|
||||
exprs::maybe_ast analyze(SereneContext &ctx, exprs::ast &tree);
|
||||
}; // namespace serene::reader
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,7 @@ std::string Error::toString() const {
|
|||
return llvm::formatv("<Error E{0}: {1}>", this->variant->id, this->message);
|
||||
}
|
||||
|
||||
serene::exprs::maybe_node Error::analyze(reader::SemanticContext &ctx) {
|
||||
serene::exprs::maybe_node Error::analyze(reader::SereneContext &ctx) {
|
||||
return Result<serene::exprs::node>::success(nullptr);
|
||||
};
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ std::string Def::toString() const {
|
|||
this->value->toString());
|
||||
}
|
||||
|
||||
maybe_node Def::analyze(reader::SemanticContext &ctx) {
|
||||
maybe_node Def::analyze(reader::SereneContext &ctx) {
|
||||
return Result<node>::success(nullptr);
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,7 @@ bool Def::classof(const Expression *e) {
|
|||
return e->getType() == ExprType::Def;
|
||||
};
|
||||
|
||||
maybe_node Def::make(reader::SemanticContext &ctx, List *list) {
|
||||
maybe_node Def::make(reader::SereneContext &ctx, List *list) {
|
||||
// TODO: Add support for docstring as the 3rd argument (4th element)
|
||||
|
||||
if (list->count() != 3) {
|
||||
|
|
|
@ -42,13 +42,13 @@ std::string Fn::toString() const {
|
|||
this->body.empty() ? "<>" : astToString(&this->body));
|
||||
}
|
||||
|
||||
maybe_node Fn::analyze(reader::SemanticContext &ctx) {
|
||||
maybe_node Fn::analyze(reader::SereneContext &ctx) {
|
||||
return Result<node>::success(nullptr);
|
||||
};
|
||||
|
||||
bool Fn::classof(const Expression *e) { return e->getType() == ExprType::Fn; };
|
||||
|
||||
maybe_node Fn::make(reader::SemanticContext &ctx, List *list) {
|
||||
maybe_node Fn::make(reader::SereneContext &ctx, List *list) {
|
||||
// TODO: Add support for docstring as the 3rd argument (4th element)
|
||||
if (list->count() < 2) {
|
||||
std::string msg =
|
||||
|
|
|
@ -55,7 +55,7 @@ std::string List::toString() const {
|
|||
return llvm::formatv("<List {0}>", s);
|
||||
};
|
||||
|
||||
maybe_node List::analyze(reader::SemanticContext &ctx) {
|
||||
maybe_node List::analyze(reader::SereneContext &ctx) {
|
||||
if (!elements.empty()) {
|
||||
auto *first = elements[0].get();
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ std::string Number::toString() const {
|
|||
return llvm::formatv("<Number {0}>", value);
|
||||
}
|
||||
|
||||
maybe_node Number::analyze(reader::SemanticContext &ctx) {
|
||||
maybe_node Number::analyze(reader::SereneContext &ctx) {
|
||||
return Result<node>::success(nullptr);
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ std::string Symbol::toString() const {
|
|||
return llvm::formatv("<Symbol {0}>", this->name);
|
||||
}
|
||||
|
||||
maybe_node Symbol::analyze(reader::SemanticContext &ctx) {
|
||||
maybe_node Symbol::analyze(reader::SereneContext &ctx) {
|
||||
return Result<node>::success(nullptr);
|
||||
};
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
namespace serene::reader {
|
||||
|
||||
SemanticContext makeSemanticContext() { return SemanticContext(); }
|
||||
SereneContext makeSereneContext() { return SereneContext(); }
|
||||
/// The entry point to the Semantic analysis phase. It calls the `analyze`
|
||||
/// method of each node in the given AST and creates a new AST that contains a
|
||||
/// more comprehensive set of nodes in a semantically correct AST. If the
|
||||
|
@ -39,7 +39,7 @@ SemanticContext makeSemanticContext() { return SemanticContext(); }
|
|||
/// semantic error.
|
||||
/// \param ctx The semantic analysis context
|
||||
/// \param inputAst The raw AST to analyze and possibly rewrite.
|
||||
exprs::maybe_ast analyze(SemanticContext &ctx, exprs::ast &inputAst) {
|
||||
exprs::maybe_ast analyze(SereneContext &ctx, exprs::ast &inputAst) {
|
||||
// TODO: Fetch the current namespace from the JIT engine later and if it is
|
||||
// `nil` then the given `ast` has to start with a namespace definition.
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ TEST_CASE("List Expression", "[expression]") {
|
|||
};
|
||||
|
||||
TEST_CASE("List semantic analysis of 'def'", "[semantic]") {
|
||||
auto ctx = reader::makeSemanticContext();
|
||||
auto ctx = reader::makeSereneContext();
|
||||
auto ast = reader::read("(def (a) b)");
|
||||
auto afterAst = reader::analyze(ctx, ast.getValue());
|
||||
REQUIRE(afterAst);
|
||||
|
@ -109,7 +109,7 @@ TEST_CASE("List semantic analysis of 'def'", "[semantic]") {
|
|||
}
|
||||
|
||||
TEST_CASE("List semantic analysis for 'fn'", "[semantic]") {
|
||||
auto ctx = reader::makeSemanticContext();
|
||||
auto ctx = reader::makeSereneContext();
|
||||
|
||||
auto ast = reader::read("(fn)");
|
||||
auto afterAst = reader::analyze(ctx, ast.getValue());
|
||||
|
@ -150,7 +150,7 @@ TEST_CASE("List semantic analysis for 'fn'", "[semantic]") {
|
|||
}
|
||||
|
||||
TEST_CASE("Complex semantic analysis", "[semantic]") {
|
||||
auto ctx = reader::makeSemanticContext();
|
||||
auto ctx = reader::makeSereneContext();
|
||||
|
||||
auto ast =
|
||||
reader::read("(def a (fn (x) x))\n((def b (fn (x) (fn (y) y))))\n\n");
|
||||
|
|
Loading…
Reference in New Issue