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