source: src/InitTweak/InitTweak.h @ 0a75b77

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 0a75b77 was f5c3b6c, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Use fake bitwise-assignment function when generating copy constructor calls.

This is change prevents assignment calls from being resolved incorrectly, but is an imperfect fix. Ideally this function could exist somewhere as a real function that the resolver never chooses.

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