summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h')
-rw-r--r--clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h72
1 files changed, 41 insertions, 31 deletions
diff --git a/clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h b/clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h
index f70f5736f0c..db37561fb9e 100644
--- a/clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h
+++ b/clang-tools-extra/clang-modernize/LoopConvert/LoopActions.h
@@ -34,30 +34,47 @@ enum LoopFixerKind {
LFK_PseudoArray
};
+struct TUTrackingInfo {
+
+ /// \brief Reset and initialize per-TU tracking information.
+ ///
+ /// Must be called before using container accessors.
+ void reset() {
+ ParentFinder.reset(new StmtAncestorASTVisitor);
+ GeneratedDecls.clear();
+ ReplacedVars.clear();
+ }
+
+ /// \name Accessors
+ /// \{
+ StmtAncestorASTVisitor &getParentFinder() { return *ParentFinder; }
+ StmtGeneratedVarNameMap &getGeneratedDecls() { return GeneratedDecls; }
+ ReplacedVarsMap &getReplacedVars() { return ReplacedVars; }
+ /// \}
+
+private:
+ llvm::OwningPtr<StmtAncestorASTVisitor> ParentFinder;
+ StmtGeneratedVarNameMap GeneratedDecls;
+ ReplacedVarsMap ReplacedVars;
+};
+
/// \brief The callback to be used for loop migration matchers.
///
/// The callback does extra checking not possible in matchers, and attempts to
/// convert the for loop, if possible.
class LoopFixer : public clang::ast_matchers::MatchFinder::MatchCallback {
- public:
- LoopFixer(StmtAncestorASTVisitor *ParentFinder,
- StmtGeneratedVarNameMap *GeneratedDecls,
- ReplacedVarsMap *ReplacedVarRanges, unsigned *AcceptedChanges,
- unsigned *DeferredChanges, unsigned *RejectedChanges,
- RiskLevel MaxRisk, LoopFixerKind FixerKind, Transform &Owner)
- : ParentFinder(ParentFinder),
- GeneratedDecls(GeneratedDecls), ReplacedVarRanges(ReplacedVarRanges),
- AcceptedChanges(AcceptedChanges), DeferredChanges(DeferredChanges),
- RejectedChanges(RejectedChanges), MaxRisk(MaxRisk),
- FixerKind(FixerKind), Owner(Owner) {}
+public:
+ LoopFixer(TUTrackingInfo &TUInfo, unsigned *AcceptedChanges,
+ unsigned *DeferredChanges, unsigned *RejectedChanges,
+ RiskLevel MaxRisk, LoopFixerKind FixerKind, Transform &Owner)
+ : TUInfo(TUInfo), AcceptedChanges(AcceptedChanges),
+ DeferredChanges(DeferredChanges), RejectedChanges(RejectedChanges),
+ MaxRisk(MaxRisk), FixerKind(FixerKind), Owner(Owner) {}
- virtual void
- run(const clang::ast_matchers::MatchFinder::MatchResult &Result);
+ virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &Result);
- private:
- StmtAncestorASTVisitor *ParentFinder;
- StmtGeneratedVarNameMap *GeneratedDecls;
- ReplacedVarsMap *ReplacedVarRanges;
+private:
+ TUTrackingInfo &TUInfo;
unsigned *AcceptedChanges;
unsigned *DeferredChanges;
unsigned *RejectedChanges;
@@ -67,17 +84,12 @@ class LoopFixer : public clang::ast_matchers::MatchFinder::MatchCallback {
/// \brief Computes the changes needed to convert a given for loop, and
/// applies it.
- void doConversion(clang::ASTContext *Context,
- const clang::VarDecl *IndexVar,
+ void doConversion(clang::ASTContext *Context, const clang::VarDecl *IndexVar,
const clang::VarDecl *MaybeContainer,
- llvm::StringRef ContainerString,
- const UsageResult &Usages,
- const clang::DeclStmt *AliasDecl,
- bool AliasUseRequired,
- bool AliasFromForInit,
- const clang::ForStmt *TheLoop,
- bool ContainerNeedsDereference,
- bool DerefByValue,
+ llvm::StringRef ContainerString, const UsageResult &Usages,
+ const clang::DeclStmt *AliasDecl, bool AliasUseRequired,
+ bool AliasFromForInit, const clang::ForStmt *TheLoop,
+ bool ContainerNeedsDereference, bool DerefByValue,
bool DerefByConstRef);
/// \brief Given a loop header that would be convertible, discover all usages
@@ -87,10 +99,8 @@ class LoopFixer : public clang::ast_matchers::MatchFinder::MatchCallback {
const clang::VarDecl *EndVar,
const clang::Expr *ContainerExpr,
const clang::Expr *BoundExpr,
- bool ContainerNeedsDereference,
- bool DerefByValue,
- bool DerefByConstRef,
- const clang::ForStmt *TheLoop,
+ bool ContainerNeedsDereference, bool DerefByValue,
+ bool DerefByConstRef, const clang::ForStmt *TheLoop,
Confidence ConfidenceLevel);
/// \brief Determine if the change should be deferred or rejected, returning
OpenPOWER on IntegriCloud