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