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:
erick-alcachofa 2025-10-12 18:55:34 -06:00
parent 91aefc27b3
commit 5e94021ae5
Signed by: me
GPG Key ID: 6FA5F8643444BAFA
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
};