Commit 565e21b3 authored by Vlad Serebrennikov's avatar Vlad Serebrennikov
Browse files

[clang][NFC] Refactor `InlineCommandComment::RenderKind`

This patch converts `InlineCommandComment::RenderKind` to a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`.
parent 609fe2cb
Loading
Loading
Loading
Loading
+9 −15
Original line number Diff line number Diff line
@@ -297,31 +297,24 @@ private:
  bool isWhitespaceNoCache() const;
};

/// A command with word-like arguments that is considered inline content.
class InlineCommandComment : public InlineContentComment {
public:
/// The most appropriate rendering mode for this command, chosen on command
/// semantics in Doxygen.
  enum RenderKind {
    RenderNormal,
    RenderBold,
    RenderMonospaced,
    RenderEmphasized,
    RenderAnchor
  };
enum InlineCommandRenderKind { Normal, Bold, Monospaced, Emphasized, Anchor };

/// A command with word-like arguments that is considered inline content.
class InlineCommandComment : public InlineContentComment {
protected:
  /// Command arguments.
  ArrayRef<Argument> Args;

public:
  InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd,
                       unsigned CommandID, RenderKind RK,
                       unsigned CommandID, InlineCommandRenderKind RK,
                       ArrayRef<Argument> Args)
      : InlineContentComment(CommentKind::InlineCommandComment, LocBegin,
                             LocEnd),
        Args(Args) {
    InlineCommandCommentBits.RenderKind = RK;
    InlineCommandCommentBits.RenderKind = llvm::to_underlying(RK);
    InlineCommandCommentBits.CommandID = CommandID;
  }

@@ -345,8 +338,9 @@ public:
    return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc());
  }

  RenderKind getRenderKind() const {
    return static_cast<RenderKind>(InlineCommandCommentBits.RenderKind);
  InlineCommandRenderKind getRenderKind() const {
    return static_cast<InlineCommandRenderKind>(
        InlineCommandCommentBits.RenderKind);
  }

  unsigned getNumArgs() const {
+1 −2
Original line number Diff line number Diff line
@@ -244,8 +244,7 @@ private:
                              StringRef Typo,
                              const TemplateParameterList *TemplateParameters);

  InlineCommandComment::RenderKind
  getInlineCommandRenderKind(StringRef Name) const;
  InlineCommandRenderKind getInlineCommandRenderKind(StringRef Name) const;
};

} // end namespace comments
+8 −11
Original line number Diff line number Diff line
@@ -380,9 +380,7 @@ InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
                                                unsigned CommandID) {
  ArrayRef<InlineCommandComment::Argument> Args;
  return new (Allocator) InlineCommandComment(
                                  LocBegin, LocEnd, CommandID,
                                  InlineCommandComment::RenderNormal,
                                  Args);
      LocBegin, LocEnd, CommandID, InlineCommandRenderKind::Normal, Args);
}

TextComment *Sema::actOnText(SourceLocation LocBegin,
@@ -1108,16 +1106,15 @@ StringRef Sema::correctTypoInTParamReference(
  return StringRef();
}

InlineCommandComment::RenderKind
Sema::getInlineCommandRenderKind(StringRef Name) const {
InlineCommandRenderKind Sema::getInlineCommandRenderKind(StringRef Name) const {
  assert(Traits.getCommandInfo(Name)->IsInlineCommand);

  return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
      .Case("b", InlineCommandComment::RenderBold)
      .Cases("c", "p", InlineCommandComment::RenderMonospaced)
      .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
      .Case("anchor", InlineCommandComment::RenderAnchor)
      .Default(InlineCommandComment::RenderNormal);
  return llvm::StringSwitch<InlineCommandRenderKind>(Name)
      .Case("b", InlineCommandRenderKind::Bold)
      .Cases("c", "p", InlineCommandRenderKind::Monospaced)
      .Cases("a", "e", "em", InlineCommandRenderKind::Emphasized)
      .Case("anchor", InlineCommandRenderKind::Anchor)
      .Default(InlineCommandRenderKind::Normal);
}

} // end namespace comments
+5 −5
Original line number Diff line number Diff line
@@ -1680,19 +1680,19 @@ void JSONNodeDumper::visitInlineCommandComment(
  JOS.attribute("name", getCommentCommandName(C->getCommandID()));

  switch (C->getRenderKind()) {
  case comments::InlineCommandComment::RenderNormal:
  case comments::InlineCommandRenderKind::Normal:
    JOS.attribute("renderKind", "normal");
    break;
  case comments::InlineCommandComment::RenderBold:
  case comments::InlineCommandRenderKind::Bold:
    JOS.attribute("renderKind", "bold");
    break;
  case comments::InlineCommandComment::RenderEmphasized:
  case comments::InlineCommandRenderKind::Emphasized:
    JOS.attribute("renderKind", "emphasized");
    break;
  case comments::InlineCommandComment::RenderMonospaced:
  case comments::InlineCommandRenderKind::Monospaced:
    JOS.attribute("renderKind", "monospaced");
    break;
  case comments::InlineCommandComment::RenderAnchor:
  case comments::InlineCommandRenderKind::Anchor:
    JOS.attribute("renderKind", "anchor");
    break;
  }
+5 −5
Original line number Diff line number Diff line
@@ -862,19 +862,19 @@ void TextNodeDumper::visitInlineCommandComment(
    const comments::InlineCommandComment *C, const comments::FullComment *) {
  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
  switch (C->getRenderKind()) {
  case comments::InlineCommandComment::RenderNormal:
  case comments::InlineCommandRenderKind::Normal:
    OS << " RenderNormal";
    break;
  case comments::InlineCommandComment::RenderBold:
  case comments::InlineCommandRenderKind::Bold:
    OS << " RenderBold";
    break;
  case comments::InlineCommandComment::RenderMonospaced:
  case comments::InlineCommandRenderKind::Monospaced:
    OS << " RenderMonospaced";
    break;
  case comments::InlineCommandComment::RenderEmphasized:
  case comments::InlineCommandRenderKind::Emphasized:
    OS << " RenderEmphasized";
    break;
  case comments::InlineCommandComment::RenderAnchor:
  case comments::InlineCommandRenderKind::Anchor:
    OS << " RenderAnchor";
    break;
  }
Loading