forked from triSYCL/sycl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge from 'master' to 'sycl-web' (triSYCL#3)
CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticSemaKinds.td
- Loading branch information
Showing
1,011 changed files
with
30,656 additions
and
11,397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//===--- ReplaceDisallowCopyAndAssignMacroCheck.cpp - clang-tidy ----------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "ReplaceDisallowCopyAndAssignMacroCheck.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
#include "clang/Lex/MacroArgs.h" | ||
#include "llvm/Support/FormatVariadic.h" | ||
|
||
namespace clang { | ||
namespace tidy { | ||
namespace modernize { | ||
|
||
namespace { | ||
|
||
class ReplaceDisallowCopyAndAssignMacroCallbacks : public PPCallbacks { | ||
public: | ||
explicit ReplaceDisallowCopyAndAssignMacroCallbacks( | ||
ReplaceDisallowCopyAndAssignMacroCheck &Check, Preprocessor &PP) | ||
: Check(Check), PP(PP) {} | ||
|
||
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD, | ||
SourceRange Range, const MacroArgs *Args) override { | ||
IdentifierInfo *Info = MacroNameTok.getIdentifierInfo(); | ||
if (!Info || !Args || Args->getNumMacroArguments() != 1) | ||
return; | ||
if (Info->getName() != Check.getMacroName()) | ||
return; | ||
// The first argument to the DISALLOW_COPY_AND_ASSIGN macro is exptected to | ||
// be the class name. | ||
const Token *ClassNameTok = Args->getUnexpArgument(0); | ||
if (Args->ArgNeedsPreexpansion(ClassNameTok, PP)) | ||
// For now we only support simple argument that don't need to be | ||
// pre-expanded. | ||
return; | ||
clang::IdentifierInfo *ClassIdent = ClassNameTok->getIdentifierInfo(); | ||
if (!ClassIdent) | ||
return; | ||
|
||
std::string Replacement = llvm::formatv( | ||
R"cpp({0}(const {0} &) = delete; | ||
const {0} &operator=(const {0} &) = delete{1})cpp", | ||
ClassIdent->getName(), shouldAppendSemi(Range) ? ";" : ""); | ||
|
||
Check.diag(MacroNameTok.getLocation(), | ||
"prefer deleting copy constructor and assignment operator over " | ||
"using macro '%0'") | ||
<< Check.getMacroName() | ||
<< FixItHint::CreateReplacement( | ||
PP.getSourceManager().getExpansionRange(Range), Replacement); | ||
} | ||
|
||
private: | ||
/// \returns \c true if the next token after the given \p MacroLoc is \b not a | ||
/// semicolon. | ||
bool shouldAppendSemi(SourceRange MacroLoc) { | ||
llvm::Optional<Token> Next = Lexer::findNextToken( | ||
MacroLoc.getEnd(), PP.getSourceManager(), PP.getLangOpts()); | ||
return !(Next && Next->is(tok::semi)); | ||
} | ||
|
||
ReplaceDisallowCopyAndAssignMacroCheck &Check; | ||
Preprocessor &PP; | ||
}; | ||
} // namespace | ||
|
||
ReplaceDisallowCopyAndAssignMacroCheck::ReplaceDisallowCopyAndAssignMacroCheck( | ||
StringRef Name, ClangTidyContext *Context) | ||
: ClangTidyCheck(Name, Context), | ||
MacroName(Options.get("MacroName", "DISALLOW_COPY_AND_ASSIGN")) {} | ||
|
||
void ReplaceDisallowCopyAndAssignMacroCheck::registerPPCallbacks( | ||
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { | ||
PP->addPPCallbacks( | ||
::std::make_unique<ReplaceDisallowCopyAndAssignMacroCallbacks>( | ||
*this, *ModuleExpanderPP)); | ||
} | ||
|
||
void ReplaceDisallowCopyAndAssignMacroCheck::storeOptions( | ||
ClangTidyOptions::OptionMap &Opts) { | ||
Options.store(Opts, "MacroName", MacroName); | ||
} | ||
|
||
} // namespace modernize | ||
} // namespace tidy | ||
} // namespace clang |
62 changes: 62 additions & 0 deletions
62
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//===--- ReplaceDisallowCopyAndAssignMacroCheck.h - clang-tidy --*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H | ||
|
||
#include "../ClangTidyCheck.h" | ||
|
||
namespace clang { | ||
namespace tidy { | ||
namespace modernize { | ||
|
||
/// This check finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and | ||
/// replaces them with a deleted copy constructor and a deleted assignment | ||
/// operator. | ||
/// | ||
/// Before: | ||
/// ~~~{.cpp} | ||
/// class Foo { | ||
/// private: | ||
/// DISALLOW_COPY_AND_ASSIGN(Foo); | ||
/// }; | ||
/// ~~~ | ||
/// | ||
/// After: | ||
/// ~~~{.cpp} | ||
/// class Foo { | ||
/// private: | ||
/// Foo(const Foo &) = delete; | ||
/// const Foo &operator=(const Foo &) = delete; | ||
/// }; | ||
/// ~~~ | ||
/// | ||
/// For the user-facing documentation see: | ||
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.html | ||
class ReplaceDisallowCopyAndAssignMacroCheck : public ClangTidyCheck { | ||
public: | ||
ReplaceDisallowCopyAndAssignMacroCheck(StringRef Name, | ||
ClangTidyContext *Context); | ||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { | ||
return LangOpts.CPlusPlus11; | ||
} | ||
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, | ||
Preprocessor *ModuleExpanderPP) override; | ||
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; | ||
|
||
const std::string &getMacroName() const { return MacroName; } | ||
|
||
private: | ||
const std::string MacroName; | ||
}; | ||
|
||
} // namespace modernize | ||
} // namespace tidy | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.