| 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 | 
|---|
| 11 | // Last Modified By : Andrew Beach | 
|---|
| 12 | // Last Modified On : Thu Apr  6 16:14:00 2023 | 
|---|
| 13 | // Update Count     : 4 | 
|---|
| 14 | // | 
|---|
| 15 |  | 
|---|
| 16 | #pragma once | 
|---|
| 17 |  | 
|---|
| 18 | #include <deque> | 
|---|
| 19 | #include <list>   // for list | 
|---|
| 20 | #include <memory> // for unique_ptr | 
|---|
| 21 | #include <stack>  // for stack | 
|---|
| 22 | #include <vector> | 
|---|
| 23 |  | 
|---|
| 24 | #include "AST/Node.hpp"  // for ptr | 
|---|
| 25 | #include "Common/CodeLocation.h" | 
|---|
| 26 |  | 
|---|
| 27 | class Designation; | 
|---|
| 28 | class Type; | 
|---|
| 29 | struct InitAlternative; | 
|---|
| 30 |  | 
|---|
| 31 | namespace ResolvExpr { | 
|---|
| 32 | class MemberIterator; | 
|---|
| 33 |  | 
|---|
| 34 | // TODO: memory management of MemberIterators | 
|---|
| 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(); | 
|---|
| 52 | /// produces the type of the current object but no subobjects | 
|---|
| 53 | Type * getCurrentType(); | 
|---|
| 54 |  | 
|---|
| 55 | private: | 
|---|
| 56 | std::stack< MemberIterator * > objStack; | 
|---|
| 57 | }; | 
|---|
| 58 | } // namespace ResolvExpr | 
|---|
| 59 |  | 
|---|
| 60 | namespace ast { | 
|---|
| 61 | // AST class types | 
|---|
| 62 | class Designation; | 
|---|
| 63 | struct InitAlternative; | 
|---|
| 64 | class Type; | 
|---|
| 65 |  | 
|---|
| 66 | /// Iterates members of a type by initializer | 
|---|
| 67 | class MemberIterator; | 
|---|
| 68 |  | 
|---|
| 69 | /// Builds initializer lists in resolution | 
|---|
| 70 | class CurrentObject final { | 
|---|
| 71 | std::vector< std::shared_ptr<MemberIterator> > objStack; | 
|---|
| 72 |  | 
|---|
| 73 | public: | 
|---|
| 74 | CurrentObject() = default; | 
|---|
| 75 | CurrentObject( const CodeLocation & loc, const Type * type ); | 
|---|
| 76 |  | 
|---|
| 77 | /// resolves unresolved designation | 
|---|
| 78 | const Designation * findNext( const Designation * designation ); | 
|---|
| 79 | /// sets current position using the resolved designation | 
|---|
| 80 | void setNext( const ast::Designation * designation ); | 
|---|
| 81 | /// steps to next sub-object of current object | 
|---|
| 82 | void increment(); | 
|---|
| 83 | /// sets new current object for the duration of this brace-enclosed intializer-list | 
|---|
| 84 | void enterListInit( const CodeLocation & loc ); | 
|---|
| 85 | /// restores previous current object | 
|---|
| 86 | void exitListInit(); | 
|---|
| 87 | /// produces a list of alternatives (Type *, Designation *) for the current sub-object's | 
|---|
| 88 | /// initializer. | 
|---|
| 89 | std::deque< InitAlternative > getOptions(); | 
|---|
| 90 | /// produces the type of the current object but no subobjects | 
|---|
| 91 | const Type * getCurrentType(); | 
|---|
| 92 | }; | 
|---|
| 93 | } // namespace ast | 
|---|
| 94 |  | 
|---|
| 95 | // Local Variables: // | 
|---|
| 96 | // tab-width: 4 // | 
|---|
| 97 | // mode: c++ // | 
|---|
| 98 | // compile-command: "make install" // | 
|---|
| 99 | // End: // | 
|---|
| 100 |  | 
|---|