-//===--- Diagnostic.h - C Language Family Diagnostic Handling ---*- C++ -*-===//
+//===- Diagnostic.h - C Language Family Diagnostic Handling -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
+//
/// \file
/// \brief Defines the Diagnostic-related interfaces.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H
#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>
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.
/// 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();
};
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.
///
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);
}
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();
/// 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.
///
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
/// 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;
/// 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;
/// 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.
/// 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
/// \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 {
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.");
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.
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 {
/// @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
SourceLocation getCurrentDiagLoc() const { return CurDiagLoc; }
/// @}
-
- friend class ASTReader;
- friend class ASTWriter;
};
/// \brief RAII class that determines when any errors have occurred
public:
explicit DiagnosticErrorTrap(DiagnosticsEngine &Diag)
- : Diag(Diag) { reset(); }
+ : Diag(Diag) { reset(); }
/// \brief Determine whether any errors have occurred since this
/// object instance was created.
/// 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;
/// call to ForceEmit.
mutable bool IsForceEmit = false;
- friend class DiagnosticsEngine;
-
DiagnosticBuilder() = default;
explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
diagObj->DiagFixItHints.clear();
}
- friend class PartialDiagnostic;
-
protected:
void FlushCounts() {
DiagObj->NumDiagArgs = NumArgs;
/// \brief Retrieve an empty diagnostic builder.
static DiagnosticBuilder getEmpty() {
- return DiagnosticBuilder();
+ return {};
}
/// \brief Forces the diagnostic to be emitted.
};
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
/// 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();
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; }
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(); }
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(); }
public:
DiagnosticConsumer() = default;
-
virtual ~DiagnosticConsumer();
unsigned getNumErrors() const { return NumErrors; }
public:
ForwardingDiagnosticConsumer(DiagnosticConsumer &Target) : Target(Target) {}
-
~ForwardingDiagnosticConsumer() override;
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
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;
};
/// 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
-//===--- DiagnosticOptions.h ------------------------------------*- C++ -*-===//
+//===- DiagnosticOptions.h --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
/// \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
}
};
-typedef DiagnosticOptions::TextDiagnosticFormat TextDiagnosticFormat;
+using TextDiagnosticFormat = DiagnosticOptions::TextDiagnosticFormat;
-} // end namespace clang
+} // namespace clang
-#endif
+#endif // LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
-//===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
+//===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
+//
/// \file
/// \brief Defines the clang::LangOptions interface.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
#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>
/// 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 {
};
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:
/// \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();
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.
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
-//===--- PartialDiagnostic.h - Diagnostic "closures" ------------*- C++ -*-===//
+//===- PartialDiagnostic.h - Diagnostic "closures" --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// 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 {
};
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).
};
/// \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.
/// \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
// 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 {
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;
}
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)
PD.AddFixItHint(Hint);
return PD;
}
-
};
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>;
+
+} // namespace clang
-} // end namespace clang
-#endif
+#endif // LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H
-//===---------- PlistSupport.h - Plist Output Utilities ---------*- C++ -*-===//
+//===- PlistSupport.h - Plist Output Utilities ------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#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) {
EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
Indent(o, indent) << "</array>\n";
}
-}
-}
-#endif
+} // namespace markup
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_PLISTSUPPORT_H
-//===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===//
+//===- SourceLocation.h - Compact identifier for Source Files ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// 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 {
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.
///
///
/// 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
};
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 {
static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E) {
return getTokenRange(SourceRange(B, E));
}
+
static CharSourceRange getCharRange(SourceLocation B, SourceLocation E) {
return getCharRange(SourceRange(B, E));
}
///
/// 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) {}
FullSourceLoc() = default;
explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
- : SourceLocation(Loc), SrcMgr(&SM) {}
+ : SourceLocation(Loc), SrcMgr(&SM) {}
bool hasManager() const {
bool hasSrcMgr = SrcMgr != nullptr;
/// 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();
}
// 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
-//===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
+//===- Diagnostic.cpp - C Language Family Diagnostic Handling -------------===//
//
// The LLVM Compiler Infrastructure
//
#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;
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();
}
TrapNumErrorsOccurred = 0;
TrapNumUnrecoverableErrorsOccurred = 0;
- CurDiagID = ~0U;
+ CurDiagID = std::numeric_limits<unsigned>::max();
LastDiagLevel = DiagnosticIDs::Ignored;
DelayedDiagID = 0;
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();
}
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();
++NumWarnings;
}
- CurDiagID = ~0U;
+ CurDiagID = std::numeric_limits<unsigned>::max();
}
bool DiagnosticsEngine::EmitCurrentDiagnostic(bool Force) {
return Emitted;
}
-
-DiagnosticConsumer::~DiagnosticConsumer() {}
+DiagnosticConsumer::~DiagnosticConsumer() = default;
void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info) {
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
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 :-)
if (*Start == ':')
return true;
- while (1) {
+ while (true) {
char C = *Start;
if (C == '%') {
// Modulo expression
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 != ':') {
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.
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);
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
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.
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())
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())
{
}
/// 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,
-//===--- DiagnosticOptions.cpp - C Language Family Diagnostic Handling ----===//
+//===- DiagnosticOptions.cpp - C Language Family Diagnostic Handling ------===//
//
// The LLVM Compiler Infrastructure
//
#include "clang/Basic/DiagnosticOptions.h"
#include "llvm/Support/raw_ostream.h"
+#include <type_traits>
namespace clang {
return Out << static_cast<UT>(M);
}
-} // end namespace clang
+} // namespace clang
-//===--- LangOptions.cpp - C Language Family Language Options ---*- C++ -*-===//
+//===- LangOptions.cpp - C Language Family Language Options ---------------===//
//
// The LLVM Compiler Infrastructure
//
// 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"
-//==--- SourceLocation.cpp - Compact identifier for Source Files -*- C++ -*-==//
+//===- SourceLocation.cpp - Compact identifier for Source Files -----------===//
//
// The LLVM Compiler Infrastructure
//
//===----------------------------------------------------------------------===//
#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;
//===----------------------------------------------------------------------===//
return SrcMgr->getFileID(*this);
}
-
FullSourceLoc FullSourceLoc::getExpansionLoc() const {
assert(isValid());
return FullSourceLoc(SrcMgr->getExpansionLoc(*this), *SrcMgr);