source: src/InitTweak/InitTweak.h@ 1ccae59

Last change on this file since 1ccae59 was 0bd3faf, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Removed forward declarations missed in the BaseSyntaxNode removal. Removed code and modified names to support two versions of the ast.

  • Property mode set to 100644
File size: 4.4 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 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 );
31 bool isCopyFunction( const ast::FunctionDecl * decl );
32
33 /// returns the base type of the first parameter to a constructor/destructor/assignment function
34 const ast::Type * getTypeofThis( const ast::FunctionType * ftype );
35
36 /// returns the first parameter of a constructor/destructor/assignment function
37 const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func);
38
39 /// generate a bitwise assignment operation.
40 ast::Expr * createBitwiseAssignment( const ast::Expr * dst, const ast::Expr * src);
41
42 /// transform Initializer into an argument list that can be passed to a call expression
43 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init );
44
45 /// True if the resolver should try to construct dwt
46 bool tryConstruct( const ast::DeclWithType * dwt );
47
48 /// True if the type can have a user-defined constructor
49 bool isConstructable( const ast::Type * t );
50
51 /// True if the Initializer contains designations
52 bool isDesignated( const ast::Init * 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( const ast::ObjectDecl * objDecl );
57
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.
61 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt );
62
63 /// get all Ctor/Dtor call expressions from a Statement
64 std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt );
65
66 /// returns true if expr is trivially a compile-time constant
67 bool isConstExpr( const ast::Expr * expr );
68 bool isConstExpr( const ast::Init * init );
69
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"
79 void addDataSectionAttribute( ast::ObjectDecl * objDecl );
80
81 class InitExpander final {
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
94 InitExpander( const ast::Init * init );
95
96 /// Always expand to expression
97 InitExpander( const ast::Expr * expr );
98
99 std::vector< ast::ptr< ast::Expr > > operator* ();
100 InitExpander & operator++ ();
101
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.
104 /// Mutates callExpr
105 ast::ptr< ast::Stmt > buildListInit( ast::UntypedExpr * callExpr );
106
107 void addArrayIndex( const ast::Expr * index, const ast::Expr * dimension );
108
109 void clearArrayIndices();
110
111 bool addReference();
112 };
113} // namespace InitTweak
114
115// Local Variables: //
116// tab-width: 4 //
117// mode: c++ //
118// compile-command: "make install" //
119// End: //
Note: See TracBrowser for help on using the repository browser.