Ignore:
Timestamp:
Jul 4, 2017, 9:40:16 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:
208e5be
Parents:
9c951e3 (diff), f7cb0bc (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 'master' into references

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    r9c951e3 rb1e63ac5  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:05:17 2017
    13 // Update Count     : 15
     12// Last Modified On : Wed Jun 21 17:35:04 2017
     13// Update Count     : 19
    1414//
    1515
     
    1818#include <cassert>
    1919#include "Tuples.h"
     20#include "Common/PassVisitor.h"
     21#include "Common/ScopedMap.h"
    2022#include "GenPoly/DeclMutator.h"
     23#include "InitTweak/GenInit.h"
     24#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"
    2130#include "SynTree/Mutator.h"
    2231#include "SynTree/Statement.h"
    23 #include "SynTree/Declaration.h"
    2432#include "SynTree/Type.h"
    25 #include "SynTree/Expression.h"
    26 #include "SynTree/Initializer.h"
    27 #include "SymTab/Mangler.h"
    28 #include "Common/ScopedMap.h"
    29 #include "ResolvExpr/typeops.h"
    30 #include "InitTweak/GenInit.h"
    31 #include "InitTweak/InitTweak.h"
    3233
    3334namespace Tuples {
     
    8283                };
    8384
    84                 class TupleIndexExpander final : public Mutator {
    85                 public:
    86                         typedef Mutator Parent;
    87                         using Parent::mutate;
    88 
    89                         virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override;
     85                class TupleIndexExpander {
     86                public:
     87                        Expression * postmutate( TupleIndexExpr * tupleExpr );
    9088                };
    9189
     
    116114                replacer.mutateDeclarationList( translationUnit );
    117115
    118                 TupleIndexExpander idxExpander;
     116                PassVisitor<TupleIndexExpander> idxExpander;
    119117                mutateAll( translationUnit, idxExpander );
    120118
     
    193191                                commaExpr->set_arg1( nullptr );
    194192                        }
    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 ) );
     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 ) ) ) );
    197195                        addDeclaration( finished );
    198196                        // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N))
    199197                        // This pattern ensures that each unique expression is evaluated once, regardless of evaluation order of the generated C code.
    200                         Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant( boolType->clone(), "1" ) ) );
     198                        Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant::from_int( 1 ) ) );
    201199                        ConditionalExpr * condExpr = new ConditionalExpr( new VariableExpr( finished ), var->clone(),
    202200                                new CommaExpr( new CommaExpr( assignUnq, assignFinished ), var->clone() ) );
     
    250248        }
    251249
    252         Expression * TupleIndexExpander::mutate( TupleIndexExpr * tupleExpr ) {
    253                 Expression * tuple = maybeMutate( tupleExpr->get_tuple(), *this );
     250        Expression * TupleIndexExpander::postmutate( TupleIndexExpr * tupleExpr ) {
     251                Expression * tuple = tupleExpr->get_tuple();
    254252                assert( tuple );
    255253                tupleExpr->set_tuple( nullptr );
     
    312310        Type * makeTupleType( const std::list< Expression * > & exprs ) {
    313311                // produce the TupleType which aggregates the types of the exprs
    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();
     312                std::list< Type * > types;
     313                Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex );
    316314                for ( Expression * expr : exprs ) {
    317315                        assert( expr->get_result() );
    318316                        if ( expr->get_result()->isVoid() ) {
    319317                                // if the type of any expr is void, the type of the entire tuple is void
    320                                 delete tupleType;
    321318                                return new VoidType( Type::Qualifiers() );
    322319                        }
    323320                        Type * type = expr->get_result()->clone();
    324                         tupleType->get_types().push_back( type );
     321                        types.push_back( type );
    325322                        // the qualifiers on the tuple type are the qualifiers that exist on all component types
    326323                        qualifiers &= type->get_qualifiers();
    327324                } // for
    328325                if ( exprs.empty() ) qualifiers = Type::Qualifiers();
    329                 return tupleType;
     326                return new TupleType( qualifiers, types );
    330327        }
    331328
    332329        TypeInstType * isTtype( Type * type ) {
    333330                if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( type ) ) {
    334                         if ( inst->get_baseType()->get_kind() == TypeDecl::Ttype ) {
     331                        if ( inst->get_baseType() && inst->get_baseType()->get_kind() == TypeDecl::Ttype ) {
    335332                                return inst;
    336333                        }
     
    356353                                maybeImpure = true;
    357354                        }
    358                         virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; }
     355                        virtual void visit( __attribute__((unused)) UntypedExpr * untypedExpr ) { maybeImpure = true; }
    359356                        bool maybeImpure = false;
    360357                };
Note: See TracChangeset for help on using the changeset viewer.