Main Content

Command/script to apply to preprocessed files (-post-preprocessing-command)

Specify command or script to run on source files after preprocessing phase of analysis

Description

Specify a command or script to run on each source file after preprocessing.

Set Option

User interface (desktop products only): In your project configuration, the option is on the Environment Settings node.

User interface (Polyspace Platform, desktop products only): In your project configuration, the option is on the Build tab on the Environment Settings node.

Command line and options file: Use the option -post-preprocessing-command. See Command-Line Information.

Why Use This Option

You can run scripts on preprocessed files to work around compilation errors or imprecisions of the analysis while keeping your original source files untouched. For instance, suppose Polyspace® does not recognize a compiler-specific keyword. If you are certain that the keyword is not relevant for the analysis, you can run a Perl script to remove all instances of the keyword. When you use this option, the software removes the keyword from your preprocessed code but keeps your original code untouched.

Use a script only if the existing analysis options do not meet your requirements. For instance:

  • For direct replacement of one keyword with another, use the option Preprocessor definitions (-D).

    However, the option does not allow search and replacement involving regular expressions. For regular expressions, use a script.

  • For mapping your library function to a standard library function, use the option -code-behavior-specifications.

    However, the option supports mapping to only a subset of standard library functions. To map to an unsupported function, use a script.

If you are unsure about removing or replacing an unsupported construct, do not use this option. Contact MathWorks® Support for guidance.

Settings

No Default

Enter full path to the command or script or click to navigate to the location of the command or script. This script is executed before verification.

Tips

  • Your script must be designed to process the standard output from preprocessing and produce its results in accordance with that standard output.

  • Your script must preserve the number of lines in the preprocessed file. In other words, it must not add or remove entire lines to or from the file.

    Adding a line or removing one can potentially result in some unpredictable behavior on the location of checks and macros in the Polyspace user interface.

  • For a Perl script, in Windows®, specify the full path to the Perl executable followed by the full path to the script.

    For example:

    • To specify a Perl command that replaces all instances of the far keyword, enter polyspaceroot\sys\perl\win32\bin\perl.exe -p -e "s/far//g".

    • To specify a Perl script replace_keyword.pl that replaces all instances of a keyword, enter polyspaceroot\sys\perl\win32\bin\perl.exe absolute_path\replace_keyword.pl.

    Here, polyspaceroot is the location of the current Polyspace installation such as C:\Program Files\Polyspace\R2019a\ and absolute_path is the location of the Perl script. If the paths contain spaces, use quotes to enclose the full path names.

  • Use this Perl script as template. The script removes all instances of the far keyword.

    #!/usr/bin/perl
    
    binmode STDOUT;
    
    # Process every line from STDIN until EOF
    while ($line = <STDIN>) 
    {
      if ($line =~ /^#/) { # lines starting with # should not be modified
        print $line;
        next;
      }
      
      # Remove far keyword
      $line =~ s/far//g;
      
      # Print the current processed line to STDOUT
      print $line;
    }

    You can use Perl regular expressions to perform substitutions. For instance, you can use the following expressions.

    ExpressionMeaning
    .Matches any single character except newline
    [a-z0-9]         Matches any single letter in the set a-z, or digit in the set 0-9
    [^a-e]Matches any single letter not in the set a-e
    \dMatches any single digit
    \wMatches any single alphanumeric character or _
    x?Matches 0 or 1 occurrence of x
    x*Matches 0 or more occurrences of x
    x+Matches 1 or more occurrences of x

    For complete list of regular expressions, see Perl documentation.

  • The script you specify using this command runs on the source files after the preprocessing phase of the analysis. The coding rule violations or Bug Finder defects that are reported during the preprocessing phase are not affected by this script.

  • If you want to replace a preprocessor directive before the preprocessing phase of the analysis, use the option -regex-replace-rgx -regex-replace-fmt.

Command-Line Information

Parameter: -post-preprocessing-command
Value: Path to executable file or script in quotes
No Default
Example in Linux® (Bug Finder): polyspace-bug-finder -sources file_name -post-preprocessing-command `pwd`/replace_keyword.pl
Example in Linux (Code Prover): polyspace-code-prover -sources file_name -post-preprocessing-command `pwd`/replace_keyword.pl
Example in Linux (Bug Finder Server): polyspace-bug-finder-server -sources file_name -post-preprocessing-command `pwd`/replace_keyword.pl
Example in Linux (Code Prover Server): polyspace-code-prover-server -sources file_name -post-preprocessing-command `pwd`/replace_keyword.pl
Example in Windows: polyspace-bug-finder -sources file_name -post-preprocessing-command "C:\Program Files\MATLAB\R2015b\sys\perl\win32\bin\perl.exe" "C:\My_Scripts\replace_keyword.pl"

You can specify an absolute path to a file or a path relative to the location from which you run the polyspace-bug-finder or polyspace-code-prover command. Note that if you are running Perl scripts, in Windows, enter the full path to the Perl executable.