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