blob: 27b85b452213504d0796ab85025a936e12118e2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
* MRustC - Rust Compiler
* - By John Hodge (Mutabah/thePowersGang)
*
* parse/tokentree.hpp
* - Token Trees (groups of tokens
*/
#ifndef TOKENTREE_HPP_INCLUDED
#define TOKENTREE_HPP_INCLUDED
#include "token.hpp"
#include <ident.hpp>
#include <vector>
class TokenTree
{
Ident::Hygiene m_hygiene;
Token m_tok;
::std::vector<TokenTree> m_subtrees;
public:
virtual ~TokenTree() {}
TokenTree() {}
TokenTree(TokenTree&&) = default;
TokenTree& operator=(TokenTree&&) = default;
TokenTree(Token tok):
m_tok( ::std::move(tok) )
{
}
TokenTree(Ident::Hygiene hygiene, Token tok):
m_hygiene( ::std::move(hygiene) ),
m_tok( ::std::move(tok) )
{
}
TokenTree(Ident::Hygiene hygiene, ::std::vector<TokenTree> subtrees):
m_hygiene( ::std::move(hygiene) ),
m_subtrees( ::std::move(subtrees) )
{
}
TokenTree clone() const;
bool is_token() const {
return m_tok.type() != TOK_NULL;
}
unsigned int size() const {
return m_subtrees.size();
}
const TokenTree& operator[](unsigned int idx) const { return m_subtrees[idx]; }
TokenTree& operator[](unsigned int idx) { return m_subtrees[idx]; }
const Token& tok() const { return m_tok; }
Token& tok() { return m_tok; }
const Ident::Hygiene& hygiene() const { return m_hygiene; }
friend ::std::ostream& operator<<(::std::ostream& os, const TokenTree& tt);
};
#endif // TOKENTREE_HPP_INCLUDED
|