Changeset e6cee92
- Timestamp:
- Jul 17, 2017, 3:25:58 PM (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:
- 795d450
- Parents:
- 7ebaa56
- Location:
- src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r7ebaa56 re6cee92 182 182 genCommaList( aggDecl->get_parameters().begin(), aggDecl->get_parameters().end() ); 183 183 output << ")" << endl; 184 output << indent; 184 185 } 185 186 … … 321 322 void CodeGenerator::visit( __attribute__((unused)) ConstructorInit * init ){ 322 323 assertf( ! genC, "ConstructorInit nodes should not reach code generation." ); 323 // xxx - generate something reasonable for constructor/destructor pairs 324 output << "<ctorinit>"; 324 // pseudo-output for constructor/destructor pairs 325 output << "<ctorinit>{" << std::endl << ++indent << "ctor: "; 326 maybeAccept( init->get_ctor(), *this ); 327 output << ", " << std::endl << indent << "dtor: "; 328 maybeAccept( init->get_dtor(), *this ); 329 output << std::endl << --indent << "}"; 325 330 } 326 331 -
src/CodeGen/CodeGenerator.h
r7ebaa56 re6cee92 20 20 #include <ostream> // for ostream, operator<< 21 21 #include <string> // for string 22 23 #include "Common/Indenter.h" // for Indenter 22 24 23 25 #include "SynTree/Declaration.h" // for DeclarationWithType (ptr only), Fun... -
src/Parser/DeclarationNode.cc
r7ebaa56 re6cee92 770 770 DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) { 771 771 if ( p ) { 772 assert( p->type->kind == TypeData::Pointer );772 assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference ); 773 773 if ( type ) { 774 774 switch ( type->kind ) { -
src/ResolvExpr/AlternativeFinder.cc
r7ebaa56 re6cee92 815 815 816 816 Expression * restructureCast( Expression * argExpr, Type * toType ) { 817 if ( argExpr->get_result()->size() > 1 && ! toType->isVoid() ) { 818 // Argument expression is a tuple and the target type is not void. Cast each member of the tuple 819 // to its corresponding target type, producing the tuple of those cast expressions. If there are 820 // more components of the tuple than components in the target type, then excess components do not 821 // come out in the result expression (but UniqueExprs ensure that side effects will still be done). 817 if ( argExpr->get_result()->size() > 1 && ! toType->isVoid() && ! dynamic_cast<ReferenceType *>( toType ) ) { 818 // Argument expression is a tuple and the target type is not void and not a reference type. 819 // Cast each member of the tuple to its corresponding target type, producing the tuple of those 820 // cast expressions. If there are more components of the tuple than components in the target type, 821 // then excess components do not come out in the result expression (but UniqueExprs ensure that 822 // side effects will still be done). 822 823 if ( Tuples::maybeImpure( argExpr ) && ! dynamic_cast< UniqueExpr * >( argExpr ) ) { 823 824 // expressions which may contain side effects require a single unique instance of the expression. -
src/ResolvExpr/CommonType.cc
r7ebaa56 re6cee92 81 81 CommonType visitor( type2, widenFirst, widenSecond, indexer, env, openVars ); 82 82 83 ReferenceType * refType1 = dynamic_cast< ReferenceType * >( type1 ); 84 ReferenceType * refType2 = dynamic_cast< ReferenceType * >( type2 ); 85 if ( (refType1 || refType2) && (! refType1 || ! refType2) ) { 86 // handle the case where exactly one of the types is a reference type specially 87 if ( refType1 ) { 88 return handleReference( refType1, type2, widenFirst, widenSecond, indexer, env, openVars ); 89 } else if ( refType2 ) { 90 return handleReference( refType2, type1, widenSecond, widenFirst, indexer, env, openVars ); 91 } 83 int depth1 = type1->referenceDepth(); 84 int depth2 = type2->referenceDepth(); 85 if ( depth1 > 0 || depth2 > 0 ) { 86 int diff = depth1-depth2; 87 // TODO: should it be possible for commonType to generate complicated conversions? I would argue no, only conversions that involve types of the same reference level or a difference of 1 should be allowed. 88 if ( diff > 1 || diff < -1 ) return nullptr; 89 90 // special case where one type has a reference depth of 1 larger than the other 91 if ( diff > 0 ) { 92 return handleReference( safe_dynamic_cast<ReferenceType *>( type1 ), type2, widenFirst, widenSecond, indexer, env, openVars ); 93 } else if ( diff < 0 ) { 94 return handleReference( safe_dynamic_cast<ReferenceType *>( type2 ), type1, widenSecond, widenFirst, indexer, env, openVars ); 95 } 96 // otherwise, both are reference types of the same depth and this is handled by the CommonType visitor. 92 97 } 93 98 -
src/ResolvExpr/Unify.cc
r7ebaa56 re6cee92 377 377 } // if 378 378 } else { 379 common = type1->clone(); 380 common->get_qualifiers() = tq1 | tq2; 379 381 result = true; 380 382 } // if -
src/SynTree/Expression.cc
r7ebaa56 re6cee92 502 502 } 503 503 504 AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}504 AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {} 505 505 506 506 -
src/SynTree/ReferenceType.cc
r7ebaa56 re6cee92 19 19 20 20 ReferenceType::ReferenceType( const Type::Qualifiers &tq, Type *base, const std::list< Attribute * > & attributes ) 21 : Type( tq, attributes ), base( base ) { 21 : Type( tq, attributes ), base( base ) { 22 assertf( base, "Reference Type with a null base created." ); 22 23 } 23 24 24 25 ReferenceType::ReferenceType( const ReferenceType &other ) 25 26 : Type( other ), base( maybeClone( other.base ) ) { 26 27 } 27 28 28 29 ReferenceType::~ReferenceType() { 29 delete base; 30 delete base; 31 } 32 33 int ReferenceType::referenceDepth() const { 34 return base->referenceDepth()+1; 30 35 } 31 36 32 37 void ReferenceType::print( std::ostream &os, int indent ) const { 33 34 35 36 37 38 Type::print( os, indent ); 39 os << "reference to "; 40 if ( base ) { 41 base->print( os, indent ); 42 } // if 38 43 } 39 44 -
src/SynTree/Type.cc
r7ebaa56 re6cee92 81 81 } 82 82 83 int Type::referenceDepth() const { return 0; } 84 83 85 void Type::print( std::ostream &os, int indent ) const { 84 86 if ( ! forall.empty() ) { -
src/SynTree/Type.h
r7ebaa56 re6cee92 163 163 Type * stripReferences(); 164 164 165 /// return the number of references occuring consecutively on the outermost layer of this type (i.e. do not count references nested within other types) 166 virtual int referenceDepth() const; 167 165 168 virtual bool isComplete() const { return true; } 166 169 … … 304 307 void set_base( Type *newValue ) { base = newValue; } 305 308 309 virtual int referenceDepth() const; 310 306 311 virtual ReferenceType *clone() const { return new ReferenceType( *this ); } 307 312 virtual void accept( Visitor & v ) { v.visit( this ); } -
src/SynTree/TypeExpr.cc
r7ebaa56 re6cee92 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TypeExpr.cc -- 7 // TypeExpr.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 21 21 } 22 22 23 TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) {23 TypeExpr::TypeExpr( const TypeExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) { 24 24 } 25 25 -
src/Tuples/Explode.h
r7ebaa56 re6cee92 27 27 28 28 namespace Tuples { 29 /// helper function used by explode to properly distribute30 /// '&' across a tuple expression31 Expression * distributeAddr( Expression * expr );32 33 29 /// helper function used by explode 34 30 template< typename OutputIterator > 35 31 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) { 36 if ( isTupleAssign ) {37 // tuple assignment needs AddressExprs to be recursively exploded to easily get at all of the components38 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {39 ResolvExpr::AltList alts;40 explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign );41 for ( ResolvExpr::Alternative & alt : alts ) {42 // distribute '&' over all components43 alt.expr = distributeAddr( alt.expr );44 *out++ = alt;45 }46 // in tuple assignment, still need to handle the other cases, but only if not already handled here (don't want to output too many alternatives)47 return;48 }49 }50 32 Type * res = expr->get_result(); 51 33 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) { -
src/Tuples/TupleAssignment.cc
r7ebaa56 re6cee92 77 77 if ( ! expr ) return false; 78 78 assert( expr->has_result() ); 79 return dynamic_cast< TupleType * >( expr->get_result() );79 return dynamic_cast< TupleType * >( expr->get_result()->stripReferences() ); 80 80 } 81 81 … … 89 89 } 90 90 91 bool pointsToTuple( Expression *expr ) { 91 bool refToTuple( Expression *expr ) { 92 assert( expr->get_result() ); 92 93 // also check for function returning tuple of reference types 93 94 if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 94 return pointsToTuple( castExpr->get_arg() );95 } else if ( AddressExpr *addr = dynamic_cast< AddressExpr * >( expr) ){96 return isTuple( addr->get_arg());95 return refToTuple( castExpr->get_arg() ); 96 } else { 97 return isTuple( expr ); 97 98 } 98 99 return false; … … 122 123 const ResolvExpr::Alternative & alt1 = ali->front(); 123 124 auto begin = std::next(ali->begin(), 1), end = ali->end(); 124 if ( pointsToTuple(alt1.expr) ) {125 if ( refToTuple(alt1.expr) ) { 125 126 if ( isMultAssign( begin, end ) ) { 126 127 matcher.reset( new MultipleAssignMatcher( *this, *ali ) ); … … 196 197 for ( ResolvExpr::Alternative & alt : lhs ) { 197 198 Expression *& expr = alt.expr; 198 Type * castType = expr->get_result()->clone(); 199 Type * type = InitTweak::getPointerBase( castType ); 200 assert( type ); 199 Type * type = expr->get_result()->clone(); 201 200 type->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 202 type->set_lvalue( true ); // xxx - might not need this 203 expr = new CastExpr( expr, castType ); 201 expr = new CastExpr( expr, new ReferenceType( Type::Qualifiers(), type ) ); 204 202 } 205 203 } … … 221 219 assert( left ); 222 220 std::list< Expression * > args; 223 args.push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( left ) )) );221 args.push_back( new VariableExpr( left ) ); 224 222 // args.push_back( new AddressExpr( new VariableExpr( left ) ) ); 225 223 if ( right ) args.push_back( new VariableExpr( right ) ); … … 241 239 assert( expr->has_result() && ! expr->get_result()->isVoid() ); 242 240 ObjectDecl * ret = new ObjectDecl( namer.newName(), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 243 ConstructorInit * ctorInit = InitTweak::genCtorInit( ret ); 244 ret->set_init( ctorInit ); 245 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 246 EnvRemover rm; // remove environments from subexpressions of StmtExprs 247 ctorInit->accept( rm ); 241 // if expression type is a reference, don't need to construct anything, a simple initializer is sufficient. 242 if ( ! dynamic_cast< ReferenceType * >( expr->get_result() ) ) { 243 ConstructorInit * ctorInit = InitTweak::genCtorInit( ret ); 244 ret->set_init( ctorInit ); 245 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 246 EnvRemover rm; // remove environments from subexpressions of StmtExprs 247 ctorInit->accept( rm ); 248 } 248 249 return ret; 249 250 }
Note: See TracChangeset
for help on using the changeset viewer.