[clang-tools-extra] r175545 - Adding files left out of commit r175544.

Edwin Vane edwin.vane at intel.com
Tue Feb 19 11:14:45 PST 2013


Author: revane
Date: Tue Feb 19 13:14:45 2013
New Revision: 175545

URL: http://llvm.org/viewvc/llvm-project?rev=175545&view=rev
Log:
Adding files left out of commit r175544.


Added:
    clang-tools-extra/trunk/test/cpp11-migrate/CMakeLists.txt
    clang-tools-extra/trunk/test/cpp11-migrate/Makefile
    clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/
    clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/
    clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/gen_my_std.h.py
    clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/gen_basic_std_iterator_tests.cpp.py

Added: clang-tools-extra/trunk/test/cpp11-migrate/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/CMakeLists.txt?rev=175545&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/test/cpp11-migrate/CMakeLists.txt Tue Feb 19 13:14:45 2013
@@ -0,0 +1,59 @@
+
+# List of generator scripts. Generator scripts must:
+# * Be written in python
+# * Output their result to standard out.
+# * Be named as gen_X.py where X will be the name of the auto-generated file.
+set(generator_scripts
+  UseAuto/gen_basic_std_iterator_tests.cpp.py
+  UseAuto/Inputs/gen_my_std.h.py
+  )
+
+# macro that runs a generator script to produce an auto-generated file.
+# Generator scripts must follow scheme above. The resulting file is placed in:
+# ${CMAKE_CURRENT_BINARY_DIR})/autogen/dirname(<script name>).
+#
+# Two arguments are required:
+# script - The generator script (relative to ${CMAKE_CURRENT_SOURCE_DIR})
+# output - Name of the variable to store the name of the generated file in.
+macro(autogenerate_file script output)
+  get_filename_component(dir ${script} PATH)
+  file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/autogen/${dir}")
+  string(REGEX REPLACE "gen_(.*).py" "\\1" output_name ${script})
+  set(script_file
+    "${CMAKE_CURRENT_SOURCE_DIR}/${script}"
+    )
+  set(output_file
+    "${CMAKE_CURRENT_BINARY_DIR}/autogen/${output_name}"
+    )
+  set(gencmd
+    ${PYTHON_EXECUTABLE}
+    ${script_file} > ${output_file}
+    )
+  add_custom_command(
+    OUTPUT ${output_file}
+    COMMAND ${gencmd}
+    DEPENDS ${script_file}
+    )
+  set(${output} ${output_file})
+endmacro(autogenerate_file)
+
+# Define rules to run generator scripts.
+set(depends)
+foreach(script ${generator_scripts})
+  autogenerate_file(${script} output)
+  list(APPEND depends ${output})
+endforeach()
+
+# This custom target will be used by parent CMakeLists.txt to ensure all
+# auto-generated files are created before lit is run.
+add_custom_target(cpp11-migrate-autogen
+  DEPENDS ${depends}
+  )
+
+set(TEST_SOURCE_ROOT ${CMAKE_CURRENT_BINARY_DIR}/autogen)
+set(TEST_EXEC_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+set(TESTSUITE_NAME "cpp11-migrate Auto-Generated Tests")
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/../lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/autogen/lit.site.cfg
+  )

Added: clang-tools-extra/trunk/test/cpp11-migrate/Makefile
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/Makefile?rev=175545&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/Makefile (added)
+++ clang-tools-extra/trunk/test/cpp11-migrate/Makefile Tue Feb 19 13:14:45 2013
@@ -0,0 +1,66 @@
+##===- tools/extra/test/cpp11-migrate/Makefile -------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+# This Makefile is responsible for creating a LIT testsuite for auto-generated
+# tests. The recipe that runs llvm-lit needs to provide the following path of
+# the lit.site.cfg for the generated testsuite: $(PROJ_OBJ_DIR)/autogen.
+
+CLANG_LEVEL := ../../../..
+include $(CLANG_LEVEL)/Makefile
+
+# List of generator scripts. Generator scripts must:
+# * Be written in python
+# * Output their result to standard out.
+# * Be named as gen_X.py where X will be the name of the auto-generated file.
+GENERATOR_SCRIPTS := \
+  UseAuto/gen_basic_std_iterator_tests.cpp.py \
+  UseAuto/Inputs/gen_my_std.h.py
+
+
+# macro to be used with $(call) that generates a rule and recipe that causes a
+# file to be auto-generated from a generator script. Generator scripts must
+# follow scheme above. The resulting file is placed in:
+# $(PROJ_OBJ_DIR)/autogen/$(dir <script name>).
+#
+# One argument required: the name of generator script relative to
+# $(PROJ_SRC_DIR).
+define autogenerate-file
+OUTFILE := $(addprefix autogen/$(dir $1), $(patsubst gen_%.py,%,$(notdir $1)))
+GENERATED_FILES := $$(GENERATED_FILES) $$(OUTFILE)
+$$(OUTFILE): $1
+	@echo "Autogenerating $$<"
+	@$(MKDIR) $(addprefix autogen/, $(dir $1))
+	@$(PYTHON) $$< > $$@
+endef
+$(foreach script, $(GENERATOR_SCRIPTS), $(eval $(call autogenerate-file,$(script))))
+
+FORCE:
+
+autogen/lit.site.cfg: FORCE
+	@$(MKDIR) $(PROJ_OBJ_DIR)/autogen
+	@echo "Making cpp11-migrate Auto-Generated Tests' 'lit.site.cfg' file..."
+	@$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > lit.tmp
+	@$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp
+	@$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> lit.tmp
+	@$(ECHOPATH) s=@LLVM_LIBS_DIR@=$(LibDir)=g >> lit.tmp
+	@$(ECHOPATH) s=@CLANG_TOOLS_SOURCE_DIR@=$(PROJ_SRC_DIR)/../..=g >> lit.tmp
+	@$(ECHOPATH) s=@CLANG_TOOLS_BINARY_DIR@=$(PROJ_OBJ_DIR)/../..=g >> lit.tmp
+	@$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g >> lit.tmp
+	@$(ECHOPATH) s=@TEST_SOURCE_ROOT@=$(PROJ_OBJ_DIR)/autogen=g >> lit.tmp
+	@$(ECHOPATH) s=@TEST_EXEC_ROOT@=$(PROJ_OBJ_DIR)=g >> lit.tmp
+	@$(ECHOPATH) s=@TESTSUITE_NAME@=cpp11-migrate Auto-Generated Tests=g >> lit.tmp
+	@sed -f lit.tmp $(PROJ_SRC_DIR)/../lit.site.cfg.in > $@
+	@-rm -f lit.tmp
+
+all:: $(GENERATED_FILES) autogen/lit.site.cfg
+
+clean::
+	@rm -r autogen
+
+.PHONY: all clean

Added: clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/gen_my_std.h.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/gen_my_std.h.py?rev=175545&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/gen_my_std.h.py (added)
+++ clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/gen_my_std.h.py Tue Feb 19 13:14:45 2013
@@ -0,0 +1,98 @@
+#!/usr/bin/python
+
+typedef_containers = [
+    "array",
+    "deque",
+    "forward_list",
+    "list",
+    "vector"
+]
+subclass_containers = [
+    "map",
+    "multimap",
+    "set",
+    "multiset",
+]
+using_containers = [
+    "unordered_map",
+    "unordered_multimap",
+    "unordered_set",
+    "unordered_multiset",
+    "queue",
+    "priority_queue",
+    "stack"
+]
+
+print """namespace internal {
+
+template <typename T, int i>
+struct iterator_wrapper {
+};
+
+template <typename T>
+class iterator_provider {
+public:
+  class iterator {};
+  class const_iterator {};
+  class reverse_iterator {};
+  class const_reverse_iterator {};
+};
+
+} // namespace internal
+
+namespace std {"""
+
+iterator_generators = """
+  iterator begin() { return iterator(); }
+  iterator end() { return iterator(); }
+
+  const_iterator begin() const { return const_iterator(); }
+  const_iterator end() const { return const_iterator(); }
+
+  reverse_iterator rbegin() { return reverse_iterator(); }
+  reverse_iterator rend() { return reverse_iterator(); }
+
+  const_reverse_iterator rbegin() const { return const_reverse_iterator(); }
+  const_reverse_iterator rend() const { return const_reverse_iterator(); }
+"""
+
+for c in typedef_containers:
+  print """
+template <typename T>
+class {0} {{
+public:
+  typedef typename internal::iterator_wrapper<{0}<T>, 0> iterator;
+  typedef typename internal::iterator_wrapper<{0}<T>, 1> const_iterator;
+  typedef typename internal::iterator_wrapper<{0}<T>, 3> reverse_iterator;
+  typedef typename internal::iterator_wrapper<{0}<T>, 2> const_reverse_iterator;
+
+  {0}() {{}}
+  {1}}};""".format(c, iterator_generators)
+
+for c in subclass_containers:
+  print """
+template <typename T>
+class {0} {{
+public:
+  class iterator {{}};
+  class const_iterator {{}};
+  class reverse_iterator {{}};
+  class const_reverse_iterator {{}};
+
+  {0}() {{}}
+  {1}}};""".format(c, iterator_generators)
+
+for c in using_containers:
+  print """
+template <typename T>
+class {0} : internal::iterator_provider<{0}<T> > {{
+public:
+  using typename internal::iterator_provider<{0}<T> >::iterator;
+  using typename internal::iterator_provider<{0}<T> >::const_iterator;
+  using typename internal::iterator_provider<{0}<T> >::reverse_iterator;
+  using typename internal::iterator_provider<{0}<T> >::const_reverse_iterator;
+
+  {0}() {{}}
+  {1}}};""".format(c, iterator_generators)
+
+print "} // namespace std"

Added: clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/gen_basic_std_iterator_tests.cpp.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/gen_basic_std_iterator_tests.cpp.py?rev=175545&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/gen_basic_std_iterator_tests.cpp.py (added)
+++ clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/gen_basic_std_iterator_tests.cpp.py Tue Feb 19 13:14:45 2013
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+containers = [
+    "array",
+    "deque",
+    "forward_list",
+    "list",
+    "vector",
+    "map",
+    "multimap",
+    "set",
+    "multiset",
+    "unordered_map",
+    "unordered_multimap",
+    "unordered_set",
+    "unordered_multiset",
+    "queue",
+    "priority_queue",
+    "stack"
+]
+
+print """// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -use-auto %t.cpp -- --std=c++11 -I %S/Inputs
+// RUN: FileCheck -input-file=%t.cpp %s
+// XFAIL: *
+#include "my_std.h"
+
+int main(int argc, char **argv) {"""
+
+for c in containers:
+  print """
+  {{
+    std::{0}<int> C;
+    std::{0}<int>::iterator I = C.begin();
+    // CHECK: auto I = C.begin();
+  }}
+  {{
+    std::{0}<int> C;
+    std::{0}<int>::reverse_iterator I = C.rbegin();
+    // CHECK: auto I = C.rbegin();
+  }}
+  {{
+    const std::{0}<int> C;
+    std::{0}<int>::const_iterator I = C.begin();
+    // CHECK: auto I = C.begin();
+  }}
+  {{
+    const std::{0}<int> C;
+    std::{0}<int>::const_reverse_iterator I = C.rbegin();
+    // CHECK: auto I = C.rbegin();
+  }}""".format(c)
+
+print """
+  return 0;
+}"""





More information about the cfe-commits mailing list