Changeset 52a4d69 for src


Ignore:
Timestamp:
Jun 5, 2020, 10:29:10 AM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d2de1be9
Parents:
5c9b20c
Message:

Improvements to ast::ptr_base::strict_as. Added null to null variant and both now inspect the node to see if it has a location to print.

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Node.cpp

    r5c9b20c r52a4d69  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 16 14:16:00 2019
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     :
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jun  5 10:21:00 2020
     13// Update Count     : 1
    1414//
    1515
     
    4343}
    4444
     45[[noreturn]] static inline void strict_fail(const ast::Node * node) {
     46        assertf(node, "strict_as had nullptr input.");
     47        const ast::ParseNode * parse = dynamic_cast<const ast::ParseNode *>( node );
     48        if ( nullptr == parse ) {
     49                assertf(nullptr, "%s (no location)", toString(node).c_str());
     50        } else if ( parse->location.isUnset() ) {
     51                assertf(nullptr, "%s (unset location)", toString(node).c_str());
     52        } else {
     53                assertf(nullptr, "%s (at %s:%d)", toString(node).c_str(),
     54                        parse->location.filename.c_str(), parse->location.first_line);
     55        }
     56}
     57
     58template< typename node_t, enum ast::Node::ref_type ref_t >
     59void ast::ptr_base<node_t, ref_t>::_strict_fail() const {
     60        strict_fail(node);
     61}
     62
    4563template< typename node_t, enum ast::Node::ref_type ref_t >
    4664void ast::ptr_base<node_t, ref_t>::_inc( const node_t * node ) {
     
    5270void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node, bool do_delete ) {
    5371        _trap( node );
    54         node->decrement(ref_t, do_delete );
    55 }
    56 
    57 template< typename node_t, enum ast::Node::ref_type ref_t >
    58 void ast::ptr_base<node_t, ref_t>::_check() const { 
     72        node->decrement( ref_t, do_delete );
     73}
     74
     75template< typename node_t, enum ast::Node::ref_type ref_t >
     76void ast::ptr_base<node_t, ref_t>::_check() const {
    5977        // if(node) assert(node->was_ever_strong == false || node->strong_count > 0);
    6078}
  • src/AST/Node.hpp

    r5c9b20c r52a4d69  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jun  3 13:26:00 2019
    13 // Update Count     : 5
     12// Last Modified On : Fri Jun 5 9:47:00 2020
     13// Update Count     : 6
    1414//
    1515
     
    243243        const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); }
    244244
    245         /// wrapper for convenient access to strict_dynamic_cast
     245        /// Wrapper that makes sure dynamic_cast returns non-null.
    246246        template<typename o_node_t>
    247         const o_node_t * strict_as() const { _check(); return strict_dynamic_cast<const o_node_t *>(node); }
     247        const o_node_t * strict_as() const {
     248                if (const o_node_t * ret = as<o_node_t>()) return ret;
     249                _strict_fail();
     250        }
     251
     252        /// Wrapper that makes sure dynamic_cast does not fail.
     253        template<typename o_node_t, decltype(nullptr) null>
     254        const o_node_t * strict_as() const { return node ? strict_as<o_node_t>() : nullptr; }
    248255
    249256        /// Returns a mutable version of the pointer in this node.
     
    266273        void _dec( const node_t * other, bool do_delete = true );
    267274        void _check() const;
     275        void _strict_fail() const __attribute__((noreturn));
    268276
    269277        const node_t * node;
Note: See TracChangeset for help on using the changeset viewer.