1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:15:09 +00:00

Lagom: Add a tool to verify correctness of the LibJS GC

This is implemented as a Clang frontend tool, and currently does two
things:
  - Ensure for all fields wrapped in {Nonnull,}GCPtr<T>, T inherits from
    JS::Cell
  - Ensure for all fields not wrapped in {Nonnull,}GCPtr, that the type
    does not inherit from JS::Cell (otherwise it should be wrapped in a
    Ptr class).

In the future, this tool could be extended further. For example, we may
consider validating all implementations of Cell::visit_impl.
This commit is contained in:
Matthew Olsson 2023-03-03 17:15:59 -07:00 committed by Linus Groh
parent 176beeb08e
commit b33b950e45
7 changed files with 341 additions and 0 deletions

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <clang/ASTMatchers/ASTMatchers.h>
#include <clang/Tooling/Tooling.h>
#include <unordered_set>
class CollectCellsHandler
: public clang::tooling::SourceFileCallbacks
, public clang::ast_matchers::MatchFinder::MatchCallback {
public:
CollectCellsHandler();
virtual ~CollectCellsHandler() override = default;
virtual bool handleBeginSource(clang::CompilerInstance&) override;
virtual void run(clang::ast_matchers::MatchFinder::MatchResult const& result) override;
clang::ast_matchers::MatchFinder& finder() { return m_finder; }
private:
std::unordered_set<std::string> m_visited_classes;
clang::ast_matchers::MatchFinder m_finder;
};