source: src/InitTweak/InitTweak.h @ 44adf1b

Last change on this file since 44adf1b was 8984003, checked in by Andrew Beach <ajbeach@…>, 7 months ago

Round of significant clean-up and reindentation of InitTweak? directory.

  • Property mode set to 100644
File size: 4.3 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.h --
8//
9// Author           : Rob Schluntz
10// Created On       : Fri May 13 11:26:36 2016
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Sep 22  9:21:00 2022
13// Update Count     : 9
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
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"
80void addDataSectionAttribute( ast::ObjectDecl * objDecl );
81
82class InitExpander final {
83public:
84        using IndexList = std::vector< ast::ptr< ast::Expr > >;
85        class ExpanderImpl;
86
87private:
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;
92
93public:
94        /// Expand by stepping through init to get each list of arguments
95        InitExpander( const ast::Init * init );
96
97        /// Always expand to expression
98        InitExpander( const ast::Expr * expr );
99
100        std::vector< ast::ptr< ast::Expr > > operator* ();
101        InitExpander & operator++ ();
102
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 );
107
108        void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
109
110        void clearArrayIndices();
111
112        bool addReference();
113};
114
115} // namespace InitTweak
116
117// Local Variables: //
118// tab-width: 4 //
119// mode: c++ //
120// compile-command: "make install" //
121// End: //
Note: See TracBrowser for help on using the repository browser.