Changeset 7f3b5ce
- Timestamp:
- Oct 31, 2022, 3:00:06 PM (18 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- e8b8e65
- Parents:
- cd5b58f (diff), f2ff0a6 (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
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
rcd5b58f r7f3b5ce 617 617 maybe_accept( node, &FunctionDecl::returns ); 618 618 maybe_accept( node, &FunctionDecl::type ); 619 maybe_accept( node, &FunctionDecl::attributes ); 619 620 // First remember that we are now within a function. 620 621 ValueGuard< bool > oldInFunction( inFunction ); … … 625 626 atFunctionTop = true; 626 627 maybe_accept( node, &FunctionDecl::stmts ); 627 maybe_accept( node, &FunctionDecl::attributes );628 628 } 629 629 } -
src/Common/PassVisitor.impl.h
rcd5b58f r7f3b5ce 607 607 indexerAddId( &func ); 608 608 maybeMutate_impl( node->type, *this ); 609 maybeMutate_impl( node->attributes, *this ); 609 610 // First remember that we are now within a function. 610 611 ValueGuard< bool > oldInFunction( inFunction ); … … 615 616 atFunctionTop = true; 616 617 maybeMutate_impl( node->statements, *this ); 617 maybeMutate_impl( node->attributes, *this );618 618 } 619 619 } -
src/GenPoly/Box.cc
rcd5b58f r7f3b5ce 68 68 /// Adds layout-generation functions to polymorphic types. 69 69 class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting { 70 // Current level of nested functions:71 unsigned int functionNesting = 0;72 70 public: 73 void previsit( FunctionDecl *functionDecl );74 71 void previsit( StructDecl *structDecl ); 75 72 void previsit( UnionDecl *unionDecl ); … … 237 234 ////////////////////////////////// LayoutFunctionBuilder //////////////////////////////////////////// 238 235 239 void LayoutFunctionBuilder::previsit( FunctionDecl *functionDecl ) {240 visit_children = false;241 maybeAccept( functionDecl->get_functionType(), *visitor );242 ++functionNesting;243 maybeAccept( functionDecl->get_statements(), *visitor );244 --functionNesting;245 }246 247 236 /// Get a list of type declarations that will affect a layout function 248 237 std::list< TypeDecl* > takeOtypeOnly( std::list< TypeDecl* > &decls ) { … … 271 260 272 261 /// Builds a layout function declaration 273 FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, unsigned int functionNesting, FunctionType *layoutFnType ) {262 FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, bool isInFunction, FunctionType *layoutFnType ) { 274 263 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 275 264 // because each unit generates copies of the default routines for each aggregate. 276 265 FunctionDecl *layoutDecl = new FunctionDecl( layoutofName( typeDecl ), 277 functionNesting > 0? Type::StorageClasses() : Type::StorageClasses( Type::Static ),266 isInFunction ? Type::StorageClasses() : Type::StorageClasses( Type::Static ), 278 267 LinkageSpec::AutoGen, layoutFnType, new CompoundStmt(), 279 268 std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) ); … … 347 336 348 337 // build function decl 349 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, functionNesting, layoutFnType );338 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, isInFunction(), layoutFnType ); 350 339 351 340 // calculate struct layout in function body … … 401 390 402 391 // build function decl 403 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, functionNesting, layoutFnType );392 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, isInFunction(), layoutFnType ); 404 393 405 394 // calculate union layout in function body … … 633 622 634 623 void Pass1::replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params ) { 635 for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param) {636 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );624 for ( Expression * const param : params ) { 625 TypeExpr *paramType = dynamic_cast< TypeExpr* >( param ); 637 626 assertf(paramType, "Aggregate parameters should be type expressions"); 638 627 paramType->set_type( replaceWithConcrete( appExpr, paramType->get_type(), false ) ); … … 753 742 754 743 void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 755 for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->parameters.end(); ++param, ++arg ) { 756 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( *param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 757 addCast( *arg, (*param)->get_type(), exprTyVars ); 758 boxParam( (*param)->get_type(), *arg, exprTyVars ); 744 for ( DeclarationWithType * param : function->parameters ) { 745 assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() ); 746 addCast( *arg, param->get_type(), exprTyVars ); 747 boxParam( param->get_type(), *arg, exprTyVars ); 748 ++arg; 759 749 } // for 760 750 } … … 762 752 void Pass1::addInferredParams( ApplicationExpr *appExpr, FunctionType *functionType, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) { 763 753 std::list< Expression *>::iterator cur = arg; 764 for ( Type ::ForallList::iterator tyVar = functionType->get_forall().begin(); tyVar != functionType->get_forall().end(); ++tyVar) {765 for ( std::list< DeclarationWithType *>::iterator assert = (*tyVar)->assertions.begin(); assert != (*tyVar)->assertions.end(); ++assert) {766 InferredParams::const_iterator inferParam = appExpr->inferParams.find( (*assert)->get_uniqueId() );767 assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( *assert ).c_str(), toString( appExpr ).c_str() );754 for ( TypeDecl * const tyVar : functionType->forall ) { 755 for ( DeclarationWithType * const assert : tyVar->assertions ) { 756 InferredParams::const_iterator inferParam = appExpr->inferParams.find( assert->get_uniqueId() ); 757 assertf( inferParam != appExpr->inferParams.end(), "addInferredParams missing inferred parameter: %s in: %s", toString( assert ).c_str(), toString( appExpr ).c_str() ); 768 758 Expression *newExpr = inferParam->second.expr->clone(); 769 addCast( newExpr, (*assert)->get_type(), tyVars );770 boxParam( (*assert)->get_type(), newExpr, tyVars );759 addCast( newExpr, assert->get_type(), tyVars ); 760 boxParam( assert->get_type(), newExpr, tyVars ); 771 761 appExpr->get_args().insert( cur, newExpr ); 772 762 } // for … … 1221 1211 std::list< DeclarationWithType *> ¶mList = functionType->parameters; 1222 1212 std::list< FunctionType *> functions; 1223 for ( 1213 for ( DeclarationWithType * const arg : functionType->parameters ) { 1224 1214 Type *orig = arg->get_type(); 1225 1215 findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter );
Note: See TracChangeset
for help on using the changeset viewer.