]> granicus.if.org Git - clang/commitdiff
[C++11] Revert uses of lambdas with array_pod_sort.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 7 Mar 2014 21:51:58 +0000 (21:51 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 7 Mar 2014 21:51:58 +0000 (21:51 +0000)
Looks like GCC implements the lambda->function pointer conversion differently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203293 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ReachableCode.cpp
lib/Frontend/PrintPreprocessedOutput.cpp
lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
tools/libclang/CIndex.cpp

index 1e5aa1224ba34f35b4b06677408bb58e0a91f49e..47f8f2b90cd37e488dd77601db1a71e5cb3360ac 100644 (file)
@@ -400,6 +400,15 @@ const Stmt *DeadCodeScan::findDeadCode(const clang::CFGBlock *Block) {
   return 0;
 }
 
+static int SrcCmp(const std::pair<const CFGBlock *, const Stmt *> *p1,
+                  const std::pair<const CFGBlock *, const Stmt *> *p2) {
+  if (p1->second->getLocStart() < p2->second->getLocStart())
+    return -1;
+  if (p2->second->getLocStart() < p1->second->getLocStart())
+    return 1;
+  return 0;
+}
+
 unsigned DeadCodeScan::scanBackwards(const clang::CFGBlock *Start,
                                      clang::reachable_code::Callback &CB) {
 
@@ -448,13 +457,7 @@ unsigned DeadCodeScan::scanBackwards(const clang::CFGBlock *Start,
   // If we didn't find a dead root, then report the dead code with the
   // earliest location.
   if (!DeferredLocs.empty()) {
-    llvm::array_pod_sort(DeferredLocs.begin(), DeferredLocs.end(),
-                         [](const DeferredLocsTy::value_type *p1,
-                            const DeferredLocsTy::value_type *p2) {
-      if (p1->second->getLocStart() != p2->second->getLocStart())
-        return p1->second->getLocStart() < p2->second->getLocStart() ? -1 : 1;
-      return 0;
-    });
+    llvm::array_pod_sort(DeferredLocs.begin(), DeferredLocs.end(), SrcCmp);
     for (DeferredLocsTy::iterator I = DeferredLocs.begin(),
          E = DeferredLocs.end(); I != E; ++I) {
       const CFGBlock *Block = I->first;
index 88e3b2212abed48c8f3eb9a9d02a3bbedd098b2f..20d7cd3a8c011cda1f57865fb7515beca8626d0b 100644 (file)
@@ -678,6 +678,11 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
   }
 }
 
+typedef std::pair<const IdentifierInfo *, MacroInfo *> id_macro_pair;
+static int MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS) {
+  return LHS->first->getName().compare(RHS->first->getName());
+}
+
 static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
   // Ignore unknown pragmas.
   PP.AddPragmaHandler(new EmptyPragmaHandler());
@@ -690,17 +695,13 @@ static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
   do PP.Lex(Tok);
   while (Tok.isNot(tok::eof));
 
-  typedef std::pair<const IdentifierInfo *, MacroInfo *> id_macro_pair;
   SmallVector<id_macro_pair, 128> MacrosByID;
   for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
        I != E; ++I) {
     if (I->first->hasMacroDefinition())
       MacrosByID.push_back(id_macro_pair(I->first, I->second->getMacroInfo()));
   }
-  llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(),
-                       [](const id_macro_pair *LHS, const id_macro_pair *RHS) {
-    return LHS->first->getName().compare(RHS->first->getName());
-  });
+  llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);
 
   for (unsigned i = 0, e = MacrosByID.size(); i != e; ++i) {
     MacroInfo &MI = *MacrosByID[i].second;
index fbb130bc176a3f6f0d92e3b5a934e8dbe1fe6082..51e7a3d3ce34c5157352214e95fcaae27acb880c 100644 (file)
@@ -161,6 +161,11 @@ namespace {
 class ConfigDumper : public Checker< check::EndOfTranslationUnit > {
   typedef AnalyzerOptions::ConfigTable Table;
 
+  static int compareEntry(const Table::MapEntryTy *const *LHS,
+                          const Table::MapEntryTy *const *RHS) {
+    return (*LHS)->getKey().compare((*RHS)->getKey());
+  }
+
 public:
   void checkEndOfTranslationUnit(const TranslationUnitDecl *TU,
                                  AnalysisManager& mgr,
@@ -171,11 +176,7 @@ public:
     for (Table::const_iterator I = Config.begin(), E = Config.end(); I != E;
          ++I)
       Keys.push_back(&*I);
-    llvm::array_pod_sort(Keys.begin(), Keys.end(),
-                         [](const Table::MapEntryTy *const *LHS,
-                            const Table::MapEntryTy *const *RHS) {
-      return (*LHS)->getKey().compare((*RHS)->getKey());
-    });
+    llvm::array_pod_sort(Keys.begin(), Keys.end(), compareEntry);
 
     llvm::errs() << "[config]\n";
     for (unsigned I = 0, E = Keys.size(); I != E; ++I)
index ff0350aafc7a4a29e71e19c783016d85fb0617c8..d98acb197fa140e796a35d856aeff191c6143b7f 100644 (file)
@@ -762,6 +762,12 @@ bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
   return false;
 }
 
+/// \brief Compare two base or member initializers based on their source order.
+static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X,
+                                      CXXCtorInitializer *const *Y) {
+  return (*X)->getSourceOrder() - (*Y)->getSourceOrder();
+}
+
 bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
   unsigned NumParamList = ND->getNumTemplateParameterLists();
   for (unsigned i = 0; i < NumParamList; i++) {
@@ -816,12 +822,9 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
       }
       
       // Sort the initializers in source order
-      llvm::array_pod_sort(
-          WrittenInits.begin(), WrittenInits.end(),
-          [](CXXCtorInitializer *const *X, CXXCtorInitializer *const *Y) {
-            return (*X)->getSourceOrder() - (*Y)->getSourceOrder();
-          });
-
+      llvm::array_pod_sort(WrittenInits.begin(), WrittenInits.end(),
+                           &CompareCXXCtorInitializers);
+      
       // Visit the initializers in source order
       for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I) {
         CXXCtorInitializer *Init = WrittenInits[I];