source: src/InitTweak/InitTweak.h@ aa00626

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since aa00626 was 9e1d485, checked in by Aaron Moss <a3moss@…>, 6 years ago

First draft of ast::Type with subclasses

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[2b46a13]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
[6b0b624]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:30:33 2017
13// Update Count : 4
[2b46a13]14//
15
[6b0b624]16#pragma once
[2b46a13]17
[d180746]18#include <list> // for list
[be9288a]19#include <memory> // for shared_ptr
[d180746]20#include <string> // for string, allocator
[2b46a13]21
[9e1d485]22#include "AST/Fwd.hpp" // for AST nodes
[d180746]23#include "SynTree/SynTree.h" // for Visitor Nodes
[2b46a13]24
25// helper functions for initialization
26namespace InitTweak {
[207c7e1d]27 FunctionDecl * isAssignment( Declaration * decl );
28 FunctionDecl * isDestructor( Declaration * decl );
29 FunctionDecl * isDefaultConstructor( Declaration * decl );
[4d4882a]30 FunctionDecl * isCopyConstructor( Declaration * decl );
[ee1635c8]31 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
[4d4882a]32
[7fc7cdb]33 /// returns the base type of the first parameter to a constructor/destructor/assignment function
[549c006]34 Type * getTypeofThis( FunctionType * ftype );
[7fc7cdb]35
36 /// returns the first parameter of a constructor/destructor/assignment function
[549c006]37 ObjectDecl * getParamThis( FunctionType * ftype );
[7fc7cdb]38
[f5c3b6c]39 /// generate a bitwise assignment operation.
40 ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src );
41
[b81adcc4]42 /// transform Initializer into an argument list that can be passed to a call expression
43 std::list< Expression * > makeInitList( Initializer * init );
[2b46a13]44
[22bc276]45 /// True if the resolver should try to construct dwt
46 bool tryConstruct( DeclarationWithType * dwt );
[2b46a13]47
[29bc63e]48 /// True if the type can have a user-defined constructor
49 bool isConstructable( Type * t );
50
[b81adcc4]51 /// True if the Initializer contains designations
52 bool isDesignated( Initializer * init );
[2b46a13]53
[dcd73d1]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( ObjectDecl * objDecl );
57
[b7b8674]58 /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
59 DeclarationWithType * getFunction( Expression * expr );
60
61 /// Non-Null if expr is a call expression whose target function is intrinsic
62 ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
[aedfd91]63
[b81adcc4]64 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
65 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
66 /// Currently has assertions that make it less than fully general.
[a465caff]67 bool isIntrinsicSingleArgCallStmt( Statement * stmt );
68
69 /// True if stmt is a call statement where the function called is intrinsic.
70 bool isIntrinsicCallStmt( Statement * stmt );
[70f89d00]71
[4d2434a]72 /// get all Ctor/Dtor call expressions from a Statement
73 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
74
[b81adcc4]75 /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
76 Expression * getCtorDtorCall( Statement * stmt );
[f1b1e4c]77
[b81adcc4]78 /// returns the name of the function being called
79 std::string getFunctionName( Expression * expr );
[f1b1e4c]80
[b81adcc4]81 /// returns the argument to a call expression in position N indexed from 0
82 Expression *& getCallArg( Expression * callExpr, unsigned int pos );
[10a7775]83
[b81adcc4]84 /// returns the base type of a PointerType or ArrayType, else returns NULL
85 Type * getPointerBase( Type * );
[9e1d485]86 const ast::Type* getPointerBase( const ast::Type* );
[64071c2]87
[b81adcc4]88 /// returns the argument if it is a PointerType or ArrayType, else returns NULL
89 Type * isPointerType( Type * );
[5f98ce5]90
[b81adcc4]91 /// returns true if expr is trivially a compile-time constant
92 bool isConstExpr( Expression * expr );
93 bool isConstExpr( Initializer * init );
[39f84a4]94
95 class InitExpander {
96 public:
97 // expand by stepping through init to get each list of arguments
98 InitExpander( Initializer * init );
99
100 // always expand to expr
101 InitExpander( Expression * expr );
102
103 // iterator-like interface
104 std::list< Expression * > operator*();
105 InitExpander & operator++();
106
107 // builds statement which has the same semantics as a C-style list initializer
108 // (for array initializers) using callExpr as the base expression to perform initialization
109 Statement * buildListInit( UntypedExpr * callExpr );
110 void addArrayIndex( Expression * index, Expression * dimension );
[4d2434a]111 void clearArrayIndices();
[1a5ad8c]112 bool addReference();
[39f84a4]113
114 class ExpanderImpl;
[d180746]115
[62e5546]116 typedef std::list< Expression * > IndexList;
[39f84a4]117 private:
118 std::shared_ptr< ExpanderImpl > expander;
119 std::list< Expression * > cur;
120
121 // invariant: list of size 2N (elements come in pairs [index, dimension])
122 IndexList indices;
123 };
[2b46a13]124} // namespace
125
126// Local Variables: //
127// tab-width: 4 //
128// mode: c++ //
129// compile-command: "make install" //
130// End: //
Note: See TracBrowser for help on using the repository browser.