Changeset 76ed81f


Ignore:
Timestamp:
May 22, 2019, 5:22:30 PM (3 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
893e106
Parents:
6380f78
Message:

Broken stuff pre-Pass fix

Location:
src/AST
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r6380f78 r76ed81f  
    159159        assert( aggregate->result );
    160160
     161        // #warning Needs GenericSubsitution.cpp building to work correctly
     162        // result.set_and_mutate( mem->get_type() )->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;  // FIXME temporary patch
     163
    161164        // take ownership of member type
    162         Type * res = result.set_and_mutate( mem->get_type() );
     165        result = mem->get_type();
    163166        // substitute aggregate generic parameters into member type
    164         genericSubsitution( aggregate->result ).apply( res );
     167        genericSubsitution( aggregate->result ).apply( result );
    165168        // ensure lvalue and appropriate restrictions from aggregate type
    166         res->set_lvalue( true );
    167         res->qualifiers |= aggregate->result->qualifiers;
    168         // ensure changes propegated back into result
    169         result = res;
     169        result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;
    170170}
    171171
  • src/AST/GenericSubstitution.cpp

    r6380f78 r76ed81f  
    3131                TypeSubstitution sub;
    3232
    33                 void previsit( const Type * ty ) {
     33                const Type * previsit( const Type * ty ) {
    3434                        assertf( false, "Attempted generic substitution for non-aggregate type: %s",
    3535                                toString( ty ).c_str() );
     36                        return ty;
    3637                }
    3738
    38                 void previsit( const ReferenceType * ) {
     39                const ReferenceType * previsit( const ReferenceType * ty ) {
    3940                        // do nothing; allows substitution from base type
     41                        return ty;
    4042                }
    4143
    42                 void previsit( const ReferenceToType * ty ) {
     44                const ReferenceToType * previsit( const ReferenceToType * ty ) {
     45                        visit_children = false;
    4346                        // build substitution from base parameters
    4447                        const AggregateDecl * aggr = ty->aggr();
    4548                        sub = TypeSubstitution{ aggr->params.begin(), aggr->params.end(), ty->params.begin() };
    46                         visit_children = false;
     49                        return ty;
    4750                }
    4851        };
  • src/AST/Node.cpp

    r6380f78 r76ed81f  
    3535void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); }
    3636
    37 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
    38 /// Returns a mutable version of the pointer in this node.
    39 template< typename node_t, enum ast::Node::ref_type ref_t >
    40 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {
    41         // ensure ownership of `n` by this node to avoid spurious single-owner mutates
    42         assign( n );
     37template< typename node_t, enum ast::Node::ref_type ref_t >
     38node_t * ast::ptr_base<node_t, ref_t>::get_and_mutate() {
    4339        // get mutable version of `n`
    4440        auto r = mutate( node );
     
    4642        assign( r );
    4743        return r;
     44}
     45
     46template< typename node_t, enum ast::Node::ref_type ref_t >
     47node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {
     48        // ensure ownership of `n` by this node to avoid spurious single-owner mutates
     49        assign( n );
     50        // return mutable version
     51        return get_and_mutate();
    4852}
    4953
  • src/AST/Node.hpp

    r6380f78 r76ed81f  
    147147        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
    148148
     149        /// Returns a mutable version of the pointer in this node.
     150        node_t * get_and_mutate();
     151
    149152        /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
    150153        /// Returns a mutable version of the pointer in this node.
  • src/AST/Print.cpp

    r6380f78 r76ed81f  
    495495
    496496        virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * node ) {
     497                os << indent << "Types:" << std::endl;
     498                for ( const auto& i : *node ) {
     499                        os << indent+1 << i.first << " -> ";
     500                        indent += 2;
     501                        i.second->accept( *this );
     502                        indent -= 2;
     503                        os << std::endl;
     504                }
     505                os << indent << "Non-types:" << std::endl;
     506                for ( auto i = node->beginVar(); i != node->endVar(); ++i ) {
     507                        os << indent+1 << i->first << " -> ";
     508                        indent += 2;
     509                        i->second->accept( *this );
     510                        indent -= 2;
     511                        os << std::endl;
     512                }
    497513                return node;
    498514        }
  • src/AST/Type.hpp

    r6380f78 r76ed81f  
    4747        bool is_atomic() const { return qualifiers.is_atomic; }
    4848
    49         void set_const( bool v ) { qualifiers.is_const = v; }
    50         void set_restrict( bool v ) { qualifiers.is_restrict = v; }
    51         void set_lvalue( bool v ) { qualifiers.is_lvalue = v; }
    52         void set_mutex( bool v ) { qualifiers.is_mutex = v; }
    53         void set_atomic( bool v ) { qualifiers.is_atomic = v; }
     49        Type * set_const( bool v ) { qualifiers.is_const = v; return this; }
     50        Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; }
     51        Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; }
     52        Type * set_mutex( bool v ) { qualifiers.is_mutex = v; return this; }
     53        Type * set_atomic( bool v ) { qualifiers.is_atomic = v; return this; }
    5454
    5555        /// How many elemental types are represented by this type
  • src/AST/TypeSubstitution.hpp

    r6380f78 r76ed81f  
    3030#include "Decl.hpp"
    3131#include "Expr.hpp"
     32#include "Node.hpp"
    3233
    3334namespace ast {
     
    4344        TypeSubstitution &operator=( const TypeSubstitution &other );
    4445
    45         template< typename SynTreeClass > int apply( SynTreeClass *&input ) const;
    46         template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const;
     46        template< typename SynTreeClass > int apply( const SynTreeClass *& input ) const;
     47        template< typename SynTreeClass > int applyFree( const SynTreeClass *& input ) const;
     48
     49        template< typename node_t, enum Node::ref_type ref_t >
     50        int apply( ptr_base< node_t, ref_t > & input ) const {
     51                const node_t * p = input.get();
     52                int ret = apply(p);
     53                input = p;
     54                return ret;
     55        }
     56
     57        template< typename node_t, enum Node::ref_type ref_t >
     58        int applyFree( ptr_base< node_t, ref_t > & input ) const {
     59                const node_t * p = input.get();
     60                int ret = applyFree(p);
     61                input = p;
     62                return ret;
     63        }
    4764
    4865        void add( std::string formalType, const Type *actualType );
     
    162179
    163180template< typename SynTreeClass >
    164 int TypeSubstitution::apply( SynTreeClass *&input ) const {
     181int TypeSubstitution::apply( const SynTreeClass *& input ) const {
    165182        assert( input );
    166183        Pass<Substituter> sub( *this, false );
    167         input = strict_dynamic_cast< SynTreeClass * >( input->accept( sub ) );
     184        input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    168185///     std::cerr << "substitution result is: ";
    169186///     newType->print( std::cerr );
     
    173190
    174191template< typename SynTreeClass >
    175 int TypeSubstitution::applyFree( SynTreeClass *&input ) const {
     192int TypeSubstitution::applyFree( const SynTreeClass *& input ) const {
    176193        assert( input );
    177194        Pass<Substituter> sub( *this, true );
    178         input = strict_dynamic_cast< SynTreeClass * >( input->accept( sub ) );
     195        input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    179196///     std::cerr << "substitution result is: ";
    180197///     newType->print( std::cerr );
Note: See TracChangeset for help on using the changeset viewer.