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 : Peter A. Buhr
|
---|
12 | // Last Modified On : Sat Jul 22 09:30:33 2017
|
---|
13 | // Update Count : 4
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include <list> // for list
|
---|
19 | #include <memory> // for shared_ptr
|
---|
20 | #include <string> // for string, allocator
|
---|
21 |
|
---|
22 | #include "SynTree/SynTree.h" // for Visitor Nodes
|
---|
23 |
|
---|
24 | // helper functions for initialization
|
---|
25 | namespace 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 );
|
---|
31 |
|
---|
32 | /// transform Initializer into an argument list that can be passed to a call expression
|
---|
33 | std::list< Expression * > makeInitList( Initializer * init );
|
---|
34 |
|
---|
35 | /// True if the resolver should try to construct objDecl
|
---|
36 | bool tryConstruct( ObjectDecl * objDecl );
|
---|
37 |
|
---|
38 | /// True if the Initializer contains designations
|
---|
39 | bool isDesignated( Initializer * init );
|
---|
40 |
|
---|
41 | /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its
|
---|
42 | /// type, where the depth of its type is the number of nested ArrayTypes + 1
|
---|
43 | bool checkInitDepth( ObjectDecl * objDecl );
|
---|
44 |
|
---|
45 | /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
|
---|
46 | DeclarationWithType * getFunction( Expression * expr );
|
---|
47 |
|
---|
48 | /// Non-Null if expr is a call expression whose target function is intrinsic
|
---|
49 | ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
|
---|
50 |
|
---|
51 | /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
|
---|
52 | /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
|
---|
53 | /// Currently has assertions that make it less than fully general.
|
---|
54 | bool isIntrinsicSingleArgCallStmt( Statement * stmt );
|
---|
55 |
|
---|
56 | /// True if stmt is a call statement where the function called is intrinsic.
|
---|
57 | bool isIntrinsicCallStmt( Statement * stmt );
|
---|
58 |
|
---|
59 | /// get all Ctor/Dtor call expressions from a Statement
|
---|
60 | void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
|
---|
61 |
|
---|
62 | /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
|
---|
63 | Expression * getCtorDtorCall( Statement * stmt );
|
---|
64 |
|
---|
65 | /// returns the name of the function being called
|
---|
66 | std::string getFunctionName( Expression * expr );
|
---|
67 |
|
---|
68 | /// returns the argument to a call expression in position N indexed from 0
|
---|
69 | Expression *& getCallArg( Expression * callExpr, unsigned int pos );
|
---|
70 |
|
---|
71 | /// returns the base type of a PointerType or ArrayType, else returns NULL
|
---|
72 | Type * getPointerBase( Type * );
|
---|
73 |
|
---|
74 | /// returns the argument if it is a PointerType or ArrayType, else returns NULL
|
---|
75 | Type * isPointerType( Type * );
|
---|
76 |
|
---|
77 | /// returns true if expr is trivially a compile-time constant
|
---|
78 | bool isConstExpr( Expression * expr );
|
---|
79 | bool isConstExpr( Initializer * init );
|
---|
80 |
|
---|
81 | class InitExpander {
|
---|
82 | public:
|
---|
83 | // expand by stepping through init to get each list of arguments
|
---|
84 | InitExpander( Initializer * init );
|
---|
85 |
|
---|
86 | // always expand to expr
|
---|
87 | InitExpander( Expression * expr );
|
---|
88 |
|
---|
89 | // iterator-like interface
|
---|
90 | std::list< Expression * > operator*();
|
---|
91 | InitExpander & operator++();
|
---|
92 |
|
---|
93 | // builds statement which has the same semantics as a C-style list initializer
|
---|
94 | // (for array initializers) using callExpr as the base expression to perform initialization
|
---|
95 | Statement * buildListInit( UntypedExpr * callExpr );
|
---|
96 | void addArrayIndex( Expression * index, Expression * dimension );
|
---|
97 | void clearArrayIndices();
|
---|
98 |
|
---|
99 | class ExpanderImpl;
|
---|
100 |
|
---|
101 | typedef std::list< Expression * > IndexList;
|
---|
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 | IndexList indices;
|
---|
108 | };
|
---|
109 | } // namespace
|
---|
110 |
|
---|
111 | // Local Variables: //
|
---|
112 | // tab-width: 4 //
|
---|
113 | // mode: c++ //
|
---|
114 | // compile-command: "make install" //
|
---|
115 | // End: //
|
---|