Path: blob/master/Utilities/ClangTidyModule/UsePragmaOnceCheck.h
3148 views
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying1file LICENSE.rst or https://cmake.org/licensing for details. */23/* This code was originally taken from part of the Clang-Tidy LLVM project and4* modified for use with CMake under the following original license: */56//===--- HeaderGuard.h - clang-tidy -----------------------------*- C++7//-*-===//8//9// Part of the LLVM Project, under the Apache License v2.0 with LLVM10// Exceptions. See https://llvm.org/LICENSE.txt for license information.11// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception12//13//===----------------------------------------------------------------------===//1415#pragma once1617#include <clang-tidy/ClangTidyCheck.h>18#include <clang-tidy/utils/FileExtensionsUtils.h>1920#if LLVM_VERSION_MAJOR >= 1721# include <clang-tidy/FileExtensionsSet.h>22#else23namespace clang {24namespace tidy {25using utils::FileExtensionsSet;26} // namespace tidy27} // namespace clang28#endif2930namespace clang {31namespace tidy {32namespace cmake {3334/// Finds and replaces header guards with pragma once.35/// The check supports these options:36/// - `HeaderFileExtensions`: a semicolon-separated list of filename37/// extensions of header files (The filename extension should not contain38/// "." prefix). ";h;hh;hpp;hxx" by default.39///40/// For extension-less header files, using an empty string or leaving an41/// empty string between ";" if there are other filename extensions.42class UsePragmaOnceCheck : public ClangTidyCheck43{44public:45UsePragmaOnceCheck(StringRef Name, ClangTidyContext* Context)46: ClangTidyCheck(Name, Context)47, RawStringHeaderFileExtensions(Options.getLocalOrGlobal(48"HeaderFileExtensions", utils::defaultHeaderFileExtensions()))49{50utils::parseFileExtensions(RawStringHeaderFileExtensions,51HeaderFileExtensions,52utils::defaultFileExtensionDelimiters());53}54void storeOptions(ClangTidyOptions::OptionMap& Opts) override;55void registerPPCallbacks(SourceManager const& SM, Preprocessor* PP,56Preprocessor* ModuleExpanderPP) override;5758/// Returns ``true`` if the check should add pragma once to the file59/// if it has none.60virtual bool shouldSuggestToAddPragmaOnce(StringRef Filename);6162private:63std::string RawStringHeaderFileExtensions;64FileExtensionsSet HeaderFileExtensions;65};6667} // namespace cmake68} // namespace tidy69} // namespace clang707172