feat(AST): Add node factory helper and missing identifier node
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.
This commit is contained in:
parent
91aefc27b3
commit
5e94021ae5
@ -23,4 +23,9 @@ namespace arti::lang::ast {
|
||||
Vector<TopLevelDeclNode> declarations;
|
||||
};
|
||||
|
||||
template <ASTNodePtr Node>
|
||||
auto MakeNode() {
|
||||
return std::make_unique<typename Node::element_type>();
|
||||
}
|
||||
|
||||
} // namespace arti::lang::ast
|
||||
|
||||
@ -74,4 +74,10 @@ namespace arti::lang::ast {
|
||||
template <typename T>
|
||||
using Vector = std::vector<T>;
|
||||
|
||||
template <typename Node>
|
||||
concept ASTNodePtr = requires {
|
||||
typename Node::element_type;
|
||||
requires std::is_same_v<std::unique_ptr<typename Node::element_type>, Node>;
|
||||
};
|
||||
|
||||
} // namespace arti::lang::ast
|
||||
|
||||
@ -57,6 +57,13 @@ namespace arti::lang::ast {
|
||||
struct nodes::NamespacedType {
|
||||
SourceLocation location;
|
||||
|
||||
String typeName;
|
||||
TypeExpressionNode baseType;
|
||||
};
|
||||
|
||||
struct nodes::NamespacedIdentifier {
|
||||
SourceLocation location;
|
||||
|
||||
Vector<String> identParts;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user