Skip to content

Commit d2e7c78

Browse files
committed
Create utility function for Associativity spelling
1 parent 46dc365 commit d2e7c78

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/swift/AST/AttrKind.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ enum class Associativity : uint8_t {
4040
Right
4141
};
4242

43+
/// Returns the in-source spelling of the given associativity.
44+
StringRef getAssociativitySpelling(Associativity value);
45+
4346
/// The kind of unary operator, if any.
4447
enum class UnaryOperatorKind : uint8_t {
4548
None,

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6002,6 +6002,15 @@ SourceRange DestructorDecl::getSourceRange() const {
60026002
return { getDestructorLoc(), getBody()->getEndLoc() };
60036003
}
60046004

6005+
StringRef swift::getAssociativitySpelling(Associativity value) {
6006+
switch (value) {
6007+
case Associativity::None: return "none";
6008+
case Associativity::Left: return "left";
6009+
case Associativity::Right: return "right";
6010+
}
6011+
llvm_unreachable("Unhandled Associativity in switch.");
6012+
}
6013+
60056014
PrecedenceGroupDecl *
60066015
PrecedenceGroupDecl::create(DeclContext *dc,
60076016
SourceLoc precedenceGroupLoc,

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,9 +4072,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
40724072
void getPrecedenceGroupCompletions(SyntaxKind SK) {
40734073
switch (SK) {
40744074
case SyntaxKind::PrecedenceGroupAssociativity:
4075-
addKeyword("none");
4076-
addKeyword("left");
4077-
addKeyword("right");
4075+
addKeyword(getAssociativitySpelling(Associativity::None));
4076+
addKeyword(getAssociativitySpelling(Associativity::Left));
4077+
addKeyword(getAssociativitySpelling(Associativity::Right));
40784078
break;
40794079
case SyntaxKind::PrecedenceGroupAssignment:
40804080
addKeyword(getTokenText(tok::kw_false), Type(), SemanticContextKind::None,

0 commit comments

Comments
 (0)