ClangPlugin: Add a PPCallbacks instance to collect JS_CELL-like macros

This commit is contained in:
Matthew Olsson 2024-05-19 11:39:43 -07:00 committed by Andrew Kaster
commit 54fffef902
Notes: sideshowbarker 2024-07-16 21:34:08 +09:00
2 changed files with 103 additions and 0 deletions

View file

@ -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)