| [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 | //
|
|---|
| [2d11663] | 7 | // InitTweak.h --
|
|---|
| [2b46a13] | 8 | //
|
|---|
| 9 | // Author : Rob Schluntz
|
|---|
| 10 | // Created On : Fri May 13 11:26:36 2016
|
|---|
| [335d81f] | 11 | // Last Modified By : Andrew Beach
|
|---|
| [e01eb4a] | 12 | // Last Modified On : Wed Sep 22 9:21:00 2022
|
|---|
| 13 | // Update Count : 9
|
|---|
| [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
|
|---|
| [2d11663] | 21 | #include <vector>
|
|---|
| [2b46a13] | 22 |
|
|---|
| [9e1d485] | 23 | #include "AST/Fwd.hpp" // for AST nodes
|
|---|
| [2b46a13] | 24 |
|
|---|
| 25 | // helper functions for initialization
|
|---|
| 26 | namespace InitTweak {
|
|---|
| [00a8e19] | 27 | bool isAssignment( const ast::FunctionDecl * decl );
|
|---|
| 28 | bool isDestructor( const ast::FunctionDecl * decl );
|
|---|
| 29 | bool isDefaultConstructor( const ast::FunctionDecl * decl );
|
|---|
| 30 | bool isCopyConstructor( const ast::FunctionDecl * decl );
|
|---|
| [d76c588] | 31 | bool isCopyFunction( const ast::FunctionDecl * decl );
|
|---|
| [4d4882a] | 32 |
|
|---|
| [7fc7cdb] | 33 | /// returns the base type of the first parameter to a constructor/destructor/assignment function
|
|---|
| [3cc1111] | 34 | const ast::Type * getTypeofThis( const ast::FunctionType * ftype );
|
|---|
| [7fc7cdb] | 35 |
|
|---|
| 36 | /// returns the first parameter of a constructor/destructor/assignment function
|
|---|
| [490fb92e] | 37 | const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);
|
|---|
| [7fc7cdb] | 38 |
|
|---|
| [f5c3b6c] | 39 | /// generate a bitwise assignment operation.
|
|---|
| [490fb92e] | 40 | ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src);
|
|---|
| 41 |
|
|---|
| [b81adcc4] | 42 | /// transform Initializer into an argument list that can be passed to a call expression
|
|---|
| [b8524ca] | 43 | std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
|
|---|
| [2b46a13] | 44 |
|
|---|
| [22bc276] | 45 | /// True if the resolver should try to construct dwt
|
|---|
| [490fb92e] | 46 | bool tryConstruct( const ast::DeclWithType * dwt );
|
|---|
| [2b46a13] | 47 |
|
|---|
| [29bc63e] | 48 | /// True if the type can have a user-defined constructor
|
|---|
| [490fb92e] | 49 | bool isConstructable( const ast::Type * t );
|
|---|
| [29bc63e] | 50 |
|
|---|
| [b81adcc4] | 51 | /// True if the Initializer contains designations
|
|---|
| [16ba4a6f] | 52 | bool isDesignated( const ast::Init * init );
|
|---|
| [2b46a13] | 53 |
|
|---|
| [dcd73d1] | 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
|
|---|
| [16ba4a6f] | 56 | bool checkInitDepth( const ast::ObjectDecl * objDecl );
|
|---|
| [dcd73d1] | 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.
|
|---|
| [2d11663] | 61 | bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
|
|---|
| [a465caff] | 62 |
|
|---|
| [4d2434a] | 63 | /// get all Ctor/Dtor call expressions from a Statement
|
|---|
| [490fb92e] | 64 | std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt );
|
|---|
| [4d2434a] | 65 |
|
|---|
| [b81adcc4] | 66 | /// returns true if expr is trivially a compile-time constant
|
|---|
| [16ba4a6f] | 67 | bool isConstExpr( const ast::Expr * expr );
|
|---|
| 68 | bool isConstExpr( const ast::Init * init );
|
|---|
| 69 |
|
|---|
| [f1791a4] | 70 | /// Modifies objDecl to have:
|
|---|
| 71 | /// __attribute__((section (".data#")))
|
|---|
| 72 | /// which makes gcc put the declared variable in the data section,
|
|---|
| 73 | /// which is helpful for global constants on newer gcc versions,
|
|---|
| 74 | /// so that CFA's generated initialization won't segfault when writing it via a const cast.
|
|---|
| 75 | /// The trailing # is an injected assembly comment, to suppress the "a" in
|
|---|
| 76 | /// .section .data,"a"
|
|---|
| 77 | /// .section .data#,"a"
|
|---|
| 78 | /// to avoid assembler warning "ignoring changed section attributes for .data"
|
|---|
| [7d651a66] | 79 | void addDataSectionAttribute( ast::ObjectDecl * objDecl );
|
|---|
| 80 |
|
|---|
| [0bd3faf] | 81 | class InitExpander final {
|
|---|
| [b8524ca] | 82 | public:
|
|---|
| 83 | using IndexList = std::vector< ast::ptr< ast::Expr > >;
|
|---|
| 84 | class ExpanderImpl;
|
|---|
| 85 |
|
|---|
| 86 | private:
|
|---|
| 87 | std::shared_ptr< ExpanderImpl > expander;
|
|---|
| 88 | std::vector< ast::ptr< ast::Expr > > crnt;
|
|---|
| 89 | // invariant: list of size 2N (elements come in pairs [index, dimension])
|
|---|
| 90 | IndexList indices;
|
|---|
| 91 |
|
|---|
| 92 | public:
|
|---|
| 93 | /// Expand by stepping through init to get each list of arguments
|
|---|
| [0bd3faf] | 94 | InitExpander( const ast::Init * init );
|
|---|
| [b8524ca] | 95 |
|
|---|
| 96 | /// Always expand to expression
|
|---|
| [0bd3faf] | 97 | InitExpander( const ast::Expr * expr );
|
|---|
| [b8524ca] | 98 |
|
|---|
| 99 | std::vector< ast::ptr< ast::Expr > > operator* ();
|
|---|
| [0bd3faf] | 100 | InitExpander & operator++ ();
|
|---|
| [b8524ca] | 101 |
|
|---|
| [6f096d2] | 102 | /// builds statement which has the same semantics as a C-style list initializer (for array
|
|---|
| 103 | /// initializers) using callExpr as the base expression to perform initialization.
|
|---|
| [c1ed2ee] | 104 | /// Mutates callExpr
|
|---|
| 105 | ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr );
|
|---|
| [b8524ca] | 106 |
|
|---|
| 107 | void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
|
|---|
| 108 |
|
|---|
| 109 | void clearArrayIndices();
|
|---|
| 110 |
|
|---|
| 111 | bool addReference();
|
|---|
| 112 | };
|
|---|
| [0bd3faf] | 113 | } // namespace InitTweak
|
|---|
| [2b46a13] | 114 |
|
|---|
| 115 | // Local Variables: //
|
|---|
| 116 | // tab-width: 4 //
|
|---|
| 117 | // mode: c++ //
|
|---|
| 118 | // compile-command: "make install" //
|
|---|
| 119 | // End: //
|
|---|