[Basic] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

llvm-svn: 325412
This commit is contained in:
Eugene Zelenko 2018-02-16 23:40:07 +00:00
parent 769134dac3
commit 25cae5a21f
10 changed files with 342 additions and 216 deletions

View File

@ -1,4 +1,4 @@
//===--- Diagnostic.h - C Language Family Diagnostic Handling ---*- C++ -*-===//
//===- Diagnostic.h - C Language Family Diagnostic Handling -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
//
/// \file
/// \brief Defines the Diagnostic-related interfaces.
///
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H
@ -22,12 +22,13 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <algorithm>
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstdint>
#include <limits>
#include <list>
#include <map>
#include <memory>
@ -44,13 +45,14 @@ class DiagnosticConsumer;
class IdentifierInfo;
class LangOptions;
class Preprocessor;
class SourceManager;
class StoredDiagnostic;
namespace tok {
enum TokenKind : unsigned short;
enum TokenKind : unsigned short;
} // end namespace tok
} // namespace tok
/// \brief Annotates a diagnostic with some code that should be
/// inserted, removed, or replaced to fix the problem.
@ -75,11 +77,11 @@ public:
/// string.
std::string CodeToInsert;
bool BeforePreviousInsertions;
bool BeforePreviousInsertions = false;
/// \brief Empty code modification hint, indicating that no code
/// modification is known.
FixItHint() : BeforePreviousInsertions(false) { }
FixItHint() = default;
bool isNull() const {
return !RemoveRange.isValid();
@ -157,43 +159,86 @@ public:
};
enum ArgumentKind {
ak_std_string, ///< std::string
ak_c_string, ///< const char *
ak_sint, ///< int
ak_uint, ///< unsigned
ak_tokenkind, ///< enum TokenKind : unsigned
ak_identifierinfo, ///< IdentifierInfo
ak_qualtype, ///< QualType
ak_declarationname, ///< DeclarationName
ak_nameddecl, ///< NamedDecl *
ak_nestednamespec, ///< NestedNameSpecifier *
ak_declcontext, ///< DeclContext *
ak_qualtype_pair, ///< pair<QualType, QualType>
ak_attr ///< Attr *
/// std::string
ak_std_string,
/// const char *
ak_c_string,
/// int
ak_sint,
/// unsigned
ak_uint,
/// enum TokenKind : unsigned
ak_tokenkind,
/// IdentifierInfo
ak_identifierinfo,
/// QualType
ak_qualtype,
/// DeclarationName
ak_declarationname,
/// NamedDecl *
ak_nameddecl,
/// NestedNameSpecifier *
ak_nestednamespec,
/// DeclContext *
ak_declcontext,
/// pair<QualType, QualType>
ak_qualtype_pair,
/// Attr *
ak_attr
};
/// \brief Represents on argument value, which is a union discriminated
/// by ArgumentKind, with a value.
typedef std::pair<ArgumentKind, intptr_t> ArgumentValue;
using ArgumentValue = std::pair<ArgumentKind, intptr_t>;
private:
unsigned char AllExtensionsSilenced; // Used by __extension__
bool SuppressAfterFatalError; // Suppress diagnostics after a fatal error?
bool SuppressAllDiagnostics; // Suppress all diagnostics.
bool ElideType; // Elide common types of templates.
bool PrintTemplateTree; // Print a tree when comparing templates.
bool ShowColors; // Color printing is enabled.
OverloadsShown ShowOverloads; // Which overload candidates to show.
unsigned ErrorLimit; // Cap of # errors emitted, 0 -> no limit.
unsigned TemplateBacktraceLimit; // Cap on depth of template backtrace stack,
// 0 -> no limit.
unsigned ConstexprBacktraceLimit; // Cap on depth of constexpr evaluation
// backtrace stack, 0 -> no limit.
// Used by __extension__
unsigned char AllExtensionsSilenced = 0;
// Suppress diagnostics after a fatal error?
bool SuppressAfterFatalError = true;
// Suppress all diagnostics.
bool SuppressAllDiagnostics = false;
// Elide common types of templates.
bool ElideType = true;
// Print a tree when comparing templates.
bool PrintTemplateTree = false;
// Color printing is enabled.
bool ShowColors = false;
// Which overload candidates to show.
OverloadsShown ShowOverloads = Ovl_All;
// Cap of # errors emitted, 0 -> no limit.
unsigned ErrorLimit = 0;
// Cap on depth of template backtrace stack, 0 -> no limit.
unsigned TemplateBacktraceLimit = 0;
// Cap on depth of constexpr evaluation backtrace stack, 0 -> no limit.
unsigned ConstexprBacktraceLimit = 0;
IntrusiveRefCntPtr<DiagnosticIDs> Diags;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
DiagnosticConsumer *Client;
DiagnosticConsumer *Client = nullptr;
std::unique_ptr<DiagnosticConsumer> Owner;
SourceManager *SourceMgr;
SourceManager *SourceMgr = nullptr;
/// \brief Mapping information for diagnostics.
///
@ -211,25 +256,38 @@ private:
public:
// "Global" configuration state that can actually vary between modules.
unsigned IgnoreAllWarnings : 1; // Ignore all warnings: -w
unsigned EnableAllWarnings : 1; // Enable all warnings.
unsigned WarningsAsErrors : 1; // Treat warnings like errors.
unsigned ErrorsAsFatal : 1; // Treat errors like fatal errors.
unsigned SuppressSystemWarnings : 1; // Suppress warnings in system headers.
diag::Severity ExtBehavior; // Map extensions to warnings or errors?
// Ignore all warnings: -w
unsigned IgnoreAllWarnings : 1;
// Enable all warnings.
unsigned EnableAllWarnings : 1;
// Treat warnings like errors.
unsigned WarningsAsErrors : 1;
// Treat errors like fatal errors.
unsigned ErrorsAsFatal : 1;
// Suppress warnings in system headers.
unsigned SuppressSystemWarnings : 1;
// Map extensions to warnings or errors?
diag::Severity ExtBehavior = diag::Severity::Ignored;
DiagState()
: IgnoreAllWarnings(false), EnableAllWarnings(false),
WarningsAsErrors(false), ErrorsAsFatal(false),
SuppressSystemWarnings(false), ExtBehavior(diag::Severity::Ignored) {}
SuppressSystemWarnings(false) {}
typedef llvm::DenseMap<unsigned, DiagnosticMapping>::iterator iterator;
typedef llvm::DenseMap<unsigned, DiagnosticMapping>::const_iterator
const_iterator;
using iterator = llvm::DenseMap<unsigned, DiagnosticMapping>::iterator;
using const_iterator =
llvm::DenseMap<unsigned, DiagnosticMapping>::const_iterator;
void setMapping(diag::kind Diag, DiagnosticMapping Info) {
DiagMap[Diag] = Info;
}
DiagnosticMapping lookupMapping(diag::kind Diag) const {
return DiagMap.lookup(Diag);
}
@ -249,12 +307,16 @@ private:
public:
/// Add an initial diagnostic state.
void appendFirst(DiagState *State);
/// Add a new latest state point.
void append(SourceManager &SrcMgr, SourceLocation Loc, DiagState *State);
/// Look up the diagnostic state at a given source location.
DiagState *lookup(SourceManager &SrcMgr, SourceLocation Loc) const;
/// Determine whether this map is empty.
bool empty() const { return Files.empty(); }
/// Clear out this map.
void clear() {
Files.clear();
@ -268,10 +330,14 @@ private:
/// Grab the most-recently-added state point.
DiagState *getCurDiagState() const { return CurDiagState; }
/// Get the location at which a diagnostic state was last added.
SourceLocation getCurDiagStateLoc() const { return CurDiagStateLoc; }
private:
friend class ASTReader;
friend class ASTWriter;
/// \brief Represents a point in source where the diagnostic state was
/// modified because of a pragma.
///
@ -280,8 +346,9 @@ private:
struct DiagStatePoint {
DiagState *State;
unsigned Offset;
DiagStatePoint(DiagState *State, unsigned Offset)
: State(State), Offset(Offset) { }
: State(State), Offset(Offset) {}
};
/// Description of the diagnostic states and state transitions for a
@ -291,11 +358,14 @@ private:
/// as looking up the DecomposedIncludedLoc for the FileID in the Files
/// map would give us this, but we cache it here for performance.
File *Parent = nullptr;
/// The offset of this file within its parent.
unsigned ParentOffset = 0;
/// Whether this file has any local (not imported from an AST file)
/// diagnostic state transitions.
bool HasLocalTransitions = false;
/// The points within the file where the state changes. There will always
/// be at least one of these (the state on entry to the file).
llvm::SmallVector<DiagStatePoint, 4> StateTransitions;
@ -308,16 +378,15 @@ private:
/// The initial diagnostic state.
DiagState *FirstDiagState;
/// The current diagnostic state.
DiagState *CurDiagState;
/// The location at which the current diagnostic state was established.
SourceLocation CurDiagStateLoc;
/// Get the diagnostic state information for a file.
File *getFile(SourceManager &SrcMgr, FileID ID) const;
friend class ASTReader;
friend class ASTWriter;
};
DiagStateMap DiagStatesByLoc;
@ -363,8 +432,11 @@ private:
/// diagnostic that they follow.
DiagnosticIDs::Level LastDiagLevel;
unsigned NumWarnings; ///< Number of warnings reported
unsigned NumErrors; ///< Number of errors reported
/// Number of warnings reported
unsigned NumWarnings;
/// Number of errors reported
unsigned NumErrors;
/// \brief A function pointer that converts an opaque diagnostic
/// argument to a strings.
@ -376,14 +448,15 @@ private:
/// avoid redundancy across arguments.
///
/// This is a hack to avoid a layering violation between libbasic and libsema.
typedef void (*ArgToStringFnTy)(
using ArgToStringFnTy = void (*)(
ArgumentKind Kind, intptr_t Val,
StringRef Modifier, StringRef Argument,
ArrayRef<ArgumentValue> PrevArgs,
SmallVectorImpl<char> &Output,
void *Cookie,
ArrayRef<intptr_t> QualTypeVals);
void *ArgToStringCookie;
void *ArgToStringCookie = nullptr;
ArgToStringFnTy ArgToStringFn;
/// \brief ID of the "delayed" diagnostic, which is a (typically
@ -425,7 +498,7 @@ public:
/// \brief Retrieve the diagnostic options.
DiagnosticOptions &getDiagnosticOptions() const { return *DiagOpts; }
typedef llvm::iterator_range<DiagState::const_iterator> diag_mapping_range;
using diag_mapping_range = llvm::iterator_range<DiagState::const_iterator>;
/// \brief Get the current set of diagnostic mappings.
diag_mapping_range getDiagnosticMappings() const {
@ -444,10 +517,12 @@ public:
std::unique_ptr<DiagnosticConsumer> takeClient() { return std::move(Owner); }
bool hasSourceManager() const { return SourceMgr != nullptr; }
SourceManager &getSourceManager() const {
assert(SourceMgr && "SourceManager not set!");
return *SourceMgr;
}
void setSourceManager(SourceManager *SrcMgr) {
assert(DiagStatesByLoc.empty() &&
"Leftover diag state from a different SourceManager.");
@ -773,7 +848,9 @@ public:
void Report(const StoredDiagnostic &storedDiag);
/// \brief Determine whethere there is already a diagnostic in flight.
bool isDiagnosticInFlight() const { return CurDiagID != ~0U; }
bool isDiagnosticInFlight() const {
return CurDiagID != std::numeric_limits<unsigned>::max();
}
/// \brief Set the "delayed" diagnostic that will be emitted once
/// the current diagnostic completes.
@ -800,33 +877,34 @@ public:
StringRef Arg2 = "");
/// \brief Clear out the current diagnostic.
void Clear() { CurDiagID = ~0U; }
void Clear() { CurDiagID = std::numeric_limits<unsigned>::max(); }
/// \brief Return the value associated with this diagnostic flag.
StringRef getFlagValue() const { return FlagValue; }
private:
/// \brief Report the delayed diagnostic.
void ReportDelayed();
// This is private state used by DiagnosticBuilder. We put it here instead of
// in DiagnosticBuilder in order to keep DiagnosticBuilder a small lightweight
// object. This implementation choice means that we can only have one
// diagnostic "in flight" at a time, but this seems to be a reasonable
// tradeoff to keep these objects small. Assertions verify that only one
// diagnostic is in flight at a time.
friend class DiagnosticIDs;
friend class DiagnosticBuilder;
friend class Diagnostic;
friend class PartialDiagnostic;
friend class DiagnosticBuilder;
friend class DiagnosticErrorTrap;
friend class DiagnosticIDs;
friend class PartialDiagnostic;
/// \brief Report the delayed diagnostic.
void ReportDelayed();
/// \brief The location of the current diagnostic that is in flight.
SourceLocation CurDiagLoc;
/// \brief The ID of the current diagnostic that is in flight.
///
/// This is set to ~0U when there is no diagnostic in flight.
/// This is set to std::numeric_limits<unsigned>::max() when there is no
/// diagnostic in flight.
unsigned CurDiagID;
enum {
@ -893,6 +971,9 @@ private:
/// @name Diagnostic Emission
/// @{
protected:
friend class ASTReader;
friend class ASTWriter;
// Sema requires access to the following functions because the current design
// of SFINAE requires it to use its own SemaDiagnosticBuilder, which needs to
// access us directly to ensure we minimize the emitted code for the common
@ -909,9 +990,6 @@ protected:
SourceLocation getCurrentDiagLoc() const { return CurDiagLoc; }
/// @}
friend class ASTReader;
friend class ASTWriter;
};
/// \brief RAII class that determines when any errors have occurred
@ -924,7 +1002,7 @@ class DiagnosticErrorTrap {
public:
explicit DiagnosticErrorTrap(DiagnosticsEngine &Diag)
: Diag(Diag) { reset(); }
: Diag(Diag) { reset(); }
/// \brief Determine whether any errors have occurred since this
/// object instance was created.
@ -962,6 +1040,9 @@ public:
/// the common fields to registers, eliminating increments of the NumArgs field,
/// for example.
class DiagnosticBuilder {
friend class DiagnosticsEngine;
friend class PartialDiagnostic;
mutable DiagnosticsEngine *DiagObj = nullptr;
mutable unsigned NumArgs = 0;
@ -976,8 +1057,6 @@ class DiagnosticBuilder {
/// call to ForceEmit.
mutable bool IsForceEmit = false;
friend class DiagnosticsEngine;
DiagnosticBuilder() = default;
explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
@ -987,8 +1066,6 @@ class DiagnosticBuilder {
diagObj->DiagFixItHints.clear();
}
friend class PartialDiagnostic;
protected:
void FlushCounts() {
DiagObj->NumDiagArgs = NumArgs;
@ -1049,7 +1126,7 @@ public:
/// \brief Retrieve an empty diagnostic builder.
static DiagnosticBuilder getEmpty() {
return DiagnosticBuilder();
return {};
}
/// \brief Forces the diagnostic to be emitted.
@ -1098,8 +1175,9 @@ public:
};
struct AddFlagValue {
explicit AddFlagValue(StringRef V) : Val(V) {}
StringRef Val;
explicit AddFlagValue(StringRef V) : Val(V) {}
};
/// \brief Register a value for the flag in the current diagnostic. This
@ -1208,14 +1286,15 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
/// A nullability kind paired with a bit indicating whether it used a
/// context-sensitive keyword.
typedef std::pair<NullabilityKind, bool> DiagNullabilityKind;
using DiagNullabilityKind = std::pair<NullabilityKind, bool>;
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
DiagNullabilityKind nullability);
inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
unsigned DiagID) {
assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
assert(CurDiagID == std::numeric_limits<unsigned>::max() &&
"Multiple diagnostics in flight at once!");
CurDiagLoc = Loc;
CurDiagID = DiagID;
FlagValue.clear();
@ -1240,7 +1319,7 @@ class Diagnostic {
public:
explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}
Diagnostic(const DiagnosticsEngine *DO, StringRef storedDiagMessage)
: DiagObj(DO), StoredDiagMessage(storedDiagMessage) {}
: DiagObj(DO), StoredDiagMessage(storedDiagMessage) {}
const DiagnosticsEngine *getDiags() const { return DiagObj; }
unsigned getID() const { return DiagObj->CurDiagID; }
@ -1382,7 +1461,8 @@ public:
void setLocation(FullSourceLoc Loc) { this->Loc = Loc; }
typedef std::vector<CharSourceRange>::const_iterator range_iterator;
using range_iterator = std::vector<CharSourceRange>::const_iterator;
range_iterator range_begin() const { return Ranges.begin(); }
range_iterator range_end() const { return Ranges.end(); }
unsigned range_size() const { return Ranges.size(); }
@ -1391,7 +1471,8 @@ public:
return llvm::makeArrayRef(Ranges);
}
typedef std::vector<FixItHint>::const_iterator fixit_iterator;
using fixit_iterator = std::vector<FixItHint>::const_iterator;
fixit_iterator fixit_begin() const { return FixIts.begin(); }
fixit_iterator fixit_end() const { return FixIts.end(); }
unsigned fixit_size() const { return FixIts.size(); }
@ -1410,7 +1491,6 @@ protected:
public:
DiagnosticConsumer() = default;
virtual ~DiagnosticConsumer();
unsigned getNumErrors() const { return NumErrors; }
@ -1476,7 +1556,6 @@ class ForwardingDiagnosticConsumer : public DiagnosticConsumer {
public:
ForwardingDiagnosticConsumer(DiagnosticConsumer &Target) : Target(Target) {}
~ForwardingDiagnosticConsumer() override;
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
@ -1494,6 +1573,7 @@ struct TemplateDiffTypes {
unsigned PrintFromType : 1;
unsigned ElideType : 1;
unsigned ShowColors : 1;
// The printer sets this variable to true if the template diff was used.
unsigned TemplateDiffUsed : 1;
};
@ -1502,13 +1582,12 @@ struct TemplateDiffTypes {
/// attribute. The character itself will be not be printed.
const char ToggleHighlight = 127;
/// ProcessWarningOptions - Initialize the diagnostic client and process the
/// warning options specified on the command line.
void ProcessWarningOptions(DiagnosticsEngine &Diags,
const DiagnosticOptions &Opts,
bool ReportDiags = true);
} // end namespace clang
} // namespace clang
#endif // LLVM_CLANG_BASIC_DIAGNOSTIC_H

View File

@ -1,4 +1,4 @@
//===--- DiagnosticOptions.h ------------------------------------*- C++ -*-===//
//===- DiagnosticOptions.h --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -21,8 +21,11 @@ namespace clang {
/// \brief Specifies which overload candidates to display when overload
/// resolution fails.
enum OverloadsShown : unsigned {
Ovl_All, ///< Show all overloads.
Ovl_Best ///< Show just the "best" overload candidates.
/// Show all overloads.
Ovl_All,
/// Show just the "best" overload candidates.
Ovl_Best
};
/// \brief A bitmask representing the diagnostic levels used by
@ -119,8 +122,8 @@ public:
}
};
typedef DiagnosticOptions::TextDiagnosticFormat TextDiagnosticFormat;
using TextDiagnosticFormat = DiagnosticOptions::TextDiagnosticFormat;
} // end namespace clang
} // namespace clang
#endif
#endif // LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H

View File

@ -1,4 +1,4 @@
//===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
//===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -6,10 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
//
/// \file
/// \brief Defines the clang::LangOptions interface.
///
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
@ -20,6 +20,8 @@
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Basic/Visibility.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include <string>
#include <vector>
@ -47,22 +49,32 @@ protected:
/// enabled, which controls the dialect of C or C++ that is accepted.
class LangOptions : public LangOptionsBase {
public:
typedef clang::Visibility Visibility;
using Visibility = clang::Visibility;
enum GCMode { NonGC, GCOnly, HybridGC };
enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
enum SignedOverflowBehaviorTy {
SOB_Undefined, // Default C standard behavior.
SOB_Defined, // -fwrapv
SOB_Trapping // -ftrapv
// Default C standard behavior.
SOB_Undefined,
// -fwrapv
SOB_Defined,
// -ftrapv
SOB_Trapping
};
// FIXME: Unify with TUKind.
enum CompilingModuleKind {
CMK_None, ///< Not compiling a module interface at all.
CMK_ModuleMap, ///< Compiling a module from a module map.
CMK_ModuleInterface ///< Compiling a C++ modules TS module interface unit.
/// Not compiling a module interface at all.
CMK_None,
/// Compiling a module from a module map.
CMK_ModuleMap,
/// Compiling a C++ modules TS module interface unit.
CMK_ModuleInterface
};
enum PragmaMSPointersToMembersKind {
@ -91,9 +103,14 @@ public:
};
enum FPContractModeKind {
FPC_Off, // Form fused FP ops only where result will not be affected.
FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
// Form fused FP ops only where result will not be affected.
FPC_Off,
// Form fused FP ops according to FP_CONTRACT rules.
FPC_On,
// Aggressively fuse FP ops (E.g. FMA).
FPC_Fast
};
public:
@ -152,7 +169,7 @@ public:
/// \brief Indicates whether the front-end is explicitly told that the
/// input is a header file (i.e. -x c-header).
bool IsHeaderFile;
bool IsHeaderFile = false;
LangOptions();
@ -219,15 +236,19 @@ public:
bool allowFPContractWithinStatement() const {
return fp_contract == LangOptions::FPC_On;
}
bool allowFPContractAcrossStatement() const {
return fp_contract == LangOptions::FPC_Fast;
}
void setAllowFPContractWithinStatement() {
fp_contract = LangOptions::FPC_On;
}
void setAllowFPContractAcrossStatement() {
fp_contract = LangOptions::FPC_Fast;
}
void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
/// Used to serialize this.
@ -242,13 +263,15 @@ private:
enum TranslationUnitKind {
/// \brief The translation unit is a complete translation unit.
TU_Complete,
/// \brief The translation unit is a prefix to a translation unit, and is
/// not complete.
TU_Prefix,
/// \brief The translation unit is a module.
TU_Module
};
} // end namespace clang
} // namespace clang
#endif
#endif // LLVM_CLANG_BASIC_LANGOPTIONS_H

View File

@ -1,4 +1,4 @@
//===--- PartialDiagnostic.h - Diagnostic "closures" ------------*- C++ -*-===//
//===- PartialDiagnostic.h - Diagnostic "closures" --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -6,25 +6,32 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
//
/// \file
/// \brief Implements a partial diagnostic that can be emitted anwyhere
/// in a DiagnosticBuilder stream.
///
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H
#define LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <cstdint>
#include <string>
#include <type_traits>
#include <utility>
namespace clang {
class DeclContext;
class IdentifierInfo;
class PartialDiagnostic {
public:
enum {
@ -36,8 +43,6 @@ public:
};
struct Storage {
Storage() : NumDiagArgs(0) { }
enum {
/// \brief The maximum number of arguments we can hold. We
/// currently only support up to 10 arguments (%0-%9).
@ -48,7 +53,7 @@ public:
};
/// \brief The number of entries in Arguments.
unsigned char NumDiagArgs;
unsigned char NumDiagArgs = 0;
/// \brief Specifies for each argument whether it is in DiagArgumentsStr
/// or in DiagArguments.
@ -71,6 +76,8 @@ public:
/// \brief If valid, provides a hint with some code to insert, remove, or
/// modify at a particular position.
SmallVector<FixItHint, 6> FixItHints;
Storage() = default;
};
/// \brief An allocator for Storage objects, which uses a small cache to
@ -114,13 +121,13 @@ private:
// in the new location.
/// \brief The diagnostic ID.
mutable unsigned DiagID;
mutable unsigned DiagID = 0;
/// \brief Storage for args and ranges.
mutable Storage *DiagStorage;
mutable Storage *DiagStorage = nullptr;
/// \brief Allocator used to allocate storage for this diagnostic.
StorageAllocator *Allocator;
StorageAllocator *Allocator = nullptr;
/// \brief Retrieve storage for this particular diagnostic.
Storage *getStorage() const {
@ -176,17 +183,16 @@ private:
public:
struct NullDiagnostic {};
/// \brief Create a null partial diagnostic, which cannot carry a payload,
/// and only exists to be swapped with a real partial diagnostic.
PartialDiagnostic(NullDiagnostic)
: DiagID(0), DiagStorage(nullptr), Allocator(nullptr) { }
PartialDiagnostic(NullDiagnostic) {}
PartialDiagnostic(unsigned DiagID, StorageAllocator &Allocator)
: DiagID(DiagID), DiagStorage(nullptr), Allocator(&Allocator) { }
: DiagID(DiagID), Allocator(&Allocator) {}
PartialDiagnostic(const PartialDiagnostic &Other)
: DiagID(Other.DiagID), DiagStorage(nullptr), Allocator(Other.Allocator)
{
: DiagID(Other.DiagID), Allocator(Other.Allocator) {
if (Other.DiagStorage) {
DiagStorage = getStorage();
*DiagStorage = *Other.DiagStorage;
@ -194,22 +200,20 @@ public:
}
PartialDiagnostic(PartialDiagnostic &&Other)
: DiagID(Other.DiagID), DiagStorage(Other.DiagStorage),
Allocator(Other.Allocator) {
: DiagID(Other.DiagID), DiagStorage(Other.DiagStorage),
Allocator(Other.Allocator) {
Other.DiagStorage = nullptr;
}
PartialDiagnostic(const PartialDiagnostic &Other, Storage *DiagStorage)
: DiagID(Other.DiagID), DiagStorage(DiagStorage),
Allocator(reinterpret_cast<StorageAllocator *>(~uintptr_t(0)))
{
: DiagID(Other.DiagID), DiagStorage(DiagStorage),
Allocator(reinterpret_cast<StorageAllocator *>(~uintptr_t(0))) {
if (Other.DiagStorage)
*this->DiagStorage = *Other.DiagStorage;
}
PartialDiagnostic(const Diagnostic &Other, StorageAllocator &Allocator)
: DiagID(Other.getID()), DiagStorage(nullptr), Allocator(&Allocator)
{
: DiagID(Other.getID()), Allocator(&Allocator) {
// Copy arguments.
for (unsigned I = 0, N = Other.getNumArgs(); I != N; ++I) {
if (Other.getArgKind(I) == DiagnosticsEngine::ak_std_string)
@ -402,7 +406,6 @@ public:
PD.AddFixItHint(Hint);
return PD;
}
};
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
@ -413,7 +416,8 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
/// \brief A partial diagnostic along with the source location where this
/// diagnostic occurs.
typedef std::pair<SourceLocation, PartialDiagnostic> PartialDiagnosticAt;
using PartialDiagnosticAt = std::pair<SourceLocation, PartialDiagnostic>;
} // end namespace clang
#endif
} // namespace clang
#endif // LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H

View File

@ -1,4 +1,4 @@
//===---------- PlistSupport.h - Plist Output Utilities ---------*- C++ -*-===//
//===- PlistSupport.h - Plist Output Utilities ------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -10,12 +10,20 @@
#ifndef LLVM_CLANG_BASIC_PLISTSUPPORT_H
#define LLVM_CLANG_BASIC_PLISTSUPPORT_H
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
namespace clang {
namespace markup {
typedef llvm::DenseMap<FileID, unsigned> FIDMap;
using FIDMap = llvm::DenseMap<FileID, unsigned>;
inline void AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
const SourceManager &SM, SourceLocation L) {
@ -112,7 +120,8 @@ inline void EmitRange(raw_ostream &o, const SourceManager &SM,
EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
Indent(o, indent) << "</array>\n";
}
}
}
#endif
} // namespace markup
} // namespace clang
#endif // LLVM_CLANG_BASIC_PLISTSUPPORT_H

View File

@ -1,4 +1,4 @@
//===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===//
//===- SourceLocation.h - Compact identifier for Source Files ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -6,28 +6,29 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
//
/// \file
/// \brief Defines the clang::SourceLocation class and associated facilities.
///
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_SOURCELOCATION_H
#define LLVM_CLANG_BASIC_SOURCELOCATION_H
#include "clang/Basic/LLVM.h"
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
#include <cassert>
#include <functional>
#include <cstdint>
#include <string>
#include <utility>
namespace llvm {
class MemoryBuffer;
template <typename T> struct DenseMapInfo;
template <typename T> struct isPodLike;
}
template <typename T> struct DenseMapInfo;
template <typename T> struct isPodLike;
} // namespace llvm
namespace clang {
@ -56,19 +57,19 @@ public:
unsigned getHashValue() const { return static_cast<unsigned>(ID); }
private:
friend class SourceManager;
friend class ASTWriter;
friend class ASTReader;
friend class SourceManager;
static FileID get(int V) {
FileID F;
F.ID = V;
return F;
}
int getOpaqueValue() const { return ID; }
};
/// \brief Encodes a location in the source. The SourceManager can decode this
/// to get at the full include stack, line and column information.
///
@ -85,10 +86,12 @@ private:
///
/// It is important that this type remains small. It is currently 32 bits wide.
class SourceLocation {
unsigned ID = 0;
friend class SourceManager;
friend class ASTReader;
friend class ASTWriter;
friend class SourceManager;
unsigned ID = 0;
enum : unsigned {
MacroIDBit = 1U << 31
};
@ -124,8 +127,8 @@ private:
L.ID = MacroIDBit | ID;
return L;
}
public:
public:
/// \brief Return a source location with the specified offset from this
/// SourceLocation.
SourceLocation getLocWithOffset(int Offset) const {
@ -245,6 +248,7 @@ public:
static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E) {
return getTokenRange(SourceRange(B, E));
}
static CharSourceRange getCharRange(SourceLocation B, SourceLocation E) {
return getCharRange(SourceRange(B, E));
}
@ -274,12 +278,12 @@ public:
///
/// You can get a PresumedLoc from a SourceLocation with SourceManager.
class PresumedLoc {
const char *Filename;
const char *Filename = nullptr;
unsigned Line, Col;
SourceLocation IncludeLoc;
public:
PresumedLoc() : Filename(nullptr) {}
PresumedLoc() = default;
PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
: Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {}
@ -336,7 +340,7 @@ public:
FullSourceLoc() = default;
explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
: SourceLocation(Loc), SrcMgr(&SM) {}
: SourceLocation(Loc), SrcMgr(&SM) {}
bool hasManager() const {
bool hasSrcMgr = SrcMgr != nullptr;
@ -415,32 +419,31 @@ public:
/// This is useful for debugging.
void dump() const;
friend inline bool
friend bool
operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
return LHS.getRawEncoding() == RHS.getRawEncoding() &&
LHS.SrcMgr == RHS.SrcMgr;
}
friend inline bool
friend bool
operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
return !(LHS == RHS);
}
};
} // end namespace clang
} // namespace clang
namespace llvm {
/// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
/// DenseSets.
template <>
struct DenseMapInfo<clang::FileID> {
static inline clang::FileID getEmptyKey() {
return clang::FileID();
static clang::FileID getEmptyKey() {
return {};
}
static inline clang::FileID getTombstoneKey() {
static clang::FileID getTombstoneKey() {
return clang::FileID::getSentinel();
}
@ -461,15 +464,17 @@ namespace llvm {
// Teach SmallPtrSet how to handle SourceLocation.
template<>
struct PointerLikeTypeTraits<clang::SourceLocation> {
static inline void *getAsVoidPointer(clang::SourceLocation L) {
enum { NumLowBitsAvailable = 0 };
static void *getAsVoidPointer(clang::SourceLocation L) {
return L.getPtrEncoding();
}
static inline clang::SourceLocation getFromVoidPointer(void *P) {
static clang::SourceLocation getFromVoidPointer(void *P) {
return clang::SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)P);
}
enum { NumLowBitsAvailable = 0 };
};
} // end namespace llvm
} // namespace llvm
#endif
#endif // LLVM_CLANG_BASIC_SOURCELOCATION_H

View File

@ -1,4 +1,4 @@
//===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
//===- Diagnostic.cpp - C Language Family Diagnostic Handling -------------===//
//
// The LLVM Compiler Infrastructure
//
@ -14,15 +14,30 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/DiagnosticError.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Locale.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <string>
#include <utility>
#include <vector>
using namespace clang;
@ -61,23 +76,9 @@ DiagnosticsEngine::DiagnosticsEngine(
IntrusiveRefCntPtr<DiagnosticIDs> diags,
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, DiagnosticConsumer *client,
bool ShouldOwnClient)
: Diags(std::move(diags)), DiagOpts(std::move(DiagOpts)), Client(nullptr),
SourceMgr(nullptr) {
: Diags(std::move(diags)), DiagOpts(std::move(DiagOpts)) {
setClient(client, ShouldOwnClient);
ArgToStringFn = DummyArgToStringFn;
ArgToStringCookie = nullptr;
AllExtensionsSilenced = 0;
SuppressAfterFatalError = true;
SuppressAllDiagnostics = false;
ElideType = true;
PrintTemplateTree = false;
ShowColors = false;
ShowOverloads = Ovl_All;
ErrorLimit = 0;
TemplateBacktraceLimit = 0;
ConstexprBacktraceLimit = 0;
Reset();
}
@ -121,7 +122,7 @@ void DiagnosticsEngine::Reset() {
TrapNumErrorsOccurred = 0;
TrapNumUnrecoverableErrorsOccurred = 0;
CurDiagID = ~0U;
CurDiagID = std::numeric_limits<unsigned>::max();
LastDiagLevel = DiagnosticIDs::Ignored;
DelayedDiagID = 0;
@ -152,8 +153,7 @@ void DiagnosticsEngine::ReportDelayed() {
Report(ID) << DelayedDiagArg1 << DelayedDiagArg2;
}
void DiagnosticsEngine::DiagStateMap::appendFirst(
DiagState *State) {
void DiagnosticsEngine::DiagStateMap::appendFirst(DiagState *State) {
assert(Files.empty() && "not first");
FirstDiagState = CurDiagState = State;
CurDiagStateLoc = SourceLocation();
@ -463,7 +463,8 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor Flavor,
}
void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
assert(CurDiagID == std::numeric_limits<unsigned>::max() &&
"Multiple diagnostics in flight at once!");
CurDiagLoc = storedDiag.getLocation();
CurDiagID = storedDiag.getID();
@ -484,7 +485,7 @@ void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
++NumWarnings;
}
CurDiagID = ~0U;
CurDiagID = std::numeric_limits<unsigned>::max();
}
bool DiagnosticsEngine::EmitCurrentDiagnostic(bool Force) {
@ -519,8 +520,7 @@ bool DiagnosticsEngine::EmitCurrentDiagnostic(bool Force) {
return Emitted;
}
DiagnosticConsumer::~DiagnosticConsumer() {}
DiagnosticConsumer::~DiagnosticConsumer() = default;
void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info) {
@ -537,7 +537,7 @@ void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
template <std::size_t StrLen>
static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
const char (&Str)[StrLen]) {
return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1);
return StrLen-1 == ModifierLen && memcmp(Modifier, Str, StrLen-1) == 0;
}
/// ScanForward - Scans forward, looking for the given character, skipping
@ -617,7 +617,6 @@ static void HandleOrdinalModifier(unsigned ValNo,
Out << ValNo << llvm::getOrdinalSuffix(ValNo);
}
/// PluralNumber - Parse an unsigned integer and advance Start.
static unsigned PluralNumber(const char *&Start, const char *End) {
// Programming 101: Parse a decimal number :-)
@ -653,7 +652,7 @@ static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
if (*Start == ':')
return true;
while (1) {
while (true) {
char C = *Start;
if (C == '%') {
// Modulo expression
@ -718,7 +717,7 @@ static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo,
const char *Argument, unsigned ArgumentLen,
SmallVectorImpl<char> &OutStr) {
const char *ArgumentEnd = Argument + ArgumentLen;
while (1) {
while (true) {
assert(Argument < ArgumentEnd && "Plural expression didn't match.");
const char *ExprEnd = Argument;
while (*ExprEnd != ':') {
@ -769,7 +768,6 @@ FormatDiagnostic(SmallVectorImpl<char> &OutStr) const {
void Diagnostic::
FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
SmallVectorImpl<char> &OutStr) const {
// When the diagnostic string is only "%0", the entire string is being given
// by an outside source. Remove unprintable characters from this string
// and skip all the other string processing.
@ -989,7 +987,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
FormattedArgs,
OutStr, QualTypeVals);
break;
case DiagnosticsEngine::ak_qualtype_pair:
case DiagnosticsEngine::ak_qualtype_pair: {
// Create a struct with all the info needed for printing.
TemplateDiffTypes TDT;
TDT.FromType = getRawArg(ArgNo);
@ -1057,6 +1055,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
FormatDiagnostic(SecondDollar + 1, Pipe, OutStr);
break;
}
}
// Remember this argument info for subsequent formatting operations. Turn
// std::strings into a null terminated string to make it be the same case as
@ -1068,7 +1067,6 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
else
FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string,
(intptr_t)getArgStdStr(ArgNo).c_str()));
}
// Append the type tree to the end of the diagnostics.
@ -1077,12 +1075,11 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
StringRef Message)
: ID(ID), Level(Level), Loc(), Message(Message) { }
: ID(ID), Level(Level), Message(Message) {}
StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level,
const Diagnostic &Info)
: ID(Info.getID()), Level(Level)
{
: ID(Info.getID()), Level(Level) {
assert((Info.getLocation().isInvalid() || Info.hasSourceManager()) &&
"Valid source location without setting a source manager for diagnostic");
if (Info.getLocation().isValid())
@ -1098,8 +1095,8 @@ StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
StringRef Message, FullSourceLoc Loc,
ArrayRef<CharSourceRange> Ranges,
ArrayRef<FixItHint> FixIts)
: ID(ID), Level(Level), Loc(Loc), Message(Message),
Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end())
: ID(ID), Level(Level), Loc(Loc), Message(Message),
Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end())
{
}
@ -1109,9 +1106,9 @@ StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
/// reported by DiagnosticsEngine.
bool DiagnosticConsumer::IncludeInDiagnosticCounts() const { return true; }
void IgnoringDiagConsumer::anchor() { }
void IgnoringDiagConsumer::anchor() {}
ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer() {}
ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer() = default;
void ForwardingDiagnosticConsumer::HandleDiagnostic(
DiagnosticsEngine::Level DiagLevel,

View File

@ -1,4 +1,4 @@
//===--- DiagnosticOptions.cpp - C Language Family Diagnostic Handling ----===//
//===- DiagnosticOptions.cpp - C Language Family Diagnostic Handling ------===//
//
// The LLVM Compiler Infrastructure
//
@ -13,6 +13,7 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "llvm/Support/raw_ostream.h"
#include <type_traits>
namespace clang {
@ -21,4 +22,4 @@ raw_ostream &operator<<(raw_ostream &Out, DiagnosticLevelMask M) {
return Out << static_cast<UT>(M);
}
} // end namespace clang
} // namespace clang

View File

@ -1,4 +1,4 @@
//===--- LangOptions.cpp - C Language Family Language Options ---*- C++ -*-===//
//===- LangOptions.cpp - C Language Family Language Options ---------------===//
//
// The LLVM Compiler Infrastructure
//
@ -10,13 +10,12 @@
// This file defines the LangOptions class.
//
//===----------------------------------------------------------------------===//
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/StringRef.h"
using namespace clang;
LangOptions::LangOptions()
: IsHeaderFile(false) {
LangOptions::LangOptions() {
#define LANGOPT(Name, Bits, Default, Description) Name = Default;
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
#include "clang/Basic/LangOptions.def"

View File

@ -1,4 +1,4 @@
//==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==//
//===- SourceLocation.cpp - Compact identifier for Source Files -----------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,10 +12,17 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/PrettyStackTrace.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdio>
#include <cassert>
#include <string>
#include <utility>
using namespace clang;
//===----------------------------------------------------------------------===//
@ -81,7 +88,6 @@ FileID FullSourceLoc::getFileID() const {
return SrcMgr->getFileID(*this);
}
FullSourceLoc FullSourceLoc::getExpansionLoc() const {
assert(isValid());
return FullSourceLoc(SrcMgr->getExpansionLoc(*this), *SrcMgr);