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

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 1ae06fa was 9236060, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Merge branch 'master' into references

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