|
22 | 22 |
|
23 | 23 | namespace llvm { |
24 | 24 |
|
25 | | - /// DiffFilesWithTolerance - Compare the two files specified, returning 0 if |
26 | | - /// the files match, 1 if they are different, and 2 if there is a file error. |
27 | | - /// This function allows you to specify an absolute and relative FP error that |
28 | | - /// is allowed to exist. If you specify a string to fill in for the error |
29 | | - /// option, it will set the string to an error message if an error occurs, or |
30 | | - /// if the files are different. |
31 | | - /// |
32 | | - int DiffFilesWithTolerance(StringRef FileA, |
33 | | - StringRef FileB, |
34 | | - double AbsTol, double RelTol, |
35 | | - std::string *Error = nullptr); |
36 | | - |
37 | | - |
38 | | - /// FileRemover - This class is a simple object meant to be stack allocated. |
39 | | - /// If an exception is thrown from a region, the object removes the filename |
40 | | - /// specified (if deleteIt is true). |
41 | | - /// |
42 | | - class FileRemover { |
43 | | - SmallString<128> Filename; |
44 | | - bool DeleteIt; |
45 | | - public: |
46 | | - FileRemover() : DeleteIt(false) {} |
47 | | - |
48 | | - explicit FileRemover(const Twine& filename, bool deleteIt = true) |
| 25 | +/// DiffFilesWithTolerance - Compare the two files specified, returning 0 if |
| 26 | +/// the files match, 1 if they are different, and 2 if there is a file error. |
| 27 | +/// This function allows you to specify an absolute and relative FP error that |
| 28 | +/// is allowed to exist. If you specify a string to fill in for the error |
| 29 | +/// option, it will set the string to an error message if an error occurs, or |
| 30 | +/// if the files are different. |
| 31 | +/// |
| 32 | +int DiffFilesWithTolerance(StringRef FileA, StringRef FileB, double AbsTol, |
| 33 | + double RelTol, std::string *Error = nullptr); |
| 34 | + |
| 35 | +/// FileRemover - This class is a simple object meant to be stack allocated. |
| 36 | +/// If an exception is thrown from a region, the object removes the filename |
| 37 | +/// specified (if deleteIt is true). |
| 38 | +/// |
| 39 | +class FileRemover { |
| 40 | + SmallString<128> Filename; |
| 41 | + bool DeleteIt; |
| 42 | + |
| 43 | +public: |
| 44 | + FileRemover() : DeleteIt(false) {} |
| 45 | + |
| 46 | + explicit FileRemover(const Twine &filename, bool deleteIt = true) |
49 | 47 | : DeleteIt(deleteIt) { |
50 | | - filename.toVector(Filename); |
51 | | - } |
| 48 | + filename.toVector(Filename); |
| 49 | + } |
52 | 50 |
|
53 | | - ~FileRemover() { |
54 | | - if (DeleteIt) { |
55 | | - // Ignore problems deleting the file. |
56 | | - sys::fs::remove(Filename); |
57 | | - } |
| 51 | + ~FileRemover() { |
| 52 | + if (DeleteIt) { |
| 53 | + // Ignore problems deleting the file. |
| 54 | + sys::fs::remove(Filename); |
58 | 55 | } |
59 | | - |
60 | | - /// setFile - Give ownership of the file to the FileRemover so it will |
61 | | - /// be removed when the object is destroyed. If the FileRemover already |
62 | | - /// had ownership of a file, remove it first. |
63 | | - void setFile(const Twine& filename, bool deleteIt = true) { |
64 | | - if (DeleteIt) { |
65 | | - // Ignore problems deleting the file. |
66 | | - sys::fs::remove(Filename); |
67 | | - } |
68 | | - |
69 | | - Filename.clear(); |
70 | | - filename.toVector(Filename); |
71 | | - DeleteIt = deleteIt; |
| 56 | + } |
| 57 | + |
| 58 | + /// setFile - Give ownership of the file to the FileRemover so it will |
| 59 | + /// be removed when the object is destroyed. If the FileRemover already |
| 60 | + /// had ownership of a file, remove it first. |
| 61 | + void setFile(const Twine &filename, bool deleteIt = true) { |
| 62 | + if (DeleteIt) { |
| 63 | + // Ignore problems deleting the file. |
| 64 | + sys::fs::remove(Filename); |
72 | 65 | } |
73 | 66 |
|
74 | | - /// releaseFile - Take ownership of the file away from the FileRemover so it |
75 | | - /// will not be removed when the object is destroyed. |
76 | | - void releaseFile() { DeleteIt = false; } |
77 | | - }; |
78 | | - |
79 | | - /// FilePermssionsApplier helps to copy permissions from an input file to |
80 | | - /// an output one. It memorizes the status of the input file and can apply |
81 | | - /// permissions and dates to the output file. |
82 | | - class FilePermissionsApplier { |
83 | | - public: |
84 | | - static Expected<FilePermissionsApplier> create(StringRef InputFilename); |
85 | | - |
86 | | - /// Apply stored permissions to the \p OutputFilename. |
87 | | - /// Copy LastAccess and ModificationTime if \p CopyDates is true. |
88 | | - /// Overwrite stored permissions if \p OverwritePermissions is specified. |
89 | | - Error |
90 | | - apply(StringRef OutputFilename, bool CopyDates = false, |
91 | | - std::optional<sys::fs::perms> OverwritePermissions = std::nullopt); |
92 | | - |
93 | | - private: |
94 | | - FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status) |
95 | | - : InputFilename(InputFilename), InputStatus(Status) {} |
96 | | - |
97 | | - StringRef InputFilename; |
98 | | - sys::fs::file_status InputStatus; |
99 | | - }; |
100 | | -} // End llvm namespace |
| 67 | + Filename.clear(); |
| 68 | + filename.toVector(Filename); |
| 69 | + DeleteIt = deleteIt; |
| 70 | + } |
| 71 | + |
| 72 | + /// releaseFile - Take ownership of the file away from the FileRemover so it |
| 73 | + /// will not be removed when the object is destroyed. |
| 74 | + void releaseFile() { DeleteIt = false; } |
| 75 | +}; |
| 76 | + |
| 77 | +/// FilePermssionsApplier helps to copy permissions from an input file to |
| 78 | +/// an output one. It memorizes the status of the input file and can apply |
| 79 | +/// permissions and dates to the output file. |
| 80 | +class FilePermissionsApplier { |
| 81 | +public: |
| 82 | + static Expected<FilePermissionsApplier> create(StringRef InputFilename); |
| 83 | + |
| 84 | + /// Apply stored permissions to the \p OutputFilename. |
| 85 | + /// Copy LastAccess and ModificationTime if \p CopyDates is true. |
| 86 | + /// Overwrite stored permissions if \p OverwritePermissions is specified. |
| 87 | + Error |
| 88 | + apply(StringRef OutputFilename, bool CopyDates = false, |
| 89 | + std::optional<sys::fs::perms> OverwritePermissions = std::nullopt); |
| 90 | + |
| 91 | +private: |
| 92 | + FilePermissionsApplier(StringRef InputFilename, sys::fs::file_status Status) |
| 93 | + : InputFilename(InputFilename), InputStatus(Status) {} |
| 94 | + |
| 95 | + StringRef InputFilename; |
| 96 | + sys::fs::file_status InputStatus; |
| 97 | +}; |
| 98 | +} // namespace llvm |
101 | 99 |
|
102 | 100 | #endif |
0 commit comments