diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-09-03 13:16:02 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-09-03 13:16:02 +0000 |
commit | 147984a8adf15183de3f3a25f74b7b3620e2a1a6 (patch) | |
tree | bf419f9698f16461fb7d4160a9a6175c5d5d6383 /clang-tools-extra/test | |
parent | 249c7fb10eb837cc78a6e6d26aef9ad802111440 (diff) | |
download | bcm5719-llvm-147984a8adf15183de3f3a25f74b7b3620e2a1a6.tar.gz bcm5719-llvm-147984a8adf15183de3f3a25f74b7b3620e2a1a6.zip |
cpp11-migrate: Refactor for driver model of operation
Re-commit of r189691 and r189689 now with a proper autoconf fix.
Massive simplification of how replacements and file overrides are
handled by the migrator:
* Sources and headers are all treated the same.
* All replacements for a given translation unit are stored in the same
TranslationUnitReplacements structure.
* Change tracking is updated only from main file; no need for
propagating "is tracking" flag around.
* Transform base class no longer responsible for applying replacements.
They are simply stored and main() looks after deduplication and
application.
* Renamed -yaml-only to -serialize-replacements. Same restrictions apply:
Can only request one transform. New restriction: formatting cannot also
be turned on since it's basically a transform.
* If -serialize-replacements is requested, changes to files will not be
applied on disk.
* Changed behaviour of function generating names for serialized
replacements: Only the main source file goes into the name of the file
since a file may contain changes for multiple different files.
* Updated HeaderReplacements LIT test for new serialization behaviour.
* Replaced old test that ensures replacements are not serialized if
-serialize-replacements is not provided. New version ensures changes
are made directly to all files in the translation unit.
* Updated unit tests.
* Due to major simplification of structures in FileOverrides.h, the
FileOverridesTest is quite a bit simpler now.
llvm-svn: 189798
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/HeaderReplacements/Inputs/no_yaml.h | 8 | ||||
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common_expected.yaml | 20 | ||||
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp | 56 | ||||
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main_expected.yaml (renamed from clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml) | 8 | ||||
-rw-r--r-- | clang-tools-extra/test/cpp11-migrate/HeaderReplacements/no_yaml.cpp | 24 |
5 files changed, 77 insertions, 39 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/Inputs/no_yaml.h b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/Inputs/no_yaml.h new file mode 100644 index 00000000000..8e09412c452 --- /dev/null +++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/Inputs/no_yaml.h @@ -0,0 +1,8 @@ +void update(int (&arr)[10]) { + int val = 1; + for (unsigned i = 0; i < sizeof(arr)/sizeof(int); ++i) { + arr[i] = val++; + // CHECK: for (auto & elem : arr) { + // CHECK-NEXT: elem = val++; + } +} diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common_expected.yaml b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common_expected.yaml new file mode 100644 index 00000000000..67eb1fb9104 --- /dev/null +++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common_expected.yaml @@ -0,0 +1,20 @@ +--- +MainSourceFile: "$(path)/common.cpp" +Replacements: + - FilePath: "$(path)/common.h" + Offset: 506 + Length: 2 + ReplacementText: "elem" + - FilePath: "$(path)/common.h" + Offset: 432 + Length: 61 + ReplacementText: "(auto & elem : C)" + - FilePath: "$(path)/common.cpp" + Offset: 289 + Length: 2 + ReplacementText: "elem" + - FilePath: "$(path)/common.cpp" + Offset: 206 + Length: 63 + ReplacementText: "(auto & elem : C1)" +... diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp index d59417cf0d6..54cbc92728e 100644 --- a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp +++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp @@ -1,44 +1,30 @@ // The following block tests the following: -// - Only 1 file is generated per translation unit and header file +// - Only 1 file is generated per translation unit // - Replacements are written in YAML that matches the expected YAML file -// RUN: rm -rf %t/Test -// RUN: mkdir -p %t/Test -// RUN: cp %S/main.cpp %S/common.cpp %S/common.h %t/Test -// RUN: cpp11-migrate -loop-convert -headers -yaml-only -include=%t/Test %t/Test/main.cpp %t/Test/common.cpp -- -// Check that only 1 file is generated per translation unit and header file. -// RUN: ls -1 %t/Test | FileCheck %s --check-prefix=MAIN_CPP -// RUN: ls -1 %t/Test | FileCheck %s --check-prefix=COMMON_CPP -// RUN: cp %S/common.h.yaml %t/Test/main.cpp_common.h.yaml -// We need to put the build path to the expected YAML file to diff against the generated one. -// RUN: sed -e 's#$(path)#%/t/Test#g' %S/common.h.yaml > %t/Test/main.cpp_common.h.yaml -// RUN: sed -i -e 's#\\#/#g' %t/Test/main.cpp_common.h_*.yaml -// RUN: diff -b %t/Test/main.cpp_common.h.yaml %t/Test/main.cpp_common.h_*.yaml -// RUN: sed -e 's#$(path)#%/t/Test#g' -e 's#main.cpp"#common.cpp"#g' %S/common.h.yaml > %t/Test/common.cpp_common.h.yaml -// RUN: sed -i -e 's#\\#/#g' %t/Test/common.cpp_common.h_*.yaml -// RUN: diff -b %t/Test/common.cpp_common.h.yaml %t/Test/common.cpp_common.h_*.yaml +// The test is run in %T/SerializeTest so it's easy to create a clean test +// directory. // -// The following block tests the following: -// - YAML files are written only when -headers is used -// RUN: rm -rf %t/Test -// RUN: mkdir -p %t/Test -// RUN: cp %S/main.cpp %S/common.cpp %S/common.h %t/Test -// RUN: cpp11-migrate -loop-convert -headers -yaml-only -include=%t/Test %t/Test/main.cpp -- -// RUN: cpp11-migrate -loop-convert %t/Test/common.cpp -- -// Check that only one YAML file is generated from main.cpp and common.h and not from common.cpp and common.h since -header is not specified -// RUN: ls -1 %t/Test | FileCheck %s --check-prefix=MAIN_CPP -// RUN: ls -1 %t/Test | FileCheck %s --check-prefix=NO_COMMON +// RUN: rm -rf %T/SerializeTest +// RUN: mkdir -p %T/SerializeTest +// RUN: cp %S/main.cpp %S/common.cpp %S/common.h %T/SerializeTest +// RUN: cpp11-migrate -loop-convert -headers -serialize-replacements -include=%T/SerializeTest %T/SerializeTest/main.cpp %T/SerializeTest/common.cpp -- +// Check that only 1 file is generated per translation unit +// RUN: ls -1 %T/SerializeTest | FileCheck %s --check-prefix=MAIN_CPP +// RUN: ls -1 %T/SerializeTest | FileCheck %s --check-prefix=COMMON_CPP // We need to put the build path to the expected YAML file to diff against the generated one. -// RUN: sed -e 's#$(path)#%/t/Test#g' %S/common.h.yaml > %t/Test/main.cpp_common.h.yaml -// RUN: sed -i -e 's#\\#/#g' %t/Test/main.cpp_common.h_*.yaml -// RUN: diff -b %t/Test/main.cpp_common.h.yaml %t/Test/main.cpp_common.h_*.yaml -// -// MAIN_CPP: {{^main.cpp_common.h_.*.yaml$}} -// MAIN_CPP-NOT: {{main.cpp_common.h_.*.yaml}} +// RUN: sed -e 's#$(path)#%/T/SerializeTest#g' %S/main_expected.yaml > %T/SerializeTest/main_expected.yaml +// RUN: sed -i -e 's#\\#/#g' %T/SerializeTest/main.cpp_*.yaml +// RUN: diff -b %T/SerializeTest/main_expected.yaml %T/SerializeTest/main.cpp_*.yaml +// RUN: sed -e 's#$(path)#%/T/SerializeTest#g' %S/common_expected.yaml > %T/SerializeTest/common_expected.yaml +// RUN: sed -i -e 's#\\#/#g' %T/SerializeTest/common.cpp_*.yaml +// RUN: diff -b %T/SerializeTest/common_expected.yaml %T/SerializeTest/common.cpp_*.yaml // -// COMMON_CPP: {{^common.cpp_common.h_.*.yaml$}} -// COMMON_CPP-NOT: {{common.cpp_common.h_.*.yaml}} +// The following are for FileCheck when used on output of 'ls'. See above. +// MAIN_CPP: {{^main.cpp_.*.yaml$}} +// MAIN_CPP-NOT: {{main.cpp_.*.yaml}} // -// NO_COMMON-NOT: {{common.cpp_common.h_.*.yaml}} +// COMMON_CPP: {{^common.cpp_.*.yaml$}} +// COMMON_CPP-NOT: {{common.cpp_.*.yaml}} #include "common.h" diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main_expected.yaml index 4b1258cae4a..8702bc17245 100644 --- a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml +++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main_expected.yaml @@ -2,11 +2,11 @@ MainSourceFile: "$(path)/main.cpp" Replacements: - FilePath: "$(path)/common.h" - Offset: 432 - Length: 61 - ReplacementText: "(auto & elem : C)" - - FilePath: "$(path)/common.h" Offset: 506 Length: 2 ReplacementText: "elem" + - FilePath: "$(path)/common.h" + Offset: 432 + Length: 61 + ReplacementText: "(auto & elem : C)" ... diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/no_yaml.cpp b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/no_yaml.cpp new file mode 100644 index 00000000000..880cc1f5a70 --- /dev/null +++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/no_yaml.cpp @@ -0,0 +1,24 @@ +// Ensure that if -serialize-replacements is not provided, no serialized +// replacement files should be generated and the changes are made directly. +// +// RUN: mkdir -p %T/Inputs +// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp +// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/no_yaml.h > %T/Inputs/no_yaml.h +// RUN: cpp11-migrate -loop-convert %t.cpp -headers -include=%T/Inputs -- -I %T/Inputs/no_yaml.h +// RUN: FileCheck --input-file=%t.cpp %s +// RUN: FileCheck --input-file=%T/Inputs/no_yaml.h %S/Inputs/no_yaml.h +// RUN: ls -1 %T | FileCheck %s --check-prefix=NO_YAML +// +// NO_YAML-NOT: {{no_yaml.cpp_.*.yaml}} +#include "Inputs/no_yaml.h" + +void func() { + int arr[10]; + for (unsigned i = 0; i < sizeof(arr)/sizeof(int); ++i) { + arr[i] = 0; + // CHECK: for (auto & elem : arr) { + // CHECK-NEXT: elem = 0; + } + + update(arr); +} |