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

Eugene Zelenko via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 14:39:26 PST 2017


Author: eugenezelenko
Date: Fri Dec  8 14:39:26 2017
New Revision: 320207

URL: http://llvm.org/viewvc/llvm-project?rev=320207&view=rev
Log:
[Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

Modified:
    cfe/trunk/include/clang/Lex/Lexer.h
    cfe/trunk/include/clang/Lex/Pragma.h
    cfe/trunk/include/clang/Lex/PreprocessingRecord.h
    cfe/trunk/include/clang/Lex/PreprocessorOptions.h
    cfe/trunk/include/clang/Lex/TokenLexer.h
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Lex/Pragma.cpp
    cfe/trunk/lib/Lex/PreprocessingRecord.cpp
    cfe/trunk/lib/Lex/TokenLexer.cpp

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- Lexer.h - C Language Family Lexer ----------------------*- C++ -*-===//
+//===- Lexer.h - C Language Family Lexer ------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -15,25 +15,39 @@
 #define LLVM_CLANG_LEX_LEXER_H
 
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/PreprocessorLexer.h"
+#include "clang/Lex/Token.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include <cassert>
+#include <cstdint>
 #include <string>
 
+namespace llvm {
+
+class MemoryBuffer;
+
+} // namespace llvm
+
 namespace clang {
-class DiagnosticsEngine;
-class SourceManager;
-class Preprocessor;
+
 class DiagnosticBuilder;
+class Preprocessor;
+class SourceManager;
 
 /// ConflictMarkerKind - Kinds of conflict marker which the lexer might be
 /// recovering from.
 enum ConflictMarkerKind {
   /// Not within a conflict marker.
   CMK_None,
+
   /// A normal or diff3 conflict marker, initiated by at least 7 "<"s,
   /// separated by at least 7 "="s or "|"s, and terminated by at least 7 ">"s.
   CMK_Normal,
+
   /// A Perforce-style conflict marker, initiated by 4 ">"s,
   /// separated by 4 "="s, and terminated by 4 "<"s.
   CMK_Perforce
@@ -43,17 +57,17 @@ enum ConflictMarkerKind {
 /// PreprocessorOptions::PrecompiledPreambleBytes.
 /// The preamble includes the BOM, if any.
 struct PreambleBounds {
-  PreambleBounds(unsigned Size, bool PreambleEndsAtStartOfLine)
-    : Size(Size),
-      PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {}
-
   /// \brief Size of the preamble in bytes.
   unsigned Size;
+
   /// \brief Whether the preamble ends at the start of a new line.
   ///
   /// Used to inform the lexer as to whether it's starting at the beginning of
   /// a line after skipping the preamble.
   bool PreambleEndsAtStartOfLine;
+
+  PreambleBounds(unsigned Size, bool PreambleEndsAtStartOfLine)
+      : Size(Size), PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {}
 };
 
 /// Lexer - This provides a simple interface that turns a text buffer into a
@@ -61,15 +75,27 @@ struct PreambleBounds {
 /// or buffering/seeking of tokens, only forward lexing is supported.  It relies
 /// on the specified Preprocessor object to handle preprocessor directives, etc.
 class Lexer : public PreprocessorLexer {
+  friend class Preprocessor;
+
   void anchor() override;
 
   //===--------------------------------------------------------------------===//
   // Constant configuration values for this lexer.
-  const char *BufferStart;       // Start of the buffer.
-  const char *BufferEnd;         // End of the buffer.
-  SourceLocation FileLoc;        // Location for start of file.
-  LangOptions LangOpts;          // LangOpts enabled by this language (cache).
-  bool Is_PragmaLexer;           // True if lexer for _Pragma handling.
+
+  // Start of the buffer.
+  const char *BufferStart;
+
+  // End of the buffer.
+  const char *BufferEnd;
+
+  // Location for start of file.
+  SourceLocation FileLoc;
+
+  // LangOpts enabled by this language (cache).
+  LangOptions LangOpts;
+
+  // True if lexer for _Pragma handling.
+  bool Is_PragmaLexer;
 
   //===--------------------------------------------------------------------===//
   // Context-specific lexing flags set by the preprocessor.
@@ -106,13 +132,9 @@ class Lexer : public PreprocessorLexer {
   // CurrentConflictMarkerState - The kind of conflict marker we are handling.
   ConflictMarkerKind CurrentConflictMarkerState;
 
-  Lexer(const Lexer &) = delete;
-  void operator=(const Lexer &) = delete;
-  friend class Preprocessor;
-
   void InitLexer(const char *BufStart, const char *BufPtr, const char *BufEnd);
-public:
 
+public:
   /// Lexer constructor - Create a new lexer object for the specified buffer
   /// with the specified preprocessor managing the lexing process.  This lexer
   /// assumes that the associated file buffer and Preprocessor objects will
@@ -131,6 +153,9 @@ public:
   Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer,
         const SourceManager &SM, const LangOptions &LangOpts);
 
+  Lexer(const Lexer &) = delete;
+  Lexer &operator=(const Lexer &) = delete;
+
   /// Create_PragmaLexer: Lexer constructor - Create a new lexer object for
   /// _Pragma expansion.  This has a variety of magic semantics that this method
   /// sets up.  It returns a new'd Lexer that must be delete'd when done.
@@ -139,7 +164,6 @@ public:
                                    SourceLocation ExpansionLocEnd,
                                    unsigned TokLen, Preprocessor &PP);
 
-
   /// getLangOpts - Return the language features currently enabled.
   /// NOTE: this lexer modifies features as a file is parsed!
   const LangOptions &getLangOpts() const { return LangOpts; }
@@ -510,9 +534,9 @@ public:
   static StringRef getIndentationForLine(SourceLocation Loc,
                                          const SourceManager &SM);
 
+private:
   //===--------------------------------------------------------------------===//
   // Internal implementation interfaces.
-private:
 
   /// LexTokenInternal - Internal interface to lex a preprocessing token. Called
   /// by Lex.
@@ -685,7 +709,7 @@ private:
   ///               valid), this parameter will be updated to point to the
   ///               character after the UCN.
   /// \param SlashLoc The position in the source buffer of the '\'.
-  /// \param Tok The token being formed. Pass \c NULL to suppress diagnostics
+  /// \param Tok The token being formed. Pass \c nullptr to suppress diagnostics
   ///            and handle token formation in the caller.
   ///
   /// \return The Unicode codepoint specified by the UCN, or 0 if the UCN is
@@ -714,6 +738,6 @@ private:
   bool tryConsumeIdentifierUTF8Char(const char *&CurPtr);
 };
 
-}  // end namespace clang
+} // namespace clang
 
-#endif
+#endif // LLVM_CLANG_LEX_LEXER_H

Modified: cfe/trunk/include/clang/Lex/Pragma.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Pragma.h?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Pragma.h (original)
+++ cfe/trunk/include/clang/Lex/Pragma.h Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- Pragma.h - Pragma registration and handling ------------*- C++ -*-===//
+//===- Pragma.h - Pragma registration and handling --------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -17,13 +17,13 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
-#include <cassert>
+#include <string>
 
 namespace clang {
-  class Preprocessor;
-  class Token;
-  class IdentifierInfo;
-  class PragmaNamespace;
+
+class PragmaNamespace;
+class Preprocessor;
+class Token;
 
   /**
    * \brief Describes how the pragma was introduced, e.g., with \#pragma,
@@ -58,9 +58,10 @@ namespace clang {
 /// pragmas.
 class PragmaHandler {
   std::string Name;
+
 public:
+  PragmaHandler() = default;
   explicit PragmaHandler(StringRef name) : Name(name) {}
-  PragmaHandler() {}
   virtual ~PragmaHandler();
 
   StringRef getName() const { return Name; }
@@ -89,8 +90,8 @@ public:
 class PragmaNamespace : public PragmaHandler {
   /// Handlers - This is a map of the handlers in this namespace with their name
   /// as key.
-  ///
-  llvm::StringMap<PragmaHandler*> Handlers;
+  llvm::StringMap<PragmaHandler *> Handlers;
+
 public:
   explicit PragmaNamespace(StringRef Name) : PragmaHandler(Name) {}
   ~PragmaNamespace() override;
@@ -103,16 +104,13 @@ public:
                              bool IgnoreNull = true) const;
 
   /// AddPragma - Add a pragma to this namespace.
-  ///
   void AddPragma(PragmaHandler *Handler);
 
   /// RemovePragmaHandler - Remove the given handler from the
   /// namespace.
   void RemovePragmaHandler(PragmaHandler *Handler);
 
-  bool IsEmpty() {
-    return Handlers.empty();
-  }
+  bool IsEmpty() const { return Handlers.empty(); }
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &FirstToken) override;
@@ -120,7 +118,6 @@ public:
   PragmaNamespace *getIfNamespace() override { return this; }
 };
 
+} // namespace clang
 
-}  // end namespace clang
-
-#endif
+#endif // LLVM_CLANG_LEX_PRAGMA_H

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- PreprocessingRecord.h - Record of Preprocessing --------*- C++ -*-===//
+//===- PreprocessingRecord.h - Record of Preprocessing ----------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -11,24 +11,33 @@
 //  of what occurred during preprocessing.
 //
 //===----------------------------------------------------------------------===//
+
 #ifndef LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
 #define LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
 
-#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Compiler.h"
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+#include <utility>
 #include <vector>
 
 namespace clang {
-  class IdentifierInfo;
-  class MacroInfo;
-  class PreprocessingRecord;
-}
+
+class PreprocessingRecord;
+
+} // namespace clang
 
 /// \brief Allocates memory within a Clang preprocessing record.
 void *operator new(size_t bytes, clang::PreprocessingRecord &PR,
@@ -39,8 +48,12 @@ void operator delete(void *ptr, clang::P
                      unsigned) noexcept;
 
 namespace clang {
-  class MacroDefinitionRecord;
-  class FileEntry;
+
+class FileEntry;
+class IdentifierInfo;
+class MacroInfo;
+class SourceManager;
+class Token;
 
   /// \brief Base class that describes a preprocessed entity, which may be a
   /// preprocessor directive or macro expansion.
@@ -78,11 +91,11 @@ namespace clang {
     SourceRange Range;
     
   protected:
-    PreprocessedEntity(EntityKind Kind, SourceRange Range)
-      : Kind(Kind), Range(Range) { }
-
     friend class PreprocessingRecord;
 
+    PreprocessedEntity(EntityKind Kind, SourceRange Range)
+        : Kind(Kind), Range(Range) {}
+
   public:
     /// \brief Retrieve the kind of preprocessed entity stored in this object.
     EntityKind getKind() const { return Kind; }
@@ -122,7 +135,7 @@ namespace clang {
   class PreprocessingDirective : public PreprocessedEntity {
   public:
     PreprocessingDirective(EntityKind Kind, SourceRange Range) 
-      : PreprocessedEntity(Kind, Range) { }
+        : PreprocessedEntity(Kind, Range) {}
     
     // Implement isa/cast/dyncast/etc.
     static bool classof(const PreprocessedEntity *PD) { 
@@ -199,10 +212,13 @@ namespace clang {
     enum InclusionKind {
       /// \brief An \c \#include directive.
       Include,
+
       /// \brief An Objective-C \c \#import directive.
       Import,
+
       /// \brief A GNU \c \#include_next directive.
       IncludeNext,
+
       /// \brief A Clang \c \#__include_macros directive.
       IncludeMacros
     };
@@ -316,11 +332,14 @@ namespace clang {
     /// value 1 corresponds to element 0 in the local entities vector,
     /// value 2 corresponds to element 1 in the local entities vector, etc.
     class PPEntityID {
-      int ID;
-      explicit PPEntityID(int ID) : ID(ID) {}
       friend class PreprocessingRecord;
+
+      int ID = 0;
+
+      explicit PPEntityID(int ID) : ID(ID) {}
+
     public:
-      PPEntityID() : ID(0) {}
+      PPEntityID() = default;
     };
 
     static PPEntityID getPPEntityID(unsigned Index, bool isLoaded) {
@@ -331,7 +350,7 @@ namespace clang {
     llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *> MacroDefinitions;
 
     /// \brief External source of preprocessed entities.
-    ExternalPreprocessingRecordSource *ExternalSource;
+    ExternalPreprocessingRecordSource *ExternalSource = nullptr;
 
     /// \brief Retrieve the preprocessed entity at the given ID.
     PreprocessedEntity *getPreprocessedEntity(PPEntityID PPID);
@@ -371,7 +390,7 @@ namespace clang {
     }
     
     /// \brief Deallocate memory in the preprocessing record.
-    void Deallocate(void *Ptr) { }
+    void Deallocate(void *Ptr) {}
 
     size_t getTotalMemory() const;
 
@@ -397,11 +416,12 @@ namespace clang {
                          iterator, int, std::random_access_iterator_tag,
                          PreprocessedEntity *, int, PreprocessedEntity *,
                          PreprocessedEntity *> {
+      friend class PreprocessingRecord;
+
       PreprocessingRecord *Self;
 
       iterator(PreprocessingRecord *Self, int Position)
           : iterator::iterator_adaptor_base(Position), Self(Self) {}
-      friend class PreprocessingRecord;
 
     public:
       iterator() : iterator(nullptr, 0) {}
@@ -451,7 +471,6 @@ namespace clang {
     /// encompasses.
     ///
     /// \param R the range to look for preprocessed entities.
-    ///
     llvm::iterator_range<iterator>
     getPreprocessedEntitiesInRange(SourceRange R);
 
@@ -485,6 +504,9 @@ namespace clang {
     }
         
   private:
+    friend class ASTReader;
+    friend class ASTWriter;
+
     void MacroExpands(const Token &Id, const MacroDefinition &MD,
                       SourceRange Range, const MacroArgs *Args) override;
     void MacroDefined(const Token &Id, const MacroDirective *MD) override;
@@ -500,6 +522,7 @@ namespace clang {
                const MacroDefinition &MD) override;
     void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
                 const MacroDefinition &MD) override;
+
     /// \brief Hook called whenever the 'defined' operator is seen.
     void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
                  SourceRange Range) override;
@@ -518,11 +541,9 @@ namespace clang {
     } CachedRangeQuery;
 
     std::pair<int, int> getPreprocessedEntitiesInRangeSlow(SourceRange R);
-
-    friend class ASTReader;
-    friend class ASTWriter;
   };
-} // end namespace clang
+
+} // namespace clang
 
 inline void *operator new(size_t bytes, clang::PreprocessingRecord &PR,
                           unsigned alignment) noexcept {

Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===//
+//===- PreprocessorOptions.h ------------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -10,30 +10,30 @@
 #ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
 
-#include "clang/Basic/SourceLocation.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
-#include <cassert>
+#include <memory> 
 #include <set>
 #include <string>
 #include <utility>
 #include <vector>
 
 namespace llvm {
-  class MemoryBuffer;
-}
 
-namespace clang {
+class MemoryBuffer;
+
+} // namespace llvm
 
-class Preprocessor;
-class LangOptions;
+namespace clang {
 
 /// \brief Enumerate the kinds of standard library that 
 enum ObjCXXARCStandardLibraryKind {
   ARCXX_nolib,
+
   /// \brief libc++
   ARCXX_libcxx,
+
   /// \brief libstdc++
   ARCXX_libstdcxx
 };
@@ -42,17 +42,17 @@ enum ObjCXXARCStandardLibraryKind {
 /// used in preprocessor initialization to InitializePreprocessor().
 class PreprocessorOptions {
 public:
-  std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
+  std::vector<std::pair<std::string, bool/*isUndef*/>> Macros;
   std::vector<std::string> Includes;
   std::vector<std::string> MacroIncludes;
 
   /// \brief Initialize the preprocessor with the compiler and target specific
   /// predefines.
-  unsigned UsePredefines : 1;
+  bool UsePredefines = true;
 
   /// \brief Whether we should maintain a detailed record of all macro
   /// definitions and expansions.
-  unsigned DetailedRecord : 1;
+  bool DetailedRecord = false;
 
   /// The implicit PCH included at the start of the translation unit, or empty.
   std::string ImplicitPCHInclude;
@@ -62,13 +62,13 @@ public:
 
   /// \brief When true, disables most of the normal validation performed on
   /// precompiled headers.
-  bool DisablePCHValidation;
+  bool DisablePCHValidation = false;
 
   /// \brief When true, a PCH with compiler errors will not be rejected.
-  bool AllowPCHWithCompilerErrors;
+  bool AllowPCHWithCompilerErrors = false;
 
   /// \brief Dump declarations that are deserialized from PCH, for testing.
-  bool DumpDeserializedPCHDecls;
+  bool DumpDeserializedPCHDecls = false;
 
   /// \brief This is a set of names for decls that we do not want to be
   /// deserialized, and we emit an error if they are; for testing purposes.
@@ -86,7 +86,7 @@ public:
   /// When the lexer is done, one of the things that need to be preserved is the
   /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when
   /// processing the rest of the file.
-  bool GeneratePreamble;
+  bool GeneratePreamble = false;
 
   /// The implicit PTH input included at the start of the translation unit, or
   /// empty.
@@ -107,7 +107,7 @@ public:
 
   /// \brief True if the SourceManager should report the original file name for
   /// contents of files that were remapped to other files. Defaults to true.
-  bool RemappedFilesKeepOriginalName;
+  bool RemappedFilesKeepOriginalName = true;
 
   /// \brief The set of file remappings, which take existing files on
   /// the system (the first part of each pair) and gives them the
@@ -126,12 +126,12 @@ public:
   /// This flag defaults to false; it can be set true only through direct
   /// manipulation of the compiler invocation object, in cases where the 
   /// compiler invocation and its buffers will be reused.
-  bool RetainRemappedFileBuffers;
+  bool RetainRemappedFileBuffers = false;
   
   /// \brief The Objective-C++ ARC standard library that we should support,
   /// by providing appropriate definitions to retrofit the standard library
   /// with support for lifetime-qualified pointers.
-  ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
+  ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary = ARCXX_nolib;
     
   /// \brief Records the set of modules
   class FailedModulesSet {
@@ -156,18 +156,11 @@ public:
   std::shared_ptr<FailedModulesSet> FailedModules;
 
 public:
-  PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
-                          DisablePCHValidation(false),
-                          AllowPCHWithCompilerErrors(false),
-                          DumpDeserializedPCHDecls(false),
-                          PrecompiledPreambleBytes(0, false),
-                          GeneratePreamble(false),
-                          RemappedFilesKeepOriginalName(true),
-                          RetainRemappedFileBuffers(false),
-                          ObjCXXARCStandardLibrary(ARCXX_nolib) { }
+  PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
 
   void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
   void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); }
+
   void addRemappedFile(StringRef From, StringRef To) {
     RemappedFiles.emplace_back(From, To);
   }
@@ -199,6 +192,6 @@ public:
   }
 };
 
-} // end namespace clang
+} // namespace clang
 
-#endif
+#endif // LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_

Modified: cfe/trunk/include/clang/Lex/TokenLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/TokenLexer.h?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/TokenLexer.h (original)
+++ cfe/trunk/include/clang/Lex/TokenLexer.h Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- TokenLexer.h - Lex from a token buffer -----------------*- C++ -*-===//
+//===- TokenLexer.h - Lex from a token buffer -------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -18,28 +18,28 @@
 #include "llvm/ADT/ArrayRef.h"
 
 namespace clang {
-  class MacroInfo;
-  class Preprocessor;
-  class Token;
-  class MacroArgs;
-  class VAOptExpansionContext;
+
+class MacroArgs;
+class MacroInfo;
+class Preprocessor;
+class Token;
+class VAOptExpansionContext;
 
 /// TokenLexer - This implements a lexer that returns tokens from a macro body
 /// or token stream instead of lexing from a character buffer.  This is used for
 /// macro expansion and _Pragma handling, for example.
-///
 class TokenLexer {
+  friend class Preprocessor;
+
   /// Macro - The macro we are expanding from.  This is null if expanding a
   /// token stream.
-  ///
-  MacroInfo *Macro;
+  MacroInfo *Macro = nullptr;
 
   /// ActualArgs - The actual arguments specified for a function-like macro, or
   /// null.  The TokenLexer owns the pointed-to object.
-  MacroArgs *ActualArgs;
+  MacroArgs *ActualArgs = nullptr;
 
   /// PP - The current preprocessor object we are expanding for.
-  ///
   Preprocessor &PP;
 
   /// Tokens - This is the pointer to an array of tokens that the macro is
@@ -51,14 +51,11 @@ class TokenLexer {
   /// Note that if it points into Preprocessor's cache buffer, the Preprocessor
   /// may update the pointer as needed.
   const Token *Tokens;
-  friend class Preprocessor;
 
   /// NumTokens - This is the length of the Tokens array.
-  ///
   unsigned NumTokens;
 
   /// This is the index of the next token that Lex will return.
-  ///
   unsigned CurTokenIdx;
 
   /// ExpandLocStart/End - The source location range where this macro was
@@ -75,6 +72,7 @@ class TokenLexer {
 
   /// \brief Location of the macro definition.
   SourceLocation MacroDefStart;
+
   /// \brief Length of the macro definition.
   unsigned MacroDefLength;
 
@@ -101,8 +99,6 @@ class TokenLexer {
   /// should not be subject to further macro expansion.
   bool DisableMacroExpansion : 1;
 
-  TokenLexer(const TokenLexer &) = delete;
-  void operator=(const TokenLexer &) = delete;
 public:
   /// Create a TokenLexer for the specified macro with the specified actual
   /// arguments.  Note that this ctor takes ownership of the ActualArgs pointer.
@@ -110,26 +106,30 @@ public:
   /// identifier for an object-like macro.
   TokenLexer(Token &Tok, SourceLocation ILEnd, MacroInfo *MI,
              MacroArgs *ActualArgs, Preprocessor &pp)
-    : Macro(nullptr), ActualArgs(nullptr), PP(pp), OwnsTokens(false) {
+      : PP(pp), OwnsTokens(false) {
     Init(Tok, ILEnd, MI, ActualArgs);
   }
 
-  /// Init - Initialize this TokenLexer to expand from the specified macro
-  /// with the specified argument information.  Note that this ctor takes
-  /// ownership of the ActualArgs pointer.  ILEnd specifies the location of the
-  /// ')' for a function-like macro or the identifier for an object-like macro.
-  void Init(Token &Tok, SourceLocation ILEnd, MacroInfo *MI,
-            MacroArgs *ActualArgs);
-
   /// Create a TokenLexer for the specified token stream.  If 'OwnsTokens' is
   /// specified, this takes ownership of the tokens and delete[]'s them when
   /// the token lexer is empty.
   TokenLexer(const Token *TokArray, unsigned NumToks, bool DisableExpansion,
              bool ownsTokens, Preprocessor &pp)
-    : Macro(nullptr), ActualArgs(nullptr), PP(pp), OwnsTokens(false) {
+      : PP(pp), OwnsTokens(false) {
     Init(TokArray, NumToks, DisableExpansion, ownsTokens);
   }
 
+  TokenLexer(const TokenLexer &) = delete;
+  TokenLexer &operator=(const TokenLexer &) = delete;
+  ~TokenLexer() { destroy(); }
+
+  /// Init - Initialize this TokenLexer to expand from the specified macro
+  /// with the specified argument information.  Note that this ctor takes
+  /// ownership of the ActualArgs pointer.  ILEnd specifies the location of the
+  /// ')' for a function-like macro or the identifier for an object-like macro.
+  void Init(Token &Tok, SourceLocation ILEnd, MacroInfo *MI,
+            MacroArgs *ActualArgs);
+
   /// Init - Initialize this TokenLexer with the specified token stream.
   /// This does not take ownership of the specified token vector.
   ///
@@ -138,8 +138,6 @@ public:
   void Init(const Token *TokArray, unsigned NumToks,
             bool DisableMacroExpansion, bool OwnsTokens);
 
-  ~TokenLexer() { destroy(); }
-
   /// isNextTokenLParen - If the next token lexed will pop this macro off the
   /// expansion stack, return 2.  If the next unexpanded token is a '(', return
   /// 1, otherwise return 0.
@@ -182,7 +180,6 @@ private:
   ///
   /// \returns If this returns true, the caller should immediately return the
   /// token.
-
   bool pasteTokens(Token &LHSTok, ArrayRef<Token> TokenStream,
                    unsigned int &CurIdx);
 
@@ -204,7 +201,6 @@ private:
   /// \param[in] VCtx - contains relevent contextual information about the
   /// state of the tokens around and including the __VA_OPT__ token, necessary
   /// for stringification.
-
   void stringifyVAOPTContents(SmallVectorImpl<Token> &ReplacementToks,
                               const VAOptExpansionContext &VCtx,
                               SourceLocation VAOPTClosingParenLoc);
@@ -243,6 +239,6 @@ private:
   void PropagateLineStartLeadingSpaceInfo(Token &Result);
 };
 
-}  // end namespace clang
+} // namespace clang
 
-#endif
+#endif // LLVM_CLANG_LEX_TOKENLEXER_H

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- Lexer.cpp - C Language Family Lexer ------------------------------===//
+//===- Lexer.cpp - C Language Family Lexer --------------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -15,13 +15,24 @@
 #include "UnicodeCharSets.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/LiteralSupport.h"
+#include "clang/Lex/MultipleIncludeOpt.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Lex/Token.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/MathExtras.h"
@@ -63,7 +74,7 @@ tok::ObjCKeywordKind Token::getObjCKeywo
 // Lexer Class Implementation
 //===----------------------------------------------------------------------===//
 
-void Lexer::anchor() { }
+void Lexer::anchor() {}
 
 void Lexer::InitLexer(const char *BufStart, const char *BufPtr,
                       const char *BufEnd) {
@@ -120,31 +131,21 @@ void Lexer::InitLexer(const char *BufSta
 /// assumes that the associated file buffer and Preprocessor objects will
 /// outlive it, so it doesn't take ownership of either of them.
 Lexer::Lexer(FileID FID, const llvm::MemoryBuffer *InputFile, Preprocessor &PP)
-  : PreprocessorLexer(&PP, FID),
-    FileLoc(PP.getSourceManager().getLocForStartOfFile(FID)),
-    LangOpts(PP.getLangOpts()) {
-
+    : PreprocessorLexer(&PP, FID),
+      FileLoc(PP.getSourceManager().getLocForStartOfFile(FID)),
+      LangOpts(PP.getLangOpts()) {
   InitLexer(InputFile->getBufferStart(), InputFile->getBufferStart(),
             InputFile->getBufferEnd());
 
   resetExtendedTokenMode();
 }
 
-void Lexer::resetExtendedTokenMode() {
-  assert(PP && "Cannot reset token mode without a preprocessor");
-  if (LangOpts.TraditionalCPP)
-    SetKeepWhitespaceMode(true);
-  else
-    SetCommentRetentionState(PP->getCommentRetentionState());
-}
-
 /// Lexer constructor - Create a new raw lexer object.  This object is only
 /// suitable for calls to 'LexFromRawLexer'.  This lexer assumes that the text
 /// range will outlive it, so it doesn't take ownership of it.
 Lexer::Lexer(SourceLocation fileloc, const LangOptions &langOpts,
              const char *BufStart, const char *BufPtr, const char *BufEnd)
-  : FileLoc(fileloc), LangOpts(langOpts) {
-
+    : FileLoc(fileloc), LangOpts(langOpts) {
   InitLexer(BufStart, BufPtr, BufEnd);
 
   // We *are* in raw mode.
@@ -159,6 +160,14 @@ Lexer::Lexer(FileID FID, const llvm::Mem
     : Lexer(SM.getLocForStartOfFile(FID), langOpts, FromFile->getBufferStart(),
             FromFile->getBufferStart(), FromFile->getBufferEnd()) {}
 
+void Lexer::resetExtendedTokenMode() {
+  assert(PP && "Cannot reset token mode without a preprocessor");
+  if (LangOpts.TraditionalCPP)
+    SetKeepWhitespaceMode(true);
+  else
+    SetCommentRetentionState(PP->getCommentRetentionState());
+}
+
 /// Create_PragmaLexer: Lexer constructor - Create a new lexer object for
 /// _Pragma expansion.  This has a variety of magic semantics that this method
 /// sets up.  It returns a new'd Lexer that must be delete'd when done.
@@ -209,7 +218,7 @@ Lexer *Lexer::Create_PragmaLexer(SourceL
   return L;
 }
 
-template <typename T> void StringifyImpl(T &Str, char Quote) {
+template <typename T> static void StringifyImpl(T &Str, char Quote) {
   typename T::size_type i = 0, e = Str.size();
   while (i < e) {
     if (Str[i] == '\\' || Str[i] == Quote) {
@@ -316,7 +325,7 @@ StringRef Lexer::getSpelling(SourceLocat
   StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
   if (invalidTemp) {
     if (invalid) *invalid = true;
-    return StringRef();
+    return {};
   }
 
   const char *tokenBegin = file.data() + locInfo.second;
@@ -354,7 +363,7 @@ std::string Lexer::getSpelling(const Tok
   if (Invalid)
     *Invalid = CharDataInvalid;
   if (CharDataInvalid)
-    return std::string();
+    return {};
 
   // If this token contains nothing interesting, return it directly.
   if (!Tok.needsCleaning())
@@ -554,12 +563,12 @@ SourceLocation Lexer::GetBeginningOfToke
 
 namespace {
 
-  enum PreambleDirectiveKind {
-    PDK_Skipped,
-    PDK_Unknown
-  };
+enum PreambleDirectiveKind {
+  PDK_Skipped,
+  PDK_Unknown
+};
 
-} // end anonymous namespace
+} // namespace
 
 PreambleBounds Lexer::ComputePreamble(StringRef Buffer,
                                       const LangOptions &LangOpts,
@@ -765,11 +774,11 @@ SourceLocation Lexer::getLocForEndOfToke
                                           const SourceManager &SM,
                                           const LangOptions &LangOpts) {
   if (Loc.isInvalid())
-    return SourceLocation();
+    return {};
 
   if (Loc.isMacroID()) {
     if (Offset > 0 || !isAtEndOfMacroExpansion(Loc, SM, LangOpts, &Loc))
-      return SourceLocation(); // Points inside the macro expansion.
+      return {}; // Points inside the macro expansion.
   }
 
   unsigned Len = Lexer::MeasureTokenLength(Loc, SM, LangOpts);
@@ -840,7 +849,7 @@ static CharSourceRange makeRangeFromFile
   if (Range.isTokenRange()) {
     End = Lexer::getLocForEndOfToken(End, 0, SM,LangOpts);
     if (End.isInvalid())
-      return CharSourceRange();
+      return {};
   }
 
   // Break down the source locations.
@@ -848,12 +857,12 @@ static CharSourceRange makeRangeFromFile
   unsigned BeginOffs;
   std::tie(FID, BeginOffs) = SM.getDecomposedLoc(Begin);
   if (FID.isInvalid())
-    return CharSourceRange();
+    return {};
 
   unsigned EndOffs;
   if (!SM.isInFileID(End, FID, &EndOffs) ||
       BeginOffs > EndOffs)
-    return CharSourceRange();
+    return {};
 
   return CharSourceRange::getCharRange(Begin, End);
 }
@@ -864,14 +873,14 @@ CharSourceRange Lexer::makeFileCharRange
   SourceLocation Begin = Range.getBegin();
   SourceLocation End = Range.getEnd();
   if (Begin.isInvalid() || End.isInvalid())
-    return CharSourceRange();
+    return {};
 
   if (Begin.isFileID() && End.isFileID())
     return makeRangeFromFileLocs(Range, SM, LangOpts);
 
   if (Begin.isMacroID() && End.isFileID()) {
     if (!isAtStartOfMacroExpansion(Begin, SM, LangOpts, &Begin))
-      return CharSourceRange();
+      return {};
     Range.setBegin(Begin);
     return makeRangeFromFileLocs(Range, SM, LangOpts);
   }
@@ -881,7 +890,7 @@ CharSourceRange Lexer::makeFileCharRange
                                                           &End)) ||
         (Range.isCharRange() && !isAtStartOfMacroExpansion(End, SM, LangOpts,
                                                            &End)))
-      return CharSourceRange();
+      return {};
     Range.setEnd(End);
     return makeRangeFromFileLocs(Range, SM, LangOpts);
   }
@@ -902,13 +911,13 @@ CharSourceRange Lexer::makeFileCharRange
   const SrcMgr::SLocEntry &BeginEntry = SM.getSLocEntry(SM.getFileID(Begin),
                                                         &Invalid);
   if (Invalid)
-    return CharSourceRange();
+    return {};
 
   if (BeginEntry.getExpansion().isMacroArgExpansion()) {
     const SrcMgr::SLocEntry &EndEntry = SM.getSLocEntry(SM.getFileID(End),
                                                         &Invalid);
     if (Invalid)
-      return CharSourceRange();
+      return {};
 
     if (EndEntry.getExpansion().isMacroArgExpansion() &&
         BeginEntry.getExpansion().getExpansionLocStart() ==
@@ -919,7 +928,7 @@ CharSourceRange Lexer::makeFileCharRange
     }
   }
 
-  return CharSourceRange();
+  return {};
 }
 
 StringRef Lexer::getSourceText(CharSourceRange Range,
@@ -929,21 +938,21 @@ StringRef Lexer::getSourceText(CharSourc
   Range = makeFileCharRange(Range, SM, LangOpts);
   if (Range.isInvalid()) {
     if (Invalid) *Invalid = true;
-    return StringRef();
+    return {};
   }
 
   // Break down the source location.
   std::pair<FileID, unsigned> beginInfo = SM.getDecomposedLoc(Range.getBegin());
   if (beginInfo.first.isInvalid()) {
     if (Invalid) *Invalid = true;
-    return StringRef();
+    return {};
   }
 
   unsigned EndOffs;
   if (!SM.isInFileID(Range.getEnd(), beginInfo.first, &EndOffs) ||
       beginInfo.second > EndOffs) {
     if (Invalid) *Invalid = true;
-    return StringRef();
+    return {};
   }
 
   // Try to the load the file buffer.
@@ -951,7 +960,7 @@ StringRef Lexer::getSourceText(CharSourc
   StringRef file = SM.getBufferData(beginInfo.first, &invalidTemp);
   if (invalidTemp) {
     if (Invalid) *Invalid = true;
-    return StringRef();
+    return {};
   }
 
   if (Invalid) *Invalid = false;
@@ -1015,7 +1024,7 @@ StringRef Lexer::getImmediateMacroNameFo
   // If the macro's spelling has no FileID, then it's actually a token paste
   // or stringization (or similar) and not a macro at all.
   if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc))))
-    return StringRef();
+    return {};
 
   // Find the spelling location of the start of the non-argument expansion
   // range. This is where the macro name was spelled in order to begin
@@ -1057,17 +1066,17 @@ bool Lexer::isNewLineEscaped(const char
 StringRef Lexer::getIndentationForLine(SourceLocation Loc,
                                        const SourceManager &SM) {
   if (Loc.isInvalid() || Loc.isMacroID())
-    return "";
+    return {};
   std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
   if (LocInfo.first.isInvalid())
-    return "";
+    return {};
   bool Invalid = false;
   StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
   if (Invalid)
-    return "";
+    return {};
   const char *Line = findBeginningOfLine(Buffer, LocInfo.second);
   if (!Line)
-    return "";
+    return {};
   StringRef Rest = Buffer.substr(Line - Buffer.data());
   size_t NumWhitespaceChars = Rest.find_first_not_of(" \t");
   return NumWhitespaceChars == StringRef::npos
@@ -1259,7 +1268,7 @@ SourceLocation Lexer::findLocationAfterT
     const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine) {
   Optional<Token> Tok = findNextToken(Loc, SM, LangOpts);
   if (!Tok || Tok->isNot(TKind))
-    return SourceLocation();
+    return {};
   SourceLocation TokenLoc = Tok->getLocation();
 
   // Calculate how much whitespace needs to be skipped if any.
@@ -1300,7 +1309,6 @@ SourceLocation Lexer::findLocationAfterT
 ///
 /// NOTE: When this method is updated, getCharAndSizeSlowNoWarn (below) should
 /// be updated to match.
-///
 char Lexer::getCharAndSizeSlow(const char *Ptr, unsigned &Size,
                                Token *Tok) {
   // If we have a slash, look for an escaped newline.
@@ -1595,7 +1603,6 @@ FinishIdentifier:
       CurPtr = ConsumeChar(CurPtr, Size, Result);
       C = getCharAndSize(CurPtr, Size);
       continue;
-
     } else if (C == '\\' && tryConsumeIdentifierUCN(CurPtr, Size, Result)) {
       C = getCharAndSize(CurPtr, Size);
       continue;
@@ -2026,7 +2033,6 @@ bool Lexer::LexCharConstant(Token &Resul
 /// Update BufferPtr to point to the next non-whitespace character and return.
 ///
 /// This method forms a token and returns true if KeepWhitespaceMode is enabled.
-///
 bool Lexer::SkipWhitespace(Token &Result, const char *CurPtr,
                            bool &TokAtPhysicalStartOfLine) {
   // Whitespace - Skip it, then return the token after the whitespace.
@@ -2899,7 +2905,6 @@ uint32_t Lexer::tryReadUCN(const char *&
     }
 
     return 0;
-
   } else if (CodePoint >= 0xD800 && CodePoint <= 0xDFFF) {
     // C++03 allows UCNs representing surrogate characters. C99 and C++11 don't.
     // We don't use isLexingRawMode() here because we need to diagnose bad

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- Pragma.cpp - Pragma registration and handling --------------------===//
+//===- Pragma.cpp - Pragma registration and handling ----------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -13,15 +13,21 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Lex/Pragma.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/ModuleLoader.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorLexer.h"
@@ -30,25 +36,27 @@
 #include "clang/Lex/TokenLexer.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include <algorithm>
 #include <cassert>
+#include <cstddef>
 #include <cstdint>
 #include <limits>
 #include <string>
+#include <utility>
 #include <vector>
 
 using namespace clang;
 
 // Out-of-line destructor to provide a home for the class.
-PragmaHandler::~PragmaHandler() {
-}
+PragmaHandler::~PragmaHandler() = default;
 
 //===----------------------------------------------------------------------===//
 // EmptyPragmaHandler Implementation.
@@ -144,15 +152,14 @@ namespace {
 class LexingFor_PragmaRAII {
   Preprocessor &PP;
   bool InMacroArgPreExpansion;
-  bool Failed;
+  bool Failed = false;
   Token &OutTok;
   Token PragmaTok;
 
 public:
   LexingFor_PragmaRAII(Preprocessor &PP, bool InMacroArgPreExpansion,
                        Token &Tok)
-    : PP(PP), InMacroArgPreExpansion(InMacroArgPreExpansion),
-      Failed(false), OutTok(Tok) {
+      : PP(PP), InMacroArgPreExpansion(InMacroArgPreExpansion), OutTok(Tok) {
     if (InMacroArgPreExpansion) {
       PragmaTok = OutTok;
       PP.EnableBacktrackAtThisPos();
@@ -186,13 +193,12 @@ public:
   }
 };
 
-} // end anonymous namespace
+} // namespace
 
 /// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then
 /// return the first token after the directive.  The _Pragma token has just
 /// been read into 'Tok'.
 void Preprocessor::Handle_Pragma(Token &Tok) {
-
   // This works differently if we are pre-expanding a macro argument.
   // In that case we don't actually "activate" the pragma now, we only lex it
   // until we are sure it is lexically correct and then we backtrack so that
@@ -381,7 +387,6 @@ void Preprocessor::HandleMicrosoft__prag
 }
 
 /// HandlePragmaOnce - Handle \#pragma once.  OnceTok is the 'once'.
-///
 void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
   // Don't honor the 'once' when handling the primary source file, unless
   // this is a prefix to a TU, which indicates we're generating a PCH file, or
@@ -406,7 +411,6 @@ void Preprocessor::HandlePragmaMark() {
 }
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 'poison'.
-///
 void Preprocessor::HandlePragmaPoison() {
   Token Tok;
 
@@ -461,7 +465,6 @@ void Preprocessor::HandlePragmaSystemHea
   // Mark the file as a system header.
   HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry());
 
-
   PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation());
   if (PLoc.isInvalid())
     return;
@@ -482,7 +485,6 @@ void Preprocessor::HandlePragmaSystemHea
 }
 
 /// HandlePragmaDependency - Handle \#pragma GCC dependency "foo" blah.
-///
 void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
   Token FilenameTok;
   CurPPLexer->LexIncludeFilename(FilenameTok);
@@ -623,7 +625,7 @@ void Preprocessor::HandlePragmaPopMacro(
   if (!IdentInfo) return;
 
   // Find the vector<MacroInfo*> associated with the macro.
-  llvm::DenseMap<IdentifierInfo*, std::vector<MacroInfo*> >::iterator iter =
+  llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>::iterator iter =
     PragmaPushMacroInfo.find(IdentInfo);
   if (iter != PragmaPushMacroInfo.end()) {
     // Forget the MacroInfo currently associated with IdentInfo.
@@ -962,6 +964,7 @@ namespace {
 /// PragmaOnceHandler - "\#pragma once" marks the file as atomically included.
 struct PragmaOnceHandler : public PragmaHandler {
   PragmaOnceHandler() : PragmaHandler("once") {}
+
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &OnceTok) override {
     PP.CheckEndOfDirective("pragma once");
@@ -1116,7 +1119,6 @@ struct PragmaDebugHandler : public Pragm
 #ifdef _MSC_VER
     #pragma warning(default : 4717)
 #endif
-
 };
 
 /// PragmaDiagnosticHandler - e.g. '\#pragma GCC diagnostic ignored "-Wformat"'
@@ -1125,8 +1127,8 @@ private:
   const char *Namespace;
 
 public:
-  explicit PragmaDiagnosticHandler(const char *NS) :
-    PragmaHandler("diagnostic"), Namespace(NS) {}
+  explicit PragmaDiagnosticHandler(const char *NS)
+      : PragmaHandler("diagnostic"), Namespace(NS) {}
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &DiagToken) override {
@@ -1330,6 +1332,7 @@ struct PragmaWarningHandler : public Pra
 /// PragmaIncludeAliasHandler - "\#pragma include_alias("...")".
 struct PragmaIncludeAliasHandler : public PragmaHandler {
   PragmaIncludeAliasHandler() : PragmaHandler("include_alias") {}
+
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &IncludeAliasTok) override {
     PP.HandlePragmaIncludeAlias(IncludeAliasTok);
@@ -1370,7 +1373,8 @@ private:
 public:
   PragmaMessageHandler(PPCallbacks::PragmaMessageKind Kind,
                        StringRef Namespace = StringRef())
-    : PragmaHandler(PragmaKind(Kind, true)), Kind(Kind), Namespace(Namespace) {}
+      : PragmaHandler(PragmaKind(Kind, true)), Kind(Kind),
+        Namespace(Namespace) {}
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &Tok) override {
@@ -1615,8 +1619,7 @@ struct PragmaSTDC_FENV_ACCESSHandler : p
 
 /// PragmaSTDC_CX_LIMITED_RANGEHandler - "\#pragma STDC CX_LIMITED_RANGE ...".
 struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
-  PragmaSTDC_CX_LIMITED_RANGEHandler()
-    : PragmaHandler("CX_LIMITED_RANGE") {}
+  PragmaSTDC_CX_LIMITED_RANGEHandler() : PragmaHandler("CX_LIMITED_RANGE") {}
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &Tok) override {
@@ -1627,7 +1630,7 @@ struct PragmaSTDC_CX_LIMITED_RANGEHandle
 
 /// PragmaSTDC_UnknownHandler - "\#pragma STDC ...".
 struct PragmaSTDC_UnknownHandler : public PragmaHandler {
-  PragmaSTDC_UnknownHandler() {}
+  PragmaSTDC_UnknownHandler() = default;
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &UnknownTok) override {
@@ -1763,7 +1766,7 @@ struct PragmaAssumeNonNullHandler : publ
 /// <a href="http://msdn.microsoft.com/en-us/library/b6xkz944(v=vs.80).aspx">editor-only</a>
 /// pragma, just skipped by compiler.
 struct PragmaRegionHandler : public PragmaHandler {
-  PragmaRegionHandler(const char *pragma) : PragmaHandler(pragma) { }
+  PragmaRegionHandler(const char *pragma) : PragmaHandler(pragma) {}
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
                     Token &NameTok) override {
@@ -1774,7 +1777,7 @@ struct PragmaRegionHandler : public Prag
   }
 };
 
-} // end anonymous namespace
+} // namespace
 
 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
 /// \#pragma GCC poison/system_header/dependency and \#pragma once.

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- PreprocessingRecord.cpp - Record of Preprocessing ------*- C++ -*-===//
+//===- PreprocessingRecord.cpp - Record of Preprocessing ------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -11,15 +11,34 @@
 //  of what occurred during preprocessing, and its helpers.
 //
 //===----------------------------------------------------------------------===//
+
 #include "clang/Lex/PreprocessingRecord.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Token.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Capacity.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <cstring>
+#include <iterator>
+#include <utility>
+#include <vector>
 
 using namespace clang;
 
-ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() { }
+ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() =
+    default;
 
 InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
                                        InclusionKind Kind, StringRef FileName,
@@ -33,10 +52,7 @@ InclusionDirective::InclusionDirective(P
   this->FileName = StringRef(Memory, FileName.size());
 }
 
-PreprocessingRecord::PreprocessingRecord(SourceManager &SM)
-  : SourceMgr(SM),
-    ExternalSource(nullptr) {
-}
+PreprocessingRecord::PreprocessingRecord(SourceManager &SM) : SourceMgr(SM) {}
 
 /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities
 /// that source range \p Range encompasses.
@@ -166,7 +182,7 @@ template <SourceLocation (SourceRange::*
 struct PPEntityComp {
   const SourceManager &SM;
 
-  explicit PPEntityComp(const SourceManager &SM) : SM(SM) { }
+  explicit PPEntityComp(const SourceManager &SM) : SM(SM) {}
 
   bool operator()(PreprocessedEntity *L, PreprocessedEntity *R) const {
     SourceLocation LHS = getLoc(L);
@@ -190,7 +206,7 @@ struct PPEntityComp {
   }
 };
 
-}
+} // namespace
 
 unsigned PreprocessingRecord::findBeginLocalPreprocessedEntity(
                                                      SourceLocation Loc) const {
@@ -271,7 +287,7 @@ PreprocessingRecord::addPreprocessedEnti
   //  FM(M1, M2)
   // \endcode
 
-  typedef std::vector<PreprocessedEntity *>::iterator pp_iter;
+  using pp_iter = std::vector<PreprocessedEntity *>::iterator;
 
   // Usually there are few macro expansions when defining the filename, do a
   // linear search for a few entities.
@@ -430,7 +446,7 @@ void PreprocessingRecord::MacroUndefined
 
 void PreprocessingRecord::InclusionDirective(
     SourceLocation HashLoc,
-    const clang::Token &IncludeTok,
+    const Token &IncludeTok,
     StringRef FileName,
     bool IsAngled,
     CharSourceRange FilenameRange,
@@ -470,10 +486,10 @@ void PreprocessingRecord::InclusionDirec
       EndLoc = EndLoc.getLocWithOffset(-1); // the InclusionDirective expects
                                             // a token range.
   }
-  clang::InclusionDirective *ID
-    = new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled,
-                                            (bool)Imported,
-                                            File, SourceRange(HashLoc, EndLoc));
+  clang::InclusionDirective *ID =
+      new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled,
+                                            (bool)Imported, File,
+                                            SourceRange(HashLoc, EndLoc));
   addPreprocessedEntity(ID);
 }
 

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=320207&r1=320206&r2=320207&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Fri Dec  8 14:39:26 2017
@@ -1,4 +1,4 @@
-//===--- TokenLexer.cpp - Lex from a token stream -------------------------===//
+//===- TokenLexer.cpp - Lex from a token stream ---------------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -12,13 +12,25 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Lex/TokenLexer.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/LexDiagnostic.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
 #include "clang/Lex/VariadicMacroSupport.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include <cassert>
+#include <cstring>
 
 using namespace clang;
 
@@ -238,7 +250,6 @@ void TokenLexer::ExpandFunctionArguments
   VAOptExpansionContext VCtx(PP);
   
   for (unsigned I = 0, E = NumTokens; I != E; ++I) {
-    
     const Token &CurTok = Tokens[I];
     // We don't want a space for the next token after a paste
     // operator.  In valid code, the token will get smooshed onto the
@@ -287,7 +298,6 @@ void TokenLexer::ExpandFunctionArguments
         }
         // ... else the macro was called with variadic arguments, and we do not
         // have a closing rparen - so process this token normally.
-
       } else {
         // Current token is the closing r_paren which marks the end of the
         // __VA_OPT__ invocation, so handle any place-marker pasting (if
@@ -573,7 +583,6 @@ static bool isWideStringLiteralFromMacro
 }
 
 /// Lex - Lex and return a token from this macro stream.
-///
 bool TokenLexer::Lex(Token &Tok) {
   // Lexing off the end of the macro, pop this macro off the expansion stack.
   if (isAtEnd()) {
@@ -677,6 +686,7 @@ bool TokenLexer::Lex(Token &Tok) {
 bool TokenLexer::pasteTokens(Token &Tok) {
   return pasteTokens(Tok, llvm::makeArrayRef(Tokens, NumTokens), CurTokenIdx);
 }
+
 /// LHSTok is the LHS of a ## operator, and CurTokenIdx is the ##
 /// operator.  Read the ## and RHS, and paste the LHS/RHS together.  If there
 /// are more ## after it, chomp them iteratively.  Return the result as LHSTok.




More information about the cfe-commits mailing list