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 { |
---|
28 | bool isConstructor( const std::string & ); |
---|
29 | bool isDestructor( const std::string & ); |
---|
30 | bool isAssignment( const std::string & ); |
---|
31 | bool isCtorDtor( const std::string & ); |
---|
32 | bool isCtorDtorAssign( const std::string & ); |
---|
33 | |
---|
34 | FunctionDecl * isCopyConstructor( Declaration * decl ); |
---|
35 | FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ); |
---|
36 | |
---|
37 | /// transform Initializer into an argument list that can be passed to a call expression |
---|
38 | std::list< Expression * > makeInitList( Initializer * init ); |
---|
39 | |
---|
40 | /// True if the resolver should try to construct objDecl |
---|
41 | bool tryConstruct( ObjectDecl * objDecl ); |
---|
42 | |
---|
43 | /// True if the Initializer contains designations |
---|
44 | bool isDesignated( Initializer * init ); |
---|
45 | |
---|
46 | /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its |
---|
47 | /// type, where the depth of its type is the number of nested ArrayTypes + 1 |
---|
48 | bool checkInitDepth( ObjectDecl * objDecl ); |
---|
49 | |
---|
50 | /// Non-Null if expr is a call expression whose target function is intrinsic |
---|
51 | ApplicationExpr * isIntrinsicCallExpr( Expression * expr ); |
---|
52 | |
---|
53 | /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. |
---|
54 | /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. |
---|
55 | /// Currently has assertions that make it less than fully general. |
---|
56 | bool isIntrinsicSingleArgCallStmt( Statement * stmt ); |
---|
57 | |
---|
58 | /// True if stmt is a call statement where the function called is intrinsic. |
---|
59 | bool isIntrinsicCallStmt( Statement * stmt ); |
---|
60 | |
---|
61 | /// get all Ctor/Dtor call expressions from a Statement |
---|
62 | void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ); |
---|
63 | |
---|
64 | /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call |
---|
65 | Expression * getCtorDtorCall( Statement * stmt ); |
---|
66 | |
---|
67 | /// returns the name of the function being called |
---|
68 | std::string getFunctionName( Expression * expr ); |
---|
69 | |
---|
70 | /// returns the argument to a call expression in position N indexed from 0 |
---|
71 | Expression *& getCallArg( Expression * callExpr, unsigned int pos ); |
---|
72 | |
---|
73 | /// returns the base type of a PointerType or ArrayType, else returns NULL |
---|
74 | Type * getPointerBase( Type * ); |
---|
75 | |
---|
76 | /// returns the argument if it is a PointerType or ArrayType, else returns NULL |
---|
77 | Type * isPointerType( Type * ); |
---|
78 | |
---|
79 | /// returns true if expr is trivially a compile-time constant |
---|
80 | bool isConstExpr( Expression * expr ); |
---|
81 | bool isConstExpr( Initializer * init ); |
---|
82 | |
---|
83 | class InitExpander { |
---|
84 | public: |
---|
85 | // expand by stepping through init to get each list of arguments |
---|
86 | InitExpander( Initializer * init ); |
---|
87 | |
---|
88 | // always expand to expr |
---|
89 | InitExpander( Expression * expr ); |
---|
90 | |
---|
91 | // iterator-like interface |
---|
92 | std::list< Expression * > operator*(); |
---|
93 | InitExpander & operator++(); |
---|
94 | |
---|
95 | // builds statement which has the same semantics as a C-style list initializer |
---|
96 | // (for array initializers) using callExpr as the base expression to perform initialization |
---|
97 | Statement * buildListInit( UntypedExpr * callExpr ); |
---|
98 | void addArrayIndex( Expression * index, Expression * dimension ); |
---|
99 | void clearArrayIndices(); |
---|
100 | |
---|
101 | class ExpanderImpl; |
---|
102 | private: |
---|
103 | std::shared_ptr< ExpanderImpl > expander; |
---|
104 | std::list< Expression * > cur; |
---|
105 | |
---|
106 | // invariant: list of size 2N (elements come in pairs [index, dimension]) |
---|
107 | typedef std::list< Expression * > IndexList; |
---|
108 | IndexList indices; |
---|
109 | }; |
---|
110 | } // namespace |
---|
111 | |
---|
112 | #endif // INITTWEAK_GENINIT_H |
---|
113 | |
---|
114 | // Local Variables: // |
---|
115 | // tab-width: 4 // |
---|
116 | // mode: c++ // |
---|
117 | // compile-command: "make install" // |
---|
118 | // End: // |
---|