Changeset 7f6a7c9 for src/Validate
- Timestamp:
- Sep 21, 2022, 11:02:15 AM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 95dab9e
- Parents:
- 428adbc (diff), 0bd46fd (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. - Location:
- src/Validate
- Files:
-
- 6 edited
-
Autogen.cpp (modified) (4 diffs)
-
EnumAndPointerDecay.cpp (modified) (4 diffs)
-
FixQualifiedTypes.cpp (modified) (4 diffs)
-
GenericParameter.cpp (modified) (2 diffs)
-
LinkReferenceToTypes.cpp (modified) (8 diffs)
-
ReplaceTypedef.cpp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
r428adbc r7f6a7c9 10 10 // Created On : Thu Dec 2 13:44:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T hr Jan 27 9:29:00 202213 // Update Count : 112 // Last Modified On : Tue Sep 20 16:00:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 25 25 26 26 #include "AST/Attribute.hpp" 27 #include "AST/Create.hpp" 27 28 #include "AST/Decl.hpp" 28 29 #include "AST/DeclReplacer.hpp" … … 236 237 if ( !enumDecl->body ) return; 237 238 239 // if ( auto enumBaseType = enumDecl->base ) { 240 // if ( auto enumBaseTypeAsStructInst = dynamic_cast<const ast::StructInstType *>(enumBaseType.get()) ) { 241 // const ast::StructDecl * structDecl = enumBaseTypeAsStructInst->base.get(); 242 // this->previsit( structDecl ); 243 // } 244 // } 245 238 246 ast::EnumInstType enumInst( enumDecl->name ); 239 247 enumInst.base = enumDecl; … … 321 329 void FuncGenerator::produceForwardDecl( const ast::FunctionDecl * decl ) { 322 330 if (0 != functionNesting) return; 323 ast::FunctionDecl * fwd = ast::deepCopy( decl );324 fwd->stmts = nullptr;331 ast::FunctionDecl * fwd = 332 ( decl->stmts ) ? ast::asForward( decl ) : ast::deepCopy( decl ) ; 325 333 fwd->fixUniqueId(); 326 334 forwards.push_back( fwd ); -
src/Validate/EnumAndPointerDecay.cpp
r428adbc r7f6a7c9 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
r428adbc r7f6a7c9 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 … … 19 19 #include "AST/TranslationUnit.hpp" 20 20 #include "Validate/NoIdSymbolTable.hpp" 21 #include "SymTab/Mangler.h" // for Mangler 22 #include "AST/LinkageSpec.hpp" // for Linkage 21 23 22 24 namespace Validate { … … 25 27 26 28 struct FixQualifiedTypesCore : 27 public WithNoIdSymbolTable, public ast::WithGuards { 28 CodeLocation const * location = nullptr; 29 30 void previsit( ast::ParseNode const * node ) { 31 GuardValue( location ) = &node->location; 32 } 33 29 public WithNoIdSymbolTable, 30 public ast::WithCodeLocation { 34 31 ast::Type const * postvisit( ast::QualifiedType const * type ) { 35 32 assert( location ); … … 89 86 } 90 87 } 88 89 ast::Expr const * postvisit( ast::QualifiedNameExpr const * t) { 90 assert( location ); 91 if ( t->type_decl ) { 92 auto enumName = t->type_decl->name; 93 const ast::EnumDecl * enumDecl = symtab.lookupEnum( enumName ); 94 for ( ast::ptr<ast::Decl> const & member : enumDecl->members ) { 95 if ( auto memberAsObj = member.as<ast::ObjectDecl>() ) { 96 if ( memberAsObj->name == t->name ) { 97 return new ast::VariableExpr( t->location, memberAsObj ); 98 } 99 } else { 100 assertf( false, "unhandled qualified child type"); 101 } 102 } 103 104 105 auto var = new ast::ObjectDecl( t->var->location, t->name, 106 new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall ); 107 var->scopeLevel = 1; // 1 for now; should copy the scopeLevel of the enumValue 108 var->mangleName = Mangle::mangle( var ); 109 return new ast::VariableExpr( t->location, var ); 110 // return ret; 111 } 112 113 return t; 114 } 115 91 116 }; 92 117 -
src/Validate/GenericParameter.cpp
r428adbc r7f6a7c9 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
r428adbc r7f6a7c9 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 ); … … 46 44 void postvisit( ast::UnionDecl const * decl ); 47 45 ast::TraitDecl const * postvisit( ast::TraitDecl const * decl ); 46 ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl); 48 47 49 48 private: … … 59 58 ForwardEnumsType forwardEnums; 60 59 61 const CodeLocation * location = nullptr;62 60 /// true if currently in a generic type body, 63 61 /// so that type parameter instances can be renamed appropriately … … 176 174 // Linking only makes sense for the 'oldest ancestor' of the qualified type. 177 175 type->parent->accept( *visitor ); 178 }179 180 void LinkTypesCore::previsit( ast::ParseNode const * node ) {181 GuardValue( location ) = &node->location;182 176 } 183 177 … … 224 218 GuardValue( inGeneric ) = !decl->params.empty(); 225 219 if ( !inGeneric ) { 226 GuardValue( location ) = &decl->location;227 220 return decl; 228 221 } 229 222 auto mut = ast::mutate( decl ); 230 GuardValue( location ) = &mut->location;231 223 for ( ast::ptr<ast::TypeDecl> & typeDecl : mut->params ) { 232 224 typeDecl.get_and_mutate()->name = "__" + typeDecl->name + "_generic_"; … … 292 284 } 293 285 286 ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) { 287 // Try to lookup type 288 if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) { 289 if ( auto inst = objDecl->type.as<ast::TypeInstType>()) { 290 if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) { 291 auto mut = ast::mutate( decl ); 292 mut->type_decl = enumDecl; 293 auto enumInst = new ast::EnumInstType( enumDecl ); 294 enumInst->name = decl->name; 295 // Adding result; addCandidate() use result 296 mut->result = enumInst; 297 decl = mut; 298 } 299 } 300 } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) { 301 auto mut = ast::mutate( decl ); 302 auto enumInst = new ast::EnumInstType( enumDecl ); 303 enumInst->name = decl->name; 304 // Adding result; addCandidate() use result 305 mut->result = enumInst; 306 decl = mut; 307 } 308 // ast::EnumDecl const * decl = symtab.lookupEnum( type->name ); 309 // // It's not a semantic error if the enum is not found, just an implicit forward declaration. 310 // if ( decl ) { 311 // // Just linking in the node. 312 // auto mut = ast::mutate( type ); 313 // mut->base = const_cast<ast::EnumDecl *>( decl ); 314 // type = mut; 315 // } 316 return decl; 317 } 318 294 319 } // namespace 295 320 -
src/Validate/ReplaceTypedef.cpp
r428adbc r7f6a7c9 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 ); … … 183 178 } else if ( auto enumType = dynamic_cast<ast::EnumInstType const *>( designatorType ) ) { 184 179 declsToAddBefore.push_back( new ast::EnumDecl( 185 decl->location, enumType->name, {}, decl->linkage,180 decl->location, enumType->name, false, {}, decl->linkage, 186 181 ( (enumType->base) ? enumType->base->base : nullptr ) 187 182 ) ); … … 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() ) { … … 199 193 } 200 194 201 void ReplaceTypedefCore::previsit( ast::FunctionDecl const * decl ) { 202 previsit( (ast::ParseNode const *)decl ); 195 void ReplaceTypedefCore::previsit( ast::FunctionDecl const * ) { 203 196 GuardScope( typedefNames ); 204 197 GuardScope( typedeclNames ); … … 206 199 } 207 200 208 void ReplaceTypedefCore::previsit( ast::ObjectDecl const * decl ) { 209 previsit( (ast::ParseNode const *)decl ); 201 void ReplaceTypedefCore::previsit( ast::ObjectDecl const * ) { 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, … … 249 241 } 250 242 251 void ReplaceTypedefCore::previsit( ast::CastExpr const * expr ) { 252 previsit( (ast::ParseNode const *)expr ); 253 GuardScope( typedefNames ); 254 GuardScope( typedeclNames ); 255 } 256 257 void ReplaceTypedefCore::previsit( ast::CompoundStmt const * expr ) { 258 previsit( (ast::ParseNode const *)expr ); 243 void ReplaceTypedefCore::previsit( ast::CastExpr const * ) { 244 GuardScope( typedefNames ); 245 GuardScope( typedeclNames ); 246 } 247 248 void ReplaceTypedefCore::previsit( ast::CompoundStmt const * ) { 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 void ReplaceTypedefCore::previsit( ast::TraitDecl const * decl ) { 289 previsit( (ast::ParseNode const *)decl ); 275 void ReplaceTypedefCore::previsit( ast::TraitDecl const * ) { 290 276 GuardScope( typedefNames ); 291 277 GuardScope( typedeclNames );
Note:
See TracChangeset
for help on using the changeset viewer.