summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate
diff options
context:
space:
mode:
authorTareq A. Siraj <tareq.a.siraj@intel.com>2013-08-13 14:58:50 +0000
committerTareq A. Siraj <tareq.a.siraj@intel.com>2013-08-13 14:58:50 +0000
commit3baabf396876af59f80a06b6ce5cfac8c2c9afda (patch)
tree2cf08348e4f268a6a79e14940c6681001b10dfd2 /clang-tools-extra/test/cpp11-migrate
parentf77718ad1d2b20c834126ce7884755f97a93eb50 (diff)
downloadbcm5719-llvm-3baabf396876af59f80a06b6ce5cfac8c2c9afda.tar.gz
bcm5719-llvm-3baabf396876af59f80a06b6ce5cfac8c2c9afda.zip
cpp11-migrate: Write header replacements to disk
Another attempt to commit r187204 after windows related problems has been fixed. Note that changes to this patch reflect the current behavior of cpp11-migrate. Header replacements are now written to disk in YAML format for an external tool to merge. A unique file will be created in the same directory as the header with all replacements that came from a source file that included the header file. The YAML file will have: - Name of the header file - Name of the source file that included the header file - Transform ID that generated the replacement - Offset - Length - Replacement text Any tool reading these replacements should read them using the HeaderChangeDocument struct. Differential Revision: http://llvm-reviews.chandlerc.com/D1369 llvm-svn: 188274
Diffstat (limited to 'clang-tools-extra/test/cpp11-migrate')
-rw-r--r--clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.cpp16
-rw-r--r--clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h27
-rw-r--r--clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml12
-rw-r--r--clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp39
4 files changed, 94 insertions, 0 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.cpp b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.cpp
new file mode 100644
index 00000000000..9c4f0e543ce
--- /dev/null
+++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.cpp
@@ -0,0 +1,16 @@
+// This is just a dummy run command to keep lit happy. Tests for this file are
+// in main.cpp
+// RUN: true
+
+#include "common.h"
+
+void func1(int &I) {
+}
+
+void func2() {
+ container C1;
+ container C2;
+ for (container::iterator I = C1.begin(), E = C1.end(); I != E; ++I) {
+ C2.push_back(*I);
+ }
+}
diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h
new file mode 100644
index 00000000000..3bb98cc705c
--- /dev/null
+++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h
@@ -0,0 +1,27 @@
+#ifndef CPP11_MIGRATE_TEST_HEADER_REPLACEMENTS_COMMON_H
+#define CPP11_MIGRATE_TEST_HEADER_REPLACEMENTS_COMMON_H
+
+struct container {
+ struct iterator {
+ int &operator*();
+ const int &operator*() const;
+ iterator &operator++();
+ bool operator!=(const iterator &other);
+ };
+
+ iterator begin();
+ iterator end();
+ void push_back(const int &);
+};
+
+void func1(int &I);
+void func2();
+
+void dostuff() {
+ container C;
+ for (container::iterator I = C.begin(), E = C.end(); I != E; ++I) {
+ func1(*I);
+ }
+}
+
+#endif // CPP11_MIGRATE_TEST_HEADER_REPLACEMENTS_COMMON_H
diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml
new file mode 100644
index 00000000000..9123bd8db16
--- /dev/null
+++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml
@@ -0,0 +1,12 @@
+---
+TransformID: "LoopConvert"
+Replacements:
+ - Offset: 432
+ Length: 61
+ ReplacementText: "(auto & elem : C)"
+ - Offset: 506
+ Length: 2
+ ReplacementText: "elem"
+HeaderFileName: "common.h"
+SourceFileName: "main.cpp"
+...
diff --git a/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp
new file mode 100644
index 00000000000..72c32f1cdea
--- /dev/null
+++ b/clang-tools-extra/test/cpp11-migrate/HeaderReplacements/main.cpp
@@ -0,0 +1,39 @@
+// The following block tests the following:
+// - Only 1 file is generated per translation unit and header file
+// - 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 -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 | grep -c "main.cpp_common.h_.*.yaml" | grep "^1$"
+// RUN: ls -1 %t/Test | grep -c "common.cpp_common.h_.*.yaml" | grep "^1$"
+// We need to remove the path from FileNames in the generated YAML file because it will have a path in the temp directory
+// RUN: sed -i -e 's/^\(HeaderFileName:\|SourceFileName:\).*[\/\\]\(.*\)"$/\1 "\2"/g' %t/Test/main.cpp_common.h_*.yaml
+// RUN: cp %S/common.h.yaml %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 -i -e 's/^\(HeaderFileName:\|SourceFileName:\).*[\/\\]\(.*\)"$/\1 "\2"/g' %t/Test/common.cpp_common.h_*.yaml
+// RUN: cp %S/common.h.yaml %t/Test/common.cpp_common.h.yaml
+// RUN: sed -i -e 's/^SourceFileName: "main.cpp"$/SourceFileName: "common.cpp"/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 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 -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 | grep -c "main.cpp_common.h_.*.yaml" | grep "^1$"
+// RUN: ls -1 %t/Test | not grep "common.cpp_common.h_.*.yaml"
+// We need to remove the path from FileName in the generated YAML file because it will have a path in the temp directory
+// RUN: sed -i -e 's/^\(HeaderFileName:\|SourceFileName:\).*[\/\\]\(.*\)"$/\1 "\2"/g' %t/Test/main.cpp_common.h_*.yaml
+// RUN: diff -b %S/common.h.yaml %t/Test/main.cpp_common.h_*.yaml
+
+#include "common.h"
+
+void test_header_replacement() {
+ dostuff();
+ func2();
+}
OpenPOWER on IntegriCloud