Changeset 24d6572 for src/AST/Print.cpp
- Timestamp:
- Jun 12, 2023, 2:45:32 PM (2 years ago)
- Branches:
- ast-experimental, master
- Children:
- 62d62db
- Parents:
- 34b4268 (diff), 251ce80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Print.cpp
r34b4268 r24d6572 16 16 #include "Print.hpp" 17 17 18 #include "Attribute.hpp" 18 19 #include "Decl.hpp" 19 20 #include "Expr.hpp" 21 #include "Init.hpp" 20 22 #include "Stmt.hpp" 21 23 #include "Type.hpp" 22 24 #include "TypeSubstitution.hpp" 23 25 #include "CompilationState.h" 24 25 #include "Common/utility.h" // for group_iterate 26 #include "Common/Iterate.hpp" 26 27 27 28 using namespace std; … … 29 30 namespace ast { 30 31 31 template <typename C, typename... T> 32 constexpr array<C,sizeof...(T)> make_array(T&&... values) 33 { 34 return array<C,sizeof...(T)>{ 35 std::forward<T>(values)... 36 }; 32 namespace { 33 34 template<typename C, typename... T> 35 constexpr array<C, sizeof...(T)> make_array( T&&... values ) { 36 return array<C, sizeof...(T)>{ std::forward<T>( values )... }; 37 } 38 39 namespace Names { 40 static constexpr auto FuncSpecifiers = make_array<const char*>( 41 "inline", "_Noreturn", "fortran" 42 ); 43 44 static constexpr auto StorageClasses = make_array<const char*>( 45 "extern", "static", "auto", "register", "__thread", "_Thread_local" 46 ); 47 48 static constexpr auto Qualifiers = make_array<const char*>( 49 "const", "restrict", "volatile", "mutex", "_Atomic" 50 ); 51 } 52 53 template<typename bits_t, size_t N> 54 void print( ostream & os, const bits_t & bits, 55 const array<const char *, N> & names ) { 56 if ( !bits.any() ) return; 57 for ( size_t i = 0 ; i < N ; i += 1 ) { 58 if ( bits[i] ) { 59 os << names[i] << ' '; 60 } 61 } 37 62 } 38 63 … … 80 105 static const char* Names[]; 81 106 82 struct Names {83 static constexpr auto FuncSpecifiers = make_array<const char*>(84 "inline", "_Noreturn", "fortran"85 );86 87 static constexpr auto StorageClasses = make_array<const char*>(88 "extern", "static", "auto", "register", "__thread", "_Thread_local"89 );90 91 static constexpr auto Qualifiers = make_array<const char*>(92 "const", "restrict", "volatile", "mutex", "_Atomic"93 );94 };95 96 template<typename storage_t, size_t N>97 void print(const storage_t & storage, const array<const char *, N> & Names ) {98 if ( storage.any() ) {99 for ( size_t i = 0; i < Names.size(); i += 1 ) {100 if ( storage[i] ) {101 os << Names[i] << ' ';102 }103 }104 }105 }106 107 void print( const ast::Function::Specs & specs ) {108 print(specs, Names::FuncSpecifiers);109 }110 111 void print( const ast::Storage::Classes & storage ) {112 print(storage, Names::StorageClasses);113 }114 115 void print( const ast::CV::Qualifiers & qualifiers ) {116 print(qualifiers, Names::Qualifiers);117 }118 119 107 void print( const std::vector<ast::Label> & labels ) { 120 108 if ( labels.empty() ) return; … … 221 209 } 222 210 211 void print( const ast::WaitStmt * node ) { 212 if ( node->timeout_time ) { 213 os << indent-1 << "timeout of:" << endl; 214 node->timeout_time->accept( *this ); 215 216 if ( node->timeout_stmt ) { 217 os << indent-1 << "... with statment:" << endl; 218 node->timeout_stmt->accept( *this ); 219 } 220 221 if ( node->timeout_cond ) { 222 os << indent-1 << "... with condition:" << endl; 223 node->timeout_cond->accept( *this ); 224 } 225 } 226 227 if ( node->else_stmt ) { 228 os << indent-1 << "else:" << endl; 229 node->else_stmt->accept( *this ); 230 231 if ( node->else_cond ) { 232 os << indent-1 << "... with condition:" << endl; 233 node->else_cond->accept( *this ); 234 } 235 } 236 } 237 223 238 void preprint( const ast::NamedTypeDecl * node ) { 224 239 if ( ! node->name.empty() ) { … … 230 245 } 231 246 232 print(node->storage );247 ast::print( os, node->storage ); 233 248 os << node->typeString(); 234 249 … … 272 287 273 288 void preprint( const ast::Type * node ) { 274 print(node->qualifiers );289 ast::print( os, node->qualifiers ); 275 290 } 276 291 … … 278 293 print( node->forall ); 279 294 print( node->assertions ); 280 print(node->qualifiers );295 ast::print( os, node->qualifiers ); 281 296 } 282 297 283 298 void preprint( const ast::BaseInstType * node ) { 284 299 print( node->attributes ); 285 print(node->qualifiers );300 ast::print( os, node->qualifiers ); 286 301 } 287 302 … … 294 309 } 295 310 296 print(node->storage );311 ast::print( os, node->storage ); 297 312 298 313 if ( node->type ) { … … 338 353 if ( ! short_mode ) printAll( node->attributes ); 339 354 340 print( node->storage ); 341 print( node->funcSpec ); 342 343 355 ast::print( os, node->storage ); 356 ast::print( os, node->funcSpec ); 344 357 345 358 if ( node->type && node->isTypeFixed ) { … … 384 397 --indent; 385 398 } 399 } 400 401 if ( ! node->withExprs.empty() ) { 402 // Not with a clause, but the 'with clause'. 403 ++indent; 404 os << " with clause" << endl << indent; 405 printAll( node->withExprs ); 406 --indent; 386 407 } 387 408 … … 746 767 virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final { 747 768 os << "Suspend Statement"; 748 switch (node-> type) {749 750 751 769 switch (node->kind) { 770 case ast::SuspendStmt::None : os << " with implicit target"; break; 771 case ast::SuspendStmt::Generator: os << " for generator"; break; 772 case ast::SuspendStmt::Coroutine: os << " for coroutine"; break; 752 773 } 753 774 os << endl; … … 759 780 } 760 781 ++indent; 782 783 return node; 784 } 785 786 virtual const ast::WhenClause * visit( const ast::WhenClause * node ) override final { 787 os << indent-1 << "target: "; 788 safe_print( node->target ); 789 790 if ( node->stmt ) { 791 os << indent-1 << "... with statment:" << endl; 792 node->stmt->accept( *this ); 793 } 794 795 if ( node->when_cond ) { 796 os << indent-1 << "... with when condition:" << endl; 797 node->when_cond->accept( *this ); 798 } 761 799 762 800 return node; … … 800 838 virtual const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final { 801 839 os << indent-1 << "target function: "; 802 safe_print( node->target _func);840 safe_print( node->target ); 803 841 804 842 if ( !node->target_args.empty() ) { … … 814 852 } 815 853 816 if ( node-> cond ) {854 if ( node->when_cond ) { 817 855 os << indent-1 << "... with condition:" << endl; 818 node->cond->accept( *this ); 819 } 820 856 node->when_cond->accept( *this ); 857 } 858 859 return node; 860 } 861 862 virtual const ast::Stmt * visit( const ast::WaitUntilStmt * node ) override final { 863 os << "Waituntil Statement" << endl; 864 indent += 2; 865 for( const auto & clause : node->clauses ) { 866 clause->accept( *this ); 867 } 868 print(node); // calls print( const ast::WaitStmt * node ) 821 869 return node; 822 870 } … … 1627 1675 }; 1628 1676 1677 } // namespace 1678 1629 1679 void print( ostream & os, const ast::Node * node, Indenter indent ) { 1630 1680 Printer printer { os, indent, false }; … … 1637 1687 } 1638 1688 1639 // Annoyingly these needed to be defined out of line to avoid undefined references. 1640 // The size here needs to be explicit but at least the compiler will produce an error 1641 // if the wrong size is specified 1642 constexpr array<const char*, 3> Printer::Names::FuncSpecifiers; 1643 constexpr array<const char*, 6> Printer::Names::StorageClasses; 1644 constexpr array<const char*, 5> Printer::Names::Qualifiers; 1689 void print( ostream & os, Function::Specs specs ) { 1690 print( os, specs, Names::FuncSpecifiers ); 1645 1691 } 1692 1693 void print( ostream & os, Storage::Classes storage ) { 1694 print( os, storage, Names::StorageClasses ); 1695 } 1696 1697 void print( ostream & os, CV::Qualifiers qualifiers ) { 1698 print( os, qualifiers, Names::Qualifiers ); 1699 } 1700 1701 } // namespace ast
Note:
See TracChangeset
for help on using the changeset viewer.