[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
|
---|
| 26 | namespace InitTweak {
|
---|
[79970ed] | 27 | bool isConstructor( const std::string & );
|
---|
| 28 | bool isDestructor( const std::string & );
|
---|
[ee1635c8] | 29 | bool isAssignment( const std::string & );
|
---|
[79970ed] | 30 | bool isCtorDtor( const std::string & );
|
---|
[ee1635c8] | 31 | bool isCtorDtorAssign( const std::string & );
|
---|
[79970ed] | 32 |
|
---|
[207c7e1d] | 33 | FunctionDecl * isAssignment( Declaration * decl );
|
---|
| 34 | FunctionDecl * isDestructor( Declaration * decl );
|
---|
| 35 | FunctionDecl * isDefaultConstructor( Declaration * decl );
|
---|
[4d4882a] | 36 | FunctionDecl * isCopyConstructor( Declaration * decl );
|
---|
[ee1635c8] | 37 | FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
|
---|
[4d4882a] | 38 |
|
---|
[b81adcc4] | 39 | /// transform Initializer into an argument list that can be passed to a call expression
|
---|
| 40 | std::list< Expression * > makeInitList( Initializer * init );
|
---|
[2b46a13] | 41 |
|
---|
[b81adcc4] | 42 | /// True if the resolver should try to construct objDecl
|
---|
| 43 | bool tryConstruct( ObjectDecl * objDecl );
|
---|
[2b46a13] | 44 |
|
---|
[b81adcc4] | 45 | /// True if the Initializer contains designations
|
---|
| 46 | bool isDesignated( Initializer * init );
|
---|
[2b46a13] | 47 |
|
---|
[dcd73d1] | 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 |
|
---|
[b7b8674] | 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 );
|
---|
[aedfd91] | 57 |
|
---|
[b81adcc4] | 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.
|
---|
[a465caff] | 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 );
|
---|
[70f89d00] | 65 |
|
---|
[4d2434a] | 66 | /// get all Ctor/Dtor call expressions from a Statement
|
---|
| 67 | void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
|
---|
| 68 |
|
---|
[b81adcc4] | 69 | /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
|
---|
| 70 | Expression * getCtorDtorCall( Statement * stmt );
|
---|
[f1b1e4c] | 71 |
|
---|
[b81adcc4] | 72 | /// returns the name of the function being called
|
---|
| 73 | std::string getFunctionName( Expression * expr );
|
---|
[f1b1e4c] | 74 |
|
---|
[b81adcc4] | 75 | /// returns the argument to a call expression in position N indexed from 0
|
---|
| 76 | Expression *& getCallArg( Expression * callExpr, unsigned int pos );
|
---|
[10a7775] | 77 |
|
---|
[b81adcc4] | 78 | /// returns the base type of a PointerType or ArrayType, else returns NULL
|
---|
| 79 | Type * getPointerBase( Type * );
|
---|
[64071c2] | 80 |
|
---|
[b81adcc4] | 81 | /// returns the argument if it is a PointerType or ArrayType, else returns NULL
|
---|
| 82 | Type * isPointerType( Type * );
|
---|
[5f98ce5] | 83 |
|
---|
[b81adcc4] | 84 | /// returns true if expr is trivially a compile-time constant
|
---|
| 85 | bool isConstExpr( Expression * expr );
|
---|
| 86 | bool isConstExpr( Initializer * init );
|
---|
[39f84a4] | 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 );
|
---|
[4d2434a] | 104 | void clearArrayIndices();
|
---|
[39f84a4] | 105 |
|
---|
| 106 | class ExpanderImpl;
|
---|
[62e5546] | 107 | typedef std::list< Expression * > IndexList;
|
---|
[39f84a4] | 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 | };
|
---|
[2b46a13] | 115 | } // namespace
|
---|
| 116 |
|
---|
| 117 | // Local Variables: //
|
---|
| 118 | // tab-width: 4 //
|
---|
| 119 | // mode: c++ //
|
---|
| 120 | // compile-command: "make install" //
|
---|
| 121 | // End: //
|
---|