주요 콘텐츠

Cpp.Macro Class

Namespace: Cpp

Represents the macros in your code

Since R2026a

Description

Macro class represents the macros in your code. Use the predicates in this class to query various macro related aspects of your code. This class is not raisable. That is, you cannot report a defect on a Macro object.

Predicates

expand all

Examples

collapse all

  1. In a new folder Macro, initialize a new coding standard. At the command line, enter:

    polyspace-query-language init

  2. In the file main.pql, enter this content:

    package main
    
    // Main PQL file defines the catalog of your PQL project.
    // The catalog is a collection of sections.
    catalog MacroExample = {
        #[Description("Example Section")]
        section ExampleSection = {
            #[Description("Macro definition repreated in multiple header files"),Id(myRule)]
            rule ExampleRule = {
                defect Exampledefect =
                when Cpp.Macro.is(&Macro1)
                and Cpp.Macro.is(&Macro2)
                and Macro1 != Macro2
                and Macro1.name(&name1)
                and Macro2.name(&name2)
                and name1 == name2
                and Macro1.locPath(&file1)
                and Macro2.locPath(&file2)
                and file1 != file2
                and Macro1.extension(&ext1)
                and Macro2.extension(&ext2)
                and ext1 == ".h"
                and ext2 == ".h"
    			and Macro1.sourceLocation(&fileRaise, &_line, &_column)
                raise "Macro \"{name1}\" is defined in multiple header files"
                on fileRaise
            }
        }
    }
    

  3. Create the coding standard Macro.pschk using this command at the command line:

    polyspace-query-language package

  4. Using the generated coding standard, run a Bug Finder analysis on your source file. Foe example, at the command line, enter:

    polyspace-bug-finder -sources foo.h,bar,h -lang cpp -checkers-activation-file Macro.pschk
    The analysis reports defects on the definitions of BUFFER_SIZE.

Version History

Introduced in R2026a