@@ -38,8 +38,10 @@ static void eatDiagnostics(const SMDiagnostic &, void *) {}
38
38
namespace clang {
39
39
namespace replace {
40
40
41
- std::error_code collectReplacementsFromDirectory (
42
- const llvm::StringRef Directory, TUReplacements &TUs,
41
+ namespace detail {
42
+ template <typename TranslationUnits>
43
+ static std::error_code collectReplacementsFromDirectory (
44
+ const llvm::StringRef Directory, TranslationUnits &TUs,
43
45
TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
44
46
using namespace llvm ::sys::fs;
45
47
using namespace llvm ::sys::path;
@@ -68,7 +70,7 @@ std::error_code collectReplacementsFromDirectory(
68
70
}
69
71
70
72
yaml::Input YIn (Out.get ()->getBuffer (), nullptr , &eatDiagnostics);
71
- tooling::TranslationUnitReplacements TU;
73
+ typename TranslationUnits::value_type TU;
72
74
YIn >> TU;
73
75
if (YIn.error ()) {
74
76
// File doesn't appear to be a header change description. Ignore it.
@@ -81,49 +83,22 @@ std::error_code collectReplacementsFromDirectory(
81
83
82
84
return ErrorCode;
83
85
}
86
+ } // namespace detail
84
87
88
+ template <>
85
89
std::error_code collectReplacementsFromDirectory (
86
- const llvm::StringRef Directory, TUDiagnostics &TUs,
90
+ const llvm::StringRef Directory, TUReplacements &TUs,
87
91
TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
88
- using namespace llvm ::sys::fs;
89
- using namespace llvm ::sys::path;
90
-
91
- std::error_code ErrorCode;
92
-
93
- for (recursive_directory_iterator I (Directory, ErrorCode), E;
94
- I != E && !ErrorCode; I.increment (ErrorCode)) {
95
- if (filename (I->path ())[0 ] == ' .' ) {
96
- // Indicate not to descend into directories beginning with '.'
97
- I.no_push ();
98
- continue ;
99
- }
100
-
101
- if (extension (I->path ()) != " .yaml" )
102
- continue ;
103
-
104
- TUFiles.push_back (I->path ());
105
-
106
- ErrorOr<std::unique_ptr<MemoryBuffer>> Out =
107
- MemoryBuffer::getFile (I->path ());
108
- if (std::error_code BufferError = Out.getError ()) {
109
- errs () << " Error reading " << I->path () << " : " << BufferError.message ()
110
- << " \n " ;
111
- continue ;
112
- }
113
-
114
- yaml::Input YIn (Out.get ()->getBuffer (), nullptr , &eatDiagnostics);
115
- tooling::TranslationUnitDiagnostics TU;
116
- YIn >> TU;
117
- if (YIn.error ()) {
118
- // File doesn't appear to be a header change description. Ignore it.
119
- continue ;
120
- }
121
-
122
- // Only keep files that properly parse.
123
- TUs.push_back (TU);
124
- }
92
+ return detail::collectReplacementsFromDirectory (Directory, TUs, TUFiles,
93
+ Diagnostics);
94
+ }
125
95
126
- return ErrorCode;
96
+ template <>
97
+ std::error_code collectReplacementsFromDirectory (
98
+ const llvm::StringRef Directory, TUDiagnostics &TUs,
99
+ TUReplacementFiles &TUFiles, clang::DiagnosticsEngine &Diagnostics) {
100
+ return detail::collectReplacementsFromDirectory (Directory, TUs, TUFiles,
101
+ Diagnostics);
127
102
}
128
103
129
104
// / Extract replacements from collected TranslationUnitReplacements and
0 commit comments