Home | History | Annotate | Download | only in value_cleanup
      1 // Copyright 2016 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 //
      5 // Handles various rewrites for base::ListValue::Append().
      6 
      7 #ifndef TOOLS_CLANG_VALUE_CLEANUP_LIST_VALUE_REWRITER_H_
      8 #define TOOLS_CLANG_VALUE_CLEANUP_LIST_VALUE_REWRITER_H_
      9 
     10 #include <memory>
     11 #include <set>
     12 #include <unordered_set>
     13 
     14 #include "clang/ASTMatchers/ASTMatchFinder.h"
     15 #include "clang/Tooling/Refactoring.h"
     16 
     17 class ListValueRewriter {
     18  public:
     19   explicit ListValueRewriter(
     20       std::set<clang::tooling::Replacement>* replacements);
     21 
     22   void RegisterMatchers(clang::ast_matchers::MatchFinder* match_finder);
     23 
     24  private:
     25   class AppendCallback
     26       : public clang::ast_matchers::MatchFinder::MatchCallback {
     27    public:
     28     explicit AppendCallback(
     29         std::set<clang::tooling::Replacement>* replacements);
     30 
     31     void run(
     32         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     33 
     34    protected:
     35     std::set<clang::tooling::Replacement>* const replacements_;
     36   };
     37 
     38   class AppendBooleanCallback : public AppendCallback {
     39    public:
     40     explicit AppendBooleanCallback(
     41         std::set<clang::tooling::Replacement>* replacements);
     42 
     43     void run(
     44         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     45   };
     46 
     47   class AppendIntegerCallback : public AppendCallback {
     48    public:
     49     explicit AppendIntegerCallback(
     50         std::set<clang::tooling::Replacement>* replacements);
     51 
     52     void run(
     53         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     54   };
     55 
     56   class AppendDoubleCallback : public AppendCallback {
     57    public:
     58     explicit AppendDoubleCallback(
     59         std::set<clang::tooling::Replacement>* replacements);
     60 
     61     void run(
     62         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     63   };
     64 
     65   class AppendStringCallback : public AppendCallback {
     66    public:
     67     explicit AppendStringCallback(
     68         std::set<clang::tooling::Replacement>* replacements);
     69 
     70     void run(
     71         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     72   };
     73 
     74   class AppendReleasedUniquePtrCallback
     75       : public clang::ast_matchers::MatchFinder::MatchCallback {
     76    public:
     77     explicit AppendReleasedUniquePtrCallback(
     78         std::set<clang::tooling::Replacement>* replacements);
     79 
     80     void run(
     81         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     82 
     83    private:
     84     std::set<clang::tooling::Replacement>* const replacements_;
     85   };
     86 
     87   class AppendRawPtrCallback
     88       : public clang::ast_matchers::MatchFinder::MatchCallback {
     89    public:
     90     explicit AppendRawPtrCallback(
     91         std::set<clang::tooling::Replacement>* replacements);
     92 
     93     void run(
     94         const clang::ast_matchers::MatchFinder::MatchResult& result) override;
     95 
     96    private:
     97     std::set<clang::tooling::Replacement>* const replacements_;
     98     std::unordered_set<const clang::VarDecl*> visited_;
     99   };
    100 
    101   AppendBooleanCallback append_boolean_callback_;
    102   AppendIntegerCallback append_integer_callback_;
    103   AppendDoubleCallback append_double_callback_;
    104   AppendStringCallback append_string_callback_;
    105   AppendReleasedUniquePtrCallback append_released_unique_ptr_callback_;
    106   AppendRawPtrCallback append_raw_ptr_callback_;
    107 };
    108 
    109 #endif  // TOOLS_CLANG_VALUE_CLEANUP_LIST_VALUE_REWRITER_H_
    110