Changeset 8984003 for src/InitTweak/InitTweak.h
- Timestamp:
- Nov 21, 2023, 4:47:58 PM (7 months ago)
- Branches:
- master
- Children:
- 53dac82
- Parents:
- c36a419
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.h
rc36a419 r8984003 25 25 // helper functions for initialization 26 26 namespace InitTweak { 27 bool isAssignment( const ast::FunctionDecl * decl );28 bool isDestructor( const ast::FunctionDecl * decl );29 bool isDefaultConstructor( const ast::FunctionDecl * decl );30 bool isCopyConstructor( const ast::FunctionDecl * decl );31 bool isCopyFunction( const ast::FunctionDecl * decl );32 27 33 /// returns the base type of the first parameter to a constructor/destructor/assignment function 34 const ast::Type * getTypeofThis( const ast::FunctionType * ftype ); 28 bool isAssignment( const ast::FunctionDecl * decl ); 29 bool isDestructor( const ast::FunctionDecl * decl ); 30 bool isDefaultConstructor( const ast::FunctionDecl * decl ); 31 bool isCopyConstructor( const ast::FunctionDecl * decl ); 32 bool isCopyFunction( const ast::FunctionDecl * decl ); 35 33 36 /// returns the first parameter ofa constructor/destructor/assignment function37 const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);34 /// returns the base type of the first parameter to a constructor/destructor/assignment function 35 const ast::Type * getTypeofThis( const ast::FunctionType * ftype ); 38 36 39 /// generate a bitwise assignment operation. 40 ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src);37 /// returns the first parameter of a constructor/destructor/assignment function 38 const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func); 41 39 42 /// transform Initializer into an argument list that can be passed to a call expression 43 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init);40 /// generate a bitwise assignment operation. 41 ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src); 44 42 45 /// True if the resolver should try to construct dwt 46 bool tryConstruct( const ast::DeclWithType * dwt );43 /// transform Initializer into an argument list that can be passed to a call expression 44 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ); 47 45 48 /// True if the type can have a user-defined constructor 49 bool isConstructable( const ast::Type *t );46 /// True if the resolver should try to construct dwt 47 bool tryConstruct( const ast::DeclWithType * dwt ); 50 48 51 /// True if the Initializer contains designations 52 bool isDesignated( const ast::Init * init );49 /// True if the type can have a user-defined constructor 50 bool isConstructable( const ast::Type * t ); 53 51 54 /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its 55 /// type, where the depth of its type is the number of nested ArrayTypes + 1 56 bool checkInitDepth( const ast::ObjectDecl * objDecl ); 52 /// True if the Initializer contains designations 53 bool isDesignated( const ast::Init * init ); 57 54 58 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. 59 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. 60 /// Currently has assertions that make it less than fully general. 61 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ); 55 /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its 56 /// type, where the depth of its type is the number of nested ArrayTypes + 1 57 bool checkInitDepth( const ast::ObjectDecl * objDecl ); 62 58 63 /// get all Ctor/Dtor call expressions from a Statement 64 std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ); 59 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. 60 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. 61 /// Currently has assertions that make it less than fully general. 62 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ); 65 63 66 /// returns true if expr is trivially a compile-time constant 67 bool isConstExpr( const ast::Expr * expr ); 68 bool isConstExpr( const ast::Init * init ); 64 /// get all Ctor/Dtor call expressions from a Statement 65 std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ); 69 66 70 /// Modifies objDecl to have: 71 /// __attribute__((section (".data#"))) 72 /// which makes gcc put the declared variable in the data section, 73 /// which is helpful for global constants on newer gcc versions, 74 /// so that CFA's generated initialization won't segfault when writing it via a const cast. 75 /// The trailing # is an injected assembly comment, to suppress the "a" in 76 /// .section .data,"a" 77 /// .section .data#,"a" 78 /// to avoid assembler warning "ignoring changed section attributes for .data" 79 void addDataSectionAttribute( ast::ObjectDecl * objDecl ); 67 /// returns true if expr is trivially a compile-time constant 68 bool isConstExpr( const ast::Expr * expr ); 69 bool isConstExpr( const ast::Init * init ); 80 70 81 class InitExpander final { 82 public: 83 using IndexList = std::vector< ast::ptr< ast::Expr > >; 84 class ExpanderImpl; 71 /// Modifies objDecl to have: 72 /// __attribute__((section (".data#"))) 73 /// which makes gcc put the declared variable in the data section, 74 /// which is helpful for global constants on newer gcc versions, 75 /// so that CFA's generated initialization won't segfault when writing it via a const cast. 76 /// The trailing # is an injected assembly comment, to suppress the "a" in 77 /// .section .data,"a" 78 /// .section .data#,"a" 79 /// to avoid assembler warning "ignoring changed section attributes for .data" 80 void addDataSectionAttribute( ast::ObjectDecl * objDecl ); 85 81 86 private: 87 std::shared_ptr< ExpanderImpl > expander; 88 std::vector< ast::ptr< ast::Expr > > crnt; 89 // invariant: list of size 2N (elements come in pairs [index, dimension]) 90 IndexList indices; 82 class InitExpander final { 83 public: 84 using IndexList = std::vector< ast::ptr< ast::Expr > >; 85 class ExpanderImpl; 91 86 92 public: 93 /// Expand by stepping through init to get each list of arguments 94 InitExpander( const ast::Init * init ); 87 private: 88 std::shared_ptr< ExpanderImpl > expander; 89 std::vector< ast::ptr< ast::Expr > > crnt; 90 // invariant: list of size 2N (elements come in pairs [index, dimension]) 91 IndexList indices; 95 92 96 /// Always expand to expression 97 InitExpander( const ast::Expr * expr ); 93 public: 94 /// Expand by stepping through init to get each list of arguments 95 InitExpander( const ast::Init * init ); 98 96 99 std::vector< ast::ptr< ast::Expr > > operator* ();100 InitExpander & operator++ ();97 /// Always expand to expression 98 InitExpander( const ast::Expr * expr ); 101 99 102 /// builds statement which has the same semantics as a C-style list initializer (for array 103 /// initializers) using callExpr as the base expression to perform initialization. 104 /// Mutates callExpr 105 ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr ); 100 std::vector< ast::ptr< ast::Expr > > operator* (); 101 InitExpander & operator++ (); 106 102 107 void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ); 103 /// builds statement which has the same semantics as a C-style list initializer (for array 104 /// initializers) using callExpr as the base expression to perform initialization. 105 /// Mutates callExpr 106 ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr ); 108 107 109 void clearArrayIndices();108 void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ); 110 109 111 bool addReference(); 112 }; 110 void clearArrayIndices(); 111 112 bool addReference(); 113 }; 114 113 115 } // namespace InitTweak 114 116
Note: See TracChangeset
for help on using the changeset viewer.