source: src/InitTweak/InitTweak.h @ d76c588

arm-ehjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since d76c588 was d76c588, checked in by Aaron Moss <a3moss@…>, 3 years ago

Stubs for new resolver, implementation of new indexer, type environment

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