function	compute_chart_information(chart)

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

	global gTargetInfo gChartInfo gMachineInfo %#ok<GVMIS>

    if sfprivate('is_eml_chart', chart)
        gChartInfo.codingExtMode = false;
    else
        gChartInfo.codingExtMode = gTargetInfo.codingExtMode;
    end
    
    % 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
    chartH = sf('IdToHandle', chart);
    if gTargetInfo.codingRTW && isprop(chartH, 'ExportChartFunctions') && chartH.ExportChartFunctions
        functions = sf('FunctionsIn',chart);
        exportedFunctions = sf('find',functions,'state.treeNode.parent',chart);
        if ~isempty(exportedFunctions)
          if gTargetInfo.mdlrefInfo.isMultiInst
              str = sprintf(gTargetInfo.mdlrefInfo.err);
              construct_coder_error(gMachineInfo.machineId,str,1);
          end
          if(gTargetInfo.isErtMultiInstanced)
              assert(~strcmp(gTargetInfo.rtwProps.systemTargetFile,'grt_malloc.tlc'));
              str = getString(message('Stateflow:cdr:GenerateReusableCodeWithExportedFunction'));
              if(strcmp(gTargetInfo.ertMultiInstanceErrCode,'Error'))
                  construct_coder_error(chart,str,1);
              elseif(strcmp(gTargetInfo.ertMultiInstanceErrCode,'Warning'))
                  warning(str);
              end
          end
        end
    end

    chartParentedData = sf('DataOf',chart);
    gChartInfo.chartInputData = sf('find',chartParentedData,'data.scope','INPUT_DATA');
    gChartInfo.chartParameterData = sf('find',chartParentedData,'data.scope','PARAMETER_DATA');
    gChartInfo.chartOutputData = sf('find',chartParentedData,'data.scope','OUTPUT_DATA');
    gChartInfo.chartEvents = sf('EventsIn',chart, false);
    gChartInfo.chartLocalEvents = sf('find',gChartInfo.chartEvents,'event.scope','LOCAL_EVENT');
    gChartInfo.chartInputEvents = sf('find',gChartInfo.chartEvents,'event.scope','INPUT_EVENT');
    chartFcnCallOutputEvents = sf('find',gChartInfo.chartEvents,'event.trigger','FUNCTION_CALL_EVENT','event.scope','OUTPUT_EVENT');
    sf('set', chartFcnCallOutputEvents,'event.functionCallIndex',(0:(length(chartFcnCallOutputEvents)-1))');

    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) && ~sf('IsPlantModelChartPostCompile', 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;
    else
       gChartInfo.executeAtInitialization = 0;
   end
