Skip to content
generate_preamble.m 2.95 KiB
Newer Older
%% generate_preamble
        %    generates the preamble for the eml code, the preamble is
        %    everything before the first if statement, this is seperated
        %    out to make the code simpler. 
        % inputs:
        %   object:EMLGenerator - current object
        % outputs:
        %   code:string - string of eml code
        function code = generate_preamble(object)
                function_name = EMLGenerator.parse_inputs(object.data.function_name);
                %generate input list
                parsed_input = EMLGenerator.parse_inputs(object.data.function_inputs);
                input = [];
                for i= 1:size(parsed_input,2)
                    input = [input char(parsed_input{i}(1))];
                    if i ~= size(parsed_input,2)
                        input = [input ',']
                    end
                end
Colin Eles's avatar
Colin Eles committed
                if (object.data.multi_mode == 1)
                    for i=1:size(object.data.Grid1.cells,2)
                         parsed_output = EMLGenerator.parse_inputs(strtrim(char(object.data.Grid1.cells(i).cond_text)));

                            output = [output char(parsed_output{1}(1))];
                           
                        if i ~= size(object.data.Grid1.cells,2)
                        output = [output ',']
                    end
                    end
                else
                    output = 'output';
                end
                
                code = sprintf('function [%s] = %s(%s)\n%s\n',output,char(function_name{1}(1)),input,'%%#eml');
                % simulink forces you to have an output for all execution paths
                % since it can't compute completness and disjointness we need
                % to have a default value, if the user builds the table
                % properly the default value will never be used. since
                % different types might have a different default value, the
                % temporary solution is just to use one of the outputs from our
                % table, we will use the first cell because it is
                % guaranteed to
                % be filled in, regardless of the dimensionality of the table.
Colin Eles's avatar
Colin Eles committed
                if (object.data.multi_mode == 1)
                    for i=1:size(object.data.Grid1.cells,2)
                         parsed_output = EMLGenerator.parse_inputs(strtrim(char(object.data.Grid1.cells(i).cond_text)));

                            output_str = char(parsed_output{1}(1));
                           
                            code = [code sprintf('%s=%s;\n',output_str,char(object.data.Grid0.Cells(i).result_text))];

                    end
                    
                else
                      code = [code sprintf('output=%s;\n',EMLGenerator.type_convert(object.datatype,char(object.data.Grid0.Cells(1).result_text)))];

                end