File tree Expand file tree Collapse file tree 5 files changed +96
-1
lines changed Expand file tree Collapse file tree 5 files changed +96
-1
lines changed Original file line number Diff line number Diff line change 23
23
#include " clang/Tooling/DiagnosticsYaml.h"
24
24
#include " clang/Tooling/ReplacementsYaml.h"
25
25
#include " llvm/ADT/ArrayRef.h"
26
+ #include " llvm/ADT/STLExtras.h"
27
+ #include " llvm/ADT/StringRef.h"
26
28
#include " llvm/ADT/StringSet.h"
27
29
#include " llvm/Support/FileSystem.h"
28
30
#include " llvm/Support/MemoryBuffer.h"
29
31
#include " llvm/Support/Path.h"
30
32
#include " llvm/Support/raw_ostream.h"
33
+ #include < array>
31
34
#include < optional>
32
35
33
36
using namespace llvm ;
@@ -39,6 +42,9 @@ namespace clang {
39
42
namespace replace {
40
43
41
44
namespace detail {
45
+
46
+ static constexpr std::array<StringRef, 2 > AllowedExtensions = {" .yaml" , " .yml" };
47
+
42
48
template <typename TranslationUnits>
43
49
static std::error_code collectReplacementsFromDirectory (
44
50
const llvm::StringRef Directory, TranslationUnits &TUs,
@@ -56,7 +62,7 @@ static std::error_code collectReplacementsFromDirectory(
56
62
continue ;
57
63
}
58
64
59
- if (extension (I->path ()) != " .yaml " )
65
+ if (! is_contained (AllowedExtensions, extension (I->path ())) )
60
66
continue ;
61
67
62
68
TUFiles.push_back (I->path ());
Original file line number Diff line number Diff line change
1
+ #ifndef BASIC_H
2
+ #define BASIC_H
3
+
4
+
5
+ class Parent {
6
+ public:
7
+ virtual void func () {}
8
+ };
9
+
10
+ class Derived : public Parent {
11
+ public:
12
+ virtual void func () {}
13
+ // CHECK: virtual void func() override {}
14
+ };
15
+
16
+ extern void ext (int (&)[5], const Parent &);
17
+
18
+ void func (int t) {
19
+ int ints[5 ];
20
+ for (unsigned i = 0 ; i < 5 ; ++i) {
21
+ int &e = ints[i];
22
+ e = t;
23
+ // CHECK: for (auto & elem : ints) {
24
+ // CHECK-NEXT: elem = t;
25
+ }
26
+
27
+ Derived d;
28
+
29
+ ext (ints, d);
30
+ }
31
+
32
+ #endif // BASIC_H
Original file line number Diff line number Diff line change
1
+ ---
2
+ MainSourceFile : source1.cpp
3
+ Diagnostics :
4
+ - DiagnosticName : test-basic
5
+ DiagnosticMessage :
6
+ Message : Fix
7
+ FilePath : $(path)/basic.h
8
+ FileOffset : 242
9
+ Replacements :
10
+ - FilePath : $(path)/basic.h
11
+ Offset : 242
12
+ Length : 26
13
+ ReplacementText : ' auto & elem : ints'
14
+ - FilePath : $(path)/basic.h
15
+ Offset : 276
16
+ Length : 22
17
+ ReplacementText : ' '
18
+ - FilePath : $(path)/basic.h
19
+ Offset : 298
20
+ Length : 1
21
+ ReplacementText : elem
22
+ - FilePath : $(path)/../yml-basic/basic.h
23
+ Offset : 148
24
+ Length : 0
25
+ ReplacementText : ' override '
26
+ ...
Original file line number Diff line number Diff line change
1
+ ---
2
+ MainSourceFile : source2.cpp
3
+ Diagnostics :
4
+ - DiagnosticName : test-basic
5
+ DiagnosticMessage :
6
+ Message : Fix
7
+ FilePath : $(path)/basic.h
8
+ FileOffset : 148
9
+ Replacements :
10
+ - FilePath : $(path)/../yml-basic/basic.h
11
+ Offset : 298
12
+ Length : 1
13
+ ReplacementText : elem
14
+ ...
Original file line number Diff line number Diff line change
1
+ // RUN: mkdir -p %T/Inputs/yml-basic
2
+ // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/yml-basic/basic.h > %T/Inputs/yml-basic/basic.h
3
+ // RUN: sed "s#\$(path)#%/T/Inputs/yml-basic#" %S/Inputs/yml-basic/file1.yml > %T/Inputs/yml-basic/file1.yml
4
+ // RUN: sed "s#\$(path)#%/T/Inputs/yml-basic#" %S/Inputs/yml-basic/file2.yml > %T/Inputs/yml-basic/file2.yml
5
+ // RUN: clang-apply-replacements %T/Inputs/yml-basic
6
+ // RUN: FileCheck -input-file=%T/Inputs/yml-basic/basic.h %S/Inputs/yml-basic/basic.h
7
+ //
8
+ // Check that the yml files are *not* deleted after running clang-apply-replacements without remove-change-desc-files.
9
+ // RUN: ls -1 %T/Inputs/yml-basic | FileCheck %s --check-prefix=YML
10
+ //
11
+ // Check that the yml files *are* deleted after running clang-apply-replacements with remove-change-desc-files.
12
+ // RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/yml-basic/basic.h > %T/Inputs/yml-basic/basic.h
13
+ // RUN: clang-apply-replacements -remove-change-desc-files %T/Inputs/yml-basic
14
+ // RUN: ls -1 %T/Inputs/yml-basic | FileCheck %s --check-prefix=NO_YML
15
+ //
16
+ // YML: {{^file.\.yml$}}
17
+ // NO_YML-NOT: {{^file.\.yml$}}
You can’t perform that action at this time.
0 commit comments