Changeset e9e9f56 for src/Validate
- Timestamp:
- Sep 21, 2022, 9:22:24 AM (19 months ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 20737104
- Parents:
- b6c3688
- Location:
- src/Validate
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/EnumAndPointerDecay.cpp
rb6c3688 re9e9f56 10 10 // Created On : Tue Jun 28 15:50:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jul 12 14:45:00 202213 // Update Count : 012 // Last Modified On : Tue Sep 20 16:14:00 2022 13 // Update Count : 1 14 14 // 15 15 … … 26 26 namespace { 27 27 28 struct EnumAndPointerDecayCore final : public ast::WithGuards { 29 CodeLocation const * location = nullptr; 30 void previsit( ast::ParseNode const * node ); 28 struct EnumAndPointerDecayCore final : public ast::WithCodeLocation { 31 29 ast::EnumDecl const * previsit( ast::EnumDecl const * decl ); 32 30 ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl ); 33 31 ast::FunctionType const * previsit( ast::FunctionType const * type ); 34 32 }; 35 36 void EnumAndPointerDecayCore::previsit( ast::ParseNode const * node ) {37 GuardValue( location ) = &node->location;38 }39 33 40 34 ast::EnumDecl const * EnumAndPointerDecayCore::previsit( … … 50 44 new ast::EnumInstType( decl, ast::CV::Const ) ); 51 45 } 52 GuardValue( location ) = &decl->location;53 46 return mut; 54 47 } … … 79 72 ast::FunctionDecl const * decl ) { 80 73 auto mut = ast::mutate( decl ); 81 GuardValue( location ) = &decl->location;82 74 ast::ArgumentFlag isVarArgs = mut->type->isVarArgs; 83 75 // It seems fixFunction (via fixFunctionList) does the pointer decay part. -
src/Validate/FixQualifiedTypes.cpp
rb6c3688 re9e9f56 10 10 // Created On : Thr Apr 21 11:13:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Apr 22 11:36:00 202213 // Update Count : 012 // Last Modified On : Tue Sep 20 16:15:00 2022 13 // Update Count : 1 14 14 // 15 15 … … 27 27 28 28 struct FixQualifiedTypesCore : 29 public WithNoIdSymbolTable, public ast::WithGuards { 30 CodeLocation const * location = nullptr; 31 32 void previsit( ast::ParseNode const * node ) { 33 GuardValue( location ) = &node->location; 34 } 35 29 public WithNoIdSymbolTable, 30 public ast::WithCodeLocation { 36 31 ast::Type const * postvisit( ast::QualifiedType const * type ) { 37 32 assert( location ); -
src/Validate/GenericParameter.cpp
rb6c3688 re9e9f56 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // GenericParameter. hpp -- Generic parameter related passes.7 // GenericParameter.cpp -- Generic parameter related passes. 8 8 // 9 9 // Author : Andrew Beach 10 10 // Created On : Fri Mar 21 10:02:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Apr 22 16:43:00 202213 // Update Count : 112 // Last Modified On : Tue Sep 20 16:28:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 119 119 } 120 120 121 struct ValidateGenericParamsCore : public ast::WithGuards { 122 const CodeLocation * locationPtr = nullptr; 123 124 void previsit( const ast::ParseNode * node ) { 125 GuardValue( locationPtr ) = &node->location; 126 } 127 121 struct ValidateGenericParamsCore : public ast::WithCodeLocation { 128 122 const ast::StructInstType * previsit( const ast::StructInstType * type ) { 129 assert( location Ptr);130 return validateGeneric( *location Ptr, type );123 assert( location ); 124 return validateGeneric( *location, type ); 131 125 } 132 126 133 127 const ast::UnionInstType * previsit( const ast::UnionInstType * type ) { 134 assert( location Ptr);135 return validateGeneric( *location Ptr, type );128 assert( location ); 129 return validateGeneric( *location, type ); 136 130 } 137 131 }; -
src/Validate/LinkReferenceToTypes.cpp
rb6c3688 re9e9f56 10 10 // Created On : Thr Apr 21 11:41:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 28 14:58:00 202213 // Update Count : 112 // Last Modified On : Tue Sep 20 16:17:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 26 26 27 27 struct LinkTypesCore : public WithNoIdSymbolTable, 28 public ast::WithCodeLocation, 28 29 public ast::WithGuards, 29 public ast::WithVisitorRef<LinkTypesCore>, 30 public ast::WithShortCircuiting { 31 30 public ast::WithShortCircuiting, 31 public ast::WithVisitorRef<LinkTypesCore> { 32 32 ast::TypeInstType const * postvisit( ast::TypeInstType const * type ); 33 33 ast::EnumInstType const * postvisit( ast::EnumInstType const * type ); … … 38 38 void postvisit( ast::QualifiedType const * type ); 39 39 40 void previsit( ast::ParseNode const * node );41 42 40 ast::EnumDecl const * postvisit( ast::EnumDecl const * decl ); 43 41 ast::StructDecl const * previsit( ast::StructDecl const * decl ); … … 60 58 ForwardEnumsType forwardEnums; 61 59 62 const CodeLocation * location = nullptr;63 60 /// true if currently in a generic type body, 64 61 /// so that type parameter instances can be renamed appropriately … … 177 174 // Linking only makes sense for the 'oldest ancestor' of the qualified type. 178 175 type->parent->accept( *visitor ); 179 }180 181 void LinkTypesCore::previsit( ast::ParseNode const * node ) {182 GuardValue( location ) = &node->location;183 176 } 184 177 … … 225 218 GuardValue( inGeneric ) = !decl->params.empty(); 226 219 if ( !inGeneric ) { 227 GuardValue( location ) = &decl->location;228 220 return decl; 229 221 } 230 222 auto mut = ast::mutate( decl ); 231 GuardValue( location ) = &mut->location;232 223 for ( ast::ptr<ast::TypeDecl> & typeDecl : mut->params ) { 233 224 typeDecl.get_and_mutate()->name = "__" + typeDecl->name + "_generic_"; -
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.