Edwin Vane | dde168b | 2013-01-04 18:25:18 +0000 | [diff] [blame] | 1 | //===-- cpp11-migrate/Transform.h - Transform Base Class Def'n --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file provides the definition for the base Transform class from |
| 12 | /// which all transforms must subclass. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H |
| 16 | #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H |
| 17 | |
| 18 | #include "clang/Tooling/CompilationDatabase.h" |
| 19 | #include <vector> |
| 20 | |
| 21 | /// \brief Description of the riskiness of actions that can be taken by |
| 22 | /// transforms. |
| 23 | enum RiskLevel { |
| 24 | /// Transformations that will not change semantics. |
| 25 | RL_Safe, |
| 26 | |
| 27 | /// Transformations that might change semantics. |
| 28 | RL_Reasonable, |
| 29 | |
| 30 | /// Transformations that are likely to change semantics. |
| 31 | RL_Risky |
| 32 | }; |
| 33 | |
| 34 | // Forward Declarations |
| 35 | namespace clang { |
| 36 | namespace tooling { |
| 37 | class CompilationDatabase; |
| 38 | } // namespace tooling |
| 39 | } // namespace clang |
| 40 | |
| 41 | /// \brief Abstract base class for all C++11 migration transforms. |
| 42 | class Transform { |
| 43 | public: |
| 44 | Transform() { |
| 45 | Reset(); |
| 46 | } |
| 47 | |
| 48 | virtual ~Transform() {} |
| 49 | |
| 50 | /// \brief Apply a transform to all files listed in \p SourcePaths. |
| 51 | /// |
| 52 | /// \p Database must contain information for how to compile all files in |
| 53 | /// \p SourcePaths. |
| 54 | virtual int apply(RiskLevel MaxRiskLevel, |
| 55 | const clang::tooling::CompilationDatabase &Database, |
| 56 | const std::vector<std::string> &SourcePaths) = 0; |
| 57 | |
| 58 | /// \brief Query if changes were made during the last call to apply(). |
| 59 | bool getChangesMade() const { return ChangesMade; } |
| 60 | |
| 61 | /// \brief Query if changes were not made due to conflicts with other changes |
| 62 | /// made during the last call to apply() or if changes were too risky for the |
| 63 | /// requested risk level. |
| 64 | bool getChangesNotMade() const { return ChangesNotMade; } |
| 65 | |
| 66 | /// \brief Reset internal state of the transform. |
| 67 | /// |
| 68 | /// Useful if calling apply() several times with one instantiation of a |
| 69 | /// transform. |
| 70 | void Reset() { |
| 71 | ChangesMade = false; |
| 72 | ChangesNotMade = false; |
| 73 | } |
| 74 | |
| 75 | protected: |
| 76 | void setChangesMade() { ChangesMade = true; } |
| 77 | void setChangesNotMade() { ChangesNotMade = true; } |
| 78 | |
| 79 | private: |
| 80 | bool ChangesMade; |
| 81 | bool ChangesNotMade; |
| 82 | }; |
| 83 | |
| 84 | #endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H |