source: src/InitTweak/InitTweak.h @ 39f84a4

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 39f84a4 was 39f84a4, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

part-way through reorganizing ctor call generation so that it is more general

  • Property mode set to 100644
File size: 3.2 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        /// transform Initializer into an argument list that can be passed to a call expression
29        std::list< Expression * > makeInitList( Initializer * init );
30
31        /// True if the resolver should try to construct objDecl
32        bool tryConstruct( ObjectDecl * objDecl );
33
34        /// True if the Initializer contains designations
35        bool isDesignated( Initializer * init );
36
37  /// Non-Null if expr is a call expression whose target function is intrinsic
38  ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
39
40        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
41        /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
42        /// Currently has assertions that make it less than fully general.
43        bool isInstrinsicSingleArgCallStmt( Statement * expr );
44
45        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
46        Expression * getCtorDtorCall( Statement * stmt );
47
48        /// returns the name of the function being called
49        std::string getFunctionName( Expression * expr );
50
51        /// returns the argument to a call expression in position N indexed from 0
52        Expression *& getCallArg( Expression * callExpr, unsigned int pos );
53
54        /// returns the base type of a PointerType or ArrayType, else returns NULL
55        Type * getPointerBase( Type * );
56
57        /// returns the argument if it is a PointerType or ArrayType, else returns NULL
58        Type * isPointerType( Type * );
59
60        /// returns true if expr is trivially a compile-time constant
61        bool isConstExpr( Expression * expr );
62        bool isConstExpr( Initializer * init );
63
64        class InitExpander {
65        public:
66                // expand by stepping through init to get each list of arguments
67                InitExpander( Initializer * init );
68
69                // always expand to expr
70                InitExpander( Expression * expr );
71
72                // iterator-like interface
73                std::list< Expression * > operator*();
74                InitExpander & operator++();
75
76                // builds statement which has the same semantics as a C-style list initializer
77                // (for array initializers) using callExpr as the base expression to perform initialization
78                Statement * buildListInit( UntypedExpr * callExpr );
79                void addArrayIndex( Expression * index, Expression * dimension );
80
81                class ExpanderImpl;
82        private:
83                std::shared_ptr< ExpanderImpl > expander;
84                std::list< Expression * > cur;
85
86                // invariant: list of size 2N (elements come in pairs [index, dimension])
87                typedef std::list< Expression * > IndexList;
88                IndexList indices;
89        };
90} // namespace
91
92#endif // INITTWEAK_GENINIT_H
93
94// Local Variables: //
95// tab-width: 4 //
96// mode: c++ //
97// compile-command: "make install" //
98// End: //
Note: See TracBrowser for help on using the repository browser.