source: src/InitTweak/InitTweak.hpp@ 13481af0

Last change on this file since 13481af0 was 13481af0, checked in by Peter A. Buhr <pabuhr@…>, 2 days ago

remove addDataSectionAttribute hack and handle dynamic initialization of const definitions by removing the const after resolution

  • Property mode set to 100644
File size: 3.8 KB
Line 
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// InitTweak.hpp --
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 : Thu Jul 2 16:45:44 2026
13// Update Count : 12
14//
15
16#pragma once
17
18#include <list> // for list
19#include <memory> // for shared_ptr
20#include <string> // for string, allocator
21#include <vector>
22
23#include "AST/Fwd.hpp" // for AST nodes
24
25// helper functions for initialization
26namespace InitTweak {
27
28bool isAssignment( const ast::FunctionDecl * decl );
29bool isDestructor( const ast::FunctionDecl * decl );
30bool isDefaultConstructor( const ast::FunctionDecl * decl );
31bool isCopyConstructor( const ast::FunctionDecl * decl );
32bool isCopyFunction( const ast::FunctionDecl * decl );
33
34/// returns the base type of the first parameter to a constructor/destructor/assignment function
35const ast::Type * getTypeofThis( const ast::FunctionType * ftype );
36
37/// returns the first parameter of a constructor/destructor/assignment function
38const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);
39
40/// generate a bitwise assignment operation.
41ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src);
42
43/// transform Initializer into an argument list that can be passed to a call expression
44std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
45
46/// True if the resolver should try to construct dwt
47bool tryConstruct( const ast::DeclWithType * dwt );
48
49/// True if the type can have a user-defined constructor
50bool isConstructable( const ast::Type * t );
51
52/// True if the Initializer contains designations
53bool isDesignated( const ast::Init * init );
54
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
57bool checkInitDepth( const ast::ObjectDecl * objDecl );
58
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.
62bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
63
64/// get all Ctor/Dtor call expressions from a Statement
65std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt );
66
67/// returns true if expr is trivially a compile-time constant
68bool isConstExpr( const ast::Expr * expr );
69bool isConstExpr( const ast::Init * init );
70
71class InitExpander final {
72public:
73 using IndexList = std::vector< ast::ptr< ast::Expr > >;
74 class ExpanderImpl;
75
76private:
77 std::shared_ptr< ExpanderImpl > expander;
78 std::vector< ast::ptr< ast::Expr > > crnt;
79 // invariant: list of size 2N (elements come in pairs [index, dimension])
80 IndexList indices;
81
82public:
83 /// Expand by stepping through init to get each list of arguments
84 InitExpander( const ast::Init * init );
85
86 /// Always expand to expression
87 InitExpander( const ast::Expr * expr );
88
89 std::vector< ast::ptr< ast::Expr > > operator* ();
90 InitExpander & operator++ ();
91
92 /// builds statement which has the same semantics as a C-style list initializer (for array
93 /// initializers) using callExpr as the base expression to perform initialization.
94 /// Mutates callExpr
95 ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr );
96
97 void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
98
99 void clearArrayIndices();
100
101 bool addReference();
102};
103
104} // namespace InitTweak
105
106// Local Variables: //
107// tab-width: 4 //
108// mode: c++ //
109// compile-command: "make install" //
110// End: //
Note: See TracBrowser for help on using the repository browser.