Gyoji Compiler
Loading...
Searching...
No Matches
src
frontend
gyoji-frontend
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
22
namespace
Gyoji::frontend::ast
{
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);
67
~SyntaxNode
();
68
69
74
const
std::vector<std::reference_wrapper<const SyntaxNode>
> &
get_children
()
const
;
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
116
const
Gyoji::context::SourceReference
&
get_source_ref
()
const
;
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.
122
std::vector<std::reference_wrapper<const SyntaxNode>
> children;
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
};
std::vector
Gyoji::context::SourceReference
References a location in the source-file.
Definition
source-reference.hpp:16
Gyoji::frontend::ast::SyntaxNode
Weakly-typed syntax node.
Definition
syntax-node.hpp:55
Gyoji::frontend::ast::SyntaxNode::get_type
const Gyoji::context::TokenID & get_type() const
Definition
syntax-node.cpp:34
Gyoji::frontend::ast::SyntaxNode::has_data
bool has_data() const
Definition
syntax-node.hpp:88
Gyoji::frontend::ast::SyntaxNode::get_syntax_node
const SyntaxNode & get_syntax_node() const
Definition
syntax-node.cpp:39
Gyoji::frontend::ast::SyntaxNode::get_data
const T & get_data() const
Definition
syntax-node.hpp:100
Gyoji::frontend::ast::SyntaxNode::get_children
const std::vector< std::reference_wrapper< const SyntaxNode > > & get_children() const
Definition
syntax-node.cpp:30
Gyoji::frontend::ast::SyntaxNode::get_source_ref
const Gyoji::context::SourceReference & get_source_ref() const
Definition
syntax-node.cpp:43
Gyoji::frontend::ast
Abstract syntax tree.
Definition
syntax-node.hpp:22
Generated by
1.9.8