basic setting of ParsedAST.

This commit is contained in:
ykiko
2024-08-30 21:45:55 +08:00
parent 81a063b628
commit 91e9094105
10 changed files with 188 additions and 45 deletions

11
include/AST/Diagnostic.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Sema/Sema.h>
#include <clang/Tooling/CompilationDatabase.h>
#include <clang/Tooling/Syntax/Tokens.h>
#include <clang/Lex/PPCallbacks.h>

21
include/AST/ParsedAST.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include "Preamble.h"
namespace clice {
struct ParsedAST {
std::unique_ptr<clang::FrontendAction> action;
std::unique_ptr<clang::CompilerInstance> instance;
static std::unique_ptr<ParsedAST>
build(llvm::StringRef filename, llvm::StringRef content, std::vector<const char*>& args, Preamble* preamble);
auto& ASTContext() const { return instance->getASTContext(); }
auto& SourceManager() const { return instance->getSourceManager(); }
auto TranslationUnitDecl() const { return ASTContext().getTranslationUnitDecl(); }
};
} // namespace clice

17
include/AST/Preamble.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include "Diagnostic.h"
namespace clice {
/// Represents the preamble of a translation unit.
/// We build preamble for the translation after first edit.
/// The preamble is used to speed up the reparse of the translation unit.
struct Preamble {
clang::PrecompiledPreamble data;
static std::unique_ptr<Preamble>
build(llvm::StringRef filename, llvm::StringRef content, std::vector<const char*>& args);
};
} // namespace clice