forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SyntaxSerialization.cpp.gyb
84 lines (76 loc) · 2.48 KB
/
SyntaxSerialization.cpp.gyb
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
%{
from gyb_syntax_support import *
from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS
grouped_nodes = { kind: [] for kind in SYNTAX_BASE_KINDS }
for node in SYNTAX_NODES:
grouped_nodes[node.base_kind].append(node)
# Ignore the following admonition; it applies to the resulting .cpp file only
}%
//// Automatically Generated From SyntaxSerialization.cpp.gyb.
//// Do Not Edit Directly!
//===---------------------- SytnaxSerialization.cpp -----------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
namespace swift {
namespace serialization {
uint16_t getNumericValue(syntax::SyntaxKind Kind) {
switch (Kind) {
case syntax::SyntaxKind::Token:
return 0;
case syntax::SyntaxKind::Unknown:
return 1;
% for name, nodes in grouped_nodes.items():
% for node in nodes:
case syntax::SyntaxKind::${node.syntax_kind}:
return ${SYNTAX_NODE_SERIALIZATION_CODES[node.syntax_kind]};
% end
% end
}
llvm_unreachable("unhandled kind");
}
uint8_t getNumericValue(syntax::TriviaKind Kind) {
switch (Kind) {
% for trivia in TRIVIAS:
case syntax::TriviaKind::${trivia.name}: return ${trivia.serialization_code};
% end
}
llvm_unreachable("unhandled kind");
}
uint8_t getNumericValue(tok Value) {
switch (Value) {
case tok::eof: return 0;
% for token in SYNTAX_TOKENS:
case tok::${token.kind}: return ${token.serialization_code};
% end
case tok::kw_undef:
case tok::kw_sil:
case tok::kw_sil_stage:
case tok::kw_sil_property:
case tok::kw_sil_vtable:
case tok::kw_sil_global:
case tok::kw_sil_witness_table:
case tok::kw_sil_default_witness_table:
case tok::kw_sil_differentiability_witness:
case tok::kw_sil_coverage_map:
case tok::kw_sil_scope:
case tok::sil_dollar:
case tok::sil_exclamation:
case tok::code_complete:
case tok::sil_local_name:
case tok::comment:
case tok::NUM_TOKENS:
llvm_unreachable("Should not get serialized in a syntax tree");
}
llvm_unreachable("unhandled token");
}
} // end namespace serialization
} // end namespace swift