Changes in src/SymTab/Validate.cc [4559b34:7c919559]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r4559b34 r7c919559 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 196 218 struct ReturnChecker : public WithGuards { 197 219 /// Checks that return statements return nothing if their return type is void … … 373 395 TranslateDimensionGenericParameters::translateDimensions( translationUnit ); 374 396 }); 397 if (!useNewAST) { 375 398 Stats::Time::TimeBlock("Resolve Enum Initializers", [&]() { 376 399 acceptAll( translationUnit, rei ); // must happen after translateDimensions because rei needs identifier lookup, which needs name mangling 377 400 }); 401 } 378 402 Stats::Time::TimeBlock("Check Function Returns", [&]() { 379 403 ReturnChecker::checkFunctionReturns( translationUnit ); … … 385 409 } 386 410 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 387 422 void validate_D( std::list< Declaration * > & translationUnit ) { 388 PassVisitor<ForallPointerDecay_old> fpd;389 423 { 390 424 Stats::Heap::newPass("validate-D"); … … 394 428 }); 395 429 Stats::Time::TimeBlock("Forall Pointer Decay", [&]() { 396 acceptAll( translationUnit, fpd); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution430 decayForallPointers( translationUnit ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution 397 431 }); 398 432 Stats::Time::TimeBlock("Hoist Control Declarations", [&]() { … … 453 487 } 454 488 455 void decayForallPointers( std::list< Declaration * > & translationUnit ) {456 PassVisitor<ForallPointerDecay_old> fpd;457 acceptAll( translationUnit, fpd );458 }459 460 489 void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) { 461 490 validate_A( translationUnit ); … … 470 499 PassVisitor<EnumAndPointerDecay_old> epc; 471 500 PassVisitor<LinkReferenceToTypes_old> lrt( indexer ); 472 PassVisitor<ForallPointerDecay_old> fpd; 501 PassVisitor<TraitExpander_old> te; 502 PassVisitor<AssertionFixer_old> af; 503 PassVisitor<CheckOperatorTypes_old> cot; 504 PassVisitor<FixUniqueIds_old> fui; 473 505 type->accept( epc ); 474 506 type->accept( lrt ); 475 type->accept( fpd ); 507 type->accept( te ); 508 type->accept( af ); 509 type->accept( cot ); 510 type->accept( fui ); 476 511 } 477 512 … … 939 974 // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information. 940 975 SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init ); 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 976 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 953 977 } 954 978 } 955 956 979 } // if 957 980 } … … 984 1007 } 985 1008 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 members 1015 for ( DeclarationWithType * assertion : asserts ) { 1016 if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) { 1017 // expand trait instance into all of its members 1018 expandAssertions( traitInst, back_inserter( type->assertions ) ); 1019 delete traitInst; 1020 } else { 1021 // pass other assertions through 1022 type->assertions.push_back( assertion ); 1023 } // if 1024 } // for 1025 } 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 } // if 1037 } // for 1038 } 1039 } 1040 986 1041 void ForallPointerDecay_old::previsit( ObjectDecl * object ) { 987 1042 // ensure that operator names only apply to functions or function pointers … … 1006 1061 void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) { 1007 1062 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 pointers 1091 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(); 1008 1098 } 1009 1099 … … 1150 1240 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); 1151 1241 } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) { 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 } 1242 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) ); 1158 1243 } // if 1159 1244 return tyDecl->clone();
Note:
See TracChangeset
for help on using the changeset viewer.