Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.h

    r7951100 rb067d9b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // RemoveInit.h --
     7// InitTweak.h --
    88//
    99// Author           : Rob Schluntz
    1010// Created On       : Fri May 13 11:26:36 2016
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:30:33 2017
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jul 19 14:18:00 2019
     13// Update Count     : 6
    1414//
    1515
     
    1919#include <memory>             // for shared_ptr
    2020#include <string>             // for string, allocator
     21#include <vector>
    2122
     23#include "AST/Fwd.hpp"        // for AST nodes
    2224#include "SynTree/SynTree.h"  // for Visitor Nodes
    2325
    2426// helper functions for initialization
    2527namespace InitTweak {
    26         FunctionDecl * isAssignment( Declaration * decl );
    27         FunctionDecl * isDestructor( Declaration * decl );
    28         FunctionDecl * isDefaultConstructor( Declaration * decl );
    29         FunctionDecl * isCopyConstructor( Declaration * decl );
    30         FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
     28        const FunctionDecl * isAssignment( const Declaration * decl );
     29        const FunctionDecl * isDestructor( const Declaration * decl );
     30        const FunctionDecl * isDefaultConstructor( const Declaration * decl );
     31        const FunctionDecl * isCopyConstructor( const Declaration * decl );
     32        const FunctionDecl * isCopyFunction( const Declaration * decl, const std::string & fname );
     33        bool isCopyFunction( const ast::FunctionDecl * decl );
    3134
    3235        /// returns the base type of the first parameter to a constructor/destructor/assignment function
     
    4144        /// transform Initializer into an argument list that can be passed to a call expression
    4245        std::list< Expression * > makeInitList( Initializer * init );
     46        std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
    4347
    4448        /// True if the resolver should try to construct dwt
     
    5761        /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
    5862        DeclarationWithType * getFunction( Expression * expr );
     63        const DeclarationWithType * getFunction( const Expression * expr );
     64        const ast::DeclWithType * getFunction( const ast::Expr * expr );
    5965
    6066        /// Non-Null if expr is a call expression whose target function is intrinsic
    6167        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
     68        const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);
    6269
    6370        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
     
    6572        /// Currently has assertions that make it less than fully general.
    6673        bool isIntrinsicSingleArgCallStmt( Statement * stmt );
     74        bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
    6775
    6876        /// True if stmt is a call statement where the function called is intrinsic.
     
    7179        /// get all Ctor/Dtor call expressions from a Statement
    7280        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
     81        std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt );
    7382
    7483        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
     
    7786        /// returns the name of the function being called
    7887        std::string getFunctionName( Expression * expr );
     88        std::string getFunctionName( const ast::Expr * expr );
    7989
    8090        /// returns the argument to a call expression in position N indexed from 0
    8191        Expression *& getCallArg( Expression * callExpr, unsigned int pos );
     92        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos );
    8293
    8394        /// returns the base type of a PointerType or ArrayType, else returns NULL
    8495        Type * getPointerBase( Type * );
     96        const ast::Type* getPointerBase( const ast::Type* );
    8597
    8698        /// returns the argument if it is a PointerType or ArrayType, else returns NULL
     
    91103        bool isConstExpr( Initializer * init );
    92104
    93         class InitExpander {
     105        class InitExpander_old {
    94106        public:
    95107                // expand by stepping through init to get each list of arguments
    96                 InitExpander( Initializer * init );
     108                InitExpander_old( Initializer * init );
    97109
    98110                // always expand to expr
    99                 InitExpander( Expression * expr );
     111                InitExpander_old( Expression * expr );
    100112
    101113                // iterator-like interface
    102114                std::list< Expression * > operator*();
    103                 InitExpander & operator++();
     115                InitExpander_old & operator++();
    104116
    105117                // builds statement which has the same semantics as a C-style list initializer
     
    120132                IndexList indices;
    121133        };
     134
     135        class InitExpander_new {
     136        public:
     137                using IndexList = std::vector< ast::ptr< ast::Expr > >;
     138                class ExpanderImpl;
     139
     140        private:
     141                std::shared_ptr< ExpanderImpl > expander;
     142                std::vector< ast::ptr< ast::Expr > > crnt;
     143                // invariant: list of size 2N (elements come in pairs [index, dimension])
     144                IndexList indices;
     145
     146        public:
     147                /// Expand by stepping through init to get each list of arguments
     148                InitExpander_new( const ast::Init * init );
     149
     150                /// Always expand to expression
     151                InitExpander_new( const ast::Expr * expr );
     152
     153                std::vector< ast::ptr< ast::Expr > > operator* ();
     154                InitExpander_new & operator++ ();
     155
     156                /// builds statement which has the same semantics as a C-style list initializer (for array
     157                /// initializers) using callExpr as the base expression to perform initialization.
     158                /// Mutates callExpr
     159                ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr );
     160
     161                void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
     162
     163                void clearArrayIndices();
     164
     165                bool addReference();
     166        };
    122167} // namespace
    123168
Note: See TracChangeset for help on using the changeset viewer.