| [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 | // | 
|---|
| [5f225f5] | 7 | // InitTweak.hpp -- | 
|---|
| [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 { | 
|---|
| [4d4882a] | 27 |  | 
|---|
| [8984003] | 28 | bool isAssignment( const ast::FunctionDecl * decl ); | 
|---|
|  | 29 | bool isDestructor( const ast::FunctionDecl * decl ); | 
|---|
|  | 30 | bool isDefaultConstructor( const ast::FunctionDecl * decl ); | 
|---|
|  | 31 | bool isCopyConstructor( const ast::FunctionDecl * decl ); | 
|---|
|  | 32 | bool isCopyFunction( const ast::FunctionDecl * decl ); | 
|---|
| [7fc7cdb] | 33 |  | 
|---|
| [8984003] | 34 | /// returns the base type of the first parameter to a constructor/destructor/assignment function | 
|---|
|  | 35 | const ast::Type * getTypeofThis( const ast::FunctionType * ftype ); | 
|---|
| [7fc7cdb] | 36 |  | 
|---|
| [8984003] | 37 | /// returns the first parameter of a constructor/destructor/assignment function | 
|---|
|  | 38 | const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func); | 
|---|
| [490fb92e] | 39 |  | 
|---|
| [8984003] | 40 | /// generate a bitwise assignment operation. | 
|---|
|  | 41 | ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src); | 
|---|
| [2b46a13] | 42 |  | 
|---|
| [8984003] | 43 | /// transform Initializer into an argument list that can be passed to a call expression | 
|---|
|  | 44 | std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ); | 
|---|
| [2b46a13] | 45 |  | 
|---|
| [8984003] | 46 | /// True if the resolver should try to construct dwt | 
|---|
|  | 47 | bool tryConstruct( const ast::DeclWithType * dwt ); | 
|---|
| [29bc63e] | 48 |  | 
|---|
| [8984003] | 49 | /// True if the type can have a user-defined constructor | 
|---|
|  | 50 | bool isConstructable( const ast::Type * t ); | 
|---|
| [2b46a13] | 51 |  | 
|---|
| [8984003] | 52 | /// True if the Initializer contains designations | 
|---|
|  | 53 | bool isDesignated( const ast::Init * init ); | 
|---|
| [dcd73d1] | 54 |  | 
|---|
| [8984003] | 55 | /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its | 
|---|
|  | 56 | /// type, where the depth of its type is the number of nested ArrayTypes + 1 | 
|---|
|  | 57 | bool checkInitDepth( const ast::ObjectDecl * objDecl ); | 
|---|
| [a465caff] | 58 |  | 
|---|
| [8984003] | 59 | /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. | 
|---|
|  | 60 | /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. | 
|---|
|  | 61 | /// Currently has assertions that make it less than fully general. | 
|---|
|  | 62 | bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ); | 
|---|
| [4d2434a] | 63 |  | 
|---|
| [8984003] | 64 | /// get all Ctor/Dtor call expressions from a Statement | 
|---|
|  | 65 | std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ); | 
|---|
| [16ba4a6f] | 66 |  | 
|---|
| [8984003] | 67 | /// returns true if expr is trivially a compile-time constant | 
|---|
|  | 68 | bool isConstExpr( const ast::Expr * expr ); | 
|---|
|  | 69 | bool isConstExpr( const ast::Init * init ); | 
|---|
| [7d651a66] | 70 |  | 
|---|
| [8984003] | 71 | /// Modifies objDecl to have: | 
|---|
|  | 72 | ///    __attribute__((section (".data#"))) | 
|---|
|  | 73 | /// which makes gcc put the declared variable in the data section, | 
|---|
|  | 74 | /// which is helpful for global constants on newer gcc versions, | 
|---|
|  | 75 | /// so that CFA's generated initialization won't segfault when writing it via a const cast. | 
|---|
|  | 76 | /// The trailing # is an injected assembly comment, to suppress the "a" in | 
|---|
|  | 77 | ///    .section .data,"a" | 
|---|
|  | 78 | ///    .section .data#,"a" | 
|---|
|  | 79 | /// to avoid assembler warning "ignoring changed section attributes for .data" | 
|---|
|  | 80 | void addDataSectionAttribute( ast::ObjectDecl * objDecl ); | 
|---|
| [b8524ca] | 81 |  | 
|---|
| [8984003] | 82 | class InitExpander final { | 
|---|
|  | 83 | public: | 
|---|
|  | 84 | using IndexList = std::vector< ast::ptr< ast::Expr > >; | 
|---|
|  | 85 | class ExpanderImpl; | 
|---|
| [b8524ca] | 86 |  | 
|---|
| [8984003] | 87 | private: | 
|---|
|  | 88 | std::shared_ptr< ExpanderImpl > expander; | 
|---|
|  | 89 | std::vector< ast::ptr< ast::Expr > > crnt; | 
|---|
|  | 90 | // invariant: list of size 2N (elements come in pairs [index, dimension]) | 
|---|
|  | 91 | IndexList indices; | 
|---|
| [b8524ca] | 92 |  | 
|---|
| [8984003] | 93 | public: | 
|---|
|  | 94 | /// Expand by stepping through init to get each list of arguments | 
|---|
|  | 95 | InitExpander( const ast::Init * init ); | 
|---|
| [b8524ca] | 96 |  | 
|---|
| [8984003] | 97 | /// Always expand to expression | 
|---|
|  | 98 | InitExpander( const ast::Expr * expr ); | 
|---|
| [b8524ca] | 99 |  | 
|---|
| [8984003] | 100 | std::vector< ast::ptr< ast::Expr > > operator* (); | 
|---|
|  | 101 | InitExpander & operator++ (); | 
|---|
| [b8524ca] | 102 |  | 
|---|
| [8984003] | 103 | /// builds statement which has the same semantics as a C-style list initializer (for array | 
|---|
|  | 104 | /// initializers) using callExpr as the base expression to perform initialization. | 
|---|
|  | 105 | /// Mutates callExpr | 
|---|
|  | 106 | ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr ); | 
|---|
| [b8524ca] | 107 |  | 
|---|
| [8984003] | 108 | void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ); | 
|---|
|  | 109 |  | 
|---|
|  | 110 | void clearArrayIndices(); | 
|---|
|  | 111 |  | 
|---|
|  | 112 | bool addReference(); | 
|---|
|  | 113 | }; | 
|---|
| [b8524ca] | 114 |  | 
|---|
| [0bd3faf] | 115 | } // namespace InitTweak | 
|---|
| [2b46a13] | 116 |  | 
|---|
|  | 117 | // Local Variables: // | 
|---|
|  | 118 | // tab-width: 4 // | 
|---|
|  | 119 | // mode: c++ // | 
|---|
|  | 120 | // compile-command: "make install" // | 
|---|
|  | 121 | // End: // | 
|---|