Changes in / [2ad4b49:1ddbf3b]
- Location:
- src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
r2ad4b49 r1ddbf3b 828 828 VISIT_START( node ); 829 829 830 { 831 // while statements introduce a level of scope (for the initialization) 832 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 833 maybeAccept_impl( node->initialization, *this ); 834 visitExpression ( node->condition ); 835 node->body = visitStatement( node->body ); 836 } 830 visitExpression( node->condition ); 831 node->body = visitStatement( node->body ); 837 832 838 833 VISIT_END( node ); … … 843 838 MUTATE_START( node ); 844 839 845 { 846 // while statements introduce a level of scope (for the initialization) 847 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 848 maybeMutate_impl( node->initialization, *this ); 849 node->condition = mutateExpression( node->condition ); 850 node->body = mutateStatement ( node->body ); 851 } 852 840 node->condition = mutateExpression( node->condition ); 841 node->body = mutateStatement ( node->body ); 853 842 854 843 MUTATE_END( Statement, node ); -
src/ControlStruct/ForExprMutator.cc
r2ad4b49 r1ddbf3b 45 45 return hoist( forStmt, forStmt->initialization ); 46 46 } 47 Statement *ForExprMutator::postmutate( WhileStmt *whileStmt ) {48 return hoist( whileStmt, whileStmt->initialization );49 }50 47 } // namespace ControlStruct 51 48 -
src/ControlStruct/ForExprMutator.h
r2ad4b49 r1ddbf3b 18 18 class IfStmt; 19 19 class ForStmt; 20 class WhileStmt;21 20 class Statement; 22 21 … … 26 25 Statement *postmutate( IfStmt * ); 27 26 Statement *postmutate( ForStmt * ); 28 Statement *postmutate( WhileStmt * );29 27 }; 30 28 } // namespace ControlStruct -
src/Parser/ParseNode.h
r2ad4b49 r1ddbf3b 403 403 }; 404 404 405 Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init );406 405 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 407 406 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); -
src/Parser/StatementNode.cc
r2ad4b49 r1ddbf3b 80 80 } 81 81 82 Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) { 82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 83 Statement * thenb, * elseb = 0; 84 std::list< Statement * > branches; 85 buildMoveList< Statement, StatementNode >( then_stmt, branches ); 86 assert( branches.size() == 1 ); 87 thenb = branches.front(); 88 89 if ( else_stmt ) { 90 std::list< Statement * > branches; 91 buildMoveList< Statement, StatementNode >( else_stmt, branches ); 92 assert( branches.size() == 1 ); 93 elseb = branches.front(); 94 } // if 95 96 std::list< Statement * > init; 83 97 if ( ctl->init != 0 ) { 84 98 buildMoveList( ctl->init, init ); … … 88 102 if ( ctl->condition ) { 89 103 // compare the provided condition against 0 90 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );104 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) ); 91 105 } else { 92 106 for ( Statement * stmt : init ) { … … 99 113 } 100 114 delete ctl; 101 return cond;102 }103 104 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {105 Statement * thenb, * elseb = 0;106 std::list< Statement * > branches;107 buildMoveList< Statement, StatementNode >( then_stmt, branches );108 assert( branches.size() == 1 );109 thenb = branches.front();110 111 if ( else_stmt ) {112 std::list< Statement * > branches;113 buildMoveList< Statement, StatementNode >( else_stmt, branches );114 assert( branches.size() == 1 );115 elseb = branches.front();116 } // if117 118 std::list< Statement * > init;119 Expression * cond = build_if_control( ctl, init );120 115 return new IfStmt( cond, thenb, elseb, init ); 121 116 } … … 149 144 buildMoveList< Statement, StatementNode >( stmt, branches ); 150 145 assert( branches.size() == 1 ); 151 152 std::list< Statement * > init; 153 return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, kind ); 146 return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind ); 154 147 } 155 148 -
src/ResolvExpr/Resolver.cc
r2ad4b49 r1ddbf3b 207 207 Alternative & choice = winners.front(); 208 208 if ( findDeletedExpr( choice.expr ) ) { 209 SemanticError( untyped->location,choice.expr, "Unique best alternative includes deleted identifier in " );209 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 210 210 } 211 211 alt = std::move( choice ); … … 242 242 243 243 static CastExpr untyped( nullptr ); // cast to void 244 untyped.location = expr->location;245 244 246 245 // set up and resolve expression cast to void … … 275 274 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer ) { 276 275 assert( untyped && type ); 277 // transfer location to generated cast for error purposes278 CodeLocation location = untyped->location;279 276 untyped = new CastExpr( untyped, type ); 280 untyped->location = location;281 277 findSingleExpression( untyped, indexer ); 282 278 removeExtraneousCast( untyped, indexer ); -
src/SymTab/Indexer.cc
r2ad4b49 r1ddbf3b 106 106 if ( ! CodeGen::isCtorDtorAssign( id ) ) return; 107 107 108 // helpful data structure to organize properties for a type108 // helpful data structure 109 109 struct ValueType { 110 struct DeclBall { // properties for this particular decl110 struct DeclBall { 111 111 IdData decl; 112 bool isUserDefinedFunc; 112 bool isUserDefinedFunc; // properties for this particular decl 113 bool isDefaultCtor; 114 bool isDtor; 113 115 bool isCopyFunc; 114 116 }; 115 117 // properties for this type 118 bool existsUserDefinedFunc = false; // any user-defined function found 119 bool existsUserDefinedCtor = false; // any user-defined constructor found 120 bool existsUserDefinedDtor = false; // any user-defined destructor found 116 121 bool existsUserDefinedCopyFunc = false; // user-defined copy ctor found 117 BaseSyntaxNode * deleteStmt = nullptr; // non-null if a user-defined function isfound122 bool existsUserDefinedDefaultCtor = false; // user-defined default ctor found 118 123 std::list< DeclBall > decls; 119 124 … … 122 127 ValueType & operator+=( IdData data ) { 123 128 DeclarationWithType * function = data.id; 124 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->linkage ); 125 bool isCopyFunc = InitTweak::isCopyFunction( function, function->name ); 126 decls.push_back( DeclBall{ data, isUserDefinedFunc, isCopyFunc } ); 129 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() ); 130 bool isDefaultCtor = InitTweak::isDefaultConstructor( function ); 131 bool isDtor = InitTweak::isDestructor( function ); 132 bool isCopyFunc = InitTweak::isCopyFunction( function, function->get_name() ); 133 decls.push_back( DeclBall{ data, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } ); 134 existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc; 135 existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) ); 136 existsUserDefinedDtor = existsUserDefinedDtor || (isUserDefinedFunc && isDtor); 127 137 existsUserDefinedCopyFunc = existsUserDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc); 128 if ( isUserDefinedFunc && ! data.deleteStmt ) { 129 // any user-defined function can act as an implicit delete statement for generated constructors. 130 // a delete stmt should not act as an implicit delete statement. 131 deleteStmt = data.id; 132 } 138 existsUserDefinedDefaultCtor = existsUserDefinedDefaultCtor || (isUserDefinedFunc && isDefaultCtor); 133 139 return *this; 134 140 } … … 154 160 155 161 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which determine 156 // the set of ctor/dtor/assign that can be used by the requester. In particular, if the user defines 157 // a default ctor, then the generated default ctor is unavailable, likewise for copy ctor 158 // and dtor. If the user defines any ctor/dtor, then no generated field ctors are available. 159 // If the user defines any ctor then the generated default ctor is unavailable (intrinsic default 160 // ctor must be overridden exactly). If the user defines anything that looks like a copy constructor, 161 // then the generated copy constructor is unavailable, and likewise for the assignment operator. 162 // the set of ctor/dtor/assign that are seen by the requester. In particular, if the user defines 163 // a default ctor, then the generated default ctor should never be seen, likewise for copy ctor 164 // and dtor. If the user defines any ctor/dtor, then no generated field ctors should be seen. 165 // If the user defines any ctor then the generated default ctor should not be seen (intrinsic default 166 // ctor must be overridden exactly). 162 167 for ( std::pair< const std::string, ValueType > & pair : funcMap ) { 163 168 ValueType & val = pair.second; 164 169 for ( ValueType::DeclBall ball : val.decls ) { 165 bool isNotUserDefinedFunc = ! ball.isUserDefinedFunc && ball.decl.id->linkage != LinkageSpec::Intrinsic;166 bool is CopyFunc = ball.isCopyFunc;167 bool existsUserDefinedCopyFunc = val.existsUserDefinedCopyFunc;168 // only implicitly delete non-user defined functions that are not intrinsic, and are169 // not copy functions (assignment or copy constructor), unless a user-defined copy function exists.170 // deleteStmt will be non-null only if a user-defined function is found.171 if (isNotUserDefinedFunc && (! isCopyFunc || existsUserDefinedCopyFunc)) {172 ball.decl.deleteStmt = val.deleteStmt;170 bool noUserDefinedFunc = ! val.existsUserDefinedFunc; 171 bool isUserDefinedFunc = ball.isUserDefinedFunc; 172 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl.id->linkage == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides 173 bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator 174 bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor; 175 if ( noUserDefinedFunc || isUserDefinedFunc || isAcceptableDefaultCtor || isAcceptableCopyFunc || isAcceptableDtor ) { 176 // decl conforms to the rules described above, so it should be seen by the requester 177 out.push_back( ball.decl ); 173 178 } 174 out.push_back( ball.decl );175 179 } 176 180 } -
src/SynTree/Statement.cc
r2ad4b49 r1ddbf3b 243 243 } 244 244 245 WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization,bool isDoWhile ):246 Statement(), condition( condition), body( body), i nitialization( initialization ), isDoWhile( isDoWhile) {245 WhileStmt::WhileStmt( Expression *condition, Statement *body, bool isDoWhile ): 246 Statement(), condition( condition), body( body), isDoWhile( isDoWhile) { 247 247 } 248 248 -
src/SynTree/Statement.h
r2ad4b49 r1ddbf3b 220 220 Expression *condition; 221 221 Statement *body; 222 std::list<Statement *> initialization;223 222 bool isDoWhile; 224 223 225 224 WhileStmt( Expression *condition, 226 Statement *body, std::list<Statement *> & initialization,bool isDoWhile = false );225 Statement *body, bool isDoWhile = false ); 227 226 WhileStmt( const WhileStmt &other ); 228 227 virtual ~WhileStmt(); -
src/tests/raii/.expect/ctor-autogen-ERR1.txt
r2ad4b49 r1ddbf3b 1 raii/ctor-autogen.c:102:1 error: Unique best alternative includes deleted identifier in Cast of:2 Application of3 Deleted Expression 4 Variable Expression: ?{}: static inline function5 ... with parameters6 _dst: reference to instance of struct Managed with body 17 x: signed int8 ... returning nothing1 raii/ctor-autogen.c:102:1 error: No reasonable alternatives for expression Applying untyped: 2 Name: ?{} 3 ...to: 4 Cast of: 5 Variable Expression: x: instance of struct Managed with body 1 6 ... to: 7 reference to instance of struct Managed with body 1 8 constant expression (123 123: signed int) 9 9 10 ... deleted by: ?{}: function11 ... with parameters12 m: reference to instance of struct Managed with body 113 ... returning nothing14 ... with body15 CompoundStmt16 Expression Statement:17 Application of18 Variable Expression: ?=?: function19 ... with parameters20 intrinsic reference to signed int21 intrinsic signed int22 ... returning23 _retval__operator_assign: signed int24 ... with attributes:25 Attribute with name: unused26 27 28 ... to arguments29 Cast of:30 Member Expression, with field:31 x: signed int32 ... from aggregate:33 Cast of:34 Variable Expression: m: reference to instance of struct Managed with body 135 ... to:36 instance of struct Managed with body 137 ... to:38 reference to signed int39 Cast of:40 constant expression (0 0: zero_t)41 ... to:42 signed int43 44 ... with environment:45 Types:46 Non-types:47 48 49 ... to arguments50 Cast of:51 Variable Expression: x: instance of struct Managed with body 152 ... to:53 reference to instance of struct Managed with body 154 constant expression (123 123: signed int)55 56 ... to: nothing
Note: See TracChangeset
for help on using the changeset viewer.