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 {
23 /// \brief VariableNamer - Create names for generated variables within
24 /// 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(ASTContext *Context, StmtGeneratedVarNameMap *GeneratedDecls,
33 const StmtParentMap *ReverseAST, const DeclContext *LoopContext,
34 const Stmt *SourceStmt, const VarDecl *OldIndex,
35 const VarDecl *TheContainer) :
36 Context(Context), GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
37 LoopContext(LoopContext), SourceStmt(SourceStmt), OldIndex(OldIndex),
38 TheContainer(TheContainer) { }
40 /// \brief Generate a new index name.
42 /// Generates the name to be used for an inserted iterator. It relies on
43 /// declarationExists() to determine that there are no naming conflicts, and
44 /// tries to use some hints from the container name and the old index name.
45 std::string createIndexName();
49 StmtGeneratedVarNameMap *GeneratedDecls;
50 const StmtParentMap *ReverseAST;
51 const DeclContext *LoopContext;
52 const Stmt *SourceStmt;
53 const VarDecl *OldIndex;
54 const VarDecl *TheContainer;
56 // Determine whether or not a declaration that would conflict with Symbol
57 // exists in an outer context or in any statement contained in SourceStmt.
58 bool declarationExists(const std::string &Symbol);
61 } // namespace loop_migrate
63 #endif //_LLVM_TOOLS_CLANG_TOOLS_LOOP_VARIABLE_NAMING_H_