Changeset 0698aa1 for src/SynTree


Ignore:
Timestamp:
Jul 12, 2017, 4:44:44 PM (7 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:
cda7889
Parents:
aca65621
Message:

Add stripReferences, fix createDeref and makeSub to work with reference types

Location:
src/SynTree
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    raca65621 r0698aa1  
    335335namespace {
    336336        TypeSubstitution makeSub( Type * t ) {
    337                 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
     337                if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) {
     338                        return makeSub( refType->get_base() );
     339                } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
    338340                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
    339341                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
     
    400402        if ( Type * type = expr->get_result() ) {
    401403                Type * base = InitTweak::getPointerBase( type );
    402                 if ( ! base ) {
    403                         std::cerr << type << std::endl;
    404                 }
    405                 assertf( base, "expected pointer type in dereference\n" );
    406                 ret->set_result( maybeClone( base ) );
     404                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
     405                ret->set_result( new ReferenceType( Type::Qualifiers(), base->clone() ) );
    407406        }
    408407        return ret;
  • src/SynTree/Type.cc

    raca65621 r0698aa1  
    6565const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
    6666
    67 Type *Type::stripDeclarator() {
     67Type * Type::stripDeclarator() {
    6868        Type * type = this;
    6969        while ( Type * at = InitTweak::getPointerBase( type ) ) {
    7070                type = at;
     71        }
     72        return type;
     73}
     74
     75Type * Type::stripReferences() {
     76        Type * type = this;
     77        while ( ReferenceType * ref = dynamic_cast<ReferenceType *>( type ) ) {
     78                type = ref->get_base();
    7179        }
    7280        return type;
  • src/SynTree/Type.h

    raca65621 r0698aa1  
    158158
    159159        /// return type without outer pointers and arrays
    160         Type *stripDeclarator();
     160        Type * stripDeclarator();
     161
     162        /// return type without outer references
     163        Type * stripReferences();
    161164
    162165        virtual bool isComplete() const { return true; }
Note: See TracChangeset for help on using the changeset viewer.