summaryrefslogtreecommitdiff
path: root/clang/tools/c-arcmt-test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/tools/c-arcmt-test')
-rw-r--r--clang/tools/c-arcmt-test/CMakeLists.txt14
-rw-r--r--clang/tools/c-arcmt-test/Makefile25
-rw-r--r--clang/tools/c-arcmt-test/c-arcmt-test.c123
3 files changed, 162 insertions, 0 deletions
diff --git a/clang/tools/c-arcmt-test/CMakeLists.txt b/clang/tools/c-arcmt-test/CMakeLists.txt
new file mode 100644
index 0000000..351f4ad
--- /dev/null
+++ b/clang/tools/c-arcmt-test/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(LLVM_USED_LIBS libclang)
+
+set( LLVM_LINK_COMPONENTS
+ support
+ mc
+ )
+
+add_clang_executable(c-arcmt-test
+ c-arcmt-test.c
+ )
+
+set_target_properties(c-arcmt-test
+ PROPERTIES
+ LINKER_LANGUAGE CXX)
diff --git a/clang/tools/c-arcmt-test/Makefile b/clang/tools/c-arcmt-test/Makefile
new file mode 100644
index 0000000..818f648
--- /dev/null
+++ b/clang/tools/c-arcmt-test/Makefile
@@ -0,0 +1,25 @@
+##===- tools/c-arcmt-test/Makefile -------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+CLANG_LEVEL := ../..
+
+TOOLNAME = c-arcmt-test
+
+# No plugins, optimize startup time.
+TOOL_NO_EXPORTS = 1
+
+# Don't install this. It is used for tests.
+NO_INSTALL = 1
+
+LINK_COMPONENTS := support mc
+USEDLIBS = clang.a clangARCMigrate.a clangRewrite.a \
+ clangFrontend.a clangDriver.a \
+ clangSerialization.a clangParse.a clangSema.a \
+ clangAnalysis.a clangEdit.a clangAST.a clangLex.a clangBasic.a
+
+include $(CLANG_LEVEL)/Makefile
diff --git a/clang/tools/c-arcmt-test/c-arcmt-test.c b/clang/tools/c-arcmt-test/c-arcmt-test.c
new file mode 100644
index 0000000..56a4132
--- /dev/null
+++ b/clang/tools/c-arcmt-test/c-arcmt-test.c
@@ -0,0 +1,123 @@
+/* c-arcmt-test.c */
+
+#include "clang-c/Index.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#if defined(_WIN32)
+#include <io.h>
+#include <fcntl.h>
+#endif
+
+static int print_remappings(const char *path) {
+ CXRemapping remap;
+ unsigned i, N;
+ CXString origFname;
+ CXString transFname;
+
+ remap = clang_getRemappings(path);
+ if (!remap)
+ return 1;
+
+ N = clang_remap_getNumFiles(remap);
+ for (i = 0; i != N; ++i) {
+ clang_remap_getFilenames(remap, i, &origFname, &transFname);
+
+ fprintf(stdout, "%s\n", clang_getCString(origFname));
+ fprintf(stdout, "%s\n", clang_getCString(transFname));
+
+ clang_disposeString(origFname);
+ clang_disposeString(transFname);
+ }
+
+ clang_remap_dispose(remap);
+ return 0;
+}
+
+static int print_remappings_filelist(const char **files, unsigned numFiles) {
+ CXRemapping remap;
+ unsigned i, N;
+ CXString origFname;
+ CXString transFname;
+
+ remap = clang_getRemappingsFromFileList(files, numFiles);
+ if (!remap)
+ return 1;
+
+ N = clang_remap_getNumFiles(remap);
+ for (i = 0; i != N; ++i) {
+ clang_remap_getFilenames(remap, i, &origFname, &transFname);
+
+ fprintf(stdout, "%s\n", clang_getCString(origFname));
+ fprintf(stdout, "%s\n", clang_getCString(transFname));
+
+ clang_disposeString(origFname);
+ clang_disposeString(transFname);
+ }
+
+ clang_remap_dispose(remap);
+ return 0;
+}
+
+/******************************************************************************/
+/* Command line processing. */
+/******************************************************************************/
+
+static void print_usage(void) {
+ fprintf(stderr,
+ "usage: c-arcmt-test -mt-migrate-directory <path>\n"
+ " c-arcmt-test <remap-file-path1> <remap-file-path2> ...\n\n\n");
+}
+
+/***/
+
+int carcmttest_main(int argc, const char **argv) {
+ clang_enableStackTraces();
+ if (argc == 3 && strncmp(argv[1], "-mt-migrate-directory", 21) == 0)
+ return print_remappings(argv[2]);
+
+ if (argc > 1)
+ return print_remappings_filelist(argv+1, argc-1);
+
+ print_usage();
+ return 1;
+}
+
+/***/
+
+/* We intentionally run in a separate thread to ensure we at least minimal
+ * testing of a multithreaded environment (for example, having a reduced stack
+ * size). */
+
+typedef struct thread_info {
+ int argc;
+ const char **argv;
+ int result;
+} thread_info;
+void thread_runner(void *client_data_v) {
+ thread_info *client_data = client_data_v;
+ client_data->result = carcmttest_main(client_data->argc, client_data->argv);
+#ifdef __CYGWIN__
+ fflush(stdout); /* stdout is not flushed on Cygwin. */
+#endif
+}
+
+int main(int argc, const char **argv) {
+ thread_info client_data;
+
+#if defined(_WIN32)
+ if (getenv("LIBCLANG_LOGGING") == NULL)
+ putenv("LIBCLANG_LOGGING=1");
+ _setmode( _fileno(stdout), _O_BINARY );
+#else
+ setenv("LIBCLANG_LOGGING", "1", /*overwrite=*/0);
+#endif
+
+ if (getenv("CINDEXTEST_NOTHREADS"))
+ return carcmttest_main(argc, argv);
+
+ client_data.argc = argc;
+ client_data.argv = argv;
+ clang_executeOnThread(thread_runner, &client_data, 0);
+ return client_data.result;
+}