Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r4864a73 r2a8f0c1  
    2727#include "typeops.h"                     // for extractResultType
    2828#include "Unify.h"                       // for unify
    29 #include "AST/Chain.hpp"
    3029#include "AST/Decl.hpp"
    3130#include "AST/Init.hpp"
     
    408407
    409408        void Resolver_old::previsit( ObjectDecl * objectDecl ) {
    410                 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that
    411                 // class-variable initContext is changed multiple time because the LHS is analysed twice.
    412                 // The second analysis changes initContext because of a function type can contain object
    413                 // declarations in the return and parameter types. So each value of initContext is
     409                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 
     410                // class-variable initContext is changed multiple time because the LHS is analysed twice. 
     411                // The second analysis changes initContext because of a function type can contain object 
     412                // declarations in the return and parameter types. So each value of initContext is 
    414413                // retained, so the type on the first analysis is preserved and used for selecting the RHS.
    415414                GuardValue( currentObject );
     
    448447
    449448        void Resolver_old::postvisit( FunctionDecl * functionDecl ) {
    450                 // default value expressions have an environment which shouldn't be there and trips up
     449                // default value expressions have an environment which shouldn't be there and trips up 
    451450                // later passes.
    452451                // xxx - it might be necessary to somehow keep the information from this environment, but I
     
    940939        ///////////////////////////////////////////////////////////////////////////
    941940
    942         class Resolver_new final
    943         : public ast::WithSymbolTable, public ast::WithGuards,
    944           public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting,
     941        class Resolver_new final 
     942        : public ast::WithSymbolTable, public ast::WithGuards, 
     943          public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting, 
    945944          public ast::WithStmtsToAdd<> {
    946 
     945       
    947946                ast::ptr< ast::Type > functionReturn = nullptr;
    948947                // ast::CurrentObject currentObject = nullptr;
    949948                // bool inEnumDecl = false;
    950949
    951         public:
     950        public: 
    952951                Resolver_new() = default;
    953952                Resolver_new( const ast::SymbolTable & syms ) { symtab = syms; }
     
    992991
    993992        const ast::FunctionDecl * Resolver_new::postvisit( const ast::FunctionDecl * functionDecl ) {
    994                 // default value expressions have an environment which shouldn't be there and trips up
     993                // default value expressions have an environment which shouldn't be there and trips up 
    995994                // later passes.
    996995                ast::ptr< ast::FunctionDecl > ret = functionDecl;
    997996                for ( unsigned i = 0; i < functionDecl->type->params.size(); ++i ) {
    998997                        const ast::ptr<ast::DeclWithType> & d = functionDecl->type->params[i];
    999 
     998                       
    1000999                        if ( const ast::ObjectDecl * obj = d.as< ast::ObjectDecl >() ) {
    10011000                                if ( const ast::SingleInit * init = obj->init.as< ast::SingleInit >() ) {
    10021001                                        if ( init->value->env == nullptr ) continue;
    10031002                                        // clone initializer minus the initializer environment
    1004                                         ast::chain_mutate( ret )
    1005                                                 ( &ast::FunctionDecl::type )
    1006                                                         ( &ast::FunctionType::params )
    1007                                                                 [i]
    1008                                                                 ( &ast::ObjectDecl::init )
    1009                                                                         ( &ast::SingleInit::value )->env = nullptr;
    1010 
    1011                                         assert( functionDecl != ret.get() || functionDecl->unique() );
    1012                                         assert( ! ret->type->params[i].strict_as< ast::ObjectDecl >()->init.strict_as< ast::SingleInit >()->value->env );
     1003                                        strict_dynamic_cast< ast::SingleInit * >(
     1004                                                strict_dynamic_cast< ast::ObjectDecl * >(
     1005                                                        ret.get_and_mutate()->type.get_and_mutate()->params[i].get_and_mutate()
     1006                                                )->init.get_and_mutate()
     1007                                        )->value.get_and_mutate()->env = nullptr;
    10131008                                }
    10141009                        }
Note: See TracChangeset for help on using the changeset viewer.