Changeset e6b42e7 for src/AST


Ignore:
Timestamp:
Sep 9, 2020, 11:33:01 AM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b7f6f0
Parents:
dfc13bb
Message:

Added the ast::Pass::read utility. Converted two passes to use its two different uses.

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.hpp

    rdfc13bb re6b42e7  
    6767// | WithSymbolTable       - provides symbol table functionality
    6868// | WithForallSubstitutor - maintains links between TypeInstType and TypeDecl under mutation
     69//
     70// Other Special Members:
     71// | result                - Either a method that takes no parameters or a field. If a method (or
     72//                           callable field) get_result calls it, otherwise the value is returned.
    6973//-------------------------------------------------------------------------------------------------
    7074template< typename core_t >
     
    8993        virtual ~Pass() = default;
    9094
     95        /// Storage for the actual pass.
     96        core_t core;
     97
     98        /// If the core defines a result, call it if possible, otherwise return it.
     99        inline auto get_result() -> decltype( __pass::get_result( core, '0' ) ) {
     100                return __pass::get_result( core, '0' );
     101        }
     102
    91103        /// Construct and run a pass on a translation unit.
    92104        template< typename... Args >
     
    96108        }
    97109
    98         template< typename... Args >
     110        /// Contruct and run a pass on a pointer to extract a value.
     111        template< typename node_type, typename... Args >
     112        static auto read( node_type const * node, Args&&... args ) {
     113                Pass<core_t> visitor( std::forward<Args>( args )... );
     114                node_type const * temp = node->accept( visitor );
     115                assert( temp == node );
     116                return visitor.get_result();
     117        }
     118
     119        // Versions of the above for older compilers.
    99120        static void run( std::list< ptr<Decl> > & decls ) {
    100121                Pass<core_t> visitor;
     
    102123        }
    103124
    104         /// Storage for the actual pass
    105         core_t core;
     125        static auto read( Node const * node ) {
     126                Pass<core_t> visitor;
     127                Node const * temp = node->accept( visitor );
     128                assert( temp == node );
     129                return visitor.get_result();
     130        }
    106131
    107132        /// Visit function declarations
  • src/AST/Pass.proto.hpp

    rdfc13bb re6b42e7  
    421421
    422422        } // namespace forall
     423
     424        template<typename core_t>
     425        static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) {
     426                return core.result();
     427        }
     428
     429        template<typename core_t>
     430        static inline auto get_result( core_t & core, int ) -> decltype( core.result ) {
     431                return core.result;
     432        }
     433
     434        template<typename core_t>
     435        static inline void get_result( core_t &, long ) {}
    423436} // namespace __pass
    424437} // namespace ast
Note: See TracChangeset for help on using the changeset viewer.