source: src/InitTweak/InitTweak.h@ 234b1cb

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

resolver porting; finish top level of initialization

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