Changeset 24d6572 for src/Validate/Autogen.cpp
- Timestamp:
- Jun 12, 2023, 2:45:32 PM (13 months ago)
- Branches:
- ast-experimental, master
- Children:
- 62d62db
- Parents:
- 34b4268 (diff), 251ce80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
r34b4268 r24d6572 25 25 26 26 #include "AST/Attribute.hpp" 27 #include "AST/Copy.hpp" 27 28 #include "AST/Create.hpp" 28 29 #include "AST/Decl.hpp" … … 39 40 #include "InitTweak/GenInit.h" // for fixReturnStatements 40 41 #include "InitTweak/InitTweak.h" // for isAssignment, isCopyConstructor 42 #include "SymTab/GenImplicitCall.hpp" // for genImplicitCall 41 43 #include "SymTab/Mangler.h" // for Mangler 42 44 #include "CompilationState.h" 43 44 // TODO: The other new ast function should be moved over to this file.45 #include "SymTab/Autogen.h"46 45 47 46 namespace Validate { … … 94 93 95 94 const CodeLocation& getLocation() const { return getDecl()->location; } 96 ast::FunctionDecl * genProto( const std::string& name,95 ast::FunctionDecl * genProto( std::string&& name, 97 96 std::vector<ast::ptr<ast::DeclWithType>>&& params, 98 97 std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const; … … 322 321 void FuncGenerator::produceDecl( const ast::FunctionDecl * decl ) { 323 322 assert( nullptr != decl->stmts ); 323 const auto & oldParams = getGenericParams(type); 324 assert( decl->type_params.size() == oldParams.size()); 325 326 /* 327 ast::DeclReplacer::TypeMap typeMap; 328 for (auto it = oldParams.begin(), jt = decl->type_params.begin(); it != oldParams.end(); ++it, ++jt) { 329 typeMap.emplace(*it, *jt); 330 } 331 332 const ast::FunctionDecl * mut = strict_dynamic_cast<const ast::FunctionDecl *>(ast::DeclReplacer::replace(decl, typeMap)); 333 assert (mut == decl); 334 */ 324 335 325 336 definitions.push_back( decl ); … … 335 346 } 336 347 348 void replaceAll( std::vector<ast::ptr<ast::DeclWithType>> & dwts, 349 const ast::DeclReplacer::TypeMap & map ) { 350 for ( auto & dwt : dwts ) { 351 dwt = strict_dynamic_cast<const ast::DeclWithType *>( 352 ast::DeclReplacer::replace( dwt, map ) ); 353 } 354 } 355 337 356 /// Generates a basic prototype function declaration. 338 ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,357 ast::FunctionDecl * FuncGenerator::genProto( std::string&& name, 339 358 std::vector<ast::ptr<ast::DeclWithType>>&& params, 340 359 std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const { … … 342 361 // Handle generic prameters and assertions, if any. 343 362 auto const & old_type_params = getGenericParams( type ); 363 ast::DeclReplacer::TypeMap oldToNew; 344 364 std::vector<ast::ptr<ast::TypeDecl>> type_params; 345 365 std::vector<ast::ptr<ast::DeclWithType>> assertions; 366 367 ast::DeclReplacer::TypeMap typeMap; 346 368 for ( auto & old_param : old_type_params ) { 347 369 ast::TypeDecl * decl = ast::deepCopy( old_param ); 348 for ( auto assertion : decl->assertions ) { 349 assertions.push_back( assertion ); 350 } 351 decl->assertions.clear(); 370 decl->init = nullptr; 371 splice( assertions, decl->assertions ); 372 oldToNew.emplace( std::make_pair( old_param, decl ) ); 352 373 type_params.push_back( decl ); 353 } 354 // TODO: The values in params and returns still may point at the old 355 // generic params, that does not appear to be an issue but perhaps it 356 // should be addressed. 374 typeMap.emplace(old_param, decl); 375 } 376 377 for (auto & param : params) { 378 param = ast::DeclReplacer::replace(param, typeMap); 379 } 380 for (auto & param : returns) { 381 param = ast::DeclReplacer::replace(param, typeMap); 382 } 383 replaceAll( params, oldToNew ); 384 replaceAll( returns, oldToNew ); 385 replaceAll( assertions, oldToNew ); 357 386 358 387 ast::FunctionDecl * decl = new ast::FunctionDecl( 359 388 // Auto-generated routines use the type declaration's location. 360 389 getLocation(), 361 name,390 std::move( name ), 362 391 std::move( type_params ), 363 392 std::move( assertions ), … … 423 452 for ( unsigned int index = 0 ; index < fields ; ++index ) { 424 453 auto member = aggr->members[index].strict_as<ast::DeclWithType>(); 425 if ( SymTab::isUnnamedBitfield(454 if ( ast::isUnnamedBitfield( 426 455 dynamic_cast<const ast::ObjectDecl *>( member ) ) ) { 427 456 if ( index == fields - 1 ) { … … 515 544 InitTweak::InitExpander_new srcParam( src ); 516 545 // Assign to destination. 517 ast:: Expr * dstSelect = new ast::MemberExpr(546 ast::MemberExpr * dstSelect = new ast::MemberExpr( 518 547 location, 519 548 field, … … 567 596 } 568 597 569 ast:: Expr * srcSelect = (srcParam) ? new ast::MemberExpr(598 ast::MemberExpr * srcSelect = (srcParam) ? new ast::MemberExpr( 570 599 location, field, new ast::VariableExpr( location, srcParam ) 571 600 ) : nullptr; … … 599 628 // Not sure why it could be null. 600 629 // Don't make a function for a parameter that is an unnamed bitfield. 601 if ( nullptr == field || SymTab::isUnnamedBitfield( field ) ) {630 if ( nullptr == field || ast::isUnnamedBitfield( field ) ) { 602 631 continue; 603 632 // Matching Parameter: Initialize the field by copy.
Note: See TracChangeset
for help on using the changeset viewer.