source: src/InitTweak/InitTweak.h @ b7b8674

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since b7b8674 was b7b8674, checked in by Rob Schluntz <rschlunt@…>, 5 years ago

make Tuples::maybeImpure slightly more precise

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