2013-01-05 02:25:18 +08:00
|
|
|
//===-- 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-07-08 20:17:37 +08:00
|
|
|
|
2013-09-05 03:13:50 +08:00
|
|
|
#ifndef CLANG_MODERNIZE_VARIABLE_NAMING_H
|
|
|
|
#define CLANG_MODERNIZE_VARIABLE_NAMING_H
|
2013-01-05 02:25:18 +08:00
|
|
|
|
|
|
|
#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:
|
2013-03-08 22:15:18 +08:00
|
|
|
VariableNamer(
|
|
|
|
StmtGeneratedVarNameMap *GeneratedDecls, const StmtParentMap *ReverseAST,
|
|
|
|
const clang::Stmt *SourceStmt, const clang::VarDecl *OldIndex,
|
|
|
|
const clang::VarDecl *TheContainer, const clang::ASTContext *Context)
|
|
|
|
: GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
|
|
|
|
SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer),
|
|
|
|
Context(Context) {}
|
2013-01-05 02:25:18 +08:00
|
|
|
|
|
|
|
/// \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;
|
2013-03-08 22:15:18 +08:00
|
|
|
const clang::ASTContext *Context;
|
2013-01-05 02:25:18 +08:00
|
|
|
|
|
|
|
// Determine whether or not a declaration that would conflict with Symbol
|
|
|
|
// exists in an outer context or in any statement contained in SourceStmt.
|
2013-03-08 22:15:18 +08:00
|
|
|
bool declarationExists(llvm::StringRef Symbol);
|
2013-01-05 02:25:18 +08:00
|
|
|
};
|
|
|
|
|
2013-09-05 03:13:50 +08:00
|
|
|
#endif // CLANG_MODERNIZE_VARIABLE_NAMING_H
|