Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/DeclStats.cc

    rf923b5f r424931d  
    1818#include <iostream>
    1919#include <map>
    20 #include <sstream>
    2120#include <string>
    2221#include <unordered_map>
     
    7271                                return *this;
    7372                        }
     73
     74                        /// Update based on a declaration list
     75                        ArgPackStats& operator+= ( std::list<DeclarationWithType*>& decls ) {
     76                                unsigned nn = 0;
     77                                unsigned nn_basic = 0;
     78                                unsigned nn_poly = 0;
     79                                for ( auto decl : decls ) {
     80                                        nn += decl->get_type()->size();
     81                                        if ( dynamic_cast<BasicType*>( decl->get_type() ) ) ++nn_basic;
     82                                        else if ( GenPoly::hasPolyBase( decl->get_type() ) ) ++nn_poly;
     83                                }
     84                                ++n.at( nn );
     85                                ++n_basic.at( nn_basic );
     86                                ++n_poly.at( nn_poly );
     87                                if ( nn > 0 ) {
     88                                        ++p_basic[ nn_basic*100/nn ];
     89                                        ++p_poly[ nn_poly*100/nn ];
     90                                }
     91                               
     92                                return *this;
     93                        }
    7494                };
    7595               
     
    80100                        /// Count of declarations with each name
    81101                        std::unordered_map<std::string, unsigned> by_name;
    82                         /// Count of uses of each basic type
    83                         std::unordered_map<std::string, unsigned> basic_type_names;
    84                         /// Count of uses of each non-basic type
    85                         std::unordered_map<std::string, unsigned> compound_type_names;
    86102                        /// Stats for the parameter list
    87103                        ArgPackStats params;
     
    96112                        ArgPackStats assn_returns;
    97113                       
    98                         Stats() : n_decls(0), n_type_params(), by_name(), basic_type_names(), compound_type_names(), params(), returns(), n_assns(), assn_params(), assn_returns() {}
     114                        Stats() : n_decls(0), n_type_params(), by_name(), params(), returns(), n_assns(), assn_params(), assn_returns() {}
    99115
    100116                public:
     
    103119                                sum( n_type_params, o.n_type_params );
    104120                                sum( by_name, o.by_name );
    105                                 sum( basic_type_names, o.basic_type_names );
    106                                 sum( compound_type_names, o.compound_type_names );
    107121                                sum( params, o.params );
    108122                                sum( returns, o.returns );
     
    119133                Stats total;
    120134
    121                 /// Update arg pack stats based on a declaration list
    122                 void analyze( Stats& stats, ArgPackStats& pstats, std::list<DeclarationWithType*>& decls ) {
    123                         unsigned n = 0;
    124                         unsigned n_basic = 0;
    125                         unsigned n_poly = 0;
    126                         for ( auto decl : decls ) {
    127                                 n += decl->get_type()->size();
    128                                 if ( BasicType* bt = dynamic_cast<BasicType*>( decl->get_type() ) ) {
    129                                         ++n_basic;
    130                                         std::stringstream ss;
    131                                         bt->print( ss );
    132                                         ++stats.basic_type_names[ ss.str() ];
    133                                 } else if ( GenPoly::hasPolyBase( decl->get_type() ) ) {
    134                                         ++n_poly;
    135                                 } else {
    136                                         std::stringstream ss;
    137                                         decl->get_type()->print( ss );
    138                                         ++stats.compound_type_names[ ss.str() ];
    139                                 }
    140                         }
    141                         ++pstats.n.at( n );
    142                         ++pstats.n_basic.at( n_basic );
    143                         ++pstats.n_poly.at( n_poly );
    144                         if ( n > 0 ) {
    145                                 ++pstats.p_basic[ n_basic*100/n ];
    146                                 ++pstats.p_poly[ n_poly*100/n ];
    147                         }
    148                 }
    149                
    150                 void analyzeFunc( FunctionType* fnTy, Stats& stats, ArgPackStats& params, ArgPackStats& returns ) {
    151                         analyze( stats, params, fnTy->get_parameters() );
    152                         analyze( stats, returns, fnTy->get_returnVals() );
     135                void analyzeFunc( FunctionType* fnTy, ArgPackStats& params, ArgPackStats& returns ) {
     136                        params += fnTy->get_parameters();
     137                        returns += fnTy->get_returnVals();
    153138                }
    154139
     
    179164                                                assnTy = assnDecl->get_functionType();
    180165                                        }
    181                                         if ( assnTy ) analyzeFunc( assnTy, stats, stats.assn_params, stats.assn_returns );
     166                                        if ( assnTy ) analyzeFunc( assnTy, stats.assn_params, stats.assn_returns );
    182167                                }
    183168                        }
     
    186171                        ++stats.by_name[ decl->get_name() ];
    187172
    188                         analyzeFunc( fnTy, stats, stats.params, stats.returns );
     173                        analyzeFunc( fnTy, stats.params, stats.returns );
    189174                }
    190175
     
    281266                        printAll("unique_names", [](const Stats& stats) { return stats.by_name.size(); });
    282267                        printAllSparseHisto("overloads", [](const Stats& stats) { return stats.by_name; });
    283                         printAll("basic_type_names", [](const Stats& stats) { return stats.basic_type_names.size(); });
    284                         printAll("compound_type_names", [](const Stats& stats) { return stats.compound_type_names.size(); });
    285268                        printAllPack("params", [](const Stats& stats) { return stats.params; });
    286269                        printAllPack("returns", [](const Stats& stats) { return stats.returns; });
Note: See TracChangeset for help on using the changeset viewer.