Main Content

getFunctions

Class: Simulink.CodeImporter.ParseInfo
Namespace: Simulink.CodeImporter

Obtain detailed information regarding functions in custom code

Since R2021a

Syntax

fcnobjs = getFunctions(obj.ParseInfo)

Description

fcnobjs = getFunctions(obj.ParseInfo), where obj is an object of class Simulink.CodeImporter or sltest.CodeImporter, returns an array of objects of class Simulink.CodeImporter.Function with detailed information on all Simulink® compatible functions in the custom code.

Note

If your code has a function with a pointer output, specify the size of the output by setting the port specification in the returned function object.

Input Arguments

expand all

Parse information, specified as a handle to a Simulink.CodeImporter.ParseInfo object.

Names of functions in custom code about which to obtain information, specified as a cell array of character vectors or a string array. fcnlist must be limited to names contained in obj.ParseInfo.AvailableFunctions, that is, functions compatible with Simulink in the specified custom code.

Data Types: cell array of character vectors | string array

Output Arguments

expand all

Information about functions in custom code, returned as an array of Simulink.CodeImporter.Function objects, where each object corresponds to one function. Each object includes the function name, C prototype, port specification, whether function is an entry-point function, and whether function is defined in the custom code. See Simulink.CodeImporter.Function.

Examples

expand all

Specify and parse custom code, then query information regarding custom code functions.

obj = Simulink.CodeImporter;

%% Set library file name and output folder
obj.LibraryFileName = "pumpController";
obj.OutputFolder = ".";

%% 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 code
parse(obj);
parseobj = obj.ParseInfo
ans = 

  ParseInfo with properties:

               Success: 1
    AvailableFunctions: ["Controller"    "setFanTempThreshold"    "setPumpTempThreshold"]
        EntryFunctions: ["Controller"    "setFanTempThreshold"    "setPumpTempThreshold"]
        AvailableTypes: "pump_control_bus"
                Errors: []
fcnobjs = getFunctions(parseobj)
fcnobjs = 

  1×3 Function array with properties:

    Name
    CPrototype
    PortSpecification
    IsEntry
    IsDefined
    IsStub
    ArrayLayout
    IsDeterministic
>> fcnobjs(1)
ans = 

  Function with properties:

                 Name: "Controller"
           CPrototype: "pump_control_bus Controller(real_T Tset, real_T Troom_in);"
    PortSpecification: [1×1 Simulink.CodeImporter.SimulinkPortSpecification]
              IsEntry: 1
            IsDefined: 1
               IsStub: 0
          ArrayLayout: NotSpecified
      IsDeterministic: 0

Version History

Introduced in R2021a