| [e4d829b] | 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 | // CurrentObject.h -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Rob Schluntz | 
|---|
|  | 10 | // Created On       : Thu Jun  8 11:07:25 2017 | 
|---|
| [6b0b624] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
|  | 12 | // Last Modified On : Sat Jul 22 09:36:48 2017 | 
|---|
|  | 13 | // Update Count     : 3 | 
|---|
| [e4d829b] | 14 | // | 
|---|
|  | 15 |  | 
|---|
| [6b0b624] | 16 | #pragma once | 
|---|
| [e4d829b] | 17 |  | 
|---|
| [60aaa51d] | 18 | #include <deque> | 
|---|
| [ea6332d] | 19 | #include <list>   // for list | 
|---|
| [b7d92b96] | 20 | #include <memory> // for unique_ptr | 
|---|
| [ea6332d] | 21 | #include <stack>  // for stack | 
|---|
| [b7d92b96] | 22 | #include <vector> | 
|---|
| [e4d829b] | 23 |  | 
|---|
| [60aaa51d] | 24 | #include "AST/Node.hpp"  // for ptr | 
|---|
| [2b59f55] | 25 | #include "Common/CodeLocation.h" | 
|---|
|  | 26 |  | 
|---|
| [ea6332d] | 27 | class Designation; | 
|---|
|  | 28 | class Type; | 
|---|
|  | 29 | struct InitAlternative; | 
|---|
| [e4d829b] | 30 |  | 
|---|
|  | 31 | namespace ResolvExpr { | 
|---|
|  | 32 | class MemberIterator; | 
|---|
|  | 33 |  | 
|---|
| [f7cb0bc] | 34 | // TODO: memory management of MemberIterators | 
|---|
| [e4d829b] | 35 | class CurrentObject { | 
|---|
|  | 36 | public: | 
|---|
|  | 37 | CurrentObject(); | 
|---|
|  | 38 | CurrentObject( Type * type ); | 
|---|
|  | 39 |  | 
|---|
|  | 40 | /// resolves unresolved designation | 
|---|
|  | 41 | Designation * findNext( Designation * designation ); | 
|---|
|  | 42 | /// sets current position using resolved designation | 
|---|
|  | 43 | void setNext( Designation * designation ); | 
|---|
|  | 44 | /// steps to next sub-object of current-object | 
|---|
|  | 45 | void increment(); | 
|---|
|  | 46 | /// sets new current-object for the duration of this brace-enclosed initializer-list | 
|---|
|  | 47 | void enterListInit(); | 
|---|
|  | 48 | /// restores previous current-object | 
|---|
|  | 49 | void exitListInit(); | 
|---|
|  | 50 | /// produces a list of alternatives (Type *, Designation *) for the current sub-object's initializer | 
|---|
|  | 51 | std::list< InitAlternative > getOptions(); | 
|---|
| [62423350] | 52 | /// produces the type of the current object but no subobjects | 
|---|
|  | 53 | Type * getCurrentType(); | 
|---|
| [e4d829b] | 54 |  | 
|---|
|  | 55 | private: | 
|---|
|  | 56 | std::stack< MemberIterator * > objStack; | 
|---|
|  | 57 | }; | 
|---|
|  | 58 | } // namespace ResolvExpr | 
|---|
|  | 59 |  | 
|---|
| [b7d92b96] | 60 | namespace ast { | 
|---|
|  | 61 | // AST class types | 
|---|
|  | 62 | class Designation; | 
|---|
| [60aaa51d] | 63 | struct InitAlternative; | 
|---|
| [b7d92b96] | 64 | class Type; | 
|---|
|  | 65 |  | 
|---|
| [60aaa51d] | 66 | /// Iterates members of a type by initializer | 
|---|
|  | 67 | class MemberIterator { | 
|---|
|  | 68 | public: | 
|---|
|  | 69 | virtual ~MemberIterator() {} | 
|---|
|  | 70 |  | 
|---|
|  | 71 | /// Internal set position based on iterator ranges | 
|---|
|  | 72 | virtual void setPosition( | 
|---|
|  | 73 | std::deque< ptr< Expr > >::const_iterator it, | 
|---|
|  | 74 | std::deque< ptr< Expr > >::const_iterator end ) = 0; | 
|---|
|  | 75 |  | 
|---|
|  | 76 | /// walks the current object using the given designators as a guide | 
|---|
|  | 77 | void setPosition( const std::deque< ptr< Expr > > & designators ) { | 
|---|
|  | 78 | setPosition( designators.begin(), designators.end() ); | 
|---|
|  | 79 | } | 
|---|
|  | 80 |  | 
|---|
|  | 81 | /// retrieve the list of possible (Type,Designation) pairs for the current position in the | 
|---|
|  | 82 | /// current object | 
|---|
|  | 83 | virtual std::deque< InitAlternative > operator* () const = 0; | 
|---|
|  | 84 |  | 
|---|
|  | 85 | /// true if the iterator is not currently at the end | 
|---|
|  | 86 | virtual operator bool() const = 0; | 
|---|
|  | 87 |  | 
|---|
|  | 88 | /// moves the iterator by one member in the current object | 
|---|
|  | 89 | virtual MemberIterator & bigStep() = 0; | 
|---|
|  | 90 |  | 
|---|
|  | 91 | /// moves the iterator by one member in the current subobject | 
|---|
|  | 92 | virtual MemberIterator & smallStep() = 0; | 
|---|
|  | 93 |  | 
|---|
|  | 94 | /// the type of the current object | 
|---|
|  | 95 | virtual const Type * getType() = 0; | 
|---|
|  | 96 |  | 
|---|
|  | 97 | /// the type of the current subobject | 
|---|
|  | 98 | virtual const Type * getNext() = 0; | 
|---|
|  | 99 |  | 
|---|
|  | 100 | /// helper for operator*; aggregates must add designator to each init alternative, but | 
|---|
|  | 101 | /// adding designators in operator* creates duplicates | 
|---|
|  | 102 | virtual std::deque< InitAlternative > first() const = 0; | 
|---|
|  | 103 | }; | 
|---|
| [b7d92b96] | 104 |  | 
|---|
|  | 105 | /// Builds initializer lists in resolution | 
|---|
|  | 106 | class CurrentObject final { | 
|---|
|  | 107 | std::vector< std::shared_ptr<MemberIterator> > objStack; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | public: | 
|---|
|  | 110 | CurrentObject() = default; | 
|---|
| [2b59f55] | 111 | CurrentObject( const CodeLocation & loc, const Type * type ); | 
|---|
|  | 112 |  | 
|---|
| [2d11663] | 113 | /// resolves unresolved designation | 
|---|
|  | 114 | const Designation * findNext( const Designation * designation ); | 
|---|
| [60aaa51d] | 115 | /// sets current position using the resolved designation | 
|---|
|  | 116 | void setNext( const ast::Designation * designation ); | 
|---|
|  | 117 | /// steps to next sub-object of current object | 
|---|
|  | 118 | void increment(); | 
|---|
|  | 119 | /// sets new current object for the duration of this brace-enclosed intializer-list | 
|---|
|  | 120 | void enterListInit( const CodeLocation & loc ); | 
|---|
|  | 121 | /// restores previous current object | 
|---|
|  | 122 | void exitListInit(); | 
|---|
| [2b59f55] | 123 | /// produces a list of alternatives (Type *, Designation *) for the current sub-object's | 
|---|
|  | 124 | /// initializer. | 
|---|
| [60aaa51d] | 125 | std::deque< InitAlternative > getOptions(); | 
|---|
|  | 126 | /// produces the type of the current object but no subobjects | 
|---|
|  | 127 | const Type * getCurrentType(); | 
|---|
| [b7d92b96] | 128 | }; | 
|---|
|  | 129 | } // namespace ast | 
|---|
|  | 130 |  | 
|---|
| [e4d829b] | 131 | // Local Variables: // | 
|---|
|  | 132 | // tab-width: 4 // | 
|---|
|  | 133 | // mode: c++ // | 
|---|
|  | 134 | // compile-command: "make install" // | 
|---|
|  | 135 | // End: // | 
|---|
|  | 136 |  | 
|---|