Changes in src/SymTab/Autogen.h [e6cf857f:16ba4a6f]
- File:
-
- 1 edited
-
src/SymTab/Autogen.h (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.h
re6cf857f r16ba4a6f 21 21 22 22 #include "AST/Decl.hpp" 23 #include "AST/Eval.hpp" 23 24 #include "AST/Expr.hpp" 24 25 #include "AST/Init.hpp" … … 70 71 template< typename OutIter > 71 72 ast::ptr< ast::Stmt > genCall( 72 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 73 const CodeLocation & loc, const std::string & fname, OutIter && out, 73 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 74 const CodeLocation & loc, const std::string & fname, OutIter && out, 74 75 const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward ); 75 76 … … 127 128 } 128 129 129 /// inserts into out a generated call expression to function fname with arguments dstParam and 130 /// inserts into out a generated call expression to function fname with arguments dstParam and 130 131 /// srcParam. Should only be called with non-array types. 131 /// optionally returns a statement which must be inserted prior to the containing loop, if 132 /// optionally returns a statement which must be inserted prior to the containing loop, if 132 133 /// there is one 133 134 template< typename OutIter > 134 ast::ptr< ast::Stmt > genScalarCall( 135 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 136 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 135 ast::ptr< ast::Stmt > genScalarCall( 136 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 137 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 137 138 const ast::Type * addCast = nullptr 138 139 ) { … … 152 153 153 154 if ( addCast ) { 154 // cast to T& with qualifiers removed, so that qualified objects can be constructed and 155 // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 156 // is considered a qualifier - for AddressExpr to resolve, its argument must have an 155 // cast to T& with qualifiers removed, so that qualified objects can be constructed and 156 // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 157 // is considered a qualifier - for AddressExpr to resolve, its argument must have an 157 158 // lvalue-qualified type, so remove all qualifiers except lvalue. 158 159 // xxx -- old code actually removed lvalue too... 159 160 ast::ptr< ast::Type > guard = addCast; // prevent castType from mutating addCast 160 161 ast::ptr< ast::Type > castType = addCast; 161 ast::remove_qualifiers( 162 castType, 162 ast::remove_qualifiers( 163 castType, 163 164 ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic ); 164 165 dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } }; … … 180 181 181 182 srcParam.clearArrayIndices(); 182 183 183 184 return listInit; 184 185 } … … 248 249 } 249 250 250 /// Store in out a loop which calls fname on each element of the array with srcParam and 251 /// Store in out a loop which calls fname on each element of the array with srcParam and 251 252 /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0 252 253 template< typename OutIter > 253 254 void genArrayCall( 254 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 255 const CodeLocation & loc, const std::string & fname, OutIter && out, 256 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 257 LoopDirection forward = LoopForward 255 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 256 const CodeLocation & loc, const std::string & fname, OutIter && out, 257 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 258 LoopDirection forward = LoopForward 258 259 ) { 259 260 static UniqueName indexName( "_index" ); … … 278 279 } else { 279 280 // generate: for ( int i = N-1; i >= 0; --i ) 280 begin = ast:: UntypedExpr::createCall( loc, "?-?",281 { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) });281 begin = ast::call( 282 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ) ); 282 283 end = ast::ConstantExpr::from_int( loc, 0 ); 283 284 cmp = "?>=?"; … … 285 286 } 286 287 287 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 288 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 288 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 289 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 289 290 new ast::SingleInit{ loc, begin } }; 290 291 ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index }; 291 292 ast::ptr< ast::Expr > cond = ast::UntypedExpr::createCall( 293 loc, cmp, { indexVar, end } ); 294 295 ast::ptr< ast::Expr > inc = ast::UntypedExpr::createCall( 296 loc, update, { indexVar } ); 297 298 ast::ptr< ast::Expr > dstIndex = ast::UntypedExpr::createCall( 299 loc, "?[?]", { dstParam, indexVar } ); 300 301 // srcParam must keep track of the array indices to build the source parameter and/or 292 293 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end ); 294 295 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar ); 296 297 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar ); 298 299 // srcParam must keep track of the array indices to build the source parameter and/or 302 300 // array list initializer 303 301 srcParam.addArrayIndex( indexVar, array->dimension ); … … 305 303 // for stmt's body, eventually containing call 306 304 ast::CompoundStmt * body = new ast::CompoundStmt{ loc }; 307 ast::ptr< ast::Stmt > listInit = genCall( 308 srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 305 ast::ptr< ast::Stmt > listInit = genCall( 306 srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 309 307 forward ); 310 308 311 309 // block containing the stmt and index variable 312 310 ast::CompoundStmt * block = new ast::CompoundStmt{ loc }; … … 330 328 template< typename OutIter > 331 329 ast::ptr< ast::Stmt > genCall( 332 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 333 const CodeLocation & loc, const std::string & fname, OutIter && out, 330 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 331 const CodeLocation & loc, const std::string & fname, OutIter && out, 334 332 const ast::Type * type, const ast::Type * addCast, LoopDirection forward 335 333 ) { 336 334 if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) { 337 genArrayCall( 338 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 335 genArrayCall( 336 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 339 337 forward ); 340 338 return {}; 341 339 } else { 342 return genScalarCall( 340 return genScalarCall( 343 341 srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast ); 344 342 } … … 379 377 } 380 378 381 static inline ast::ptr< ast::Stmt > genImplicitCall( 382 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 383 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 384 LoopDirection forward = LoopForward 379 static inline ast::ptr< ast::Stmt > genImplicitCall( 380 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 381 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 382 LoopDirection forward = LoopForward 385 383 ) { 386 384 // unnamed bit fields are not copied as they cannot be accessed … … 394 392 395 393 std::vector< ast::ptr< ast::Stmt > > stmts; 396 genCall( 394 genCall( 397 395 srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward ); 398 396 … … 402 400 const ast::Stmt * callStmt = stmts.front(); 403 401 if ( addCast ) { 404 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 402 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 405 403 // aware they were generated. 406 404 callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt }; … … 419 417 // compile-command: "make install" // 420 418 // End: // 419
Note:
See TracChangeset
for help on using the changeset viewer.