Changeset 8a930c03 for src/Validate/Autogen.cpp
- Timestamp:
- Jun 12, 2023, 12:05:58 PM (2 years ago)
- Branches:
- master
- Children:
- fec8bd1
- Parents:
- 2b78949 (diff), 38e266ca (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
r2b78949 r8a930c03 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" … … 43 44 #include "CompilationState.h" 44 45 45 // TODO: The other new ast function should be moved over to this file.46 #include "SymTab/Autogen.h"47 48 46 namespace Validate { 49 47 … … 95 93 96 94 const CodeLocation& getLocation() const { return getDecl()->location; } 97 ast::FunctionDecl * genProto( const std::string& name,95 ast::FunctionDecl * genProto( std::string&& name, 98 96 std::vector<ast::ptr<ast::DeclWithType>>&& params, 99 97 std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const; … … 336 334 } 337 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 338 344 /// Generates a basic prototype function declaration. 339 ast::FunctionDecl * FuncGenerator::genProto( const std::string& name,345 ast::FunctionDecl * FuncGenerator::genProto( std::string&& name, 340 346 std::vector<ast::ptr<ast::DeclWithType>>&& params, 341 347 std::vector<ast::ptr<ast::DeclWithType>>&& returns ) const { … … 343 349 // Handle generic prameters and assertions, if any. 344 350 auto const & old_type_params = getGenericParams( type ); 351 ast::DeclReplacer::TypeMap oldToNew; 345 352 std::vector<ast::ptr<ast::TypeDecl>> type_params; 346 353 std::vector<ast::ptr<ast::DeclWithType>> assertions; 347 354 for ( auto & old_param : old_type_params ) { 348 355 ast::TypeDecl * decl = ast::deepCopy( old_param ); 349 for ( auto assertion : decl->assertions ) { 350 assertions.push_back( assertion ); 351 } 352 decl->assertions.clear(); 356 decl->init = nullptr; 357 splice( assertions, decl->assertions ); 358 oldToNew.emplace( std::make_pair( old_param, decl ) ); 353 359 type_params.push_back( decl ); 354 360 } 355 // TODO: The values in params and returns still may point at the old356 // generic params, that does not appear to be an issue but perhaps it357 // should be addressed.361 replaceAll( params, oldToNew ); 362 replaceAll( returns, oldToNew ); 363 replaceAll( assertions, oldToNew ); 358 364 359 365 ast::FunctionDecl * decl = new ast::FunctionDecl( 360 366 // Auto-generated routines use the type declaration's location. 361 367 getLocation(), 362 name,368 std::move( name ), 363 369 std::move( type_params ), 364 370 std::move( assertions ),
Note:
See TracChangeset
for help on using the changeset viewer.