Changeset 2a301ff for src/Validate/ForallPointerDecay.cpp
- Timestamp:
- Aug 31, 2023, 11:31:15 PM (2 years ago)
- Branches:
- master
- Children:
- 950c58e
- Parents:
- 92355883 (diff), 686912c (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/ForallPointerDecay.cpp
r92355883 r2a301ff 23 23 #include "Common/CodeLocation.h" 24 24 #include "Common/ToString.hpp" 25 #include "Common/utility.h" 25 26 #include "SymTab/FixFunction.h" 26 27 #include "AST/Print.hpp"28 27 29 28 namespace Validate { … … 51 50 } 52 51 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(); 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; 60 62 } 61 63 … … 96 98 decl->get_type() ) ) { 97 99 auto moreAsserts = expandTrait( traitInst ); 98 append( assertions, moreAsserts );100 splice( assertions, moreAsserts ); 99 101 } else { 100 102 assertions.push_back( decl ); … … 108 110 static TypeDeclVec expandTypeDecls( const TypeDeclVec & old ) { 109 111 TypeDeclVec typeDecls; 112 typeDecls.reserve( old.size() ); 110 113 for ( const ast::TypeDecl * typeDecl : old ) { 111 114 typeDecls.push_back( ast::mutate_field( typeDecl, … … 123 126 mut->assertions = expandAssertions( decl->assertions ); 124 127 // Update the assertion list on the type as well. 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; 128 return updateAssertions( mut ); 133 129 } 134 130 … … 154 150 const std::vector<ast::ptr<ast::DeclWithType>> & assertions ) { 155 151 std::vector<ast::ptr<ast::DeclWithType>> ret; 152 ret.reserve( assertions.size() ); 156 153 for ( const auto & assn : assertions ) { 157 154 bool isVoid = false; … … 187 184 } 188 185 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 189 193 const ast::StructDecl * previsit( const ast::StructDecl * decl ) { 190 194 if ( decl->params.empty() ) { … … 204 208 }; 205 209 206 struct O beratorChecker final {210 struct OperatorChecker final { 207 211 void previsit( const ast::ObjectDecl * obj ) { 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 } 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(), 217 " is not a function or function pointer." ) ); 216 218 } 217 219 }; … … 234 236 ast::Pass<TraitExpander>::run( transUnit ); 235 237 ast::Pass<AssertionFunctionFixer>::run( transUnit ); 236 ast::Pass<OberatorChecker>::run( transUnit ); 238 ast::Pass<OperatorChecker>::run( transUnit ); 239 } 240 241 void fixUniqueIds( ast::TranslationUnit & transUnit ) { 237 242 ast::Pass<UniqueFixCore>::run( transUnit ); 238 243 }
Note:
See TracChangeset
for help on using the changeset viewer.