source: src/InitTweak/InitTweak.h @ b7fe2e6

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since b7fe2e6 was 335d81f, checked in by Andrew Beach <ajbeach@…>, 5 years ago

getFunction has const version and maybeImpure[IgnoreUnique?] have const input.

  • Property mode set to 100644
File size: 6.4 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
41        /// generate a bitwise assignment operation.
42        ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src );
43
44        /// transform Initializer into an argument list that can be passed to a call expression
45        std::list< Expression * > makeInitList( Initializer * init );
46        std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
47
48        /// True if the resolver should try to construct dwt
49        bool tryConstruct( DeclarationWithType * dwt );
50
51        /// True if the type can have a user-defined constructor
52        bool isConstructable( Type * t );
53
54        /// True if the Initializer contains designations
55        bool isDesignated( Initializer * init );
56
57        /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its
58        /// type, where the depth of its type is the number of nested ArrayTypes + 1
59        bool checkInitDepth( ObjectDecl * objDecl );
60
61        /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
62        DeclarationWithType * getFunction( Expression * expr );
63        const DeclarationWithType * getFunction( const Expression * expr );
64        const ast::DeclWithType * getFunction( const ast::Expr * expr );
65
66        /// Non-Null if expr is a call expression whose target function is intrinsic
67        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
68        const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);
69
70        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
71        /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
72        /// Currently has assertions that make it less than fully general.
73        bool isIntrinsicSingleArgCallStmt( Statement * stmt );
74        bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
75
76        /// True if stmt is a call statement where the function called is intrinsic.
77        bool isIntrinsicCallStmt( Statement * stmt );
78
79        /// get all Ctor/Dtor call expressions from a Statement
80        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
81        std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt );
82
83        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
84        Expression * getCtorDtorCall( Statement * stmt );
85
86        /// returns the name of the function being called
87        std::string getFunctionName( Expression * expr );
88        std::string getFunctionName( const ast::Expr * expr );
89
90        /// returns the argument to a call expression in position N indexed from 0
91        Expression *& getCallArg( Expression * callExpr, unsigned int pos );
92        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos );
93
94        /// returns the base type of a PointerType or ArrayType, else returns NULL
95        Type * getPointerBase( Type * );
96        const ast::Type* getPointerBase( const ast::Type* );
97
98        /// returns the argument if it is a PointerType or ArrayType, else returns NULL
99        Type * isPointerType( Type * );
100
101        /// returns true if expr is trivially a compile-time constant
102        bool isConstExpr( Expression * expr );
103        bool isConstExpr( Initializer * init );
104
105        class InitExpander_old {
106        public:
107                // expand by stepping through init to get each list of arguments
108                InitExpander_old( Initializer * init );
109
110                // always expand to expr
111                InitExpander_old( Expression * expr );
112
113                // iterator-like interface
114                std::list< Expression * > operator*();
115                InitExpander_old & operator++();
116
117                // builds statement which has the same semantics as a C-style list initializer
118                // (for array initializers) using callExpr as the base expression to perform initialization
119                Statement * buildListInit( UntypedExpr * callExpr );
120                void addArrayIndex( Expression * index, Expression * dimension );
121                void clearArrayIndices();
122                bool addReference();
123
124                class ExpanderImpl;
125
126                typedef std::list< Expression * > IndexList;
127        private:
128                std::shared_ptr< ExpanderImpl > expander;
129                std::list< Expression * > cur;
130
131                // invariant: list of size 2N (elements come in pairs [index, dimension])
132                IndexList indices;
133        };
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        };
167} // namespace
168
169// Local Variables: //
170// tab-width: 4 //
171// mode: c++ //
172// compile-command: "make install" //
173// End: //
Note: See TracBrowser for help on using the repository browser.