Changeset e9e9f56 for src/Validate/ReplaceTypedef.cpp
- Timestamp:
- Sep 21, 2022, 9:22:24 AM (22 months ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 20737104
- Parents:
- b6c3688
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/ReplaceTypedef.cpp
rb6c3688 re9e9f56 10 10 // Created On : Tue Jun 29 14:59:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 13 14:45:00 202213 // Update Count : 112 // Last Modified On : Tue Sep 20 17:00:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 39 39 40 40 struct ReplaceTypedefCore final : 41 public ast::WithVisitorRef<ReplaceTypedefCore>, 41 public ast::WithCodeLocation, 42 public ast::WithDeclsToAdd<>, 42 43 public ast::WithGuards, 43 44 public ast::WithShortCircuiting, 44 public ast::WithDeclsToAdd<> { 45 46 void previsit( ast::ParseNode const * node ); 45 public ast::WithVisitorRef<ReplaceTypedefCore> { 46 47 47 void previsit( ast::QualifiedType const * ); 48 48 ast::Type const * postvisit( ast::QualifiedType const * ); … … 74 74 TypedefMap typedefNames; 75 75 TypeDeclMap typedeclNames; 76 CodeLocation const * nearestLocation = nullptr;77 76 int scopeLevel; 78 77 bool isAtFunctionTop = false; 79 78 }; 80 81 void ReplaceTypedefCore::previsit( ast::ParseNode const * node ) {82 GuardValue( nearestLocation ) = &node->location;83 }84 79 85 80 void ReplaceTypedefCore::previsit( ast::QualifiedType const * ) { … … 115 110 auto rtt = dynamic_cast<ast::BaseInstType *>( ret ); 116 111 if ( !rtt ) { 117 assert( nearestLocation );118 SemanticError( * nearestLocation, "Cannot apply type parameters to base type of " + type->name );112 assert( location ); 113 SemanticError( *location, "Cannot apply type parameters to base type of " + type->name ); 119 114 } 120 115 rtt->params.clear(); … … 129 124 TypeDeclMap::const_iterator base = typedeclNames.find( type->name ); 130 125 if ( base == typedeclNames.end() ) { 131 assert( nearestLocation );132 SemanticError( * nearestLocation, toString( "Use of undefined type ", type->name ) );126 assert( location ); 127 SemanticError( *location, toString( "Use of undefined type ", type->name ) ); 133 128 } 134 129 return ast::mutate_field( type, &ast::TypeInstType::base, base->second ); … … 191 186 192 187 void ReplaceTypedefCore::previsit( ast::TypeDecl const * decl ) { 193 previsit( (ast::ParseNode const *)decl );194 188 TypedefMap::iterator iter = typedefNames.find( decl->name ); 195 189 if ( iter != typedefNames.end() ) { … … 200 194 201 195 void ReplaceTypedefCore::previsit( ast::FunctionDecl const * decl ) { 202 previsit( (ast::ParseNode const *)decl );203 196 GuardScope( typedefNames ); 204 197 GuardScope( typedeclNames ); … … 207 200 208 201 void ReplaceTypedefCore::previsit( ast::ObjectDecl const * decl ) { 209 previsit( (ast::ParseNode const *)decl );210 202 GuardScope( typedefNames ); 211 203 GuardScope( typedeclNames ); … … 217 209 using DWTVector = std::vector<ast::ptr<ast::DeclWithType>>; 218 210 using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>; 219 CodeLocation const & location = decl->location;211 CodeLocation const & declLocation = decl->location; 220 212 UniqueName paramNamer( decl->name + "Param" ); 221 213 222 214 // Replace the current object declaration with a function declaration. 223 215 ast::FunctionDecl const * newDecl = new ast::FunctionDecl( 224 location,216 declLocation, 225 217 decl->name, 226 218 map_range<DeclVector>( type->forall, []( const ast::TypeInstType * inst ) { … … 230 222 return ast::deepCopy( expr->var ); 231 223 } ), 232 map_range<DWTVector>( type->params, [& location, ¶mNamer]( const ast::Type * type ) {224 map_range<DWTVector>( type->params, [&declLocation, ¶mNamer]( const ast::Type * type ) { 233 225 assert( type ); 234 return new ast::ObjectDecl( location, paramNamer.newName(), ast::deepCopy( type ) );226 return new ast::ObjectDecl( declLocation, paramNamer.newName(), ast::deepCopy( type ) ); 235 227 } ), 236 map_range<DWTVector>( type->returns, [& location, ¶mNamer]( const ast::Type * type ) {228 map_range<DWTVector>( type->returns, [&declLocation, ¶mNamer]( const ast::Type * type ) { 237 229 assert( type ); 238 return new ast::ObjectDecl( location, paramNamer.newName(), ast::deepCopy( type ) );230 return new ast::ObjectDecl( declLocation, paramNamer.newName(), ast::deepCopy( type ) ); 239 231 } ), 240 232 nullptr, … … 250 242 251 243 void ReplaceTypedefCore::previsit( ast::CastExpr const * expr ) { 252 previsit( (ast::ParseNode const *)expr );253 244 GuardScope( typedefNames ); 254 245 GuardScope( typedeclNames ); … … 256 247 257 248 void ReplaceTypedefCore::previsit( ast::CompoundStmt const * expr ) { 258 previsit( (ast::ParseNode const *)expr );259 249 GuardScope( typedefNames ); 260 250 GuardScope( typedeclNames ); … … 268 258 269 259 ast::StructDecl const * ReplaceTypedefCore::previsit( ast::StructDecl const * decl ) { 270 previsit( (ast::ParseNode const *)decl );271 260 visit_children = false; 272 261 addImplicitTypedef( decl ); … … 275 264 276 265 ast::UnionDecl const * ReplaceTypedefCore::previsit( ast::UnionDecl const * decl ) { 277 previsit( (ast::ParseNode const *)decl );278 266 visit_children = false; 279 267 addImplicitTypedef( decl ); … … 282 270 283 271 void ReplaceTypedefCore::previsit( ast::EnumDecl const * decl ) { 284 previsit( (ast::ParseNode const *)decl );285 272 addImplicitTypedef( decl ); 286 273 } 287 274 288 275 void ReplaceTypedefCore::previsit( ast::TraitDecl const * decl ) { 289 previsit( (ast::ParseNode const *)decl );290 276 GuardScope( typedefNames ); 291 277 GuardScope( typedeclNames );
Note: See TracChangeset
for help on using the changeset viewer.