Changeset aa8f9df for src/SynTree


Ignore:
Timestamp:
Sep 15, 2016, 3:22:50 PM (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:
4ab9536
Parents:
fd782b2 (diff), 906e24d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'replace-results-list' into tuples

Conflicts:

src/ResolvExpr/AlternativeFinder.cc
src/SymTab/Indexer.cc
src/SynTree/Mutator.cc
src/SynTree/Visitor.cc
src/Tuples/TupleAssignment.cc
src/Tuples/TupleAssignment.h

Location:
src/SynTree
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/AddressExpr.cc

    rfd782b2 raa8f9df  
    1919
    2020AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) {
    21         for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) {
    22                 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );
    23         } // for
     21        if ( arg->has_result() ) {
     22                set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) );
     23        }
    2424}
    2525
     
    3535        if ( arg ) {
    3636                os << std::string( indent+2, ' ' );
    37     arg->print( os, indent+2 );
     37                arg->print( os, indent+2 );
    3838        } // if
    3939}
  • src/SynTree/ApplicationExpr.cc

    rfd782b2 raa8f9df  
    2121#include "TypeSubstitution.h"
    2222#include "Common/utility.h"
    23 
     23#include "ResolvExpr/typeops.h"
    2424
    2525ParamEntry::ParamEntry( const ParamEntry &other ) :
     
    4343
    4444ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) {
    45         PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() );
    46         assert( pointer );
    47         FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    48         assert( function );
     45        PointerType *pointer = safe_dynamic_cast< PointerType* >( funcExpr->get_result() );
     46        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    4947
    50         for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {
    51                 get_results().push_back( (*i)->get_type()->clone() );
    52         } // for
     48        set_result( ResolvExpr::extractResultType( function ) );
     49
     50        assert( has_result() );
    5351}
    5452
  • src/SynTree/CommaExpr.cc

    rfd782b2 raa8f9df  
    2323        // to false on all result types. Actually doing this causes some strange things
    2424        // to happen in later passes (particularly, Specialize, Lvalue, and Box). This needs to be looked into.
    25         cloneAll( arg2->get_results(), get_results() );
    26         // for ( Type *& type : get_results() ) {
    27         //      type->set_isLvalue( false );
    28         // }
     25        set_result( maybeClone( arg2->get_result() ) );
     26        // get_type->set_isLvalue( false );
    2927}
    3028
  • src/SynTree/Expression.cc

    rfd782b2 raa8f9df  
    3131
    3232
    33 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {}
    34 
    35 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    36         cloneAll( other.results, results );
     33Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
     34
     35Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
    3736}
    3837
     
    4039        delete env;
    4140        delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
    42         deleteAll( results );
    43 }
    44 
    45 void Expression::add_result( Type *t ) {
    46         if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
    47                 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
    48         } else {
    49                 results.push_back(t);
    50         } // if
     41        delete result;
    5142}
    5243
     
    6859
    6960ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
    70         add_result( constant.get_type()->clone() );
     61        set_result( constant.get_type()->clone() );
    7162}
    7263
     
    8576        assert( var );
    8677        assert( var->get_type() );
    87         add_result( var->get_type()->clone() );
    88         for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    89                 (*i)->set_isLvalue( true );
    90         } // for
     78        Type * type = var->get_type()->clone();
     79        type->set_isLvalue( true );
     80        set_result( type );
    9181}
    9282
     
    110100SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
    111101                Expression( _aname ), expr(expr_), type(0), isType(false) {
    112         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     102        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    113103}
    114104
    115105SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
    116106                Expression( _aname ), expr(0), type(type_), isType(true) {
    117         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     107        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    118108}
    119109
     
    141131AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
    142132                Expression( _aname ), expr(expr_), type(0), isType(false) {
    143         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    144134}
    145135
    146136AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
    147137                Expression( _aname ), expr(0), type(type_), isType(true) {
    148         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     138        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    149139}
    150140
     
    172162UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
    173163                Expression( _aname ), type(type_), member(member_) {
    174         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     164        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    175165}
    176166
     
    197187OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
    198188                Expression( _aname ), type(type_), member(member_) {
    199         add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
     189        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
    200190}
    201191
     
    229219
    230220OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
    231         add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
     221        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
    232222}
    233223
     
    284274
    285275CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
    286         add_result(toType);
     276        set_result(toType);
    287277}
    288278
    289279CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
     280        set_result( new VoidType( Type::Qualifiers() ) );
    290281}
    291282
     
    303294        arg->print(os, indent+2);
    304295        os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
    305         if ( results.empty() ) {
    306                 os << std::string( indent+2, ' ' ) << "nothing" << std::endl;
     296        os << std::string( indent+2, ' ' );
     297        if ( result->isVoid() ) {
     298                os << "nothing";
    307299        } else {
    308                 printAll(results, os, indent+2);
     300                result->print( os, indent+2 );
    309301        } // if
     302        os << std::endl;
    310303        Expression::print( os, indent );
    311304}
     
    341334MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
    342335                Expression( _aname ), member(_member), aggregate(_aggregate) {
    343         add_result( member->get_type()->clone() );
    344         for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
    345                 (*i)->set_isLvalue( true );
    346         } // for
     336        set_result( member->get_type()->clone() );
     337        get_result()->set_isLvalue( true );
    347338}
    348339
     
    419410LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
    420411                Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
    421         add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     412        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    422413}
    423414
     
    477468ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
    478469        assert( callExpr );
    479         cloneAll( callExpr->get_results(), results );
     470        assert( callExpr->has_result() );
     471        set_result( callExpr->get_result()->clone() );
    480472}
    481473
     
    510502        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
    511503        assert( arg );
    512         cloneAll( arg->get_results(), results );
     504        set_result( maybeClone( arg->get_result() ) );
    513505}
    514506
     
    530522
    531523CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
    532         add_result( type->clone() );
     524        set_result( type->clone() );
    533525}
    534526
     
    570562        if ( ! body.empty() ) {
    571563                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
    572                         cloneAll( exprStmt->get_expr()->get_results(), get_results() );
     564                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
    573565                }
    574566        }
  • src/SynTree/Expression.h

    rfd782b2 raa8f9df  
    3232        virtual ~Expression();
    3333
    34         std::list<Type *>& get_results() { return results; }
    35         void add_result( Type *t );
     34        Type *& get_result() { return result; }
     35        void set_result( Type *newValue ) { result = newValue; }
     36        bool has_result() const { return result != nullptr; }
    3637
    3738        TypeSubstitution *get_env() const { return env; }
     
    4748        virtual void print( std::ostream &os, int indent = 0 ) const;
    4849  protected:
    49         std::list<Type *> results;
     50        Type * result;
    5051        TypeSubstitution *env;
    5152        Expression* argName; // if expression is used as an argument, it can be "designated" by this name
  • src/SynTree/Mutator.cc

    rfd782b2 raa8f9df  
    178178
    179179Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
    180         mutateAll( applicationExpr->get_results(), *this );
     180        applicationExpr->set_result( maybeMutate( applicationExpr->get_result(), *this ) );
    181181        applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
    182182        mutateAll( applicationExpr->get_args(), *this );
     
    185185
    186186Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
    187         mutateAll( untypedExpr->get_results(), *this );
     187        untypedExpr->set_result( maybeMutate( untypedExpr->get_result(), *this ) );
    188188        mutateAll( untypedExpr->get_args(), *this );
    189189        return untypedExpr;
     
    191191
    192192Expression *Mutator::mutate( NameExpr *nameExpr ) {
    193         mutateAll( nameExpr->get_results(), *this );
     193        nameExpr->set_result( maybeMutate( nameExpr->get_result(), *this ) );
    194194        return nameExpr;
    195195}
    196196
    197197Expression *Mutator::mutate( AddressExpr *addressExpr ) {
    198         mutateAll( addressExpr->get_results(), *this );
     198        addressExpr->set_result( maybeMutate( addressExpr->get_result(), *this ) );
    199199        addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
    200200        return addressExpr;
     
    202202
    203203Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
    204         mutateAll( labelAddressExpr->get_results(), *this );
     204        labelAddressExpr->set_result( maybeMutate( labelAddressExpr->get_result(), *this ) );
    205205        labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
    206206        return labelAddressExpr;
     
    208208
    209209Expression *Mutator::mutate( CastExpr *castExpr ) {
    210         mutateAll( castExpr->get_results(), *this );
     210        castExpr->set_result( maybeMutate( castExpr->get_result(), *this ) );
    211211        castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
    212212        return castExpr;
     
    214214
    215215Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
    216         mutateAll( memberExpr->get_results(), *this );
     216        memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) );
    217217        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    218218        memberExpr->set_member( maybeMutate( memberExpr->get_member(), *this ) );
     
    221221
    222222Expression *Mutator::mutate( MemberExpr *memberExpr ) {
    223         mutateAll( memberExpr->get_results(), *this );
     223        memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) );
    224224        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
    225225        return memberExpr;
     
    227227
    228228Expression *Mutator::mutate( VariableExpr *variableExpr ) {
    229         mutateAll( variableExpr->get_results(), *this );
     229        variableExpr->set_result( maybeMutate( variableExpr->get_result(), *this ) );
    230230        return variableExpr;
    231231}
    232232
    233233Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
    234         mutateAll( constantExpr->get_results(), *this );
     234        constantExpr->set_result( maybeMutate( constantExpr->get_result(), *this ) );
    235235//  maybeMutate( constantExpr->get_constant(), *this )
    236236        return constantExpr;
     
    238238
    239239Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
    240         mutateAll( sizeofExpr->get_results(), *this );
     240        sizeofExpr->set_result( maybeMutate( sizeofExpr->get_result(), *this ) );
    241241        if ( sizeofExpr->get_isType() ) {
    242242                sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
     
    248248
    249249Expression *Mutator::mutate( AlignofExpr *alignofExpr ) {
    250         mutateAll( alignofExpr->get_results(), *this );
     250        alignofExpr->set_result( maybeMutate( alignofExpr->get_result(), *this ) );
    251251        if ( alignofExpr->get_isType() ) {
    252252                alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) );
     
    258258
    259259Expression *Mutator::mutate( UntypedOffsetofExpr *offsetofExpr ) {
    260         mutateAll( offsetofExpr->get_results(), *this );
     260        offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) );
    261261        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
    262262        return offsetofExpr;
     
    264264
    265265Expression *Mutator::mutate( OffsetofExpr *offsetofExpr ) {
    266         mutateAll( offsetofExpr->get_results(), *this );
     266        offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) );
    267267        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
    268268        offsetofExpr->set_member( maybeMutate( offsetofExpr->get_member(), *this ) );
     
    271271
    272272Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
    273         mutateAll( offsetPackExpr->get_results(), *this );
     273        offsetPackExpr->set_result( maybeMutate( offsetPackExpr->get_result(), *this ) );
    274274        offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
    275275        return offsetPackExpr;
     
    277277
    278278Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    279         mutateAll( attrExpr->get_results(), *this );
     279        attrExpr->set_result( maybeMutate( attrExpr->get_result(), *this ) );
    280280        if ( attrExpr->get_isType() ) {
    281281                attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
     
    287287
    288288Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
    289         mutateAll( logicalExpr->get_results(), *this );
     289        logicalExpr->set_result( maybeMutate( logicalExpr->get_result(), *this ) );
    290290        logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
    291291        logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
     
    294294
    295295Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
    296         mutateAll( conditionalExpr->get_results(), *this );
     296        conditionalExpr->set_result( maybeMutate( conditionalExpr->get_result(), *this ) );
    297297        conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
    298298        conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
     
    302302
    303303Expression *Mutator::mutate( CommaExpr *commaExpr ) {
    304         mutateAll( commaExpr->get_results(), *this );
     304        commaExpr->set_result( maybeMutate( commaExpr->get_result(), *this ) );
    305305        commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
    306306        commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
     
    309309
    310310Expression *Mutator::mutate( TypeExpr *typeExpr ) {
    311         mutateAll( typeExpr->get_results(), *this );
     311        typeExpr->set_result( maybeMutate( typeExpr->get_result(), *this ) );
    312312        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
    313313        return typeExpr;
     
    329329
    330330Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) {
    331         mutateAll( ctorExpr->get_results(), *this );
     331        ctorExpr->set_result( maybeMutate( ctorExpr->get_result(), *this ) );
    332332        ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) );
    333333        return ctorExpr;
     
    335335
    336336Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {
    337         mutateAll( compLitExpr->get_results(), *this );
     337        compLitExpr->set_result( maybeMutate( compLitExpr->get_result(), *this ) );
    338338        compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );
    339339        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
     
    342342
    343343Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
    344         mutateAll( valofExpr->get_results(), *this );
     344        valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) );
    345345        return valofExpr;
    346346}
     
    353353
    354354Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
    355         mutateAll( tupleExpr->get_results(), *this );
     355        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
    356356        mutateAll( tupleExpr->get_exprs(), *this );
    357357        return tupleExpr;
     
    359359
    360360Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) {
    361         mutateAll( tupleExpr->get_results(), *this );
     361        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
    362362        tupleExpr->set_tuple( maybeMutate( tupleExpr->get_tuple(), *this ) );
    363363        return tupleExpr;
     
    365365
    366366Expression *Mutator::mutate( MemberTupleExpr *tupleExpr ) {
    367         mutateAll( tupleExpr->get_results(), *this );
     367        tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );
    368368        tupleExpr->set_member( maybeMutate( tupleExpr->get_member(), *this ) );
    369369        tupleExpr->set_aggregate( maybeMutate( tupleExpr->get_aggregate(), *this ) );
     
    372372
    373373Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) {
    374         mutateAll( assignExpr->get_results(), *this );
     374        assignExpr->set_result( maybeMutate( assignExpr->get_result(), *this ) );
    375375        mutateAll( assignExpr->get_tempDecls(), *this );
    376376        mutateAll( assignExpr->get_assigns(), *this );
     
    379379
    380380Expression *Mutator::mutate( StmtExpr *stmtExpr ) {
    381         mutateAll( stmtExpr->get_results(), *this );
     381        stmtExpr->set_result( maybeMutate( stmtExpr->get_result(), *this ) );
    382382        stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) );
    383383        return stmtExpr;
  • src/SynTree/TupleExpr.cc

    rfd782b2 raa8f9df  
    3131
    3232void TupleExpr::print( std::ostream &os, int indent ) const {
    33         os << std::string( indent, ' ' ) << "Tuple:" << std::endl;
     33        os << "Tuple:" << std::endl;
    3434        printAll( exprs, os, indent+2 );
    3535        Expression::print( os, indent );
     
    3737
    3838TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) {
    39         // TupleType * type = safe_dynamic_cast< TypeType * >( tuple->get_ )
    40         assert( tuple->get_results().size() >= index );
    41         add_result( *std::next( tuple->get_results().begin(), index ) );
     39        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
     40        assert( type->size() >= index );
     41        set_result( *std::next( type->get_types().begin(), index ) );
    4242}
    4343
     
    5050
    5151void TupleIndexExpr::print( std::ostream &os, int indent ) const {
    52         os << std::string( indent, ' ' ) << "Tuple Index Expression, with tuple:" << std::endl;
     52        os << "Tuple Index Expression, with tuple:" << std::endl;
    5353        tuple->print( os, indent+2 );
    5454        os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl;
     
    5757
    5858MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {
    59         cloneAll( member->get_results(), get_results() ); // xxx - ???
     59        set_result( maybeClone( member->get_result() ) ); // xxx - ???
    6060}
    6161
     
    6969
    7070void MemberTupleExpr::print( std::ostream &os, int indent ) const {
    71         os << std::string( indent, ' ' ) << "Member Tuple Expression, with aggregate:" << std::endl;
     71        os << "Member Tuple Expression, with aggregate:" << std::endl;
    7272        aggregate->print( os, indent+2 );
    7373        os << std::string( indent+2, ' ' ) << "with member: " << std::endl;
     
    7878
    7979TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) {
     80        TupleType * type = new TupleType( Type::Qualifiers() );
    8081        for ( Expression * expr : assigns ) {
    81                 cloneAll( expr->get_results(), get_results() );
     82                assert( expr->has_result() );
     83                type->get_types().push_back( expr->get_result()->clone() );
    8284        }
     85        set_result( type );
    8386}
    8487
  • src/SynTree/Type.h

    rfd782b2 raa8f9df  
    2727                Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
    2828
     29                Qualifiers &operator&=( const Qualifiers &other );
    2930                Qualifiers &operator+=( const Qualifiers &other );
    3031                Qualifiers &operator-=( const Qualifiers &other );
     
    6566        std::list<TypeDecl*>& get_forall() { return forall; }
    6667
     68        /// How many elemental types are represented by this type
     69        virtual unsigned size() const { return 1; };
     70        virtual bool isVoid() const { return size() == 0; }
     71
    6772        virtual Type *clone() const = 0;
    6873        virtual void accept( Visitor &v ) = 0;
     
    7782  public:
    7883        VoidType( const Type::Qualifiers &tq );
     84
     85        virtual unsigned size() const { return 0; };
    7986
    8087        virtual VoidType *clone() const { return new VoidType( *this ); }
     
    357364
    358365        std::list<Type*>& get_types() { return types; }
     366        virtual unsigned size() const { return types.size(); };
    359367
    360368        iterator begin() { return types.begin(); }
     
    425433};
    426434
     435inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) {
     436        isConst &= other.isConst;
     437        isVolatile &= other.isVolatile;
     438        isRestrict &= other.isRestrict;
     439        isLvalue &= other.isLvalue;
     440        isAtomic &= other.isAtomic;
     441        return *this;
     442}
     443
    427444inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
    428445        isConst |= other.isConst;
  • src/SynTree/Visitor.cc

    rfd782b2 raa8f9df  
    150150
    151151void Visitor::visit( ApplicationExpr *applicationExpr ) {
    152         acceptAll( applicationExpr->get_results(), *this );
     152        maybeAccept( applicationExpr->get_result(), *this );
    153153        maybeAccept( applicationExpr->get_function(), *this );
    154154        acceptAll( applicationExpr->get_args(), *this );
     
    156156
    157157void Visitor::visit( UntypedExpr *untypedExpr ) {
    158         acceptAll( untypedExpr->get_results(), *this );
     158        maybeAccept( untypedExpr->get_result(), *this );
    159159        acceptAll( untypedExpr->get_args(), *this );
    160160}
    161161
    162162void Visitor::visit( NameExpr *nameExpr ) {
    163         acceptAll( nameExpr->get_results(), *this );
     163        maybeAccept( nameExpr->get_result(), *this );
    164164}
    165165
    166166void Visitor::visit( AddressExpr *addressExpr ) {
    167         acceptAll( addressExpr->get_results(), *this );
     167        maybeAccept( addressExpr->get_result(), *this );
    168168        maybeAccept( addressExpr->get_arg(), *this );
    169169}
    170170
    171171void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
    172         acceptAll( labAddressExpr->get_results(), *this );
     172        maybeAccept( labAddressExpr->get_result(), *this );
    173173        maybeAccept( labAddressExpr->get_arg(), *this );
    174174}
    175175
    176176void Visitor::visit( CastExpr *castExpr ) {
    177         acceptAll( castExpr->get_results(), *this );
     177        maybeAccept( castExpr->get_result(), *this );
    178178        maybeAccept( castExpr->get_arg(), *this );
    179179}
    180180
    181181void Visitor::visit( UntypedMemberExpr *memberExpr ) {
    182         acceptAll( memberExpr->get_results(), *this );
     182        maybeAccept( memberExpr->get_result(), *this );
    183183        maybeAccept( memberExpr->get_aggregate(), *this );
    184184        maybeAccept( memberExpr->get_member(), *this );
     
    186186
    187187void Visitor::visit( MemberExpr *memberExpr ) {
    188         acceptAll( memberExpr->get_results(), *this );
     188        maybeAccept( memberExpr->get_result(), *this );
    189189        maybeAccept( memberExpr->get_aggregate(), *this );
    190190}
    191191
    192192void Visitor::visit( VariableExpr *variableExpr ) {
    193         acceptAll( variableExpr->get_results(), *this );
     193        maybeAccept( variableExpr->get_result(), *this );
    194194}
    195195
    196196void Visitor::visit( ConstantExpr *constantExpr ) {
    197         acceptAll( constantExpr->get_results(), *this );
     197        maybeAccept( constantExpr->get_result(), *this );
    198198        maybeAccept( constantExpr->get_constant(), *this );
    199199}
    200200
    201201void Visitor::visit( SizeofExpr *sizeofExpr ) {
    202         acceptAll( sizeofExpr->get_results(), *this );
     202        maybeAccept( sizeofExpr->get_result(), *this );
    203203        if ( sizeofExpr->get_isType() ) {
    204204                maybeAccept( sizeofExpr->get_type(), *this );
     
    209209
    210210void Visitor::visit( AlignofExpr *alignofExpr ) {
    211         acceptAll( alignofExpr->get_results(), *this );
     211        maybeAccept( alignofExpr->get_result(), *this );
    212212        if ( alignofExpr->get_isType() ) {
    213213                maybeAccept( alignofExpr->get_type(), *this );
     
    218218
    219219void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
    220         acceptAll( offsetofExpr->get_results(), *this );
     220        maybeAccept( offsetofExpr->get_result(), *this );
    221221        maybeAccept( offsetofExpr->get_type(), *this );
    222222}
    223223
    224224void Visitor::visit( OffsetofExpr *offsetofExpr ) {
    225         acceptAll( offsetofExpr->get_results(), *this );
     225        maybeAccept( offsetofExpr->get_result(), *this );
    226226        maybeAccept( offsetofExpr->get_type(), *this );
    227227        maybeAccept( offsetofExpr->get_member(), *this );
     
    229229
    230230void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
    231         acceptAll( offsetPackExpr->get_results(), *this );
     231        maybeAccept( offsetPackExpr->get_result(), *this );
    232232        maybeAccept( offsetPackExpr->get_type(), *this );
    233233}
    234234
    235235void Visitor::visit( AttrExpr *attrExpr ) {
    236         acceptAll( attrExpr->get_results(), *this );
     236        maybeAccept( attrExpr->get_result(), *this );
    237237        if ( attrExpr->get_isType() ) {
    238238                maybeAccept( attrExpr->get_type(), *this );
     
    243243
    244244void Visitor::visit( LogicalExpr *logicalExpr ) {
    245         acceptAll( logicalExpr->get_results(), *this );
     245        maybeAccept( logicalExpr->get_result(), *this );
    246246        maybeAccept( logicalExpr->get_arg1(), *this );
    247247        maybeAccept( logicalExpr->get_arg2(), *this );
     
    249249
    250250void Visitor::visit( ConditionalExpr *conditionalExpr ) {
    251         acceptAll( conditionalExpr->get_results(), *this );
     251        maybeAccept( conditionalExpr->get_result(), *this );
    252252        maybeAccept( conditionalExpr->get_arg1(), *this );
    253253        maybeAccept( conditionalExpr->get_arg2(), *this );
     
    256256
    257257void Visitor::visit( CommaExpr *commaExpr ) {
    258         acceptAll( commaExpr->get_results(), *this );
     258        maybeAccept( commaExpr->get_result(), *this );
    259259        maybeAccept( commaExpr->get_arg1(), *this );
    260260        maybeAccept( commaExpr->get_arg2(), *this );
     
    262262
    263263void Visitor::visit( TypeExpr *typeExpr ) {
    264         acceptAll( typeExpr->get_results(), *this );
     264        maybeAccept( typeExpr->get_result(), *this );
    265265        maybeAccept( typeExpr->get_type(), *this );
    266266}
     
    279279
    280280void Visitor::visit( ConstructorExpr * ctorExpr ) {
    281         acceptAll( ctorExpr->get_results(), *this );
     281        maybeAccept( ctorExpr->get_result(), *this );
    282282        maybeAccept( ctorExpr->get_callExpr(), *this );
    283283}
    284284
    285285void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
    286         acceptAll( compLitExpr->get_results(), *this );
     286        maybeAccept( compLitExpr->get_result(), *this );
    287287        maybeAccept( compLitExpr->get_type(), *this );
    288288        maybeAccept( compLitExpr->get_initializer(), *this );
     
    290290
    291291void Visitor::visit( UntypedValofExpr *valofExpr ) {
    292         acceptAll( valofExpr->get_results(), *this );
     292        maybeAccept( valofExpr->get_result(), *this );
    293293        maybeAccept( valofExpr->get_body(), *this );
    294294}
     
    300300
    301301void Visitor::visit( TupleExpr *tupleExpr ) {
    302         acceptAll( tupleExpr->get_results(), *this );
     302        maybeAccept( tupleExpr->get_result(), *this );
    303303        acceptAll( tupleExpr->get_exprs(), *this );
    304304}
    305305
    306306void Visitor::visit( TupleIndexExpr *tupleExpr ) {
    307         acceptAll( tupleExpr->get_results(), *this );
     307        maybeAccept( tupleExpr->get_result(), *this );
    308308        maybeAccept( tupleExpr->get_tuple(), *this );
    309309}
    310310
    311311void Visitor::visit( MemberTupleExpr *tupleExpr ) {
    312         acceptAll( tupleExpr->get_results(), *this );
     312        maybeAccept( tupleExpr->get_result(), *this );
    313313        maybeAccept( tupleExpr->get_member(), *this );
    314314        maybeAccept( tupleExpr->get_aggregate(), *this );
     
    316316
    317317void Visitor::visit( TupleAssignExpr *assignExpr ) {
    318         acceptAll( assignExpr->get_results(), *this );
     318        maybeAccept( assignExpr->get_result(), *this );
    319319        acceptAll( assignExpr->get_tempDecls(), *this );
    320320        acceptAll( assignExpr->get_assigns(), *this );
     
    322322
    323323void Visitor::visit( StmtExpr *stmtExpr ) {
    324         acceptAll( stmtExpr->get_results(), *this );
     324        maybeAccept( stmtExpr->get_result(), *this );
    325325        maybeAccept( stmtExpr->get_statements(), *this );
    326326}
Note: See TracChangeset for help on using the changeset viewer.