Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ $(OBJ_DIR)/core/%.o: $(SRC_DIR)/core/%.cc
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) -MMD -MP -c $< -o $@

# 使用LLVM标志编译key_generator文件
$(OBJ_DIR)/util/key_generator/%.o: $(SRC_DIR)/util/key_generator/%.cc
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) -MMD -MP -c $< -o $@

# ==============================================
# Code Generation
# ==============================================
Expand Down
32 changes: 18 additions & 14 deletions include/core/processor/preprocessor_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "core/processor/base_processor.h"
#include "core/srcloc_recorder.h"
#include "model/db/preprocessor.h"
#include "model/db/container.h"
#include "model/db/preprocessor.h"
#include <clang/Basic/SourceLocation.h>
#include <clang/Lex/PPCallbacks.h>
#include <clang/Lex/Preprocessor.h>
Expand All @@ -16,7 +16,7 @@ using namespace clang;
class PreprocessorProcessor : public BaseProcessor, public PPCallbacks {
public:
PreprocessorProcessor(ASTContext *ast_context, const PrintingPolicy pp,
class Preprocessor *preprocessor);
class Preprocessor *preprocessor);
~PreprocessorProcessor() = default;

////// PPCallbacks Interface - Conditional Compilation //////
Expand All @@ -35,24 +35,26 @@ class PreprocessorProcessor : public BaseProcessor, public PPCallbacks {
////// PPCallbacks Interface - Include Directives //////

void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath,
const Module *SuggestedModule, bool ModuleImported,
SrcMgr::CharacteristicKind FileType) override;
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *SuggestedModule,
bool ModuleImported,
SrcMgr::CharacteristicKind FileType) override;

////// PPCallbacks Interface - Macro Definitions //////

void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) override;
void MacroDefined(const Token &MacroNameTok,
const MacroDirective *MD) override;
void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
const MacroDirective *Undef) override;

////// PPCallbacks Interface - Other Directives //////

void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind Introducer) override;
void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind,
StringRef Str) override;
void PragmaDirective(SourceLocation Loc,
PragmaIntroducerKind Introducer) override;
void PragmaMessage(SourceLocation Loc, StringRef Namespace,
PragmaMessageKind Kind, StringRef Str) override;
void PragmaDebug(SourceLocation Loc, StringRef DebugType) override;

private:
Expand All @@ -72,10 +74,12 @@ class PreprocessorProcessor : public BaseProcessor, public PPCallbacks {
////// Helper Methods //////

// Process a preprocessor directive and return its ID
int processDirective(SourceLocation Loc, PreprocDirectKind kind);
int processDirective(SourceLocation Loc, PreprocDirectKind kind,
const std::string &key_suffix = "");

// Extract and store directive text (head and body)
void extractDirectiveText(SourceLocation Loc, int directive_id, PreprocDirectKind kind);
void extractDirectiveText(SourceLocation Loc, int directive_id,
PreprocDirectKind kind);

// Record branch pairing (begin -> elif/else/endif)
void recordBranchPair(int begin_id, int end_id);
Expand Down
9 changes: 9 additions & 0 deletions include/db/table_defs/preprocessor.h
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要对照 schemedatatable-list, 来加入相关数据表的实现.

这个macro_defs好像并不是文档中的数据表

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ inline auto includes() {
make_column("included", &DbModel::Includes::included));
}

inline auto macro_defs() {
return make_table(
"macro_defs",
make_column("id", &DbModel::MacroDef::id, primary_key()),
make_column("name", &DbModel::MacroDef::name),
make_column("body", &DbModel::MacroDef::body),
make_column("location", &DbModel::MacroDef::location));
}

// clang-format on

} // namespace PreprocessorTableFn
Expand Down
13 changes: 6 additions & 7 deletions include/util/key_generator/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@

#include "db/cache_repository.h"
#include "model/db/preprocessor.h"
#include <clang/Basic/SourceLocation.h>
#include <clang/Lex/Preprocessor.h>
#include <string>

#define SEARCH_PREPROC_CACHE(key) \
#define SEARCH_PREPROC_CACHE(key) \
CacheManager::instance() \
.getRepository<CacheRepository<DbModel::Preprocdirect>>() \
.getRepository<CacheRepository<DbModel::Preprocdirect>>() \
.find(key)

#define INSERT_PREPROC_CACHE(key, id) \
#define INSERT_PREPROC_CACHE(key, id) \
CacheManager::instance() \
.getRepository<CacheRepository<DbModel::Preprocdirect>>() \
.getRepository<CacheRepository<DbModel::Preprocdirect>>() \
.insert(key, id)

using KeyType = std::string;
Expand All @@ -24,7 +22,8 @@ namespace KeyGen {
namespace Preprocessor {

// Generate unique key for preprocessor directive based on source location
KeyType makeKey(clang::SourceLocation Loc, clang::Preprocessor &PP);
KeyType makeKey(const std::string &filename, unsigned line, unsigned column,
int directive_kind, const std::string &extra_tag = "");

} // namespace Preprocessor

Expand Down
Loading