• Home
  • History
  • Annotate
  • Raw
  • Download

Lines Matching +full:argument +full:- +full:count

1 //===--- MacroParenthesesCheck.cpp - clang-tidy----------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
26 replacementList(MacroNameTok, MD->getMacroInfo()); in MacroDefined()
27 argument(MacroNameTok, MD->getMacroInfo()); in MacroDefined()
35 void argument(const Token &MacroNameTok, const MacroInfo *MI);
42 /// Is argument surrounded properly with parentheses/braces/squares/commas?
48 /// Is argument surrounded properly with parentheses/braces/squares/commas?
78 if (Tok == MI->tokens_end()) in possibleVarDecl()
87 if (!Tok->isOneOf(tok::identifier, tok::raw_identifier, tok::coloncolon)) in possibleVarDecl()
91 while (Tok != MI->tokens_end() && in possibleVarDecl()
92 Tok->isOneOf(tok::identifier, tok::raw_identifier, tok::coloncolon, in possibleVarDecl()
98 return Tok == MI->tokens_end() || in possibleVarDecl()
99 Tok->isOneOf(tok::equal, tok::semi, tok::l_square, tok::l_paren) || in possibleVarDecl()
106 if (possibleVarDecl(MI, MI->tokens_begin())) in replacementList()
109 // Count how deep we are in parentheses/braces/squares. in replacementList()
110 int Count = 0; in replacementList() local
115 for (auto TI = MI->tokens_begin(), TE = MI->tokens_end(); TI != TE; ++TI) { in replacementList()
121 if (Count == 0 && Tok.isOneOf(tok::comma, tok::semi)) in replacementList()
124 ++Count; in replacementList()
126 --Count; in replacementList()
128 if (Count < 0) in replacementList()
130 } else if (Count == 0 && isWarnOp(Tok)) { in replacementList()
134 if (TI == MI->tokens_begin() && (TI + 1) != TE && in replacementList()
139 if ((TE - 1)->is(tok::star)) in replacementList()
146 const Token &Last = *(MI->tokens_end() - 1); in replacementList()
147 Check->diag(Loc, "macro replacement list should be enclosed in parentheses") in replacementList()
148 << FixItHint::CreateInsertion(MI->tokens_begin()->getLocation(), "(") in replacementList()
150 PP->getSpelling(Last).length()), in replacementList()
155 void MacroParenthesesPPCallbacks::argument(const Token &MacroNameTok, in argument() function in clang::tidy::bugprone::MacroParenthesesPPCallbacks
159 bool VarDecl = possibleVarDecl(MI, MI->tokens_begin()); in argument()
161 for (auto TI = MI->tokens_begin(), TE = MI->tokens_end(); TI != TE; ++TI) { in argument()
163 if (TI == MI->tokens_begin()) in argument()
167 if ((TI + 1) == MI->tokens_end()) in argument()
170 const Token &Prev = *(TI - 1); in argument()
187 if (MI->getParameterNum(Tok.getIdentifierInfo()) < 0) in argument()
190 // Argument is surrounded with parentheses/squares/braces/commas. in argument()
198 // Argument is a struct member. in argument()
203 // Argument is a namespace or class. in argument()
222 TI + 2 != MI->tokens_end() && (TI + 2)->is(tok::r_paren)) in argument()
230 if (PP->getLangOpts().CPlusPlus && Prev.isOneOf(tok::comma, tok::less) && in argument()
239 if (MI->isVariadic()) in argument()
242 Check->diag(Tok.getLocation(), "macro argument should be enclosed in " in argument()
246 PP->getSpelling(Tok).length()), in argument()
253 PP->addPPCallbacks(std::make_unique<MacroParenthesesPPCallbacks>(PP, this)); in registerPPCallbacks()