%{ 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