source: src/InitTweak/InitTweak.h@ ea6332d

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since ea6332d was d180746, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 2

  • 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// RemoveInit.h --
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 : Sat Jul 22 09:30:33 2017
13// Update Count : 4
14//
15
16#pragma once
17
18#include <bits/shared_ptr.h> // for shared_ptr
19#include <list> // for list
20#include <string> // for string, allocator
21
22#include "SynTree/SynTree.h" // for Visitor Nodes
23
24// helper functions for initialization
25namespace InitTweak {
26 bool isConstructor( const std::string & );
27 bool isDestructor( const std::string & );
28 bool isAssignment( const std::string & );
29 bool isCtorDtor( const std::string & );
30 bool isCtorDtorAssign( const std::string & );
31
32 FunctionDecl * isAssignment( Declaration * decl );
33 FunctionDecl * isDestructor( Declaration * decl );
34 FunctionDecl * isDefaultConstructor( Declaration * decl );
35 FunctionDecl * isCopyConstructor( Declaration * decl );
36 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
37
38 /// transform Initializer into an argument list that can be passed to a call expression
39 std::list< Expression * > makeInitList( Initializer * init );
40
41 /// True if the resolver should try to construct objDecl
42 bool tryConstruct( ObjectDecl * objDecl );
43
44 /// True if the Initializer contains designations
45 bool isDesignated( Initializer * init );
46
47 /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its
48 /// type, where the depth of its type is the number of nested ArrayTypes + 1
49 bool checkInitDepth( ObjectDecl * objDecl );
50
51 /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
52 DeclarationWithType * getFunction( Expression * expr );
53
54 /// Non-Null if expr is a call expression whose target function is intrinsic
55 ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
56
57 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
58 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
59 /// Currently has assertions that make it less than fully general.
60 bool isIntrinsicSingleArgCallStmt( Statement * stmt );
61
62 /// True if stmt is a call statement where the function called is intrinsic.
63 bool isIntrinsicCallStmt( Statement * stmt );
64
65 /// get all Ctor/Dtor call expressions from a Statement
66 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
67
68 /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
69 Expression * getCtorDtorCall( Statement * stmt );
70
71 /// returns the name of the function being called
72 std::string getFunctionName( Expression * expr );
73
74 /// returns the argument to a call expression in position N indexed from 0
75 Expression *& getCallArg( Expression * callExpr, unsigned int pos );
76
77 /// returns the base type of a PointerType or ArrayType, else returns NULL
78 Type * getPointerBase( Type * );
79
80 /// returns the argument if it is a PointerType or ArrayType, else returns NULL
81 Type * isPointerType( Type * );
82
83 /// returns true if expr is trivially a compile-time constant
84 bool isConstExpr( Expression * expr );
85 bool isConstExpr( Initializer * init );
86
87 class InitExpander {
88 public:
89 // expand by stepping through init to get each list of arguments
90 InitExpander( Initializer * init );
91
92 // always expand to expr
93 InitExpander( Expression * expr );
94
95 // iterator-like interface
96 std::list< Expression * > operator*();
97 InitExpander & operator++();
98
99 // builds statement which has the same semantics as a C-style list initializer
100 // (for array initializers) using callExpr as the base expression to perform initialization
101 Statement * buildListInit( UntypedExpr * callExpr );
102 void addArrayIndex( Expression * index, Expression * dimension );
103 void clearArrayIndices();
104
105 class ExpanderImpl;
106
107 typedef std::list< Expression * > IndexList;
108 private:
109 std::shared_ptr< ExpanderImpl > expander;
110 std::list< Expression * > cur;
111
112 // invariant: list of size 2N (elements come in pairs [index, dimension])
113 IndexList indices;
114 };
115} // namespace
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.