Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    r62423350 r94a8123  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 21 17:35:04 2017
    13 // Update Count     : 19
     12// Last Modified On : Thu Mar 16 08:05:17 2017
     13// Update Count     : 15
    1414//
    1515
     
    1818#include <cassert>
    1919#include "Tuples.h"
    20 #include "Common/PassVisitor.h"
     20#include "GenPoly/DeclMutator.h"
     21#include "SynTree/Mutator.h"
     22#include "SynTree/Statement.h"
     23#include "SynTree/Declaration.h"
     24#include "SynTree/Type.h"
     25#include "SynTree/Expression.h"
     26#include "SynTree/Initializer.h"
     27#include "SymTab/Mangler.h"
    2128#include "Common/ScopedMap.h"
    22 #include "GenPoly/DeclMutator.h"
     29#include "ResolvExpr/typeops.h"
    2330#include "InitTweak/GenInit.h"
    2431#include "InitTweak/InitTweak.h"
    25 #include "ResolvExpr/typeops.h"
    26 #include "SymTab/Mangler.h"
    27 #include "SynTree/Declaration.h"
    28 #include "SynTree/Expression.h"
    29 #include "SynTree/Initializer.h"
    30 #include "SynTree/Mutator.h"
    31 #include "SynTree/Statement.h"
    32 #include "SynTree/Type.h"
    3332
    3433namespace Tuples {
     
    8382                };
    8483
    85                 class TupleIndexExpander {
    86                 public:
    87                         Expression * postmutate( TupleIndexExpr * tupleExpr );
     84                class TupleIndexExpander final : public Mutator {
     85                public:
     86                        typedef Mutator Parent;
     87                        using Parent::mutate;
     88
     89                        virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override;
    8890                };
    8991
     
    114116                replacer.mutateDeclarationList( translationUnit );
    115117
    116                 PassVisitor<TupleIndexExpander> idxExpander;
     118                TupleIndexExpander idxExpander;
    117119                mutateAll( translationUnit, idxExpander );
    118120
     
    191193                                commaExpr->set_arg1( nullptr );
    192194                        }
    193                         ObjectDecl * finished = new ObjectDecl( toString( "_unq", id, "_finished_" ), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::Bool ),
    194                                                                                                         new SingleInit( new ConstantExpr( Constant::from_int( 0 ) ) ) );
     195                        BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool );
     196                        ObjectDecl * finished = new ObjectDecl( toString( "_unq", id, "_finished_" ), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::Bool ), new SingleInit( new ConstantExpr( Constant( boolType->clone(), "0" ) ), noDesignators ) );
    195197                        addDeclaration( finished );
    196198                        // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N))
    197199                        // This pattern ensures that each unique expression is evaluated once, regardless of evaluation order of the generated C code.
    198                         Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant::from_int( 1 ) ) );
     200                        Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant( boolType->clone(), "1" ) ) );
    199201                        ConditionalExpr * condExpr = new ConditionalExpr( new VariableExpr( finished ), var->clone(),
    200202                                new CommaExpr( new CommaExpr( assignUnq, assignFinished ), var->clone() ) );
     
    248250        }
    249251
    250         Expression * TupleIndexExpander::postmutate( TupleIndexExpr * tupleExpr ) {
    251                 Expression * tuple = tupleExpr->get_tuple();
     252        Expression * TupleIndexExpander::mutate( TupleIndexExpr * tupleExpr ) {
     253                Expression * tuple = maybeMutate( tupleExpr->get_tuple(), *this );
    252254                assert( tuple );
    253255                tupleExpr->set_tuple( nullptr );
     
    310312        Type * makeTupleType( const std::list< Expression * > & exprs ) {
    311313                // produce the TupleType which aggregates the types of the exprs
    312                 std::list< Type * > types;
    313                 Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex );
     314                TupleType *tupleType = new TupleType( Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex ) );
     315                Type::Qualifiers &qualifiers = tupleType->get_qualifiers();
    314316                for ( Expression * expr : exprs ) {
    315317                        assert( expr->get_result() );
    316318                        if ( expr->get_result()->isVoid() ) {
    317319                                // if the type of any expr is void, the type of the entire tuple is void
     320                                delete tupleType;
    318321                                return new VoidType( Type::Qualifiers() );
    319322                        }
    320323                        Type * type = expr->get_result()->clone();
    321                         types.push_back( type );
     324                        tupleType->get_types().push_back( type );
    322325                        // the qualifiers on the tuple type are the qualifiers that exist on all component types
    323326                        qualifiers &= type->get_qualifiers();
    324327                } // for
    325328                if ( exprs.empty() ) qualifiers = Type::Qualifiers();
    326                 return new TupleType( qualifiers, types );
     329                return tupleType;
    327330        }
    328331
    329332        TypeInstType * isTtype( Type * type ) {
    330333                if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( type ) ) {
    331                         if ( inst->get_baseType() && inst->get_baseType()->get_kind() == TypeDecl::Ttype ) {
     334                        if ( inst->get_baseType()->get_kind() == TypeDecl::Ttype ) {
    332335                                return inst;
    333336                        }
     
    353356                                maybeImpure = true;
    354357                        }
    355                         virtual void visit( __attribute__((unused)) UntypedExpr * untypedExpr ) { maybeImpure = true; }
     358                        virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; }
    356359                        bool maybeImpure = false;
    357360                };
Note: See TracChangeset for help on using the changeset viewer.