Changes in src/Tuples/TupleExpansion.cc [62423350:94a8123]
- File:
-
- 1 edited
-
src/Tuples/TupleExpansion.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
r62423350 r94a8123 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 17:35:04201713 // Update Count : 1 912 // Last Modified On : Thu Mar 16 08:05:17 2017 13 // Update Count : 15 14 14 // 15 15 … … 18 18 #include <cassert> 19 19 #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" 21 28 #include "Common/ScopedMap.h" 22 #include " GenPoly/DeclMutator.h"29 #include "ResolvExpr/typeops.h" 23 30 #include "InitTweak/GenInit.h" 24 31 #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"33 32 34 33 namespace Tuples { … … 83 82 }; 84 83 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; 88 90 }; 89 91 … … 114 116 replacer.mutateDeclarationList( translationUnit ); 115 117 116 PassVisitor<TupleIndexExpander>idxExpander;118 TupleIndexExpander idxExpander; 117 119 mutateAll( translationUnit, idxExpander ); 118 120 … … 191 193 commaExpr->set_arg1( nullptr ); 192 194 } 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 ) ); 195 197 addDeclaration( finished ); 196 198 // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N)) 197 199 // 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" ) ) ); 199 201 ConditionalExpr * condExpr = new ConditionalExpr( new VariableExpr( finished ), var->clone(), 200 202 new CommaExpr( new CommaExpr( assignUnq, assignFinished ), var->clone() ) ); … … 248 250 } 249 251 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 ); 252 254 assert( tuple ); 253 255 tupleExpr->set_tuple( nullptr ); … … 310 312 Type * makeTupleType( const std::list< Expression * > & exprs ) { 311 313 // 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(); 314 316 for ( Expression * expr : exprs ) { 315 317 assert( expr->get_result() ); 316 318 if ( expr->get_result()->isVoid() ) { 317 319 // if the type of any expr is void, the type of the entire tuple is void 320 delete tupleType; 318 321 return new VoidType( Type::Qualifiers() ); 319 322 } 320 323 Type * type = expr->get_result()->clone(); 321 t ypes.push_back( type );324 tupleType->get_types().push_back( type ); 322 325 // the qualifiers on the tuple type are the qualifiers that exist on all component types 323 326 qualifiers &= type->get_qualifiers(); 324 327 } // for 325 328 if ( exprs.empty() ) qualifiers = Type::Qualifiers(); 326 return new TupleType( qualifiers, types );329 return tupleType; 327 330 } 328 331 329 332 TypeInstType * isTtype( Type * type ) { 330 333 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 ) { 332 335 return inst; 333 336 } … … 353 356 maybeImpure = true; 354 357 } 355 virtual void visit( __attribute__((unused))UntypedExpr * untypedExpr ) { maybeImpure = true; }358 virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; } 356 359 bool maybeImpure = false; 357 360 };
Note:
See TracChangeset
for help on using the changeset viewer.