Changes in src/SymTab/Validate.cc [095b99a:09867ec]
- File:
-
- 1 edited
-
src/SymTab/Validate.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Validate.cc
r095b99a r09867ec 64 64 #include "Common/UniqueName.h" // for UniqueName 65 65 #include "Common/utility.h" // for operator+, cloneAll, deleteAll 66 #include "CompilationState.h" // skip some passes in new-ast build 66 67 #include "Concurrency/Keywords.h" // for applyKeywords 67 68 #include "FixFunction.h" // for FixFunction … … 270 271 }; 271 272 272 struct ArrayLength : public WithIndexer{273 struct InitializerLength { 273 274 /// for array types without an explicit length, compute the length and store it so that it 274 275 /// is known to the rest of the phases. For example, … … 281 282 282 283 void previsit( ObjectDecl * objDecl ); 284 }; 285 286 struct ArrayLength : public WithIndexer { 287 static void computeLength( std::list< Declaration * > & translationUnit ); 288 283 289 void previsit( ArrayType * arrayType ); 284 290 }; … … 311 317 Stats::Heap::newPass("validate-A"); 312 318 Stats::Time::BlockGuard guard("validate-A"); 319 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 313 320 acceptAll( translationUnit, hoistDecls ); 314 321 ReplaceTypedef::replaceTypedef( translationUnit ); … … 336 343 Stats::Time::BlockGuard guard("validate-C"); 337 344 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes_old 338 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors339 345 ReturnChecker::checkFunctionReturns( translationUnit ); 340 346 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen … … 368 374 mutateAll( translationUnit, compoundliteral ); 369 375 }); 370 Stats::Time::TimeBlock("Resolve With Expressions", [&]() { 371 ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables 372 }); 376 if (!useNewAST) { 377 Stats::Time::TimeBlock("Resolve With Expressions", [&]() { 378 ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables 379 }); 380 } 373 381 } 374 382 { 375 383 Stats::Heap::newPass("validate-F"); 376 384 Stats::Time::BlockGuard guard("validate-F"); 377 Stats::Time::TimeCall("Fix Object Type", 378 FixObjectType::fix, translationUnit); 379 Stats::Time::TimeCall("Array Length", 380 ArrayLength::computeLength, translationUnit); 385 if (!useNewAST) { 386 Stats::Time::TimeCall("Fix Object Type", 387 FixObjectType::fix, translationUnit); 388 } 389 Stats::Time::TimeCall("Initializer Length", 390 InitializerLength::computeLength, translationUnit); 391 if (!useNewAST) { 392 Stats::Time::TimeCall("Array Length", 393 ArrayLength::computeLength, translationUnit); 394 } 381 395 Stats::Time::TimeCall("Find Special Declarations", 382 396 Validate::findSpecialDecls, translationUnit); 383 397 Stats::Time::TimeCall("Fix Label Address", 384 398 mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer); 385 Stats::Time::TimeCall("Handle Attributes", 386 Validate::handleAttributes, translationUnit); 399 if (!useNewAST) { 400 Stats::Time::TimeCall("Handle Attributes", 401 Validate::handleAttributes, translationUnit); 402 } 387 403 } 388 404 } … … 960 976 } 961 977 978 static bool isNonParameterAttribute( Attribute * attr ) { 979 static const std::vector<std::string> bad_names = { 980 "aligned", "__aligned__", 981 }; 982 for ( auto name : bad_names ) { 983 if ( name == attr->name ) { 984 return true; 985 } 986 } 987 return false; 988 } 989 962 990 Type * ReplaceTypedef::postmutate( TypeInstType * typeInst ) { 963 991 // instances of typedef types will come here. If it is an instance … … 968 996 ret->location = typeInst->location; 969 997 ret->get_qualifiers() |= typeInst->get_qualifiers(); 970 // attributes are not carried over from typedef to function parameters/return values 971 if ( ! inFunctionType ) { 972 ret->attributes.splice( ret->attributes.end(), typeInst->attributes ); 973 } else { 974 deleteAll( ret->attributes ); 975 ret->attributes.clear(); 976 } 998 // GCC ignores certain attributes if they arrive by typedef, this mimics that. 999 if ( inFunctionType ) { 1000 ret->attributes.remove_if( isNonParameterAttribute ); 1001 } 1002 ret->attributes.splice( ret->attributes.end(), typeInst->attributes ); 977 1003 // place instance parameters on the typedef'd type 978 1004 if ( ! typeInst->parameters.empty() ) { … … 1182 1208 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. 1183 1209 if ( params.size() == 0 ) { 1184 SemanticError( funcDecl , "Constructors, destructors, and assignment functions require at least one parameter" );1210 SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." ); 1185 1211 } 1186 1212 ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() ); 1187 1213 if ( ! refType ) { 1188 SemanticError( funcDecl , "First parameter of a constructor, destructor, or assignment function must be a reference" );1214 SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." ); 1189 1215 } 1190 1216 if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) { 1191 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " ); 1217 if(!returnVals.front()->get_type()->isVoid()) { 1218 SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." ); 1219 } 1192 1220 } 1193 1221 } … … 1313 1341 } 1314 1342 1343 void InitializerLength::computeLength( std::list< Declaration * > & translationUnit ) { 1344 PassVisitor<InitializerLength> len; 1345 acceptAll( translationUnit, len ); 1346 } 1347 1315 1348 void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) { 1316 1349 PassVisitor<ArrayLength> len; … … 1318 1351 } 1319 1352 1320 void ArrayLength::previsit( ObjectDecl * objDecl ) {1353 void InitializerLength::previsit( ObjectDecl * objDecl ) { 1321 1354 if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->type ) ) { 1322 1355 if ( at->dimension ) return; … … 1372 1405 /// Replaces enum types by int, and function/array types in function parameter and return 1373 1406 /// lists by appropriate pointers 1407 /* 1374 1408 struct EnumAndPointerDecay_new { 1375 1409 const ast::EnumDecl * previsit( const ast::EnumDecl * enumDecl ) { … … 1422 1456 } 1423 1457 }; 1458 */ 1424 1459 1425 1460 /// expand assertions from a trait instance, performing appropriate type variable substitutions … … 1440 1475 } 1441 1476 1477 /* 1478 1442 1479 /// Associates forward declarations of aggregates with their definitions 1443 1480 class LinkReferenceToTypes_new final … … 1506 1543 } 1507 1544 1508 void checkGenericParameters( const ast:: ReferenceToType * inst ) {1545 void checkGenericParameters( const ast::BaseInstType * inst ) { 1509 1546 for ( const ast::Expr * param : inst->params ) { 1510 1547 if ( ! dynamic_cast< const ast::TypeExpr * >( param ) ) { … … 1770 1807 static const node_t * forallFixer( 1771 1808 const CodeLocation & loc, const node_t * node, 1772 ast:: ParameterizedType::ForallList parent_t::* forallField1809 ast::FunctionType::ForallList parent_t::* forallField 1773 1810 ) { 1774 1811 for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) { … … 1821 1858 } 1822 1859 }; 1860 */ 1823 1861 } // anonymous namespace 1824 1862 1863 /* 1825 1864 const ast::Type * validateType( 1826 1865 const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab ) { 1827 ast::Pass< EnumAndPointerDecay_new > epc;1866 // ast::Pass< EnumAndPointerDecay_new > epc; 1828 1867 ast::Pass< LinkReferenceToTypes_new > lrt{ loc, symtab }; 1829 1868 ast::Pass< ForallPointerDecay_new > fpd{ loc }; 1830 1869 1831 return type->accept( epc )->accept(lrt )->accept( fpd );1870 return type->accept( lrt )->accept( fpd ); 1832 1871 } 1872 */ 1833 1873 1834 1874 } // namespace SymTab
Note:
See TracChangeset
for help on using the changeset viewer.