ElementPass Class
class QQmlSA::ElementPass要素に対するすべての静的解析パスの基本クラスです。さらに...
ヘッダ | #include <ElementPass> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS QmlCompiler) target_link_libraries(mytarget PRIVATE Qt6::QmlCompiler) |
継承する: | QQmlSA::GenericPass |
ステータス | 技術プレビュー |
パブリック関数
virtual void | run(const QQmlSA::Element &element) = 0 |
virtual bool | shouldRun(const QQmlSA::Element &element) |
詳細説明
ElementPassは、2つの解析パスのうち単純な方です。ファイル内のすべての要素を考慮します。shouldRun() メソッドを使用して、無関係な要素をフィルタリングできます。また、run() メソッドが初期作業を行います。
ElementPass に適した一般的なタスクは次のとおりです。
- 要素のプロパティが無意味に組み合わされていないかチェックする。
- プロパティ値の検証(たとえば、プロパティが特定の列挙型値しか取らないなど)
- Elementの親に依存する動作のチェック(親要素が
Layout
の場合、Item::width を使用しないなど)。
以下のスニペットに示すように、ElementPassのコンストラクタで必要な型解決を行い、ローカルメンバにキャッシュすることを推奨します。また、静的解析のパフォーマンスを維持するために、shouldRun ()を介していくつかのフィルタリングを実装することを推奨します。
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 } }
ElementPassは、要素のプロパティがどのように使用されているかについての洞察は限られています。そのような情報が必要な場合は、PropertyPass 。
注意: ElementPassはインスタンス化可能な型しか考慮しません。そのため、アタッチ型やシングルトンを分析するのには適していません。それらはPropertyPass で処理する必要があります。
メンバ関数のドキュメント
[pure virtual]
void ElementPass::run(const QQmlSA::Element &element)
shouldRun()
がtrue
を返した場合に実行。element でパスの実計算を実行する。このメソッドはオーバーライドされることを意図している。ベース・メソッドを呼び出す必要はありません。
[virtual]
bool ElementPass::shouldRun(const QQmlSA::Element &element)
与えられたelement に対してrun()
関数を実行するかどうかを制御します。サブクラスは、このメソッドをオーバーライドして、関連性のない要素をフィルタリングすることで、解析のパフォーマンスを向上させることができます。
デフォルトの実装では、無条件にtrue
を返します。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.