Changeset 62d62db for src/Validate
- Timestamp:
- Jun 12, 2023, 6:06:26 PM (20 months ago)
- Branches:
- ast-experimental, master
- Children:
- e172f42
- Parents:
- 24d6572 (diff), 38e266ca (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/HoistStruct.cpp
r24d6572 r62d62db 18 18 #include <sstream> 19 19 20 #include "AST/DeclReplacer.hpp" 20 21 #include "AST/Pass.hpp" 21 22 #include "AST/TranslationUnit.hpp" 23 #include "AST/Vector.hpp" 22 24 23 25 namespace Validate { … … 51 53 template<typename AggrDecl> 52 54 AggrDecl const * postAggregate( AggrDecl const * ); 55 template<typename InstType> 56 InstType const * preCollectionInstType( InstType const * type ); 53 57 54 58 ast::AggregateDecl const * parent = nullptr; … … 66 70 qualifiedName( decl, ss ); 67 71 return ss.str(); 72 } 73 74 void extendParams( ast::vector<ast::TypeDecl> & dstParams, 75 ast::vector<ast::TypeDecl> const & srcParams ) { 76 if ( srcParams.empty() ) return; 77 78 ast::DeclReplacer::TypeMap newToOld; 79 ast::vector<ast::TypeDecl> params; 80 for ( ast::ptr<ast::TypeDecl> const & srcParam : srcParams ) { 81 ast::TypeDecl * dstParam = ast::deepCopy( srcParam.get() ); 82 dstParam->init = nullptr; 83 newToOld.emplace( srcParam, dstParam ); 84 for ( auto assertion : dstParam->assertions ) { 85 assertion = ast::DeclReplacer::replace( assertion, newToOld ); 86 } 87 params.emplace_back( dstParam ); 88 } 89 spliceBegin( dstParams, params ); 68 90 } 69 91 … … 74 96 mut->parent = parent; 75 97 mut->name = qualifiedName( mut ); 76 return mut;77 } else {78 GuardValue( parent ) = decl;79 returndecl;80 }98 extendParams( mut->params, parent->params ); 99 decl = mut; 100 } 101 GuardValue( parent ) = decl; 102 return decl; 81 103 } 82 104 … … 112 134 } 113 135 136 ast::AggregateDecl const * commonParent( 137 ast::AggregateDecl const * lhs, ast::AggregateDecl const * rhs ) { 138 for ( auto outer = lhs ; outer ; outer = outer->parent ) { 139 for ( auto inner = rhs ; inner ; inner = inner->parent ) { 140 if ( outer == inner ) { 141 return outer; 142 } 143 } 144 } 145 return nullptr; 146 } 147 148 template<typename InstType> 149 InstType const * HoistStructCore::preCollectionInstType( InstType const * type ) { 150 if ( !type->base->parent ) return type; 151 if ( type->base->params.empty() ) return type; 152 153 InstType * mut = ast::mutate( type ); 154 ast::AggregateDecl const * parent = 155 commonParent( this->parent, mut->base->parent ); 156 assert( parent ); 157 158 std::vector<ast::ptr<ast::Expr>> args; 159 for ( const ast::ptr<ast::TypeDecl> & param : parent->params ) { 160 args.emplace_back( new ast::TypeExpr( param->location, 161 new ast::TypeInstType( param ) 162 ) ); 163 } 164 spliceBegin( mut->params, args ); 165 return mut; 166 } 167 114 168 template<typename InstType> 115 169 InstType const * preInstType( InstType const * type ) { … … 121 175 122 176 ast::StructInstType const * HoistStructCore::previsit( ast::StructInstType const * type ) { 123 return preInstType( type);177 return preInstType( preCollectionInstType( type ) ); 124 178 } 125 179 126 180 ast::UnionInstType const * HoistStructCore::previsit( ast::UnionInstType const * type ) { 127 return preInstType( type);181 return preInstType( preCollectionInstType( type ) ); 128 182 } 129 183
Note: See TracChangeset
for help on using the changeset viewer.