OS.indent(IndentLevel * 2);
}
-namespace {
-struct BaseOffsetComparator {
- const ASTRecordLayout &RL;
- BaseOffsetComparator(const ASTRecordLayout &RL) : RL(RL) {}
- bool operator()(const CXXRecordDecl *L, const CXXRecordDecl *R) const {
- return RL.getBaseClassOffset(L) < RL.getBaseClassOffset(R);
- }
-};
-}
-
static void DumpCXXRecordLayout(raw_ostream &OS,
const CXXRecordDecl *RD, const ASTContext &C,
CharUnits Offset,
}
// Sort nvbases by offset.
- BaseOffsetComparator Cmp(Layout);
- std::stable_sort(Bases.begin(), Bases.end(), Cmp);
+ std::stable_sort(Bases.begin(), Bases.end(),
+ [&](const CXXRecordDecl *L, const CXXRecordDecl *R) {
+ return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R);
+ });
// Dump (non-virtual) bases
for (SmallVectorImpl<const CXXRecordDecl *>::iterator I = Bases.begin(),
}
}
-struct ItaniumThunkInfoComparator {
- bool operator() (const ThunkInfo &LHS, const ThunkInfo &RHS) {
- assert(LHS.Method == 0);
- assert(RHS.Method == 0);
-
- if (LHS.This != RHS.This)
- return LHS.This < RHS.This;
-
- if (LHS.Return != RHS.Return)
- return LHS.Return < RHS.Return;
-
- return false;
- }
-};
-
/// dumpLayout - Dump the vtable layout.
void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) {
// FIXME: write more tests that actually use the dumpLayout output to prevent
ThunkInfoVectorTy ThunksVector = Thunks[MD];
std::sort(ThunksVector.begin(), ThunksVector.end(),
- ItaniumThunkInfoComparator());
+ [](const ThunkInfo &LHS, const ThunkInfo &RHS) {
+ assert(LHS.Method == 0 && RHS.Method == 0);
+
+ if (LHS.This != RHS.This)
+ return LHS.This < RHS.This;
+ return LHS.Return < RHS.Return;
+ });
Out << "Thunks for '" << MethodName << "' (" << ThunksVector.size();
Out << (ThunksVector.size() == 1 ? " entry" : " entries") << ").\n";
Out << '\n';
}
-
-struct VTableThunksComparator {
- bool operator()(const VTableLayout::VTableThunkTy &LHS,
- const VTableLayout::VTableThunkTy &RHS) {
- if (LHS.first == RHS.first) {
- assert(LHS.second == RHS.second &&
- "Different thunks should have unique indices!");
- }
- return LHS.first < RHS.first;
- }
-};
}
VTableLayout::VTableLayout(uint64_t NumVTableComponents,
this->VTableThunks.get());
std::sort(this->VTableThunks.get(),
this->VTableThunks.get() + NumVTableThunks,
- VTableThunksComparator());
+ [](const VTableLayout::VTableThunkTy &LHS,
+ const VTableLayout::VTableThunkTy &RHS) {
+ assert((LHS.first != RHS.first || LHS.second == RHS.second) &&
+ "Different thunks should have unique indices!");
+ return LHS.first < RHS.first;
+ });
}
VTableLayout::~VTableLayout() { }
}
}
-namespace {
-struct MicrosoftThunkInfoStableSortComparator {
- bool operator() (const ThunkInfo &LHS, const ThunkInfo &RHS) {
- if (LHS.This != RHS.This)
- return LHS.This < RHS.This;
-
- if (LHS.Return != RHS.Return)
- return LHS.Return < RHS.Return;
-
- // Keep different thunks with the same adjustments in the order they
- // were put into the vector.
- return false;
- }
-};
-}
-
static void dumpMicrosoftThunkAdjustment(const ThunkInfo &TI, raw_ostream &Out,
bool ContinueFirstLine) {
const ReturnAdjustment &R = TI.Return;
ThunkInfoVectorTy ThunksVector = Thunks[MD];
std::stable_sort(ThunksVector.begin(), ThunksVector.end(),
- MicrosoftThunkInfoStableSortComparator());
+ [](const ThunkInfo &LHS, const ThunkInfo &RHS) {
+ // Keep different thunks with the same adjustments in the order they
+ // were put into the vector.
+ if (LHS.This != RHS.This)
+ return LHS.This < RHS.This;
+ return LHS.Return < RHS.Return;
+ });
Out << "Thunks for '" << MethodName << "' (" << ThunksVector.size();
Out << (ThunksVector.size() == 1 ? " entry" : " entries") << ").\n";
return Copy;
}
-namespace {
-// Wrapper for FilterCallback to make operator() nonvirtual so it
-// can be passed by value to std::remove_if
-class FilterWrapper {
- const MultilibSet::FilterCallback &F;
-public:
- FilterWrapper(const MultilibSet::FilterCallback &F) : F(F) {}
- bool operator()(const Multilib &M) const { return F(M); }
-};
-} // end anonymous namespace
-
void MultilibSet::filterInPlace(const MultilibSet::FilterCallback &F,
multilib_list &Ms) {
- Ms.erase(std::remove_if(Ms.begin(), Ms.end(), FilterWrapper(F)), Ms.end());
+ Ms.erase(std::remove_if(Ms.begin(), Ms.end(),
+ [&F](const Multilib &M) { return F(M); }),
+ Ms.end());
}
raw_ostream &clang::driver::operator<<(raw_ostream &OS, const MultilibSet &MS) {
Data.Instance.ExecuteAction(Data.CreateModuleAction);
}
-namespace {
- /// \brief Function object that checks with the given macro definition should
- /// be removed, because it is one of the ignored macros.
- class RemoveIgnoredMacro {
- const HeaderSearchOptions &HSOpts;
-
- public:
- explicit RemoveIgnoredMacro(const HeaderSearchOptions &HSOpts)
- : HSOpts(HSOpts) { }
-
- bool operator()(const std::pair<std::string, bool> &def) const {
- StringRef MacroDef = def.first;
- return HSOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first) > 0;
- }
- };
-}
-
/// \brief Compile a module file for the given module, using the options
/// provided by the importing compiler instance.
static void compileModule(CompilerInstance &ImportingInstance,
// Remove any macro definitions that are explicitly ignored by the module.
// They aren't supposed to affect how the module is built anyway.
const HeaderSearchOptions &HSOpts = Invocation->getHeaderSearchOpts();
- PPOpts.Macros.erase(std::remove_if(PPOpts.Macros.begin(), PPOpts.Macros.end(),
- RemoveIgnoredMacro(HSOpts)),
- PPOpts.Macros.end());
-
+ PPOpts.Macros.erase(
+ std::remove_if(PPOpts.Macros.begin(), PPOpts.Macros.end(),
+ [&HSOpts](const std::pair<std::string, bool> &def) {
+ StringRef MacroDef = def.first;
+ return HSOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first) > 0;
+ }),
+ PPOpts.Macros.end());
// Note the name of the module we're building.
Invocation->getLangOpts()->CurrentModule = Module->getTopLevelModuleName();
SmallVector<int,200> m_byteToColumn;
SmallVector<int,200> m_columnToByte;
};
-
-// used in assert in selectInterestingSourceRegion()
-struct char_out_of_range {
- const char lower,upper;
- char_out_of_range(char lower, char upper) :
- lower(lower), upper(upper) {}
- bool operator()(char c) { return c < lower || upper < c; }
-};
} // end anonymous namespace
/// \brief When the source code line we want to print is too long for
// No special characters are allowed in CaretLine.
assert(CaretLine.end() ==
std::find_if(CaretLine.begin(), CaretLine.end(),
- char_out_of_range(' ','~')));
+ [](char c) { return c < ' ' || '~' < c; }));
// Find the slice that we need to display the full caret line
// correctly.
}
-namespace {
-typedef std::pair<const Stmt *,
- sema::FunctionScopeInfo::WeakObjectUseMap::const_iterator>
- StmtUsesPair;
-
-class StmtUseSorter {
- const SourceManager &SM;
-
-public:
- explicit StmtUseSorter(const SourceManager &SM) : SM(SM) { }
-
- bool operator()(const StmtUsesPair &LHS, const StmtUsesPair &RHS) {
- return SM.isBeforeInTranslationUnit(LHS.first->getLocStart(),
- RHS.first->getLocStart());
- }
-};
-}
-
static bool isInLoop(const ASTContext &Ctx, const ParentMap &PM,
const Stmt *S) {
assert(S);
typedef sema::FunctionScopeInfo::WeakObjectProfileTy WeakObjectProfileTy;
typedef sema::FunctionScopeInfo::WeakObjectUseMap WeakObjectUseMap;
typedef sema::FunctionScopeInfo::WeakUseVector WeakUseVector;
+ typedef std::pair<const Stmt *, WeakObjectUseMap::const_iterator>
+ StmtUsesPair;
ASTContext &Ctx = S.getASTContext();
return;
// Sort by first use so that we emit the warnings in a deterministic order.
+ SourceManager &SM = S.getSourceManager();
std::sort(UsesByStmt.begin(), UsesByStmt.end(),
- StmtUseSorter(S.getSourceManager()));
+ [&SM](const StmtUsesPair &LHS, const StmtUsesPair &RHS) {
+ return SM.isBeforeInTranslationUnit(LHS.first->getLocStart(),
+ RHS.first->getLocStart());
+ });
// Classify the current code body for better warning text.
// This enum should stay in sync with the cases in
}
}
-
namespace {
-struct SLocSort {
- bool operator()(const UninitUse &a, const UninitUse &b) {
- // Prefer a more confident report over a less confident one.
- if (a.getKind() != b.getKind())
- return a.getKind() > b.getKind();
- SourceLocation aLoc = a.getUser()->getLocStart();
- SourceLocation bLoc = b.getUser()->getLocStart();
- return aLoc.getRawEncoding() < bLoc.getRawEncoding();
- }
-};
-
class UninitValsDiagReporter : public UninitVariablesHandler {
Sema &S;
typedef SmallVector<UninitUse, 2> UsesVec;
// Sort the uses by their SourceLocations. While not strictly
// guaranteed to produce them in line/column order, this will provide
// a stable ordering.
- std::sort(vec->begin(), vec->end(), SLocSort());
-
+ std::sort(vec->begin(), vec->end(),
+ [](const UninitUse &a, const UninitUse &b) {
+ // Prefer a more confident report over a less confident one.
+ if (a.getKind() != b.getKind())
+ return a.getKind() > b.getKind();
+ return a.getUser()->getLocStart() < b.getUser()->getLocStart();
+ });
+
for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve;
++vi) {
// If we have self-init, downgrade all uses to 'may be uninitialized'.
return false;
}
-namespace {
- struct SortUndefinedButUsed {
- const SourceManager &SM;
- explicit SortUndefinedButUsed(SourceManager &SM) : SM(SM) {}
-
- bool operator()(const std::pair<NamedDecl *, SourceLocation> &l,
- const std::pair<NamedDecl *, SourceLocation> &r) const {
- if (l.second.isValid() && !r.second.isValid())
- return true;
- if (!l.second.isValid() && r.second.isValid())
- return false;
- if (l.second != r.second)
- return SM.isBeforeInTranslationUnit(l.second, r.second);
- return SM.isBeforeInTranslationUnit(l.first->getLocation(),
- r.first->getLocation());
- }
- };
-}
-
/// Obtains a sorted list of functions that are undefined but ODR-used.
void Sema::getUndefinedButUsed(
SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined) {
// Sort (in order of use site) so that we're not dependent on the iteration
// order through an llvm::DenseMap.
+ SourceManager &SM = Context.getSourceManager();
std::sort(Undefined.begin(), Undefined.end(),
- SortUndefinedButUsed(Context.getSourceManager()));
+ [&SM](const std::pair<NamedDecl *, SourceLocation> &l,
+ const std::pair<NamedDecl *, SourceLocation> &r) {
+ if (l.second.isValid() && !r.second.isValid())
+ return true;
+ if (!l.second.isValid() && r.second.isValid())
+ return false;
+ if (l.second != r.second)
+ return SM.isBeforeInTranslationUnit(l.second, r.second);
+ return SM.isBeforeInTranslationUnit(l.first->getLocation(),
+ r.first->getLocation());
+ });
}
/// checkUndefinedButUsed - Check for undefined objects with internal linkage
Results.data(),Results.size());
}
-namespace {
- struct IsBetterOverloadCandidate {
- Sema &S;
- SourceLocation Loc;
-
- public:
- explicit IsBetterOverloadCandidate(Sema &S, SourceLocation Loc)
- : S(S), Loc(Loc) { }
-
- bool
- operator()(const OverloadCandidate &X, const OverloadCandidate &Y) const {
- return isBetterOverloadCandidate(S, X, Y, Loc);
- }
- };
-}
-
static bool anyNullArguments(ArrayRef<Expr *> Args) {
if (Args.size() && !Args.data())
return true;
if (!CandidateSet.empty()) {
// Sort the overload candidate set by placing the best overloads first.
- std::stable_sort(CandidateSet.begin(), CandidateSet.end(),
- IsBetterOverloadCandidate(*this, Loc));
-
+ std::stable_sort(
+ CandidateSet.begin(), CandidateSet.end(),
+ [&](const OverloadCandidate &X, const OverloadCandidate &Y) {
+ return isBetterOverloadCandidate(*this, X, Y, Loc);
+ });
+
// Add the remaining viable overload candidates as code-completion reslults.
for (OverloadCandidateSet::iterator Cand = CandidateSet.begin(),
CandEnd = CandidateSet.end();
return NewModule? NewlyLoaded : AlreadyLoaded;
}
-namespace {
- /// \brief Predicate that checks whether a module file occurs within
- /// the given set.
- class IsInModuleFileSet : public std::unary_function<ModuleFile *, bool> {
- llvm::SmallPtrSet<ModuleFile *, 4> &Removed;
-
- public:
- IsInModuleFileSet(llvm::SmallPtrSet<ModuleFile *, 4> &Removed)
- : Removed(Removed) { }
-
- bool operator()(ModuleFile *MF) const {
- return Removed.count(MF);
- }
- };
-}
-
void ModuleManager::removeModules(ModuleIterator first, ModuleIterator last,
ModuleMap *modMap) {
if (first == last)
llvm::SmallPtrSet<ModuleFile *, 4> victimSet(first, last);
// Remove any references to the now-destroyed modules.
- IsInModuleFileSet checkInSet(victimSet);
+ std::function<bool(ModuleFile *)> checkInSet = [&](ModuleFile *MF) {
+ return victimSet.count(MF);
+ };
for (unsigned i = 0, n = Chain.size(); i != n; ++i) {
Chain[i]->ImportedBy.remove_if(checkInSet);
}
return b.getValue();
}
-namespace {
-struct CompareDiagnostics {
- // Compare if 'X' is "<" than 'Y'.
- bool operator()(const PathDiagnostic *X, const PathDiagnostic *Y) const {
- if (X == Y)
- return false;
- return compare(*X, *Y);
- }
-};
-}
-
void PathDiagnosticConsumer::FlushDiagnostics(
PathDiagnosticConsumer::FilesMade *Files) {
if (flushed)
// Sort the diagnostics so that they are always emitted in a deterministic
// order.
if (!BatchDiags.empty())
- std::sort(BatchDiags.begin(), BatchDiags.end(), CompareDiagnostics());
-
+ std::sort(BatchDiags.begin(), BatchDiags.end(),
+ [](const PathDiagnostic *X, const PathDiagnostic *Y) {
+ return X != Y && compare(*X, *Y);
+ });
+
FlushDiagnosticsImpl(BatchDiags, Files);
// Delete the flushed diagnostics.
}
}
-namespace {
- struct ContainerDeclsSort {
- SourceManager &SM;
- ContainerDeclsSort(SourceManager &sm) : SM(sm) {}
- bool operator()(Decl *A, Decl *B) {
- SourceLocation L_A = A->getLocStart();
- SourceLocation L_B = B->getLocStart();
- assert(L_A.isValid() && L_B.isValid());
- return SM.isBeforeInTranslationUnit(L_A, L_B);
- }
- };
-}
-
bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) {
// FIXME: Eventually convert back to just 'VisitDeclContext()'. Essentially
// an @implementation can lexically contain Decls that are not properly
// Now sort the Decls so that they appear in lexical order.
std::sort(DeclsInContainer.begin(), DeclsInContainer.end(),
- ContainerDeclsSort(SM));
+ [&SM](Decl *A, Decl *B) {
+ SourceLocation L_A = A->getLocStart();
+ SourceLocation L_B = B->getLocStart();
+ assert(L_A.isValid() && L_B.isValid());
+ return SM.isBeforeInTranslationUnit(L_A, L_B);
+ });
// Now visit the decls.
for (SmallVectorImpl<Decl*>::iterator I = DeclsInContainer.begin(),
std::string Name;
};
-
-struct RecordIndexElementSorter :
- public std::binary_function<RecordIndexElement, RecordIndexElement, bool> {
-
- bool operator()(RecordIndexElement const &Lhs,
- RecordIndexElement const &Rhs) const {
- return Lhs.Name < Rhs.Name;
- }
-
-};
-
} // end anonymous namespace.
namespace clang {
Index.push_back(RecordIndexElement(R));
}
- std::sort(Index.begin(), Index.end(), RecordIndexElementSorter());
+ std::sort(Index.begin(), Index.end(),
+ [](const RecordIndexElement &Lhs,
+ const RecordIndexElement &Rhs) { return Lhs.Name < Rhs.Name; });
for (unsigned i = 0, e = Index.size(); i != e; ++i) {
const RecordIndexElement &R = Index[i];