add Directive.

This commit is contained in:
ykiko
2024-07-25 19:57:06 +08:00
parent 498f66d426
commit c5a34e0b9e
6 changed files with 103 additions and 66 deletions

View File

@@ -9,11 +9,10 @@
#include <clang/Tooling/CompilationDatabase.h>
#include <clang/Tooling/Syntax/Tokens.h>
namespace clice {
using llvm::StringRef;
using PathRef = StringRef;
using clang::CompilerInstance;
using clang::CompilerInvocation;

27
include/Clang/Directive.h Normal file
View File

@@ -0,0 +1,27 @@
#include <Clang/Clang.h>
namespace clice {
struct MacroDefinition {
std::string name;
std::string definition;
clang::SourceRange range;
};
struct MacroExpansion {
std::string name;
std::string expansion;
};
class Directive {
private:
std::string name;
clang::SourceRange range;
std::vector<MacroDefinition> definitions;
std::vector<MacroExpansion> expansions;
public:
static std::unique_ptr<Directive> create(clang::SourceManager& sourceManager, clang::SourceRange range);
};
} // namespace clice

View File

@@ -9,7 +9,6 @@ namespace clice {
class ParsedAST {
private:
using Decl = clang::Decl*;
using PathRef = llvm::StringRef;
using TokenBuffer = clang::syntax::TokenBuffer;
using ASTConsumer = std::unique_ptr<clang::ASTConsumer>;
@@ -32,8 +31,6 @@ private:
clang::SyntaxOnlyAction action;
CompilerInstance instance;
ParsedAST() = default;
public:
static std::unique_ptr<ParsedAST> build(std::string_view path, std::string_view content);

View File

@@ -1,20 +1,19 @@
#pragma once
#include "Clang.h"
#include "Directive.h"
namespace clice {
class Preamble {
private:
clang::PrecompiledPreamble* preamble;
Directive directive;
clang::PrecompiledPreamble data;
Preamble(clang::PrecompiledPreamble* preamble) : preamble(preamble) {}
Preamble(clang::PrecompiledPreamble&& preamble) : data(std::move(preamble)) {}
public:
Preamble() = default;
static Preamble
build(std::string_view path, std::string_view content, const CompilerInvocation& invocation);
static std::unique_ptr<Preamble>
build(PathRef path, StringRef content, const CompilerInvocation& invocation);
};
} // namespace clice