Signed-off-by: erick-alcachofa <erick@artichoke.dev> This commit introduces an utility factory function and structural improvements to the Abstract Syntax Tree (AST). * Adds a new `ASTNodePtr` C++20 concept to constrain template types to be `std::unique_ptr`s pointing to AST nodes. * Introduces a `MakeNode<T>()` factory function that uses this concept to simplify and standardize the creation of new nodes. * Fixed `NamespacedType` and added the missing `NamespacedIdentifier` node.
32 lines
679 B
C++
32 lines
679 B
C++
#pragma once
|
|
|
|
#include <artichoke/Parser/AST/Common.hpp>
|
|
#include <artichoke/Parser/AST/Declarations.hpp>
|
|
|
|
namespace arti::lang::ast {
|
|
|
|
namespace nodes {
|
|
/* Forward declaration of types */
|
|
|
|
/* Main declaration node types */
|
|
struct CompilationUnit;
|
|
|
|
} // namespace nodes
|
|
|
|
/* Public Aliases */
|
|
using CompilationUnitNode = Ptr<nodes::CompilationUnit>;
|
|
using AST = CompilationUnitNode;
|
|
|
|
/* Node definitions */
|
|
struct nodes::CompilationUnit {
|
|
String unitName;
|
|
Vector<TopLevelDeclNode> declarations;
|
|
};
|
|
|
|
template <ASTNodePtr Node>
|
|
auto MakeNode() {
|
|
return std::make_unique<typename Node::element_type>();
|
|
}
|
|
|
|
} // namespace arti::lang::ast
|