Base class for all static analysis passes on elements. More...
| Header: | #include <ElementPass> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS QmlCompiler)target_link_libraries(mytarget PRIVATE Qt6::QmlCompiler) |
| Inherits: | QQmlSA::GenericPass |
| Status: | Technical Preview |
| ElementPass(QQmlSA::PassManager *manager) | |
| virtual void | run(const QQmlSA::Element &element) = 0 |
| virtual bool | shouldRun(const QQmlSA::Element &element) |
ElementPass is the simpler of the two analysis passes. It will consider every element in a file. The shouldRun() method can be used to filter out irrelevant elements, and the run() method is doing the initial work.
Common tasks suitable for an ElementPass are
Layout).
As shown in the snippet below, it is recommended to do necessary type resolution in the constructor of the ElementPass and cache it in local members, and to implement some filtering via shouldRun() to keep the static analysis performant.
using namespace QQmlSA; class MyElementPass : public ElementPass { Element myType; public: MyElementPass(QQmlSA::PassManager *manager) : myType(resolveType("MyModule", "MyType")) {} bool shouldRun(const Element &element) override { return element.inherits(myType); } void run(const Element &element) override { // actual pass logic } }
ElementPasses have limited insight into how an element's properties are used. If you need that information, consider using a PropertyPass instead.
Note: ElementPass will only ever consider instantiable types. Therefore, it is unsuitable to analyze attached types and singletons. Those need to be handled via a PropertyPass.
Creates an ElementPass object and uses manager to refer to the pass manager.
[pure virtual] void ElementPass::run(const QQmlSA::Element &element)Executes if shouldRun() returns true. Performs the real computation of the pass on element. This method is meant to be overridden. Calling the
base method is not necessary.
[virtual] bool ElementPass::shouldRun(const QQmlSA::Element &element)Controls whether the run() function should be executed on the given element. Subclasses can override this method to improve performance of the analysis by filtering out
elements which are not relevant.
The default implementation unconditionally returns true.
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: