Main Content

parse

Analyze custom code for functions, types, global variables, and their dependencies

    Description

    example

    success = obj.parse(), where obj is an object of Simulink.CodeImporter or sltest.CodeImporter class, parses the custom code, but does not re-parse the custom code if the custom code has been parsed previously and neither the custom code nor the settings of obj.CustomCode have changed since the previous parse. Results of a successful parse or error information from an unsuccessful parse are stored in the ParseInfo property of obj.

    success = obj.parse('Force','On') parses the custom code irrespective or whether any changes have been made since a previous parse.

    success = obj.parse('Force','Off') has the same effect as success = obj.parse().

    Examples

    collapse all

    %% Create code importer object
    obj = Simulink.CodeImporter;
    
    %% Set the custom code to import
    obj.CustomCode.InterfaceHeaders = ["pumpController.h"];
    obj.CustomCode.IncludePaths = ["./include"];
    obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"];
    
    %% Parse custom code
    s = obj.parse;
    obj.ParseInfo
    
    ans = 
    
      ParseInfo with properties:
    
                   Success: 1
        AvailableFunctions: ["Controller"    "setFanTempThreshold"    "setPumpTempThreshold"]
            EntryFunctions: ["Controller"    "setFanTempThreshold"    "setPumpTempThreshold"]
            AvailableTypes: "pump_control_bus"
                    Errors: []
    

    Output Arguments

    collapse all

    Indicator of whether parsing is successful, returned as a logical scalar. Simulink® throws an exception if parsing is unsuccessful.

    Introduced in R2021a