Skip to content

Commit 94c3f55

Browse files
committed
libSyntax: extract meta-information of trivia kinds to syntax_gyb_support. NFC
The existing libSyntax infrastructure uses external python dictionaries to share logic between C++ and Swift implementations. This patch teaches trivia kinds to adapt to this infrastructure as well.
1 parent 25cdc98 commit 94c3f55

File tree

11 files changed

+314
-495
lines changed

11 files changed

+314
-495
lines changed

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
125125
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
126126
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"
127127
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Token.py"
128+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Trivia.py"
128129
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Traits.py"
129130
"${SWIFT_SOURCE_DIR}/utils/gyb_sourcekit_support/__init__.py"
130131
"${SWIFT_SOURCE_DIR}/utils/gyb_sourcekit_support/UIDs.py")

include/swift/Syntax/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ set(generated_include_sources
99
SyntaxNodes.h.gyb
1010
SyntaxBuilders.h.gyb
1111
SyntaxFactory.h.gyb
12-
SyntaxVisitor.h.gyb)
12+
SyntaxVisitor.h.gyb
13+
Trivia.h.gyb)
1314

1415
add_gyb_target(swift-syntax-generated-headers
1516
"${generated_include_sources}")

include/swift/Syntax/Serialization/SyntaxSerialization.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -46,64 +46,6 @@ struct ScalarEnumerationTraits<tok> {
4646
}
4747
};
4848

49-
/// Serialization traits for TriviaPiece.
50-
/// - All trivia pieces will have a "kind" key that contains the serialized
51-
/// name of the trivia kind.
52-
/// - Comment trivia will have the associated text of the comment under the
53-
/// "value" key.
54-
/// - All other trivia will have the associated integer count of their
55-
/// occurrences under the "value" key.
56-
template<>
57-
struct ObjectTraits<syntax::TriviaPiece> {
58-
static void mapping(Output &out, syntax::TriviaPiece &value) {
59-
auto kind = value.getKind();
60-
out.mapRequired("kind", kind);
61-
switch (kind) {
62-
case syntax::TriviaKind::Space:
63-
case syntax::TriviaKind::Tab:
64-
case syntax::TriviaKind::VerticalTab:
65-
case syntax::TriviaKind::Formfeed:
66-
case syntax::TriviaKind::Newline:
67-
case syntax::TriviaKind::CarriageReturn:
68-
case syntax::TriviaKind::CarriageReturnLineFeed:
69-
case syntax::TriviaKind::Backtick: {
70-
auto count = value.getCount();
71-
out.mapRequired("value", count);
72-
break;
73-
}
74-
case syntax::TriviaKind::LineComment:
75-
case syntax::TriviaKind::BlockComment:
76-
case syntax::TriviaKind::DocLineComment:
77-
case syntax::TriviaKind::DocBlockComment:
78-
case syntax::TriviaKind::GarbageText: {
79-
auto text = value.getText();
80-
out.mapRequired("value", text);
81-
break;
82-
}
83-
}
84-
}
85-
};
86-
87-
/// Serialization traits for TriviaKind.
88-
template <>
89-
struct ScalarEnumerationTraits<syntax::TriviaKind> {
90-
static void enumeration(Output &out, syntax::TriviaKind &value) {
91-
out.enumCase(value, "Space", syntax::TriviaKind::Space);
92-
out.enumCase(value, "Tab", syntax::TriviaKind::Tab);
93-
out.enumCase(value, "VerticalTab", syntax::TriviaKind::VerticalTab);
94-
out.enumCase(value, "Formfeed", syntax::TriviaKind::Formfeed);
95-
out.enumCase(value, "Newline", syntax::TriviaKind::Newline);
96-
out.enumCase(value, "CarriageReturn", syntax::TriviaKind::CarriageReturn);
97-
out.enumCase(value, "CarriageReturnLineFeed", syntax::TriviaKind::CarriageReturnLineFeed);
98-
out.enumCase(value, "LineComment", syntax::TriviaKind::LineComment);
99-
out.enumCase(value, "BlockComment", syntax::TriviaKind::BlockComment);
100-
out.enumCase(value, "DocLineComment", syntax::TriviaKind::DocLineComment);
101-
out.enumCase(value, "DocBlockComment", syntax::TriviaKind::DocBlockComment);
102-
out.enumCase(value, "Backtick", syntax::TriviaKind::Backtick);
103-
out.enumCase(value, "GarbageText", syntax::TriviaKind::GarbageText);
104-
}
105-
};
106-
10749
/// Serialization traits for Trivia.
10850
/// Trivia will serialize as an array of the underlying TriviaPieces.
10951
template<>

0 commit comments

Comments
 (0)