Ignore:
Timestamp:
Nov 21, 2023, 4:47:58 PM (7 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
53dac82
Parents:
c36a419
Message:

Round of significant clean-up and reindentation of InitTweak? directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.h

    rc36a419 r8984003  
    2525// helper functions for initialization
    2626namespace 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 );
    3227
    33         /// returns the base type of the first parameter to a constructor/destructor/assignment function
    34         const ast::Type * getTypeofThis( const ast::FunctionType * ftype );
     28bool isAssignment( const ast::FunctionDecl * decl );
     29bool isDestructor( const ast::FunctionDecl * decl );
     30bool isDefaultConstructor( const ast::FunctionDecl * decl );
     31bool isCopyConstructor( const ast::FunctionDecl * decl );
     32bool isCopyFunction( const ast::FunctionDecl * decl );
    3533
    36         /// returns the first parameter of a constructor/destructor/assignment function
    37         const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);
     34/// returns the base type of the first parameter to a constructor/destructor/assignment function
     35const ast::Type * getTypeofThis( const ast::FunctionType * ftype );
    3836
    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
     38const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);
    4139
    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.
     41ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src);
    4442
    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
     44std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
    4745
    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
     47bool tryConstruct( const ast::DeclWithType * dwt );
    5048
    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
     50bool isConstructable( const ast::Type * t );
    5351
    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
     53bool isDesignated( const ast::Init * init );
    5754
    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
     57bool checkInitDepth( const ast::ObjectDecl * objDecl );
    6258
    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.
     62bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
    6563
    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
     65std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt );
    6966
    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
     68bool isConstExpr( const ast::Expr * expr );
     69bool isConstExpr( const ast::Init * init );
    8070
    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"
     80void addDataSectionAttribute( ast::ObjectDecl * objDecl );
    8581
    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;
     82class InitExpander final {
     83public:
     84        using IndexList = std::vector< ast::ptr< ast::Expr > >;
     85        class ExpanderImpl;
    9186
    92         public:
    93                 /// Expand by stepping through init to get each list of arguments
    94                 InitExpander( const ast::Init * init );
     87private:
     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;
    9592
    96                 /// Always expand to expression
    97                 InitExpander( const ast::Expr * expr );
     93public:
     94        /// Expand by stepping through init to get each list of arguments
     95        InitExpander( const ast::Init * init );
    9896
    99                 std::vector< ast::ptr< ast::Expr > > operator* ();
    100                 InitExpander & operator++ ();
     97        /// Always expand to expression
     98        InitExpander( const ast::Expr * expr );
    10199
    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++ ();
    106102
    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 );
    108107
    109                 void clearArrayIndices();
     108        void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
    110109
    111                 bool addReference();
    112         };
     110        void clearArrayIndices();
     111
     112        bool addReference();
     113};
     114
    113115} // namespace InitTweak
    114116
Note: See TracChangeset for help on using the changeset viewer.