Changeset 1f44196 for src/SynTree
- Timestamp:
- Nov 29, 2016, 3:30:59 PM (9 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, stuck-waitfor-destruct, with_gc
- Children:
- 8e5724e
- Parents:
- 3a2128f (diff), 9129a84 (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. - Location:
- src/SynTree
- Files:
-
- 2 added
- 18 edited
-
AddressExpr.cc (modified) (2 diffs)
-
ApplicationExpr.cc (modified) (2 diffs)
-
CommaExpr.cc (modified) (1 diff)
-
CompoundStmt.cc (modified) (2 diffs)
-
Expression.cc (modified) (21 diffs)
-
Expression.h (modified) (9 diffs)
-
Initializer.h (modified) (1 diff)
-
Mutator.cc (modified) (20 diffs)
-
Mutator.h (modified) (2 diffs)
-
ReferenceToType.cc (modified) (1 diff)
-
SynTree.h (modified) (2 diffs)
-
TupleExpr.cc (modified) (3 diffs)
-
TupleType.cc (modified) (2 diffs)
-
Type.h (modified) (8 diffs)
-
TypeSubstitution.cc (modified) (3 diffs)
-
VarExprReplacer.cc (added)
-
VarExprReplacer.h (added)
-
Visitor.cc (modified) (11 diffs)
-
Visitor.h (modified) (2 diffs)
-
module.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AddressExpr.cc
r3a2128f r1f44196 19 19 20 20 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) { 21 for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i) {22 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );23 } // for21 if ( arg->has_result() ) { 22 set_result( new PointerType( Type::Qualifiers(), arg->get_result()->clone() ) ); 23 } 24 24 } 25 25 … … 35 35 if ( arg ) { 36 36 os << std::string( indent+2, ' ' ); 37 arg->print( os, indent+2 );37 arg->print( os, indent+2 ); 38 38 } // if 39 39 } -
src/SynTree/ApplicationExpr.cc
r3a2128f r1f44196 21 21 #include "TypeSubstitution.h" 22 22 #include "Common/utility.h" 23 23 #include "ResolvExpr/typeops.h" 24 24 25 25 ParamEntry::ParamEntry( const ParamEntry &other ) : … … 43 43 44 44 ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) { 45 PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); 46 assert( pointer ); 47 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); 48 assert( function ); 45 PointerType *pointer = safe_dynamic_cast< PointerType* >( funcExpr->get_result() ); 46 FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() ); 49 47 50 for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {51 get_results().push_back( (*i)->get_type()->clone() ); 52 } // for48 set_result( ResolvExpr::extractResultType( function ) ); 49 50 assert( has_result() ); 53 51 } 54 52 -
src/SynTree/CommaExpr.cc
r3a2128f r1f44196 23 23 // to false on all result types. Actually doing this causes some strange things 24 24 // to happen in later passes (particularly, Specialize, Lvalue, and Box). This needs to be looked into. 25 cloneAll( arg2->get_results(), get_results() ); 26 // for ( Type *& type : get_results() ) { 27 // type->set_isLvalue( false ); 28 // } 25 set_result( maybeClone( arg2->get_result() ) ); 26 // get_type->set_isLvalue( false ); 29 27 } 30 28 -
src/SynTree/CompoundStmt.cc
r3a2128f r1f44196 20 20 #include "Expression.h" 21 21 #include "Declaration.h" 22 #include "SynTree/VarExprReplacer.h" 22 23 23 24 using std::string; 24 25 using std::endl; 25 26 class VarExprReplacer : public Visitor {27 public:28 typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;29 private:30 const DeclMap & declMap;31 public:32 VarExprReplacer( const DeclMap & declMap ) : declMap( declMap ) {}33 34 // replace variable with new node from decl map35 virtual void visit( VariableExpr * varExpr ) {36 if ( declMap.count( varExpr->get_var() ) ) {37 varExpr->set_var( declMap.at( varExpr->get_var() ) );38 }39 }40 };41 42 26 43 27 CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) { … … 47 31 cloneAll( other.kids, kids ); 48 32 49 // when cloning a compound statement, we may end up cloning declarations which 50 // are referred to by VariableExprs throughout the block. Cloning a VariableExpr 51 // does a shallow copy, so the VariableExpr will end up pointing to the original 52 // declaration. If the original declaration is deleted, e.g. because the original 53 // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case, 54 // find all DeclarationWithType nodes (since a VariableExpr must point to a 55 // DeclarationWithType) in the original CompoundStmt and map them to the cloned 56 // node in the new CompoundStmt ('this'), then replace the Declarations referred to 57 // by each VariableExpr according to the constructed map. Note that only the declarations 58 // in the current level are collected into the map, because child CompoundStmts will 59 // recursively execute this routine. There may be more efficient ways of doing 60 // this. 61 VarExprReplacer::DeclMap declMap; 62 std::list< Statement * >::const_iterator origit = other.kids.begin(); 63 for ( Statement * s : kids ) { 64 assert( origit != other.kids.end() ); 65 if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( s ) ) { 66 DeclStmt * origDeclStmt = dynamic_cast< DeclStmt * >( *origit ); 67 assert( origDeclStmt ); 68 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * > ( declStmt->get_decl() ) ) { 69 DeclarationWithType * origdwt = dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() ); 70 assert( origdwt ); 71 declMap[ origdwt ] = dwt; 72 } 73 } 74 } 75 if ( ! declMap.empty() ) { 76 VarExprReplacer replacer( declMap ); 77 accept( replacer ); 78 } 33 // when cloning a compound statement, we may end up cloning declarations which 34 // are referred to by VariableExprs throughout the block. Cloning a VariableExpr 35 // does a shallow copy, so the VariableExpr will end up pointing to the original 36 // declaration. If the original declaration is deleted, e.g. because the original 37 // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case, 38 // find all DeclarationWithType nodes (since a VariableExpr must point to a 39 // DeclarationWithType) in the original CompoundStmt and map them to the cloned 40 // node in the new CompoundStmt ('this'), then replace the Declarations referred to 41 // by each VariableExpr according to the constructed map. Note that only the declarations 42 // in the current level are collected into the map, because child CompoundStmts will 43 // recursively execute this routine. There may be more efficient ways of doing 44 // this. 45 VarExprReplacer::DeclMap declMap; 46 std::list< Statement * >::const_iterator origit = other.kids.begin(); 47 for ( Statement * s : kids ) { 48 assert( origit != other.kids.end() ); 49 Statement * origStmt = *origit++; 50 if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( s ) ) { 51 DeclStmt * origDeclStmt = dynamic_cast< DeclStmt * >( origStmt ); 52 assert( origDeclStmt ); 53 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * > ( declStmt->get_decl() ) ) { 54 DeclarationWithType * origdwt = dynamic_cast< DeclarationWithType * > ( origDeclStmt->get_decl() ); 55 assert( origdwt ); 56 assert( dwt->get_name() == origdwt->get_name() ); 57 declMap[ origdwt ] = dwt; 58 } 59 } 60 } 61 if ( ! declMap.empty() ) { 62 VarExprReplacer replacer( declMap ); 63 accept( replacer ); 64 } 79 65 } 80 66 -
src/SynTree/Expression.cc
r3a2128f r1f44196 31 31 32 32 33 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {} 34 35 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) { 36 cloneAll( other.results, results ); 33 Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {} 34 35 Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) { 37 36 } 38 37 … … 40 39 delete env; 41 40 delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 42 deleteAll( results ); 43 } 44 45 void Expression::add_result( Type *t ) { 46 if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { 47 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); 48 } else { 49 results.push_back(t); 50 } // if 41 delete result; 51 42 } 52 43 … … 68 59 69 60 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { 70 add_result( constant.get_type()->clone() );61 set_result( constant.get_type()->clone() ); 71 62 } 72 63 … … 85 76 assert( var ); 86 77 assert( var->get_type() ); 87 add_result( var->get_type()->clone() ); 88 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 89 (*i)->set_isLvalue( true ); 90 } // for 78 Type * type = var->get_type()->clone(); 79 type->set_isLvalue( true ); 80 set_result( type ); 91 81 } 92 82 … … 110 100 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : 111 101 Expression( _aname ), expr(expr_), type(0), isType(false) { 112 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );102 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 113 103 } 114 104 115 105 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : 116 106 Expression( _aname ), expr(0), type(type_), isType(true) { 117 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );107 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 118 108 } 119 109 … … 141 131 AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) : 142 132 Expression( _aname ), expr(expr_), type(0), isType(false) { 143 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );133 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 144 134 } 145 135 146 136 AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : 147 137 Expression( _aname ), expr(0), type(type_), isType(true) { 148 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );138 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 149 139 } 150 140 … … 172 162 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) : 173 163 Expression( _aname ), type(type_), member(member_) { 174 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );164 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 175 165 } 176 166 … … 197 187 OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) : 198 188 Expression( _aname ), type(type_), member(member_) { 199 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );189 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 200 190 } 201 191 … … 229 219 230 220 OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) { 231 add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );221 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); 232 222 } 233 223 … … 284 274 285 275 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { 286 add_result(toType);276 set_result(toType); 287 277 } 288 278 289 279 CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { 280 set_result( new VoidType( Type::Qualifiers() ) ); 290 281 } 291 282 … … 303 294 arg->print(os, indent+2); 304 295 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; 305 if ( results.empty() ) { 306 os << std::string( indent+2, ' ' ) << "nothing" << std::endl; 296 os << std::string( indent+2, ' ' ); 297 if ( result->isVoid() ) { 298 os << "nothing"; 307 299 } else { 308 printAll(results, os, indent+2);300 result->print( os, indent+2 ); 309 301 } // if 310 Expression::print( os, indent ); 311 } 312 313 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : 302 os << std::endl; 303 Expression::print( os, indent ); 304 } 305 306 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) : 314 307 Expression( _aname ), member(_member), aggregate(_aggregate) {} 315 308 316 309 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : 317 Expression( other ), member( other.member), aggregate( maybeClone( other.aggregate ) ) {310 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 318 311 } 319 312 320 313 UntypedMemberExpr::~UntypedMemberExpr() { 321 314 delete aggregate; 315 delete member; 322 316 } 323 317 324 318 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 325 os << "Untyped Member Expression, with field: " << get_member(); 319 os << "Untyped Member Expression, with field: " << std::endl; 320 os << std::string( indent+2, ' ' ); 321 get_member()->print(os, indent+4); 322 os << std::string( indent+2, ' ' ); 326 323 327 324 Expression *agg = get_aggregate(); 328 os << " , from aggregate: ";325 os << "from aggregate: " << std::endl; 329 326 if (agg != 0) { 330 os << std::string( indent + 2, ' ' );331 agg->print(os, indent + 2);327 os << std::string( indent + 4, ' ' ); 328 agg->print(os, indent + 4); 332 329 } 333 330 os << std::string( indent+2, ' ' ); … … 338 335 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 339 336 Expression( _aname ), member(_member), aggregate(_aggregate) { 340 add_result( member->get_type()->clone() ); 341 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 342 (*i)->set_isLvalue( true ); 343 } // for 337 set_result( member->get_type()->clone() ); 338 get_result()->set_isLvalue( true ); 344 339 } 345 340 … … 372 367 } 373 368 374 375 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function) {}369 UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) : 370 Expression( _aname ), function(_function), args(_args) {} 376 371 377 372 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : … … 380 375 } 381 376 382 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :383 Expression( _aname ), function(_function), args(_args) {}384 385 377 UntypedExpr::~UntypedExpr() { 386 378 delete function; 387 379 deleteAll( args ); 388 380 } 381 382 UntypedExpr * UntypedExpr::createDeref( Expression * expr ) { 383 UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } ); 384 if ( Type * type = expr->get_result() ) { 385 Type * base = InitTweak::getPointerBase( type ); 386 if ( ! base ) { 387 std::cerr << type << std::endl; 388 } 389 assertf( base, "expected pointer type in dereference\n" ); 390 ret->set_result( maybeClone( base ) ); 391 } 392 return ret; 393 } 394 395 UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) { 396 assert( arg1 && arg2 ); 397 UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } ); 398 if ( arg1->get_result() && arg2->get_result() ) { 399 // if both expressions are typed, assumes that this assignment is a C bitwise assignment, 400 // so the result is the type of the RHS 401 ret->set_result( arg2->get_result()->clone() ); 402 } 403 return ret; 404 } 405 389 406 390 407 void UntypedExpr::print( std::ostream &os, int indent ) const { … … 419 436 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : 420 437 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { 421 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );438 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 422 439 } 423 440 … … 454 471 455 472 void ConditionalExpr::print( std::ostream &os, int indent ) const { 456 os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl; 473 os << "Conditional expression on: " << std::endl; 474 os << std::string( indent+2, ' ' ); 457 475 arg1->print( os, indent+2 ); 458 476 os << std::string( indent, ' ' ) << "First alternative:" << std::endl; 477 os << std::string( indent+2, ' ' ); 459 478 arg2->print( os, indent+2 ); 460 479 os << std::string( indent, ' ' ) << "Second alternative:" << std::endl; 480 os << std::string( indent+2, ' ' ); 461 481 arg3->print( os, indent+2 ); 462 482 os << std::endl; … … 477 497 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { 478 498 assert( callExpr ); 479 cloneAll( callExpr->get_results(), results ); 499 assert( callExpr->has_result() ); 500 set_result( callExpr->get_result()->clone() ); 480 501 } 481 502 … … 510 531 Expression * arg = InitTweak::getCallArg( callExpr, 0 ); 511 532 assert( arg ); 512 cloneAll( arg->get_results(), results);533 set_result( maybeClone( arg->get_result() ) ); 513 534 } 514 535 … … 530 551 531 552 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { 532 add_result( type->clone() ); 533 } 534 535 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {} 553 assert( type && initializer ); 554 set_result( type->clone() ); 555 } 556 557 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( other.type->clone() ), initializer( other.initializer->clone() ) {} 536 558 537 559 CompoundLiteralExpr::~CompoundLiteralExpr() { … … 542 564 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { 543 565 os << "Compound Literal Expression: " << std::endl; 544 if ( type ) type->print( os, indent + 2 ); 545 if ( initializer ) initializer->print( os, indent + 2 ); 566 os << std::string( indent+2, ' ' ); 567 type->print( os, indent + 2 ); 568 os << std::string( indent+2, ' ' ); 569 initializer->print( os, indent + 2 ); 546 570 } 547 571 … … 557 581 558 582 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 559 RangeExpr::RangeExpr( const RangeExpr &other ) : low( other.low->clone() ), high( other.high->clone() ) {}583 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 560 584 void RangeExpr::print( std::ostream &os, int indent ) const { 561 os << std::string( indent, ' ' ) <<"Range Expression: ";585 os << "Range Expression: "; 562 586 low->print( os, indent ); 563 587 os << " ... "; 564 588 high->print( os, indent ); 589 } 590 591 StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) { 592 assert( statements ); 593 std::list< Statement * > & body = statements->get_kids(); 594 if ( ! body.empty() ) { 595 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) { 596 set_result( maybeClone( exprStmt->get_expr()->get_result() ) ); 597 } 598 } 599 } 600 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {} 601 StmtExpr::~StmtExpr() { 602 delete statements; 603 } 604 void StmtExpr::print( std::ostream &os, int indent ) const { 605 os << "Statement Expression: " << std::endl << std::string( indent, ' ' ); 606 statements->print( os, indent+2 ); 607 } 608 609 610 long long UniqueExpr::count = 0; 611 UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) { 612 assert( expr ); 613 assert( count != -1 ); 614 if ( id == -1 ) id = count++; 615 if ( expr->get_result() ) { 616 set_result( expr->get_result()->clone() ); 617 } 618 } 619 UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { 620 } 621 UniqueExpr::~UniqueExpr() { 622 delete expr; 623 delete object; 624 delete var; 625 } 626 void UniqueExpr::print( std::ostream &os, int indent ) const { 627 os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' ); 628 get_expr()->print( os, indent+2 ); 629 if ( get_object() ) { 630 os << " with decl: "; 631 get_object()->printShort( os, indent+2 ); 632 } 565 633 } 566 634 -
src/SynTree/Expression.h
r3a2128f r1f44196 32 32 virtual ~Expression(); 33 33 34 std::list<Type *>& get_results() { return results; } 35 void add_result( Type *t ); 34 Type *& get_result() { return result; } 35 void set_result( Type *newValue ) { result = newValue; } 36 bool has_result() const { return result != nullptr; } 36 37 37 38 TypeSubstitution *get_env() const { return env; } … … 47 48 virtual void print( std::ostream &os, int indent = 0 ) const; 48 49 protected: 49 std::list<Type *> results;50 Type * result; 50 51 TypeSubstitution *env; 51 52 Expression* argName; // if expression is used as an argument, it can be "designated" by this name … … 98 99 class UntypedExpr : public Expression { 99 100 public: 100 UntypedExpr( Expression *function, Expression *_aname = nullptr );101 UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr ); 101 102 UntypedExpr( const UntypedExpr &other ); 102 UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );103 103 virtual ~UntypedExpr(); 104 104 … … 111 111 std::list<Expression*>& get_args() { return args; } 112 112 113 static UntypedExpr * createDeref( Expression * arg ); 114 static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 ); 115 113 116 virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); } 114 117 virtual void accept( Visitor &v ) { v.visit( this ); } … … 200 203 class UntypedMemberExpr : public Expression { 201 204 public: 202 UntypedMemberExpr( std::stringmember, Expression *aggregate, Expression *_aname = nullptr );205 UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr ); 203 206 UntypedMemberExpr( const UntypedMemberExpr &other ); 204 207 virtual ~UntypedMemberExpr(); 205 208 206 std::stringget_member() const { return member; }207 void set_member( const std::string &newValue ) { member = newValue; }209 Expression * get_member() const { return member; } 210 void set_member( Expression * newValue ) { member = newValue; } 208 211 Expression *get_aggregate() const { return aggregate; } 209 212 void set_aggregate( Expression *newValue ) { aggregate = newValue; } … … 214 217 virtual void print( std::ostream &os, int indent = 0 ) const; 215 218 private: 216 std::stringmember;219 Expression *member; 217 220 Expression *aggregate; 218 221 }; … … 483 486 }; 484 487 485 /// TupleExpr represents a tuple expression ( [a, b, c] )486 class TupleExpr : public Expression {487 public:488 TupleExpr( Expression *_aname = nullptr );489 TupleExpr( const TupleExpr &other );490 virtual ~TupleExpr();491 492 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }493 std::list<Expression*>& get_exprs() { return exprs; }494 495 virtual TupleExpr *clone() const { return new TupleExpr( *this ); }496 virtual void accept( Visitor &v ) { v.visit( this ); }497 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }498 virtual void print( std::ostream &os, int indent = 0 ) const;499 private:500 std::list<Expression*> exprs;501 };502 503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on504 class SolvedTupleExpr : public Expression {505 public:506 SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}507 SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );508 SolvedTupleExpr( const SolvedTupleExpr &other );509 virtual ~SolvedTupleExpr() {}510 511 std::list<Expression*> &get_exprs() { return exprs; }512 513 virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }514 virtual void accept( Visitor &v ) { v.visit( this ); }515 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }516 virtual void print( std::ostream &os, int indent = 0 ) const;517 private:518 std::list<Expression*> exprs;519 };520 521 488 /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 522 489 class TypeExpr : public Expression { … … 618 585 CompoundLiteralExpr( Type * type, Initializer * initializer ); 619 586 CompoundLiteralExpr( const CompoundLiteralExpr &other ); 620 ~CompoundLiteralExpr();587 virtual ~CompoundLiteralExpr(); 621 588 622 589 Type * get_type() const { return type; } … … 670 637 private: 671 638 Expression *low, *high; 639 }; 640 641 /// TupleExpr represents a tuple expression ( [a, b, c] ) 642 class TupleExpr : public Expression { 643 public: 644 TupleExpr( const std::list< Expression * > & exprs = std::list< Expression * >(), Expression *_aname = nullptr ); 645 TupleExpr( const TupleExpr &other ); 646 virtual ~TupleExpr(); 647 648 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } 649 std::list<Expression*>& get_exprs() { return exprs; } 650 651 virtual TupleExpr *clone() const { return new TupleExpr( *this ); } 652 virtual void accept( Visitor &v ) { v.visit( this ); } 653 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 654 virtual void print( std::ostream &os, int indent = 0 ) const; 655 private: 656 std::list<Expression*> exprs; 657 }; 658 659 /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer 660 class TupleIndexExpr : public Expression { 661 public: 662 TupleIndexExpr( Expression * tuple, unsigned int index ); 663 TupleIndexExpr( const TupleIndexExpr &other ); 664 virtual ~TupleIndexExpr(); 665 666 Expression * get_tuple() const { return tuple; } 667 int get_index() const { return index; } 668 TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; } 669 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; } 670 671 virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); } 672 virtual void accept( Visitor &v ) { v.visit( this ); } 673 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 674 virtual void print( std::ostream &os, int indent = 0 ) const; 675 private: 676 Expression * tuple; 677 unsigned int index; 678 }; 679 680 /// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer 681 class MemberTupleExpr : public Expression { 682 public: 683 MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr ); 684 MemberTupleExpr( const MemberTupleExpr &other ); 685 virtual ~MemberTupleExpr(); 686 687 Expression * get_member() const { return member; } 688 Expression * get_aggregate() const { return aggregate; } 689 MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; } 690 MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; } 691 692 virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); } 693 virtual void accept( Visitor &v ) { v.visit( this ); } 694 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 695 virtual void print( std::ostream &os, int indent = 0 ) const; 696 private: 697 Expression * member; 698 Expression * aggregate; 699 }; 700 701 /// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0;, or a tuple ctor/dtor expression 702 class TupleAssignExpr : public Expression { 703 public: 704 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr ); 705 TupleAssignExpr( const TupleAssignExpr &other ); 706 virtual ~TupleAssignExpr(); 707 708 std::list< Expression * > & get_assigns() { return assigns; } 709 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 710 711 virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); } 712 virtual void accept( Visitor &v ) { v.visit( this ); } 713 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 714 virtual void print( std::ostream &os, int indent = 0 ) const; 715 private: 716 std::list< Expression * > assigns; // assignment expressions that use tempDecls 717 std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs 718 }; 719 720 /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; }) 721 class StmtExpr : public Expression { 722 public: 723 StmtExpr( CompoundStmt *statements ); 724 StmtExpr( const StmtExpr & other ); 725 virtual ~StmtExpr(); 726 727 CompoundStmt * get_statements() const { return statements; } 728 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } 729 730 virtual StmtExpr *clone() const { return new StmtExpr( *this ); } 731 virtual void accept( Visitor &v ) { v.visit( this ); } 732 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 733 virtual void print( std::ostream &os, int indent = 0 ) const; 734 private: 735 CompoundStmt * statements; 736 }; 737 738 class UniqueExpr : public Expression { 739 public: 740 UniqueExpr( Expression * expr, long long idVal = -1 ); 741 UniqueExpr( const UniqueExpr & other ); 742 ~UniqueExpr(); 743 744 Expression * get_expr() const { return expr; } 745 UniqueExpr * set_expr( Expression * newValue ) { expr = newValue; return this; } 746 747 ObjectDecl * get_object() const { return object; } 748 UniqueExpr * set_object( ObjectDecl * newValue ) { object = newValue; return this; } 749 750 VariableExpr * get_var() const { return var; } 751 UniqueExpr * set_var( VariableExpr * newValue ) { var = newValue; return this; } 752 753 int get_id() const { return id; } 754 755 virtual UniqueExpr *clone() const { return new UniqueExpr( *this ); } 756 virtual void accept( Visitor &v ) { v.visit( this ); } 757 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 758 virtual void print( std::ostream &os, int indent = 0 ) const; 759 private: 760 Expression * expr; 761 ObjectDecl * object; 762 VariableExpr * var; 763 int id; 764 static long long count; 672 765 }; 673 766 -
src/SynTree/Initializer.h
r3a2128f r1f44196 23 23 24 24 #include <cassert> 25 26 const std::list<Expression*> noDesignators; 25 27 26 28 // Initializer: base class for object initializers (provide default values) -
src/SynTree/Mutator.cc
r3a2128f r1f44196 178 178 179 179 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 180 mutateAll( applicationExpr->get_results(), *this);180 applicationExpr->set_result( maybeMutate( applicationExpr->get_result(), *this ) ); 181 181 applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) ); 182 182 mutateAll( applicationExpr->get_args(), *this ); … … 185 185 186 186 Expression *Mutator::mutate( UntypedExpr *untypedExpr ) { 187 mutateAll( untypedExpr->get_results(), *this);187 untypedExpr->set_result( maybeMutate( untypedExpr->get_result(), *this ) ); 188 188 mutateAll( untypedExpr->get_args(), *this ); 189 189 return untypedExpr; … … 191 191 192 192 Expression *Mutator::mutate( NameExpr *nameExpr ) { 193 mutateAll( nameExpr->get_results(), *this);193 nameExpr->set_result( maybeMutate( nameExpr->get_result(), *this ) ); 194 194 return nameExpr; 195 195 } 196 196 197 197 Expression *Mutator::mutate( AddressExpr *addressExpr ) { 198 mutateAll( addressExpr->get_results(), *this);198 addressExpr->set_result( maybeMutate( addressExpr->get_result(), *this ) ); 199 199 addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) ); 200 200 return addressExpr; … … 202 202 203 203 Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) { 204 mutateAll( labelAddressExpr->get_results(), *this);204 labelAddressExpr->set_result( maybeMutate( labelAddressExpr->get_result(), *this ) ); 205 205 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) ); 206 206 return labelAddressExpr; … … 208 208 209 209 Expression *Mutator::mutate( CastExpr *castExpr ) { 210 mutateAll( castExpr->get_results(), *this);210 castExpr->set_result( maybeMutate( castExpr->get_result(), *this ) ); 211 211 castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) ); 212 212 return castExpr; … … 214 214 215 215 Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) { 216 mutateAll( memberExpr->get_results(), *this ); 216 memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) ); 217 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 218 memberExpr->set_member( maybeMutate( memberExpr->get_member(), *this ) ); 219 return memberExpr; 220 } 221 222 Expression *Mutator::mutate( MemberExpr *memberExpr ) { 223 memberExpr->set_result( maybeMutate( memberExpr->get_result(), *this ) ); 217 224 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 218 225 return memberExpr; 219 226 } 220 227 221 Expression *Mutator::mutate( MemberExpr *memberExpr ) {222 mutateAll( memberExpr->get_results(), *this );223 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );224 return memberExpr;225 }226 227 228 Expression *Mutator::mutate( VariableExpr *variableExpr ) { 228 mutateAll( variableExpr->get_results(), *this);229 variableExpr->set_result( maybeMutate( variableExpr->get_result(), *this ) ); 229 230 return variableExpr; 230 231 } 231 232 232 233 Expression *Mutator::mutate( ConstantExpr *constantExpr ) { 233 mutateAll( constantExpr->get_results(), *this);234 constantExpr->set_result( maybeMutate( constantExpr->get_result(), *this ) ); 234 235 // maybeMutate( constantExpr->get_constant(), *this ) 235 236 return constantExpr; … … 237 238 238 239 Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) { 239 mutateAll( sizeofExpr->get_results(), *this);240 sizeofExpr->set_result( maybeMutate( sizeofExpr->get_result(), *this ) ); 240 241 if ( sizeofExpr->get_isType() ) { 241 242 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) ); … … 247 248 248 249 Expression *Mutator::mutate( AlignofExpr *alignofExpr ) { 249 mutateAll( alignofExpr->get_results(), *this);250 alignofExpr->set_result( maybeMutate( alignofExpr->get_result(), *this ) ); 250 251 if ( alignofExpr->get_isType() ) { 251 252 alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) ); … … 257 258 258 259 Expression *Mutator::mutate( UntypedOffsetofExpr *offsetofExpr ) { 259 mutateAll( offsetofExpr->get_results(), *this);260 offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) ); 260 261 offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) ); 261 262 return offsetofExpr; … … 263 264 264 265 Expression *Mutator::mutate( OffsetofExpr *offsetofExpr ) { 265 mutateAll( offsetofExpr->get_results(), *this);266 offsetofExpr->set_result( maybeMutate( offsetofExpr->get_result(), *this ) ); 266 267 offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) ); 267 268 offsetofExpr->set_member( maybeMutate( offsetofExpr->get_member(), *this ) ); … … 270 271 271 272 Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) { 272 mutateAll( offsetPackExpr->get_results(), *this);273 offsetPackExpr->set_result( maybeMutate( offsetPackExpr->get_result(), *this ) ); 273 274 offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) ); 274 275 return offsetPackExpr; … … 276 277 277 278 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 278 mutateAll( attrExpr->get_results(), *this);279 attrExpr->set_result( maybeMutate( attrExpr->get_result(), *this ) ); 279 280 if ( attrExpr->get_isType() ) { 280 281 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) ); … … 286 287 287 288 Expression *Mutator::mutate( LogicalExpr *logicalExpr ) { 288 mutateAll( logicalExpr->get_results(), *this);289 logicalExpr->set_result( maybeMutate( logicalExpr->get_result(), *this ) ); 289 290 logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) ); 290 291 logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) ); … … 293 294 294 295 Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) { 295 mutateAll( conditionalExpr->get_results(), *this);296 conditionalExpr->set_result( maybeMutate( conditionalExpr->get_result(), *this ) ); 296 297 conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) ); 297 298 conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) ); … … 301 302 302 303 Expression *Mutator::mutate( CommaExpr *commaExpr ) { 303 mutateAll( commaExpr->get_results(), *this);304 commaExpr->set_result( maybeMutate( commaExpr->get_result(), *this ) ); 304 305 commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) ); 305 306 commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) ); … … 307 308 } 308 309 309 Expression *Mutator::mutate( TupleExpr *tupleExpr ) {310 mutateAll( tupleExpr->get_results(), *this );311 mutateAll( tupleExpr->get_exprs(), *this );312 return tupleExpr;313 }314 315 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {316 mutateAll( tupleExpr->get_results(), *this );317 mutateAll( tupleExpr->get_exprs(), *this );318 return tupleExpr;319 }320 321 310 Expression *Mutator::mutate( TypeExpr *typeExpr ) { 322 mutateAll( typeExpr->get_results(), *this);311 typeExpr->set_result( maybeMutate( typeExpr->get_result(), *this ) ); 323 312 typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) ); 324 313 return typeExpr; … … 340 329 341 330 Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) { 342 mutateAll( ctorExpr->get_results(), *this);331 ctorExpr->set_result( maybeMutate( ctorExpr->get_result(), *this ) ); 343 332 ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) ); 344 333 return ctorExpr; … … 346 335 347 336 Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) { 348 mutateAll( compLitExpr->get_results(), *this);337 compLitExpr->set_result( maybeMutate( compLitExpr->get_result(), *this ) ); 349 338 compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) ); 350 339 compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) ); … … 353 342 354 343 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 355 mutateAll( valofExpr->get_results(), *this);344 valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) ); 356 345 return valofExpr; 357 346 } … … 361 350 rangeExpr->set_high( maybeMutate( rangeExpr->get_high(), *this ) ); 362 351 return rangeExpr; 352 } 353 354 Expression *Mutator::mutate( TupleExpr *tupleExpr ) { 355 tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) ); 356 mutateAll( tupleExpr->get_exprs(), *this ); 357 return tupleExpr; 358 } 359 360 Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) { 361 tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) ); 362 tupleExpr->set_tuple( maybeMutate( tupleExpr->get_tuple(), *this ) ); 363 return tupleExpr; 364 } 365 366 Expression *Mutator::mutate( MemberTupleExpr *tupleExpr ) { 367 tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) ); 368 tupleExpr->set_member( maybeMutate( tupleExpr->get_member(), *this ) ); 369 tupleExpr->set_aggregate( maybeMutate( tupleExpr->get_aggregate(), *this ) ); 370 return tupleExpr; 371 } 372 373 Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) { 374 assignExpr->set_result( maybeMutate( assignExpr->get_result(), *this ) ); 375 mutateAll( assignExpr->get_tempDecls(), *this ); 376 mutateAll( assignExpr->get_assigns(), *this ); 377 return assignExpr; 378 } 379 380 Expression *Mutator::mutate( StmtExpr *stmtExpr ) { 381 stmtExpr->set_result( maybeMutate( stmtExpr->get_result(), *this ) ); 382 stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) ); 383 return stmtExpr; 384 } 385 386 Expression *Mutator::mutate( UniqueExpr *uniqueExpr ) { 387 uniqueExpr->set_result( maybeMutate( uniqueExpr->get_result(), *this ) ); 388 uniqueExpr->set_expr( maybeMutate( uniqueExpr->get_expr(), *this ) ); 389 return uniqueExpr; 363 390 } 364 391 -
src/SynTree/Mutator.h
r3a2128f r1f44196 71 71 virtual Expression* mutate( ConditionalExpr *conditionalExpr ); 72 72 virtual Expression* mutate( CommaExpr *commaExpr ); 73 virtual Expression* mutate( TupleExpr *tupleExpr );74 virtual Expression* mutate( SolvedTupleExpr *tupleExpr );75 73 virtual Expression* mutate( TypeExpr *typeExpr ); 76 74 virtual Expression* mutate( AsmExpr *asmExpr ); … … 80 78 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 81 79 virtual Expression* mutate( RangeExpr *rangeExpr ); 80 virtual Expression* mutate( TupleExpr *tupleExpr ); 81 virtual Expression* mutate( TupleIndexExpr *tupleExpr ); 82 virtual Expression* mutate( MemberTupleExpr *tupleExpr ); 83 virtual Expression* mutate( TupleAssignExpr *assignExpr ); 84 virtual Expression* mutate( StmtExpr * stmtExpr ); 85 virtual Expression* mutate( UniqueExpr * uniqueExpr ); 82 86 83 87 virtual Type* mutate( VoidType *basicType ); -
src/SynTree/ReferenceToType.cc
r3a2128f r1f44196 56 56 } 57 57 } // namespace 58 59 StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct ) : Parent( tq, baseStruct->get_name() ), baseStruct( baseStruct ) {} 58 60 59 61 std::string StructInstType::typeString() const { return "struct"; } -
src/SynTree/SynTree.h
r3a2128f r1f44196 76 76 class ConditionalExpr; 77 77 class CommaExpr; 78 class TupleExpr;79 class SolvedTupleExpr;80 78 class TypeExpr; 81 79 class AsmExpr; … … 85 83 class UntypedValofExpr; 86 84 class RangeExpr; 85 class TupleExpr; 86 class TupleIndexExpr; 87 class MemberTupleExpr; 88 class TupleAssignExpr; 89 class StmtExpr; 90 class UniqueExpr; 87 91 88 92 class Type; -
src/SynTree/TupleExpr.cc
r3a2128f r1f44196 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TupleExpr.cc -- 7 // TupleExpr.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 16 16 #include "Expression.h" 17 17 #include "Common/utility.h" 18 #include "Type.h" 19 #include "Declaration.h" 20 #include "Tuples/Tuples.h" 21 #include "VarExprReplacer.h" 18 22 19 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) { 23 TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { 24 if ( ! exprs.empty() ) { 25 if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) { 26 set_result( Tuples::makeTupleType( exprs ) ); 27 } 28 } 20 29 } 21 30 … … 29 38 30 39 void TupleExpr::print( std::ostream &os, int indent ) const { 31 os << std::string( indent, ' ' ) <<"Tuple:" << std::endl;40 os << "Tuple:" << std::endl; 32 41 printAll( exprs, os, indent+2 ); 33 42 Expression::print( os, indent ); 34 43 } 35 44 36 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) { 37 std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs)); 45 TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index ) { 46 TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() ); 47 assert( type->size() > index ); 48 set_result( (*std::next( type->get_types().begin(), index ))->clone() ); 49 get_result()->set_isLvalue( type->get_isLvalue() ); 38 50 } 39 51 40 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) { 41 cloneAll( other.exprs, exprs ); 52 TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) { 42 53 } 43 54 44 void SolvedTupleExpr::print( std::ostream &os, int indent ) const { 45 os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl; 46 printAll( exprs, os, indent+2 ); 55 TupleIndexExpr::~TupleIndexExpr() { 56 delete tuple; 57 } 58 59 void TupleIndexExpr::print( std::ostream &os, int indent ) const { 60 os << "Tuple Index Expression, with tuple:" << std::endl; 61 os << std::string( indent+2, ' ' ); 62 tuple->print( os, indent+2 ); 63 os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl; 47 64 Expression::print( os, indent ); 48 65 } 66 67 MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) { 68 set_result( maybeClone( member->get_result() ) ); // xxx - ??? 69 } 70 71 MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) { 72 } 73 74 MemberTupleExpr::~MemberTupleExpr() { 75 delete member; 76 delete aggregate; 77 } 78 79 void MemberTupleExpr::print( std::ostream &os, int indent ) const { 80 os << "Member Tuple Expression, with aggregate:" << std::endl; 81 os << std::string( indent+2, ' ' ); 82 aggregate->print( os, indent+2 ); 83 os << std::string( indent+2, ' ' ) << "with member: " << std::endl; 84 os << std::string( indent+2, ' ' ); 85 member->print( os, indent+2 ); 86 Expression::print( os, indent ); 87 } 88 89 90 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) { 91 set_result( Tuples::makeTupleType( assigns ) ); 92 } 93 94 TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) { 95 cloneAll( other.assigns, assigns ); 96 cloneAll( other.tempDecls, tempDecls ); 97 98 // clone needs to go into assigns and replace tempDecls 99 VarExprReplacer::DeclMap declMap; 100 std::list< ObjectDecl * >::const_iterator origit = other.tempDecls.begin(); 101 for ( ObjectDecl * temp : tempDecls ) { 102 assert( origit != other.tempDecls.end() ); 103 ObjectDecl * origTemp = *origit++; 104 assert( origTemp ); 105 assert( temp->get_name() == origTemp->get_name() ); 106 declMap[ origTemp ] = temp; 107 } 108 if ( ! declMap.empty() ) { 109 VarExprReplacer replacer( declMap ); 110 for ( Expression * assn : assigns ) { 111 assn->accept( replacer ); 112 } 113 } 114 } 115 116 TupleAssignExpr::~TupleAssignExpr() { 117 deleteAll( assigns ); 118 // deleteAll( tempDecls ); 119 } 120 121 void TupleAssignExpr::print( std::ostream &os, int indent ) const { 122 os << "Tuple Assignment Expression, with temporaries:" << std::endl; 123 printAll( tempDecls, os, indent+4 ); 124 os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl; 125 printAll( assigns, os, indent+4 ); 126 Expression::print( os, indent ); 127 } 128 129 49 130 50 131 // Local Variables: // -
src/SynTree/TupleType.cc
r3a2128f r1f44196 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TupleType.cc -- 7 // TupleType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 17 17 #include "Common/utility.h" 18 18 19 TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq) {19 TupleType::TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types ) : Type( tq ), types( types ) { 20 20 } 21 21 -
src/SynTree/Type.h
r3a2128f r1f44196 20 20 #include "Visitor.h" 21 21 #include "Mutator.h" 22 #include "Common/utility.h" 22 23 23 24 class Type { … … 27 28 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {} 28 29 30 Qualifiers &operator&=( const Qualifiers &other ); 29 31 Qualifiers &operator+=( const Qualifiers &other ); 30 32 Qualifiers &operator-=( const Qualifiers &other ); … … 63 65 void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; } 64 66 void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; } 65 std::list<TypeDecl*>& get_forall() { return forall; } 67 68 typedef std::list<TypeDecl *> ForallList; 69 ForallList& get_forall() { return forall; } 70 71 /// How many elemental types are represented by this type 72 virtual unsigned size() const { return 1; }; 73 virtual bool isVoid() const { return size() == 0; } 66 74 67 75 virtual Type *clone() const = 0; … … 71 79 private: 72 80 Qualifiers tq; 73 std::list<TypeDecl*>forall;81 ForallList forall; 74 82 }; 75 83 … … 77 85 public: 78 86 VoidType( const Type::Qualifiers &tq ); 87 88 virtual unsigned size() const { return 0; }; 79 89 80 90 virtual VoidType *clone() const { return new VoidType( *this ); } … … 234 244 public: 235 245 StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} 246 StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct ); 236 247 StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} 237 248 … … 348 359 class TupleType : public Type { 349 360 public: 350 TupleType( const Type::Qualifiers &tq );361 TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >() ); 351 362 TupleType( const TupleType& ); 352 363 virtual ~TupleType(); 353 364 365 typedef std::list<Type*> value_type; 366 typedef value_type::iterator iterator; 367 354 368 std::list<Type*>& get_types() { return types; } 369 virtual unsigned size() const { return types.size(); }; 370 371 iterator begin() { return types.begin(); } 372 iterator end() { return types.end(); } 355 373 356 374 virtual TupleType *clone() const { return new TupleType( *this ); } … … 442 460 }; 443 461 462 inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) { 463 isConst &= other.isConst; 464 isVolatile &= other.isVolatile; 465 isRestrict &= other.isRestrict; 466 isLvalue &= other.isLvalue; 467 isAtomic &= other.isAtomic; 468 return *this; 469 } 470 444 471 inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { 445 472 isConst |= other.isConst; -
src/SynTree/TypeSubstitution.cc
r3a2128f r1f44196 72 72 Type *TypeSubstitution::lookup( std::string formalType ) const { 73 73 TypeEnvType::const_iterator i = typeEnv.find( formalType ); 74 74 75 75 // break on not in substitution set 76 76 if ( i == typeEnv.end() ) return 0; 77 77 78 78 // attempt to transitively follow TypeInstType links. 79 79 while ( TypeInstType *actualType = dynamic_cast< TypeInstType* >( i->second ) ) { 80 80 const std::string& typeName = actualType->get_name(); 81 81 82 82 // break cycles in the transitive follow 83 83 if ( formalType == typeName ) break; 84 84 85 85 // Look for the type this maps to, returning previous mapping if none-such 86 86 i = typeEnv.find( typeName ); 87 87 if ( i == typeEnv.end() ) return actualType; 88 88 } 89 89 90 90 // return type from substitution set 91 91 return i->second; 92 92 93 93 #if 0 94 94 if ( i == typeEnv.end() ) { … … 149 149 // bind type variables from forall-qualifiers 150 150 if ( freeOnly ) { 151 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {151 for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 152 152 boundVars.insert( (*tyvar )->get_name() ); 153 153 } // for … … 163 163 // bind type variables from forall-qualifiers 164 164 if ( freeOnly ) { 165 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) {165 for ( Type::ForallList::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 166 166 boundVars.insert( (*tyvar )->get_name() ); 167 167 } // for -
src/SynTree/Visitor.cc
r3a2128f r1f44196 150 150 151 151 void Visitor::visit( ApplicationExpr *applicationExpr ) { 152 acceptAll( applicationExpr->get_results(), *this );152 maybeAccept( applicationExpr->get_result(), *this ); 153 153 maybeAccept( applicationExpr->get_function(), *this ); 154 154 acceptAll( applicationExpr->get_args(), *this ); … … 156 156 157 157 void Visitor::visit( UntypedExpr *untypedExpr ) { 158 acceptAll( untypedExpr->get_results(), *this );158 maybeAccept( untypedExpr->get_result(), *this ); 159 159 acceptAll( untypedExpr->get_args(), *this ); 160 160 } 161 161 162 162 void Visitor::visit( NameExpr *nameExpr ) { 163 acceptAll( nameExpr->get_results(), *this );163 maybeAccept( nameExpr->get_result(), *this ); 164 164 } 165 165 166 166 void Visitor::visit( AddressExpr *addressExpr ) { 167 acceptAll( addressExpr->get_results(), *this );167 maybeAccept( addressExpr->get_result(), *this ); 168 168 maybeAccept( addressExpr->get_arg(), *this ); 169 169 } 170 170 171 171 void Visitor::visit( LabelAddressExpr *labAddressExpr ) { 172 acceptAll( labAddressExpr->get_results(), *this );172 maybeAccept( labAddressExpr->get_result(), *this ); 173 173 maybeAccept( labAddressExpr->get_arg(), *this ); 174 174 } 175 175 176 176 void Visitor::visit( CastExpr *castExpr ) { 177 acceptAll( castExpr->get_results(), *this );177 maybeAccept( castExpr->get_result(), *this ); 178 178 maybeAccept( castExpr->get_arg(), *this ); 179 179 } 180 180 181 181 void Visitor::visit( UntypedMemberExpr *memberExpr ) { 182 acceptAll( memberExpr->get_results(), *this );182 maybeAccept( memberExpr->get_result(), *this ); 183 183 maybeAccept( memberExpr->get_aggregate(), *this ); 184 maybeAccept( memberExpr->get_member(), *this ); 184 185 } 185 186 186 187 void Visitor::visit( MemberExpr *memberExpr ) { 187 acceptAll( memberExpr->get_results(), *this );188 maybeAccept( memberExpr->get_result(), *this ); 188 189 maybeAccept( memberExpr->get_aggregate(), *this ); 189 190 } 190 191 191 192 void Visitor::visit( VariableExpr *variableExpr ) { 192 acceptAll( variableExpr->get_results(), *this );193 maybeAccept( variableExpr->get_result(), *this ); 193 194 } 194 195 195 196 void Visitor::visit( ConstantExpr *constantExpr ) { 196 acceptAll( constantExpr->get_results(), *this );197 maybeAccept( constantExpr->get_result(), *this ); 197 198 maybeAccept( constantExpr->get_constant(), *this ); 198 199 } 199 200 200 201 void Visitor::visit( SizeofExpr *sizeofExpr ) { 201 acceptAll( sizeofExpr->get_results(), *this );202 maybeAccept( sizeofExpr->get_result(), *this ); 202 203 if ( sizeofExpr->get_isType() ) { 203 204 maybeAccept( sizeofExpr->get_type(), *this ); … … 208 209 209 210 void Visitor::visit( AlignofExpr *alignofExpr ) { 210 acceptAll( alignofExpr->get_results(), *this );211 maybeAccept( alignofExpr->get_result(), *this ); 211 212 if ( alignofExpr->get_isType() ) { 212 213 maybeAccept( alignofExpr->get_type(), *this ); … … 217 218 218 219 void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) { 219 acceptAll( offsetofExpr->get_results(), *this );220 maybeAccept( offsetofExpr->get_result(), *this ); 220 221 maybeAccept( offsetofExpr->get_type(), *this ); 221 222 } 222 223 223 224 void Visitor::visit( OffsetofExpr *offsetofExpr ) { 224 acceptAll( offsetofExpr->get_results(), *this );225 maybeAccept( offsetofExpr->get_result(), *this ); 225 226 maybeAccept( offsetofExpr->get_type(), *this ); 226 227 maybeAccept( offsetofExpr->get_member(), *this ); … … 228 229 229 230 void Visitor::visit( OffsetPackExpr *offsetPackExpr ) { 230 acceptAll( offsetPackExpr->get_results(), *this );231 maybeAccept( offsetPackExpr->get_result(), *this ); 231 232 maybeAccept( offsetPackExpr->get_type(), *this ); 232 233 } 233 234 234 235 void Visitor::visit( AttrExpr *attrExpr ) { 235 acceptAll( attrExpr->get_results(), *this );236 maybeAccept( attrExpr->get_result(), *this ); 236 237 if ( attrExpr->get_isType() ) { 237 238 maybeAccept( attrExpr->get_type(), *this ); … … 242 243 243 244 void Visitor::visit( LogicalExpr *logicalExpr ) { 244 acceptAll( logicalExpr->get_results(), *this );245 maybeAccept( logicalExpr->get_result(), *this ); 245 246 maybeAccept( logicalExpr->get_arg1(), *this ); 246 247 maybeAccept( logicalExpr->get_arg2(), *this ); … … 248 249 249 250 void Visitor::visit( ConditionalExpr *conditionalExpr ) { 250 acceptAll( conditionalExpr->get_results(), *this );251 maybeAccept( conditionalExpr->get_result(), *this ); 251 252 maybeAccept( conditionalExpr->get_arg1(), *this ); 252 253 maybeAccept( conditionalExpr->get_arg2(), *this ); … … 255 256 256 257 void Visitor::visit( CommaExpr *commaExpr ) { 257 acceptAll( commaExpr->get_results(), *this );258 maybeAccept( commaExpr->get_result(), *this ); 258 259 maybeAccept( commaExpr->get_arg1(), *this ); 259 260 maybeAccept( commaExpr->get_arg2(), *this ); 260 261 } 261 262 262 void Visitor::visit( TupleExpr *tupleExpr ) {263 acceptAll( tupleExpr->get_results(), *this );264 acceptAll( tupleExpr->get_exprs(), *this );265 }266 267 void Visitor::visit( SolvedTupleExpr *tupleExpr ) {268 acceptAll( tupleExpr->get_results(), *this );269 acceptAll( tupleExpr->get_exprs(), *this );270 }271 272 263 void Visitor::visit( TypeExpr *typeExpr ) { 273 acceptAll( typeExpr->get_results(), *this );264 maybeAccept( typeExpr->get_result(), *this ); 274 265 maybeAccept( typeExpr->get_type(), *this ); 275 266 } … … 288 279 289 280 void Visitor::visit( ConstructorExpr * ctorExpr ) { 290 acceptAll( ctorExpr->get_results(), *this );281 maybeAccept( ctorExpr->get_result(), *this ); 291 282 maybeAccept( ctorExpr->get_callExpr(), *this ); 292 283 } 293 284 294 285 void Visitor::visit( CompoundLiteralExpr *compLitExpr ) { 295 acceptAll( compLitExpr->get_results(), *this );286 maybeAccept( compLitExpr->get_result(), *this ); 296 287 maybeAccept( compLitExpr->get_type(), *this ); 297 288 maybeAccept( compLitExpr->get_initializer(), *this ); … … 299 290 300 291 void Visitor::visit( UntypedValofExpr *valofExpr ) { 301 acceptAll( valofExpr->get_results(), *this );292 maybeAccept( valofExpr->get_result(), *this ); 302 293 maybeAccept( valofExpr->get_body(), *this ); 303 294 } … … 306 297 maybeAccept( rangeExpr->get_low(), *this ); 307 298 maybeAccept( rangeExpr->get_high(), *this ); 299 } 300 301 void Visitor::visit( TupleExpr *tupleExpr ) { 302 maybeAccept( tupleExpr->get_result(), *this ); 303 acceptAll( tupleExpr->get_exprs(), *this ); 304 } 305 306 void Visitor::visit( TupleIndexExpr *tupleExpr ) { 307 maybeAccept( tupleExpr->get_result(), *this ); 308 maybeAccept( tupleExpr->get_tuple(), *this ); 309 } 310 311 void Visitor::visit( MemberTupleExpr *tupleExpr ) { 312 maybeAccept( tupleExpr->get_result(), *this ); 313 maybeAccept( tupleExpr->get_member(), *this ); 314 maybeAccept( tupleExpr->get_aggregate(), *this ); 315 } 316 317 void Visitor::visit( TupleAssignExpr *assignExpr ) { 318 maybeAccept( assignExpr->get_result(), *this ); 319 acceptAll( assignExpr->get_tempDecls(), *this ); 320 acceptAll( assignExpr->get_assigns(), *this ); 321 } 322 323 void Visitor::visit( StmtExpr *stmtExpr ) { 324 maybeAccept( stmtExpr->get_result(), *this ); 325 maybeAccept( stmtExpr->get_statements(), *this ); 326 } 327 328 void Visitor::visit( UniqueExpr *uniqueExpr ) { 329 maybeAccept( uniqueExpr->get_result(), *this ); 330 maybeAccept( uniqueExpr->get_expr(), *this ); 308 331 } 309 332 -
src/SynTree/Visitor.h
r3a2128f r1f44196 71 71 virtual void visit( ConditionalExpr *conditionalExpr ); 72 72 virtual void visit( CommaExpr *commaExpr ); 73 virtual void visit( TupleExpr *tupleExpr );74 virtual void visit( SolvedTupleExpr *tupleExpr );75 73 virtual void visit( TypeExpr *typeExpr ); 76 74 virtual void visit( AsmExpr *asmExpr ); … … 80 78 virtual void visit( UntypedValofExpr *valofExpr ); 81 79 virtual void visit( RangeExpr *rangeExpr ); 80 virtual void visit( TupleExpr *tupleExpr ); 81 virtual void visit( TupleIndexExpr *tupleExpr ); 82 virtual void visit( MemberTupleExpr *tupleExpr ); 83 virtual void visit( TupleAssignExpr *assignExpr ); 84 virtual void visit( StmtExpr * stmtExpr ); 85 virtual void visit( UniqueExpr * uniqueExpr ); 82 86 83 87 virtual void visit( VoidType *basicType ); -
src/SynTree/module.mk
r3a2128f r1f44196 49 49 SynTree/AddStmtVisitor.cc \ 50 50 SynTree/TypeSubstitution.cc \ 51 SynTree/Attribute.cc 51 SynTree/Attribute.cc \ 52 SynTree/VarExprReplacer.cc 52 53
Note:
See TracChangeset
for help on using the changeset viewer.