Changeset e5c74d1
 Timestamp:
 Jan 22, 2018, 2:27:24 PM (4 years ago)
 Branches:
 aaronthesis, armeh, cleanupdtors, deferred_resn, demangler, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, resolvnew, with_gc
 Children:
 b04a408
 Parents:
 13deae88
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/CodeTools/DeclStats.cc
r13deae88 re5c74d1 23 23 #include <utility> // for pair, make_pair 24 24 25 #include "Common/PassVisitor.h" 25 26 #include "Common/SemanticError.h" // for SemanticError 26 27 #include "Common/VectorMap.h" // for VectorMap … … 35 36 namespace CodeTools { 36 37 37 class DeclStats : public Visitor{38 struct DeclStats : public WithShortCircuiting { 38 39 template<typename T> 39 40 static void sum(T& a, const T& b) { a += b; } … … 200 201 201 202 public: 202 using Visitor::visit; 203 204 virtual void visit( FunctionDecl *decl ) { 203 void previsit( FunctionDecl *decl ) { 205 204 // skip if already seen declaration for this function 206 const std::string& mangleName = decl>get_mangleName().empty() ? decl>get_name() : decl>get_mangleName(); 207 if ( ! seen_names.insert( mangleName ).second ) { 208 maybeAccept( decl>get_statements(), *this ); 209 return; 210 } 211 212 Stats& stats = for_linkage[ decl>get_linkage() ]; 213 214 ++stats.n_decls; 215 FunctionType* fnTy = decl>get_functionType(); 216 const Type::ForallList& forall = fnTy>get_forall(); 217 ++stats.n_type_params.at( forall.size() ); 218 unsigned n_assns = 0; 219 for ( TypeDecl* fdecl : forall ) { 220 n_assns += fdecl>get_assertions().size(); 221 for ( DeclarationWithType* assn : fdecl>get_assertions() ) { 222 FunctionType *assnTy = 0; 223 if ( ObjectDecl *assnObj = dynamic_cast<ObjectDecl*>(assn) ) { 224 if ( PointerType *ptrTy = dynamic_cast<PointerType*>(assnObj>get_type()) ) { 225 assnTy = dynamic_cast<FunctionType*>(ptrTy>get_base()); 226 } else assnTy = dynamic_cast<FunctionType*>(assnObj>get_type()); 227 } else if ( FunctionDecl *assnDecl = dynamic_cast<FunctionDecl*>(assn) ) { 228 assnTy = assnDecl>get_functionType(); 205 const std::string& mangleName = decl>get_mangleName().empty() ? decl>name : decl>get_mangleName(); 206 if ( seen_names.insert( mangleName ).second ) { 207 Stats& stats = for_linkage[ decl>linkage ]; 208 209 ++stats.n_decls; 210 FunctionType* fnTy = decl>type; 211 const Type::ForallList& forall = fnTy>forall; 212 ++stats.n_type_params.at( forall.size() ); 213 unsigned n_assns = 0; 214 for ( TypeDecl* fdecl : forall ) { 215 n_assns += fdecl>assertions.size(); 216 for ( DeclarationWithType* assn : fdecl>assertions ) { 217 FunctionType *assnTy = nullptr; 218 if ( ObjectDecl *assnObj = dynamic_cast<ObjectDecl*>(assn) ) { 219 if ( PointerType *ptrTy = dynamic_cast<PointerType*>(assnObj>get_type()) ) { 220 assnTy = dynamic_cast<FunctionType*>(ptrTy>get_base()); 221 } else assnTy = dynamic_cast<FunctionType*>(assnObj>get_type()); 222 } else if ( FunctionDecl *assnDecl = dynamic_cast<FunctionDecl*>(assn) ) { 223 assnTy = assnDecl>type; 224 } 225 if ( assnTy ) analyzeFunc( assnTy, stats, stats.assn_params, stats.assn_returns ); 229 226 } 230 if ( assnTy ) analyzeFunc( assnTy, stats, stats.assn_params, stats.assn_returns ); 231 } 232 } 233 ++stats.n_assns[ n_assns ]; 234 235 ++stats.by_name[ decl>get_name() ]; 236 237 analyzeFunc( fnTy, stats, stats.params, stats.returns ); 238 239 // analyze expressions in decl statements 240 maybeAccept( decl>get_statements(), *this ); 241 } 242 243 virtual void visit( UntypedExpr *expr ) { 227 } 228 ++stats.n_assns[ n_assns ]; 229 230 ++stats.by_name[ decl>get_name() ]; 231 232 analyzeFunc( fnTy, stats, stats.params, stats.returns ); 233 } 234 } 235 236 void previsit( UntypedExpr *expr ) { 237 visit_children = false; 244 238 analyzeExpr( expr, 0 ); 245 239 } … … 366 360 367 361 void printDeclStats( std::list< Declaration * > &translationUnit ) { 368 DeclStatsstats;362 PassVisitor<DeclStats> stats; 369 363 acceptAll( translationUnit, stats ); 370 stats.p rint();364 stats.pass.print(); 371 365 } 372 366
Note: See TracChangeset
for help on using the changeset viewer.