opnsense-src/include/clang/Frontend/ASTUnit.h

182 lines
6.5 KiB
C
Raw Normal View History

2009-06-22 04:08:35 -04:00
//===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// ASTUnit utility class.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
#define LLVM_CLANG_FRONTEND_ASTUNIT_H
2009-10-14 14:03:49 -04:00
#include "clang/Basic/SourceManager.h"
2009-06-22 04:08:35 -04:00
#include "llvm/ADT/OwningPtr.h"
2009-10-23 10:22:18 -04:00
#include "clang/Basic/FileManager.h"
2009-11-04 10:04:32 -05:00
#include "clang/Index/ASTLocation.h"
2009-06-22 04:08:35 -04:00
#include <string>
2009-12-15 13:49:47 -05:00
#include <vector>
#include <cassert>
2010-01-23 06:10:26 -05:00
#include <utility>
namespace llvm {
class MemoryBuffer;
}
2009-06-22 04:08:35 -04:00
namespace clang {
2009-12-01 06:08:04 -05:00
class ASTContext;
class CompilerInvocation;
class Decl;
class Diagnostic;
class FileEntry;
class FileManager;
class HeaderSearch;
class Preprocessor;
class SourceManager;
class TargetInfo;
2009-06-22 04:08:35 -04:00
2009-11-04 10:04:32 -05:00
using namespace idx;
2009-06-22 04:08:35 -04:00
/// \brief Utility class for loading a ASTContext from a PCH file.
///
class ASTUnit {
2009-10-23 10:22:18 -04:00
FileManager FileMgr;
2009-10-14 14:03:49 -04:00
SourceManager SourceMgr;
2009-06-22 04:08:35 -04:00
llvm::OwningPtr<HeaderSearch> HeaderInfo;
llvm::OwningPtr<TargetInfo> Target;
llvm::OwningPtr<Preprocessor> PP;
llvm::OwningPtr<ASTContext> Ctx;
2009-10-23 10:22:18 -04:00
bool tempFile;
2009-12-15 13:49:47 -05:00
2010-02-16 04:31:36 -05:00
/// Optional owned invocation, just used to make the invocation used in
/// LoadFromCommandLine available.
llvm::OwningPtr<CompilerInvocation> Invocation;
2009-10-23 10:22:18 -04:00
// OnlyLocalDecls - when true, walking this AST should only visit declarations
// that come from the AST itself, not from included precompiled headers.
// FIXME: This is temporary; eventually, CIndex will always do this.
bool OnlyLocalDecls;
2009-12-15 13:49:47 -05:00
/// Track whether the main file was loaded from an AST or not.
bool MainFileIsAST;
/// Track the top-level decls which appeared in an ASTUnit which was loaded
/// from a source file.
//
// FIXME: This is just an optimization hack to avoid deserializing large parts
// of a PCH file when using the Index library on an ASTUnit loaded from
// source. In the long term we should make the Index library use efficient and
// more scalable search mechanisms.
std::vector<Decl*> TopLevelDecls;
/// The name of the original source file used to generate this ASTUnit.
std::string OriginalSourceFile;
2009-11-04 10:04:32 -05:00
// Critical optimization when using clang_getCursor().
ASTLocation LastLoc;
2009-12-15 13:49:47 -05:00
2009-10-14 14:03:49 -04:00
ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
2009-06-22 04:08:35 -04:00
public:
2009-12-15 13:49:47 -05:00
ASTUnit(bool MainFileIsAST);
2009-06-22 04:08:35 -04:00
~ASTUnit();
2009-12-15 13:49:47 -05:00
bool isMainFileAST() const { return MainFileIsAST; }
2009-10-14 14:03:49 -04:00
const SourceManager &getSourceManager() const { return SourceMgr; }
SourceManager &getSourceManager() { return SourceMgr; }
2009-06-22 04:08:35 -04:00
const Preprocessor &getPreprocessor() const { return *PP.get(); }
Preprocessor &getPreprocessor() { return *PP.get(); }
2009-10-14 14:03:49 -04:00
2009-06-22 04:08:35 -04:00
const ASTContext &getASTContext() const { return *Ctx.get(); }
ASTContext &getASTContext() { return *Ctx.get(); }
2009-10-23 10:22:18 -04:00
const FileManager &getFileManager() const { return FileMgr; }
FileManager &getFileManager() { return FileMgr; }
2009-12-15 13:49:47 -05:00
2009-10-14 14:03:49 -04:00
const std::string &getOriginalSourceFileName();
2009-10-23 10:22:18 -04:00
const std::string &getPCHFileName();
2009-10-14 14:03:49 -04:00
2009-10-23 10:22:18 -04:00
void unlinkTemporaryFile() { tempFile = true; }
2009-12-15 13:49:47 -05:00
2009-10-23 10:22:18 -04:00
bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
2009-12-15 13:49:47 -05:00
2009-11-04 10:04:32 -05:00
void setLastASTLocation(ASTLocation ALoc) { LastLoc = ALoc; }
ASTLocation getLastASTLocation() const { return LastLoc; }
2009-12-15 13:49:47 -05:00
std::vector<Decl*> &getTopLevelDecls() {
assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
return TopLevelDecls;
}
const std::vector<Decl*> &getTopLevelDecls() const {
assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
return TopLevelDecls;
}
2010-01-23 06:10:26 -05:00
/// \brief A mapping from a file name to the memory buffer that stores the
/// remapped contents of that file.
typedef std::pair<std::string, const llvm::MemoryBuffer *> RemappedFile;
2009-06-22 04:08:35 -04:00
/// \brief Create a ASTUnit from a PCH file.
///
2009-10-14 14:03:49 -04:00
/// \param Filename - The PCH file to load.
///
2009-12-15 13:49:47 -05:00
/// \param Diags - The diagnostics engine to use for reporting errors; its
/// lifetime is expected to extend past that of the returned ASTUnit.
2009-06-22 04:08:35 -04:00
///
2009-10-14 14:03:49 -04:00
/// \returns - The initialized ASTUnit or null if the PCH failed to load.
2009-06-22 04:08:35 -04:00
static ASTUnit *LoadFromPCHFile(const std::string &Filename,
2009-12-15 13:49:47 -05:00
Diagnostic &Diags,
2009-10-23 10:22:18 -04:00
bool OnlyLocalDecls = false,
2010-01-23 06:10:26 -05:00
RemappedFile *RemappedFiles = 0,
unsigned NumRemappedFiles = 0);
2009-12-01 06:08:04 -05:00
/// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
/// CompilerInvocation object.
///
/// \param CI - The compiler invocation to use; it must have exactly one input
2010-02-16 04:31:36 -05:00
/// source file. The ASTUnit takes ownership of the CompilerInvocation object.
2009-12-01 06:08:04 -05:00
///
2009-12-15 13:49:47 -05:00
/// \param Diags - The diagnostics engine to use for reporting errors; its
/// lifetime is expected to extend past that of the returned ASTUnit.
2009-12-01 06:08:04 -05:00
//
// FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
// shouldn't need to specify them at construction time.
2010-02-16 04:31:36 -05:00
static ASTUnit *LoadFromCompilerInvocation(CompilerInvocation *CI,
2009-12-01 06:08:04 -05:00
Diagnostic &Diags,
2009-12-15 13:49:47 -05:00
bool OnlyLocalDecls = false);
2009-12-01 06:08:04 -05:00
2009-12-15 13:49:47 -05:00
/// LoadFromCommandLine - Create an ASTUnit from a vector of command line
/// arguments, which must specify exactly one source file.
///
/// \param ArgBegin - The beginning of the argument vector.
///
/// \param ArgEnd - The end of the argument vector.
///
/// \param Diags - The diagnostics engine to use for reporting errors; its
/// lifetime is expected to extend past that of the returned ASTUnit.
///
/// \param ResourceFilesPath - The path to the compiler resource files.
//
// FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
// shouldn't need to specify them at construction time.
static ASTUnit *LoadFromCommandLine(const char **ArgBegin,
const char **ArgEnd,
Diagnostic &Diags,
llvm::StringRef ResourceFilesPath,
bool OnlyLocalDecls = false,
2010-01-23 06:10:26 -05:00
RemappedFile *RemappedFiles = 0,
unsigned NumRemappedFiles = 0);
2009-06-22 04:08:35 -04:00
};
} // namespace clang
#endif