Changeset ce8c12f for src/SynTree


Ignore:
Timestamp:
May 15, 2017, 11:30:26 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
d36c117
Parents:
65aca88
Message:

initial work on references: reference types passed through the system, very simple examples work

Location:
src/SynTree
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AddressExpr.cc

    r65aca88 rce8c12f  
    2020AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    2121        if ( arg->has_result() ) {
    22                 set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) );
     22                if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( arg->get_result() ) ) {
     23                        // xxx - very temporary, make &ref look like **
     24                        set_result( new PointerType( Type::Qualifiers( Type::Lvalue ), refType->get_base()->clone() ) );
     25                } else {
     26                        set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) );
     27                }
    2328        }
    2429}
  • src/SynTree/Mutator.cc

    r65aca88 rce8c12f  
    462462}
    463463
     464Type *Mutator::mutate( ReferenceType *refType ) {
     465        mutateAll( refType->get_forall(), *this );
     466        refType->set_base( maybeMutate( refType->get_base(), *this ) );
     467        return refType;
     468}
     469
    464470Type *Mutator::mutate( FunctionType *functionType ) {
    465471        mutateAll( functionType->get_forall(), *this );
  • src/SynTree/Mutator.h

    r65aca88 rce8c12f  
    9191        virtual Type* mutate( PointerType *pointerType );
    9292        virtual Type* mutate( ArrayType *arrayType );
     93        virtual Type* mutate( ReferenceType *refType );
    9394        virtual Type* mutate( FunctionType *functionType );
    9495        virtual Type* mutate( StructInstType *aggregateUseType );
  • src/SynTree/SynTree.h

    r65aca88 rce8c12f  
    9999class PointerType;
    100100class ArrayType;
     101class ReferenceType;
    101102class FunctionType;
    102103class ReferenceToType;
  • src/SynTree/Type.h

    r65aca88 rce8c12f  
    249249        bool is_array() const { return isStatic || isVarLen || dimension; }
    250250
     251        virtual bool isComplete() const { return ! isVarLen; }
     252
    251253        virtual PointerType *clone() const { return new PointerType( *this ); }
    252254        virtual void accept( Visitor & v ) { v.visit( this ); }
     
    290292};
    291293
     294class ReferenceType : public Type {
     295public:
     296        ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
     297        ReferenceType( const ReferenceType & );
     298        virtual ~ReferenceType();
     299
     300        Type *get_base() { return base; }
     301        void set_base( Type *newValue ) { base = newValue; }
     302
     303        virtual ReferenceType *clone() const { return new ReferenceType( *this ); }
     304        virtual void accept( Visitor & v ) { v.visit( this ); }
     305        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
     306        virtual void print( std::ostream & os, int indent = 0 ) const;
     307private:
     308        Type *base;
     309        unsigned int level = 0;
     310};
     311
    292312class FunctionType : public Type {
    293313  public:
  • src/SynTree/Visitor.cc

    r65aca88 rce8c12f  
    354354void Visitor::visit( PointerType *pointerType ) {
    355355        acceptAll( pointerType->get_forall(), *this );
     356        // xxx - should PointerType visit/mutate dimension?
    356357        maybeAccept( pointerType->get_base(), *this );
    357358}
     
    361362        maybeAccept( arrayType->get_dimension(), *this );
    362363        maybeAccept( arrayType->get_base(), *this );
     364}
     365
     366void Visitor::visit( ReferenceType *refType ) {
     367        acceptAll( refType->get_forall(), *this );
     368        maybeAccept( refType->get_base(), *this );
    363369}
    364370
  • src/SynTree/Visitor.h

    r65aca88 rce8c12f  
    9494        virtual void visit( PointerType *pointerType );
    9595        virtual void visit( ArrayType *arrayType );
     96        virtual void visit( ReferenceType *refType );
    9697        virtual void visit( FunctionType *functionType );
    9798        virtual void visit( StructInstType *aggregateUseType );
     
    163164                        } // if
    164165                } catch( SemanticError &e ) {
    165                         e.set_location( (*i)->location );                       
     166                        e.set_location( (*i)->location );
    166167                        errors.append( e );
    167168                } // try
  • src/SynTree/module.mk

    r65aca88 rce8c12f  
    2020       SynTree/PointerType.cc \
    2121       SynTree/ArrayType.cc \
     22       SynTree/ReferenceType.cc \
    2223       SynTree/FunctionType.cc \
    2324       SynTree/ReferenceToType.cc \
Note: See TracChangeset for help on using the changeset viewer.