ElementPass Class

class QQmlSA::ElementPass

요소에 대한 모든 정적 분석 패스를 위한 기본 클래스입니다. 더 보기...

Header: #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는 두 가지 분석 패스 중 더 간단한 패스입니다. 파일에 있는 모든 요소를 고려합니다. shouldRun () 메서드는 관련 없는 요소를 필터링하는 데 사용할 수 있으며, run() 메서드는 초기 작업을 수행합니다.

ElementPass에 적합한 일반적인 작업은 다음과 같습니다.

  • 엘리먼트의 프로퍼티가 무의미한 방식으로 결합되지 않았는지 확인
  • 프로퍼티 값의 유효성 검사(예: 프로퍼티가 특정 열거형 값만 취하는 경우)
  • 엘리먼트의 부모에 따라 달라지는 동작 확인(예: 부모 엘리먼트가 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
        }
}

엘리먼트 패스는 엘리먼트의 프로퍼티가 어떻게 사용되는지에 대한 인사이트가 제한적입니다. 해당 정보가 필요한 경우 대신 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.