source: src/InitTweak/InitTweak.h @ 37b7d95

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 37b7d95 was 490fb92e, checked in by Fangren Yu <f37yu@…>, 4 years ago

move FixInit? to new ast

  • Property mode set to 100644
File size: 6.7 KB
Line 
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// InitTweak.h --
8//
9// Author           : Rob Schluntz
10// Created On       : Fri May 13 11:26:36 2016
11// Last Modified By : Andrew Beach
12// Last Modified On : Fri Jul 19 14:18:00 2019
13// Update Count     : 6
14//
15
16#pragma once
17
18#include <list>               // for list
19#include <memory>             // for shared_ptr
20#include <string>             // for string, allocator
21#include <vector>
22
23#include "AST/Fwd.hpp"        // for AST nodes
24#include "SynTree/SynTree.h"  // for Visitor Nodes
25
26// helper functions for initialization
27namespace InitTweak {
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 );
34
35        /// returns the base type of the first parameter to a constructor/destructor/assignment function
36        Type * getTypeofThis( FunctionType * ftype );
37
38        /// returns the first parameter of a constructor/destructor/assignment function
39        ObjectDecl * getParamThis( FunctionType * ftype );
40        const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);
41
42        /// generate a bitwise assignment operation.
43        ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src );
44
45        ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src);
46
47        /// transform Initializer into an argument list that can be passed to a call expression
48        std::list< Expression * > makeInitList( Initializer * init );
49        std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
50
51        /// True if the resolver should try to construct dwt
52        bool tryConstruct( DeclarationWithType * dwt );
53        bool tryConstruct( const ast::DeclWithType * dwt );
54
55        /// True if the type can have a user-defined constructor
56        bool isConstructable( Type * t );
57        bool isConstructable( const ast::Type * t );
58
59        /// True if the Initializer contains designations
60        bool isDesignated( Initializer * init );
61
62        /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its
63        /// type, where the depth of its type is the number of nested ArrayTypes + 1
64        bool checkInitDepth( ObjectDecl * objDecl );
65
66        /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
67        DeclarationWithType * getFunction( Expression * expr );
68        const DeclarationWithType * getFunction( const Expression * expr );
69        const ast::DeclWithType * getFunction( const ast::Expr * expr );
70
71        /// Non-Null if expr is a call expression whose target function is intrinsic
72        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
73        const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);
74
75        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
76        /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
77        /// Currently has assertions that make it less than fully general.
78        bool isIntrinsicSingleArgCallStmt( Statement * stmt );
79        bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
80
81        /// True if stmt is a call statement where the function called is intrinsic.
82        bool isIntrinsicCallStmt( Statement * stmt );
83
84        /// get all Ctor/Dtor call expressions from a Statement
85        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
86        std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt );
87
88        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
89        Expression * getCtorDtorCall( Statement * stmt );
90
91        /// returns the name of the function being called
92        std::string getFunctionName( Expression * expr );
93        std::string getFunctionName( const ast::Expr * expr );
94
95        /// returns the argument to a call expression in position N indexed from 0
96        Expression *& getCallArg( Expression * callExpr, unsigned int pos );
97        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos );
98
99        /// returns the base type of a PointerType or ArrayType, else returns NULL
100        Type * getPointerBase( Type * );
101        const ast::Type* getPointerBase( const ast::Type* );
102
103        /// returns the argument if it is a PointerType or ArrayType, else returns NULL
104        Type * isPointerType( Type * );
105
106        /// returns true if expr is trivially a compile-time constant
107        bool isConstExpr( Expression * expr );
108        bool isConstExpr( Initializer * init );
109
110        class InitExpander_old {
111        public:
112                // expand by stepping through init to get each list of arguments
113                InitExpander_old( Initializer * init );
114
115                // always expand to expr
116                InitExpander_old( Expression * expr );
117
118                // iterator-like interface
119                std::list< Expression * > operator*();
120                InitExpander_old & operator++();
121
122                // builds statement which has the same semantics as a C-style list initializer
123                // (for array initializers) using callExpr as the base expression to perform initialization
124                Statement * buildListInit( UntypedExpr * callExpr );
125                void addArrayIndex( Expression * index, Expression * dimension );
126                void clearArrayIndices();
127                bool addReference();
128
129                class ExpanderImpl;
130
131                typedef std::list< Expression * > IndexList;
132        private:
133                std::shared_ptr< ExpanderImpl > expander;
134                std::list< Expression * > cur;
135
136                // invariant: list of size 2N (elements come in pairs [index, dimension])
137                IndexList indices;
138        };
139
140        class InitExpander_new {
141        public:
142                using IndexList = std::vector< ast::ptr< ast::Expr > >;
143                class ExpanderImpl;
144
145        private:
146                std::shared_ptr< ExpanderImpl > expander;
147                std::vector< ast::ptr< ast::Expr > > crnt;
148                // invariant: list of size 2N (elements come in pairs [index, dimension])
149                IndexList indices;
150
151        public:
152                /// Expand by stepping through init to get each list of arguments
153                InitExpander_new( const ast::Init * init );
154
155                /// Always expand to expression
156                InitExpander_new( const ast::Expr * expr );
157
158                std::vector< ast::ptr< ast::Expr > > operator* ();
159                InitExpander_new & operator++ ();
160
161                /// builds statement which has the same semantics as a C-style list initializer (for array
162                /// initializers) using callExpr as the base expression to perform initialization.
163                /// Mutates callExpr
164                ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr );
165
166                void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
167
168                void clearArrayIndices();
169
170                bool addReference();
171        };
172} // namespace
173
174// Local Variables: //
175// tab-width: 4 //
176// mode: c++ //
177// compile-command: "make install" //
178// End: //
Note: See TracBrowser for help on using the repository browser.