r285182 - [PP] Replace some uses of unsigned with size_t

Erik Verbruggen via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 26 02:58:32 PDT 2016


Author: erikjv
Date: Wed Oct 26 04:58:31 2016
New Revision: 285182

URL: http://llvm.org/viewvc/llvm-project?rev=285182&view=rev
Log:
[PP] Replace some uses of unsigned with size_t

All values are returned by a method as size_t, and subsequently passed
to functions taking a size_t, or used where a size_t is also valid.
Better still, two loops (which had an unsigned), can be replaced by
a range-based for loop.

Differential Revision: http://reviews.llvm.org/D25939

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=285182&r1=285181&r2=285182&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Oct 26 04:58:31 2016
@@ -471,7 +471,7 @@ void Preprocessor::SkipExcludedCondition
       Directive = RI;
     } else {
       std::string DirectiveStr = getSpelling(Tok);
-      unsigned IdLen = DirectiveStr.size();
+      size_t IdLen = DirectiveStr.size();
       if (IdLen >= 20) {
         CurPPLexer->ParsingPreprocessorDirective = false;
         // Restore comment saving mode.
@@ -801,8 +801,7 @@ const FileEntry *Preprocessor::LookupFil
     // headers included by quoted include directives.
     // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
     if (LangOpts.MSVCCompat && !isAngled) {
-      for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-        IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
+      for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
         if (IsFileLexer(ISEntry))
           if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
             Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
@@ -865,8 +864,7 @@ const FileEntry *Preprocessor::LookupFil
     }
   }
 
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-    IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
     if (IsFileLexer(ISEntry)) {
       if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
         if ((FE = HeaderInfo.LookupSubframeworkHeader(
@@ -1567,7 +1565,7 @@ bool Preprocessor::ConcatenateIncludeNam
       FilenameBuffer.push_back(' ');
 
     // Get the spelling of the token, directly into FilenameBuffer if possible.
-    unsigned PreAppendSize = FilenameBuffer.size();
+    size_t PreAppendSize = FilenameBuffer.size();
     FilenameBuffer.resize(PreAppendSize+CurTok.getLength());
 
     const char *BufPtr = &FilenameBuffer[PreAppendSize];
@@ -1618,7 +1616,7 @@ static void diagnoseAutoModuleImport(
   assert(PP.getLangOpts().ObjC2 && "no import syntax available");
 
   SmallString<128> PathString;
-  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+  for (size_t I = 0, N = Path.size(); I != N; ++I) {
     if (I)
       PathString += '.';
     PathString += Path[I].first->getName();




More information about the cfe-commits mailing list