mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 01:26:22 +00:00
ClangPlugin: Add a PPCallbacks instance to collect JS_CELL-like macros
This commit is contained in:
parent
d74838f44d
commit
54fffef902
Notes:
sideshowbarker
2024-07-16 21:34:08 +09:00
Author: https://github.com/mattco98
Commit: 54fffef902
Pull-request: https://github.com/SerenityOS/serenity/pull/24422
Issue: https://github.com/SerenityOS/serenity/issues/23880
Issue: https://github.com/SerenityOS/serenity/issues/23881
Issue: https://github.com/SerenityOS/serenity/issues/23900
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 103 additions and 0 deletions
|
@ -10,6 +10,47 @@
|
|||
#include <clang/AST/RecursiveASTVisitor.h>
|
||||
#include <clang/Frontend/FrontendAction.h>
|
||||
|
||||
struct LibJSCellMacro {
|
||||
enum class Type {
|
||||
JSCell,
|
||||
JSObject,
|
||||
JSEnvironment,
|
||||
JSPrototypeObject,
|
||||
WebPlatformObject,
|
||||
};
|
||||
|
||||
struct Arg {
|
||||
std::string text;
|
||||
clang::SourceLocation location;
|
||||
};
|
||||
|
||||
clang::SourceRange range;
|
||||
Type type;
|
||||
std::vector<Arg> args;
|
||||
|
||||
static char const* type_name(Type);
|
||||
};
|
||||
|
||||
using LibJSCellMacroMap = std::unordered_map<unsigned int, std::vector<LibJSCellMacro>>;
|
||||
|
||||
class LibJSPPCallbacks : public clang::PPCallbacks {
|
||||
public:
|
||||
LibJSPPCallbacks(clang::Preprocessor& preprocessor, LibJSCellMacroMap& macro_map)
|
||||
: m_preprocessor(preprocessor)
|
||||
, m_macro_map(macro_map)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void LexedFileChanged(clang::FileID curr_fid, LexedFileChangeReason, clang::SrcMgr::CharacteristicKind, clang::FileID, clang::SourceLocation) override;
|
||||
|
||||
virtual void MacroExpands(clang::Token const& name_token, clang::MacroDefinition const& definition, clang::SourceRange range, clang::MacroArgs const* args) override;
|
||||
|
||||
private:
|
||||
clang::Preprocessor& m_preprocessor;
|
||||
std::vector<unsigned int> m_curr_fid_hash_stack;
|
||||
LibJSCellMacroMap& m_macro_map;
|
||||
};
|
||||
|
||||
class LibJSGCVisitor : public clang::RecursiveASTVisitor<LibJSGCVisitor> {
|
||||
public:
|
||||
explicit LibJSGCVisitor(clang::ASTContext& context)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue