Changeset 8913de4 for src/Validate/Autogen.cpp
- Timestamp:
- May 30, 2023, 11:13:58 AM (16 months ago)
- Branches:
- ast-experimental, master
- Children:
- 2cb8bf71, 6f774be, 70a4ed5
- Parents:
- efe89894
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
refe89894 r8913de4 44 44 #include "CompilationState.h" 45 45 46 // TODO: The other new ast function should be moved over to this file.47 #include "SymTab/Autogen.h"48 49 46 namespace Validate { 50 47 … … 96 93 97 94 const CodeLocation& getLocation() const { return getDecl()->location; } 98 ast::FunctionDecl * genProto( const std::string& name,95 ast::FunctionDecl * genProto( std::string&& name, 99 96 std::vector<ast::ptr<ast::DeclWithType>>&& params, 100 97 std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const; … … 337 334 } 338 335 336 void replaceAll( std::vector<ast::ptr<ast::DeclWithType>> & dwts, 337 const ast::DeclReplacer::TypeMap & map ) { 338 for ( auto & dwt : dwts ) { 339 dwt = strict_dynamic_cast<const ast::DeclWithType *>( 340 ast::DeclReplacer::replace( dwt, map ) ); 341 } 342 } 343 339 344 /// Generates a basic prototype function declaration. 340 ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,345 ast::FunctionDecl * FuncGenerator::genProto( std::string&& name, 341 346 std::vector<ast::ptr<ast::DeclWithType>>&& params, 342 347 std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const { … … 344 349 // Handle generic prameters and assertions, if any. 345 350 auto const & old_type_params = getGenericParams( type ); 351 ast::DeclReplacer::TypeMap oldToNew; 346 352 std::vector<ast::ptr<ast::TypeDecl>> type_params; 347 353 std::vector<ast::ptr<ast::DeclWithType>> assertions; 348 354 for ( auto & old_param : old_type_params ) { 349 355 ast::TypeDecl * decl = ast::deepCopy( old_param ); 350 for ( auto assertion : decl->assertions ) { 351 assertions.push_back( assertion ); 352 } 353 decl->assertions.clear(); 356 decl->init = nullptr; 357 splice( assertions, decl->assertions ); 358 oldToNew.emplace( std::make_pair( old_param, decl ) ); 354 359 type_params.push_back( decl ); 355 360 } 356 // TODO: The values in params and returns still may point at the old357 // generic params, that does not appear to be an issue but perhaps it358 // should be addressed.361 replaceAll( params, oldToNew ); 362 replaceAll( returns, oldToNew ); 363 replaceAll( assertions, oldToNew ); 359 364 360 365 ast::FunctionDecl * decl = new ast::FunctionDecl( 361 366 // Auto-generated routines use the type declaration's location. 362 367 getLocation(), 363 name,368 std::move( name ), 364 369 std::move( type_params ), 365 370 std::move( assertions ),
Note: See TracChangeset
for help on using the changeset viewer.