www.gusucode.com > private工具箱matlab源码程序 > private/compute_chart_information.m

    function	compute_chart_information(chart)

%   Copyright 1995-2012 The MathWorks, Inc.
%   Compute instance independent chart information.

	global gTargetInfo gChartInfo gMachineInfo

	sortAllStatesByName = 1; % this will override the geometrical sort
                            % for AND states => required for G84273
    if ~sf('Cg','chart_allows_debugging',chart)
        gChartInfo.codingDebug = 0;
    else
        gChartInfo.codingDebug = gTargetInfo.codingDebug;
    end

    if sfprivate('is_eml_chart', chart)
        gChartInfo.codingExtMode = false;
    else
        gChartInfo.codingExtMode = gTargetInfo.codingExtMode;
    end

	gChartInfo.states = sf('SubstatesIn',chart,sortAllStatesByName);% passing 1 to get a lexicographic
	gChartInfo.functions = sf('FunctionsIn',chart);
    
    % g1265152: This is a temporary fix for 15b. Previously, we were
    % setting gChartInfo.simulinkFunctions to the set of uncommented
    % simulink functions, however, since commented simulink functions are
    % still connected to the demux block under the stateflow mask, we do
    % need the list of *all* simulink functions, commented or otherwise.
    gChartInfo.simulinkFunctions = sf('SimulinkFunctionsIn',chart,true);

	gChartInfo.chartTransitions = sfprivate('chart_real_transitions',chart);

	if(export_chart_functions(chart))
		gChartInfo.functionsToBeExported = sf('find',gChartInfo.functions,'state.treeNode.parent',chart);
	else
		gChartInfo.functionsToBeExported = [];
	end
	gChartInfo.functionsNotToBeExported = sfprivate('vset',gChartInfo.functions,'-',gChartInfo.functionsToBeExported);

	gChartInfo.chartData = sf('DataIn',chart, false);
	gChartInfo.chartDataNumbers = sf('get',gChartInfo.chartData,'data.number')';

	chartTemporaryData = sf('find',sf('DataOf', chart),'data.scope','TEMPORARY_DATA');

    % XXX (savadhan): Once we begin supporting reusable code with scoped
    % Simulink functions and public/global etc. this bit of code will have
    % to be revisited.
    % sf('feature', 'ScopedSimulinkFunctions')
    % G269739, G142162: throw proper errors
    if(gTargetInfo.codingRTW && ~isempty(gChartInfo.functionsToBeExported))
        
        if gTargetInfo.mdlrefInfo.isMultiInst
            str = sprintf(gTargetInfo.mdlrefInfo.err);
            construct_coder_error(gMachineInfo.machineId,str,1);
        end
        if(gTargetInfo.isErtMultiInstanced)
            if(strcmp(gTargetInfo.rtwProps.systemTargetFile,'grt_malloc.tlc'))
                str = sprintf('GRT Malloc Code-format cannot be used in the presence of exported graphical functions.');
                construct_coder_error(chart,str,1);
            else
                str = sprintf('ERT option "Generate reusable code" cannot be used in the presence of exported graphical functions.');
                if(strcmp(gTargetInfo.ertMultiInstanceErrCode,'Error'))
                    construct_coder_error(chart,str,1);
                elseif(strcmp(gTargetInfo.ertMultiInstanceErrCode,'Warning'))
                    warning(str); %#ok
                end
            end
        end
    end

	% WISH fix this later. for now we consider temporary data same as local data

	if(sf('HasAtleastOneSubstate',chart))
		% has substates. cannot have temporary data
		gChartInfo.chartLocalData = [chartTemporaryData,sf('find',gChartInfo.chartData,'data.scope','LOCAL_DATA')];
		gChartInfo.chartLocalDataNumbers = sf('get',gChartInfo.chartLocalData,'data.number')';
	else
		% stateless chart. can have temporary data
		gChartInfo.chartLocalData = sf('find',gChartInfo.chartData,'data.scope','LOCAL_DATA');
		gChartInfo.chartLocalDataNumbers = sf('get',gChartInfo.chartLocalData,'data.number')';
	end

	gChartInfo.chartConstantData = sf('find',gChartInfo.chartData,'data.scope','CONSTANT_DATA');
	gChartInfo.chartConstantDataNumbers = sf('get',gChartInfo.chartConstantData,'data.number')';

	chartParentedData = sf('DataOf',chart);

	gChartInfo.chartInputData = sf('find',chartParentedData,'data.scope','INPUT_DATA');
	gChartInfo.chartInputDataNumbers = sf('get',gChartInfo.chartInputData,'data.number')';

	gChartInfo.chartParameterData = sf('find',chartParentedData,'data.scope','PARAMETER_DATA');
	gChartInfo.chartParameterDataNumbers = sf('get',gChartInfo.chartParameterData,'data.number')';

	gChartInfo.chartOutputData = sf('find',chartParentedData,'data.scope','OUTPUT_DATA');
	gChartInfo.chartOutputDataNumbers = sf('get',gChartInfo.chartOutputData,'data.number')';

    gChartInfo.chartEvents = sf('EventsIn',chart, false);
    gChartInfo.chartLocalEvents = sf('find',gChartInfo.chartEvents,'event.scope','LOCAL_EVENT');
    gChartInfo.chartOutputEvents = sf('find',gChartInfo.chartEvents,'event.scope','OUTPUT_EVENT');
    gChartInfo.chartInputEvents = sf('find',gChartInfo.chartEvents,'event.scope','INPUT_EVENT');
    gChartInfo.chartFcnCallOutputEvents = sf('find',gChartInfo.chartOutputEvents,'event.trigger','FUNCTION_CALL_EVENT');
    sf('set',gChartInfo.chartFcnCallOutputEvents,'event.functionCallIndex',(0:(length(gChartInfo.chartFcnCallOutputEvents)-1))');

    gChartInfo.chartNumSLFcnOutputs = 0;
    gChartInfo.chartNumSLFcnInputs = 0;
    for i=1:length(gChartInfo.simulinkFunctions)
        fcnData = sf('DataOf', gChartInfo.simulinkFunctions(i));
        gChartInfo.chartNumSLFcnInputs = gChartInfo.chartNumSLFcnInputs + length(sf('find', fcnData, 'data.scope', 'FUNCTION_INPUT_DATA'));
        gChartInfo.chartNumSLFcnOutputs = gChartInfo.chartNumSLFcnOutputs + length(sf('find', fcnData, 'data.scope', 'FUNCTION_OUTPUT_DATA'));
    end

	gChartInfo.chartHasContinuousTime = 0;
	if gTargetInfo.codingSFunction
		gChartInfo.chartHasContinuousTime = sf('Cg','get_chart_has_continuous_time',chart);
	elseif gTargetInfo.codingRTW
           if(sf('get',chart,'chart.updateMethod')==2) && ~sfprivate('is_plant_model_chart', chart)
              hyperLink = sf('GetHyperLinkedNameForObjects', chart);
              msg = message('Stateflow:misc:ContinuousUpdateForSimulinkCoder', hyperLink);
              error(msg);
           end
	end

    if(gTargetInfo.codingSFunction)
        gTargetInfo.codingMultiInstance = sf('ChartIsMultiInstantiable', chart);
    end
    
	if gTargetInfo.codingRTW
		gChartInfo.chartInstanceVarName = '%<LibSFChartInstance(block)>';
	else
		if(gTargetInfo.codingMultiInstance)
			gChartInfo.chartInstanceVarName = 'chartInstance->';
		else
			gChartInfo.chartInstanceVarName = 'chartInstance.';
		end
	end   
   
   if sfprivate('is_sf_chart', chart)
       hChart = idToHandle(sfroot, chart);
       % The UDD interface shows the semantic "execute at initialization"
       % value accounting for things such as the actual raw "execute at
       % initialization" being unset but the chart being a Moore chart.
       gChartInfo.executeAtInitialization = hChart.ExecuteAtInitialization;
       gChartInfo.initializeOutput = hChart.InitializeOutput;
   else
       gChartInfo.executeAtInitialization = 0;
       gChartInfo.initializeOutput = 0;
   end