Gyoji Compiler
Loading...
Searching...
No Matches
syntax-node.hpp
1#ifndef _GYOJI_INTERNAL
2#error "This header is intended to be used internally as a part of the Gyoji front-end. Please include frontend.hpp instead."
3#endif
4#pragma once
5
23
55 class SyntaxNode {
56 public:
57 typedef std::variant<GYOJI_SYNTAX_NODE_VARIANT_LIST> specific_type_t;
58
66 SyntaxNode(Gyoji::context::TokenID _type, specific_type_t _data, const Gyoji::context::SourceReference & _source_ref);
68
69
75
80 const Gyoji::context::TokenID & get_type() const;
81
88 template <class T> bool has_data() const {
89 return std::holds_alternative<T*>(data);
90 }
91
100 template <class T> const T &get_data() const {
101 const T *d = std::get<T*>(data);
102 return *d;
103 }
104
110 const SyntaxNode & get_syntax_node() const;
111
117
118 private:
119 // This list does NOT own its children, so
120 // the class deriving from this one must
121 // agree to own the pointers separately.
123 const Gyoji::context::SourceReference & source_ref;
124
125 protected:
126 // Children are owned by their parents, so this is
127 // private and can only be called by the
128 // deriving class.
129 void add_child(const SyntaxNode & node);
130 void prepend_child(const SyntaxNode & node);
131
132 Gyoji::context::TokenID type;
133 specific_type_t data;
134
135 };
136
137};
References a location in the source-file.
Definition source-reference.hpp:16
Weakly-typed syntax node.
Definition syntax-node.hpp:55
const Gyoji::context::TokenID & get_type() const
Definition syntax-node.cpp:34
bool has_data() const
Definition syntax-node.hpp:88
const SyntaxNode & get_syntax_node() const
Definition syntax-node.cpp:39
const T & get_data() const
Definition syntax-node.hpp:100
const std::vector< std::reference_wrapper< const SyntaxNode > > & get_children() const
Definition syntax-node.cpp:30
const Gyoji::context::SourceReference & get_source_ref() const
Definition syntax-node.cpp:43
Abstract syntax tree.
Definition syntax-node.hpp:22