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