blob: b6371b86766dc067c36e5e3fef9dd0d4d88b3345 [file] [log] [blame]
Edwin Vanedde168b2013-01-04 18:25:18 +00001//===-- LoopConvert/VariableNaming.h - Gererate variable names --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file contains the declaration of the VariableNamer class, which
12/// is responsible for generating new variable names and ensuring that they do
13/// not conflict with existing ones.
14//
15//===----------------------------------------------------------------------===//
16#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
17#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
18
19#include "StmtAncestor.h"
20#include "clang/AST/ASTContext.h"
21
22/// \brief Create names for generated variables within a particular statement.
23///
24/// VariableNamer uses a DeclContext as a reference point, checking for any
25/// conflicting declarations higher up in the context or within SourceStmt.
26/// It creates a variable name using hints from a source container and the old
27/// index, if they exist.
28class VariableNamer {
29 public:
30 VariableNamer(StmtGeneratedVarNameMap *GeneratedDecls,
31 const StmtParentMap *ReverseAST, const clang::Stmt *SourceStmt,
32 const clang::VarDecl *OldIndex,
33 const clang::VarDecl *TheContainer) :
34 GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
35 SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer) { }
36
37 /// \brief Generate a new index name.
38 ///
39 /// Generates the name to be used for an inserted iterator. It relies on
40 /// declarationExists() to determine that there are no naming conflicts, and
41 /// tries to use some hints from the container name and the old index name.
42 std::string createIndexName();
43
44 private:
45 StmtGeneratedVarNameMap *GeneratedDecls;
46 const StmtParentMap *ReverseAST;
47 const clang::Stmt *SourceStmt;
48 const clang::VarDecl *OldIndex;
49 const clang::VarDecl *TheContainer;
50
51 // Determine whether or not a declaration that would conflict with Symbol
52 // exists in an outer context or in any statement contained in SourceStmt.
53 bool declarationExists(const llvm::StringRef Symbol);
54};
55
56#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H