Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CurrentObject.cc

    rba4a1d8 r2b59f55  
    2020#include <string>                      // for string, operator<<, allocator
    2121
     22#include "AST/Expr.hpp"                // for InitAlternative
     23#include "AST/Init.hpp"                // for Designation
     24#include "AST/Node.hpp"                // for readonly
    2225#include "Common/Indenter.h"           // for Indenter, operator<<
    2326#include "Common/SemanticError.h"      // for SemanticError
     
    579582} // namespace ResolvExpr
    580583
     584namespace ast {
     585
     586        /// Iterates members of a type by initializer
     587        class MemberIterator {
     588        public:
     589                virtual ~MemberIterator() {}
     590
     591                /// retrieve the list of possible (Type,Designation) pairs for the current position in the
     592                /// current object
     593                virtual std::vector< InitAlternative > operator* () const = 0;
     594       
     595        protected:
     596                /// helper for operator*; aggregates must add designator to each init alternative, but
     597                /// adding designators in operator* creates duplicates
     598                virtual std::vector< InitAlternative > first() const = 0;
     599        };
     600
     601        /// Iterates "other" types (e.g. basic, pointer) which do not change at list initializer entry
     602        class SimpleIterator final : public MemberIterator {
     603                CodeLocation location;
     604                readonly< Type > type = nullptr;
     605        public:
     606                SimpleIterator( const CodeLocation & loc, const Type * t ) : location( loc ), type( t ) {}
     607
     608                std::vector< InitAlternative > operator* () const override { return first(); }
     609
     610        protected:
     611                std::vector< InitAlternative > first() const override {
     612                        if ( type ) return { InitAlternative{ type, new Designation{ location } } };
     613                        return {};
     614                }
     615        };
     616
     617        CurrentObject::CurrentObject( const CodeLocation & loc, const Type * type ) : objStack() {
     618                objStack.emplace_back( new SimpleIterator{ loc, type } );
     619        }
     620
     621        std::vector< InitAlternative > CurrentObject::getOptions() {
     622                PRINT( std::cerr << "____getting current options" << std::endl; )
     623                assertf( ! objStack.empty(), "objstack empty in getOptions" );
     624                return **objStack.back();
     625        }
     626}
     627
    581628// Local Variables: //
    582629// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.