Changes in / [a87d40b:6f15121]
- Location:
- src
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
ra87d40b r6f15121 518 518 } 519 519 520 const ast:: Stmt* visit( const ast::WithStmt * node ) override final {520 const ast::Decl * visit( const ast::WithStmt * node ) override final { 521 521 if ( inCache( node ) ) return nullptr; 522 522 auto stmt = new WithStmt( … … 524 524 get<Statement>().accept1( node->stmt ) 525 525 ); 526 return stmtPostamble( stmt, node ); 526 declPostamble( stmt, node ); 527 return nullptr; 527 528 } 528 529 … … 1039 1040 get<Expression>().accept1(node->expr), 1040 1041 inCache(node->deleteStmt) ? 1041 this->node:1042 get< BaseSyntaxNode>().accept1(node->deleteStmt)1042 strict_dynamic_cast<Declaration*>(this->node) : 1043 get<Declaration>().accept1(node->deleteStmt) 1043 1044 ) 1044 1045 ); … … 1908 1909 old->location, 1909 1910 GET_ACCEPT_V(exprs, Expr), 1910 GET_ACCEPT_1(stmt, Stmt), 1911 GET_LABELS_V(old->labels) 1911 GET_ACCEPT_1(stmt, Stmt) 1912 1912 ); 1913 1913 cache.emplace( old, this->node ); … … 2397 2397 GET_ACCEPT_1(expr, Expr), 2398 2398 inCache(old->deleteStmt) ? 2399 this->node:2400 GET_ACCEPT_1(deleteStmt, Node)2399 strict_dynamic_cast<ast::Decl*>(this->node) : 2400 GET_ACCEPT_1(deleteStmt, Decl) 2401 2401 ) 2402 2402 ); -
src/AST/Decl.hpp
ra87d40b r6f15121 102 102 ptr<Expr> bitfieldWidth; 103 103 104 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, 105 const Init * init = nullptr, Storage::Classes storage = {}, 106 Linkage::Spec linkage = Linkage::C, const Expr * bitWd = nullptr, 104 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, 105 const Init * init = nullptr, Storage::Classes storage = {}, 106 Linkage::Spec linkage = Linkage::C, const Expr * bitWd = nullptr, 107 107 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} ) 108 108 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ), … … 321 321 }; 322 322 323 /// With statement `with (...) ...` 324 class WithStmt final : public Decl { 325 public: 326 std::vector<ptr<Expr>> exprs; 327 ptr<Stmt> stmt; 328 329 WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt ) 330 : Decl(loc, "", Storage::Auto, Linkage::Cforall), exprs(std::move(exprs)), stmt(stmt) {} 331 332 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 333 private: 334 WithStmt * clone() const override { return new WithStmt{ *this }; } 335 MUTATE_FRIEND 336 }; 337 323 338 class AsmDecl : public Decl { 324 339 public: -
src/AST/Expr.hpp
ra87d40b r6f15121 769 769 public: 770 770 ptr<Expr> expr; 771 readonly< Node> deleteStmt;772 773 DeletedExpr( const CodeLocation & loc, const Expr * e, const Node* del )771 readonly<Decl> deleteStmt; 772 773 DeletedExpr( const CodeLocation & loc, const Expr * e, const Decl * del ) 774 774 : Expr( loc, e->result ), expr( e ), deleteStmt( del ) { assert( expr->result ); } 775 775 -
src/AST/Pass.hpp
ra87d40b r6f15121 112 112 const ast::Stmt * visit( const ast::FinallyStmt * ) override final; 113 113 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; 114 const ast:: Stmt* visit( const ast::WithStmt * ) override final;114 const ast::Decl * visit( const ast::WithStmt * ) override final; 115 115 const ast::NullStmt * visit( const ast::NullStmt * ) override final; 116 116 const ast::Stmt * visit( const ast::DeclStmt * ) override final; -
src/AST/Pass.impl.hpp
ra87d40b r6f15121 894 894 // WithStmt 895 895 template< typename pass_t > 896 const ast:: Stmt* ast::Pass< pass_t >::visit( const ast::WithStmt * node ) {896 const ast::Decl * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) { 897 897 VISIT_START( node ); 898 898 -
src/AST/Print.cpp
ra87d40b r6f15121 37 37 } 38 38 39 class Printer : public Visitor {39 class Printer final : public Visitor { 40 40 public: 41 41 ostream & os; … … 272 272 273 273 public: 274 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) {274 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 275 275 if ( ! node->name.empty() ) os << node->name << ": "; 276 276 … … 314 314 } 315 315 316 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) {316 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 317 317 if ( !node->name.empty() ) os << node->name << ": "; 318 318 … … 342 342 } 343 343 344 virtual const ast::Decl * visit( const ast::StructDecl * node ) {344 virtual const ast::Decl * visit( const ast::StructDecl * node ) override final { 345 345 print(node); 346 346 return node; 347 347 } 348 348 349 virtual const ast::Decl * visit( const ast::UnionDecl * node ) {349 virtual const ast::Decl * visit( const ast::UnionDecl * node ) override final { 350 350 print(node); 351 351 return node; 352 352 } 353 353 354 virtual const ast::Decl * visit( const ast::EnumDecl * node ) {354 virtual const ast::Decl * visit( const ast::EnumDecl * node ) override final { 355 355 print(node); 356 356 return node; 357 357 } 358 358 359 virtual const ast::Decl * visit( const ast::TraitDecl * node ) {359 virtual const ast::Decl * visit( const ast::TraitDecl * node ) override final { 360 360 print(node); 361 361 return node; 362 362 } 363 363 364 virtual const ast::Decl * visit( const ast::TypeDecl * node ) {364 virtual const ast::Decl * visit( const ast::TypeDecl * node ) override final { 365 365 preprint( node ); 366 366 if ( ! short_mode && node->init ) { … … 374 374 } 375 375 376 virtual const ast::Decl * visit( const ast::TypedefDecl * node ) {377 preprint( node ); 378 return node; 379 } 380 381 virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) {376 virtual const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 377 preprint( node ); 378 return node; 379 } 380 381 virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 382 382 safe_print( node->stmt ); 383 383 return node; 384 384 } 385 385 386 virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) {386 virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 387 387 os << "Static Assert with condition: "; 388 388 ++indent; … … 396 396 } 397 397 398 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) {398 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 399 399 os << "Compound Statement:" << endl; 400 400 ++indent; … … 404 404 } 405 405 406 virtual const ast::Stmt * visit( const ast::ExprStmt * node ) {406 virtual const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 407 407 ++indent; 408 408 os << "Expression Statement:" << endl << indent; … … 412 412 } 413 413 414 virtual const ast::Stmt * visit( const ast::AsmStmt * node ) {414 virtual const ast::Stmt * visit( const ast::AsmStmt * node ) override final { 415 415 os << "Assembler Statement:" << endl; 416 416 ++indent; … … 433 433 } 434 434 435 virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) {435 virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 436 436 os << "GCC Directive: " << node->directive << endl; 437 437 return node; 438 438 } 439 439 440 virtual const ast::Stmt * visit( const ast::IfStmt * node ) {440 virtual const ast::Stmt * visit( const ast::IfStmt * node ) override final { 441 441 os << "If on condition:" << endl; 442 442 ++indent; … … 473 473 } 474 474 475 virtual const ast::Stmt * visit( const ast::WhileStmt * node ) {475 virtual const ast::Stmt * visit( const ast::WhileStmt * node ) override final { 476 476 if ( node->isDoWhile ) { os << "Do-"; } 477 477 os << "While on condition:" << endl; … … 490 490 } 491 491 492 virtual const ast::Stmt * visit( const ast::ForStmt * node ) {492 virtual const ast::Stmt * visit( const ast::ForStmt * node ) override final { 493 493 os << "For Statement" << endl; 494 494 … … 532 532 } 533 533 534 virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) {534 virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 535 535 os << "Switch on condition: "; 536 536 safe_print( node->cond ); … … 546 546 } 547 547 548 virtual const ast::Stmt * visit( const ast::CaseStmt * node ) {548 virtual const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 549 549 if ( node->isDefault() ) { 550 550 os << indent << "Default "; … … 565 565 } 566 566 567 virtual const ast::Stmt * visit( const ast::BranchStmt * node ) {567 virtual const ast::Stmt * visit( const ast::BranchStmt * node ) override final { 568 568 os << "Branch (" << node->kindName() << ")" << endl; 569 569 ++indent; … … 586 586 } 587 587 588 virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) {588 virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 589 589 os << "Return Statement, returning"; 590 590 if ( node->expr ) { … … 601 601 } 602 602 603 virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) {603 virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { 604 604 if ( node->target ) os << "Non-Local "; 605 605 … … 621 621 } 622 622 623 virtual const ast::Stmt * visit( const ast::TryStmt * node ) {623 virtual const ast::Stmt * visit( const ast::TryStmt * node ) override final { 624 624 ++indent; 625 625 os << "Try Statement" << endl << indent-1 … … 642 642 } 643 643 644 virtual const ast::Stmt * visit( const ast::CatchStmt * node ) {644 virtual const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 645 645 os << "Catch "; 646 646 switch ( node->kind ) { … … 667 667 } 668 668 669 virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) {669 virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 670 670 os << "Finally Statement" << endl; 671 671 os << indent << "... with block:" << endl; … … 678 678 } 679 679 680 virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) {680 virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 681 681 os << "Waitfor Statement" << endl; 682 682 indent += 2; … … 732 732 } 733 733 734 virtual const ast:: Stmt * visit( const ast::WithStmt * node ){734 virtual const ast::Decl * visit( const ast::WithStmt * node ) override final { 735 735 os << "With statement" << endl; 736 736 os << indent << "... with expressions:" << endl; … … 744 744 } 745 745 746 virtual const ast::NullStmt * visit( const ast::NullStmt * node ) {746 virtual const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 747 747 os << "Null Statement" << endl; 748 748 print( node->labels ); … … 751 751 } 752 752 753 virtual const ast::Stmt * visit( const ast::DeclStmt * node ) {753 virtual const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 754 754 os << "Declaration of "; 755 755 safe_print( node->decl ); … … 758 758 } 759 759 760 virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) {760 virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { 761 761 os << "Implicit Ctor Dtor Statement" << endl; 762 762 os << indent << "... with Ctor/Dtor: "; … … 769 769 } 770 770 771 virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) {771 virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 772 772 ++indent; 773 773 os << "Application of" << endl << indent; … … 784 784 } 785 785 786 virtual const ast::Expr * visit( const ast::UntypedExpr * node ) {786 virtual const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 787 787 ++indent; 788 788 os << "Applying untyped:" << endl; … … 797 797 } 798 798 799 virtual const ast::Expr * visit( const ast::NameExpr * node ) {799 virtual const ast::Expr * visit( const ast::NameExpr * node ) override final { 800 800 os << "Name: " << node->name; 801 801 postprint( node ); … … 804 804 } 805 805 806 virtual const ast::Expr * visit( const ast::AddressExpr * node ) {806 virtual const ast::Expr * visit( const ast::AddressExpr * node ) override final { 807 807 os << "Address of:" << endl; 808 808 ++indent; … … 815 815 } 816 816 817 virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) {817 virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 818 818 os << "Address of label:" << node->arg; 819 819 … … 821 821 } 822 822 823 virtual const ast::Expr * visit( const ast::CastExpr * node ) {823 virtual const ast::Expr * visit( const ast::CastExpr * node ) override final { 824 824 ++indent; 825 825 os << (node->isGenerated ? "Generated" : "Explicit") << " cast of:" << endl << indent; … … 841 841 } 842 842 843 virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) {843 virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 844 844 ++indent; 845 845 os << "Keyword Cast of:" << endl << indent; … … 852 852 } 853 853 854 virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) {854 virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 855 855 ++indent; 856 856 os << "Virtual Cast of:" << endl << indent; … … 869 869 } 870 870 871 virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) {871 virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 872 872 ++indent; 873 873 os << "Untyped Member Expression, with field: " << endl << indent; … … 881 881 } 882 882 883 virtual const ast::Expr * visit( const ast::MemberExpr * node ) {883 virtual const ast::Expr * visit( const ast::MemberExpr * node ) override final { 884 884 ++indent; 885 885 os << "Member Expression, with field:" << endl << indent; … … 893 893 } 894 894 895 virtual const ast::Expr * visit( const ast::VariableExpr * node ) {895 virtual const ast::Expr * visit( const ast::VariableExpr * node ) override final { 896 896 os << "Variable Expression: "; 897 897 short_print( node->var ); … … 901 901 } 902 902 903 virtual const ast::Expr * visit( const ast::ConstantExpr * node ) {903 virtual const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 904 904 os << "Constant Expression (" << node->rep; 905 905 if ( node->result ) { … … 913 913 } 914 914 915 virtual const ast::Expr * visit( const ast::SizeofExpr * node ) {915 virtual const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 916 916 os << "Sizeof Expression on: "; 917 917 ++indent; … … 924 924 } 925 925 926 virtual const ast::Expr * visit( const ast::AlignofExpr * node ) {926 virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 927 927 os << "Alignof Expression on: "; 928 928 ++indent; … … 935 935 } 936 936 937 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) {937 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 938 938 os << "Untyped Offsetof Expression on member " << node->member << " of "; 939 939 ++indent; … … 945 945 } 946 946 947 virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) {947 virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 948 948 os << "Offsetof Expression on member " << node->member->name << " of "; 949 949 ++indent; … … 955 955 } 956 956 957 virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) {957 virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 958 958 os << "Offset Pack Expression on: "; 959 959 ++indent; … … 965 965 } 966 966 967 virtual const ast::Expr * visit( const ast::LogicalExpr * node ) {967 virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 968 968 os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: "; 969 969 safe_print( node->arg1 ); … … 975 975 } 976 976 977 virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) {977 virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 978 978 ++indent; 979 979 os << "Conditional expression on:" << endl << indent; … … 989 989 } 990 990 991 virtual const ast::Expr * visit( const ast::CommaExpr * node ) {991 virtual const ast::Expr * visit( const ast::CommaExpr * node ) override final { 992 992 ++indent; 993 993 os << "Comma Expression:" << endl << indent; … … 1001 1001 } 1002 1002 1003 virtual const ast::Expr * visit( const ast::TypeExpr * node ) {1003 virtual const ast::Expr * visit( const ast::TypeExpr * node ) override final { 1004 1004 safe_print( node->type ); 1005 1005 postprint( node ); … … 1008 1008 } 1009 1009 1010 virtual const ast::Expr * visit( const ast::AsmExpr * node ) {1010 virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final { 1011 1011 os << "Asm Expression:" << endl; 1012 1012 ++indent; … … 1019 1019 } 1020 1020 1021 virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) {1021 virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 1022 1022 ++indent; 1023 1023 os << "Implicit Copy Constructor Expression:" << endl << indent; … … 1029 1029 } 1030 1030 1031 virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) {1031 virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 1032 1032 os << "Constructor Expression:" << endl << indent+1; 1033 1033 indent += 2; … … 1039 1039 } 1040 1040 1041 virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) {1041 virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 1042 1042 ++indent; 1043 1043 os << "Compound Literal Expression: " << endl << indent; … … 1051 1051 } 1052 1052 1053 virtual const ast::Expr * visit( const ast::RangeExpr * node ) {1053 virtual const ast::Expr * visit( const ast::RangeExpr * node ) override final { 1054 1054 os << "Range Expression: "; 1055 1055 safe_print( node->low ); … … 1061 1061 } 1062 1062 1063 virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) {1063 virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 1064 1064 os << "Untyped Tuple:" << endl; 1065 1065 ++indent; … … 1071 1071 } 1072 1072 1073 virtual const ast::Expr * visit( const ast::TupleExpr * node ) {1073 virtual const ast::Expr * visit( const ast::TupleExpr * node ) override final { 1074 1074 os << "Tuple:" << endl; 1075 1075 ++indent; … … 1081 1081 } 1082 1082 1083 virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) {1083 virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 1084 1084 os << "Tuple Index Expression, with tuple:" << endl; 1085 1085 ++indent; … … 1093 1093 } 1094 1094 1095 virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) {1095 virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 1096 1096 os << "Tuple Assignment Expression, with stmt expr:" << endl; 1097 1097 ++indent; … … 1104 1104 } 1105 1105 1106 virtual const ast::Expr * visit( const ast::StmtExpr * node ) {1106 virtual const ast::Expr * visit( const ast::StmtExpr * node ) override final { 1107 1107 ++indent; 1108 1108 os << "Statement Expression:" << endl << indent; … … 1122 1122 } 1123 1123 1124 virtual const ast::Expr * visit( const ast::UniqueExpr * node ) {1124 virtual const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 1125 1125 ++indent; 1126 1126 os << "Unique Expression with id: " << node->id << endl << indent; … … 1136 1136 } 1137 1137 1138 virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) {1138 virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 1139 1139 ++indent; 1140 1140 os << "Untyped Init Expression" << endl << indent; … … 1152 1152 } 1153 1153 1154 virtual const ast::Expr * visit( const ast::InitExpr * node ) {1154 virtual const ast::Expr * visit( const ast::InitExpr * node ) override final { 1155 1155 ++indent; 1156 1156 os << "Init Expression" << endl << indent; … … 1163 1163 } 1164 1164 1165 virtual const ast::Expr * visit( const ast::DeletedExpr * node ) {1165 virtual const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 1166 1166 ++indent; 1167 1167 os << "Deleted Expression" << endl << indent; … … 1174 1174 } 1175 1175 1176 virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) {1176 virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 1177 1177 ++indent; 1178 1178 os << "Default Argument Expression" << endl << indent; … … 1183 1183 } 1184 1184 1185 virtual const ast::Expr * visit( const ast::GenericExpr * node ) {1185 virtual const ast::Expr * visit( const ast::GenericExpr * node ) override final { 1186 1186 ++indent; 1187 1187 os << "C11 _Generic Expression" << endl << indent; … … 1206 1206 } 1207 1207 1208 virtual const ast::Type * visit( const ast::VoidType * node ) {1208 virtual const ast::Type * visit( const ast::VoidType * node ) override final { 1209 1209 preprint( node ); 1210 1210 os << "void"; … … 1212 1212 } 1213 1213 1214 virtual const ast::Type * visit( const ast::BasicType * node ) {1214 virtual const ast::Type * visit( const ast::BasicType * node ) override final { 1215 1215 preprint( node ); 1216 1216 os << ast::BasicType::typeNames[ node->kind ]; … … 1218 1218 } 1219 1219 1220 virtual const ast::Type * visit( const ast::PointerType * node ) {1220 virtual const ast::Type * visit( const ast::PointerType * node ) override final { 1221 1221 preprint( node ); 1222 1222 if ( ! node->isArray() ) { … … 1241 1241 } 1242 1242 1243 virtual const ast::Type * visit( const ast::ArrayType * node ) {1243 virtual const ast::Type * visit( const ast::ArrayType * node ) override final { 1244 1244 preprint( node ); 1245 1245 if ( node->isStatic ) { … … 1265 1265 } 1266 1266 1267 virtual const ast::Type * visit( const ast::ReferenceType * node ) {1267 virtual const ast::Type * visit( const ast::ReferenceType * node ) override final { 1268 1268 preprint( node ); 1269 1269 os << "reference to "; … … 1273 1273 } 1274 1274 1275 virtual const ast::Type * visit( const ast::QualifiedType * node ) {1275 virtual const ast::Type * visit( const ast::QualifiedType * node ) override final { 1276 1276 preprint( node ); 1277 1277 ++indent; … … 1286 1286 } 1287 1287 1288 virtual const ast::Type * visit( const ast::FunctionType * node ) {1288 virtual const ast::Type * visit( const ast::FunctionType * node ) override final { 1289 1289 preprint( node ); 1290 1290 … … 1315 1315 } 1316 1316 1317 virtual const ast::Type * visit( const ast::StructInstType * node ) {1317 virtual const ast::Type * visit( const ast::StructInstType * node ) override final { 1318 1318 preprint( node ); 1319 1319 os << "instance of struct " << node->name; … … 1326 1326 } 1327 1327 1328 virtual const ast::Type * visit( const ast::UnionInstType * node ) {1328 virtual const ast::Type * visit( const ast::UnionInstType * node ) override final { 1329 1329 preprint( node ); 1330 1330 os << "instance of union " << node->name; … … 1337 1337 } 1338 1338 1339 virtual const ast::Type * visit( const ast::EnumInstType * node ) {1339 virtual const ast::Type * visit( const ast::EnumInstType * node ) override final { 1340 1340 preprint( node ); 1341 1341 os << "instance of enum " << node->name; … … 1348 1348 } 1349 1349 1350 virtual const ast::Type * visit( const ast::TraitInstType * node ) {1350 virtual const ast::Type * visit( const ast::TraitInstType * node ) override final { 1351 1351 preprint( node ); 1352 1352 os << "instance of trait " << node->name; … … 1356 1356 } 1357 1357 1358 virtual const ast::Type * visit( const ast::TypeInstType * node ) {1358 virtual const ast::Type * visit( const ast::TypeInstType * node ) override final { 1359 1359 preprint( node ); 1360 1360 os << "instance of type " << node->name … … 1365 1365 } 1366 1366 1367 virtual const ast::Type * visit( const ast::TupleType * node ) {1367 virtual const ast::Type * visit( const ast::TupleType * node ) override final { 1368 1368 preprint( node ); 1369 1369 os << "tuple of types" << endl; … … 1375 1375 } 1376 1376 1377 virtual const ast::Type * visit( const ast::TypeofType * node ) {1377 virtual const ast::Type * visit( const ast::TypeofType * node ) override final { 1378 1378 preprint( node ); 1379 1379 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; } … … 1384 1384 } 1385 1385 1386 virtual const ast::Type * visit( const ast::VarArgsType * node ) {1386 virtual const ast::Type * visit( const ast::VarArgsType * node ) override final { 1387 1387 preprint( node ); 1388 1388 os << "builtin var args pack"; … … 1390 1390 } 1391 1391 1392 virtual const ast::Type * visit( const ast::ZeroType * node ) {1392 virtual const ast::Type * visit( const ast::ZeroType * node ) override final { 1393 1393 preprint( node ); 1394 1394 os << "zero_t"; … … 1396 1396 } 1397 1397 1398 virtual const ast::Type * visit( const ast::OneType * node ) {1398 virtual const ast::Type * visit( const ast::OneType * node ) override final { 1399 1399 preprint( node ); 1400 1400 os << "one_t"; … … 1402 1402 } 1403 1403 1404 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) {1404 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final { 1405 1405 preprint( node ); 1406 1406 os << "Global Scope Type"; … … 1408 1408 } 1409 1409 1410 virtual const ast::Designation * visit( const ast::Designation * node ) {1410 virtual const ast::Designation * visit( const ast::Designation * node ) override final { 1411 1411 if ( node->designators.empty() ) return node; 1412 1412 os << "... designated by: " << endl; … … 1421 1421 } 1422 1422 1423 virtual const ast::Init * visit( const ast::SingleInit * node ) {1423 virtual const ast::Init * visit( const ast::SingleInit * node ) override final { 1424 1424 os << "Simple Initializer: "; 1425 1425 safe_print( node->value ); … … 1427 1427 } 1428 1428 1429 virtual const ast::Init * visit( const ast::ListInit * node ) {1429 virtual const ast::Init * visit( const ast::ListInit * node ) override final { 1430 1430 os << "Compound initializer: " << endl; 1431 1431 ++indent; … … 1445 1445 } 1446 1446 1447 virtual const ast::Init * visit( const ast::ConstructorInit * node ) {1447 virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final { 1448 1448 os << "Constructor initializer: " << endl; 1449 1449 if ( node->ctor ) { … … 1470 1470 } 1471 1471 1472 virtual const ast::Attribute * visit( const ast::Attribute * node ) {1472 virtual const ast::Attribute * visit( const ast::Attribute * node ) override final { 1473 1473 if ( node->empty() ) return node; 1474 1474 os << "Attribute with name: " << node->name; … … 1481 1481 } 1482 1482 1483 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) {1483 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { 1484 1484 os << indent << "Types:" << endl; 1485 1485 for ( const auto& i : *node ) { -
src/AST/Stmt.hpp
ra87d40b r6f15121 380 380 }; 381 381 382 /// With statement `with (...) ...`383 class WithStmt final : public Stmt {384 public:385 std::vector<ptr<Expr>> exprs;386 ptr<Stmt> stmt;387 388 WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt,389 std::vector<Label> && labels = {} )390 : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {}391 392 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }393 private:394 WithStmt * clone() const override { return new WithStmt{ *this }; }395 MUTATE_FRIEND396 };397 398 382 /// Any declaration in a (compound) statement. 399 383 class DeclStmt final : public Stmt { -
src/AST/SymbolTable.cpp
ra87d40b r6f15121 73 73 74 74 SymbolTable::SymbolTable() 75 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 75 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 76 76 prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; } 77 77 … … 171 171 } 172 172 173 void SymbolTable::addDeletedId( const DeclWithType * decl, const Node* deleter ) {173 void SymbolTable::addDeletedId( const DeclWithType * decl, const Decl * deleter ) { 174 174 // default handling of conflicts is to raise an error 175 175 addId( decl, OnConflict::error(), nullptr, deleter ); … … 189 189 } 190 190 } 191 // does not need to be added to the table if both existing and added have a base that are 191 // does not need to be added to the table if both existing and added have a base that are 192 192 // the same 193 193 return true; … … 209 209 const std::string &id = decl->name; 210 210 211 if ( ! typeTable ) { 211 if ( ! typeTable ) { 212 212 typeTable = TypeTable::new_ptr(); 213 213 } else { 214 214 ++*stats().map_lookups; 215 215 auto existing = typeTable->find( id ); 216 if ( existing != typeTable->end() 217 && existing->second.scope == scope 216 if ( existing != typeTable->end() 217 && existing->second.scope == scope 218 218 && addedTypeConflicts( existing->second.decl, decl ) ) return; 219 219 } 220 220 221 221 lazyInitScope(); 222 222 ++*stats().map_mutations; … … 237 237 ++*stats().map_lookups; 238 238 auto existing = structTable->find( id ); 239 if ( existing != structTable->end() 240 && existing->second.scope == scope 239 if ( existing != structTable->end() 240 && existing->second.scope == scope 241 241 && addedDeclConflicts( existing->second.decl, decl ) ) return; 242 242 } … … 256 256 ++*stats().map_lookups; 257 257 auto existing = enumTable->find( id ); 258 if ( existing != enumTable->end() 259 && existing->second.scope == scope 258 if ( existing != enumTable->end() 259 && existing->second.scope == scope 260 260 && addedDeclConflicts( existing->second.decl, decl ) ) return; 261 261 } 262 262 263 263 lazyInitScope(); 264 264 ++*stats().map_mutations; … … 279 279 ++*stats().map_lookups; 280 280 auto existing = unionTable->find( id ); 281 if ( existing != unionTable->end() 282 && existing->second.scope == scope 281 if ( existing != unionTable->end() 282 && existing->second.scope == scope 283 283 && addedDeclConflicts( existing->second.decl, decl ) ) return; 284 284 } … … 298 298 ++*stats().map_lookups; 299 299 auto existing = traitTable->find( id ); 300 if ( existing != traitTable->end() 301 && existing->second.scope == scope 300 if ( existing != traitTable->end() 301 && existing->second.scope == scope 302 302 && addedDeclConflicts( existing->second.decl, decl ) ) return; 303 303 } … … 309 309 310 310 311 void SymbolTable::addWith( const std::vector< ptr<Expr> > & withExprs, const Node* withStmt ) {311 void SymbolTable::addWith( const std::vector< ptr<Expr> > & withExprs, const Decl * withStmt ) { 312 312 for ( const Expr * expr : withExprs ) { 313 313 if ( ! expr->result ) continue; 314 314 const Type * resTy = expr->result->stripReferences(); 315 315 auto aggrType = dynamic_cast< const ReferenceToType * >( resTy ); 316 assertf( aggrType, "WithStmt expr has non-aggregate type: %s", 316 assertf( aggrType, "WithStmt expr has non-aggregate type: %s", 317 317 toString( expr->result ).c_str() ); 318 318 const AggregateDecl * aggr = aggrType->aggr(); 319 assertf( aggr, "WithStmt has null aggregate from type: %s", 319 assertf( aggr, "WithStmt has null aggregate from type: %s", 320 320 toString( expr->result ).c_str() ); 321 321 322 322 addMembers( aggr, expr, OnConflict::deleteWith( withStmt ) ); 323 323 } … … 373 373 } 374 374 375 /// gets the declaration for the function acting on a type specified by otype key, 375 /// gets the declaration for the function acting on a type specified by otype key, 376 376 /// nullptr if none such 377 const FunctionDecl * getFunctionForOtype( 377 const FunctionDecl * getFunctionForOtype( 378 378 const DeclWithType * decl, const std::string & otypeKey ) { 379 379 auto func = dynamic_cast< const FunctionDecl * >( decl ); … … 383 383 } 384 384 385 bool SymbolTable::removeSpecialOverrides( 385 bool SymbolTable::removeSpecialOverrides( 386 386 SymbolTable::IdData & data, SymbolTable::MangleTable::Ptr & mangleTable ) { 387 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 388 // determine the set of ctor/dtor/assign that can be used by the requester. In particular, 389 // if the user defines a default ctor, then the generated default ctor is unavailable, 390 // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 391 // field ctors are available. If the user defines any ctor then the generated default ctor 392 // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 393 // anything that looks like a copy constructor, then the generated copy constructor is 387 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 388 // determine the set of ctor/dtor/assign that can be used by the requester. In particular, 389 // if the user defines a default ctor, then the generated default ctor is unavailable, 390 // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 391 // field ctors are available. If the user defines any ctor then the generated default ctor 392 // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 393 // anything that looks like a copy constructor, then the generated copy constructor is 394 394 // unavailable, and likewise for the assignment operator. 395 395 … … 450 450 // if this is the first user-defined function, delete non-user-defined overloads 451 451 std::vector< MangleTable::value_type > deleted; 452 452 453 453 for ( const auto& entry : *mangleTable ) { 454 454 // skip decls that aren't functions or are for the wrong type … … 489 489 if ( dataIsCopyFunc ) { 490 490 // remove current function if exists a user-defined copy function 491 // since the signatures for copy functions don't need to match exactly, using 491 // since the signatures for copy functions don't need to match exactly, using 492 492 // a delete statement is the wrong approach 493 493 if ( InitTweak::isCopyFunction( decl ) ) return false; … … 499 499 } 500 500 } 501 501 502 502 // nothing (more) to fix, return true 503 503 return true; … … 525 525 526 526 bool SymbolTable::addedIdConflicts( 527 const SymbolTable::IdData & existing, const DeclWithType * added, 528 SymbolTable::OnConflict handleConflicts, const Node* deleter ) {529 // if we're giving the same name mangling to things of different types then there is something 527 const SymbolTable::IdData & existing, const DeclWithType * added, 528 SymbolTable::OnConflict handleConflicts, const Decl * deleter ) { 529 // if we're giving the same name mangling to things of different types then there is something 530 530 // wrong 531 531 assert( (isObject( added ) && isObject( existing.id ) ) 532 532 || ( isFunction( added ) && isFunction( existing.id ) ) ); 533 533 534 534 if ( existing.id->linkage.is_overrideable ) { 535 535 // new definition shadows the autogenerated one, even at the same scope 536 536 return false; 537 } else if ( existing.id->linkage.is_mangled 538 || ResolvExpr::typesCompatible( 537 } else if ( existing.id->linkage.is_mangled 538 || ResolvExpr::typesCompatible( 539 539 added->get_type(), existing.id->get_type(), SymbolTable{} ) ) { 540 540 541 541 // it is a conflict if one declaration is deleted and the other is not 542 542 if ( deleter && ! existing.deleter ) { … … 555 555 if ( isDefinition( added ) && isDefinition( existing.id ) ) { 556 556 if ( handleConflicts.mode == OnConflict::Error ) { 557 SemanticError( added, 558 isFunction( added ) ? 559 "duplicate function definition for " : 557 SemanticError( added, 558 isFunction( added ) ? 559 "duplicate function definition for " : 560 560 "duplicate object definition for " ); 561 561 } … … 572 572 } 573 573 574 void SymbolTable::addId( 575 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr, 576 const Node* deleter ) {574 void SymbolTable::addId( 575 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr, 576 const Decl * deleter ) { 577 577 ++*stats().add_calls; 578 578 const std::string &name = decl->name; … … 581 581 std::string mangleName; 582 582 if ( decl->linkage.is_overrideable ) { 583 // mangle the name without including the appropriate suffix, so overridable routines 583 // mangle the name without including the appropriate suffix, so overridable routines 584 584 // are placed into the same "bucket" as their user defined versions. 585 585 mangleName = Mangle::mangle( decl, Mangle::Mode{ Mangle::NoOverrideable } ); … … 588 588 } 589 589 590 // this ensures that no two declarations with the same unmangled name at the same scope 590 // this ensures that no two declarations with the same unmangled name at the same scope 591 591 // both have C linkage 592 592 if ( decl->linkage.is_mangled ) { … … 596 596 } 597 597 } else { 598 // NOTE: only correct if name mangling is completely isomorphic to C 598 // NOTE: only correct if name mangling is completely isomorphic to C 599 599 // type-compatibility, which it may not be. 600 600 if ( hasIncompatibleCDecl( name, mangleName ) ) { … … 628 628 idTable = idTable->set( 629 629 name, 630 mangleTable->set( 631 mangleName, 630 mangleTable->set( 631 mangleName, 632 632 IdData{ existing->second, handleConflicts.deleter } ) ); 633 633 } … … 647 647 } 648 648 649 void SymbolTable::addMembers( 649 void SymbolTable::addMembers( 650 650 const AggregateDecl * aggr, const Expr * expr, SymbolTable::OnConflict handleConflicts ) { 651 651 for ( const Decl * decl : aggr->members ) { … … 655 655 const Type * t = dwt->get_type()->stripReferences(); 656 656 if ( auto rty = dynamic_cast<const ReferenceToType *>( t ) ) { 657 if ( ! dynamic_cast<const StructInstType *>(rty) 657 if ( ! dynamic_cast<const StructInstType *>(rty) 658 658 && ! dynamic_cast<const UnionInstType *>(rty) ) continue; 659 659 ResolvExpr::Cost cost = ResolvExpr::Cost::zero; 660 660 const Expr * base = ResolvExpr::referenceToRvalueConversion( expr, cost ); 661 addMembers( 661 addMembers( 662 662 rty->aggr(), new MemberExpr{ base->location, dwt, base }, handleConflicts ); 663 663 } … … 680 680 if ( ! decl.second.id->linkage.is_mangled && decl.first == mangleName ) return true; 681 681 } 682 682 683 683 return false; 684 684 } -
src/AST/SymbolTable.hpp
ra87d40b r6f15121 37 37 readonly<DeclWithType> id = nullptr; ///< Identifier of declaration 38 38 readonly<Expr> baseExpr = nullptr; ///< Implied containing aggregate (from WithExpr) 39 readonly< Node> deleter = nullptr; ///< Node deleting this declaration (if non-null)39 readonly<Decl> deleter = nullptr; ///< Node deleting this declaration (if non-null) 40 40 unsigned long scope = 0; ///< Scope of identifier 41 41 42 42 IdData() = default; 43 IdData( const DeclWithType * i, const Expr * base, const Node * del, unsigned long s )43 IdData( const DeclWithType * i, const Expr * base, const Decl * del, unsigned long s ) 44 44 : id( i ), baseExpr( base ), deleter( del ), scope( s ) {} 45 45 46 46 /// Modify an existing node with a new deleter 47 IdData( const IdData & o, const Node* del )47 IdData( const IdData & o, const Decl * del ) 48 48 : id( o.id ), baseExpr( o.baseExpr ), deleter( del ), scope( o.scope ) {} 49 49 … … 58 58 struct scoped { 59 59 readonly<D> decl; ///< wrapped declaration 60 unsigned long scope; ///< scope of this declaration 60 unsigned long scope; ///< scope of this declaration 61 61 62 62 scoped(const D * d, unsigned long s) : decl(d), scope(s) {} … … 88 88 ~SymbolTable(); 89 89 90 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to 90 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to 91 91 // tell the indexer explicitly when scopes begin and end 92 92 void enterScope(); … … 118 118 void addId( const DeclWithType * decl, const Expr * baseExpr = nullptr ); 119 119 /// Adds a deleted identifier declaration to the symbol table 120 void addDeletedId( const DeclWithType * decl, const Node* deleter );120 void addDeletedId( const DeclWithType * decl, const Decl * deleter ); 121 121 122 122 /// Adds a type to the symbol table … … 136 136 137 137 /// adds all of the IDs from WithStmt exprs 138 void addWith( const std::vector< ptr<Expr> > & withExprs, const Node* withStmt );138 void addWith( const std::vector< ptr<Expr> > & withExprs, const Decl * withStmt ); 139 139 140 140 /// convenience function for adding a list of Ids to the indexer … … 154 154 const SymbolTable * atScope( unsigned long i ) const; 155 155 156 /// Removes matching autogenerated constructors and destructors so that they will not be 156 /// Removes matching autogenerated constructors and destructors so that they will not be 157 157 /// selected. If returns false, passed decl should not be added. 158 158 bool removeSpecialOverrides( IdData & decl, MangleTable::Ptr & mangleTable ); … … 164 164 Delete ///< Delete the earlier version with the delete statement 165 165 } mode; 166 const Node* deleter; ///< Statement that deletes this expression166 const Decl * deleter; ///< Statement that deletes this expression 167 167 168 168 private: 169 169 OnConflict() : mode(Error), deleter(nullptr) {} 170 OnConflict( const Node* d ) : mode(Delete), deleter(d) {}170 OnConflict( const Decl * d ) : mode(Delete), deleter(d) {} 171 171 public: 172 172 OnConflict( const OnConflict& ) = default; 173 173 174 174 static OnConflict error() { return {}; } 175 static OnConflict deleteWith( const Node* d ) { return { d }; }175 static OnConflict deleteWith( const Decl * d ) { return { d }; } 176 176 }; 177 177 178 178 /// true if the existing identifier conflicts with the added identifier 179 179 bool addedIdConflicts( 180 const IdData & existing, const DeclWithType * added, OnConflict handleConflicts, 181 const Node* deleter );180 const IdData & existing, const DeclWithType * added, OnConflict handleConflicts, 181 const Decl * deleter ); 182 182 183 183 /// common code for addId, addDeletedId, etc. 184 void addId( 185 const DeclWithType * decl, OnConflict handleConflicts, const Expr * baseExpr = nullptr, 186 const Node* deleter = nullptr );184 void addId( 185 const DeclWithType * decl, OnConflict handleConflicts, const Expr * baseExpr = nullptr, 186 const Decl * deleter = nullptr ); 187 187 188 188 /// adds all of the members of the Aggregate (addWith helper) -
src/AST/Visitor.hpp
ra87d40b r6f15121 48 48 virtual const ast::Stmt * visit( const ast::FinallyStmt * ) = 0; 49 49 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0; 50 virtual const ast:: Stmt* visit( const ast::WithStmt * ) = 0;50 virtual const ast::Decl * visit( const ast::WithStmt * ) = 0; 51 51 virtual const ast::NullStmt * visit( const ast::NullStmt * ) = 0; 52 52 virtual const ast::Stmt * visit( const ast::DeclStmt * ) = 0; -
src/Common/PassVisitor.h
ra87d40b r6f15121 279 279 virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; 280 280 virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; 281 virtual Statement* mutate( WithStmt * withStmt ) override final;281 virtual Declaration * mutate( WithStmt * withStmt ) override final; 282 282 virtual NullStmt * mutate( NullStmt * nullStmt ) override final; 283 283 virtual Statement * mutate( DeclStmt * declStmt ) override final; … … 420 420 void indexerAddUnionFwd ( const UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); } 421 421 void indexerAddTrait ( const TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); } 422 void indexerAddWith ( const std::list< Expression * > & exprs, const BaseSyntaxNode* withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); }422 void indexerAddWith ( const std::list< Expression * > & exprs, const Declaration * withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); } 423 423 424 424 -
src/Common/PassVisitor.impl.h
ra87d40b r6f15121 1617 1617 1618 1618 template< typename pass_type > 1619 Statement* PassVisitor< pass_type >::mutate( WithStmt * node ) {1619 Declaration * PassVisitor< pass_type >::mutate( WithStmt * node ) { 1620 1620 MUTATE_START( node ); 1621 1621 maybeMutate_impl( node->exprs, *this ); … … 1626 1626 maybeMutate_impl( node->stmt, *this ); 1627 1627 } 1628 MUTATE_END( Statement, node );1628 MUTATE_END( Declaration, node ); 1629 1629 } 1630 1630 -
src/Common/PassVisitor.proto.h
ra87d40b r6f15121 235 235 INDEXER_FUNC1( addUnion , const UnionDecl * ); 236 236 INDEXER_FUNC1( addTrait , const TraitDecl * ); 237 INDEXER_FUNC2( addWith , const std::list< Expression * > &, const BaseSyntaxNode* );237 INDEXER_FUNC2( addWith , const std::list< Expression * > &, const Declaration * ); 238 238 239 239 #undef INDEXER_FUNC1 -
src/Parser/ParseNode.h
ra87d40b r6f15121 437 437 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ); 438 438 WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when ); 439 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt );439 Statement * build_with( ExpressionNode * exprs, StatementNode * stmt ); 440 440 441 441 //############################################################################## -
src/Parser/StatementNode.cc
ra87d40b r6f15121 317 317 } // build_waitfor_timeout 318 318 319 WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {319 Statement * build_with( ExpressionNode * exprs, StatementNode * stmt ) { 320 320 std::list< Expression * > e; 321 321 buildMoveList( exprs, e ); 322 322 Statement * s = maybeMoveBuild<Statement>( stmt ); 323 return new WithStmt( e, s);323 return new DeclStmt( new WithStmt( e, s ) ); 324 324 } // build_with 325 325 -
src/SymTab/Indexer.cc
ra87d40b r6f15121 210 210 bool Indexer::addedIdConflicts( 211 211 const Indexer::IdData & existing, const DeclarationWithType * added, 212 Indexer::OnConflict handleConflicts, const BaseSyntaxNode* deleteStmt ) {212 Indexer::OnConflict handleConflicts, const Declaration * deleteStmt ) { 213 213 // if we're giving the same name mangling to things of different types then there is 214 214 // something wrong … … 432 432 433 433 void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr, 434 const BaseSyntaxNode* deleteStmt ) {434 const Declaration * deleteStmt ) { 435 435 ++* stats().add_calls; 436 436 const std::string &name = decl->name; … … 510 510 } 511 511 512 void Indexer::addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode* deleteStmt ) {512 void Indexer::addDeletedId( const DeclarationWithType * decl, const Declaration * deleteStmt ) { 513 513 // default handling of conflicts is to raise an error 514 514 addId( decl, OnConflict::error(), nullptr, deleteStmt ); … … 661 661 } 662 662 663 void Indexer::addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode* withStmt ) {663 void Indexer::addWith( const std::list< Expression * > & withExprs, const Declaration * withStmt ) { 664 664 for ( const Expression * expr : withExprs ) { 665 665 if ( expr->result ) { … … 704 704 ret = new VariableExpr( const_cast<DeclarationWithType *>(id) ); 705 705 } 706 if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast< BaseSyntaxNode*>(deleteStmt) );706 if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<Declaration *>(deleteStmt) ); 707 707 return ret; 708 708 } -
src/SymTab/Indexer.h
ra87d40b r6f15121 44 44 45 45 /// non-null if this declaration is deleted 46 const BaseSyntaxNode* deleteStmt = nullptr;46 const Declaration * deleteStmt = nullptr; 47 47 /// scope of identifier 48 48 unsigned long scope = 0; … … 51 51 IdData() = default; 52 52 IdData( 53 const DeclarationWithType * id, const Expression * baseExpr, const BaseSyntaxNode* deleteStmt,53 const DeclarationWithType * id, const Expression * baseExpr, const Declaration * deleteStmt, 54 54 unsigned long scope ) 55 55 : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ), scope( scope ) {} 56 IdData( const IdData& o, const BaseSyntaxNode* deleteStmt )56 IdData( const IdData& o, const Declaration * deleteStmt ) 57 57 : id( o.id ), baseExpr( o.baseExpr ), deleteStmt( deleteStmt ), scope( o.scope ) {} 58 58 … … 83 83 84 84 void addId( const DeclarationWithType * decl, const Expression * baseExpr = nullptr ); 85 void addDeletedId( const DeclarationWithType * decl, const BaseSyntaxNode* deleteStmt );85 void addDeletedId( const DeclarationWithType * decl, const Declaration * deleteStmt ); 86 86 87 87 void addType( const NamedTypeDecl * decl ); … … 94 94 95 95 /// adds all of the IDs from WithStmt exprs 96 void addWith( const std::list< Expression * > & withExprs, const BaseSyntaxNode* withStmt );96 void addWith( const std::list< Expression * > & withExprs, const Declaration * withStmt ); 97 97 98 98 /// convenience function for adding a list of Ids to the indexer … … 152 152 Delete ///< Delete the earlier version with the delete statement 153 153 } mode; 154 const BaseSyntaxNode* deleteStmt; ///< Statement that deletes this expression154 const Declaration * deleteStmt; ///< Statement that deletes this expression 155 155 156 156 private: 157 157 OnConflict() : mode(Error), deleteStmt(nullptr) {} 158 OnConflict( const BaseSyntaxNode* d ) : mode(Delete), deleteStmt(d) {}158 OnConflict( const Declaration * d ) : mode(Delete), deleteStmt(d) {} 159 159 public: 160 160 OnConflict( const OnConflict& ) = default; 161 161 162 162 static OnConflict error() { return {}; } 163 static OnConflict deleteWith( const BaseSyntaxNode* d ) { return { d }; }163 static OnConflict deleteWith( const Declaration * d ) { return { d }; } 164 164 }; 165 165 … … 167 167 bool addedIdConflicts( 168 168 const IdData & existing, const DeclarationWithType * added, OnConflict handleConflicts, 169 const BaseSyntaxNode* deleteStmt );169 const Declaration * deleteStmt ); 170 170 171 171 /// common code for addId, addDeletedId, etc. 172 172 void addId(const DeclarationWithType * decl, OnConflict handleConflicts, 173 const Expression * baseExpr = nullptr, const BaseSyntaxNode* deleteStmt = nullptr );173 const Expression * baseExpr = nullptr, const Declaration * deleteStmt = nullptr ); 174 174 175 175 /// adds all of the members of the Aggregate (addWith helper) -
src/SynTree/Declaration.h
ra87d40b r6f15121 360 360 }; 361 361 362 class WithStmt : public Declaration { 363 public: 364 std::list< Expression * > exprs; 365 Statement * stmt; 366 367 WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 368 WithStmt( const WithStmt & other ); 369 virtual ~WithStmt(); 370 371 virtual WithStmt * clone() const override { return new WithStmt( *this ); } 372 virtual void accept( Visitor & v ) override { v.visit( this ); } 373 virtual void accept( Visitor & v ) const override { v.visit( this ); } 374 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 375 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 376 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override { print(os, indent); } 377 }; 378 362 379 class AsmDecl : public Declaration { 363 380 public: -
src/SynTree/Expression.cc
ra87d40b r6f15121 724 724 } 725 725 726 DeletedExpr::DeletedExpr( Expression * expr, BaseSyntaxNode* deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {726 DeletedExpr::DeletedExpr( Expression * expr, Declaration * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) { 727 727 assert( expr->result ); 728 728 result = expr->result->clone(); -
src/SynTree/Expression.h
ra87d40b r6f15121 888 888 public: 889 889 Expression * expr; 890 BaseSyntaxNode* deleteStmt;891 892 DeletedExpr( Expression * expr, BaseSyntaxNode* deleteStmt );890 Declaration * deleteStmt; 891 892 DeletedExpr( Expression * expr, Declaration * deleteStmt ); 893 893 DeletedExpr( const DeletedExpr & other ); 894 894 ~DeletedExpr(); -
src/SynTree/Mutator.h
ra87d40b r6f15121 52 52 virtual Statement * mutate( FinallyStmt * catchStmt ) = 0; 53 53 virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0; 54 virtual Statement* mutate( WithStmt * withStmt ) = 0;54 virtual Declaration * mutate( WithStmt * withStmt ) = 0; 55 55 virtual NullStmt * mutate( NullStmt * nullStmt ) = 0; 56 56 virtual Statement * mutate( DeclStmt * declStmt ) = 0; -
src/SynTree/Statement.cc
ra87d40b r6f15121 493 493 494 494 495 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Statement(), exprs( exprs ), stmt( stmt ) {}496 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) {495 WithStmt::WithStmt( const std::list< Expression * > & exprs, Statement * stmt ) : Declaration("", noStorageClasses, LinkageSpec::Cforall), exprs( exprs ), stmt( stmt ) {} 496 WithStmt::WithStmt( const WithStmt & other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { 497 497 cloneAll( other.exprs, exprs ); 498 498 } -
src/SynTree/Statement.h
ra87d40b r6f15121 461 461 }; 462 462 463 class WithStmt : public Statement {464 public:465 std::list< Expression * > exprs;466 Statement * stmt;467 468 WithStmt( const std::list< Expression * > & exprs, Statement * stmt );469 WithStmt( const WithStmt & other );470 virtual ~WithStmt();471 472 virtual WithStmt * clone() const override { return new WithStmt( *this ); }473 virtual void accept( Visitor & v ) override { v.visit( this ); }474 virtual void accept( Visitor & v ) const override { v.visit( this ); }475 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }476 virtual void print( std::ostream & os, Indenter indent = {} ) const override;477 };463 // class WithStmt : public Statement { 464 // public: 465 // std::list< Expression * > exprs; 466 // Statement * stmt; 467 468 // WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 469 // WithStmt( const WithStmt & other ); 470 // virtual ~WithStmt(); 471 472 // virtual WithStmt * clone() const override { return new WithStmt( *this ); } 473 // virtual void accept( Visitor & v ) override { v.visit( this ); } 474 // virtual void accept( Visitor & v ) const override { v.visit( this ); } 475 // virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 476 // virtual void print( std::ostream & os, Indenter indent = {} ) const override; 477 // }; 478 478 479 479
Note: See TracChangeset
for help on using the changeset viewer.