[2b46a13] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // RemoveInit.h -- |
---|
| 8 | // |
---|
| 9 | // Author : Rob Schluntz |
---|
| 10 | // Created On : Fri May 13 11:26:36 2016 |
---|
| 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Fri May 13 11:35:36 2016 |
---|
| 13 | // Update Count : 3 |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #ifndef INIT_TWEAK_H |
---|
| 17 | #define INIT_TWEAK_H |
---|
| 18 | |
---|
| 19 | #include <string> |
---|
| 20 | #include <list> |
---|
| 21 | |
---|
| 22 | #include "SynTree/SynTree.h" |
---|
| 23 | #include "SynTree/Declaration.h" |
---|
| 24 | #include "SynTree/Mutator.h" |
---|
| 25 | |
---|
| 26 | // helper functions for initialization |
---|
| 27 | namespace InitTweak { |
---|
[79970ed] | 28 | bool isConstructor( const std::string & ); |
---|
| 29 | bool isDestructor( const std::string & ); |
---|
| 30 | bool isCtorDtor( const std::string & ); |
---|
| 31 | |
---|
[b81adcc4] | 32 | /// transform Initializer into an argument list that can be passed to a call expression |
---|
| 33 | std::list< Expression * > makeInitList( Initializer * init ); |
---|
[2b46a13] | 34 | |
---|
[b81adcc4] | 35 | /// True if the resolver should try to construct objDecl |
---|
| 36 | bool tryConstruct( ObjectDecl * objDecl ); |
---|
[2b46a13] | 37 | |
---|
[b81adcc4] | 38 | /// True if the Initializer contains designations |
---|
| 39 | bool isDesignated( Initializer * init ); |
---|
[2b46a13] | 40 | |
---|
[aedfd91] | 41 | /// Non-Null if expr is a call expression whose target function is intrinsic |
---|
| 42 | ApplicationExpr * isIntrinsicCallExpr( Expression * expr ); |
---|
| 43 | |
---|
[b81adcc4] | 44 | /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. |
---|
| 45 | /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. |
---|
| 46 | /// Currently has assertions that make it less than fully general. |
---|
[a465caf] | 47 | bool isIntrinsicSingleArgCallStmt( Statement * stmt ); |
---|
| 48 | |
---|
| 49 | /// True if stmt is a call statement where the function called is intrinsic. |
---|
| 50 | bool isIntrinsicCallStmt( Statement * stmt ); |
---|
[70f89d00] | 51 | |
---|
[4d2434a] | 52 | /// get all Ctor/Dtor call expressions from a Statement |
---|
| 53 | void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ); |
---|
| 54 | |
---|
[b81adcc4] | 55 | /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call |
---|
| 56 | Expression * getCtorDtorCall( Statement * stmt ); |
---|
[f1b1e4c] | 57 | |
---|
[b81adcc4] | 58 | /// returns the name of the function being called |
---|
| 59 | std::string getFunctionName( Expression * expr ); |
---|
[f1b1e4c] | 60 | |
---|
[b81adcc4] | 61 | /// returns the argument to a call expression in position N indexed from 0 |
---|
| 62 | Expression *& getCallArg( Expression * callExpr, unsigned int pos ); |
---|
[10a7775] | 63 | |
---|
[b81adcc4] | 64 | /// returns the base type of a PointerType or ArrayType, else returns NULL |
---|
| 65 | Type * getPointerBase( Type * ); |
---|
[64071c2] | 66 | |
---|
[b81adcc4] | 67 | /// returns the argument if it is a PointerType or ArrayType, else returns NULL |
---|
| 68 | Type * isPointerType( Type * ); |
---|
[5f98ce5] | 69 | |
---|
[b81adcc4] | 70 | /// returns true if expr is trivially a compile-time constant |
---|
| 71 | bool isConstExpr( Expression * expr ); |
---|
| 72 | bool isConstExpr( Initializer * init ); |
---|
[39f84a4] | 73 | |
---|
| 74 | class InitExpander { |
---|
| 75 | public: |
---|
| 76 | // expand by stepping through init to get each list of arguments |
---|
| 77 | InitExpander( Initializer * init ); |
---|
| 78 | |
---|
| 79 | // always expand to expr |
---|
| 80 | InitExpander( Expression * expr ); |
---|
| 81 | |
---|
| 82 | // iterator-like interface |
---|
| 83 | std::list< Expression * > operator*(); |
---|
| 84 | InitExpander & operator++(); |
---|
| 85 | |
---|
| 86 | // builds statement which has the same semantics as a C-style list initializer |
---|
| 87 | // (for array initializers) using callExpr as the base expression to perform initialization |
---|
| 88 | Statement * buildListInit( UntypedExpr * callExpr ); |
---|
| 89 | void addArrayIndex( Expression * index, Expression * dimension ); |
---|
[4d2434a] | 90 | void clearArrayIndices(); |
---|
[39f84a4] | 91 | |
---|
| 92 | class ExpanderImpl; |
---|
| 93 | private: |
---|
| 94 | std::shared_ptr< ExpanderImpl > expander; |
---|
| 95 | std::list< Expression * > cur; |
---|
| 96 | |
---|
| 97 | // invariant: list of size 2N (elements come in pairs [index, dimension]) |
---|
| 98 | typedef std::list< Expression * > IndexList; |
---|
| 99 | IndexList indices; |
---|
| 100 | }; |
---|
[2b46a13] | 101 | } // namespace |
---|
| 102 | |
---|
| 103 | #endif // INITTWEAK_GENINIT_H |
---|
| 104 | |
---|
| 105 | // Local Variables: // |
---|
| 106 | // tab-width: 4 // |
---|
| 107 | // mode: c++ // |
---|
| 108 | // compile-command: "make install" // |
---|
| 109 | // End: // |
---|