function compute_autoinheritance_info
% Compute the auto inheritance information and store it in the chart
global gMachineInfo %#ok<GVMIS>
   
for i = 1:length(gMachineInfo.charts)
    chart = gMachineInfo.charts(i);
    numSpecs = length(gMachineInfo.specializations{i});
    
    aiInfos = []; % "auto_inheritance_info"
    for j = 1:numSpecs
        thisSpec = gMachineInfo.specializations{i}{j};
        thisAiInfo = generate_autoinheritance_info(chart, thisSpec);
        thisAiInfo.spec = thisSpec;
        aiKey = ['k_' thisAiInfo.checksum];
        aiInfos.(aiKey) = thisAiInfo;
    end
    
    sf('set', chart, 'chart.sfunInfo.autoInheritanceInfo', aiInfos);
end


function ai = generate_autoinheritance_info(chartId, spec)
ai.serializedDataTypes = Stateflow.internal.serializeDataTypes(chartId, false);
chartData = sf('DataIn',chartId, false);

ai.checksum = sf('SyncAutoinheritanceChecksum', chartId, spec);

ai.inputs = get_ai_for_scope(chartData, 'INPUT_DATA', chartId);
ai.parameters = get_ai_for_scope(chartData, 'PARAMETER_DATA', chartId);
ai.outputs = get_ai_for_scope(chartData, 'OUTPUT_DATA', chartId);
ai.locals = get_ai_for_scope(chartData, 'LOCAL_DATA', chartId);

[ai.postCodegenInfo.exportedFunctionsUsedByThisChart, ai.postCodegenInfo.exportedFunctionsChecksum] = sf('ExportedFunctionsInfo', chartId);
ai.hasBreakpoints = logical(sf('get', chartId, '.hadBreakpoints'));
ai.chartUsesVerifyKeyword = logical(sf('get', chartId, '.sfunInfo.chartUsesVerify'));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ai = get_ai_for_scope(dataSet, dataScope, chartId)
dataSubset =  sf('find',dataSet,'data.scope',dataScope);

ai = [];

genInfo = true;
if(strcmp(dataScope, 'LOCAL_DATA'))
    genInfo = Stateflow.MALUtils.isMalChart(chartId);
end
if(genInfo)
    for i = 1:length(dataSubset)
        data = dataSubset(i);
        dataParsedInfo = sf('DataParsedInfo', data);
        ai(i).size = dataParsedInfo.size; %#ok<AGROW>
        ai(i).type.base = dataParsedInfo.type.base; %#ok<AGROW>
        ai(i).type.fixpt = dataParsedInfo.type.fixpt; %#ok<AGROW>
        ai(i).type.isFixedPointType = dataParsedInfo.type.isFixedPointType; %#ok<AGROW>
        ai(i).type.stringProps = dataParsedInfo.type.stringProps; %#ok<AGROW>
        ai(i).complexity = dataParsedInfo.complexity; %#ok<AGROW>
    end
end
