Changes in / [f23de79d:5902625]


Ignore:
Location:
src/AST
Files:
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    rf23de79d r5902625  
    2020#include <vector>
    2121
    22 #include "GenericSubstitution.hpp"
    2322#include "Stmt.hpp"
    2423#include "Type.hpp"
    25 #include "TypeSubstitution.hpp"
    2624#include "Common/utility.h"
    2725#include "Common/SemanticError.h"
     
    159157        assert( aggregate->result );
    160158
    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 
    164         // // take ownership of member type
    165         // result = mem->get_type();
    166         // // substitute aggregate generic parameters into member type
    167         // genericSubsitution( aggregate->result ).apply( result );
    168         // // ensure lvalue and appropriate restrictions from aggregate type
    169         // result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;
     159//      assert(!"unimplemented; need TypeSubstitution, genericSubstitution");
    170160}
    171161
  • src/AST/Node.cpp

    rf23de79d r5902625  
    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.
    3739template< typename node_t, enum ast::Node::ref_type ref_t >
    38 node_t * ast::ptr_base<node_t, ref_t>::get_and_mutate() {
     40node_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 );
    3943        // get mutable version of `n`
    4044        auto r = mutate( node );
     
    4246        assign( r );
    4347        return r;
    44 }
    45 
    46 template< typename node_t, enum ast::Node::ref_type ref_t >
    47 node_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();
    5248}
    5349
  • src/AST/Node.hpp

    rf23de79d r5902625  
    9494std::ostream& operator<< ( std::ostream& out, const Node * node );
    9595
    96 /// Call a visitor on a possibly-null node
    97 template<typename node_t>
    98 auto maybe_accept( const node_t * n, Visitor & v ) -> decltype( n->accept(v) ) {
    99         return n ? n->accept( v ) : nullptr;
    100 }
    101 
    10296/// Base class for the smart pointer types
    10397/// should never really be used.
     
    147141        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
    148142
    149         /// Returns a mutable version of the pointer in this node.
    150         node_t * get_and_mutate();
    151 
    152143        /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
    153144        /// Returns a mutable version of the pointer in this node.
  • src/AST/Pass.hpp

    rf23de79d r5902625  
    223223};
    224224
    225 /// Apply a pass to an entire translation unit
    226225template<typename pass_t>
    227226void accept_all( std::list< ast::ptr<ast::Decl> > &, ast::Pass<pass_t> & visitor );
  • src/AST/Print.cpp

    rf23de79d r5902625  
    656656
    657657        virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) {
    658                 os << indent << "Types:" << std::endl;
    659                 for ( const auto& i : *node ) {
    660                         os << indent+1 << i.first << " -> ";
    661                         indent += 2;
    662                         i.second->accept( *this );
    663                         indent -= 2;
    664                         os << std::endl;
    665                 }
    666                 os << indent << "Non-types:" << std::endl;
    667                 for ( auto i = node->beginVar(); i != node->endVar(); ++i ) {
    668                         os << indent+1 << i->first << " -> ";
    669                         indent += 2;
    670                         i->second->accept( *this );
    671                         indent -= 2;
    672                         os << std::endl;
    673                 }
    674658                return node;
    675659        }
  • src/AST/Type.hpp

    rf23de79d r5902625  
    4747        bool is_atomic() const { return qualifiers.is_atomic; }
    4848
    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; }
     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; }
    5454
    5555        /// How many elemental types are represented by this type
  • src/AST/TypeSubstitution.hpp

    rf23de79d r5902625  
    2525#include "Fwd.hpp"        // for UniqueId
    2626#include "ParseNode.hpp"
    27 #include "Type.hpp"       
     27#include "Type.hpp"       // for ptr<Type>
    2828#include "Common/SemanticError.h"  // for SemanticError
    2929#include "Visitor.hpp"
    3030#include "Decl.hpp"
    3131#include "Expr.hpp"
    32 #include "Node.hpp"
    3332
    3433namespace ast {
     
    4443        TypeSubstitution &operator=( const TypeSubstitution &other );
    4544
    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         }
     45        template< typename SynTreeClass > int apply( SynTreeClass *&input ) const;
     46        template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const;
    6447
    6548        void add( std::string formalType, const Type *actualType );
     
    179162
    180163template< typename SynTreeClass >
    181 int TypeSubstitution::apply( const SynTreeClass *& input ) const {
     164int TypeSubstitution::apply( SynTreeClass *&input ) const {
    182165        assert( input );
    183166        Pass<Substituter> sub( *this, false );
    184         input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
     167        input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) );
     168        assert( input );
    185169///     std::cerr << "substitution result is: ";
    186170///     newType->print( std::cerr );
     
    190174
    191175template< typename SynTreeClass >
    192 int TypeSubstitution::applyFree( const SynTreeClass *& input ) const {
     176int TypeSubstitution::applyFree( SynTreeClass *&input ) const {
    193177        assert( input );
    194178        Pass<Substituter> sub( *this, true );
    195         input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
     179        input = dynamic_cast< SynTreeClass * >( input->acceptMutator( sub ) );
     180        assert( input );
    196181///     std::cerr << "substitution result is: ";
    197182///     newType->print( std::cerr );
  • src/AST/porting.md

    rf23de79d r5902625  
    3838
    3939`N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class
    40 * **TODO** `Declaration::printShort` should also be integrated
     40* **TODO** write this visitor
     41* **TODO** write `std::ostream& operator<< ( std::ostream& out, const Node* node )` in `Node.hpp` in terms of `ast::Print`
     42* `Declaration::printShort` should also be integrated
    4143
    4244`clone` is private to `Node` now
     
    206208
    207209`CompoundStmt`
     210* **TODO** port copy operator
     211  * Needs to be an almost-shallow clone, where the declarations are cloned only if needed
     212  * **TODO** port `DeclReplacer`
    208213* Still a `std::list` for children, rather than `std::vector`
    209214  * allows more-efficient splicing for purposes of later code generation
     
    224229  * `getAggr()` => `aggr()`
    225230    * also now returns `const AggregateDecl *`
    226 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp`
     231* `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` **TODO** write
    227232
    228233`BasicType`
Note: See TracChangeset for help on using the changeset viewer.