1 //===-- loop-convert/LoopActions.h - C++11 For loop migration ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares matchers and callbacks for use in migrating C++ for loops.
12 //===----------------------------------------------------------------------===//
13 #ifndef _LLVM_TOOLS_CLANG_TOOLS_LOOP_CONVERT_LOOPACTIONS_H_
14 #define _LLVM_TOOLS_CLANG_TOOLS_LOOP_CONVERT_LOOPACTIONS_H_
16 #include "StmtAncestor.h"
17 #include "clang/Tooling/Refactoring.h"
18 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/RecursiveASTVisitor.h"
20 #include "clang/ASTMatchers/ASTMatchFinder.h"
23 namespace loop_migrate {
26 // The main computational result of ForLoopIndexUseVisitor.
27 typedef llvm::SmallVector<Usage, 8> UsageResult;
29 /// \brief The level of safety to require of transformations.
30 enum TranslationConfidenceKind {
42 /// \brief The callback to be used for loop migration matchers.
44 /// The callback does extra checking not possible in matchers, and attempts to
45 /// convert the for loop, if possible.
46 class LoopFixer : public ast_matchers::MatchFinder::MatchCallback {
48 LoopFixer(StmtAncestorASTVisitor *ParentFinder,
49 tooling::Replacements *Replace,
50 StmtGeneratedVarNameMap *GeneratedDecls,
51 ReplacedVarsMap *ReplacedVarRanges,
52 unsigned *AcceptedChanges, unsigned *DeferredChanges,
53 unsigned *RejectedChanges, bool CountOnly,
54 TranslationConfidenceKind RequiredConfidenceLevel,
55 LoopFixerKind FixerKind) :
56 ParentFinder(ParentFinder), Replace(Replace),
57 GeneratedDecls(GeneratedDecls), ReplacedVarRanges(ReplacedVarRanges),
58 AcceptedChanges(AcceptedChanges), DeferredChanges(DeferredChanges),
59 RejectedChanges(RejectedChanges), CountOnly(CountOnly),
60 RequiredConfidenceLevel(RequiredConfidenceLevel), FixerKind(FixerKind) { }
61 virtual void run(const ast_matchers::MatchFinder::MatchResult &Result);
64 StmtAncestorASTVisitor *ParentFinder;
65 tooling::Replacements *Replace;
66 StmtGeneratedVarNameMap *GeneratedDecls;
67 ReplacedVarsMap *ReplacedVarRanges;
68 unsigned *AcceptedChanges;
69 unsigned *DeferredChanges;
70 unsigned *RejectedChanges;
72 TranslationConfidenceKind RequiredConfidenceLevel;
73 LoopFixerKind FixerKind;
75 /// \brief Computes the changes needed to convert a given for loop, and
76 /// applies it if this->CountOnly is false.
77 void doConversion(ASTContext *Context,
78 const VarDecl *IndexVar, const VarDecl *EndVar,
79 const Expr *ContainerExpr, const UsageResult &Usages,
80 const DeclStmt *AliasDecl, const ForStmt *TheLoop,
81 bool ContainerNeedsDereference);
85 } // namespace loop_migrate
87 #endif // _LLVM_TOOLS_CLANG_TOOLS_LOOP_CONVERT_LOOPACTIONS_H_