Add a new type alias for Result<shared_ptr<Expressoin>>
This commit is contained in:
parent
c737af51a4
commit
1330bad6fb
|
@ -45,6 +45,11 @@ enum class ExprType {
|
|||
List,
|
||||
Number,
|
||||
};
|
||||
class Expression;
|
||||
|
||||
using node = std::shared_ptr<Expression>;
|
||||
using maybe_node = Result<node>;
|
||||
using ast = llvm::SmallVector<node, 0>;
|
||||
|
||||
/// The base class of the expressions which provides the common interface for
|
||||
/// the expressions to implement.
|
||||
|
@ -65,12 +70,9 @@ public:
|
|||
/// The AST representation of an expression
|
||||
virtual std::string toString() const = 0;
|
||||
|
||||
virtual Result<Expression *> analyze(reader::SemanticContext &) = 0;
|
||||
virtual maybe_node analyze(reader::SemanticContext &) = 0;
|
||||
};
|
||||
|
||||
using node = std::shared_ptr<Expression>;
|
||||
using ast = llvm::SmallVector<node, 0>;
|
||||
|
||||
/// Create a new `node` of type `T` and forwards any given parameter
|
||||
/// to the constructor of type `T`. This is the **official way** to create
|
||||
/// a new `Expression`. Here is an example:
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
std::string toString() const;
|
||||
|
||||
void append(node);
|
||||
Result<Expression *> analyze(reader::SemanticContext &);
|
||||
maybe_node analyze(reader::SemanticContext &);
|
||||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ struct Number : public Expression {
|
|||
|
||||
ExprType getType() const;
|
||||
std::string toString() const;
|
||||
Result<Expression *> analyze(reader::SemanticContext &ctx);
|
||||
maybe_node analyze(reader::SemanticContext &ctx);
|
||||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
|
||||
static bool classof(const Expression *e);
|
||||
|
||||
Result<Expression *> analyze(reader::SemanticContext &);
|
||||
maybe_node analyze(reader::SemanticContext &);
|
||||
|
||||
~Symbol() = default;
|
||||
};
|
||||
|
|
|
@ -37,7 +37,7 @@ class Semantics {
|
|||
public:
|
||||
Semantics(){};
|
||||
|
||||
exprs::ast analyze(exprs::ast &);
|
||||
exprs::maybe_node analyze(exprs::ast &);
|
||||
};
|
||||
}; // namespace serene::reader
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ std::string List::toString() const {
|
|||
this->location.end.toString(), s);
|
||||
};
|
||||
|
||||
Result<Expression *> List::analyze(reader::SemanticContext &ctx) {
|
||||
return Result<Expression *>::Success(this);
|
||||
maybe_node List::analyze(reader::SemanticContext &ctx) {
|
||||
return Result<node>::Success(node(this));
|
||||
};
|
||||
|
||||
bool List::classof(const Expression *e) {
|
||||
|
|
|
@ -36,8 +36,8 @@ std::string Number::toString() const {
|
|||
this->location.end.toString(), value);
|
||||
}
|
||||
|
||||
Result<Expression *> Number::analyze(reader::SemanticContext &ctx) {
|
||||
return Result<Expression *>::Success(this);
|
||||
maybe_node Number::analyze(reader::SemanticContext &ctx) {
|
||||
return Result<node>::Success(node(this));
|
||||
};
|
||||
|
||||
bool Number::classof(const Expression *e) {
|
||||
|
|
|
@ -36,8 +36,8 @@ std::string Symbol::toString() const {
|
|||
this->location.end.toString(), this->name);
|
||||
}
|
||||
|
||||
Result<Expression *> Symbol::analyze(reader::SemanticContext &ctx) {
|
||||
return Result<Expression *>::Success(this);
|
||||
maybe_node Symbol::analyze(reader::SemanticContext &ctx) {
|
||||
return Result<node>::Success(node(this));
|
||||
};
|
||||
|
||||
bool Symbol::classof(const Expression *e) {
|
||||
|
|
Loading…
Reference in New Issue