ast: Add base Node class with get_ast_kind() function
This adds a new base class common to all abstract base classes of the AST: We can use it to store information shared by all nodes, such as the newly introduced `AST::Kind` which helps in differentiating nodes. We could also consider using it to store location info, since all AST nodes probably need it.
This commit is contained in:
parent
2dfc196477
commit
14b99bed08
|
@ -36,6 +36,27 @@ namespace AST {
|
|||
class ASTVisitor;
|
||||
using AttrVec = std::vector<Attribute>;
|
||||
|
||||
// The available kinds of AST Nodes
|
||||
enum Kind
|
||||
{
|
||||
UNKNOWN,
|
||||
MACRO_RULES_DEFINITION,
|
||||
};
|
||||
|
||||
// Abstract base class for all AST elements
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Get the kind of Node this is. This is used to differentiate various AST
|
||||
* elements with very little overhead when extracting the derived type through
|
||||
* static casting is not necessary.
|
||||
*/
|
||||
// FIXME: Mark this as `= 0` in the future to make sure every node implements
|
||||
// it
|
||||
virtual Kind get_ast_kind () const { return Kind::UNKNOWN; }
|
||||
};
|
||||
|
||||
// Delimiter types - used in macros and whatever.
|
||||
enum DelimType
|
||||
{
|
||||
|
@ -813,7 +834,7 @@ class MetaListNameValueStr;
|
|||
|
||||
/* Base statement abstract class. Note that most "statements" are not allowed in
|
||||
* top-level module scope - only a subclass of statements called "items" are. */
|
||||
class Stmt
|
||||
class Stmt : public Node
|
||||
{
|
||||
public:
|
||||
// Unique pointer custom clone function
|
||||
|
|
|
@ -441,6 +441,8 @@ public:
|
|||
is_builtin_rule = true;
|
||||
}
|
||||
|
||||
Kind get_ast_kind () const override { return Kind::MACRO_RULES_DEFINITION; }
|
||||
|
||||
protected:
|
||||
/* Use covariance to implement clone function as returning this object rather
|
||||
* than base */
|
||||
|
|
Loading…
Reference in New Issue