#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTImporter.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ExternalASTMerger.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/CodeGen/ModuleBuilder.h"
#include "clang/Driver/Types.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Parse/ParseAST.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Signals.h"
#include "llvm/TargetParser/Host.h"
#include <memory>
#include <string>
usingnamespaceclang;
static llvm::cl::opt<std::string> Expression(
"expression", llvm::cl::Required,
llvm::cl::desc("Path to a file containing the expression to parse"));
static llvm::cl::list<std::string>
Imports("import",
llvm::cl::desc("Path to a file containing declarations to import"));
static llvm::cl::opt<bool>
Direct("direct", llvm::cl::Optional,
llvm::cl::desc("Use the parsed declarations without indirection"));
static llvm::cl::opt<bool> UseOrigins(
"use-origins", llvm::cl::Optional,
llvm::cl::desc(
"Use DeclContext origin information for more accurate lookups"));
static llvm::cl::list<std::string>
ClangArgs("Xcc",
llvm::cl::desc("Argument to pass to the CompilerInvocation"),
llvm::cl::CommaSeparated);
static llvm::cl::opt<std::string>
Input("x", llvm::cl::Optional,
llvm::cl::desc("The language to parse (default: c++)"),
llvm::cl::init("c++"));
static llvm::cl::opt<bool> ObjCARC("objc-arc", llvm::cl::init(false),
llvm::cl::desc("Emable ObjC ARC"));
static llvm::cl::opt<bool> DumpAST("dump-ast", llvm::cl::init(false),
llvm::cl::desc("Dump combined AST"));
static llvm::cl::opt<bool> DumpIR("dump-ir", llvm::cl::init(false),
llvm::cl::desc("Dump IR from final parse"));
namespace init_convenience {
class TestDiagnosticConsumer : public DiagnosticConsumer { … };
std::unique_ptr<CompilerInstance> BuildCompilerInstance() { … }
std::unique_ptr<ASTContext>
BuildASTContext(CompilerInstance &CI, SelectorTable &ST, Builtin::Context &BC) { … }
std::unique_ptr<CodeGenerator> BuildCodeGen(CompilerInstance &CI,
llvm::LLVMContext &LLVMCtx) { … }
}
namespace {
struct CIAndOrigins { … };
void AddExternalSource(CIAndOrigins &CI,
llvm::MutableArrayRef<CIAndOrigins> Imports) { … }
CIAndOrigins BuildIndirect(CIAndOrigins &CI) { … }
llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI,
ASTConsumer &Consumer) { … }
llvm::Expected<CIAndOrigins> Parse(const std::string &Path,
llvm::MutableArrayRef<CIAndOrigins> Imports,
bool ShouldDumpAST, bool ShouldDumpIR) { … }
void Forget(CIAndOrigins &CI, llvm::MutableArrayRef<CIAndOrigins> Imports) { … }
}
int main(int argc, const char **argv) { … }