File tree Expand file tree Collapse file tree 5 files changed +25
-31
lines changed Expand file tree Collapse file tree 5 files changed +25
-31
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,26 @@ using namespace cxx_synthesis;
17
17
18
18
StringRef cxx_synthesis::getCxxImplNamespaceName () { return " _impl" ; }
19
19
20
+ bool ClangSyntaxPrinter::isClangKeyword (StringRef name) {
21
+ static const llvm::DenseSet<StringRef> keywords = [] {
22
+ llvm::DenseSet<StringRef> set;
23
+ // FIXME: clang::IdentifierInfo /nearly/ has the API we need to do this
24
+ // in a more principled way, but not quite.
25
+ #define KEYWORD (SPELLING, FLAGS ) set.insert(#SPELLING);
26
+ #define CXX_KEYWORD_OPERATOR (SPELLING, TOK ) set.insert(#SPELLING);
27
+ #include " clang/Basic/TokenKinds.def"
28
+ return set;
29
+ }();
30
+
31
+ return keywords.contains (name);
32
+ }
33
+
34
+ bool ClangSyntaxPrinter::isClangKeyword (Identifier name) {
35
+ if (name.empty ())
36
+ return false ;
37
+ return ClangSyntaxPrinter::isClangKeyword (name.str ());
38
+ }
39
+
20
40
// / Print a C++ namespace declaration with the give name and body.
21
41
void ClangSyntaxPrinter::printNamespace (
22
42
llvm::function_ref<void (raw_ostream &OS)> namePrinter,
Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ class ClangSyntaxPrinter {
53
53
Optional<OptionalTypeKind> kind,
54
54
NullabilityPrintKind printKind = NullabilityPrintKind::After) const ;
55
55
56
+ // / Returns true if \p name matches a keyword in any Clang language mode.
57
+ static bool isClangKeyword (StringRef name);
58
+ static bool isClangKeyword (Identifier name);
59
+
56
60
protected:
57
61
raw_ostream &os;
58
62
};
Original file line number Diff line number Diff line change @@ -57,33 +57,6 @@ static bool isAnyObjectOrAny(Type type) {
57
57
return type->isAnyObject () || type->isAny ();
58
58
}
59
59
60
- // / Returns true if \p name matches a keyword in any Clang language mode.
61
- static bool isClangKeyword (StringRef name) {
62
- static const llvm::DenseSet<StringRef> keywords = []{
63
- llvm::DenseSet<StringRef> set;
64
- // FIXME: clang::IdentifierInfo /nearly/ has the API we need to do this
65
- // in a more principled way, but not quite.
66
- #define KEYWORD (SPELLING, FLAGS ) \
67
- set.insert (#SPELLING);
68
- #define CXX_KEYWORD_OPERATOR (SPELLING, TOK ) \
69
- set.insert (#SPELLING);
70
- #include " clang/Basic/TokenKinds.def"
71
- return set;
72
- }();
73
-
74
- return keywords.contains (name);
75
- }
76
-
77
- static bool isClangKeyword (Identifier name) {
78
- if (name.empty ())
79
- return false ;
80
- return isClangKeyword (name.str ());
81
- }
82
-
83
- bool DeclAndTypePrinter::isStrClangKeyword (StringRef name) {
84
- return ::isClangKeyword (name);
85
- }
86
-
87
60
// For a given Decl and Type, if the type is not an optional return
88
61
// the type and OTK_None as the optionality. If the type is
89
62
// optional, return the underlying object type, and an optionality
Original file line number Diff line number Diff line change @@ -92,9 +92,6 @@ class DeclAndTypePrinter {
92
92
93
93
static std::pair<Type, OptionalTypeKind>
94
94
getObjectTypeAndOptionality (const ValueDecl *D, Type ty);
95
-
96
- // / Returns true if \p name matches a keyword in any Clang language mode.
97
- static bool isStrClangKeyword (StringRef name);
98
95
};
99
96
100
97
} // end namespace swift
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ void DeclAndTypeClangFunctionPrinter::printFunctionDeclAsCFunctionDecl(
97
97
98
98
if (!name.empty ()) {
99
99
os << ' ' << name;
100
- if (DeclAndTypePrinter::isStrClangKeyword (name))
100
+ if (ClangSyntaxPrinter::isClangKeyword (name))
101
101
os << ' _' ;
102
102
}
103
103
};
You can’t perform that action at this time.
0 commit comments