add Expr::kind() -> string method, purely for debugging

This commit is contained in:
Qyriad 2024-06-24 11:45:16 -06:00
parent 7c3b8229cc
commit 44b0d74370
2 changed files with 148 additions and 2 deletions

View file

@ -581,6 +581,146 @@ std::string ExprLambda::showNamePos(const EvalState & state) const
}
std::string_view Expr::kind() const
{
return "abstract";
}
std::string_view ExprInt::kind() const
{
return "int";
}
std::string_view ExprFloat::kind() const
{
return "float";
}
std::string_view ExprString::kind() const
{
return "string";
}
std::string_view ExprPath::kind() const
{
return "path";
}
std::string_view ExprVar::kind() const
{
return "var";
}
std::string_view ExprInheritFrom::kind() const
{
return "inherit from";
}
std::string_view ExprSelect::kind() const
{
return "select";
}
std::string_view ExprOpHasAttr::kind() const
{
return "hasattr operator";
}
std::string_view ExprAttrs::kind() const
{
return "attrs";
}
std::string_view ExprList::kind() const
{
return "list";
}
std::string_view ExprLambda::kind() const
{
return "lambda";
}
std::string_view ExprCall::kind() const
{
return "call";
}
std::string_view ExprLet::kind() const
{
return "let";
}
std::string_view ExprWith::kind() const
{
return "with";
}
std::string_view ExprIf::kind() const
{
return "if";
}
std::string_view ExprAssert::kind() const
{
return "assert";
}
std::string_view ExprOpNot::kind() const
{
return "not operator";
}
std::string_view ExprOpEq::kind() const
{
return "equality operator";
}
std::string_view ExprOpNEq::kind() const
{
return "inequality operator";
}
std::string_view ExprOpAnd::kind() const
{
return "logical AND operator";
}
std::string_view ExprOpOr::kind() const
{
return "logical OR operator";
}
std::string_view ExprOpImpl::kind() const
{
return "logical implication operator";
}
std::string_view ExprOpUpdate::kind() const
{
return "update operator";
}
std::string_view ExprOpConcatLists::kind() const
{
return "list concatenation operator";
}
std::string_view ExprConcatStrings::kind() const
{
return "string concatenation";
}
std::string_view ExprPos::kind() const
{
return "position";
}
std::string_view ExprBlackHole::kind() const
{
return "blackhole";
}
/* Position table. */

View file

@ -63,12 +63,15 @@ public:
virtual Value * maybeThunk(EvalState & state, Env & env);
virtual void setName(Symbol name);
virtual PosIdx getPos() const { return noPos; }
/** Entirely for debugging. */
virtual std::string_view kind() const;
};
#define COMMON_METHODS \
void show(const SymbolTable & symbols, std::ostream & str) const override; \
void eval(EvalState & state, Env & env, Value & v) override; \
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) override;
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) override; \
virtual std::string_view kind() const override;
struct ExprInt : Expr
{
@ -151,7 +154,8 @@ struct ExprInheritFrom : ExprVar
this->fromWith = nullptr;
}
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) override;
std::string_view kind() const override;
};
struct ExprSelect : Expr
@ -418,6 +422,7 @@ struct ExprOpNot : Expr
} \
void eval(EvalState & state, Env & env, Value & v) override; \
PosIdx getPos() const override { return pos; } \
std::string_view kind() const override; \
};
MakeBinOp(ExprOpEq, "==")
@ -453,6 +458,7 @@ struct ExprBlackHole : Expr
void show(const SymbolTable & symbols, std::ostream & str) const override {}
void eval(EvalState & state, Env & env, Value & v) override;
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) override {}
std::string_view kind() const override;
};
extern ExprBlackHole eBlackHole;