Changes in src/SymTab/Validate.cc [7c919559:4559b34]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r7c919559 r4559b34 194 194 }; 195 195 196 // These structs are the sub-sub-passes of ForallPointerDecay_old.197 198 struct TraitExpander_old final {199 void previsit( FunctionType * );200 void previsit( StructDecl * );201 void previsit( UnionDecl * );202 };203 204 struct AssertionFixer_old final {205 void previsit( FunctionType * );206 void previsit( StructDecl * );207 void previsit( UnionDecl * );208 };209 210 struct CheckOperatorTypes_old final {211 void previsit( ObjectDecl * );212 };213 214 struct FixUniqueIds_old final {215 void previsit( DeclarationWithType * );216 };217 218 196 struct ReturnChecker : public WithGuards { 219 197 /// Checks that return statements return nothing if their return type is void … … 395 373 TranslateDimensionGenericParameters::translateDimensions( translationUnit ); 396 374 }); 397 if (!useNewAST) {398 375 Stats::Time::TimeBlock("Resolve Enum Initializers", [&]() { 399 376 acceptAll( translationUnit, rei ); // must happen after translateDimensions because rei needs identifier lookup, which needs name mangling 400 377 }); 401 }402 378 Stats::Time::TimeBlock("Check Function Returns", [&]() { 403 379 ReturnChecker::checkFunctionReturns( translationUnit ); … … 409 385 } 410 386 411 static void decayForallPointers( std::list< Declaration * > & translationUnit ) {412 PassVisitor<TraitExpander_old> te;413 acceptAll( translationUnit, te );414 PassVisitor<AssertionFixer_old> af;415 acceptAll( translationUnit, af );416 PassVisitor<CheckOperatorTypes_old> cot;417 acceptAll( translationUnit, cot );418 PassVisitor<FixUniqueIds_old> fui;419 acceptAll( translationUnit, fui );420 }421 422 387 void validate_D( std::list< Declaration * > & translationUnit ) { 388 PassVisitor<ForallPointerDecay_old> fpd; 423 389 { 424 390 Stats::Heap::newPass("validate-D"); … … 428 394 }); 429 395 Stats::Time::TimeBlock("Forall Pointer Decay", [&]() { 430 decayForallPointers( translationUnit); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution396 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution 431 397 }); 432 398 Stats::Time::TimeBlock("Hoist Control Declarations", [&]() { … … 487 453 } 488 454 455 void decayForallPointers( std::list< Declaration * > & translationUnit ) { 456 PassVisitor<ForallPointerDecay_old> fpd; 457 acceptAll( translationUnit, fpd ); 458 } 459 489 460 void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) { 490 461 validate_A( translationUnit ); … … 499 470 PassVisitor<EnumAndPointerDecay_old> epc; 500 471 PassVisitor<LinkReferenceToTypes_old> lrt( indexer ); 501 PassVisitor<TraitExpander_old> te; 502 PassVisitor<AssertionFixer_old> af; 503 PassVisitor<CheckOperatorTypes_old> cot; 504 PassVisitor<FixUniqueIds_old> fui; 472 PassVisitor<ForallPointerDecay_old> fpd; 505 473 type->accept( epc ); 506 474 type->accept( lrt ); 507 type->accept( te ); 508 type->accept( af ); 509 type->accept( cot ); 510 type->accept( fui ); 475 type->accept( fpd ); 511 476 } 512 477 … … 974 939 // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information. 975 940 SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init ); 976 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 941 if ( !enumDecl->base || dynamic_cast<BasicType *>(enumDecl->base)) 942 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 943 else { 944 if (dynamic_cast<PointerType *>(enumDecl->base)) { 945 auto typePtr = dynamic_cast<PointerType *>(enumDecl->base); 946 ResolvExpr::findSingleExpression( init->value, 947 new PointerType( Type::Qualifiers(), typePtr->base ), indexer ); 948 } else { 949 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 950 } 951 } 952 977 953 } 978 954 } 955 979 956 } // if 980 957 } … … 1007 984 } 1008 985 1009 /// Replace all traits in assertion lists with their assertions.1010 void expandTraits( std::list< TypeDecl * > & forall ) {1011 for ( TypeDecl * type : forall ) {1012 std::list< DeclarationWithType * > asserts;1013 asserts.splice( asserts.end(), type->assertions );1014 // expand trait instances into their members1015 for ( DeclarationWithType * assertion : asserts ) {1016 if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {1017 // expand trait instance into all of its members1018 expandAssertions( traitInst, back_inserter( type->assertions ) );1019 delete traitInst;1020 } else {1021 // pass other assertions through1022 type->assertions.push_back( assertion );1023 } // if1024 } // for1025 }1026 }1027 1028 /// Fix each function in the assertion list and check for invalid void type.1029 void fixAssertions(1030 std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) {1031 for ( TypeDecl * type : forall ) {1032 for ( DeclarationWithType *& assertion : type->assertions ) {1033 bool isVoid = fixFunction( assertion );1034 if ( isVoid ) {1035 SemanticError( node, "invalid type void in assertion of function " );1036 } // if1037 } // for1038 }1039 }1040 1041 986 void ForallPointerDecay_old::previsit( ObjectDecl * object ) { 1042 987 // ensure that operator names only apply to functions or function pointers … … 1061 1006 void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) { 1062 1007 forallFixer( aggrDecl->parameters, aggrDecl ); 1063 }1064 1065 void TraitExpander_old::previsit( FunctionType * ftype ) {1066 expandTraits( ftype->forall );1067 }1068 1069 void TraitExpander_old::previsit( StructDecl * aggrDecl ) {1070 expandTraits( aggrDecl->parameters );1071 }1072 1073 void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {1074 expandTraits( aggrDecl->parameters );1075 }1076 1077 void AssertionFixer_old::previsit( FunctionType * ftype ) {1078 fixAssertions( ftype->forall, ftype );1079 }1080 1081 void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {1082 fixAssertions( aggrDecl->parameters, aggrDecl );1083 }1084 1085 void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {1086 fixAssertions( aggrDecl->parameters, aggrDecl );1087 }1088 1089 void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {1090 // ensure that operator names only apply to functions or function pointers1091 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {1092 SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." ) );1093 }1094 }1095 1096 void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {1097 decl->fixUniqueId();1098 1008 } 1099 1009 … … 1240 1150 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); 1241 1151 } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) { 1242 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) ); 1152 // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) ); 1153 if (enumDecl->baseEnum) { 1154 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) ); 1155 } else { 1156 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) ); 1157 } 1243 1158 } // if 1244 1159 return tyDecl->clone();
Note:
See TracChangeset
for help on using the changeset viewer.