Changes in / [fbfb38e:6812d89]
- Location:
- src
- Files:
-
- 4 deleted
- 50 edited
-
CodeGen/CodeGenerator.cc (modified) (36 diffs)
-
CodeGen/FixNames.cc (modified) (4 diffs)
-
CodeGen/OperatorTable.cc (modified) (2 diffs)
-
CodeGen/OperatorTable.h (modified) (2 diffs)
-
GenPoly/Box.cc (modified) (29 diffs)
-
GenPoly/CopyParams.cc (modified) (4 diffs)
-
GenPoly/Specialize.cc (modified) (2 diffs)
-
InitTweak/FixInit.cc (deleted)
-
InitTweak/FixInit.h (deleted)
-
InitTweak/InitModel.cc (modified) (3 diffs)
-
InitTweak/RemoveInit.cc (modified) (8 diffs)
-
InitTweak/RemoveInit.h (modified) (2 diffs)
-
InitTweak/module.mk (modified) (1 diff)
-
MakeLibCfa.cc (modified) (6 diffs)
-
Makefile.in (modified) (12 diffs)
-
Parser/DeclarationNode.cc (modified) (7 diffs)
-
Parser/InitializerNode.cc (modified) (5 diffs)
-
Parser/ParseNode.h (modified) (4 diffs)
-
Parser/TypeData.cc (modified) (3 diffs)
-
Parser/parser.cc (modified) (1 diff)
-
Parser/parser.yy (modified) (3 diffs)
-
ResolvExpr/AlternativeFinder.cc (modified) (2 diffs)
-
ResolvExpr/AlternativeFinder.h (modified) (3 diffs)
-
ResolvExpr/Resolver.cc (modified) (15 diffs)
-
ResolvExpr/Resolver.h (modified) (2 diffs)
-
SymTab/AddVisit.h (modified) (2 diffs)
-
SymTab/Autogen.cc (deleted)
-
SymTab/Autogen.h (deleted)
-
SymTab/Validate.cc (modified) (9 diffs)
-
SymTab/module.mk (modified) (2 diffs)
-
SynTree/CommaExpr.cc (modified) (2 diffs)
-
SynTree/CompoundStmt.cc (modified) (3 diffs)
-
SynTree/Declaration.h (modified) (4 diffs)
-
SynTree/DeclarationWithType.cc (modified) (2 diffs)
-
SynTree/Expression.cc (modified) (3 diffs)
-
SynTree/Expression.h (modified) (3 diffs)
-
SynTree/Initializer.cc (modified) (4 diffs)
-
SynTree/Initializer.h (modified) (7 diffs)
-
SynTree/Mutator.cc (modified) (3 diffs)
-
SynTree/Mutator.h (modified) (4 diffs)
-
SynTree/ObjectDecl.cc (modified) (4 diffs)
-
SynTree/SynTree.h (modified) (3 diffs)
-
SynTree/Visitor.cc (modified) (3 diffs)
-
SynTree/Visitor.h (modified) (4 diffs)
-
examples/vector_int.c (modified) (2 diffs)
-
examples/vector_int.h (modified) (2 diffs)
-
examples/vector_test.c (modified) (2 diffs)
-
initialization.txt (modified) (1 diff)
-
libcfa/Makefile.am (modified) (3 diffs)
-
libcfa/Makefile.in (modified) (3 diffs)
-
libcfa/fstream.c (modified) (4 diffs)
-
libcfa/iostream.c (modified) (8 diffs)
-
libcfa/prelude.cf (modified) (3 diffs)
-
main.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CodeGenerator.cc -- 7 // CodeGenerator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 17:10:21201613 // Update Count : 2 5511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:32:16 2016 13 // Update Count : 243 14 14 // 15 15 … … 67 67 string mangleName( DeclarationWithType *decl ) { 68 68 if ( decl->get_mangleName() != "" ) { 69 // need to incorporate scope level in order to differentiate names for destructors 70 return decl->get_scopedMangleName(); 69 return decl->get_mangleName(); 71 70 } else { 72 71 return decl->get_name(); … … 100 99 handleStorageClass( objectDecl ); 101 100 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); 102 101 103 102 if ( objectDecl->get_init() ) { 104 103 output << " = "; … … 114 113 if ( aggDecl->get_name() != "" ) 115 114 output << aggDecl->get_name(); 116 115 117 116 std::list< Declaration * > &memb = aggDecl->get_members(); 118 117 … … 120 119 output << " {" << endl; 121 120 122 cur_indent += CodeGenerator::tabsize; 121 cur_indent += CodeGenerator::tabsize; 123 122 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 124 output << indent; 123 output << indent; 125 124 (*i)->accept( *this ); 126 125 output << ";" << endl; 127 126 } 128 127 129 cur_indent -= CodeGenerator::tabsize; 128 cur_indent -= CodeGenerator::tabsize; 130 129 131 130 output << indent << "}"; … … 142 141 handleAggregate( aggregateDecl ); 143 142 } 144 143 145 144 void CodeGenerator::visit( EnumDecl *aggDecl ) { 146 145 output << "enum "; … … 148 147 if ( aggDecl->get_name() != "" ) 149 148 output << aggDecl->get_name(); 150 149 151 150 std::list< Declaration* > &memb = aggDecl->get_members(); 152 151 … … 154 153 output << " {" << endl; 155 154 156 cur_indent += CodeGenerator::tabsize; 155 cur_indent += CodeGenerator::tabsize; 157 156 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 158 157 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 159 158 assert( obj ); 160 output << indent << mangleName( obj ); 159 output << indent << mangleName( obj ); 161 160 if ( obj->get_init() ) { 162 161 output << " = "; … … 166 165 } // for 167 166 168 cur_indent -= CodeGenerator::tabsize; 167 cur_indent -= CodeGenerator::tabsize; 169 168 170 169 output << indent << "}"; 171 170 } // if 172 171 } 173 172 174 173 void CodeGenerator::visit( TraitDecl *aggregateDecl ) {} 175 174 176 175 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 177 176 output << "typedef "; 178 177 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 179 178 } 180 179 181 180 void CodeGenerator::visit( TypeDecl *typeDecl ) { 182 181 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, … … 214 213 printDesignators( init->get_designators() ); 215 214 output << "{ "; 216 if ( init->begin_initializers() == init->end_initializers() ) { 217 // illegal to leave initializer list empty for scalar initializers, 218 // but always legal to have 0 219 output << "0"; 220 } else { 221 genCommaList( init->begin_initializers(), init->end_initializers() ); 222 } 215 genCommaList( init->begin_initializers(), init->end_initializers() ); 223 216 output << " }"; 224 217 } 225 218 226 void CodeGenerator::visit( Constant *constant ) { 219 void CodeGenerator::visit( Constant *constant ) { 227 220 output << constant->get_value() ; 228 221 } … … 238 231 case OT_POSTFIXASSIGN: 239 232 case OT_INFIXASSIGN: 240 case OT_CTOR:241 233 { 242 234 assert( arg != applicationExpr->get_args().end() ); 243 235 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 244 // remove & from first assignment/ctor argument236 245 237 *arg = addrExpr->get_arg(); 246 238 } else { 247 // no address-of operator, so must be a pointer - add dereference248 239 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) ); 249 240 newExpr->get_args().push_back( *arg ); … … 252 243 break; 253 244 } 254 245 255 246 default: 256 247 // do nothing 257 248 ; 258 249 } 259 250 260 251 switch ( opInfo.type ) { 261 252 case OT_INDEX: … … 266 257 output << "]"; 267 258 break; 268 259 269 260 case OT_CALL: 270 261 // there are no intrinsic definitions of the function call operator 271 262 assert( false ); 272 263 break; 273 274 case OT_CTOR: 275 if ( applicationExpr->get_args().size() == 1 ) { 276 // the expression fed into a single parameter constructor may contain 277 // side effects - output as a void expression 278 output << "((void)("; 279 (*arg++)->accept( *this ); 280 output << ")) /* ?{} */"; 281 } else if ( applicationExpr->get_args().size() == 2 ) { 282 // intrinsic constructors are essentially bitwise assignment 283 output << "("; 284 (*arg++)->accept( *this ); 285 output << opInfo.symbol; 286 (*arg)->accept( *this ); 287 output << ") /* ?{} */"; 288 } else { 289 // not constructors with 0 or more than 2 parameters 290 assert( false ); 291 } 292 break; 293 294 case OT_DTOR: 295 // intrinsic destructors do nothing - don't generate any code 296 output << " /* " << dynamic_cast<VariableExpr*>(applicationExpr->get_function())->get_var()->get_name() << " */"; 297 break; 298 264 299 265 case OT_PREFIX: 300 266 case OT_PREFIXASSIGN: … … 305 271 output << ")"; 306 272 break; 307 273 308 274 case OT_POSTFIX: 309 275 case OT_POSTFIXASSIGN: … … 312 278 output << opInfo.symbol; 313 279 break; 314 315 280 316 281 case OT_INFIX: … … 323 288 output << ")"; 324 289 break; 325 290 326 291 case OT_CONSTANT: 327 292 case OT_LABELADDRESS: … … 342 307 } // if 343 308 } 344 309 345 310 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 346 311 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 356 321 output << "]"; 357 322 break; 358 323 359 324 case OT_CALL: 360 325 assert( false ); 361 362 case OT_CTOR: 363 case OT_DTOR: 364 // intrinsic constructors should never be called 365 // intrinsic destructors do nothing 366 break; 367 326 break; 327 368 328 case OT_PREFIX: 369 329 case OT_PREFIXASSIGN: … … 375 335 output << ")"; 376 336 break; 377 337 378 338 case OT_POSTFIX: 379 339 case OT_POSTFIXASSIGN: … … 382 342 output << opInfo.symbol; 383 343 break; 384 344 385 345 case OT_INFIX: 386 346 case OT_INFIXASSIGN: … … 392 352 output << ")"; 393 353 break; 394 354 395 355 case OT_CONSTANT: 396 356 // there are no intrinsic definitions of 0 or 1 as functions … … 410 370 } // if 411 371 } 412 372 413 373 void CodeGenerator::visit( NameExpr *nameExpr ) { 414 374 OperatorInfo opInfo; … … 420 380 } // if 421 381 } 422 382 423 383 void CodeGenerator::visit( AddressExpr *addressExpr ) { 424 384 output << "(&"; … … 449 409 output << ")"; 450 410 } 451 411 452 412 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 453 413 assert( false ); 454 414 } 455 415 456 416 void CodeGenerator::visit( MemberExpr *memberExpr ) { 457 417 memberExpr->get_aggregate()->accept( *this ); 458 418 output << "." << mangleName( memberExpr->get_member() ); 459 419 } 460 420 461 421 void CodeGenerator::visit( VariableExpr *variableExpr ) { 462 422 OperatorInfo opInfo; … … 467 427 } // if 468 428 } 469 429 470 430 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 471 431 assert( constantExpr->get_constant() ); 472 432 constantExpr->get_constant()->accept( *this ); 473 433 } 474 434 475 435 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 476 436 output << "sizeof("; … … 509 469 assert( false && "OffsetPackExpr should not reach code generation" ); 510 470 } 511 471 512 472 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 513 473 output << "("; … … 521 481 output << ")"; 522 482 } 523 483 524 484 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 525 485 output << "("; … … 531 491 output << ")"; 532 492 } 533 493 534 494 void CodeGenerator::visit( CommaExpr *commaExpr ) { 535 495 output << "("; … … 539 499 output << ")"; 540 500 } 541 501 542 502 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 543 503 544 504 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 545 505 … … 572 532 } 573 533 } 574 cur_indent -= CodeGenerator::tabsize; 534 cur_indent -= CodeGenerator::tabsize; 575 535 576 536 output << indent << "}"; … … 578 538 579 539 void CodeGenerator::visit( ExprStmt *exprStmt ) { 580 // I don't see why this check is necessary. 581 // If this starts to cause problems then put it back in, 540 // I don't see why this check is necessary. 541 // If this starts to cause problems then put it back in, 582 542 // with an explanation 583 543 assert( exprStmt ); … … 629 589 switchStmt->get_condition()->accept( *this ); 630 590 output << " ) "; 631 591 632 592 output << "{" << std::endl; 633 593 cur_indent += CodeGenerator::tabsize; … … 649 609 } // if 650 610 output << ":\n"; 651 611 652 612 std::list<Statement *> sts = caseStmt->get_statements(); 653 613 … … 666 626 if ( ! branchStmt->get_target().empty() ) 667 627 output << "goto " << branchStmt->get_target(); 668 else { 628 else { 669 629 if ( branchStmt->get_computedTarget() != 0 ) { 670 630 output << "goto *"; … … 717 677 718 678 void CodeGenerator::visit( ForStmt *forStmt ) { 719 // initialization is always hoisted, so don't 720 // bother doing anything with that 679 // initialization is always hoisted, so don't 680 // bother doing anything with that 721 681 output << "for (;"; 722 682 … … 742 702 void CodeGenerator::visit( DeclStmt *declStmt ) { 743 703 declStmt->get_decl()->accept( *this ); 744 704 745 705 if ( doSemicolon( declStmt->get_decl() ) ) { 746 706 output << ";"; -
src/CodeGen/FixNames.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixNames.cc -- 7 // FixNames.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 11 15:38:10 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 23:36:42 2015 13 13 // Update Count : 1 14 14 // … … 26 26 virtual void visit( ObjectDecl *objectDecl ); 27 27 virtual void visit( FunctionDecl *functionDecl ); 28 29 virtual void visit( CompoundStmt *compoundStmt );30 31 private:32 int scopeLevel = 1;33 34 void fixDWT( DeclarationWithType *dwt );35 28 }; 36 29 … … 40 33 } 41 34 42 void FixNames::fixDWT( DeclarationWithType *dwt ) {35 void fixDWT( DeclarationWithType *dwt ) { 43 36 if ( dwt->get_name() != "" ) { 44 37 if ( LinkageSpec::isDecoratable( dwt->get_linkage() ) ) { 45 38 dwt->set_mangleName( SymTab::Mangler::mangle( dwt ) ); 46 dwt->set_scopeLevel( scopeLevel );47 39 } // if 48 40 } // if … … 58 50 fixDWT( functionDecl ); 59 51 } 60 61 void FixNames::visit( CompoundStmt *compoundStmt ) {62 scopeLevel++;63 Visitor::visit( compoundStmt );64 scopeLevel--;65 }66 52 } // namespace CodeGen 67 53 -
src/CodeGen/OperatorTable.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // OperatorTable.cc -- 7 // OperatorTable.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T hu Apr 14 16:48:27 201613 // Update Count : 911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 23 17:41:14 2015 13 // Update Count : 5 14 14 // 15 15 … … 21 21 const OperatorInfo tableValues[] = { 22 22 { "?[?]", "", "_operator_index", OT_INDEX }, 23 { "?{}", "=", "_constructor", OT_CTOR },24 { "^?{}", "", "_destructor", OT_DTOR },25 23 { "?()", "", "_operator_call", OT_CALL }, 26 24 { "?++", "++", "_operator_postincr", OT_POSTFIXASSIGN }, -
src/CodeGen/OperatorTable.h
rfbfb38e r6812d89 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Jun 24 16:17:57 201513 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 23 16:09:27 2015 13 // Update Count : 3 14 14 // 15 15 … … 22 22 enum OperatorType { 23 23 OT_INDEX, 24 OT_CTOR,25 OT_DTOR,26 24 OT_CALL, 27 25 OT_PREFIX, -
src/GenPoly/Box.cc
rfbfb38e r6812d89 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 18 13:22:15201613 // Update Count : 2 9511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 5 16:45:07 2016 13 // Update Count : 286 14 14 // 15 15 … … 133 133 Value *lookup( Key *key, const std::list< TypeExpr* >& params ) const { 134 134 TypeList typeList( params ); 135 135 136 136 // scan scopes for matches to the key 137 137 for ( typename InnerMap::const_iterator insts = instantiations.find( key ); insts != instantiations.end(); insts = instantiations.findNext( insts, key ) ) { … … 160 160 virtual Declaration *mutate( UnionDecl *unionDecl ); 161 161 }; 162 162 163 163 /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call 164 164 class Pass1 : public PolyMutator { … … 208 208 ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps; ///< Currently known assignment operators 209 209 ScopedMap< std::string, DeclarationWithType* > adapters; ///< Set of adapter functions in the current scope 210 210 211 211 DeclarationWithType *retval; 212 212 bool useRetval; … … 226 226 virtual Type *mutate( PointerType *pointerType ); 227 227 virtual Type *mutate( FunctionType *funcType ); 228 228 229 229 private: 230 230 void addAdapters( FunctionType *functionType ); … … 297 297 /// Exits the type-variable scope 298 298 void endTypeScope(); 299 299 300 300 ScopedSet< std::string > knownLayouts; ///< Set of generic type layouts known in the current scope, indexed by sizeofName 301 301 ScopedSet< std::string > knownOffsets; ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName … … 351 351 PolyGenericCalculator polyCalculator; 352 352 Pass3 pass3; 353 353 354 354 layoutBuilder.mutateDeclarationList( translationUnit ); 355 355 mutateTranslationUnit/*All*/( translationUnit, pass1 ); … … 370 370 return functionDecl; 371 371 } 372 372 373 373 /// Get a list of type declarations that will affect a layout function 374 374 std::list< TypeDecl* > takeOtypeOnly( std::list< TypeDecl* > &decls ) { … … 380 380 } 381 381 } 382 382 383 383 return otypeDecls; 384 384 } … … 387 387 void addOtypeParams( FunctionType *layoutFnType, std::list< TypeDecl* > &otypeParams ) { 388 388 BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 389 389 390 390 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) { 391 391 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param ); … … 444 444 return makeCond( ifCond, ifExpr ); 445 445 } 446 446 447 447 /// adds an expression to a compound statement 448 448 void addExpr( CompoundStmt *stmts, Expression *expr ) { … … 454 454 stmts->get_kids().push_back( stmt ); 455 455 } 456 456 457 457 Declaration *LayoutFunctionBuilder::mutate( StructDecl *structDecl ) { 458 458 // do not generate layout function for "empty" tag structs … … 467 467 BasicType *sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 468 468 PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType ); 469 469 470 470 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( structDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 471 471 layoutFnType->get_parameters().push_back( sizeParam ); … … 497 497 addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), new AlignofExpr( memberType->clone() ) ) ); 498 498 } 499 499 500 500 // place current size in the current offset index 501 501 addExpr( layoutDecl->get_statements(), makeOp( "?=?", makeOp( "?[?]", new VariableExpr( offsetParam ), new ConstantExpr( Constant::from( n_members ) ) ), … … 505 505 // add member size to current size 506 506 addExpr( layoutDecl->get_statements(), makeOp( "?+=?", derefVar( sizeParam ), new SizeofExpr( memberType->clone() ) ) ); 507 507 508 508 // take max of member alignment and global alignment 509 509 addStmt( layoutDecl->get_statements(), makeAssignMax( derefVar( alignParam ), new AlignofExpr( memberType->clone() ) ) ); … … 515 515 return structDecl; 516 516 } 517 517 518 518 Declaration *LayoutFunctionBuilder::mutate( UnionDecl *unionDecl ) { 519 519 // do not generate layout function for "empty" tag unions 520 520 if ( unionDecl->get_members().empty() ) return unionDecl; 521 521 522 522 // get parameters that can change layout, exiting early if none 523 523 std::list< TypeDecl* > otypeParams = takeOtypeOnly( unionDecl->get_parameters() ); … … 528 528 BasicType *sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 529 529 PointerType *sizeAlignOutType = new PointerType( Type::Qualifiers(), sizeAlignType ); 530 530 531 531 ObjectDecl *sizeParam = new ObjectDecl( sizeofName( unionDecl->get_name() ), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, sizeAlignOutType, 0 ); 532 532 layoutFnType->get_parameters().push_back( sizeParam ); … … 545 545 assert( dwt ); 546 546 Type *memberType = dwt->get_type(); 547 547 548 548 // take max member size and global size 549 549 addStmt( layoutDecl->get_statements(), makeAssignMax( derefVar( sizeParam ), new SizeofExpr( memberType->clone() ) ) ); 550 550 551 551 // take max of member alignment and global alignment 552 552 addStmt( layoutDecl->get_statements(), makeAssignMax( derefVar( alignParam ), new AlignofExpr( memberType->clone() ) ) ); … … 558 558 return unionDecl; 559 559 } 560 560 561 561 ////////////////////////////////////////// Pass1 //////////////////////////////////////////////////// 562 562 … … 619 619 return 0; 620 620 } 621 621 622 622 /// returns T if the given declaration is: (*?=?)(T *, T) for some type T (return not checked, but maybe should be), NULL otherwise 623 623 /// Only picks assignments where neither parameter is cv-qualified … … 631 631 Type *paramType2 = funType->get_parameters().back()->get_type(); 632 632 if ( paramType2->get_qualifiers() != defaultQualifiers ) return 0; 633 633 634 634 if ( PointerType *pointerType = dynamic_cast< PointerType* >( paramType1 ) ) { 635 635 Type *baseType1 = pointerType->get_base(); … … 784 784 arg++; 785 785 } else { 786 /// xxx - should this be an assertion?787 786 throw SemanticError( "unbound type variable in application ", appExpr ); 788 787 } // if … … 804 803 passArgTypeVars( appExpr, polyRetType, concRetType, arg, exprTyVars, seenTypes ); 805 804 } 806 805 807 806 // add type information args for presently unseen types in parameter list 808 807 for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) { … … 883 882 assert( env ); 884 883 Type *concrete = replaceWithConcrete( appExpr, polyType ); 885 // add out-parameter for return value 884 // add out-parameter for return value 886 885 return addRetParam( appExpr, function, concrete, arg ); 887 886 } … … 1367 1366 return new VariableExpr( functionObj ); 1368 1367 } 1369 1368 1370 1369 Statement * Pass1::mutate( ReturnStmt *returnStmt ) { 1371 1370 if ( retval && returnStmt->get_expr() ) { … … 1887 1886 } 1888 1887 } 1889 1888 1890 1889 Type *ret = Mutator::mutate( funcType ); 1891 1890 … … 1906 1905 1907 1906 std::list<Expression*> designators; 1908 objectDecl->set_init( new SingleInit( alloc, designators , false ) ); // not constructed1907 objectDecl->set_init( new SingleInit( alloc, designators ) ); 1909 1908 } 1910 1909 } … … 1947 1946 return derefdVar; 1948 1947 } 1949 1948 1950 1949 Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) { 1951 1950 // mutate, exiting early if no longer MemberExpr … … 2145 2144 Type *ty = offsetofExpr->get_type(); 2146 2145 if ( ! findGeneric( ty ) ) return offsetofExpr; 2147 2146 2148 2147 if ( StructInstType *structType = dynamic_cast< StructInstType* >( ty ) ) { 2149 2148 // replace offsetof expression by index into offset array -
src/GenPoly/CopyParams.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CopyParams.cc -- 7 // CopyParams.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz11 // Last Modified By : Peter A. Buhr 12 12 // Last Modified On : Tue May 19 07:33:31 2015 13 13 // Update Count : 1 … … 29 29 public: 30 30 CopyParams(); 31 31 32 32 virtual void visit( FunctionDecl *funcDecl ); 33 33 virtual void visit( AddressExpr *addrExpr ); … … 50 50 if ( funcDecl->get_statements() ) { 51 51 funcDecl->get_statements()->accept( *this ); 52 52 53 53 if ( ! modVars.empty() ) { 54 54 std::map< std::string, DeclarationWithType* > assignOps; … … 57 57 if ( (*tyVar)->get_kind() == TypeDecl::Any ) { 58 58 assert( !(*tyVar)->get_assertions().empty() ); 59 assert( (*tyVar)->get_assertions().front()->get_name() == "?=?" );60 59 assignOps[ (*tyVar)->get_name() ] = (*tyVar)->get_assertions().front(); 61 60 } // if -
src/GenPoly/Specialize.cc
rfbfb38e r6812d89 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 20 1 3:00:00201613 // Update Count : 2412 // Last Modified On : Wed Jan 20 12:40:33 2016 13 // Update Count : 18 14 14 // 15 15 … … 142 142 143 143 Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) { 144 assert( ! actual->get_results().empty() ); // using front, should have this assert144 assert( ! actual->get_results().empty() ); 145 145 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) { 146 146 FunctionType *funType; -
src/InitTweak/InitModel.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InitModel.cc -- 7 // InitModel.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T hu Jan 07 13:38:46 201613 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:37:08 2015 13 // Update Count : 1 14 14 // 15 15 … … 198 198 assert(init == 0 && single != 0); 199 199 std::list< Expression * > empty; 200 init = new SingleInit( single->get_expr(), empty , false ); // cannot be constructed200 init = new SingleInit( single->get_expr(), empty ); 201 201 return; 202 202 } … … 214 214 } // if 215 215 216 std::list< Expression * > desig; 217 init = new ListInit( contents, desig, false ); // cannot be constructed 216 init = new ListInit( contents ); 218 217 return; 219 218 } -
src/InitTweak/RemoveInit.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.cc -- 7 // RemoveInit.cc -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T hu Apr 14 15:09:36 201613 // Update Count : 1 6611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 15 15:37:26 2015 13 // Update Count : 15 14 14 // 15 15 16 #include <stack>17 #include <list>18 16 #include "RemoveInit.h" 19 17 #include "SynTree/Declaration.h" … … 23 21 #include "SynTree/Initializer.h" 24 22 #include "SynTree/Mutator.h" 25 #include "SymTab/Autogen.h"26 #include "GenPoly/PolyMutator.h"27 23 28 24 namespace InitTweak { 29 25 namespace { 30 26 const std::list<Label> noLabels; 31 const std::list<Expression *> noDesignators;32 27 } 33 34 class RemoveInit : public GenPoly::PolyMutator {28 29 class RemoveInit : public Mutator { 35 30 public: 36 /// removes and replaces initialization for polymorphic value objects37 /// with assignment (TODO: constructor) statements.38 /// also consistently allocates a temporary variable for the return value39 /// of a function so that anything which the resolver decides can be assigned40 /// into the return type of a function can be returned.41 static void removeInitializers( std::list< Declaration * > &translationUnit );42 43 31 RemoveInit(); 44 45 virtual ObjectDecl * mutate( ObjectDecl *objDecl ); 32 virtual ObjectDecl * mutate(ObjectDecl *objDecl); 46 33 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 47 34 48 35 virtual Statement * mutate( ReturnStmt * returnStmt ); 36 37 virtual CompoundStmt * mutate(CompoundStmt * compoundStmt); 38 39 protected: 40 std::list< Statement* > stmtsToAddBefore; 41 std::list< Statement* > stmtsToAddAfter; 42 void mutateStatementList( std::list< Statement* > &statements ); 49 43 50 protected:51 44 std::list<DeclarationWithType*> returnVals; 52 45 UniqueName tempNamer; … … 54 47 }; 55 48 56 class CtorDtor : public GenPoly::PolyMutator { 57 public: 58 /// create constructor and destructor statements for object declarations. 59 /// Destructors are inserted directly into the code, whereas constructors 60 /// will be added in after the resolver has run so that the initializer expression 61 /// is only removed if a constructor is found 62 static void generateCtorDtor( std::list< Declaration * > &translationUnit ); 63 64 CtorDtor() : inFunction( false ) {} 65 66 virtual DeclarationWithType * mutate( ObjectDecl * ); 67 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 68 virtual Declaration* mutate( StructDecl *aggregateDecl ); 69 virtual Declaration* mutate( UnionDecl *aggregateDecl ); 70 virtual Declaration* mutate( EnumDecl *aggregateDecl ); 71 virtual Declaration* mutate( TraitDecl *aggregateDecl ); 72 virtual TypeDecl* mutate( TypeDecl *typeDecl ); 73 virtual Declaration* mutate( TypedefDecl *typeDecl ); 74 75 virtual Type * mutate( FunctionType *funcType ); 76 77 protected: 78 bool inFunction; 79 }; 80 81 void tweak( std::list< Declaration * > & translationUnit ) { 82 RemoveInit::removeInitializers( translationUnit ); 83 CtorDtor::generateCtorDtor( translationUnit ); 84 } 85 86 void RemoveInit::removeInitializers( std::list< Declaration * > & translationUnit ) { 49 void tweak( std::list< Declaration * > translationUnit ) { 87 50 RemoveInit remover; 88 51 mutateAll( translationUnit, remover ); … … 90 53 91 54 RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {} 55 56 void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) { 57 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 58 if ( ! stmtsToAddAfter.empty() ) { 59 statements.splice( i, stmtsToAddAfter ); 60 } // if 61 *i = (*i)->acceptMutator( *this ); 62 if ( ! stmtsToAddBefore.empty() ) { 63 statements.splice( i, stmtsToAddBefore ); 64 } // if 65 } // for 66 if ( ! stmtsToAddAfter.empty() ) { 67 statements.splice( statements.end(), stmtsToAddAfter ); 68 } // if 69 } 70 71 CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) { 72 mutateStatementList( compoundStmt->get_kids() ); 73 return compoundStmt; 74 } 92 75 93 76 // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the … … 96 79 if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) { 97 80 if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) { 98 // xxx this can be more complicated - consider ListInit 99 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?{}" ) ); 100 assign->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 81 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 82 assign->get_args().push_back( new AddressExpr (new NameExpr( objDecl->get_name() ) ) ); 101 83 assign->get_args().push_back( single->get_value()->clone() ); 102 84 stmtsToAddAfter.push_back(new ExprStmt(noLabels, assign)); … … 111 93 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address 112 94 // is being returned 113 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 114 // ensure return value is not destructed by explicitly creating 115 // an empty SingleInit node wherein maybeConstruct is false 116 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), new ListInit( std::list<Initializer*>(), noDesignators, false ) ); 117 stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) ); 118 119 // and explicitly create the constructor expression separately 120 UntypedExpr *construct = new UntypedExpr( new NameExpr( "?{}" ) ); 121 construct->get_args().push_back( new AddressExpr( new VariableExpr( newObj ) ) ); 122 construct->get_args().push_back( returnStmt->get_expr() ); 123 stmtsToAdd.push_back(new ExprStmt(noLabels, construct)); 95 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 96 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 ); 97 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) ); 98 99 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 100 assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) ); 101 assign->get_args().push_back( returnStmt->get_expr() ); 102 stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign)); 124 103 125 104 returnStmt->set_expr( new VariableExpr( newObj ) ); … … 131 110 std::list<DeclarationWithType*> oldReturnVals = returnVals; 132 111 std::string oldFuncName = funcName; 133 112 134 113 FunctionType * type = functionDecl->get_functionType(); 135 114 returnVals = type->get_returnVals(); … … 140 119 return decl; 141 120 } 142 143 144 void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) {145 CtorDtor ctordtor;146 mutateAll( translationUnit, ctordtor );147 }148 149 namespace {150 bool tryConstruct( ObjectDecl * objDecl ) {151 // xxx - handle designations152 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&153 (objDecl->get_init() == NULL ||154 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() ));155 }156 157 Expression * makeCtorDtorExpr( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) {158 UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) );159 expr->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );160 expr->get_args().splice( expr->get_args().end(), args );161 return expr;162 }163 164 class InitExpander : public Visitor {165 public:166 InitExpander() {}167 // ~InitExpander() {}168 virtual void visit( SingleInit * singleInit );169 virtual void visit( ListInit * listInit );170 std::list< Expression * > argList;171 };172 173 void InitExpander::visit( SingleInit * singleInit ) {174 argList.push_back( singleInit->get_value()->clone() );175 }176 177 void InitExpander::visit( ListInit * listInit ) {178 // xxx - for now, assume no nested list inits179 std::list<Initializer*>::iterator it = listInit->begin_initializers();180 for ( ; it != listInit->end_initializers(); ++it ) {181 (*it)->accept( *this );182 }183 }184 185 std::list< Expression * > makeInitList( Initializer * init ) {186 InitExpander expander;187 maybeAccept( init, expander );188 return expander.argList;189 }190 }191 192 DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) {193 // hands off if designated or if @=194 if ( tryConstruct( objDecl ) ) {195 if ( inFunction ) {196 if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {197 // call into makeArrayFunction from validate.cc to generate calls to ctor/dtor for each element of array198 // TODO: walk initializer and generate appropriate copy ctor if element has initializer199 std::list< Statement * > ctor;200 std::list< Statement * > dtor;201 202 SymTab::makeArrayFunction( NULL, new VariableExpr( objDecl ), at, "?{}", back_inserter( ctor ) );203 SymTab::makeArrayFunction( NULL, new VariableExpr( objDecl ), at, "^?{}", front_inserter( dtor ), false );204 205 // Currently makeArrayFunction produces a single Statement - a CompoundStmt206 // which wraps everything that needs to happen. As such, it's technically207 // possible to use a Statement ** in the above calls, but this is inherently208 // unsafe, so instead we take the slightly less efficient route, but will be209 // immediately informed if somehow the above assumption is broken. In this case,210 // we could always wrap the list of statements at this point with a CompoundStmt,211 // but it seems reasonable at the moment for this to be done by makeArrayFunction212 // itself213 assert( ctor.size() == 1 );214 assert( dtor.size() == 1 );215 216 objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ) );217 } else {218 // it's sufficient to attempt to call the ctor/dtor for the given object and its initializer219 Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) );220 Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() );221 222 // need to remember init expression, in case no ctors exist223 // if ctor does exist, want to use ctor expression instead of init224 // push this decision to the resolver225 ExprStmt * ctorStmt = new ExprStmt( noLabels, ctor );226 ExprStmt * dtorStmt = new ExprStmt( noLabels, dtor );227 objDecl->set_init( new ConstructorInit( ctorStmt, dtorStmt, objDecl->get_init() ) );228 }229 } else {230 // xxx - find a way to construct/destruct globals231 // hack: implicit "static" initialization routine for each struct type? or something similar?232 // --ties into module system233 // this can be done by mangling main and replacing it with our own main which calls each234 // module initialization routine in some decided order (order given in link command?)235 // and finally calls mangled main236 }237 }238 return Mutator::mutate( objDecl );239 }240 241 DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) {242 // parameters should not be constructed and destructed, so don't mutate FunctionType243 bool oldInFunc = inFunction;244 mutateAll( functionDecl->get_oldDecls(), *this );245 inFunction = true;246 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );247 inFunction = oldInFunc;248 return functionDecl;249 }250 251 // should not traverse into any of these declarations to find objects252 // that need to be constructed or destructed253 Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) { return aggregateDecl; }254 Declaration* CtorDtor::mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; }255 Declaration* CtorDtor::mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; }256 Declaration* CtorDtor::mutate( TraitDecl *aggregateDecl ) { return aggregateDecl; }257 TypeDecl* CtorDtor::mutate( TypeDecl *typeDecl ) { return typeDecl; }258 Declaration* CtorDtor::mutate( TypedefDecl *typeDecl ) { return typeDecl; }259 Type* CtorDtor::mutate( FunctionType *funcType ) { return funcType; }260 261 121 } // namespace InitTweak 262 122 -
src/InitTweak/RemoveInit.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.h -- 7 // RemoveInit.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Jan 11 16:02:44 201613 // Update Count : 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 27 17:00:47 2015 13 // Update Count : 2 14 14 // 15 15 … … 26 26 namespace InitTweak { 27 27 /// Adds assignment statements for polymorphic type initializers 28 void tweak( std::list< Declaration * > &translationUnit );29 } // namespace 28 void tweak( std::list< Declaration * > translationUnit ); 29 } // namespace 30 30 31 31 #endif // GENPOLY_POLYMUTATOR_H -
src/InitTweak/module.mk
rfbfb38e r6812d89 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 12 ## Last Modified By : Rob Schluntz 13 ## Last Modified On : Wed Jan 13 16:29:03201614 ## Update Count : 313 ## Last Modified On : Mon Jan 11 14:40:16 2016 14 ## Update Count : 2 15 15 ############################################################################### 16 16 17 SRC += InitTweak/RemoveInit.cc \18 InitTweak/FixInit.cc 17 SRC += InitTweak/RemoveInit.cc 18 -
src/MakeLibCfa.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // MakeLibCfa.cc -- 7 // MakeLibCfa.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sat May 16 10:33:33 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Jan 19 13:20:26 201613 // Update Count : 4014 // 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 26 16:52:59 2015 13 // Update Count : 14 14 // 15 15 16 16 #include "MakeLibCfa.h" … … 29 29 void visit( FunctionDecl* funcDecl ); 30 30 void visit( ObjectDecl* objDecl ); 31 31 32 32 std::list< Declaration* > &get_newDecls() { return newDecls; } 33 33 private: … … 43 43 void MakeLibCfa::visit( FunctionDecl* origFuncDecl ) { 44 44 if ( origFuncDecl->get_linkage() != LinkageSpec::Intrinsic ) return; 45 45 46 46 FunctionDecl *funcDecl = origFuncDecl->clone(); 47 47 CodeGen::OperatorInfo opInfo; … … 54 54 assert( param != funcDecl->get_functionType()->get_parameters().end() ); 55 55 56 for ( ; param != funcDecl->get_functionType()->get_parameters().end(); ++param ) { 57 if ( (*param)->get_name() == "" ) { 58 (*param)->set_name( paramNamer.newName() ); 59 (*param)->set_linkage( LinkageSpec::C ); 60 } 61 newExpr->get_args().push_back( new VariableExpr( *param ) ); 62 } // for 63 64 funcDecl->set_statements( new CompoundStmt( std::list< Label >() ) ); 65 newDecls.push_back( funcDecl ); 56 if ( (*param)->get_name() == "" ) { 57 (*param)->set_name( paramNamer.newName() ); 58 (*param)->set_linkage( LinkageSpec::C ); 59 } // if 66 60 67 61 switch ( opInfo.type ) { … … 71 65 case CodeGen::OT_POSTFIX: 72 66 case CodeGen::OT_INFIX: 67 newExpr->get_args().push_back( new VariableExpr( *param ) ); 68 break; 73 69 case CodeGen::OT_PREFIXASSIGN: 74 70 case CodeGen::OT_POSTFIXASSIGN: 75 71 case CodeGen::OT_INFIXASSIGN: 76 funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( std::list< Label >(), newExpr ) ); 72 { 73 newExpr->get_args().push_back( new VariableExpr( *param ) ); 74 // UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 75 // deref->get_args().push_back( new VariableExpr( *param ) ); 76 // newExpr->get_args().push_back( deref ); 77 77 break; 78 case CodeGen::OT_CTOR: 79 // ctors don't return a value 80 if ( funcDecl->get_functionType()->get_parameters().size() == 1 ) { 81 // intrinsic default constructors should do nothing 82 // delete newExpr; 83 break; 84 } else { 85 assert( funcDecl->get_functionType()->get_parameters().size() == 2 ); 86 // anything else is a single parameter constructor that is effectively a C-style assignment 87 // delete newExpr->get_function(); 88 assert(newExpr->get_args().size()==2); 89 newExpr->set_function( new NameExpr( "?=?" ) ); 90 funcDecl->get_statements()->get_kids().push_back( new ExprStmt( std::list< Label >(), newExpr ) ); 91 } 92 break; 93 case CodeGen::OT_DTOR: 94 // intrinsic destructors should do nothing 95 // delete newExpr; 96 break; 78 } 97 79 case CodeGen::OT_CONSTANT: 98 80 case CodeGen::OT_LABELADDRESS: … … 100 82 assert( false ); 101 83 } // switch 84 85 for ( param++; param != funcDecl->get_functionType()->get_parameters().end(); ++param ) { 86 if ( (*param)->get_name() == "" ) { 87 (*param)->set_name( paramNamer.newName() ); 88 (*param)->set_linkage( LinkageSpec::C ); 89 } 90 newExpr->get_args().push_back( new VariableExpr( *param ) ); 91 } // for 92 funcDecl->set_statements( new CompoundStmt( std::list< Label >() ) ); 93 funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( std::list< Label >(), newExpr ) ); 94 newDecls.push_back( funcDecl ); 102 95 } 103 96 104 97 void MakeLibCfa::visit( ObjectDecl* origObjDecl ) { 105 98 if ( origObjDecl->get_linkage() != LinkageSpec::Intrinsic ) return; 106 99 107 100 ObjectDecl *objDecl = origObjDecl->clone(); 108 101 assert( ! objDecl->get_init() ); 109 102 std::list< Expression* > noDesignators; 110 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators , false ) ); // cannot be constructed103 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators ) ); 111 104 newDecls.push_back( objDecl ); 112 105 } 113 106 } // namespace LibCfa 107 108 // Local Variables: // 109 // tab-width: 4 // 110 // mode: c++ // 111 // compile-command: "make install" // 112 // End: // -
src/Makefile.in
rfbfb38e r6812d89 124 124 GenPoly/driver_cfa_cpp-DeclMutator.$(OBJEXT) \ 125 125 InitTweak/driver_cfa_cpp-RemoveInit.$(OBJEXT) \ 126 InitTweak/driver_cfa_cpp-FixInit.$(OBJEXT) \127 126 Parser/driver_cfa_cpp-parser.$(OBJEXT) \ 128 127 Parser/driver_cfa_cpp-lex.$(OBJEXT) \ … … 160 159 SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT) \ 161 160 SymTab/driver_cfa_cpp-TypeEquality.$(OBJEXT) \ 162 SymTab/driver_cfa_cpp-Autogen.$(OBJEXT) \163 161 SynTree/driver_cfa_cpp-Type.$(OBJEXT) \ 164 162 SynTree/driver_cfa_cpp-VoidType.$(OBJEXT) \ … … 348 346 GenPoly/CopyParams.cc GenPoly/FindFunction.cc \ 349 347 GenPoly/DeclMutator.cc InitTweak/RemoveInit.cc \ 350 InitTweak/FixInit.cc Parser/parser.yy Parser/lex.ll \ 351 Parser/TypedefTable.cc Parser/ParseNode.cc \ 352 Parser/DeclarationNode.cc Parser/ExpressionNode.cc \ 353 Parser/StatementNode.cc Parser/InitializerNode.cc \ 354 Parser/TypeData.cc Parser/LinkageSpec.cc \ 355 Parser/parseutility.cc Parser/Parser.cc \ 348 Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \ 349 Parser/ParseNode.cc Parser/DeclarationNode.cc \ 350 Parser/ExpressionNode.cc Parser/StatementNode.cc \ 351 Parser/InitializerNode.cc Parser/TypeData.cc \ 352 Parser/LinkageSpec.cc Parser/parseutility.cc Parser/Parser.cc \ 356 353 ResolvExpr/AlternativeFinder.cc ResolvExpr/Alternative.cc \ 357 354 ResolvExpr/Unify.cc ResolvExpr/PtrsAssignable.cc \ … … 365 362 SymTab/Mangler.cc SymTab/Validate.cc SymTab/FixFunction.cc \ 366 363 SymTab/ImplementationType.cc SymTab/TypeEquality.cc \ 367 SymTab/Autogen.cc SynTree/Type.cc SynTree/VoidType.cc \ 368 SynTree/BasicType.cc SynTree/PointerType.cc \ 369 SynTree/ArrayType.cc SynTree/FunctionType.cc \ 370 SynTree/ReferenceToType.cc SynTree/TupleType.cc \ 371 SynTree/TypeofType.cc SynTree/AttrType.cc \ 364 SynTree/Type.cc SynTree/VoidType.cc SynTree/BasicType.cc \ 365 SynTree/PointerType.cc SynTree/ArrayType.cc \ 366 SynTree/FunctionType.cc SynTree/ReferenceToType.cc \ 367 SynTree/TupleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \ 372 368 SynTree/VarArgsType.cc SynTree/Constant.cc \ 373 369 SynTree/Expression.cc SynTree/TupleExpr.cc \ … … 567 563 InitTweak/driver_cfa_cpp-RemoveInit.$(OBJEXT): \ 568 564 InitTweak/$(am__dirstamp) InitTweak/$(DEPDIR)/$(am__dirstamp) 569 InitTweak/driver_cfa_cpp-FixInit.$(OBJEXT): InitTweak/$(am__dirstamp) \570 InitTweak/$(DEPDIR)/$(am__dirstamp)571 565 Parser/parser.h: Parser/parser.cc 572 566 @if test ! -f $@; then rm -f Parser/parser.cc; else :; fi … … 676 670 SymTab/driver_cfa_cpp-TypeEquality.$(OBJEXT): SymTab/$(am__dirstamp) \ 677 671 SymTab/$(DEPDIR)/$(am__dirstamp) 678 SymTab/driver_cfa_cpp-Autogen.$(OBJEXT): SymTab/$(am__dirstamp) \679 SymTab/$(DEPDIR)/$(am__dirstamp)680 672 SynTree/$(am__dirstamp): 681 673 @$(MKDIR_P) SynTree … … 800 792 -rm -f GenPoly/driver_cfa_cpp-ScrubTyVars.$(OBJEXT) 801 793 -rm -f GenPoly/driver_cfa_cpp-Specialize.$(OBJEXT) 802 -rm -f InitTweak/driver_cfa_cpp-FixInit.$(OBJEXT)803 794 -rm -f InitTweak/driver_cfa_cpp-RemoveInit.$(OBJEXT) 804 795 -rm -f Parser/driver_cfa_cpp-DeclarationNode.$(OBJEXT) … … 831 822 -rm -f ResolvExpr/driver_cfa_cpp-TypeEnvironment.$(OBJEXT) 832 823 -rm -f ResolvExpr/driver_cfa_cpp-Unify.$(OBJEXT) 833 -rm -f SymTab/driver_cfa_cpp-Autogen.$(OBJEXT)834 824 -rm -f SymTab/driver_cfa_cpp-FixFunction.$(OBJEXT) 835 825 -rm -f SymTab/driver_cfa_cpp-ImplementationType.$(OBJEXT) … … 907 897 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-ScrubTyVars.Po@am__quote@ 908 898 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-Specialize.Po@am__quote@ 909 @AMDEP_TRUE@@am__include@ @am__quote@InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Po@am__quote@910 899 @AMDEP_TRUE@@am__include@ @am__quote@InitTweak/$(DEPDIR)/driver_cfa_cpp-RemoveInit.Po@am__quote@ 911 900 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/driver_cfa_cpp-DeclarationNode.Po@am__quote@ … … 938 927 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-TypeEnvironment.Po@am__quote@ 939 928 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-Unify.Po@am__quote@ 940 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Po@am__quote@941 929 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-FixFunction.Po@am__quote@ 942 930 @AMDEP_TRUE@@am__include@ @am__quote@SymTab/$(DEPDIR)/driver_cfa_cpp-ImplementationType.Po@am__quote@ … … 1392 1380 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o InitTweak/driver_cfa_cpp-RemoveInit.obj `if test -f 'InitTweak/RemoveInit.cc'; then $(CYGPATH_W) 'InitTweak/RemoveInit.cc'; else $(CYGPATH_W) '$(srcdir)/InitTweak/RemoveInit.cc'; fi` 1393 1381 1394 InitTweak/driver_cfa_cpp-FixInit.o: InitTweak/FixInit.cc1395 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/driver_cfa_cpp-FixInit.o -MD -MP -MF InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Tpo -c -o InitTweak/driver_cfa_cpp-FixInit.o `test -f 'InitTweak/FixInit.cc' || echo '$(srcdir)/'`InitTweak/FixInit.cc1396 @am__fastdepCXX_TRUE@ $(am__mv) InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Tpo InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Po1397 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='InitTweak/FixInit.cc' object='InitTweak/driver_cfa_cpp-FixInit.o' libtool=no @AMDEPBACKSLASH@1398 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1399 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o InitTweak/driver_cfa_cpp-FixInit.o `test -f 'InitTweak/FixInit.cc' || echo '$(srcdir)/'`InitTweak/FixInit.cc1400 1401 InitTweak/driver_cfa_cpp-FixInit.obj: InitTweak/FixInit.cc1402 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/driver_cfa_cpp-FixInit.obj -MD -MP -MF InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Tpo -c -o InitTweak/driver_cfa_cpp-FixInit.obj `if test -f 'InitTweak/FixInit.cc'; then $(CYGPATH_W) 'InitTweak/FixInit.cc'; else $(CYGPATH_W) '$(srcdir)/InitTweak/FixInit.cc'; fi`1403 @am__fastdepCXX_TRUE@ $(am__mv) InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Tpo InitTweak/$(DEPDIR)/driver_cfa_cpp-FixInit.Po1404 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='InitTweak/FixInit.cc' object='InitTweak/driver_cfa_cpp-FixInit.obj' libtool=no @AMDEPBACKSLASH@1405 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1406 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o InitTweak/driver_cfa_cpp-FixInit.obj `if test -f 'InitTweak/FixInit.cc'; then $(CYGPATH_W) 'InitTweak/FixInit.cc'; else $(CYGPATH_W) '$(srcdir)/InitTweak/FixInit.cc'; fi`1407 1408 1382 Parser/driver_cfa_cpp-parser.o: Parser/parser.cc 1409 1383 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Parser/driver_cfa_cpp-parser.o -MD -MP -MF Parser/$(DEPDIR)/driver_cfa_cpp-parser.Tpo -c -o Parser/driver_cfa_cpp-parser.o `test -f 'Parser/parser.cc' || echo '$(srcdir)/'`Parser/parser.cc … … 1895 1869 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1896 1870 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-TypeEquality.obj `if test -f 'SymTab/TypeEquality.cc'; then $(CYGPATH_W) 'SymTab/TypeEquality.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/TypeEquality.cc'; fi` 1897 1898 SymTab/driver_cfa_cpp-Autogen.o: SymTab/Autogen.cc1899 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-Autogen.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Tpo -c -o SymTab/driver_cfa_cpp-Autogen.o `test -f 'SymTab/Autogen.cc' || echo '$(srcdir)/'`SymTab/Autogen.cc1900 @am__fastdepCXX_TRUE@ $(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Po1901 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SymTab/Autogen.cc' object='SymTab/driver_cfa_cpp-Autogen.o' libtool=no @AMDEPBACKSLASH@1902 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1903 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-Autogen.o `test -f 'SymTab/Autogen.cc' || echo '$(srcdir)/'`SymTab/Autogen.cc1904 1905 SymTab/driver_cfa_cpp-Autogen.obj: SymTab/Autogen.cc1906 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-Autogen.obj -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Tpo -c -o SymTab/driver_cfa_cpp-Autogen.obj `if test -f 'SymTab/Autogen.cc'; then $(CYGPATH_W) 'SymTab/Autogen.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/Autogen.cc'; fi`1907 @am__fastdepCXX_TRUE@ $(am__mv) SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Tpo SymTab/$(DEPDIR)/driver_cfa_cpp-Autogen.Po1908 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SymTab/Autogen.cc' object='SymTab/driver_cfa_cpp-Autogen.obj' libtool=no @AMDEPBACKSLASH@1909 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@1910 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SymTab/driver_cfa_cpp-Autogen.obj `if test -f 'SymTab/Autogen.cc'; then $(CYGPATH_W) 'SymTab/Autogen.cc'; else $(CYGPATH_W) '$(srcdir)/SymTab/Autogen.cc'; fi`1911 1871 1912 1872 SynTree/driver_cfa_cpp-Type.o: SynTree/Type.cc -
src/Parser/DeclarationNode.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // DeclarationNode.cc -- 7 // DeclarationNode.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 12:34:05 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:38:09201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 16:53:17 2016 13 13 // Update Count : 161 14 14 // … … 97 97 os << endl << string( indent + 2, ' ' ) << "with initializer "; 98 98 initializer->printOneLine( os ); 99 os << " maybe constructed? " << initializer->get_maybeConstructed();100 101 99 } // if 102 100 … … 355 353 } // if 356 354 } 357 355 358 356 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 359 357 if ( q ) { … … 506 504 assert( false ); 507 505 } // switch 508 506 509 507 return this; 510 508 } … … 617 615 assert( a->type->kind == TypeData::Array ); 618 616 TypeData *lastArray = findLast( a->type ); 619 if ( type ) { 617 if ( type ) { 620 618 switch ( type->kind ) { 621 619 case TypeData::Aggregate: … … 661 659 } // if 662 660 } 663 661 664 662 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) { 665 663 type = addIdListToType( type, ids ); … … 866 864 Type *DeclarationNode::buildType() const { 867 865 assert( type ); 868 866 869 867 switch ( type->kind ) { 870 868 case TypeData::Enum: -
src/Parser/InitializerNode.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InitializerNode.cc -- 8 // 7 // InitializerNode.cc -- 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:20:24 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jan 07 13:32:57 201613 // Update Count : 1314 // 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Oct 8 17:18:55 2015 13 // Update Count : 4 14 // 15 15 16 16 #include <cassert> … … 23 23 24 24 InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des ) 25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ) , maybeConstructed( true ){25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ) { 26 26 if ( aggrp ) 27 27 kids = dynamic_cast< InitializerNode *>( get_link() ); … … 32 32 33 33 InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des ) 34 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ) , maybeConstructed( true ){34 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ) { 35 35 if ( init != 0 ) 36 36 set_link(init); … … 91 91 } // if 92 92 93 return new ListInit( initlist, designlist , maybeConstructed);93 return new ListInit( initlist, designlist ); 94 94 } else { 95 95 std::list< Expression *> designators; … … 99 99 100 100 if ( get_expression() != 0) 101 return new SingleInit( get_expression()->build(), designators , maybeConstructed);101 return new SingleInit( get_expression()->build(), designators ); 102 102 } // if 103 103 -
src/Parser/ParseNode.h
rfbfb38e r6812d89 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Apr 14 15:37:52 201612 // Last Modified On : Mon Apr 11 11:50:52 2016 13 13 // Update Count : 205 14 14 // … … 185 185 // monadic 186 186 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, 187 Ctor, Dtor,188 187 }; 189 188 … … 526 525 ExpressionNode *get_designators() const { return designator; } 527 526 528 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }529 bool get_maybeConstructed() const { return maybeConstructed; }530 531 527 InitializerNode *next_init() const { return kids; } 532 528 … … 540 536 ExpressionNode *designator; // may be list 541 537 InitializerNode *kids; 542 bool maybeConstructed;543 538 }; 544 539 -
src/Parser/TypeData.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TypeData.cc -- 7 // TypeData.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:12:51 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 06 16:57:53201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:26:45 2016 13 13 // Update Count : 49 14 14 // … … 449 449 for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) { 450 450 if ( (*i)->get_kind() == TypeDecl::Any ) { 451 // add assertion parameters to `type' tyvars in reverse order452 // add dtor: void ^?{}(T *)453 FunctionType *dtorType = new FunctionType( Type::Qualifiers(), false );454 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );455 (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, 0, false, false ) );456 457 // add copy ctor: void ?{}(T *, T)458 FunctionType *copyCtorType = new FunctionType( Type::Qualifiers(), false );459 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );460 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );461 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, 0, false, false ) );462 463 // add default ctor: void ?{}(T *)464 FunctionType *ctorType = new FunctionType( Type::Qualifiers(), false );465 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );466 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, 0, false, false ) );467 468 // add assignment operator: T * ?=?(T *, T)469 451 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 470 452 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) ); … … 920 902 if ( cur->get_enumeratorValue() != NULL ) { 921 903 ObjectDecl *member = dynamic_cast<ObjectDecl *>(*members); 922 member->set_init( new SingleInit( maybeBuild< Expression >( cur->get_enumeratorValue() ) , std::list< Expression * >()) );904 member->set_init( new SingleInit( maybeBuild< Expression >( cur->get_enumeratorValue() ) ) ); 923 905 } // if 924 906 } // for -
src/Parser/parser.cc
rfbfb38e r6812d89 7468 7468 /* Line 1806 of yacc.c */ 7469 7469 #line 1704 "parser.yy" 7470 { (yyval.in) = (yyvsp[(2) - (2)].in) ->set_maybeConstructed( false ); }7470 { (yyval.in) = (yyvsp[(2) - (2)].in); } 7471 7471 break; 7472 7472 -
src/Parser/parser.yy
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // cfa.y -- 8 // 7 // cfa.y -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 … … 12 12 // Last Modified On : Wed Apr 13 16:58:43 2016 13 13 // Update Count : 1519 14 // 14 // 15 15 16 16 // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C … … 1702 1702 { $$ = $2; } 1703 1703 | ATassign initializer 1704 { $$ = $2 ->set_maybeConstructed( false ); }1704 { $$ = $2; } 1705 1705 ; 1706 1706 -
src/ResolvExpr/AlternativeFinder.cc
rfbfb38e r6812d89 10 10 // Created On : Sat May 16 23:52:08 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Apr 20 14:24:03201612 // Last Modified On : Wed Feb 10 17:00:04 2016 13 13 // Update Count : 24 14 14 // … … 982 982 } // for 983 983 } 984 985 void AlternativeFinder::visit( ImplicitCopyCtorExpr * impCpCtorExpr ) {986 alternatives.push_back( Alternative( impCpCtorExpr->clone(), env, Cost::zero ) );987 }988 984 } // namespace ResolvExpr 989 985 -
src/ResolvExpr/AlternativeFinder.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // AlternativeFinder.h -- 7 // AlternativeFinder.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sat May 16 23:56:12 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Apr 19 11:44:53 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 23:58:43 2015 13 13 // Update Count : 2 14 // 14 // 15 15 16 16 #ifndef ALTERNATIVEFINDER_H … … 54 54 virtual void visit( NameExpr *variableExpr ); 55 55 virtual void visit( VariableExpr *variableExpr ); 56 virtual void visit( ConstantExpr *constantExpr ); 56 virtual void visit( ConstantExpr *constantExpr ); 57 57 virtual void visit( SizeofExpr *sizeofExpr ); 58 58 virtual void visit( AlignofExpr *alignofExpr ); … … 65 65 virtual void visit( CommaExpr *commaExpr ); 66 66 virtual void visit( TupleExpr *tupleExpr ); 67 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );68 67 public: // xxx - temporary hack - should make Tuples::TupleAssignment a friend 69 68 template< typename InputIterator, typename OutputIterator > -
src/ResolvExpr/Resolver.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Resolver.cc -- 7 // Resolver.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 11:18:12201613 // Update Count : 20311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 24 16:43:11 2016 13 // Update Count : 181 14 14 // 15 15 … … 33 33 public: 34 34 Resolver() : SymTab::Indexer( false ), switchType( 0 ) {} 35 35 36 36 virtual void visit( FunctionDecl *functionDecl ); 37 37 virtual void visit( ObjectDecl *functionDecl ); … … 54 54 virtual void visit( SingleInit *singleInit ); 55 55 virtual void visit( ListInit *listInit ); 56 virtual void visit( ConstructorInit *ctorInit );57 56 private: 58 57 typedef std::list< Initializer * >::iterator InitIterator; … … 60 59 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); 61 60 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & ); 62 void fallbackInit( ConstructorInit * ctorInit ); 61 63 62 std::list< Type * > functionReturn; 64 63 Type *initContext; … … 83 82 } 84 83 85 86 84 namespace { 87 85 void finishExpr( Expression *expr, const TypeEnvironment &env ) { … … 89 87 env.makeSubstitution( *expr->get_env() ); 90 88 } 91 } // namespace 92 93 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 94 global_renamer.reset(); 95 TypeEnvironment env; 96 Expression *newExpr = resolveInVoidContext( untyped, indexer, env ); 97 finishExpr( newExpr, env ); 98 return newExpr; 99 } 100 101 namespace { 89 90 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 91 global_renamer.reset(); 92 TypeEnvironment env; 93 Expression *newExpr = resolveInVoidContext( untyped, indexer, env ); 94 finishExpr( newExpr, env ); 95 return newExpr; 96 } 97 102 98 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 103 99 TypeEnvironment env; … … 130 126 } // if 131 127 } 132 128 133 129 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 134 130 TypeEnvironment env; … … 163 159 return newExpr; 164 160 } 165 166 } 167 161 162 } 163 168 164 void Resolver::visit( ObjectDecl *objectDecl ) { 169 165 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); … … 262 258 forStmt->set_condition( newExpr ); 263 259 } // if 264 260 265 261 if ( forStmt->get_increment() ) { 266 262 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 276 272 delete switchStmt->get_condition(); 277 273 switchStmt->set_condition( newExpr ); 278 274 279 275 visitor.Visitor::visit( switchStmt ); 280 276 } … … 318 314 bool isCharType( T t ) { 319 315 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 320 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 316 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 321 317 bt->get_kind() == BasicType::UnsignedChar; 322 318 } … … 330 326 string n = ne->get_name(); 331 327 if (n == "0") { 332 initContext = new BasicType(Type::Qualifiers(), 328 initContext = new BasicType(Type::Qualifiers(), 333 329 BasicType::SignedInt); 334 330 } else { … … 336 332 initContext = decl->get_type(); 337 333 } 338 } else if (ConstantExpr * e = 334 } else if (ConstantExpr * e = 339 335 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 340 336 Constant *c = e->get_constant(); … … 359 355 singleInit->set_value( ce->get_arg() ); 360 356 ce->set_arg( NULL ); 361 delete ce; 357 delete ce; 362 358 } 363 359 } … … 475 471 #endif 476 472 } 477 478 // ConstructorInit - fall back on C-style initializer479 void Resolver::fallbackInit( ConstructorInit * ctorInit ) {480 // could not find valid constructor, or found an intrinsic constructor481 // fall back on C-style initializer482 delete ctorInit->get_ctor();483 ctorInit->set_ctor( NULL );484 maybeAccept( ctorInit->get_init(), *this );485 }486 487 void Resolver::visit( ConstructorInit *ctorInit ) {488 try {489 maybeAccept( ctorInit->get_ctor(), *this );490 maybeAccept( ctorInit->get_dtor(), *this );491 } catch ( SemanticError ) {492 // no alternatives for the constructor initializer - fallback on C-style initializer493 // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation?494 fallbackInit( ctorInit );495 return;496 }497 498 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * > ( ctorInit->get_ctor() ) ) {499 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() );500 assert( appExpr );501 VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() );502 assert( function );503 if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) {504 // if the constructor that was found is intrinsic or autogenerated, reset to C-style505 // initializer so that code generation is easy to handle506 fallbackInit( ctorInit );507 return;508 }509 }510 // found a constructor - can get rid of C-style initializer511 delete ctorInit->get_init();512 ctorInit->set_init( NULL );513 }514 473 } // namespace ResolvExpr 515 474 -
src/ResolvExpr/Resolver.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Resolver.h -- 7 // Resolver.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:18:34 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:06:53 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 12:19:32 2015 13 13 // Update Count : 2 14 14 // … … 24 24 void resolve( std::list< Declaration * > translationUnit ); 25 25 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer ); 26 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer );27 26 } // namespace ResolvExpr 28 27 -
src/SymTab/AddVisit.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // AddVisit.h -- 7 // AddVisit.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 16:14:32 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:52:42201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 7 14:42:21 2016 13 13 // Update Count : 5 14 14 // … … 48 48 // maybeAccept( caseStmt->get_condition(), visitor ); 49 49 // } 50 51 template< typename Visitor >52 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {53 std::list< Declaration * >::iterator i = translationUnit.begin();54 while ( i != translationUnit.end() ) {55 (*i)->accept( visitor );56 std::list< Declaration * >::iterator next = i;57 next++;58 if ( ! visitor.get_declsToAdd().empty() ) {59 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );60 } // if61 i = next;62 } // while63 }64 65 50 } // namespace SymTab 66 51 -
src/SymTab/Validate.cc
rfbfb38e r6812d89 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:37:23201613 // Update Count : 2 9711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 16:39:30 2016 13 // Update Count : 251 14 14 // 15 15 … … 56 56 #include "MakeLibCfa.h" 57 57 #include "TypeEquality.h" 58 #include "Autogen.h"59 58 #include "ResolvExpr/typeops.h" 60 59 … … 123 122 124 123 const Indexer *indexer; 124 }; 125 126 class AutogenerateRoutines : public Visitor { 127 public: 128 /// Generates assignment operators for aggregate types as required 129 static void autogenerateRoutines( std::list< Declaration * > &translationUnit ); 130 131 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 132 133 virtual void visit( EnumDecl *enumDecl ); 134 virtual void visit( StructDecl *structDecl ); 135 virtual void visit( UnionDecl *structDecl ); 136 virtual void visit( TypeDecl *typeDecl ); 137 virtual void visit( TraitDecl *ctxDecl ); 138 virtual void visit( FunctionDecl *functionDecl ); 139 140 virtual void visit( FunctionType *ftype ); 141 virtual void visit( PointerType *ftype ); 142 143 virtual void visit( CompoundStmt *compoundStmt ); 144 virtual void visit( SwitchStmt *switchStmt ); 145 virtual void visit( ChooseStmt *chooseStmt ); 146 // virtual void visit( CaseStmt *caseStmt ); 147 148 AutogenerateRoutines() : functionNesting( 0 ) {} 149 private: 150 template< typename StmtClass > void visitStatement( StmtClass *stmt ); 151 152 std::list< Declaration * > declsToAdd; 153 std::set< std::string > structsDone; 154 unsigned int functionNesting; // current level of nested functions 125 155 }; 126 156 … … 162 192 template<typename AggDecl> 163 193 void addImplicitTypedef( AggDecl * aggDecl ); 164 194 165 195 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 166 196 TypedefMap typedefNames; 167 197 int scopeLevel; 168 198 }; 169 170 class VerifyCtorDtor : public Visitor {171 public:172 /// ensure that constructors and destructors have at least one173 /// parameter, the first of which must be a pointer, and no174 /// return values.175 static void verify( std::list< Declaration * > &translationUnit );176 177 virtual void visit( FunctionDecl *funcDecl );178 };179 199 180 200 class CompoundLiteral : public GenPoly::DeclMutator { … … 197 217 ReturnChecker::checkFunctionReturns( translationUnit ); 198 218 mutateAll( translationUnit, compoundliteral ); 199 autogenerateRoutines( translationUnit );219 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 200 220 acceptAll( translationUnit, pass3 ); 201 VerifyCtorDtor::verify( translationUnit );202 221 } 203 222 … … 209 228 type->accept( pass2 ); 210 229 type->accept( pass3 ); 230 } 231 232 template< typename Visitor > 233 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) { 234 std::list< Declaration * >::iterator i = translationUnit.begin(); 235 while ( i != translationUnit.end() ) { 236 (*i)->accept( visitor ); 237 std::list< Declaration * >::iterator next = i; 238 next++; 239 if ( ! visitor.get_declsToAdd().empty() ) { 240 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() ); 241 } // if 242 i = next; 243 } // while 211 244 } 212 245 … … 470 503 } 471 504 505 static const std::list< std::string > noLabels; 506 507 void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) { 508 AutogenerateRoutines visitor; 509 acceptAndAdd( translationUnit, visitor, false ); 510 } 511 512 template< typename OutputIterator > 513 void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) { 514 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member ); 515 // unnamed bit fields are not copied as they cannot be accessed 516 if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return; 517 518 UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) ); 519 520 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 521 derefExpr->get_args().push_back( new VariableExpr( dstParam ) ); 522 523 // do something special for unnamed members 524 Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) ); 525 assignExpr->get_args().push_back( dstselect ); 526 527 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) ); 528 assignExpr->get_args().push_back( srcselect ); 529 530 *out++ = new ExprStmt( noLabels, assignExpr ); 531 } 532 533 template< typename OutputIterator > 534 void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) { 535 static UniqueName indexName( "_index" ); 536 537 // for a flexible array member nothing is done -- user must define own assignment 538 if ( ! array->get_dimension() ) return; 539 540 ObjectDecl *index = new ObjectDecl( indexName.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ); 541 *out++ = new DeclStmt( noLabels, index ); 542 543 UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) ); 544 init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 545 init->get_args().push_back( new NameExpr( "0" ) ); 546 Statement *initStmt = new ExprStmt( noLabels, init ); 547 std::list<Statement *> initList; 548 initList.push_back( initStmt ); 549 550 UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) ); 551 cond->get_args().push_back( new VariableExpr( index ) ); 552 cond->get_args().push_back( array->get_dimension()->clone() ); 553 554 UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) ); 555 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 556 557 UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) ); 558 559 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 560 derefExpr->get_args().push_back( new VariableExpr( dstParam ) ); 561 562 Expression *dstselect = new MemberExpr( member, derefExpr ); 563 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) ); 564 dstIndex->get_args().push_back( dstselect ); 565 dstIndex->get_args().push_back( new VariableExpr( index ) ); 566 assignExpr->get_args().push_back( dstIndex ); 567 568 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) ); 569 UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 570 srcIndex->get_args().push_back( srcselect ); 571 srcIndex->get_args().push_back( new VariableExpr( index ) ); 572 assignExpr->get_args().push_back( srcIndex ); 573 574 *out++ = new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, assignExpr ) ); 575 } 576 577 template< typename OutputIterator > 578 void makeUnionFieldsAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, UnionInstType *unionType, OutputIterator out ) { 579 UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) ); 580 copy->get_args().push_back( new VariableExpr( dstParam ) ); 581 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 582 copy->get_args().push_back( new SizeofExpr( unionType ) ); 583 584 *out++ = new ExprStmt( noLabels, copy ); 585 } 586 587 //E ?=?(E volatile*, int), 588 // ?=?(E _Atomic volatile*, int); 589 void makeEnumAssignment( EnumDecl *enumDecl, EnumInstType *refType, unsigned int functionNesting, std::list< Declaration * > &declsToAdd ) { 590 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 591 592 ObjectDecl *returnVal = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 593 assignType->get_returnVals().push_back( returnVal ); 594 595 // need two assignment operators with different types 596 FunctionType * assignType2 = assignType->clone(); 597 598 // E ?=?(E volatile *, E) 599 Type *etype = refType->clone(); 600 // etype->get_qualifiers() += Type::Qualifiers(false, true, false, false, false, false); 601 602 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), etype ), 0 ); 603 assignType->get_parameters().push_back( dstParam ); 604 605 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, etype->clone(), 0 ); 606 assignType->get_parameters().push_back( srcParam ); 607 608 // E ?=?(E volatile *, int) 609 assignType2->get_parameters().push_back( dstParam->clone() ); 610 BasicType * paramType = new BasicType(Type::Qualifiers(), BasicType::SignedInt); 611 ObjectDecl *srcParam2 = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, paramType, 0 ); 612 assignType2->get_parameters().push_back( srcParam2 ); 613 614 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 615 // because each unit generates copies of the default routines for each aggregate. 616 617 // since there is no definition, these should not be inline 618 // make these intrinsic so that the code generator does not make use of them 619 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType, 0, false, false ); 620 assignDecl->fixUniqueId(); 621 FunctionDecl *assignDecl2 = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType2, 0, false, false ); 622 assignDecl2->fixUniqueId(); 623 624 // these should be built in the same way that the prelude 625 // functions are, so build a list containing the prototypes 626 // and allow MakeLibCfa to autogenerate the bodies. 627 std::list< Declaration * > assigns; 628 assigns.push_back( assignDecl ); 629 assigns.push_back( assignDecl2 ); 630 631 LibCfa::makeLibCfa( assigns ); 632 633 // need to remove the prototypes, since this may be nested in a routine 634 for (int start = 0, end = assigns.size()/2; start < end; start++) { 635 delete assigns.front(); 636 assigns.pop_front(); 637 } // for 638 639 declsToAdd.insert( declsToAdd.begin(), assigns.begin(), assigns.end() ); 640 } 641 642 /// Clones a reference type, replacing any parameters it may have with a clone of the provided list 643 template< typename GenericInstType > 644 GenericInstType *cloneWithParams( GenericInstType *refType, const std::list< Expression* >& params ) { 645 GenericInstType *clone = refType->clone(); 646 clone->get_parameters().clear(); 647 cloneAll( params, clone->get_parameters() ); 648 return clone; 649 } 650 651 /// Creates a new type decl that's the same as src, but renamed and with only the ?=? assertion (for complete types only) 652 TypeDecl *cloneAndRename( TypeDecl *src, const std::string &name ) { 653 TypeDecl *dst = new TypeDecl( name, src->get_storageClass(), 0, src->get_kind() ); 654 655 if ( src->get_kind() == TypeDecl::Any ) { 656 // just include assignment operator assertion 657 TypeInstType *assignParamType = new TypeInstType( Type::Qualifiers(), name, dst ); 658 FunctionType *assignFunctionType = new FunctionType( Type::Qualifiers(), false ); 659 assignFunctionType->get_returnVals().push_back( 660 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType->clone(), 0 ) ); 661 assignFunctionType->get_parameters().push_back( 662 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), assignParamType->clone() ), 0 ) ); 663 assignFunctionType->get_parameters().push_back( 664 new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, assignParamType, 0 ) ); 665 FunctionDecl *assignAssert = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignFunctionType, 0, false, false ); 666 dst->get_assertions().push_back( assignAssert ); 667 } 668 669 return dst; 670 } 671 672 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 673 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 674 675 // Make function polymorphic in same parameters as generic struct, if applicable 676 bool isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union) 677 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 678 std::list< Expression* > structParams; // List of matching parameters to put on types 679 TypeSubstitution genericSubs; // Substitutions to make to member types of struct 680 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 681 isGeneric = true; 682 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 683 assignType->get_forall().push_back( typeParam ); 684 TypeInstType *newParamType = new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ); 685 genericSubs.add( (*param)->get_name(), newParamType ); 686 structParams.push_back( new TypeExpr( newParamType ) ); 687 } 688 689 ObjectDecl *returnVal = new ObjectDecl( "_ret", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 690 assignType->get_returnVals().push_back( returnVal ); 691 692 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 ); 693 assignType->get_parameters().push_back( dstParam ); 694 695 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, structParams ), 0 ); 696 assignType->get_parameters().push_back( srcParam ); 697 698 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 699 // because each unit generates copies of the default routines for each aggregate. 700 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true, false ); 701 assignDecl->fixUniqueId(); 702 703 for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) { 704 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) { 705 // query the type qualifiers of this field and skip assigning it if it is marked const. 706 // If it is an array type, we need to strip off the array layers to find its qualifiers. 707 Type * type = dwt->get_type(); 708 while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 709 type = at->get_base(); 710 } 711 712 if ( type->get_qualifiers().isConst ) { 713 // don't assign const members 714 continue; 715 } 716 717 if ( isGeneric ) { 718 // rewrite member type in terms of the type variables on this operator 719 DeclarationWithType *fixedMember = dwt->clone(); 720 genericSubs.apply( fixedMember ); 721 722 // assign to both destination and return value 723 if ( ArrayType *array = dynamic_cast< ArrayType * >( fixedMember->get_type() ) ) { 724 makeArrayAssignment( srcParam, dstParam, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 725 makeArrayAssignment( srcParam, returnVal, fixedMember, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 726 } else { 727 makeScalarAssignment( srcParam, dstParam, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 728 makeScalarAssignment( srcParam, returnVal, fixedMember, back_inserter( assignDecl->get_statements()->get_kids() ) ); 729 } // if 730 } else { 731 // assign to destination 732 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 733 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 734 } else { 735 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 736 } // if 737 } // if 738 } // if 739 } // for 740 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 741 742 return assignDecl; 743 } 744 745 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 746 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 747 748 // Make function polymorphic in same parameters as generic union, if applicable 749 bool isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct) 750 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 751 std::list< Expression* > unionParams; // List of matching parameters to put on types 752 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 753 isGeneric = true; 754 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 755 assignType->get_forall().push_back( typeParam ); 756 unionParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) ); 757 } 758 759 ObjectDecl *returnVal = new ObjectDecl( "_ret", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 760 assignType->get_returnVals().push_back( returnVal ); 761 762 ObjectDecl *dstParam = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, unionParams ) ), 0 ); 763 assignType->get_parameters().push_back( dstParam ); 764 765 ObjectDecl *srcParam = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, cloneWithParams( refType, unionParams ), 0 ); 766 assignType->get_parameters().push_back( srcParam ); 767 768 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 769 // because each unit generates copies of the default routines for each aggregate. 770 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true, false ); 771 assignDecl->fixUniqueId(); 772 773 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 774 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 775 776 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 777 778 return assignDecl; 779 } 780 781 void AutogenerateRoutines::visit( EnumDecl *enumDecl ) { 782 if ( ! enumDecl->get_members().empty() ) { 783 EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() ); 784 // enumInst->set_baseEnum( enumDecl ); 785 // declsToAdd.push_back( 786 makeEnumAssignment( enumDecl, enumInst, functionNesting, declsToAdd ); 787 } 788 } 789 790 void AutogenerateRoutines::visit( StructDecl *structDecl ) { 791 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 792 StructInstType structInst( Type::Qualifiers(), structDecl->get_name() ); 793 structInst.set_baseStruct( structDecl ); 794 declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) ); 795 structsDone.insert( structDecl->get_name() ); 796 } // if 797 } 798 799 void AutogenerateRoutines::visit( UnionDecl *unionDecl ) { 800 if ( ! unionDecl->get_members().empty() ) { 801 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() ); 802 unionInst.set_baseUnion( unionDecl ); 803 declsToAdd.push_back( makeUnionAssignment( unionDecl, &unionInst, functionNesting ) ); 804 } // if 805 } 806 807 void AutogenerateRoutines::visit( TypeDecl *typeDecl ) { 808 CompoundStmt *stmts = 0; 809 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); 810 typeInst->set_baseType( typeDecl ); 811 ObjectDecl *src = new ObjectDecl( "_src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 ); 812 ObjectDecl *dst = new ObjectDecl( "_dst", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 ); 813 if ( typeDecl->get_base() ) { 814 stmts = new CompoundStmt( std::list< Label >() ); 815 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 816 assign->get_args().push_back( new CastExpr( new VariableExpr( dst ), new PointerType( Type::Qualifiers(), typeDecl->get_base()->clone() ) ) ); 817 assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) ); 818 stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) ); 819 } // if 820 FunctionType *type = new FunctionType( Type::Qualifiers(), false ); 821 type->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) ); 822 type->get_parameters().push_back( dst ); 823 type->get_parameters().push_back( src ); 824 FunctionDecl *func = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false, false ); 825 declsToAdd.push_back( func ); 826 } 827 828 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) { 829 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) { 830 statements.insert( i, new DeclStmt( noLabels, *decl ) ); 831 } // for 832 declsToAdd.clear(); 833 } 834 835 void AutogenerateRoutines::visit( FunctionType *) { 836 // ensure that we don't add assignment ops for types defined as part of the function 837 } 838 839 void AutogenerateRoutines::visit( PointerType *) { 840 // ensure that we don't add assignment ops for types defined as part of the pointer 841 } 842 843 void AutogenerateRoutines::visit( TraitDecl *) { 844 // ensure that we don't add assignment ops for types defined as part of the context 845 } 846 847 template< typename StmtClass > 848 inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) { 849 std::set< std::string > oldStructs = structsDone; 850 addVisit( stmt, *this ); 851 structsDone = oldStructs; 852 } 853 854 void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) { 855 maybeAccept( functionDecl->get_functionType(), *this ); 856 acceptAll( functionDecl->get_oldDecls(), *this ); 857 functionNesting += 1; 858 maybeAccept( functionDecl->get_statements(), *this ); 859 functionNesting -= 1; 860 } 861 862 void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) { 863 visitStatement( compoundStmt ); 864 } 865 866 void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) { 867 visitStatement( switchStmt ); 868 } 869 870 void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) { 871 visitStatement( switchStmt ); 872 } 873 874 // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) { 875 // visitStatement( caseStmt ); 876 // } 877 472 878 void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) { 473 879 ReturnChecker checker; … … 627 1033 return aggDecl; 628 1034 } 629 1035 630 1036 template<typename AggDecl> 631 1037 void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) { … … 666 1072 } 667 1073 668 void VerifyCtorDtor::verify( std::list< Declaration * > & translationUnit ) {669 VerifyCtorDtor verifier;670 acceptAll( translationUnit, verifier );671 }672 673 void VerifyCtorDtor::visit( FunctionDecl * funcDecl ) {674 FunctionType * funcType = funcDecl->get_functionType();675 std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();676 std::list< DeclarationWithType * > ¶ms = funcType->get_parameters();677 678 if ( funcDecl->get_name() == "?{}" || funcDecl->get_name() == "^?{}" ) {679 if ( params.size() == 0 ) {680 throw SemanticError( "Constructors and destructors require at least one parameter ", funcDecl );681 }682 if ( ! dynamic_cast< PointerType * >( params.front()->get_type() ) ) {683 throw SemanticError( "First parameter of a constructor or destructor must be a pointer ", funcDecl );684 }685 if ( returnVals.size() != 0 ) {686 throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );687 }688 }689 690 Visitor::visit( funcDecl );691 // original idea: modify signature of ctor/dtors and insert appropriate return statements692 // to cause desired behaviour693 // new idea: add comma exprs to every ctor call to produce first parameter.694 // this requires some memoization of the first parameter, because it can be a695 // complicated expression with side effects (see: malloc). idea: add temporary variable696 // that is assigned address of constructed object in ctor argument position and697 // return the temporary. It should also be done after all implicit ctors are698 // added, so not in this pass!699 }700 701 1074 DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) { 702 1075 storageclass = objectDecl->get_storageClass(); -
src/SymTab/module.mk
rfbfb38e r6812d89 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## module.mk -- 8 ## module.mk -- 9 9 ## 10 10 ## Author : Richard C. Bilson … … 20 20 SymTab/FixFunction.cc \ 21 21 SymTab/ImplementationType.cc \ 22 SymTab/TypeEquality.cc \ 23 SymTab/Autogen.cc 22 SymTab/TypeEquality.cc -
src/SynTree/CommaExpr.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CommaExpr.cc -- 7 // CommaExpr.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 06 17:07:54 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:09:58 2015 13 13 // Update Count : 1 14 14 // … … 20 20 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname ) 21 21 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) { 22 // xxx - result of a comma expression is never an lvalue, so should set lvalue23 // to false on all result types24 22 cloneAll( arg2->get_results(), get_results() ); 25 23 } -
src/SynTree/CompoundStmt.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc -- 7 // XXX.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 06 14:35:37 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 23 11:37:49 2015 13 13 // Update Count : 3 14 14 // … … 18 18 #include <algorithm> 19 19 #include <functional> 20 #include "Expression.h"21 #include "Declaration.h"22 20 23 21 using std::string; 24 22 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 23 43 24 CompoundStmt::CompoundStmt( std::list<Label> labels ) : Statement( labels ) { … … 46 27 CompoundStmt::CompoundStmt( const CompoundStmt &other ) : Statement( other ) { 47 28 cloneAll( other.kids, kids ); 48 49 // when cloning a compound statement, we may end up cloning declarations which50 // are referred to by VariableExprs throughout the block. Cloning a VariableExpr51 // does a shallow copy, so the VariableExpr will end up pointing to the original52 // declaration. If the original declaration is deleted, e.g. because the original53 // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case,54 // find all DeclarationWithType nodes (since a VariableExpr must point to a55 // DeclarationWithType) in the original CompoundStmt and map them to the cloned56 // node in the new CompoundStmt ('this'), then replace the Declarations referred to57 // by each VariableExpr according to the constructed map. Note that only the declarations58 // in the current level are collected into the map, because child CompoundStmts will59 // recursively execute this routine. There may be more efficient ways of doing60 // 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 }79 29 } 80 30 -
src/SynTree/Declaration.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Declaration.h -- 7 // Declaration.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 11 16:55:12201613 // Update Count : 3 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:28:11 2016 13 // Update Count : 33 14 14 // 15 15 … … 22 22 #include "Parser/LinkageSpec.h" 23 23 #include "Parser/ParseNode.h" 24 #include <string>25 24 26 25 class Declaration { … … 68 67 void set_mangleName( std::string newValue ) { mangleName = newValue; } 69 68 70 std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }71 72 int get_scopeLevel() const { return scopeLevel; }73 void set_scopeLevel( int newValue ) { scopeLevel = newValue; }74 75 69 virtual DeclarationWithType *clone() const = 0; 76 70 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; … … 81 75 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2 82 76 std::string mangleName; 83 // need to remember the scope level at which the variable was declared, so that84 // shadowed identifiers can be accessed85 int scopeLevel = 0;86 77 }; 87 78 -
src/SynTree/DeclarationWithType.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // DeclarationWithType.cc -- 7 // DeclarationWithType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 11 15:35:27 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 13 08:08:07 2015 13 13 // Update Count : 3 14 14 // … … 23 23 24 24 DeclarationWithType::DeclarationWithType( const DeclarationWithType &other ) 25 : Declaration( other ), mangleName( other.mangleName ) , scopeLevel( other.scopeLevel ){25 : Declaration( other ), mangleName( other.mangleName ) { 26 26 } 27 27 -
src/SynTree/Expression.cc
rfbfb38e r6812d89 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 18 17:25:06201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 8 17:16:23 2016 13 13 // Update Count : 40 14 14 // … … 79 79 80 80 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) { 81 assert( var );82 assert( var->get_type() );83 81 add_result( var->get_type()->clone() ); 84 82 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { … … 456 454 } 457 455 458 459 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {460 assert( callExpr );461 cloneAll( callExpr->get_results(), results );462 }463 464 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {465 cloneAll( other.results, results );466 cloneAll( other.copyCtors, copyCtors );467 cloneAll( other.tempDecls, tempDecls );468 cloneAll( other.returnDecls, returnDecls );469 cloneAll( other.dtors, dtors );470 }471 472 ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {473 delete callExpr;474 deleteAll( copyCtors );475 deleteAll( tempDecls );476 deleteAll( returnDecls );477 deleteAll( dtors );478 }479 480 void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {481 os << std::string( indent, ' ' ) << "Implicit Copy Constructor Expression: " << std::endl;482 assert( callExpr );483 callExpr->print( os, indent + 2 );484 os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;485 printAll(tempDecls, os, indent+2);486 os << std::endl << std::string( indent, ' ' ) << "with copyCtors:" << std::endl;487 printAll(copyCtors, os, indent+2);488 os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;489 printAll(returnDecls, os, indent+2);490 Expression::print( os, indent );491 }492 493 456 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {} 494 457 -
src/SynTree/Expression.h
rfbfb38e r6812d89 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:40:56 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 8 17:18:06 2016 13 13 // Update Count : 21 14 14 // … … 22 22 #include "Mutator.h" 23 23 #include "Constant.h" 24 #include "Common/UniqueName.h"25 24 26 25 /// Expression is the root type for all expressions … … 560 559 }; 561 560 562 /// ImplicitCopyCtorExpr represents the application of a function to a set of parameters,563 /// along with a set of copy constructor calls, one for each argument.564 class ImplicitCopyCtorExpr : public Expression {565 public:566 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );567 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );568 virtual ~ImplicitCopyCtorExpr();569 570 ApplicationExpr *get_callExpr() const { return callExpr; }571 void set_callExpr( ApplicationExpr *newValue ) { callExpr = newValue; }572 573 std::list< Expression * > & get_copyCtors() { return copyCtors; }574 void set_copyCtors( std::list< Expression * > newValue ) { copyCtors = newValue; }575 576 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }577 void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; }578 579 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }580 void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; }581 582 std::list< Expression * > & get_dtors() { return dtors; }583 void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; }584 585 virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); }586 virtual void accept( Visitor &v ) { v.visit( this ); }587 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }588 virtual void print( std::ostream &os, int indent = 0 ) const;589 private:590 ApplicationExpr * callExpr;591 std::list< Expression * > copyCtors;592 std::list< ObjectDecl * > tempDecls;593 std::list< ObjectDecl * > returnDecls;594 std::list< Expression * > dtors;595 };596 597 561 /// ValofExpr represents a GCC 'lambda expression' 598 562 class UntypedValofExpr : public Expression { -
src/SynTree/Initializer.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Initializer.cc -- 7 // Initializer.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Apr 11 17:36:10 201613 // Update Count : 2812 // Last Modified On : Wed Aug 12 14:05:25 2015 13 // Update Count : 14 14 14 // 15 15 16 16 #include "Initializer.h" 17 17 #include "Expression.h" 18 #include "Statement.h"19 18 #include "Common/utility.h" 20 19 21 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed) {}20 Initializer::Initializer() {} 22 21 23 22 Initializer::~Initializer() {} … … 32 31 void Initializer::print( std::ostream &os, int indent ) {} 33 32 34 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) { 35 34 } 36 35 37 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value )) {36 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) { 38 37 cloneAll(other.designators, designators ); 39 38 } … … 55 54 } 56 55 57 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed)58 : Initializer( maybeConstructed),initializers( _initializers ), designators( _designators ) {56 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) 57 : initializers( _initializers ), designators( _designators ) { 59 58 } 60 59 … … 66 65 67 66 void ListInit::print( std::ostream &os, int indent ) { 68 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 67 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 69 68 if ( ! designators.empty() ) { 70 69 os << std::string(indent + 2, ' ' ) << "designated by: ["; 71 70 for ( std::list < Expression * >::iterator i = designators.begin(); 72 71 i != designators.end(); i++ ) { 73 ( *i )->print(os, indent + 4 ); 72 ( *i )->print(os, indent + 4 ); 74 73 } // for 75 74 76 75 os << std::string(indent + 2, ' ' ) << "]"; 77 76 } // if 78 77 79 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 78 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 80 79 (*i)->print( os, indent + 2 ); 81 80 } 82 83 84 ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}85 ConstructorInit::~ConstructorInit() {86 delete ctor;87 delete init;88 }89 90 ConstructorInit *ConstructorInit::clone() const {91 return new ConstructorInit( *this );92 }93 94 void ConstructorInit::print( std::ostream &os, int indent ) {95 os << std::endl << std::string(indent, ' ') << "Constructor initializer: ";96 if ( ctor ) {97 os << " initially constructed with ";98 ctor->print( os, indent+2 );99 } // if100 101 if ( dtor ) {102 os << " destructed with ";103 dtor->print( os, indent+2 );104 }105 106 if ( init ) {107 os << " with fallback C-style initializer: ";108 init->print( os, indent+2 );109 }110 }111 112 std::ostream & operator<<( std::ostream & out, Initializer * init ) {113 init->print( out );114 return out;115 }116 117 81 // Local Variables: // 118 82 // tab-width: 4 // -
src/SynTree/Initializer.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Initializer.h -- 7 // Initializer.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Apr 12 13:49:13 201613 // Update Count : 1 911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:03:48 2015 13 // Update Count : 1 14 14 // 15 15 … … 27 27 public: 28 28 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 29 Initializer( bool maybeConstructed);29 Initializer( ); 30 30 virtual ~Initializer(); 31 31 … … 43 43 } 44 44 45 bool get_maybeConstructed() { return maybeConstructed; }46 47 45 virtual Initializer *clone() const = 0; 48 46 virtual void accept( Visitor &v ) = 0; … … 52 50 // std::string name; 53 51 // int pos; 54 bool maybeConstructed;55 52 }; 56 53 … … 58 55 class SingleInit : public Initializer { 59 56 public: 60 SingleInit( Expression *value, const std::list< Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false);57 SingleInit( Expression *value, std::list< Expression *> &designators = *(new std::list<Expression *>()) ); 61 58 SingleInit( const SingleInit &other ); 62 59 virtual ~SingleInit(); 63 60 64 61 Expression *get_value() { return value; } 65 62 void set_value( Expression *newValue ) { value = newValue; } … … 82 79 class ListInit : public Initializer { 83 80 public: 84 ListInit( const std::list<Initializer*> &initializers,85 const std::list<Expression *> &designators = std::list< Expression * >(), bool maybeConstructed = false);81 ListInit( std::list<Initializer*> &, 82 std::list<Expression *> &designators = *(new std::list<Expression *>()) ); 86 83 virtual ~ListInit(); 87 84 … … 103 100 }; 104 101 105 // ConstructorInit represents an initializer that is either a constructor expression or106 // a C-style initializer.107 class ConstructorInit : public Initializer {108 public:109 ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );110 virtual ~ConstructorInit();111 112 void set_ctor( Statement * newValue ) { ctor = newValue; }113 Statement * get_ctor() const { return ctor; }114 void set_dtor( Statement * newValue ) { dtor = newValue; }115 Statement * get_dtor() const { return dtor; }116 void set_init( Initializer * newValue ) { init = newValue; }117 Initializer * get_init() const { return init; }118 119 virtual ConstructorInit *clone() const;120 virtual void accept( Visitor &v ) { v.visit( this ); }121 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }122 virtual void print( std::ostream &os, int indent = 0 );123 124 private:125 Statement * ctor;126 Statement * dtor;127 // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback128 // if an appropriate constructor definition is not found by the resolver129 Initializer * init;130 };131 132 std::ostream & operator<<( std::ostream & out, Initializer * init );133 134 102 #endif // INITIALIZER_H 135 103 -
src/SynTree/Mutator.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Mutator.cc -- 7 // Mutator.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 18 17:29:55201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 18:05:16 2016 13 13 // Update Count : 16 14 14 // … … 337 337 } 338 338 339 Expression* Mutator::mutate( ImplicitCopyCtorExpr *impCpCtorExpr ) {340 impCpCtorExpr->set_callExpr( maybeMutate( impCpCtorExpr->get_callExpr(), *this ) );341 mutateAll( impCpCtorExpr->get_copyCtors(), *this );342 mutateAll( impCpCtorExpr->get_tempDecls(), *this );343 mutateAll( impCpCtorExpr->get_returnDecls(), *this );344 return impCpCtorExpr;345 }346 347 339 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 348 340 mutateAll( valofExpr->get_results(), *this ); … … 458 450 } 459 451 460 Initializer *Mutator::mutate( ConstructorInit *ctorInit ) {461 ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) );462 ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) );463 return ctorInit;464 }465 466 452 Subrange *Mutator::mutate( Subrange *subrange ) { 467 453 return subrange; -
src/SynTree/Mutator.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Mutator.h -- 7 // Mutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:32:00201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 17:26:56 2016 13 13 // Update Count : 10 14 14 // … … 62 62 virtual Expression* mutate( MemberExpr *memberExpr ); 63 63 virtual Expression* mutate( VariableExpr *variableExpr ); 64 virtual Expression* mutate( ConstantExpr *constantExpr ); 64 virtual Expression* mutate( ConstantExpr *constantExpr ); 65 65 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 66 66 virtual Expression* mutate( AlignofExpr *alignofExpr ); … … 76 76 virtual Expression* mutate( TypeExpr *typeExpr ); 77 77 virtual Expression* mutate( AsmExpr *asmExpr ); 78 virtual Expression* mutate( ImplicitCopyCtorExpr *impCpCtorExpr );79 78 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 80 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ); … … 97 96 virtual Initializer* mutate( SingleInit *singleInit ); 98 97 virtual Initializer* mutate( ListInit *listInit ); 99 virtual Initializer* mutate( ConstructorInit *ctorInit );100 98 101 99 virtual Subrange *mutate( Subrange *subrange ); -
src/SynTree/ObjectDecl.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ObjectDecl.cc -- 7 // ObjectDecl.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Feb 09 13:21:03 201613 // Update Count : 3012 // Last Modified On : Tue Sep 29 14:13:01 2015 13 // Update Count : 18 14 14 // 15 15 … … 19 19 #include "Expression.h" 20 20 #include "Common/utility.h" 21 #include "Statement.h"22 21 23 22 ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline, bool isNoreturn ) … … 59 58 os << " with initializer "; 60 59 init->print( os, indent ); 61 os << std::string(indent, ' ') << "maybeConstructed? " << init->get_maybeConstructed();62 60 } // if 63 61 … … 71 69 #if 0 72 70 if ( get_mangleName() != "") { 73 os << get_mangleName() << ": "; 74 } else 71 os << get_mangleName() << ": "; 72 } else 75 73 #endif 76 74 if ( get_name() != "" ) { -
src/SynTree/SynTree.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // SynTree.h -- 7 // SynTree.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:31:36201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 16:47:44 2016 13 13 // Update Count : 5 14 14 // … … 81 81 class TypeExpr; 82 82 class AsmExpr; 83 class ImplicitCopyCtorExpr;84 83 class UntypedValofExpr; 85 84 class CompoundLiteralExpr; … … 105 104 class SingleInit; 106 105 class ListInit; 107 class ConstructorInit;108 106 109 107 class Subrange; -
src/SynTree/Visitor.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Visitor.cc -- 7 // Visitor.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 18 17:30:10201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 18:05:13 2016 13 13 // Update Count : 18 14 14 // … … 284 284 } 285 285 286 void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) {287 maybeAccept( impCpCtorExpr->get_callExpr(), *this );288 acceptAll( impCpCtorExpr->get_copyCtors(), *this );289 acceptAll( impCpCtorExpr->get_tempDecls(), *this );290 acceptAll( impCpCtorExpr->get_returnDecls(), *this );291 }292 293 286 void Visitor::visit( UntypedValofExpr *valofExpr ) { 294 287 acceptAll( valofExpr->get_results(), *this ); … … 386 379 } 387 380 388 void Visitor::visit( ConstructorInit *ctorInit ) {389 maybeAccept( ctorInit->get_ctor(), *this );390 maybeAccept( ctorInit->get_init(), *this );391 }392 393 381 void Visitor::visit( Subrange *subrange ) {} 394 382 -
src/SynTree/Visitor.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Visitor.h -- 7 // Visitor.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 15:30:58201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 1 17:26:55 2016 13 13 // Update Count : 7 14 14 // … … 62 62 virtual void visit( MemberExpr *memberExpr ); 63 63 virtual void visit( VariableExpr *variableExpr ); 64 virtual void visit( ConstantExpr *constantExpr ); 64 virtual void visit( ConstantExpr *constantExpr ); 65 65 virtual void visit( SizeofExpr *sizeofExpr ); 66 66 virtual void visit( AlignofExpr *alignofExpr ); … … 76 76 virtual void visit( TypeExpr *typeExpr ); 77 77 virtual void visit( AsmExpr *asmExpr ); 78 virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr );79 78 virtual void visit( UntypedValofExpr *valofExpr ); 80 79 virtual void visit( CompoundLiteralExpr *compLitExpr ); … … 97 96 virtual void visit( SingleInit *singleInit ); 98 97 virtual void visit( ListInit *listInit ); 99 virtual void visit( ConstructorInit *ctorInit );100 98 101 99 virtual void visit( Subrange *subrange ); -
src/examples/vector_int.c
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // vector_int.c -- 7 // vector_int.c -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Wed May 27 17:56:53 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 06 17:18:31 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:38:05 2015 13 13 // Update Count : 3 14 14 // … … 22 22 #define DEFAULT_CAPACITY 20 23 23 24 v oid ?{}( vector_int * vec) {25 vec { DEFAULT_CAPACITY };24 vector_int vector_int_allocate() { 25 return vector_int_allocate( DEFAULT_CAPACITY ); 26 26 } 27 27 28 void ?{}( vector_int * vec, int reserve ) { 29 vec->last = -1; 30 vec->capacity = reserve; 31 vec->data = malloc( sizeof( int ) * reserve ); 28 vector_int vector_int_allocate( int reserve ) { 29 vector_int new_vector; 30 new_vector.last = -1; 31 new_vector.capacity = reserve; 32 new_vector.data = malloc( sizeof( int ) * reserve ); 33 return new_vector; 32 34 } 33 35 34 void ^?{}( vector_int *vec ) {35 free( vec ->data );36 void vector_int_deallocate( vector_int vec ) { 37 free( vec.data ); 36 38 } 37 39 -
src/examples/vector_int.h
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // vector_int.h -- 7 // vector_int.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Wed May 27 17:56:53 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 06 17:21:59 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:39:05 2015 13 13 // Update Count : 2 14 14 // … … 25 25 } vector_int; 26 26 27 v oid ?{}( vector_int * );// allocate vector with default capacity28 v oid ?{}( vector_int *, int reserve );// allocate vector with specified capacity29 void ^?{}( vector_int * );// deallocate vector's storage27 vector_int vector_int_allocate(); // allocate vector with default capacity 28 vector_int vector_int_allocate( int reserve ); // allocate vector with specified capacity 29 void vector_int_deallocate( vector_int ); // deallocate vector's storage 30 30 31 31 void reserve( vector_int *vec, int reserve ); // reserve more capacity -
src/examples/vector_test.c
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // vector_test.c -- 7 // vector_test.c -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Wed May 27 17:56:53 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Apr 06 17:19:07201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 17 12:23:55 2016 13 13 // Update Count : 18 14 14 // … … 20 20 21 21 int main( void ) { 22 vector_int vec ;22 vector_int vec = vector_int_allocate(); 23 23 24 24 // read in numbers until EOF or error -
src/initialization.txt
rfbfb38e r6812d89 34 34 sure that resolved initializers for all declarations are being 35 35 generated. 36 37 38 ------39 40 More recent email: (I am quoted; Richard is the responder)41 > As far as I'm aware, the only way that I could currently get the correct42 > results from the unification engine is by feeding it an expression that43 > looks like "?=?( ((struct Y)x.y).a, 10 )", then picking out the pieces that44 > I need (namely the correct choice for a). Does this seem like a reasonable45 > approach to solve this problem?46 47 No, unfortunately. Initialization isn't being rewritten as assignment,48 so you shouldn't allow the particular selection of assignment49 operators that happen to be in scope (and which may include50 user-defined operators) to guide the type resolution.51 52 I don't think there is any way to rewrite an initializer as a single53 expression and have the resolver just do the right thing. I see the54 algorithm as:55 56 For each alternative interpretation of the designator:57 Construct an expression that casts the initializer to the type of58 the designator59 Construct an AlternativeFinder and use it to find the lowest cost60 interpretation of the expression61 Add this interpretation to a list of possibilities62 Go through the list of possibilities and pick the lowest cost63 64 As with many things in the resolver, it's conceptually simple but the65 implementation may be a bit of a pain. It fits in with functions like66 findSingleExpression, findIntegralExpression in Resolver.cc, although67 it will be significantly more complicated than any of the existing68 ones.69 70 71 -
src/libcfa/Makefile.am
rfbfb38e r6812d89 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## Makefile.am -- 8 ## Makefile.am -- 9 9 ## 10 10 ## Author : Peter A. Buhr … … 51 51 52 52 CFLAGS = -g -Wall -Wno-unused-function -B${abs_top_srcdir}/src/driver -XCFA -t # TEMPORARY: does not build with -O2 53 CC = ${abs_top_srcdir}/src/driver/cfa 53 CC = ${abs_top_srcdir}/src/driver/cfa 54 54 55 55 # extension-less header files are overridden by default make rules => explicitly override rule … … 67 67 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} 68 68 69 CLEANFILES = libcfa-prelude.c70 69 MAINTAINERCLEANFILES += ${includedir}/* -
src/libcfa/Makefile.in
rfbfb38e r6812d89 111 111 AWK = @AWK@ 112 112 BACKEND_CC = @BACKEND_CC@ 113 CC = ${abs_top_srcdir}/src/driver/cfa 113 CC = ${abs_top_srcdir}/src/driver/cfa 114 114 CCDEPMODE = @CCDEPMODE@ 115 115 CFA_BINDIR = @CFA_BINDIR@ … … 219 219 cfaheaders = # limits 220 220 include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders} 221 CLEANFILES = libcfa-prelude.c222 221 all: all-am 223 222 … … 458 457 459 458 clean-generic: 460 -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)461 459 462 460 distclean-generic: -
src/libcfa/fstream.c
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fstream.c -- 7 // fstream.c -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 17:04:24201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 6 17:55:27 2016 13 13 // Update Count : 176 14 14 // … … 75 75 if ( fclose( (FILE *)(os->file) ) == EOF ) { 76 76 perror( IO_MSG "close output" ); 77 } // if 77 } // if 78 78 } // close 79 79 … … 139 139 if ( fclose( (FILE *)(is->file) ) == EOF ) { 140 140 perror( IO_MSG "close input" ); 141 } // if 141 } // if 142 142 } // close 143 143 … … 154 154 return is; 155 155 } // read 156 156 157 157 ifstream *ungetc( ifstream * is, char c ) { 158 158 if ( fail( is ) ) { -
src/libcfa/iostream.c
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // iostream.c -- 7 // iostream.c -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Wed May 27 17:56:53 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Apr 14 16:02:09 201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 6 16:13:29 2016 13 13 // Update Count : 278 14 14 // … … 193 193 194 194 195 forall( dtype ostype | ostream( ostype ) ) 195 forall( dtype ostype | ostream( ostype ) ) 196 196 ostype * ?|?( ostype *os, ostype * (* manip)( ostype * ) ) { 197 197 return manip( os ); 198 198 } // ?|? 199 199 200 forall( dtype ostype | ostream( ostype ) ) 200 forall( dtype ostype | ostream( ostype ) ) 201 201 ostype * endl( ostype * os ) { 202 202 os | '\n'; … … 206 206 } // endl 207 207 208 forall( dtype ostype | ostream( ostype ) ) 208 forall( dtype ostype | ostream( ostype ) ) 209 209 ostype * sepOn( ostype * os ) { 210 210 sepOn( os ); … … 212 212 } // sepOn 213 213 214 forall( dtype ostype | ostream( ostype ) ) 214 forall( dtype ostype | ostream( ostype ) ) 215 215 ostype * sepOff( ostype * os ) { 216 216 sepOff( os ); … … 218 218 } // sepOff 219 219 220 forall( dtype ostype | ostream( ostype ) ) 220 forall( dtype ostype | ostream( ostype ) ) 221 221 ostype * sepEnable( ostype * os ) { 222 222 sepEnable( os ); … … 224 224 } // sepEnable 225 225 226 forall( dtype ostype | ostream( ostype ) ) 226 forall( dtype ostype | ostream( ostype ) ) 227 227 ostype * sepDisable( ostype * os ) { 228 228 sepDisable( os ); … … 344 344 } // ?|? 345 345 346 _Istream_cstrUC cstr( char * s tr ) { _Istream_cstrUC s = { str}; return s; }346 _Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; } 347 347 forall( dtype istype | istream( istype ) ) 348 348 istype * ?|?( istype * is, _Istream_cstrUC cstr ) { … … 351 351 } // cstr 352 352 353 _Istream_cstrC cstr( char * s tr, int size ) { _Istream_cstrC s = { str, size }; return s; }353 _Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; } 354 354 forall( dtype istype | istream( istype ) ) 355 355 istype * ?|?( istype * is, _Istream_cstrC cstr ) { -
src/libcfa/prelude.cf
rfbfb38e r6812d89 1 1 # 2 "prelude.cf" // needed for error messages from this file 2 // -*- Mode: C -*- 3 // 2 // -*- Mode: C -*- 3 // 4 4 // Copyright (C) Glen Ditchfield 1994, 1999 5 // 5 // 6 6 // prelude.cf -- Standard Cforall Preample for C99 7 // 7 // 8 8 // Author : Glen Ditchfield 9 9 // Created On : Sat Nov 29 07:23:41 2014 … … 117 117 forall( ftype FT ) lvalue FT *?( FT * ); 118 118 119 _Bool +?( _Bool ), -?( _Bool ), ~?( _Bool ); 120 signed int +?( signed int ), -?( signed int ), ~?( signed int ); 121 unsigned int +?( unsigned int ), -?( unsigned int ), ~?( unsigned int ); 122 signed long int +?( signed long int ), -?( signed long int ), ~?( signed long int ); 123 unsigned long int +?( unsigned long int ), -?( unsigned long int ), ~?( unsigned long int ); 124 signed long long int +?( signed long long int ), -?( signed long long int ), ~?( signed long long int ); 125 unsigned long long int +?( unsigned long long int ), -?( unsigned long long int ), ~?( unsigned long long int ); 119 _Bool +?( _Bool ), -?( _Bool ), ~?( _Bool ); 120 signed int +?( signed int ), -?( signed int ), ~?( signed int ); 121 unsigned int +?( unsigned int ), -?( unsigned int ), ~?( unsigned int ); 122 signed long int +?( signed long int ), -?( signed long int ), ~?( signed long int ); 123 unsigned long int +?( unsigned long int ), -?( unsigned long int ), ~?( unsigned long int ); 124 signed long long int +?( signed long long int ), -?( signed long long int ), ~?( signed long long int ); 125 unsigned long long int +?( unsigned long long int ), -?( unsigned long long int ), ~?( unsigned long long int ); 126 126 float +?( float ), -?( float ); 127 127 double +?( double ), -?( double ); … … 627 627 ?+=?( long double _Complex *, long double _Complex ), ?+=?( volatile long double _Complex *, long double _Complex ), 628 628 ?-=?( long double _Complex *, long double _Complex ), ?-=?( volatile long double _Complex *, long double _Complex ); 629 630 631 632 633 634 // ------------------------------------------------------------635 //636 // Section ??? Constructors and Destructors637 //638 // ------------------------------------------------------------639 640 // default ctor641 void ?{}( _Bool * ), ?{}( volatile _Bool * );642 void ?{}( char * ), ?{}( volatile char * );643 void ?{}( unsigned char * ), ?{}( volatile unsigned char * );644 void ?{}( char signed * ), ?{}( volatile char signed * );645 void ?{}( int short * ), ?{}( volatile int short * );646 void ?{}( int short unsigned * ), ?{}( volatile int short unsigned * );647 void ?{}( signed int * ), ?{}( volatile signed int * );648 void ?{}( unsigned int * ), ?{}( volatile unsigned int * );649 void ?{}( signed long int * ), ?{}( volatile signed long int * );650 void ?{}( unsigned long int * ), ?{}( volatile unsigned long int * );651 void ?{}( signed long long int * ), ?{}( volatile signed long long int * );652 void ?{}( unsigned long long int * ), ?{}( volatile unsigned long long int * );653 void ?{}( float * ), ?{}( volatile float * );654 void ?{}( double * ), ?{}( volatile double * );655 void ?{}( long double * ), ?{}( volatile long double * );656 void ?{}( float _Complex * ), ?{}( volatile float _Complex * );657 void ?{}( double _Complex * ), ?{}( volatile double _Complex * );658 void ?{}( long double _Complex * ), ?{}( volatile long double _Complex * );659 660 // copy ctor661 void ?{}( _Bool *, _Bool ), ?{}( volatile _Bool *, _Bool );662 void ?{}( char *, char ), ?{}( volatile char *, char );663 void ?{}( unsigned char *, unsigned char ), ?{}( volatile unsigned char *, unsigned char );664 void ?{}( char signed *, char signed ), ?{}( volatile char signed *, char signed );665 void ?{}( int short *, int short ), ?{}( volatile int short *, int short );666 void ?{}( int short unsigned *, int short unsigned ), ?{}( volatile int short unsigned *, int short unsigned );667 void ?{}( signed int *, signed int), ?{}( volatile signed int *, signed int );668 void ?{}( unsigned int *, unsigned int), ?{}( volatile unsigned int *, unsigned int );669 void ?{}( signed long int *, signed long int), ?{}( volatile signed long int *, signed long int );670 void ?{}( unsigned long int *, unsigned long int), ?{}( volatile unsigned long int *, unsigned long int );671 void ?{}( signed long long int *, signed long long int), ?{}( volatile signed long long int *, signed long long int );672 void ?{}( unsigned long long int *, unsigned long long int), ?{}( volatile unsigned long long int *, unsigned long long int );673 void ?{}( float *, float), ?{}( volatile float *, float );674 void ?{}( double *, double), ?{}( volatile double *, double );675 void ?{}( long double *, long double), ?{}( volatile long double *, long double );676 void ?{}( float _Complex *, float _Complex), ?{}( volatile float _Complex *, float _Complex );677 void ?{}( double _Complex *, double _Complex), ?{}( volatile double _Complex *, double _Complex );678 void ?{}( long double _Complex *, long double _Complex), ?{}( volatile long double _Complex *, long double _Complex );679 680 // dtor681 void ^?{}( _Bool * ), ^?{}( volatile _Bool * );682 void ^?{}( char * ), ^?{}( volatile char * );683 void ^?{}( char unsigned * ), ^?{}( volatile char unsigned * );684 void ^?{}( char signed * ), ^?{}( volatile char signed * );685 void ^?{}( int short * ), ^?{}( volatile int short * );686 void ^?{}( int short unsigned * ), ^?{}( volatile int short unsigned * );687 void ^?{}( signed int * ), ^?{}( volatile signed int * );688 void ^?{}( unsigned int * ), ^?{}( volatile unsigned int * );689 void ^?{}( signed long int * ), ^?{}( volatile signed long int * );690 void ^?{}( unsigned long int * ), ^?{}( volatile unsigned long int * );691 void ^?{}( signed long long int * ), ^?{}( volatile signed long long int * );692 void ^?{}( unsigned long long int * ), ^?{}( volatile unsigned long long int * );693 void ^?{}( float * ), ^?{}( volatile float * );694 void ^?{}( double * ), ^?{}( volatile double * );695 void ^?{}( long double * ), ^?{}( volatile long double * );696 void ^?{}( float _Complex * ), ^?{}( volatile float _Complex * );697 void ^?{}( double _Complex * ), ^?{}( volatile double _Complex * );698 void ^?{}( long double _Complex * ), ^?{}( volatile long double _Complex * );699 700 // // default ctor701 // forall( dtype DT ) void ?{}( DT ** );702 // forall( dtype DT ) void ?{}( const DT ** );703 // forall( dtype DT ) void ?{}( volatile DT ** );704 // forall( dtype DT ) void ?{}( const volatile DT ** );705 706 // // copy ctor707 // forall( dtype DT ) void ?{}( DT **, DT* );708 // forall( dtype DT ) void ?{}( const DT **, DT* );709 // forall( dtype DT ) void ?{}( volatile DT **, DT* );710 // forall( dtype DT ) void ?{}( const volatile DT **, DT* );711 712 // // dtor713 // forall( dtype DT ) void ^?{}( DT ** );714 // forall( dtype DT ) void ^?{}( const DT ** );715 // forall( dtype DT ) void ^?{}( volatile DT ** );716 // forall( dtype DT ) void ^?{}( const volatile DT ** );717 718 // copied from assignment section719 // copy constructors720 forall( ftype FT ) void ?{}( FT **, FT * );721 forall( ftype FT ) void ?{}( FT * volatile *, FT * );722 723 forall( dtype DT ) void ?{}( DT * *, DT * );724 forall( dtype DT ) void ?{}( DT * volatile *, DT * );725 forall( dtype DT ) void ?{}( const DT * *, DT * );726 forall( dtype DT ) void ?{}( const DT * volatile *, DT * );727 forall( dtype DT ) void ?{}( const DT * *, const DT * );728 forall( dtype DT ) void ?{}( const DT * volatile *, const DT * );729 forall( dtype DT ) void ?{}( volatile DT * *, DT * );730 forall( dtype DT ) void ?{}( volatile DT * volatile *, DT * );731 forall( dtype DT ) void ?{}( volatile DT * *, volatile DT * );732 forall( dtype DT ) void ?{}( volatile DT * volatile *, volatile DT * );733 734 forall( dtype DT ) void ?{}( const volatile DT * *, DT * );735 forall( dtype DT ) void ?{}( const volatile DT * volatile *, DT * );736 forall( dtype DT ) void ?{}( const volatile DT * *, const DT * );737 forall( dtype DT ) void ?{}( const volatile DT * volatile *, const DT * );738 forall( dtype DT ) void ?{}( const volatile DT * *, volatile DT * );739 forall( dtype DT ) void ?{}( const volatile DT * volatile *, volatile DT * );740 forall( dtype DT ) void ?{}( const volatile DT * *, const volatile DT * );741 forall( dtype DT ) void ?{}( const volatile DT * volatile *, const volatile DT * );742 743 forall( dtype DT ) void ?{}( DT * *, void * );744 forall( dtype DT ) void ?{}( DT * volatile *, void * );745 forall( dtype DT ) void ?{}( const DT * *, void * );746 forall( dtype DT ) void ?{}( const DT * volatile *, void * );747 forall( dtype DT ) void ?{}( const DT * *, const void * );748 forall( dtype DT ) void ?{}( const DT * volatile *, const void * );749 forall( dtype DT ) void ?{}( volatile DT * *, void * );750 forall( dtype DT ) void ?{}( volatile DT * volatile *, void * );751 forall( dtype DT ) void ?{}( volatile DT * *, volatile void * );752 forall( dtype DT ) void ?{}( volatile DT * volatile *, volatile void * );753 754 forall( dtype DT ) void ?{}( const volatile DT * *, void * );755 forall( dtype DT ) void ?{}( const volatile DT * volatile *, void * );756 forall( dtype DT ) void ?{}( const volatile DT * *, const void * );757 forall( dtype DT ) void ?{}( const volatile DT * volatile *, const void * );758 forall( dtype DT ) void ?{}( const volatile DT * *, volatile void * );759 forall( dtype DT ) void ?{}( const volatile DT * volatile *, volatile void * );760 forall( dtype DT ) void ?{}( const volatile DT * *, const volatile void * );761 forall( dtype DT ) void ?{}( const volatile DT * volatile *, const volatile void * );762 763 forall( dtype DT ) void ?{}( void * *, DT * );764 forall( dtype DT ) void ?{}( void * volatile *, DT * );765 forall( dtype DT ) void ?{}( const void * *, DT * );766 forall( dtype DT ) void ?{}( const void * volatile *, DT * );767 forall( dtype DT ) void ?{}( const void * *, const DT * );768 forall( dtype DT ) void ?{}( const void * volatile *, const DT * );769 forall( dtype DT ) void ?{}( volatile void * *, DT * );770 forall( dtype DT ) void ?{}( volatile void * volatile *, DT * );771 forall( dtype DT ) void ?{}( volatile void * *, volatile DT * );772 forall( dtype DT ) void ?{}( volatile void * volatile *, volatile DT * );773 forall( dtype DT ) void ?{}( const volatile void * *, DT * );774 forall( dtype DT ) void ?{}( const volatile void * volatile *, DT * );775 forall( dtype DT ) void ?{}( const volatile void * *, const DT * );776 forall( dtype DT ) void ?{}( const volatile void * volatile *, const DT * );777 forall( dtype DT ) void ?{}( const volatile void * *, volatile DT * );778 forall( dtype DT ) void ?{}( const volatile void * volatile *, volatile DT * );779 forall( dtype DT ) void ?{}( const volatile void * *, const volatile DT * );780 forall( dtype DT ) void ?{}( const volatile void * volatile *, const volatile DT * );781 782 void ?{}( void * *, void * );783 void ?{}( void * volatile *, void * );784 void ?{}( const void * *, void * );785 void ?{}( const void * volatile *, void * );786 void ?{}( const void * *, const void * );787 void ?{}( const void * volatile *, const void * );788 void ?{}( volatile void * *, void * );789 void ?{}( volatile void * volatile *, void * );790 void ?{}( volatile void * *, volatile void * );791 void ?{}( volatile void * volatile *, volatile void * );792 void ?{}( const volatile void * *, void * );793 void ?{}( const volatile void * volatile *, void * );794 void ?{}( const volatile void * *, const void * );795 void ?{}( const volatile void * volatile *, const void * );796 void ?{}( const volatile void * *, volatile void * );797 void ?{}( const volatile void * volatile *, volatile void * );798 void ?{}( const volatile void * *, const volatile void * );799 void ?{}( const volatile void * volatile *, const volatile void * );800 801 //forall( dtype DT ) void ?{}( DT * *, forall( dtype DT2 ) const DT2 * );802 //forall( dtype DT ) void ?{}( DT * volatile *, forall( dtype DT2 ) const DT2 * );803 forall( dtype DT ) void ?{}( const DT * *, forall( dtype DT2 ) const DT2 * );804 forall( dtype DT ) void ?{}( const DT * volatile *, forall( dtype DT2 ) const DT2 * );805 //forall( dtype DT ) void ?{}( volatile DT * *, forall( dtype DT2 ) const DT2 * );806 //forall( dtype DT ) void ?{}( volatile DT * volatile *, forall( dtype DT2 ) const DT2 * );807 forall( dtype DT ) void ?{}( const volatile DT * *, forall( dtype DT2 ) const DT2 * );808 forall( dtype DT ) void ?{}( const volatile DT * volatile *, forall( dtype DT2 ) const DT2 * );809 810 forall( ftype FT ) void ?{}( FT * *, forall( ftype FT2 ) FT2 * );811 forall( ftype FT ) void ?{}( FT * volatile *, forall( ftype FT2 ) FT2 * );812 813 // default ctors814 forall( ftype FT ) void ?{}( FT * * );815 forall( ftype FT ) void ?{}( FT * volatile * );816 817 forall( dtype DT ) void ?{}( DT * *);818 forall( dtype DT ) void ?{}( DT * volatile *);819 forall( dtype DT ) void ?{}( const DT * *);820 forall( dtype DT ) void ?{}( const DT * volatile *);821 forall( dtype DT ) void ?{}( volatile DT * *);822 forall( dtype DT ) void ?{}( volatile DT * volatile *);823 forall( dtype DT ) void ?{}( const volatile DT * *);824 forall( dtype DT ) void ?{}( const volatile DT * volatile *);825 826 void ?{}( void * *);827 void ?{}( void * volatile *);828 void ?{}( const void * *);829 void ?{}( const void * volatile *);830 void ?{}( volatile void * *);831 void ?{}( volatile void * volatile *);832 void ?{}( const volatile void * *);833 void ?{}( const volatile void * volatile *);834 835 // dtors836 forall( ftype FT ) void ^?{}( FT * * );837 forall( ftype FT ) void ^?{}( FT * volatile * );838 839 forall( dtype DT ) void ^?{}( DT * *);840 forall( dtype DT ) void ^?{}( DT * volatile *);841 forall( dtype DT ) void ^?{}( const DT * *);842 forall( dtype DT ) void ^?{}( const DT * volatile *);843 forall( dtype DT ) void ^?{}( volatile DT * *);844 forall( dtype DT ) void ^?{}( volatile DT * volatile *);845 forall( dtype DT ) void ^?{}( const volatile DT * *);846 forall( dtype DT ) void ^?{}( const volatile DT * volatile *);847 848 void ^?{}( void * *);849 void ^?{}( void * volatile *);850 void ^?{}( const void * *);851 void ^?{}( const void * volatile *);852 void ^?{}( volatile void * *);853 void ^?{}( volatile void * volatile *);854 void ^?{}( const volatile void * *);855 void ^?{}( const volatile void * volatile *); -
src/main.cc
rfbfb38e r6812d89 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // main.cc -- 7 // main.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Apr 11 17:49:38201613 // Update Count : 20011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 27 22:20:20 2016 13 // Update Count : 199 14 14 // 15 15 … … 41 41 #include "InitTweak/Mutate.h" 42 42 #include "InitTweak/RemoveInit.h" 43 #include "InitTweak/FixInit.h"44 43 //#include "Explain/GenProlog.h" 45 44 //#include "Try/Visit.h" … … 56 55 57 56 static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 58 static void dump( std::list< Declaration * > & translationUnit , std::ostream & out = std::cout);57 static void dump( std::list< Declaration * > & translationUnit ); 59 58 60 59 bool 61 60 astp = false, 62 61 bresolvep = false, 63 ctorinitp = false,64 62 exprp = false, 65 63 expraltp = false, … … 76 74 codegenp = false; 77 75 78 enum { Ast, Bresolver, CtorInitFix,Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };76 enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, }; 79 77 80 78 static struct option long_opts[] = { 81 79 { "ast", no_argument, 0, Ast }, 82 80 { "before-resolver", no_argument, 0, Bresolver }, 83 { "ctorinitfix", no_argument, 0, CtorInitFix },84 81 { "expr", no_argument, 0, Expr }, 85 82 { "expralt", no_argument, 0, ExprAlt }, … … 103 100 104 101 opterr = 0; // prevent getopt from printing error messages 105 102 106 103 int c; 107 while ( (c = getopt_long( argc, argv, "ab cefFglnpqrstvyzD:", long_opts, &long_index )) != -1 ) {104 while ( (c = getopt_long( argc, argv, "abefglnpqrstvyzD:", long_opts, &long_index )) != -1 ) { 108 105 switch ( c ) { 109 106 case Ast: … … 114 111 case 'b': // print before resolver steps 115 112 bresolvep = true; 116 break;117 case CtorInitFix:118 case 'c':119 ctorinitp = true;120 113 break; 121 114 case Expr: … … 194 187 output = new ofstream( argv[ optind ] ); 195 188 } // if 196 189 197 190 Parser::get_parser().set_debug( grammarp ); 198 191 … … 215 208 exit( 1 ); 216 209 } // if 217 210 218 211 parse( prelude, LinkageSpec::Intrinsic ); 219 212 } // if 220 213 } // if 221 214 222 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 223 215 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 216 224 217 if ( parsep ) { 225 218 Parser::get_parser().get_parseTree()->printList( std::cout ); … … 256 249 OPTPRINT( "mutate" ) 257 250 ControlStruct::mutate( translationUnit ); 258 OPTPRINT( "fixNames" ) 251 OPTPRINT( "fixNames" ) 259 252 CodeGen::fixNames( translationUnit ); 260 OPTPRINT( "tweak Init" )253 OPTPRINT( "tweak" ) 261 254 InitTweak::tweak( translationUnit ); 262 255 … … 275 268 if ( exprp ) { 276 269 dump( translationUnit ); 277 return 0;278 }279 280 OPTPRINT( "fixInit" )281 // fix ObjectDecl - replaces ConstructorInit nodes282 InitTweak::fix( translationUnit );283 if ( ctorinitp ) {284 dump ( translationUnit );285 return 0;286 270 } 287 271 … … 294 278 OPTPRINT( "box" ) 295 279 GenPoly::box( translationUnit ); 296 280 297 281 // print tree right before code generation 298 282 if ( codegenp ) { … … 308 292 } catch ( SemanticError &e ) { 309 293 if ( errorp ) { 310 std::cerr << "---AST at error:---" << std::endl; 311 dump( translationUnit, std::cerr ); 312 std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl; 294 dump( translationUnit ); 313 295 } 314 296 e.print( std::cerr ); … … 332 314 } // try 333 315 334 deleteAll( translationUnit );335 316 return 0; 336 317 } // main … … 350 331 } 351 332 352 static void dump( std::list< Declaration * > & translationUnit , std::ostream & out) {333 static void dump( std::list< Declaration * > & translationUnit ) { 353 334 std::list< Declaration * > decls; 354 335 if ( noprotop ) { 355 filter( translationUnit.begin(), translationUnit.end(), 336 filter( translationUnit.begin(), translationUnit.end(), 356 337 std::back_inserter( decls ), notPrelude ); 357 338 } else { … … 359 340 } 360 341 361 printAll( decls, out );342 printAll( decls, std::cout ); 362 343 deleteAll( translationUnit ); 363 344 }
Note:
See TracChangeset
for help on using the changeset viewer.