Changeset 7f3b5ce


Ignore:
Timestamp:
Oct 31, 2022, 3:00:06 PM (18 months ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    rcd5b58f r7f3b5ce  
    617617                                maybe_accept( node, &FunctionDecl::returns );
    618618                                maybe_accept( node, &FunctionDecl::type );
     619                                maybe_accept( node, &FunctionDecl::attributes );
    619620                                // First remember that we are now within a function.
    620621                                ValueGuard< bool > oldInFunction( inFunction );
     
    625626                                atFunctionTop = true;
    626627                                maybe_accept( node, &FunctionDecl::stmts );
    627                                 maybe_accept( node, &FunctionDecl::attributes );
    628628                        }
    629629                }
  • src/Common/PassVisitor.impl.h

    rcd5b58f r7f3b5ce  
    607607                        indexerAddId( &func );
    608608                        maybeMutate_impl( node->type, *this );
     609                        maybeMutate_impl( node->attributes, *this );
    609610                        // First remember that we are now within a function.
    610611                        ValueGuard< bool > oldInFunction( inFunction );
     
    615616                        atFunctionTop = true;
    616617                        maybeMutate_impl( node->statements, *this );
    617                         maybeMutate_impl( node->attributes, *this );
    618618                }
    619619        }
  • src/GenPoly/Box.cc

    rcd5b58f r7f3b5ce  
    6868                /// Adds layout-generation functions to polymorphic types.
    6969                class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting {
    70                         // Current level of nested functions:
    71                         unsigned int functionNesting = 0;
    7270                public:
    73                         void previsit( FunctionDecl *functionDecl );
    7471                        void previsit( StructDecl *structDecl );
    7572                        void previsit( UnionDecl *unionDecl );
     
    237234        ////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////////
    238235
    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 
    247236        /// Get a list of type declarations that will affect a layout function
    248237        std::list< TypeDecl* > takeOtypeOnly( std::list< TypeDecl* > &decls ) {
     
    271260
    272261        /// Builds a layout function declaration
    273         FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, unsigned int functionNesting, FunctionType *layoutFnType ) {
     262        FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, bool isInFunction, FunctionType *layoutFnType ) {
    274263                // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
    275264                // because each unit generates copies of the default routines for each aggregate.
    276265                FunctionDecl *layoutDecl = new FunctionDecl( layoutofName( typeDecl ),
    277                                                                                                          functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static ),
     266                                                                                                         isInFunction ? Type::StorageClasses() : Type::StorageClasses( Type::Static ),
    278267                                                                                                         LinkageSpec::AutoGen, layoutFnType, new CompoundStmt(),
    279268                                                                                                         std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) );
     
    347336
    348337                // build function decl
    349                 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, functionNesting, layoutFnType );
     338                FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, isInFunction(), layoutFnType );
    350339
    351340                // calculate struct layout in function body
     
    401390
    402391                // build function decl
    403                 FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, functionNesting, layoutFnType );
     392                FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, isInFunction(), layoutFnType );
    404393
    405394                // calculate union layout in function body
     
    633622
    634623                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 );
    637626                                assertf(paramType, "Aggregate parameters should be type expressions");
    638627                                paramType->set_type( replaceWithConcrete( appExpr, paramType->get_type(), false ) );
     
    753742
    754743                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;
    759749                        } // for
    760750                }
     
    762752                void Pass1::addInferredParams( ApplicationExpr *appExpr, FunctionType *functionType, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) {
    763753                        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() );
    768758                                        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 );
    771761                                        appExpr->get_args().insert( cur, newExpr );
    772762                                } // for
     
    12211211                        std::list< DeclarationWithType *> &paramList = functionType->parameters;
    12221212                        std::list< FunctionType *> functions;
    1223                         for (  DeclarationWithType * const arg : functionType->parameters ) {
     1213                        for ( DeclarationWithType * const arg : functionType->parameters ) {
    12241214                                Type *orig = arg->get_type();
    12251215                                findAndReplaceFunction( orig, functions, scopeTyVars, needsAdapter );
Note: See TracChangeset for help on using the changeset viewer.