source: src/InitTweak/InitTweak.h @ 74b007ba

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 74b007ba was 9236060, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Merge branch 'master' into references

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