[PATCH] D60362: [clang-format] [PR39719] clang-format converting object-like macro to function-like macro

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 17 06:03:51 PDT 2019


MyDeveloperDay added a comment.

@klimek one possible solution to this might be to replace the "keyword" back to an identifier in a  '#define <keywoord>' scenario

Maybe something like this?

  bool FormatTokenLexer::tryConvertKeyWordDefines() {
    // ensure #define keyword x = tok::hash,tok::identifier,tok::identifier
    if (Tokens.size() < 3)
      return false;
  
    auto &Hash = *(Tokens.end() - 3);
    auto &Define = *(Tokens.end() - 2);
    auto &Keyword = *(Tokens.end() - 1);
  
    if (!Hash->is(tok::hash))
      return false;
  
    if (!Define->is(tok::identifier))
      return false;
  
    // Already an identifier
    if (Keyword->is(tok::identifier))
      return false;
  
    if (!Define->Tok.getIdentifierInfo() ||
        Define->Tok.getIdentifierInfo()->getPPKeywordID() != tok::pp_define)
      return false;
  
    // switch the type to be an identifier
    Keyword->Tok.setKind(tok::identifier);
    return true;
  }


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60362/new/

https://reviews.llvm.org/D60362





More information about the cfe-commits mailing list