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