Changeset 0bd3faf for src/InitTweak
- Timestamp:
- Nov 13, 2023, 1:40:12 PM (2 years ago)
- Branches:
- master
- Children:
- 6ea85b22
- Parents:
- 25f2798
- Location:
- src/InitTweak
- Files:
-
- 6 edited
-
FixGlobalInit.cc (modified) (3 diffs)
-
FixInitNew.cpp (modified) (2 diffs)
-
GenInit.cc (modified) (10 diffs)
-
GenInit.h (modified) (1 diff)
-
InitTweak.cc (modified) (18 diffs)
-
InitTweak.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r25f2798 r0bd3faf 27 27 28 28 namespace InitTweak { 29 class GlobalFixer _new: public ast::WithShortCircuiting {29 class GlobalFixer : public ast::WithShortCircuiting { 30 30 public: 31 31 void previsit (const ast::ObjectDecl *); … … 42 42 43 43 void fixGlobalInit(ast::TranslationUnit & translationUnit, bool inLibrary) { 44 ast::Pass<GlobalFixer _new> fixer;44 ast::Pass<GlobalFixer> fixer; 45 45 accept_all(translationUnit, fixer); 46 46 … … 73 73 } 74 74 75 void GlobalFixer _new::previsit(const ast::ObjectDecl * objDecl) {75 void GlobalFixer::previsit(const ast::ObjectDecl * objDecl) { 76 76 auto mutDecl = mutate(objDecl); 77 77 assertf(mutDecl == objDecl, "Global object decl must be unique"); -
src/InitTweak/FixInitNew.cpp
r25f2798 r0bd3faf 917 917 // static variables with the same name in different functions. 918 918 // Note: it isn't sufficient to modify only the mangleName, because 919 // then subsequent Indexerpasses can choke on seeing the object's name919 // then subsequent SymbolTable passes can choke on seeing the object's name 920 920 // if another object has the same name and type. An unfortunate side-effect 921 921 // of renaming the object is that subsequent NameExprs may fail to resolve, … … 1169 1169 arg2 = new ast::MemberExpr(funcDecl->location, field, new ast::VariableExpr(funcDecl->location, function->params.back() ) ); 1170 1170 } 1171 InitExpander _newsrcParam( arg2 );1171 InitExpander srcParam( arg2 ); 1172 1172 // cast away reference type and construct field. 1173 1173 ast::Expr * thisExpr = new ast::CastExpr(funcDecl->location, new ast::VariableExpr(funcDecl->location, thisParam ), thisParam->get_type()->stripReferences()); -
src/InitTweak/GenInit.cc
r25f2798 r0bd3faf 46 46 namespace { 47 47 48 # warning Remove the _New suffix after the conversion is complete.49 50 48 // Outer pass finds declarations, for their type could wrap a type that needs hoisting 51 struct HoistArrayDimension_NoResolve _Newfinal :49 struct HoistArrayDimension_NoResolve final : 52 50 public ast::WithDeclsToAdd<>, public ast::WithShortCircuiting, 53 51 public ast::WithGuards, public ast::WithConstTranslationUnit, 54 public ast::WithVisitorRef<HoistArrayDimension_NoResolve _New>,52 public ast::WithVisitorRef<HoistArrayDimension_NoResolve>, 55 53 public ast::WithSymbolTableX<ast::SymbolTable::ErrorDetection::IgnoreErrors> { 56 54 … … 59 57 public ast::WithShortCircuiting, public ast::WithGuards { 60 58 61 HoistArrayDimension_NoResolve _New* outer;62 HoistDimsFromTypes( HoistArrayDimension_NoResolve _New* outer ) : outer(outer) {}59 HoistArrayDimension_NoResolve * outer; 60 HoistDimsFromTypes( HoistArrayDimension_NoResolve * outer ) : outer(outer) {} 63 61 64 62 // Only intended for visiting through types. … … 211 209 212 210 213 struct ReturnFixer _Newfinal :211 struct ReturnFixer final : 214 212 public ast::WithStmtsToAdd<>, ast::WithGuards, ast::WithShortCircuiting { 215 213 void previsit( const ast::FunctionDecl * decl ); … … 219 217 }; 220 218 221 void ReturnFixer _New::previsit( const ast::FunctionDecl * decl ) {219 void ReturnFixer::previsit( const ast::FunctionDecl * decl ) { 222 220 if (decl->linkage == ast::Linkage::Intrinsic) visit_children = false; 223 221 GuardValue( funcDecl ) = decl; 224 222 } 225 223 226 const ast::ReturnStmt * ReturnFixer _New::previsit(224 const ast::ReturnStmt * ReturnFixer::previsit( 227 225 const ast::ReturnStmt * stmt ) { 228 226 auto & returns = funcDecl->returns; … … 265 263 266 264 void genInit( ast::TranslationUnit & transUnit ) { 267 ast::Pass<HoistArrayDimension_NoResolve _New>::run( transUnit );268 ast::Pass<ReturnFixer _New>::run( transUnit );265 ast::Pass<HoistArrayDimension_NoResolve>::run( transUnit ); 266 ast::Pass<ReturnFixer>::run( transUnit ); 269 267 } 270 268 271 269 void fixReturnStatements( ast::TranslationUnit & transUnit ) { 272 ast::Pass<ReturnFixer _New>::run( transUnit );273 } 274 275 bool ManagedTypes _new::isManaged( const ast::Type * type ) const {270 ast::Pass<ReturnFixer>::run( transUnit ); 271 } 272 273 bool ManagedTypes::isManaged( const ast::Type * type ) const { 276 274 // references are never constructed 277 275 if ( dynamic_cast< const ast::ReferenceType * >( type ) ) return false; … … 292 290 } 293 291 294 bool ManagedTypes _new::isManaged( const ast::ObjectDecl * objDecl ) const {292 bool ManagedTypes::isManaged( const ast::ObjectDecl * objDecl ) const { 295 293 const ast::Type * type = objDecl->type; 296 294 while ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) { … … 302 300 } 303 301 304 void ManagedTypes _new::handleDWT( const ast::DeclWithType * dwt ) {302 void ManagedTypes::handleDWT( const ast::DeclWithType * dwt ) { 305 303 // if this function is a user-defined constructor or destructor, mark down the type as "managed" 306 304 if ( ! dwt->linkage.is_overrideable && CodeGen::isCtorDtor( dwt->name ) ) { … … 313 311 } 314 312 315 void ManagedTypes _new::handleStruct( const ast::StructDecl * aggregateDecl ) {313 void ManagedTypes::handleStruct( const ast::StructDecl * aggregateDecl ) { 316 314 // don't construct members, but need to take note if there is a managed member, 317 315 // because that means that this type is also managed … … 329 327 } 330 328 331 void ManagedTypes _new::beginScope() { managedTypes.beginScope(); }332 void ManagedTypes _new::endScope() { managedTypes.endScope(); }329 void ManagedTypes::beginScope() { managedTypes.beginScope(); } 330 void ManagedTypes::endScope() { managedTypes.endScope(); } 333 331 334 332 ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg) { 335 333 assertf(objDecl, "genCtorDtor passed null objDecl"); 336 InitExpander _newsrcParam(arg);334 InitExpander srcParam(arg); 337 335 return SymTab::genImplicitCall(srcParam, new ast::VariableExpr(loc, objDecl), loc, fname, objDecl); 338 336 } … … 341 339 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor for each 342 340 // constructable object 343 InitExpander _newsrcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr };341 InitExpander srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr }; 344 342 ast::ptr< ast::Expr > dstParam = new ast::VariableExpr(loc, objDecl); 345 343 -
src/InitTweak/GenInit.h
r25f2798 r0bd3faf 37 37 ast::ConstructorInit * genCtorInit( const CodeLocation & loc, const ast::ObjectDecl * objDecl ); 38 38 39 class ManagedTypes _new{39 class ManagedTypes final { 40 40 public: 41 41 bool isManaged( const ast::ObjectDecl * objDecl ) const ; // determine if object is managed -
src/InitTweak/InitTweak.cc
r25f2798 r0bd3faf 39 39 namespace InitTweak { 40 40 namespace { 41 struct HasDesignations _new: public ast::WithShortCircuiting {41 struct HasDesignations : public ast::WithShortCircuiting { 42 42 bool result = false; 43 43 … … 57 57 }; 58 58 59 struct InitDepthChecker _new{59 struct InitDepthChecker { 60 60 bool result = true; 61 61 const ast::Type * type; 62 62 int curDepth = 0, maxDepth = 0; 63 InitDepthChecker _new( const ast::Type * type ) : type( type ) {63 InitDepthChecker( const ast::Type * type ) : type( type ) { 64 64 const ast::Type * t = type; 65 65 while ( auto at = dynamic_cast< const ast::ArrayType * >( t ) ) { … … 78 78 }; 79 79 80 struct InitFlattener _new: public ast::WithShortCircuiting {80 struct InitFlattener : public ast::WithShortCircuiting { 81 81 std::vector< ast::ptr< ast::Expr > > argList; 82 82 … … 90 90 91 91 bool isDesignated( const ast::Init * init ) { 92 ast::Pass<HasDesignations _new> finder;92 ast::Pass<HasDesignations> finder; 93 93 maybe_accept( init, finder ); 94 94 return finder.core.result; … … 96 96 97 97 bool checkInitDepth( const ast::ObjectDecl * objDecl ) { 98 ast::Pass<InitDepthChecker _new> checker( objDecl->type );98 ast::Pass<InitDepthChecker> checker( objDecl->type ); 99 99 maybe_accept( objDecl->init.get(), checker ); 100 100 return checker.core.result; … … 102 102 103 103 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ) { 104 ast::Pass< InitFlattener _new> flattener;104 ast::Pass< InitFlattener > flattener; 105 105 maybe_accept( init, flattener ); 106 106 return std::move( flattener.core.argList ); 107 107 } 108 108 109 class InitExpander _new::ExpanderImpl {109 class InitExpander::ExpanderImpl { 110 110 public: 111 111 virtual ~ExpanderImpl() = default; … … 137 137 template< typename Out > 138 138 void build( 139 ast::UntypedExpr * callExpr, const InitExpander _new::IndexList & indices,139 ast::UntypedExpr * callExpr, const InitExpander::IndexList & indices, 140 140 const ast::Init * init, Out & out 141 141 ) { … … 183 183 } 184 184 185 class InitImpl _new final : public InitExpander_new::ExpanderImpl {185 class InitImpl final : public InitExpander::ExpanderImpl { 186 186 ast::ptr< ast::Init > init; 187 187 public: 188 InitImpl _new( const ast::Init * i ) : init( i ) {}189 190 std::vector< ast::ptr< ast::Expr > > next( InitExpander _new::IndexList & ) override {188 InitImpl( const ast::Init * i ) : init( i ) {} 189 190 std::vector< ast::ptr< ast::Expr > > next( InitExpander::IndexList & ) override { 191 191 return makeInitList( init ); 192 192 } 193 193 194 194 ast::ptr< ast::Stmt > buildListInit( 195 ast::UntypedExpr * callExpr, InitExpander _new::IndexList & indices195 ast::UntypedExpr * callExpr, InitExpander::IndexList & indices 196 196 ) override { 197 197 // If array came with an initializer list, initialize each element. We may have more … … 215 215 }; 216 216 217 class ExprImpl _new final : public InitExpander_new::ExpanderImpl {217 class ExprImpl final : public InitExpander::ExpanderImpl { 218 218 ast::ptr< ast::Expr > arg; 219 219 public: 220 ExprImpl _new( const ast::Expr * a ) : arg( a ) {}220 ExprImpl( const ast::Expr * a ) : arg( a ) {} 221 221 222 222 std::vector< ast::ptr< ast::Expr > > next( 223 InitExpander _new::IndexList & indices223 InitExpander::IndexList & indices 224 224 ) override { 225 225 if ( ! arg ) return {}; … … 237 237 238 238 ast::ptr< ast::Stmt > buildListInit( 239 ast::UntypedExpr *, InitExpander _new::IndexList &239 ast::UntypedExpr *, InitExpander::IndexList & 240 240 ) override { 241 241 return {}; … … 244 244 } // anonymous namespace 245 245 246 InitExpander _new::InitExpander_new( const ast::Init * init )247 : expander( new InitImpl _new{ init } ), crnt(), indices() {}248 249 InitExpander _new::InitExpander_new( const ast::Expr * expr )250 : expander( new ExprImpl _new{ expr } ), crnt(), indices() {}251 252 std::vector< ast::ptr< ast::Expr > > InitExpander _new::operator* () { return crnt; }253 254 InitExpander _new & InitExpander_new::operator++ () {246 InitExpander::InitExpander( const ast::Init * init ) 247 : expander( new InitImpl{ init } ), crnt(), indices() {} 248 249 InitExpander::InitExpander( const ast::Expr * expr ) 250 : expander( new ExprImpl{ expr } ), crnt(), indices() {} 251 252 std::vector< ast::ptr< ast::Expr > > InitExpander::operator* () { return crnt; } 253 254 InitExpander & InitExpander::operator++ () { 255 255 crnt = expander->next( indices ); 256 256 return *this; … … 259 259 /// builds statement which has the same semantics as a C-style list initializer (for array 260 260 /// initializers) using callExpr as the base expression to perform initialization 261 ast::ptr< ast::Stmt > InitExpander _new::buildListInit( ast::UntypedExpr * callExpr ) {261 ast::ptr< ast::Stmt > InitExpander::buildListInit( ast::UntypedExpr * callExpr ) { 262 262 return expander->buildListInit( callExpr, indices ); 263 263 } 264 264 265 void InitExpander _new::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) {265 void InitExpander::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) { 266 266 indices.emplace_back( index ); 267 267 indices.emplace_back( dimension ); 268 268 } 269 269 270 void InitExpander _new::clearArrayIndices() { indices.clear(); }271 272 bool InitExpander _new::addReference() {270 void InitExpander::clearArrayIndices() { indices.clear(); } 271 272 bool InitExpander::addReference() { 273 273 for ( ast::ptr< ast::Expr > & expr : crnt ) { 274 274 expr = new ast::AddressExpr{ expr }; … … 308 308 } 309 309 310 struct CallFinder _newfinal {310 struct CallFinder final { 311 311 std::vector< const ast::Expr * > matches; 312 312 const std::vector< std::string > names; 313 313 314 CallFinder _new( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {}314 CallFinder( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {} 315 315 316 316 void handleCallExpr( const ast::Expr * expr ) { … … 326 326 327 327 std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ) { 328 ast::Pass< CallFinder _new> finder{ std::vector< std::string >{ "?{}", "^?{}" } };328 ast::Pass< CallFinder > finder{ std::vector< std::string >{ "?{}", "^?{}" } }; 329 329 maybe_accept( stmt, finder ); 330 330 return std::move( finder.core.matches ); … … 381 381 } 382 382 383 struct ConstExprChecker _new: public ast::WithShortCircuiting {383 struct ConstExprChecker : public ast::WithShortCircuiting { 384 384 // most expressions are not const expr 385 385 void previsit( const ast::Expr * ) { result = false; visit_children = false; } … … 426 426 bool isConstExpr( const ast::Expr * expr ) { 427 427 if ( expr ) { 428 ast::Pass<ConstExprChecker _new> checker;428 ast::Pass<ConstExprChecker> checker; 429 429 expr->accept( checker ); 430 430 return checker.core.result; … … 435 435 bool isConstExpr( const ast::Init * init ) { 436 436 if ( init ) { 437 ast::Pass<ConstExprChecker _new> checker;437 ast::Pass<ConstExprChecker> checker; 438 438 init->accept( checker ); 439 439 return checker.core.result; … … 486 486 } 487 487 488 } 488 } // namespace InitTweak -
src/InitTweak/InitTweak.h
r25f2798 r0bd3faf 79 79 void addDataSectionAttribute( ast::ObjectDecl * objDecl ); 80 80 81 class InitExpander _new{81 class InitExpander final { 82 82 public: 83 83 using IndexList = std::vector< ast::ptr< ast::Expr > >; … … 92 92 public: 93 93 /// Expand by stepping through init to get each list of arguments 94 InitExpander _new( const ast::Init * init );94 InitExpander( const ast::Init * init ); 95 95 96 96 /// Always expand to expression 97 InitExpander _new( const ast::Expr * expr );97 InitExpander( const ast::Expr * expr ); 98 98 99 99 std::vector< ast::ptr< ast::Expr > > operator* (); 100 InitExpander _new& operator++ ();100 InitExpander & operator++ (); 101 101 102 102 /// builds statement which has the same semantics as a C-style list initializer (for array … … 111 111 bool addReference(); 112 112 }; 113 } // namespace 113 } // namespace InitTweak 114 114 115 115 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.