Changeset def751f for src/AST


Ignore:
Timestamp:
Jul 25, 2022, 3:17:25 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
b0d9ff7
Parents:
4e2befe3 (diff), ffec1bf (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' into qualifiedEnum

Location:
src/AST
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r4e2befe3 rdef751f  
    272272        // Adjust the length of the string for the terminator.
    273273        const Expr * strSize = from_ulong( loc, str.size() + 1 );
    274         const Type * strType = new ArrayType( charType, strSize, FixedLen, StaticDim );
     274        const Type * strType = new ArrayType( charType, strSize, FixedLen, DynamicDim );
    275275        const std::string strValue = "\"" + str + "\"";
    276276        return new ConstantExpr( loc, strType, strValue, std::nullopt );
  • src/AST/Pass.hpp

    r4e2befe3 rdef751f  
    264264        __pass::result1<ast::Stmt> call_accept_as_compound(const ast::Stmt *);
    265265
     266        // requests type environment to be updated (why is it implemented like this?)
     267        __pass::result1<ast::Expr> call_accept_top(const ast::Expr *);
     268
    266269        template< template <class...> class container_t >
    267270        __pass::resultNstmt<container_t> call_accept( const container_t< ptr<Stmt> > & );
     
    277280        template<typename node_t, typename parent_t, typename field_t>
    278281        void maybe_accept_as_compound(const node_t * &, field_t parent_t::* field);
     282
     283        template<typename node_t, typename parent_t, typename field_t>
     284        void maybe_accept_top(const node_t * &, field_t parent_t::* field);
    279285
    280286private:
  • src/AST/Pass.impl.hpp

    r4e2befe3 rdef751f  
    155155                __pedantic_pass_assert( expr );
    156156
    157                 const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
    158                 if ( typeSubs_ptr && expr->env ) {
    159                         *typeSubs_ptr = expr->env;
    160                 }
    161 
    162157                auto nval = expr->accept( *this );
    163158                return { nval != expr, nval };
     
    171166                const ast::Stmt * nval = stmt->accept( *this );
    172167                return { nval != stmt, nval };
     168        }
     169
     170        template< typename core_t >
     171        __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept_top( const ast::Expr * expr ) {
     172                __pedantic_pass_assert( __visit_children() );
     173                __pedantic_pass_assert( expr );
     174
     175                const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
     176                if ( typeSubs_ptr && expr->env ) {
     177                        *typeSubs_ptr = expr->env;
     178                }
     179
     180                auto nval = expr->accept( *this );
     181                return { nval != expr, nval };
    173182        }
    174183
     
    410419
    411420                auto new_val = call_accept( old_val );
     421
     422                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
     423
     424                if( new_val.differs ) {
     425                        auto new_parent = __pass::mutate<core_t>(parent);
     426                        new_val.apply(new_parent, field);
     427                        parent = new_parent;
     428                }
     429        }
     430
     431        template< typename core_t >
     432        template<typename node_t, typename super_t, typename field_t>
     433        void ast::Pass< core_t >::maybe_accept_top(
     434                const node_t * & parent,
     435                field_t super_t::*field
     436        ) {
     437                static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
     438
     439                if(__pass::skip(parent->*field)) return;
     440                const auto & old_val = __pass::get(parent->*field, 0);
     441
     442                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
     443
     444                auto new_val = call_accept_top( old_val );
    412445
    413446                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value /* || std::is_same<int, decltype(old_val)>::value */, "ERROR");
     
    756789
    757790        if ( __visit_children() ) {
    758                 maybe_accept( node, &StaticAssertDecl::cond );
     791                maybe_accept_top( node, &StaticAssertDecl::cond );
    759792                maybe_accept( node, &StaticAssertDecl::msg  );
    760793        }
     
    798831
    799832        if ( __visit_children() ) {
    800                 maybe_accept( node, &ExprStmt::expr );
     833                maybe_accept_top( node, &ExprStmt::expr );
    801834        }
    802835
     
    839872                guard_symtab guard { *this };
    840873                maybe_accept( node, &IfStmt::inits    );
    841                 maybe_accept( node, &IfStmt::cond     );
     874                maybe_accept_top( node, &IfStmt::cond     );
    842875                maybe_accept_as_compound( node, &IfStmt::then );
    843876                maybe_accept_as_compound( node, &IfStmt::else_ );
     
    857890                guard_symtab guard { *this };
    858891                maybe_accept( node, &WhileDoStmt::inits );
    859                 maybe_accept( node, &WhileDoStmt::cond  );
     892                maybe_accept_top( node, &WhileDoStmt::cond  );
    860893                maybe_accept_as_compound( node, &WhileDoStmt::body  );
    861894        }
     
    875908                // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later.
    876909                maybe_accept( node, &ForStmt::inits );
    877                 maybe_accept( node, &ForStmt::cond  );
    878                 maybe_accept( node, &ForStmt::inc   );
     910                maybe_accept_top( node, &ForStmt::cond  );
     911                maybe_accept_top( node, &ForStmt::inc   );
    879912                maybe_accept_as_compound( node, &ForStmt::body  );
    880913        }
     
    890923
    891924        if ( __visit_children() ) {
    892                 maybe_accept( node, &SwitchStmt::cond  );
     925                maybe_accept_top( node, &SwitchStmt::cond  );
    893926                maybe_accept( node, &SwitchStmt::cases );
    894927        }
     
    904937
    905938        if ( __visit_children() ) {
    906                 maybe_accept( node, &CaseClause::cond  );
     939                maybe_accept_top( node, &CaseClause::cond  );
    907940                maybe_accept( node, &CaseClause::stmts );
    908941        }
     
    926959
    927960        if ( __visit_children() ) {
    928                 maybe_accept( node, &ReturnStmt::expr );
     961                maybe_accept_top( node, &ReturnStmt::expr );
    929962        }
    930963
     
    9711004                guard_symtab guard { *this };
    9721005                maybe_accept( node, &CatchClause::decl );
    973                 maybe_accept( node, &CatchClause::cond );
     1006                maybe_accept_top( node, &CatchClause::cond );
    9741007                maybe_accept_as_compound( node, &CatchClause::body );
    9751008        }
     
    20582091
    20592092        if ( __visit_children() ) {
    2060                 maybe_accept( node, &SingleInit::value );
     2093                maybe_accept_top( node, &SingleInit::value );
    20612094        }
    20622095
  • src/AST/SymbolTable.cpp

    r4e2befe3 rdef751f  
    6565
    6666Expr * SymbolTable::IdData::combine( const CodeLocation & loc, ResolvExpr::Cost & cost ) const {
    67         Expr * ret = ( baseExpr ) ?
    68                 (Expr *)new MemberExpr{ loc, id, referenceToRvalueConversion( baseExpr, cost ) } :
    69                 (Expr *)new VariableExpr{ loc, id };
     67        Expr * ret;
     68        if ( baseExpr ) {
     69                if (baseExpr->env) {
     70                        Expr * base = shallowCopy(baseExpr);
     71                        const TypeSubstitution * subs = baseExpr->env;
     72                        base->env = nullptr;
     73                        ret = new MemberExpr{loc, id, referenceToRvalueConversion( base, cost )};
     74                        ret->env = subs;
     75                }
     76                else {
     77                        ret = new MemberExpr{ loc, id, referenceToRvalueConversion( baseExpr, cost ) };
     78                }
     79        }
     80        else {
     81                ret = new VariableExpr{ loc, id };
     82        }
    7083        if ( deleter ) { ret = new DeletedExpr{ loc, ret, deleter }; }
    7184        return ret;
     
    772785                                                && ! dynamic_cast<const UnionInstType *>(rty) ) continue;
    773786                                        ResolvExpr::Cost cost = ResolvExpr::Cost::zero;
     787                                        ast::ptr<ast::TypeSubstitution> tmp = expr->env;
     788                                        expr = mutate_field(expr, &Expr::env, nullptr);
    774789                                        const Expr * base = ResolvExpr::referenceToRvalueConversion( expr, cost );
     790                                        base = mutate_field(base, &Expr::env, tmp);
     791
    775792                                        addMembers(
    776793                                                rty->aggr(), new MemberExpr{ base->location, dwt, base }, handleConflicts );
  • src/AST/TypeSubstitution.cpp

    r4e2befe3 rdef751f  
    9797                TypeSubstitution * newEnv;
    9898                EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
    99                 void previsit( FunctionType * ftype ) {
     99                void previsit( const FunctionType * ftype ) {
    100100                        // transfer known bindings for seen type variables
    101101                        for (auto & formal : ftype->forall) {
Note: See TracChangeset for help on using the changeset viewer.