Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 1 | //===--- ClangTidyOptions.cpp - clang-tidy ----------------------*- 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 | #include "ClangTidyOptions.h" |
| 11 | #include "llvm/Support/YAMLTraits.h" |
| 12 | |
Alexander Kornienko | a469522 | 2014-06-05 13:31:45 +0000 | [diff] [blame] | 13 | using clang::tidy::ClangTidyOptions; |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 14 | using clang::tidy::FileFilter; |
| 15 | |
| 16 | LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter) |
| 17 | LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter::LineRange) |
| 18 | |
| 19 | namespace llvm { |
| 20 | namespace yaml { |
| 21 | |
| 22 | // Map std::pair<int, int> to a JSON array of size 2. |
| 23 | template <> struct SequenceTraits<FileFilter::LineRange> { |
| 24 | static size_t size(IO &IO, FileFilter::LineRange &Range) { |
| 25 | return Range.first == 0 ? 0 : Range.second == 0 ? 1 : 2; |
| 26 | } |
| 27 | static unsigned &element(IO &IO, FileFilter::LineRange &Range, size_t Index) { |
| 28 | if (Index > 1) |
| 29 | IO.setError("Too many elements in line range."); |
| 30 | return Index == 0 ? Range.first : Range.second; |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | template <> struct MappingTraits<FileFilter> { |
| 35 | static void mapping(IO &IO, FileFilter &File) { |
| 36 | IO.mapRequired("name", File.Name); |
| 37 | IO.mapOptional("lines", File.LineRanges); |
| 38 | } |
| 39 | static StringRef validate(IO &io, FileFilter &File) { |
| 40 | if (File.Name.empty()) |
| 41 | return "No file name specified"; |
| 42 | for (const FileFilter::LineRange &Range : File.LineRanges) { |
| 43 | if (Range.first <= 0 || Range.second <= 0) |
| 44 | return "Invalid line range"; |
| 45 | } |
| 46 | return StringRef(); |
| 47 | } |
| 48 | }; |
| 49 | |
Alexander Kornienko | a469522 | 2014-06-05 13:31:45 +0000 | [diff] [blame] | 50 | template <> struct MappingTraits<ClangTidyOptions> { |
| 51 | static void mapping(IO &IO, ClangTidyOptions &Options) { |
| 52 | IO.mapOptional("Checks", Options.Checks); |
| 53 | IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex); |
| 54 | IO.mapOptional("AnalyzeTemporaryDtors", Options.AnalyzeTemporaryDtors); |
| 55 | } |
| 56 | }; |
| 57 | |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 58 | } // namespace yaml |
| 59 | } // namespace llvm |
| 60 | |
| 61 | namespace clang { |
| 62 | namespace tidy { |
| 63 | |
| 64 | /// \brief Parses -line-filter option and stores it to the \c Options. |
Rafael Espindola | 15c5784 | 2014-06-12 13:32:11 +0000 | [diff] [blame] | 65 | std::error_code parseLineFilter(const std::string &LineFilter, |
| 66 | clang::tidy::ClangTidyGlobalOptions &Options) { |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 67 | llvm::yaml::Input Input(LineFilter); |
| 68 | Input >> Options.LineFilter; |
| 69 | return Input.error(); |
| 70 | } |
| 71 | |
Rafael Espindola | 15c5784 | 2014-06-12 13:32:11 +0000 | [diff] [blame] | 72 | std::error_code parseConfiguration(const std::string &Config, |
| 73 | clang::tidy::ClangTidyOptions &Options) { |
Alexander Kornienko | a469522 | 2014-06-05 13:31:45 +0000 | [diff] [blame] | 74 | llvm::yaml::Input Input(Config); |
| 75 | Input >> Options; |
| 76 | return Input.error(); |
| 77 | } |
| 78 | |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 79 | } // namespace tidy |
| 80 | } // namespace clang |