summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-modernize/Core/IncludeExcludeInfo.h
blob: aa42c658708d83a4b8bb3222b5de2a9c49df0226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//===-- Core/IncludeExcludeInfo.h - IncludeExclude class def'n --*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides the definition for the IncludeExcludeInfo class
/// to handle the include and exclude command line options.
///
//===----------------------------------------------------------------------===//

#ifndef CLANG_MODERNIZE_INCLUDEEXCLUDEINFO_H
#define CLANG_MODERNIZE_INCLUDEEXCLUDEINFO_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/system_error.h"
#include <vector>

/// \brief Class encapsulating the handling of include and exclude paths
/// provided by the user through command line options.
class IncludeExcludeInfo {
public:
  /// \brief Read and parse a comma-separated lists of paths from
  /// \a IncludeString and \a ExcludeString.
  ///
  /// Returns error_code::success() on successful parse of the strings or
  /// an error_code indicating the encountered error.
  std::error_code readListFromString(llvm::StringRef IncludeString,
                                     llvm::StringRef ExcludeString);

  /// \brief Read and parse the lists of paths from \a IncludeListFile
  /// and \a ExcludeListFile. Each file should contain one path per line.
  ///
  /// Returns error_code::success() on successful read and parse of both files
  /// or an error_code indicating the encountered error.
  std::error_code readListFromFile(llvm::StringRef IncludeListFile,
                                   llvm::StringRef ExcludeListFile);

  /// \brief Determine if the given path is in the list of include paths but
  /// not in the list of exclude paths.
  ///
  /// \a FilePath shouldn't contain relative operators i.e. ".." or "." since
  /// Path comes from the include/exclude list of paths in which relative
  /// operators were removed.
  bool isFileIncluded(llvm::StringRef FilePath) const;

  /// \brief Determine if a file path was explicitly excluded.
  bool isFileExplicitlyExcluded(llvm::StringRef FilePath) const;

  /// \brief Determine if a list of include paths was provided.
  bool isIncludeListEmpty() const { return IncludeList.empty(); }

private:
  std::vector<std::string> IncludeList;
  std::vector<std::string> ExcludeList;
};

#endif // CLANG_MODERNIZE_INCLUDEEXCLUDEINFO_H
OpenPOWER on IntegriCloud