Port loop-convert into cpp11-migrate
Took existing code from loop-convert tool and made it into a cpp11-migrate
transform. Pattern now set for having transform code in subdirectories. Related
changes:
- Makefile and CMakeLists.txt updated to support source files in
subdirectories.
- At least one transform must be specified. syntax-only tests removed to
reflect this.
- TODO: port over loop-convert tests.
Reviewers: klimek, silvas
llvm-svn: 171481
diff --git a/clang-tools-extra/cpp11-migrate/LoopConvert/VariableNaming.h b/clang-tools-extra/cpp11-migrate/LoopConvert/VariableNaming.h
new file mode 100644
index 0000000..b6371b8
--- /dev/null
+++ b/clang-tools-extra/cpp11-migrate/LoopConvert/VariableNaming.h
@@ -0,0 +1,56 @@
+//===-- LoopConvert/VariableNaming.h - Gererate variable names --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file contains the declaration of the VariableNamer class, which
+/// is responsible for generating new variable names and ensuring that they do
+/// not conflict with existing ones.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
+#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
+
+#include "StmtAncestor.h"
+#include "clang/AST/ASTContext.h"
+
+/// \brief Create names for generated variables within a particular statement.
+///
+/// VariableNamer uses a DeclContext as a reference point, checking for any
+/// conflicting declarations higher up in the context or within SourceStmt.
+/// It creates a variable name using hints from a source container and the old
+/// index, if they exist.
+class VariableNamer {
+ public:
+ VariableNamer(StmtGeneratedVarNameMap *GeneratedDecls,
+ const StmtParentMap *ReverseAST, const clang::Stmt *SourceStmt,
+ const clang::VarDecl *OldIndex,
+ const clang::VarDecl *TheContainer) :
+ GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
+ SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer) { }
+
+ /// \brief Generate a new index name.
+ ///
+ /// Generates the name to be used for an inserted iterator. It relies on
+ /// declarationExists() to determine that there are no naming conflicts, and
+ /// tries to use some hints from the container name and the old index name.
+ std::string createIndexName();
+
+ private:
+ StmtGeneratedVarNameMap *GeneratedDecls;
+ const StmtParentMap *ReverseAST;
+ const clang::Stmt *SourceStmt;
+ const clang::VarDecl *OldIndex;
+ const clang::VarDecl *TheContainer;
+
+ // Determine whether or not a declaration that would conflict with Symbol
+ // exists in an outer context or in any statement contained in SourceStmt.
+ bool declarationExists(const llvm::StringRef Symbol);
+};
+
+#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H