Clean up the unsed expr traits

This commit is contained in:
Sameer Rahmani 2021-05-06 21:00:58 +01:00
parent fde6636ca2
commit bbf3bd3660
4 changed files with 10 additions and 36 deletions

View File

@ -63,10 +63,6 @@ public:
~Error() = default;
};
// std::shared_ptr<Error> makeError(reader::LocationRange &loc, ErrorVariant
// *err,
// serene::exprs::Node &t, llvm::StringRef
// msg);
}; // namespace serene::errors
#endif

View File

@ -55,6 +55,7 @@ using MaybeNode = Result<Node, ErrorTree>;
using Ast = std::vector<Node>;
using MaybeAst = Result<Ast, ErrorTree>;
static auto EmptyNode = MaybeNode::success(nullptr);
/// The base class of the expressions which provides the common interface for
/// the expressions to implement.
class Expression {
@ -112,11 +113,18 @@ std::shared_ptr<T> makeAndCast(Args &&...args) {
return std::make_shared<T>(std::forward<Args>(args)...);
};
/// The helper function to create a new `Node` and use that as the success case
// of a `Result`. It should be useds where every we want to return a `MaybeNode`
/// successfully
template <typename T, typename... Args>
Result<Node, ErrorTree> makeSuccessfulNode(Args &&...args) {
return Result<Node, ErrorTree>::success(make<T>(std::forward<Args>(args)...));
};
/// The hlper function to create an Errorful `Result<T,...>` (`T` would be
/// either
/// `Node` or `Ast` most of the time) with just one error creating from passing
/// any argument to this function to the `serene::errors::Error` constructor.
template <typename T, typename... Args>
Result<T, ErrorTree> makeErrorful(Args &&...args) {
std::vector<ErrorPtr> v{

View File

@ -48,34 +48,6 @@ static const char *exprTypes[] = {
"Symbol", "List", "Number", "Def", "Error", "Fn", "Call",
};
template <typename ConcreteType>
class ITypeable : public TraitBase<ConcreteType, ITypeable> {
public:
ITypeable(){};
ITypeable(const ITypeable &) = delete;
ExprType getType() const { return this->Object().getType(); }
};
template <typename ConcreteType>
class IAnalyzable : public TraitBase<ConcreteType, IAnalyzable> {
public:
IAnalyzable(){};
IAnalyzable(const IAnalyzable &) = delete;
auto analyze(SereneContext &ctx);
};
template <typename ConcreteType>
class SExp : public WithTrait<ConcreteType, ITypeable,
serene::reader::ILocatable, serene::IDebuggable> {
protected:
serene::reader::LocationRange location;
SExp(const serene::reader::LocationRange &loc) : location(loc){};
public:
serene::reader::LocationRange where() const { return this->location; }
};
}; // namespace serene::exprs
#endif

View File

@ -40,9 +40,7 @@ std::string Call::toString() const {
astToString(&this->params));
}
MaybeNode Call::analyze(SereneContext &ctx) {
return MaybeNode::success(nullptr);
};
MaybeNode Call::analyze(SereneContext &ctx) { return EmptyNode; };
bool Call::classof(const Expression *e) {
return e->getType() == ExprType::Call;
@ -75,7 +73,7 @@ MaybeNode Call::make(SereneContext &ctx, List *list) {
}
};
return MaybeNode::success(nullptr);
return EmptyNode;
};
} // namespace exprs
} // namespace serene