Changes in / [dbf5e18:847ab8f]
- Location:
- src
- Files:
-
- 6 edited
-
AST/Util.cpp (modified) (2 diffs)
-
InitTweak/InitTweak.cc (modified) (1 diff)
-
Parser/parser.yy (modified) (4 diffs)
-
Validate/ForallPointerDecay.cpp (modified) (9 diffs)
-
Validate/LinkReferenceToTypes.cpp (modified) (8 diffs)
-
Validate/ReplaceTypedef.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Util.cpp
rdbf5e18 r847ab8f 102 102 } 103 103 104 /// Check for Floating Nodes:105 /// Every node should be reachable from a root (the TranslationUnit) via a106 /// chain of structural references (tracked with ptr). This cannot check all107 /// of that, it just checks if a given node's field has a strong reference.108 template<typename node_t, typename field_t>109 void noFloatingNode( const node_t * node, field_t node_t::*field_ptr ) {110 const field_t & field = node->*field_ptr;111 if ( nullptr == field ) return;112 assertf( field->isManaged(), "Floating node found." );113 }114 115 104 struct InvariantCore { 116 105 // To save on the number of visits: this is a kind of composed core. … … 138 127 } 139 128 140 void previsit( const VariableExpr * node ) {141 previsit( (const ParseNode *)node );142 noFloatingNode( node, &VariableExpr::var );143 }144 145 129 void previsit( const MemberExpr * node ) { 146 130 previsit( (const ParseNode *)node ); 147 131 memberMatchesAggregate( node ); 148 }149 150 void previsit( const StructInstType * node ) {151 previsit( (const Node *)node );152 noFloatingNode( node, &StructInstType::base );153 }154 155 void previsit( const UnionInstType * node ) {156 previsit( (const Node *)node );157 noFloatingNode( node, &UnionInstType::base );158 }159 160 void previsit( const EnumInstType * node ) {161 previsit( (const Node *)node );162 noFloatingNode( node, &EnumInstType::base );163 }164 165 void previsit( const TypeInstType * node ) {166 previsit( (const Node *)node );167 noFloatingNode( node, &TypeInstType::base );168 132 } 169 133 -
src/InitTweak/InitTweak.cc
rdbf5e18 r847ab8f 882 882 if (!assign) { 883 883 auto td = new ast::TypeDecl(CodeLocation(), "T", {}, nullptr, ast::TypeDecl::Dtype, true); 884 assign = new ast::FunctionDecl(CodeLocation(), "?=?", { td},884 assign = new ast::FunctionDecl(CodeLocation(), "?=?", {}, 885 885 { new ast::ObjectDecl(CodeLocation(), "_dst", new ast::ReferenceType(new ast::TypeInstType("T", td))), 886 886 new ast::ObjectDecl(CodeLocation(), "_src", new ast::TypeInstType("T", td))}, -
src/Parser/parser.yy
rdbf5e18 r847ab8f 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 12 23:06:44202313 // Update Count : 638 912 // Last Modified On : Wed Jul 12 06:14:16 2023 13 // Update Count : 6382 14 14 // 15 15 … … 1868 1868 1869 1869 KR_parameter_list: 1870 c_declaration';'1871 { $$ = $ 1; }1872 | KR_parameter_list c_declaration';'1873 { $$ = $1->appendList( $ 2); }1870 push c_declaration pop ';' 1871 { $$ = $2; } 1872 | KR_parameter_list push c_declaration pop ';' 1873 { $$ = $1->appendList( $3 ); } 1874 1874 ; 1875 1875 … … 2033 2033 } else $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 2034 2034 } 2035 | typedef_declaration ','declarator2036 { 2037 typedefTable.addToEnclosingScope( *$ 3->name, TYPEDEFname, "typedef_declaration 2" );2038 $$ = $1->appendList( $1->cloneBaseType( $ 3)->addTypedef() );2035 | typedef_declaration pop ',' push declarator 2036 { 2037 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "typedef_declaration 2" ); 2038 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 2039 2039 } 2040 2040 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) … … 2052 2052 SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 2053 2053 } 2054 | typedef_expression ','identifier '=' assignment_expression2054 | typedef_expression pop ',' push identifier '=' assignment_expression 2055 2055 { 2056 2056 SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr; -
src/Validate/ForallPointerDecay.cpp
rdbf5e18 r847ab8f 23 23 #include "Common/CodeLocation.h" 24 24 #include "Common/ToString.hpp" 25 #include "Common/utility.h"26 25 #include "SymTab/FixFunction.h" 26 27 #include "AST/Print.hpp" 27 28 28 29 namespace Validate { … … 50 51 } 51 52 52 ast::FunctionDecl * updateAssertions( ast::FunctionDecl * decl ) { 53 auto type = ast::mutate( decl->type.get() ); 54 type->assertions.clear(); 55 type->assertions.reserve( decl->assertions.size() ); 56 for ( auto & assertion : decl->assertions ) { 57 type->assertions.emplace_back( 58 new ast::VariableExpr( decl->location, assertion ) ); 59 } 60 decl->type = type; 61 return decl; 53 template<typename T> 54 void append( std::vector<T> & dst, std::vector<T> & src ) { 55 dst.reserve( dst.size() + src.size() ); 56 for ( auto el : src ) { 57 dst.emplace_back( std::move( el ) ); 58 } 59 src.clear(); 62 60 } 63 61 … … 98 96 decl->get_type() ) ) { 99 97 auto moreAsserts = expandTrait( traitInst ); 100 splice( assertions, moreAsserts );98 append( assertions, moreAsserts ); 101 99 } else { 102 100 assertions.push_back( decl ); … … 110 108 static TypeDeclVec expandTypeDecls( const TypeDeclVec & old ) { 111 109 TypeDeclVec typeDecls; 112 typeDecls.reserve( old.size() );113 110 for ( const ast::TypeDecl * typeDecl : old ) { 114 111 typeDecls.push_back( ast::mutate_field( typeDecl, … … 126 123 mut->assertions = expandAssertions( decl->assertions ); 127 124 // Update the assertion list on the type as well. 128 return updateAssertions( mut ); 125 auto mutType = ast::mutate( mut->type.get() ); 126 mutType->assertions.clear(); 127 for ( auto & assertion : mut->assertions ) { 128 mutType->assertions.emplace_back( 129 new ast::VariableExpr( mut->location, assertion ) ); 130 } 131 mut->type = mutType; 132 return mut; 129 133 } 130 134 … … 150 154 const std::vector<ast::ptr<ast::DeclWithType>> & assertions ) { 151 155 std::vector<ast::ptr<ast::DeclWithType>> ret; 152 ret.reserve( assertions.size() );153 156 for ( const auto & assn : assertions ) { 154 157 bool isVoid = false; … … 184 187 } 185 188 186 const ast::FunctionDecl * postvisit( const ast::FunctionDecl * decl ) {187 if ( decl->assertions.empty() ) {188 return decl;189 }190 return updateAssertions( mutate( decl ) );191 }192 193 189 const ast::StructDecl * previsit( const ast::StructDecl * decl ) { 194 190 if ( decl->params.empty() ) { … … 208 204 }; 209 205 210 struct O peratorChecker final {206 struct OberatorChecker final { 211 207 void previsit( const ast::ObjectDecl * obj ) { 212 if ( !CodeGen::isOperator( obj->name ) ) return; 213 auto type = obj->type->stripDeclarator(); 214 if ( dynamic_cast< const ast::FunctionType * >( type ) ) return; 215 SemanticError( obj->location, 216 toCString( "operator ", obj->name.c_str(), " is not " 217 "a function or function pointer." ) ); 208 if ( CodeGen::isOperator( obj->name ) ) { 209 auto type = obj->type->stripDeclarator(); 210 if ( ! dynamic_cast< const ast::FunctionType * >( type ) ) { 211 SemanticError( obj->location, 212 toCString( "operator ", obj->name.c_str(), " is not " 213 "a function or function pointer." ) ); 214 } 215 } 218 216 } 219 217 }; … … 236 234 ast::Pass<TraitExpander>::run( transUnit ); 237 235 ast::Pass<AssertionFunctionFixer>::run( transUnit ); 238 ast::Pass<O peratorChecker>::run( transUnit );236 ast::Pass<OberatorChecker>::run( transUnit ); 239 237 ast::Pass<UniqueFixCore>::run( transUnit ); 240 238 } -
src/Validate/LinkReferenceToTypes.cpp
rdbf5e18 r847ab8f 10 10 // Created On : Thr Apr 21 11:41:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jul 14 9:19:00 202313 // Update Count : 312 // Last Modified On : Tue Sep 20 16:17:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 27 27 struct LinkTypesCore : public WithNoIdSymbolTable, 28 28 public ast::WithCodeLocation, 29 public ast::WithDeclsToAdd<>,30 29 public ast::WithGuards, 31 30 public ast::WithShortCircuiting, … … 64 63 template<typename AggrDecl> 65 64 AggrDecl const * renameGenericParams( AggrDecl const * decl ); 66 67 // This cluster is used to add declarations (before) but outside of68 // any "namespaces" which would qualify the names.69 bool inNamespace = false;70 std::list<ast::ptr<ast::Decl>> declsToAddOutside;71 /// The "leaveNamespace" is handled by guard.72 void enterNamespace();73 /// Puts the decl on the back of declsToAddAfter once traversal is74 /// outside of any namespaces.75 void addDeclAfterOutside( ast::Decl const * );76 65 }; 77 78 void LinkTypesCore::enterNamespace() {79 if ( inNamespace ) return;80 inNamespace = true;81 GuardAction( [this](){82 inNamespace = false;83 declsToAddAfter.splice( declsToAddAfter.begin(), declsToAddOutside );84 } );85 }86 87 void LinkTypesCore::addDeclAfterOutside( ast::Decl const * decl ) {88 if ( inNamespace ) {89 declsToAddOutside.emplace_back( decl );90 } else {91 declsToAddAfter.emplace_back( decl );92 }93 }94 66 95 67 ast::TypeInstType const * LinkTypesCore::postvisit( ast::TypeInstType const * type ) { … … 108 80 ast::EnumInstType const * LinkTypesCore::postvisit( ast::EnumInstType const * type ) { 109 81 ast::EnumDecl const * decl = symtab.lookupEnum( type->name ); 82 ast::EnumInstType * mut = ast::mutate( type ); 110 83 // It's not a semantic error if the enum is not found, just an implicit forward declaration. 111 // The unset code location is used to detect imaginary declarations. 112 // (They may never be used for enumerations.) 113 if ( !decl || decl->location.isUnset() ) { 114 assert( location ); 115 ast::EnumDecl * mut = new ast::EnumDecl( *location, type->name ); 116 mut->linkage = ast::Linkage::Compiler; 117 decl = mut; 118 symtab.addEnum( decl ); 119 addDeclAfterOutside( decl ); 120 } 121 122 ast::EnumInstType * mut = ast::mutate( type ); 123 124 // Just linking in the node. 125 mut->base = decl; 126 127 if ( !decl->body ) { 84 if ( decl ) { 85 // Just linking in the node. 86 mut->base = decl; 87 } 88 if ( !decl || !decl->body ) { 128 89 forwardEnums[ mut->name ].push_back( mut ); 129 90 } … … 133 94 ast::StructInstType const * LinkTypesCore::postvisit( ast::StructInstType const * type ) { 134 95 ast::StructDecl const * decl = symtab.lookupStruct( type->name ); 96 ast::StructInstType * mut = ast::mutate( type ); 135 97 // It's not a semantic error if the struct is not found, just an implicit forward declaration. 136 // The unset code location is used to detect imaginary declarations. 137 if ( !decl || decl->location.isUnset() ) { 138 assert( location ); 139 ast::StructDecl * mut = new ast::StructDecl( *location, type->name ); 140 mut->linkage = ast::Linkage::Compiler; 141 decl = mut; 142 symtab.addStruct( decl ); 143 addDeclAfterOutside( decl ); 144 } 145 146 ast::StructInstType * mut = ast::mutate( type ); 147 148 // Just linking in the node. 149 mut->base = decl; 150 151 if ( !decl->body ) { 98 if ( decl ) { 99 // Just linking in the node. 100 mut->base = decl; 101 } 102 if ( !decl || !decl->body ) { 152 103 forwardStructs[ mut->name ].push_back( mut ); 153 104 } … … 157 108 ast::UnionInstType const * LinkTypesCore::postvisit( ast::UnionInstType const * type ) { 158 109 ast::UnionDecl const * decl = symtab.lookupUnion( type->name ); 110 ast::UnionInstType * mut = ast::mutate( type ); 159 111 // It's not a semantic error if the union is not found, just an implicit forward declaration. 160 // The unset code location is used to detect imaginary declarations. 161 if ( !decl || decl->location.isUnset() ) { 162 assert( location ); 163 ast::UnionDecl * mut = new ast::UnionDecl( *location, type->name ); 164 mut->linkage = ast::Linkage::Compiler; 165 decl = mut; 166 symtab.addUnion( decl ); 167 addDeclAfterOutside( decl ); 168 } 169 170 ast::UnionInstType * mut = ast::mutate( type ); 171 172 // Just linking in the node. 173 mut->base = decl; 174 175 if ( !decl->body ) { 112 if ( decl ) { 113 // Just linking in the node. 114 mut->base = decl; 115 } 116 if ( !decl || !decl->body ) { 176 117 forwardUnions[ mut->name ].push_back( mut ); 177 118 } … … 278 219 279 220 ast::StructDecl const * LinkTypesCore::previsit( ast::StructDecl const * decl ) { 280 enterNamespace();281 221 return renameGenericParams( decl ); 282 222 } … … 297 237 298 238 ast::UnionDecl const * LinkTypesCore::previsit( ast::UnionDecl const * decl ) { 299 enterNamespace();300 239 return renameGenericParams( decl ); 301 240 } -
src/Validate/ReplaceTypedef.cpp
rdbf5e18 r847ab8f 20 20 #include "Common/ScopedMap.h" 21 21 #include "Common/UniqueName.h" 22 #include "Common/utility.h" 22 23 #include "ResolvExpr/Unify.h" 23 24 … … 293 294 aggrDecl->name, ast::Storage::Classes(), type, aggrDecl->linkage ); 294 295 // Add the implicit typedef to the AST. 295 declsToAdd After.push_back( ast::deepCopy( typeDecl.get() ) );296 declsToAddBefore.push_back( ast::deepCopy( typeDecl.get() ) ); 296 297 // Shore the name in the map of names. 297 298 typedefNames[ aggrDecl->name ] = … … 315 316 auto mut = ast::mutate( decl ); 316 317 317 std:: list<ast::ptr<ast::Decl>> members;318 std::vector<ast::ptr<ast::Decl>> members; 318 319 // Unroll accept_all for decl->members so that implicit typedefs for 319 320 // nested types are added to the aggregate body. 320 321 for ( ast::ptr<ast::Decl> const & member : mut->members ) { 321 assert( declsToAddBefore.empty() );322 322 assert( declsToAddAfter.empty() ); 323 323 ast::Decl const * newMember = nullptr; … … 328 328 } 329 329 if ( !declsToAddBefore.empty() ) { 330 members.splice( members.end(), declsToAddBefore ); 330 for ( auto declToAdd : declsToAddBefore ) { 331 members.push_back( declToAdd ); 332 } 333 declsToAddBefore.clear(); 331 334 } 332 335 members.push_back( newMember ); 333 if ( !declsToAddAfter.empty() ) { 334 members.splice( members.end(), declsToAddAfter ); 335 } 336 } 337 assert( declsToAddBefore.empty() ); 336 } 338 337 assert( declsToAddAfter.empty() ); 339 338 if ( !errors.isEmpty() ) { throw errors; }
Note:
See TracChangeset
for help on using the changeset viewer.