source: src/InitTweak/InitTweak.h @ cbce272

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since cbce272 was 6b0b624, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

change #ifndef to #pragma once

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