Changeset 71f4e4f
- Timestamp:
- Jan 13, 2016, 5:19:47 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- f1e012b
- Parents:
- 02c7d04
- Location:
- src
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r02c7d04 r71f4e4f 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 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Sep 17 15:25:58 201513 // Update Count : 23 312 // Last Modified On : Wed Jan 13 16:26:59 2016 13 // Update Count : 234 14 14 // 15 15 … … 98 98 handleStorageClass( objectDecl ); 99 99 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); 100 100 101 101 if ( objectDecl->get_init() ) { 102 102 output << " = "; … … 112 112 if ( aggDecl->get_name() != "" ) 113 113 output << aggDecl->get_name(); 114 114 115 115 std::list< Declaration * > &memb = aggDecl->get_members(); 116 116 … … 118 118 output << " {" << endl; 119 119 120 cur_indent += CodeGenerator::tabsize; 120 cur_indent += CodeGenerator::tabsize; 121 121 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 122 output << indent; 122 output << indent; 123 123 (*i)->accept( *this ); 124 124 output << ";" << endl; 125 125 } 126 126 127 cur_indent -= CodeGenerator::tabsize; 127 cur_indent -= CodeGenerator::tabsize; 128 128 129 129 output << indent << "}"; … … 140 140 handleAggregate( aggregateDecl ); 141 141 } 142 142 143 143 void CodeGenerator::visit( EnumDecl *aggDecl ) { 144 144 output << "enum "; … … 146 146 if ( aggDecl->get_name() != "" ) 147 147 output << aggDecl->get_name(); 148 148 149 149 std::list< Declaration* > &memb = aggDecl->get_members(); 150 150 … … 152 152 output << " {" << endl; 153 153 154 cur_indent += CodeGenerator::tabsize; 154 cur_indent += CodeGenerator::tabsize; 155 155 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 156 156 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 157 157 assert( obj ); 158 output << indent << mangleName( obj ); 158 output << indent << mangleName( obj ); 159 159 if ( obj->get_init() ) { 160 160 output << " = "; … … 164 164 } // for 165 165 166 cur_indent -= CodeGenerator::tabsize; 166 cur_indent -= CodeGenerator::tabsize; 167 167 168 168 output << indent << "}"; 169 169 } // if 170 170 } 171 171 172 172 void CodeGenerator::visit( ContextDecl *aggregateDecl ) {} 173 173 174 174 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 175 175 output << "typedef "; 176 176 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 177 177 } 178 178 179 179 void CodeGenerator::visit( TypeDecl *typeDecl ) { 180 180 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, … … 216 216 } 217 217 218 void CodeGenerator::visit( Constant *constant ) { 218 void CodeGenerator::visit( Constant *constant ) { 219 219 output << constant->get_value() ; 220 220 } … … 233 233 assert( arg != applicationExpr->get_args().end() ); 234 234 if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) { 235 235 236 236 *arg = addrExpr->get_arg(); 237 237 } else { … … 242 242 break; 243 243 } 244 244 245 245 default: 246 246 // do nothing 247 247 ; 248 248 } 249 249 250 250 switch ( opInfo.type ) { 251 251 case OT_INDEX: … … 256 256 output << "]"; 257 257 break; 258 258 259 259 case OT_CALL: 260 260 case OT_CTOR: … … 263 263 assert( false ); 264 264 break; 265 265 266 266 case OT_PREFIX: 267 267 case OT_PREFIXASSIGN: … … 272 272 output << ")"; 273 273 break; 274 274 275 275 case OT_POSTFIX: 276 276 case OT_POSTFIXASSIGN: … … 289 289 output << ")"; 290 290 break; 291 291 292 292 case OT_CONSTANT: 293 293 case OT_LABELADDRESS: … … 308 308 } // if 309 309 } 310 310 311 311 void CodeGenerator::visit( UntypedExpr *untypedExpr ) { 312 312 if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) { … … 322 322 output << "]"; 323 323 break; 324 324 325 325 case OT_CALL: 326 326 case OT_CTOR: … … 328 328 assert( false ); 329 329 break; 330 330 331 331 case OT_PREFIX: 332 332 case OT_PREFIXASSIGN: … … 338 338 output << ")"; 339 339 break; 340 340 341 341 case OT_POSTFIX: 342 342 case OT_POSTFIXASSIGN: … … 345 345 output << opInfo.symbol; 346 346 break; 347 347 348 348 case OT_INFIX: 349 349 case OT_INFIXASSIGN: … … 355 355 output << ")"; 356 356 break; 357 357 358 358 case OT_CONSTANT: 359 359 // there are no intrinsic definitions of 0 or 1 as functions … … 373 373 } // if 374 374 } 375 375 376 376 void CodeGenerator::visit( NameExpr *nameExpr ) { 377 377 OperatorInfo opInfo; … … 383 383 } // if 384 384 } 385 385 386 386 void CodeGenerator::visit( AddressExpr *addressExpr ) { 387 387 output << "(&"; … … 410 410 output << ")"; 411 411 castExpr->get_arg()->accept( *this ); 412 output << ")"; 412 output << ")"; 413 413 } 414 414 } 415 415 416 416 void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) { 417 417 assert( false ); 418 418 } 419 419 420 420 void CodeGenerator::visit( MemberExpr *memberExpr ) { 421 421 memberExpr->get_aggregate()->accept( *this ); 422 422 output << "." << mangleName( memberExpr->get_member() ); 423 423 } 424 424 425 425 void CodeGenerator::visit( VariableExpr *variableExpr ) { 426 426 OperatorInfo opInfo; … … 431 431 } // if 432 432 } 433 433 434 434 void CodeGenerator::visit( ConstantExpr *constantExpr ) { 435 435 assert( constantExpr->get_constant() ); 436 436 constantExpr->get_constant()->accept( *this ); 437 437 } 438 438 439 439 void CodeGenerator::visit( SizeofExpr *sizeofExpr ) { 440 440 output << "sizeof("; … … 457 457 output << ")"; 458 458 } 459 459 460 460 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { 461 461 output << "("; … … 469 469 output << ")"; 470 470 } 471 471 472 472 void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) { 473 473 output << "("; … … 479 479 output << ")"; 480 480 } 481 481 482 482 void CodeGenerator::visit( CommaExpr *commaExpr ) { 483 483 output << "("; … … 487 487 output << ")"; 488 488 } 489 489 490 490 void CodeGenerator::visit( TupleExpr *tupleExpr ) {} 491 491 492 492 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 493 493 … … 520 520 } 521 521 } 522 cur_indent -= CodeGenerator::tabsize; 522 cur_indent -= CodeGenerator::tabsize; 523 523 524 524 output << indent << "}"; … … 526 526 527 527 void CodeGenerator::visit( ExprStmt *exprStmt ) { 528 // I don't see why this check is necessary. 529 // If this starts to cause problems then put it back in, 528 // I don't see why this check is necessary. 529 // If this starts to cause problems then put it back in, 530 530 // with an explanation 531 531 assert( exprStmt ); … … 577 577 switchStmt->get_condition()->accept( *this ); 578 578 output << " ) "; 579 579 580 580 output << "{" << std::endl; 581 581 cur_indent += CodeGenerator::tabsize; … … 597 597 } // if 598 598 output << ":\n"; 599 599 600 600 std::list<Statement *> sts = caseStmt->get_statements(); 601 601 … … 614 614 if ( ! branchStmt->get_target().empty() ) 615 615 output << "goto " << branchStmt->get_target(); 616 else { 616 else { 617 617 if ( branchStmt->get_computedTarget() != 0 ) { 618 618 output << "goto *"; … … 665 665 666 666 void CodeGenerator::visit( ForStmt *forStmt ) { 667 // initialization is always hoisted, so don't 668 // bother doing anything with that 667 // initialization is always hoisted, so don't 668 // bother doing anything with that 669 669 output << "for (;"; 670 670 … … 690 690 void CodeGenerator::visit( DeclStmt *declStmt ) { 691 691 declStmt->get_decl()->accept( *this ); 692 692 693 693 if ( doSemicolon( declStmt->get_decl() ) ) { 694 694 output << ";"; -
src/InitTweak/RemoveInit.cc
r02c7d04 r71f4e4f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jan 11 16:10:45 201613 // Update Count : 15 012 // Last Modified On : Wed Jan 13 15:19:35 2016 13 // Update Count : 154 14 14 // 15 15 … … 148 148 } 149 149 150 Expr Stmt * makeCtorDtorStmt( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) {150 Expression * makeCtorDtorExpr( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) { 151 151 UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) ); 152 152 expr->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 153 153 expr->get_args().splice( expr->get_args().end(), args ); 154 return new ExprStmt( noLabels, expr );154 return expr; 155 155 } 156 156 … … 186 186 // hands off if designated or if @= 187 187 if ( tryConstruct( objDecl ) ) { 188 ExprStmt * ctor = makeCtorDtorStmt( "?{}", objDecl, makeInitList( objDecl->get_init() ) ); 189 ExprStmt * dtor = makeCtorDtorStmt( "^?{}", objDecl, std::list< Expression * >() ); 190 191 // set_ctor... 188 Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) ); 189 Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() ); 190 192 191 // need to remember init expression, in case no ctors exist 193 // if ctor does exist, want to use ctor stmt instead of init 194 objDecl->set_ctor( ctor ); 195 destructorStmts.push_front( dtor ); 192 // if ctor does exist, want to use ctor expression instead of init 193 // push this decision to the resolver 194 objDecl->set_init( new ConstructorInit( ctor, objDecl->get_init() ) ); 195 destructorStmts.push_front( new ExprStmt( noLabels, dtor ) ); 196 196 } 197 197 return objDecl; -
src/InitTweak/module.mk
r02c7d04 r71f4e4f 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 12 ## Last Modified By : Rob Schluntz 13 ## Last Modified On : Mon Jan 11 14:40:16201614 ## Update Count : 213 ## Last Modified On : Wed Jan 13 16:29:03 2016 14 ## Update Count : 3 15 15 ############################################################################### 16 16 17 SRC += InitTweak/RemoveInit.cc 18 17 SRC += InitTweak/RemoveInit.cc \ 18 InitTweak/FixInit.cc -
src/Makefile.in
r02c7d04 r71f4e4f 124 124 GenPoly/cfa_cpp-DeclMutator.$(OBJEXT) \ 125 125 InitTweak/cfa_cpp-RemoveInit.$(OBJEXT) \ 126 InitTweak/cfa_cpp-FixInit.$(OBJEXT) \ 126 127 Parser/cfa_cpp-parser.$(OBJEXT) Parser/cfa_cpp-lex.$(OBJEXT) \ 127 128 Parser/cfa_cpp-TypedefTable.$(OBJEXT) \ … … 346 347 GenPoly/CopyParams.cc GenPoly/FindFunction.cc \ 347 348 GenPoly/InstantiateGeneric.cc GenPoly/DeclMutator.cc \ 348 InitTweak/RemoveInit.cc Parser/parser.yy Parser/lex.ll\349 Parser/ TypedefTable.cc Parser/ParseNode.cc \349 InitTweak/RemoveInit.cc InitTweak/FixInit.cc Parser/parser.yy \ 350 Parser/lex.ll Parser/TypedefTable.cc Parser/ParseNode.cc \ 350 351 Parser/DeclarationNode.cc Parser/ExpressionNode.cc \ 351 352 Parser/StatementNode.cc Parser/InitializerNode.cc \ … … 562 563 @: > InitTweak/$(DEPDIR)/$(am__dirstamp) 563 564 InitTweak/cfa_cpp-RemoveInit.$(OBJEXT): InitTweak/$(am__dirstamp) \ 565 InitTweak/$(DEPDIR)/$(am__dirstamp) 566 InitTweak/cfa_cpp-FixInit.$(OBJEXT): InitTweak/$(am__dirstamp) \ 564 567 InitTweak/$(DEPDIR)/$(am__dirstamp) 565 568 Parser/parser.h: Parser/parser.cc … … 783 786 -rm -f GenPoly/cfa_cpp-ScrubTyVars.$(OBJEXT) 784 787 -rm -f GenPoly/cfa_cpp-Specialize.$(OBJEXT) 788 -rm -f InitTweak/cfa_cpp-FixInit.$(OBJEXT) 785 789 -rm -f InitTweak/cfa_cpp-RemoveInit.$(OBJEXT) 786 790 -rm -f Parser/cfa_cpp-DeclarationNode.$(OBJEXT) … … 890 894 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-ScrubTyVars.Po@am__quote@ 891 895 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-Specialize.Po@am__quote@ 896 @AMDEP_TRUE@@am__include@ @am__quote@InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Po@am__quote@ 892 897 @AMDEP_TRUE@@am__include@ @am__quote@InitTweak/$(DEPDIR)/cfa_cpp-RemoveInit.Po@am__quote@ 893 898 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/cfa_cpp-DeclarationNode.Po@am__quote@ … … 1388 1393 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o InitTweak/cfa_cpp-RemoveInit.obj `if test -f 'InitTweak/RemoveInit.cc'; then $(CYGPATH_W) 'InitTweak/RemoveInit.cc'; else $(CYGPATH_W) '$(srcdir)/InitTweak/RemoveInit.cc'; fi` 1389 1394 1395 InitTweak/cfa_cpp-FixInit.o: InitTweak/FixInit.cc 1396 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/cfa_cpp-FixInit.o -MD -MP -MF InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Tpo -c -o InitTweak/cfa_cpp-FixInit.o `test -f 'InitTweak/FixInit.cc' || echo '$(srcdir)/'`InitTweak/FixInit.cc 1397 @am__fastdepCXX_TRUE@ $(am__mv) InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Tpo InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Po 1398 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='InitTweak/FixInit.cc' object='InitTweak/cfa_cpp-FixInit.o' libtool=no @AMDEPBACKSLASH@ 1399 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1400 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o InitTweak/cfa_cpp-FixInit.o `test -f 'InitTweak/FixInit.cc' || echo '$(srcdir)/'`InitTweak/FixInit.cc 1401 1402 InitTweak/cfa_cpp-FixInit.obj: InitTweak/FixInit.cc 1403 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/cfa_cpp-FixInit.obj -MD -MP -MF InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Tpo -c -o InitTweak/cfa_cpp-FixInit.obj `if test -f 'InitTweak/FixInit.cc'; then $(CYGPATH_W) 'InitTweak/FixInit.cc'; else $(CYGPATH_W) '$(srcdir)/InitTweak/FixInit.cc'; fi` 1404 @am__fastdepCXX_TRUE@ $(am__mv) InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Tpo InitTweak/$(DEPDIR)/cfa_cpp-FixInit.Po 1405 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='InitTweak/FixInit.cc' object='InitTweak/cfa_cpp-FixInit.obj' libtool=no @AMDEPBACKSLASH@ 1406 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1407 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o InitTweak/cfa_cpp-FixInit.obj `if test -f 'InitTweak/FixInit.cc'; then $(CYGPATH_W) 'InitTweak/FixInit.cc'; else $(CYGPATH_W) '$(srcdir)/InitTweak/FixInit.cc'; fi` 1408 1390 1409 Parser/cfa_cpp-parser.o: Parser/parser.cc 1391 1410 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Parser/cfa_cpp-parser.o -MD -MP -MF Parser/$(DEPDIR)/cfa_cpp-parser.Tpo -c -o Parser/cfa_cpp-parser.o `test -f 'Parser/parser.cc' || echo '$(srcdir)/'`Parser/parser.cc -
src/ResolvExpr/Resolver.cc
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Fri Jul 24 17:33:54 201513 // Update Count : 1 7811 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 16:23:51 2016 13 // Update Count : 186 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 ); 56 57 private: 57 58 typedef std::list< Initializer * >::iterator InitIterator; … … 95 96 return newExpr; 96 97 } 97 98 98 99 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 99 100 TypeEnvironment env; … … 126 127 } // if 127 128 } 128 129 129 130 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 130 131 TypeEnvironment env; … … 159 160 return newExpr; 160 161 } 161 162 } 163 162 163 } 164 164 165 void Resolver::visit( ObjectDecl *objectDecl ) { 165 166 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); … … 251 252 forStmt->set_condition( newExpr ); 252 253 } // if 253 254 254 255 if ( forStmt->get_increment() ) { 255 256 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 265 266 delete switchStmt->get_condition(); 266 267 switchStmt->set_condition( newExpr ); 267 268 268 269 visitor.Visitor::visit( switchStmt ); 269 270 } … … 307 308 bool isCharType( T t ) { 308 309 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 309 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 310 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 310 311 bt->get_kind() == BasicType::UnsignedChar; 311 312 } … … 319 320 string n = ne->get_name(); 320 321 if (n == "0") { 321 initContext = new BasicType(Type::Qualifiers(), 322 initContext = new BasicType(Type::Qualifiers(), 322 323 BasicType::SignedInt); 323 324 } else { … … 325 326 initContext = decl->get_type(); 326 327 } 327 } else if (ConstantExpr * e = 328 } else if (ConstantExpr * e = 328 329 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 329 330 Constant *c = e->get_constant(); … … 349 350 singleInit->set_value( ce->get_arg() ); 350 351 ce->set_arg( NULL ); 351 delete ce; 352 delete ce; 352 353 } 353 354 } … … 465 466 #endif 466 467 } 468 469 void Resolver::visit( ConstructorInit *ctorInit ) { 470 TypeEnvironment env; 471 AlternativeFinder finder( *this, env ); 472 finder.find( ctorInit->get_ctor() ); 473 if ( finder.get_alternatives().size() == 0 ) { 474 // could not find valid constructor 475 delete ctorInit->get_ctor(); 476 ctorInit->set_ctor( NULL ); 477 478 maybeAccept( ctorInit->get_init(), *this ); 479 } else if ( finder.get_alternatives().size() == 1 ) { 480 // found a constructor - can get rid of C-style initializer 481 Alternative &choice = finder.get_alternatives().front(); 482 Expression *newExpr = choice.expr->clone(); 483 finishExpr( newExpr, choice.env ); 484 ctorInit->set_ctor( newExpr ); 485 delete ctorInit->get_init(); 486 ctorInit->set_init( NULL ); 487 } else { 488 // too many constructors found 489 assert(false); 490 } 491 } 467 492 } // namespace ResolvExpr 468 493 -
src/SynTree/Declaration.h
r02c7d04 r71f4e4f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 14:48:44201613 // Update Count : 3 412 // Last Modified On : Wed Jan 13 16:11:49 2016 13 // Update Count : 36 14 14 // 15 15 … … 91 91 Expression *get_bitfieldWidth() const { return bitfieldWidth; } 92 92 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; } 93 ExprStmt * get_ctor() const { return ctor; }94 void set_ctor( ExprStmt * newValue ) { ctor = newValue; }95 93 96 94 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } … … 103 101 Initializer *init; 104 102 Expression *bitfieldWidth; 105 ExprStmt * ctor;106 103 }; 107 104 -
src/SynTree/Initializer.cc
r02c7d04 r71f4e4f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 15:00:18201613 // Update Count : 2 312 // Last Modified On : Wed Jan 13 15:31:45 2016 13 // Update Count : 28 14 14 // 15 15 … … 79 79 (*i)->print( os, indent + 2 ); 80 80 } 81 82 83 ConstructorInit::ConstructorInit( Expression * ctor, Initializer * init ) : Initializer( true ), ctor( ctor ), init( init ) {} 84 ConstructorInit::~ConstructorInit() { 85 delete ctor; 86 delete init; 87 } 88 89 ConstructorInit *ConstructorInit::clone() const { 90 return new ConstructorInit( *this ); 91 } 92 93 void ConstructorInit::print( std::ostream &os, int indent ) { 94 os << std::endl << std::string(indent, ' ') << "Constructor initializer: "; 95 if ( ctor ) { 96 os << " initially constructed with "; 97 ctor->print( os, indent+2 ); 98 } // if 99 100 if ( init ) { 101 os << " with fallback C-style initializer: "; 102 init->print( os, indent+2 ); 103 } 104 } 105 106 81 107 // Local Variables: // 82 108 // tab-width: 4 // -
src/SynTree/Initializer.h
r02c7d04 r71f4e4f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:33:20201613 // Update Count : 512 // Last Modified On : Wed Jan 13 15:29:53 2016 13 // Update Count : 17 14 14 // 15 15 … … 103 103 }; 104 104 105 // ConstructorInit represents an initializer that is either a constructor expression or 106 // a C-style initializer. 107 class ConstructorInit : public Initializer { 108 public: 109 ConstructorInit( Expression * ctor, Initializer * init ); 110 virtual ~ConstructorInit(); 111 112 void set_ctor( Expression * newValue ) { ctor = newValue; } 113 Expression * get_ctor() const { return ctor; } 114 void set_init( Initializer * newValue ) { init = newValue; } 115 Initializer * get_init() const { return init; } 116 117 virtual ConstructorInit *clone() const; 118 virtual void accept( Visitor &v ) { v.visit( this ); } 119 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 120 virtual void print( std::ostream &os, int indent = 0 ); 121 122 private: 123 Expression * ctor; 124 // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback 125 // if an appropriate constructor definition is not found by the resolver 126 Initializer * init; 127 }; 128 105 129 #endif // INITIALIZER_H 106 130 -
src/SynTree/Mutator.cc
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Sat Jul 25 19:21:33 201513 // Update Count : 1 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 15:32:29 2016 13 // Update Count : 15 14 14 // 15 15 … … 419 419 } 420 420 421 Initializer *Mutator::mutate( ConstructorInit *ctorInit ) { 422 ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) ); 423 ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) ); 424 return ctorInit; 425 } 426 421 427 Subrange *Mutator::mutate( Subrange *subrange ) { 422 428 return subrange; -
src/SynTree/Mutator.h
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Thu Nov 19 22:26:16 201513 // Update Count : 811 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 15:24:26 2016 13 // Update Count : 9 14 14 // 15 15 #include <cassert> … … 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 ); … … 91 91 virtual Initializer* mutate( SingleInit *singleInit ); 92 92 virtual Initializer* mutate( ListInit *listInit ); 93 virtual Initializer* mutate( ConstructorInit *ctorInit ); 93 94 94 95 virtual Subrange *mutate( Subrange *subrange ); -
src/SynTree/ObjectDecl.cc
r02c7d04 r71f4e4f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Jan 08 15:29:10201613 // Update Count : 2 712 // Last Modified On : Wed Jan 13 16:11:19 2016 13 // Update Count : 29 14 14 // 15 15 … … 25 25 set_isInline( isInline ); 26 26 set_isNoreturn( isNoreturn ); 27 set_ctor( NULL );28 27 } 29 28 30 29 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 31 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) , ctor( maybeClone( other.ctor ) ){30 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { 32 31 } 33 32 … … 36 35 delete init; 37 36 delete bitfieldWidth; 38 delete ctor;39 37 } 40 38 … … 67 65 os << " with bitfield width "; 68 66 bitfieldWidth->print( os ); 69 } // if70 71 if ( ctor ) {72 os << " initially constructed with ";73 ctor->print( os, indent );74 67 } // if 75 68 } -
src/SynTree/SynTree.h
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Thu Jul 23 23:25:04 201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 15:28:41 2016 13 // Update Count : 4 14 14 // 15 15 … … 99 99 class SingleInit; 100 100 class ListInit; 101 class ConstructorInit; 101 102 102 103 class Subrange; -
src/SynTree/Visitor.cc
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Fri Jul 24 16:11:05 201513 // Update Count : 1 511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 15:27:23 2016 13 // Update Count : 18 14 14 // 15 15 … … 353 353 } 354 354 355 void Visitor::visit( ConstructorInit *ctorInit ) { 356 maybeAccept( ctorInit->get_ctor(), *this ); 357 maybeAccept( ctorInit->get_init(), *this ); 358 } 359 355 360 void Visitor::visit( Subrange *subrange ) {} 356 361 -
src/SynTree/Visitor.h
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Thu Jul 23 23:22:23 201513 // Update Count : 411 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 15:24:05 2016 13 // Update Count : 5 14 14 // 15 15 … … 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 ); … … 91 91 virtual void visit( SingleInit *singleInit ); 92 92 virtual void visit( ListInit *listInit ); 93 virtual void visit( ConstructorInit *ctorInit ); 93 94 94 95 virtual void visit( Subrange *subrange ); -
src/main.cc
r02c7d04 r71f4e4f 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 : Peter A. Buhr12 // Last Modified On : Thu Dec 17 12:59:06 201513 // Update Count : 1 7911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 16:47:25 2016 13 // Update Count : 181 14 14 // 15 15 … … 42 42 #include "InitTweak/Mutate.h" 43 43 #include "InitTweak/RemoveInit.h" 44 #include "InitTweak/FixInit.h" 44 45 //#include "Explain/GenProlog.h" 45 46 //#include "Try/Visit.h" … … 99 100 100 101 opterr = 0; // prevent getopt from printing error messages 101 102 102 103 int c; 103 104 while ( (c = getopt_long( argc, argv, "abefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) { … … 182 183 output = new ofstream( argv[ optind ] ); 183 184 } // if 184 185 185 186 Parser::get_parser().set_debug( grammarp ); 186 187 … … 203 204 exit( 1 ); 204 205 } // if 205 206 206 207 parse( prelude, LinkageSpec::Intrinsic ); 207 208 } // if 208 209 } // if 209 210 210 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 211 211 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 212 212 213 if ( parsep ) { 213 214 Parser::get_parser().get_parseTree()->printList( std::cout ); … … 244 245 OPTPRINT( "mutate" ) 245 246 ControlStruct::mutate( translationUnit ); 246 OPTPRINT( "fixNames" ) 247 OPTPRINT( "fixNames" ) 247 248 CodeGen::fixNames( translationUnit ); 248 249 OPTPRINT( "tweak" ) … … 264 265 dump( translationUnit ); 265 266 } 267 268 // fix ObjectDecl - replaces ConstructorInit nodes 269 InitTweak::fix( translationUnit ); 266 270 267 271 OPTPRINT( "instantiateGeneric" ) … … 331 335 std::list< Declaration * > decls; 332 336 if ( noprotop ) { 333 filter( translationUnit.begin(), translationUnit.end(), 337 filter( translationUnit.begin(), translationUnit.end(), 334 338 std::back_inserter( decls ), notPrelude ); 335 339 } else {
Note: See TracChangeset
for help on using the changeset viewer.