source: src/InitTweak/InitTweak.h @ c1ed2ee

arm-ehjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since c1ed2ee was c1ed2ee, checked in by Aaron Moss <a3moss@…>, 3 years ago

Continued resolver porting

  • mostly initialization and validation
  • added move() and copy() to utility.h
  • Property mode set to 100644
File size: 6.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// InitTweak.h --
8//
9// Author           : Rob Schluntz
10// Created On       : Fri May 13 11:26:36 2016
11// Last Modified By : Aaron B. Moss
12// Last Modified On : Mon Jun 10 13:30:00 2019
13// Update Count     : 5
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        FunctionDecl * isAssignment( Declaration * decl );
29        FunctionDecl * isDestructor( Declaration * decl );
30        FunctionDecl * isDefaultConstructor( Declaration * decl );
31        FunctionDecl * isCopyConstructor( Declaration * decl );
32        FunctionDecl * isCopyFunction( 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 ast::DeclWithType * getFunction( const ast::Expr * expr );
64
65        /// Non-Null if expr is a call expression whose target function is intrinsic
66        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
67        const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr);
68
69        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
70        /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
71        /// Currently has assertions that make it less than fully general.
72        bool isIntrinsicSingleArgCallStmt( Statement * stmt );
73        bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
74
75        /// True if stmt is a call statement where the function called is intrinsic.
76        bool isIntrinsicCallStmt( Statement * stmt );
77
78        /// get all Ctor/Dtor call expressions from a Statement
79        void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
80        std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt );
81
82        /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
83        Expression * getCtorDtorCall( Statement * stmt );
84
85        /// returns the name of the function being called
86        std::string getFunctionName( Expression * expr );
87        std::string getFunctionName( const ast::Expr * expr );
88
89        /// returns the argument to a call expression in position N indexed from 0
90        Expression *& getCallArg( Expression * callExpr, unsigned int pos );
91        const ast::Expr * getCallArg( const ast::Expr * call, unsigned pos );
92
93        /// returns the base type of a PointerType or ArrayType, else returns NULL
94        Type * getPointerBase( Type * );
95        const ast::Type* getPointerBase( const ast::Type* );
96
97        /// returns the argument if it is a PointerType or ArrayType, else returns NULL
98        Type * isPointerType( Type * );
99
100        /// returns true if expr is trivially a compile-time constant
101        bool isConstExpr( Expression * expr );
102        bool isConstExpr( Initializer * init );
103
104        class InitExpander_old {
105        public:
106                // expand by stepping through init to get each list of arguments
107                InitExpander_old( Initializer * init );
108
109                // always expand to expr
110                InitExpander_old( Expression * expr );
111
112                // iterator-like interface
113                std::list< Expression * > operator*();
114                InitExpander_old & operator++();
115
116                // builds statement which has the same semantics as a C-style list initializer
117                // (for array initializers) using callExpr as the base expression to perform initialization
118                Statement * buildListInit( UntypedExpr * callExpr );
119                void addArrayIndex( Expression * index, Expression * dimension );
120                void clearArrayIndices();
121                bool addReference();
122
123                class ExpanderImpl;
124
125                typedef std::list< Expression * > IndexList;
126        private:
127                std::shared_ptr< ExpanderImpl > expander;
128                std::list< Expression * > cur;
129
130                // invariant: list of size 2N (elements come in pairs [index, dimension])
131                IndexList indices;
132        };
133
134        class InitExpander_new {
135        public:
136                using IndexList = std::vector< ast::ptr< ast::Expr > >;
137                class ExpanderImpl;
138
139        private:
140                std::shared_ptr< ExpanderImpl > expander;
141                std::vector< ast::ptr< ast::Expr > > crnt;
142                // invariant: list of size 2N (elements come in pairs [index, dimension])
143                IndexList indices;
144
145        public:
146                /// Expand by stepping through init to get each list of arguments
147                InitExpander_new( const ast::Init * init );
148
149                /// Always expand to expression
150                InitExpander_new( const ast::Expr * expr );
151
152                std::vector< ast::ptr< ast::Expr > > operator* ();
153                InitExpander_new & operator++ ();
154
155                /// builds statement which has the same semantics as a C-style list initializer (for array
156                /// initializers) using callExpr as the base expression to perform initialization.
157                /// Mutates callExpr
158                ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr );
159
160                void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
161
162                void clearArrayIndices();
163
164                bool addReference();
165        };
166} // namespace
167
168// Local Variables: //
169// tab-width: 4 //
170// mode: c++ //
171// compile-command: "make install" //
172// End: //
Note: See TracBrowser for help on using the repository browser.