Skip to content

Commit

Permalink
💡 Write documents of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharp0802 committed Dec 8, 2024
1 parent 82000b1 commit d3fe9c8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS = *.h
PREDEFINED =
EXPAND_AS_DEFINED =
Expand Down
33 changes: 23 additions & 10 deletions src/polyglat-c/annotation-emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,44 @@
#include <clang/AST/RecursiveASTVisitor.h>

namespace polyglat::c {

/**
* @brief A recursive-ast-visitor that emits annotations to symbols
* to preserve object-oriented things over low-level environment (LLVM).
*/
class AnnotationEmitter final : public clang::RecursiveASTVisitor<AnnotationEmitter> {
clang::Sema *Sema;

static auto ShouldBeAnnotated(const clang::NamedDecl *decl) -> bool;

public:
/**
* @brief Creates new instance with specified semantic context.
* @param sema A semantic context to use.
*/
explicit AnnotationEmitter(clang::Sema *sema) : Sema(sema) {}

/**
* @brief Tries to annotate declaration of record.
* @param decl A declaration to be annotated.
*/
auto VisitRecordDecl(clang::RecordDecl *decl) -> bool;

/**
* @brief Tries to annotate declaration of function.
* @param decl A declaration to be annotated.
*/
auto VisitFunctionDecl(clang::FunctionDecl *decl) -> bool;
};

class ASTConsumer final : public clang::SemaConsumer {
clang::Sema *Sema = nullptr;

public:
void HandleTranslationUnit(clang::ASTContext &ctx) override;

void InitializeSema(clang::Sema &sema) override;
};

/**
* @brief A plugin-ast-action that emits annotations to result IR
* to preserve object-oriented things over low-level environment (LLVM).
*/
class AnnotationEmitAction final : public clang::PluginASTAction {
public:
/**
* @brief Creates new instance.
*/
auto CreateASTConsumer(clang::CompilerInstance &ci, llvm::StringRef inFile) -> std::unique_ptr<clang::ASTConsumer> override;

auto ParseArgs(const clang::CompilerInstance &ci, const std::vector<std::string> &arg) -> bool override;
Expand Down
19 changes: 12 additions & 7 deletions src/polyglat-c/src/annotation-emitter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ auto polyglat::c::AnnotationEmitter::VisitFunctionDecl(clang::FunctionDecl *decl
return true;
}

void polyglat::c::ASTConsumer::HandleTranslationUnit(clang::ASTContext &Ctx) {
AnnotationEmitter emitter{Sema};
emitter.TraverseDecl(Ctx.getTranslationUnitDecl());
}
class ASTConsumer final : public clang::SemaConsumer {
clang::Sema *Sema = nullptr;

void polyglat::c::ASTConsumer::InitializeSema(clang::Sema &S) {
Sema = &S;
}
public:
void HandleTranslationUnit(clang::ASTContext &ctx) override {
polyglat::c::AnnotationEmitter emitter{Sema};
emitter.TraverseDecl(ctx.getTranslationUnitDecl());
}

void InitializeSema(clang::Sema &sema) override {
Sema = &sema;
}
};

auto polyglat::c::AnnotationEmitAction::CreateASTConsumer(clang::CompilerInstance & /**/, llvm::StringRef /**/) -> std::unique_ptr<clang::ASTConsumer> {
return std::make_unique<ASTConsumer>();
Expand Down

0 comments on commit d3fe9c8

Please sign in to comment.