diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 06effad42db45..d501ce1822862 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -675,6 +675,8 @@ class BlockCommandComment : public BlockContentComment { } }; +enum class ParamCommandPassDirection { In, Out, InOut }; + /// Doxygen \\param command. class ParamCommandComment : public BlockCommandComment { private: @@ -692,7 +694,8 @@ class ParamCommandComment : public BlockCommandComment { : BlockCommandComment(CommentKind::ParamCommandComment, LocBegin, LocEnd, CommandID, CommandMarker), ParamIndex(InvalidParamIndex) { - ParamCommandCommentBits.Direction = In; + ParamCommandCommentBits.Direction = + llvm::to_underlying(ParamCommandPassDirection::In); ParamCommandCommentBits.IsDirectionExplicit = false; } @@ -700,24 +703,19 @@ class ParamCommandComment : public BlockCommandComment { return C->getCommentKind() == CommentKind::ParamCommandComment; } - enum PassDirection { - In, - Out, - InOut - }; - - static const char *getDirectionAsString(PassDirection D); + static const char *getDirectionAsString(ParamCommandPassDirection D); - PassDirection getDirection() const LLVM_READONLY { - return static_cast(ParamCommandCommentBits.Direction); + ParamCommandPassDirection getDirection() const LLVM_READONLY { + return static_cast( + ParamCommandCommentBits.Direction); } bool isDirectionExplicit() const LLVM_READONLY { return ParamCommandCommentBits.IsDirectionExplicit; } - void setDirection(PassDirection Direction, bool Explicit) { - ParamCommandCommentBits.Direction = Direction; + void setDirection(ParamCommandPassDirection Direction, bool Explicit) { + ParamCommandCommentBits.Direction = llvm::to_underlying(Direction); ParamCommandCommentBits.IsDirectionExplicit = Explicit; } diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp index 0a2d310e5b489..cce8b12170f21 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -187,13 +187,14 @@ static bool getFunctionTypeLoc(TypeLoc TL, FunctionTypeLoc &ResFTL) { return false; } -const char *ParamCommandComment::getDirectionAsString(PassDirection D) { +const char * +ParamCommandComment::getDirectionAsString(ParamCommandPassDirection D) { switch (D) { - case ParamCommandComment::In: + case ParamCommandPassDirection::In: return "[in]"; - case ParamCommandComment::Out: + case ParamCommandPassDirection::Out: return "[out]"; - case ParamCommandComment::InOut: + case ParamCommandPassDirection::InOut: return "[in,out]"; } llvm_unreachable("unknown PassDirection"); diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 6f68577954137..bc01baa1d917b 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -219,12 +219,12 @@ void Sema::checkContainerDecl(const BlockCommandComment *Comment) { /// Turn a string into the corresponding PassDirection or -1 if it's not /// valid. -static int getParamPassDirection(StringRef Arg) { - return llvm::StringSwitch(Arg) - .Case("[in]", ParamCommandComment::In) - .Case("[out]", ParamCommandComment::Out) - .Cases("[in,out]", "[out,in]", ParamCommandComment::InOut) - .Default(-1); +static ParamCommandPassDirection getParamPassDirection(StringRef Arg) { + return llvm::StringSwitch(Arg) + .Case("[in]", ParamCommandPassDirection::In) + .Case("[out]", ParamCommandPassDirection::Out) + .Cases("[in,out]", "[out,in]", ParamCommandPassDirection::InOut) + .Default(static_cast(-1)); } void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command, @@ -232,25 +232,25 @@ void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command, SourceLocation ArgLocEnd, StringRef Arg) { std::string ArgLower = Arg.lower(); - int Direction = getParamPassDirection(ArgLower); + ParamCommandPassDirection Direction = getParamPassDirection(ArgLower); - if (Direction == -1) { + if (Direction == static_cast(-1)) { // Try again with whitespace removed. llvm::erase_if(ArgLower, clang::isWhitespace); Direction = getParamPassDirection(ArgLower); SourceRange ArgRange(ArgLocBegin, ArgLocEnd); - if (Direction != -1) { - const char *FixedName = ParamCommandComment::getDirectionAsString( - (ParamCommandComment::PassDirection)Direction); + if (Direction != static_cast(-1)) { + const char *FixedName = + ParamCommandComment::getDirectionAsString(Direction); Diag(ArgLocBegin, diag::warn_doc_param_spaces_in_direction) << ArgRange << FixItHint::CreateReplacement(ArgRange, FixedName); } else { Diag(ArgLocBegin, diag::warn_doc_param_invalid_direction) << ArgRange; - Direction = ParamCommandComment::In; // Sane fall back. + Direction = ParamCommandPassDirection::In; // Sane fall back. } } - Command->setDirection((ParamCommandComment::PassDirection)Direction, + Command->setDirection(Direction, /*Explicit=*/true); } @@ -263,7 +263,8 @@ void Sema::actOnParamCommandParamNameArg(ParamCommandComment *Command, if (!Command->isDirectionExplicit()) { // User didn't provide a direction argument. - Command->setDirection(ParamCommandComment::In, /* Explicit = */ false); + Command->setDirection(ParamCommandPassDirection::In, + /* Explicit = */ false); } auto *A = new (Allocator) Comment::Argument{SourceRange(ArgLocBegin, ArgLocEnd), Arg}; diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index cfcf27ecddebb..ace5178bf6258 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -1740,13 +1740,13 @@ void JSONNodeDumper::visitBlockCommandComment( void JSONNodeDumper::visitParamCommandComment( const comments::ParamCommandComment *C, const comments::FullComment *FC) { switch (C->getDirection()) { - case comments::ParamCommandComment::In: + case comments::ParamCommandPassDirection::In: JOS.attribute("direction", "in"); break; - case comments::ParamCommandComment::Out: + case comments::ParamCommandPassDirection::Out: JOS.attribute("direction", "out"); break; - case comments::ParamCommandComment::InOut: + case comments::ParamCommandPassDirection::InOut: JOS.attribute("direction", "in,out"); break; } diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp index e7f5bfebec233..295f3f228ff79 100644 --- a/clang/lib/Index/CommentToXML.cpp +++ b/clang/lib/Index/CommentToXML.cpp @@ -751,13 +751,13 @@ void CommentASTToXMLConverter::visitParamCommandComment( Result << "isDirectionExplicit() << "\">"; switch (C->getDirection()) { - case ParamCommandComment::In: + case ParamCommandPassDirection::In: Result << "in"; break; - case ParamCommandComment::Out: + case ParamCommandPassDirection::Out: Result << "out"; break; - case ParamCommandComment::InOut: + case ParamCommandPassDirection::InOut: Result << "in,out"; break; } diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp index 5abbf9c1161a1..e87efd23578f0 100644 --- a/clang/tools/libclang/CXComment.cpp +++ b/clang/tools/libclang/CXComment.cpp @@ -296,13 +296,13 @@ enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection( return CXCommentParamPassDirection_In; switch (PCC->getDirection()) { - case ParamCommandComment::In: + case ParamCommandPassDirection::In: return CXCommentParamPassDirection_In; - case ParamCommandComment::Out: + case ParamCommandPassDirection::Out: return CXCommentParamPassDirection_Out; - case ParamCommandComment::InOut: + case ParamCommandPassDirection::InOut: return CXCommentParamPassDirection_InOut; } llvm_unreachable("unknown ParamCommandComment::PassDirection"); diff --git a/clang/unittests/AST/CommentParser.cpp b/clang/unittests/AST/CommentParser.cpp index ab2157dcb71b0..1368f56d0f8ed 100644 --- a/clang/unittests/AST/CommentParser.cpp +++ b/clang/unittests/AST/CommentParser.cpp @@ -176,16 +176,11 @@ ::testing::AssertionResult HasBlockCommandAt(const Comment *C, return ::testing::AssertionSuccess(); } -::testing::AssertionResult HasParamCommandAt( - const Comment *C, - const CommandTraits &Traits, - size_t Idx, - ParamCommandComment *&PCC, - StringRef CommandName, - ParamCommandComment::PassDirection Direction, - bool IsDirectionExplicit, - StringRef ParamName, - ParagraphComment *&Paragraph) { +::testing::AssertionResult +HasParamCommandAt(const Comment *C, const CommandTraits &Traits, size_t Idx, + ParamCommandComment *&PCC, StringRef CommandName, + ParamCommandPassDirection Direction, bool IsDirectionExplicit, + StringRef ParamName, ParagraphComment *&Paragraph) { ::testing::AssertionResult AR = GetChildAt(C, Idx, PCC); if (!AR) return AR; @@ -756,10 +751,9 @@ TEST_F(CommentParserTest, ParamCommand1) { { ParamCommandComment *PCC; ParagraphComment *PC; - ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::In, - /* IsDirectionExplicit = */ false, - "aaa", PC)); + ASSERT_TRUE(HasParamCommandAt( + FC, Traits, 1, PCC, "param", ParamCommandPassDirection::In, + /* IsDirectionExplicit = */ false, "aaa", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasChildCount(PC, 0)); } @@ -776,9 +770,8 @@ TEST_F(CommentParserTest, ParamCommand2) { ParamCommandComment *PCC; ParagraphComment *PC; ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::In, - /* IsDirectionExplicit = */ false, - "", PC)); + ParamCommandPassDirection::In, + /* IsDirectionExplicit = */ false, "", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasChildCount(PC, 0)); } @@ -809,10 +802,9 @@ TEST_F(CommentParserTest, ParamCommand3) { { ParamCommandComment *PCC; ParagraphComment *PC; - ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::In, - /* IsDirectionExplicit = */ false, - "aaa", PC)); + ASSERT_TRUE(HasParamCommandAt( + FC, Traits, 1, PCC, "param", ParamCommandPassDirection::In, + /* IsDirectionExplicit = */ false, "aaa", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); } @@ -839,10 +831,9 @@ TEST_F(CommentParserTest, ParamCommand4) { { ParamCommandComment *PCC; ParagraphComment *PC; - ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::In, - /* IsDirectionExplicit = */ true, - "aaa", PC)); + ASSERT_TRUE(HasParamCommandAt( + FC, Traits, 1, PCC, "param", ParamCommandPassDirection::In, + /* IsDirectionExplicit = */ true, "aaa", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); } @@ -869,10 +860,9 @@ TEST_F(CommentParserTest, ParamCommand5) { { ParamCommandComment *PCC; ParagraphComment *PC; - ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::Out, - /* IsDirectionExplicit = */ true, - "aaa", PC)); + ASSERT_TRUE(HasParamCommandAt( + FC, Traits, 1, PCC, "param", ParamCommandPassDirection::Out, + /* IsDirectionExplicit = */ true, "aaa", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); } @@ -900,10 +890,9 @@ TEST_F(CommentParserTest, ParamCommand6) { { ParamCommandComment *PCC; ParagraphComment *PC; - ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::InOut, - /* IsDirectionExplicit = */ true, - "aaa", PC)); + ASSERT_TRUE(HasParamCommandAt( + FC, Traits, 1, PCC, "param", ParamCommandPassDirection::InOut, + /* IsDirectionExplicit = */ true, "aaa", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasParagraphCommentAt(PCC, 0, " Bbb")); } @@ -921,10 +910,9 @@ TEST_F(CommentParserTest, ParamCommand7) { { ParamCommandComment *PCC; ParagraphComment *PC; - ASSERT_TRUE(HasParamCommandAt(FC, Traits, 1, PCC, "param", - ParamCommandComment::In, - /* IsDirectionExplicit = */ false, - "aaa", PC)); + ASSERT_TRUE(HasParamCommandAt( + FC, Traits, 1, PCC, "param", ParamCommandPassDirection::In, + /* IsDirectionExplicit = */ false, "aaa", PC)); ASSERT_TRUE(HasChildCount(PCC, 1)); ASSERT_TRUE(HasChildCount(PC, 5));