Changes in src/SymTab/Validate.cc [c1ed2ee:c8e4d2f8]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
rc1ed2ee rc8e4d2f8 46 46 #include <utility> // for pair 47 47 48 #include "AST/Decl.hpp"49 #include "AST/Node.hpp"50 #include "AST/Pass.hpp"51 #include "AST/SymbolTable.hpp"52 #include "AST/Type.hpp"53 48 #include "CodeGen/CodeGenerator.h" // for genName 54 49 #include "CodeGen/OperatorTable.h" // for isCtorDtor, isCtorDtorAssign … … 129 124 130 125 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 131 struct EnumAndPointerDecay _old{126 struct EnumAndPointerDecay { 132 127 void previsit( EnumDecl *aggregateDecl ); 133 128 void previsit( FunctionType *func ); … … 135 130 136 131 /// Associates forward declarations of aggregates with their definitions 137 struct LinkReferenceToTypes _old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {138 LinkReferenceToTypes _old( const Indexer *indexer );132 struct LinkReferenceToTypes final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes>, public WithShortCircuiting { 133 LinkReferenceToTypes( const Indexer *indexer ); 139 134 void postvisit( TypeInstType *typeInst ); 140 135 … … 170 165 171 166 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 172 struct ForallPointerDecay _oldfinal {167 struct ForallPointerDecay final { 173 168 void previsit( ObjectDecl * object ); 174 169 void previsit( FunctionDecl * func ); … … 295 290 296 291 void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) { 297 PassVisitor<EnumAndPointerDecay _old> epc;298 PassVisitor<LinkReferenceToTypes _old> lrt( nullptr );299 PassVisitor<ForallPointerDecay _old> fpd;292 PassVisitor<EnumAndPointerDecay> epc; 293 PassVisitor<LinkReferenceToTypes> lrt( nullptr ); 294 PassVisitor<ForallPointerDecay> fpd; 300 295 PassVisitor<CompoundLiteral> compoundliteral; 301 296 PassVisitor<ValidateGenericParameters> genericParams; … … 310 305 ReplaceTypedef::replaceTypedef( translationUnit ); 311 306 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 312 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes _oldbecause it is an indexer and needs correct types for mangling307 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes because it is an indexer and needs correct types for mangling 313 308 } 314 309 { … … 319 314 }); 320 315 Stats::Time::TimeBlock("Fix Qualified Types", [&]() { 321 mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes _old, because aggregate members are accessed316 mutateAll( translationUnit, fixQual ); // must happen after LinkReferenceToTypes, because aggregate members are accessed 322 317 }); 323 318 Stats::Time::TimeBlock("Hoist Structs", [&]() { … … 331 326 Stats::Heap::newPass("validate-C"); 332 327 Stats::Time::BlockGuard guard("validate-C"); 333 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes _old328 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes 334 329 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 335 330 ReturnChecker::checkFunctionReturns( translationUnit ); … … 349 344 }); 350 345 Stats::Time::TimeBlock("Generate Autogen routines", [&]() { 351 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay _old346 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 352 347 }); 353 348 } … … 390 385 391 386 void validateType( Type *type, const Indexer *indexer ) { 392 PassVisitor<EnumAndPointerDecay _old> epc;393 PassVisitor<LinkReferenceToTypes _old> lrt( indexer );394 PassVisitor<ForallPointerDecay _old> fpd;387 PassVisitor<EnumAndPointerDecay> epc; 388 PassVisitor<LinkReferenceToTypes> lrt( indexer ); 389 PassVisitor<ForallPointerDecay> fpd; 395 390 type->accept( epc ); 396 391 type->accept( lrt ); … … 591 586 } 592 587 593 void EnumAndPointerDecay _old::previsit( EnumDecl *enumDecl ) {588 void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) { 594 589 // Set the type of each member of the enumeration to be EnumConstant 595 590 for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) { … … 623 618 } 624 619 625 void EnumAndPointerDecay _old::previsit( FunctionType *func ) {620 void EnumAndPointerDecay::previsit( FunctionType *func ) { 626 621 // Fix up parameters and return types 627 622 fixFunctionList( func->parameters, func->isVarArgs, func ); … … 629 624 } 630 625 631 LinkReferenceToTypes _old::LinkReferenceToTypes_old( const Indexer *other_indexer ) {626 LinkReferenceToTypes::LinkReferenceToTypes( const Indexer *other_indexer ) { 632 627 if ( other_indexer ) { 633 628 local_indexer = other_indexer; … … 637 632 } 638 633 639 void LinkReferenceToTypes _old::postvisit( EnumInstType *enumInst ) {634 void LinkReferenceToTypes::postvisit( EnumInstType *enumInst ) { 640 635 EnumDecl *st = local_indexer->lookupEnum( enumInst->name ); 641 636 // it's not a semantic error if the enum is not found, just an implicit forward declaration … … 657 652 } 658 653 659 void LinkReferenceToTypes _old::postvisit( StructInstType *structInst ) {654 void LinkReferenceToTypes::postvisit( StructInstType *structInst ) { 660 655 StructDecl *st = local_indexer->lookupStruct( structInst->name ); 661 656 // it's not a semantic error if the struct is not found, just an implicit forward declaration … … 670 665 } 671 666 672 void LinkReferenceToTypes _old::postvisit( UnionInstType *unionInst ) {667 void LinkReferenceToTypes::postvisit( UnionInstType *unionInst ) { 673 668 UnionDecl *un = local_indexer->lookupUnion( unionInst->name ); 674 669 // it's not a semantic error if the union is not found, just an implicit forward declaration … … 683 678 } 684 679 685 void LinkReferenceToTypes _old::previsit( QualifiedType * ) {680 void LinkReferenceToTypes::previsit( QualifiedType * ) { 686 681 visit_children = false; 687 682 } 688 683 689 void LinkReferenceToTypes _old::postvisit( QualifiedType * qualType ) {684 void LinkReferenceToTypes::postvisit( QualifiedType * qualType ) { 690 685 // linking only makes sense for the 'oldest ancestor' of the qualified type 691 686 qualType->parent->accept( *visitor ); … … 734 729 } 735 730 736 void LinkReferenceToTypes _old::postvisit( TraitDecl * traitDecl ) {731 void LinkReferenceToTypes::postvisit( TraitDecl * traitDecl ) { 737 732 if ( traitDecl->name == "sized" ) { 738 733 // "sized" is a special trait - flick the sized status on for the type variable … … 756 751 } 757 752 758 void LinkReferenceToTypes _old::postvisit( TraitInstType * traitInst ) {753 void LinkReferenceToTypes::postvisit( TraitInstType * traitInst ) { 759 754 // handle other traits 760 755 TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name ); … … 782 777 } 783 778 784 void LinkReferenceToTypes _old::postvisit( EnumDecl *enumDecl ) {779 void LinkReferenceToTypes::postvisit( EnumDecl *enumDecl ) { 785 780 // visit enum members first so that the types of self-referencing members are updated properly 786 781 if ( enumDecl->body ) { … … 804 799 } 805 800 806 void LinkReferenceToTypes _old::renameGenericParams( std::list< TypeDecl * > & params ) {801 void LinkReferenceToTypes::renameGenericParams( std::list< TypeDecl * > & params ) { 807 802 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g. 808 803 // forall(otype T) … … 822 817 } 823 818 824 void LinkReferenceToTypes _old::previsit( StructDecl * structDecl ) {819 void LinkReferenceToTypes::previsit( StructDecl * structDecl ) { 825 820 renameGenericParams( structDecl->parameters ); 826 821 } 827 822 828 void LinkReferenceToTypes _old::previsit( UnionDecl * unionDecl ) {823 void LinkReferenceToTypes::previsit( UnionDecl * unionDecl ) { 829 824 renameGenericParams( unionDecl->parameters ); 830 825 } 831 826 832 void LinkReferenceToTypes _old::postvisit( StructDecl *structDecl ) {827 void LinkReferenceToTypes::postvisit( StructDecl *structDecl ) { 833 828 // visit struct members first so that the types of self-referencing members are updated properly 834 829 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults) … … 844 839 } 845 840 846 void LinkReferenceToTypes _old::postvisit( UnionDecl *unionDecl ) {841 void LinkReferenceToTypes::postvisit( UnionDecl *unionDecl ) { 847 842 if ( unionDecl->body ) { 848 843 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name ); … … 856 851 } 857 852 858 void LinkReferenceToTypes _old::postvisit( TypeInstType *typeInst ) {853 void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) { 859 854 // ensure generic parameter instances are renamed like the base type 860 855 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name; … … 893 888 } 894 889 895 void ForallPointerDecay _old::previsit( ObjectDecl *object ) {890 void ForallPointerDecay::previsit( ObjectDecl *object ) { 896 891 // ensure that operator names only apply to functions or function pointers 897 892 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) { … … 901 896 } 902 897 903 void ForallPointerDecay _old::previsit( FunctionDecl *func ) {898 void ForallPointerDecay::previsit( FunctionDecl *func ) { 904 899 func->fixUniqueId(); 905 900 } 906 901 907 void ForallPointerDecay _old::previsit( FunctionType * ftype ) {902 void ForallPointerDecay::previsit( FunctionType * ftype ) { 908 903 forallFixer( ftype->forall, ftype ); 909 904 } 910 905 911 void ForallPointerDecay _old::previsit( StructDecl * aggrDecl ) {906 void ForallPointerDecay::previsit( StructDecl * aggrDecl ) { 912 907 forallFixer( aggrDecl->parameters, aggrDecl ); 913 908 } 914 909 915 void ForallPointerDecay _old::previsit( UnionDecl * aggrDecl ) {910 void ForallPointerDecay::previsit( UnionDecl * aggrDecl ) { 916 911 forallFixer( aggrDecl->parameters, aggrDecl ); 917 912 } … … 1373 1368 } 1374 1369 1375 namespace { 1376 /// Replaces enum types by int, and function/array types in function parameter and return 1377 /// lists by appropriate pointers 1378 struct EnumAndPointerDecay_new { 1379 const ast::EnumDecl * previsit( const ast::EnumDecl * enumDecl ) { 1380 // set the type of each member of the enumeration to be EnumConstant 1381 for ( unsigned i = 0; i < enumDecl->members.size(); ++i ) { 1382 // build new version of object with EnumConstant 1383 ast::ptr< ast::ObjectDecl > obj = 1384 enumDecl->members[i].strict_as< ast::ObjectDecl >(); 1385 obj.get_and_mutate()->type = 1386 new ast::EnumInstType{ enumDecl->name, ast::CV::Const }; 1387 1388 // set into decl 1389 ast::EnumDecl * mut = mutate( enumDecl ); 1390 mut->members[i] = obj.get(); 1391 enumDecl = mut; 1392 } 1393 return enumDecl; 1394 } 1395 1396 static const ast::FunctionType * fixFunctionList( 1397 const ast::FunctionType * func, 1398 std::vector< ast::ptr< ast::DeclWithType > > ast::FunctionType::* field, 1399 ast::ArgumentFlag isVarArgs = ast::FixedArgs 1400 ) { 1401 const auto & dwts = func->*field; 1402 unsigned nvals = dwts.size(); 1403 bool hasVoid = false; 1404 for ( unsigned i = 0; i < nvals; ++i ) { 1405 func = ast::mutate_field_index( func, field, i, fixFunction( dwts[i], hasVoid ) ); 1406 } 1407 1408 // the only case in which "void" is valid is where it is the only one in the list 1409 if ( hasVoid && ( nvals > 1 || isVarArgs ) ) { 1410 SemanticError( 1411 dwts.front()->location, func, "invalid type void in function type" ); 1412 } 1413 1414 // one void is the only thing in the list, remove it 1415 if ( hasVoid ) { 1416 func = ast::mutate_field( 1417 func, field, std::vector< ast::ptr< ast::DeclWithType > >{} ); 1418 } 1419 1420 return func; 1421 } 1422 1423 const ast::FunctionType * previsit( const ast::FunctionType * func ) { 1424 func = fixFunctionList( func, &ast::FunctionType::params, func->isVarArgs ); 1425 return fixFunctionList( func, &ast::FunctionType::returns ); 1426 } 1427 }; 1428 1429 /// Associates forward declarations of aggregates with their definitions 1430 struct LinkReferenceToTypes_new final 1431 : public ast::WithSymbolTable, public ast::WithGuards, public 1432 ast::WithVisitorRef<LinkReferenceToTypes_new>, public ast::WithShortCircuiting { 1433 1434 const ast::SymbolTable * localSyms; 1435 1436 LinkReferenceToTypes_new( const ast::SymbolTable & syms ) : localSyms( &syms ) {} 1437 1438 #warning incomplete 1439 }; 1440 1441 /// Replaces array and function types in forall lists by appropriate pointer type and assigns 1442 /// each object and function declaration a unique ID 1443 struct ForallPointerDecay_new { 1444 #warning incomplete 1445 }; 1446 } // anonymous namespace 1447 1448 const ast::Type * validateType( const ast::Type * type, const ast::SymbolTable & symtab ) { 1449 ast::Pass< EnumAndPointerDecay_new > epc; 1450 ast::Pass< LinkReferenceToTypes_new > lrt{ symtab }; 1451 ast::Pass< ForallPointerDecay_new > fpd; 1452 1453 return type->accept( epc )->accept( lrt )->accept( fpd ); 1454 } 1455 1370 const ast::Type * validateType( const ast::Type * type, const ast::SymbolTable & symtab ) { 1371 #warning unimplemented 1372 (void)type; (void)symtab; 1373 assert(false); 1374 return nullptr; 1375 } 1456 1376 } // namespace SymTab 1457 1377
Note:
See TracChangeset
for help on using the changeset viewer.