source: src/InitTweak/InitTweak.h @ dcfc4b35

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since dcfc4b35 was 549c006, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Implemented out of order waitfor for destructors

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