Changeset 46438e4 for src/AST


Ignore:
Timestamp:
Jun 7, 2019, 11:21:07 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
1e6ea4e1
Parents:
866545b (diff), 05d55ff (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/AST
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/AssertAcyclic.cpp

    r866545b r46438e4  
    1010// Created On       : Thu Jun 06 15:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Jun 06 15:00:00 2019
    13 // Update Count     : 0
     12// Last Modified On : Fri Jun 07 14:32:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    2020namespace {
    2121
    22 class NoStrongCyclesCore : public ast::WithGuards {
     22class NoStrongCyclesCore {
    2323    std::vector<const ast::Node *> parents;
    2424public:
    25         void previsit ( const ast::Node * node ) {
    26                 for (auto & p : parents) {
    27                         assert(p != node);
     25        void previsit( const ast::Node * node ) {
     26                for (auto & parent : parents) {
     27                        assert(parent != node);
    2828                }
    2929                parents.push_back(node);
    30                 GuardAction( [this]() { parents.pop_back(); } );
     30        }
     31        void postvisit( const ast::Node * ) {
     32                parents.pop_back();
    3133        }
    3234};
     
    3638namespace ast {
    3739
    38 void assertAcyclic( const std::list< ast::ptr< ast::Decl > > translationUnit ) {
     40void assertAcyclic( const std::list< ast::ptr< ast::Decl > > & translationUnit ) {
    3941        Pass<NoStrongCyclesCore> visitor;
    4042        for ( auto & decl : translationUnit ) {
  • src/AST/AssertAcyclic.hpp

    r866545b r46438e4  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Thr May 6 15:00:00 2019
     10// Created On       : Thr Jun 6 15:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May 6 15:00:00 2019
    13 // Update Count     : 0
     12// Last Modified On : Fri Jun  7 14:32:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    2525namespace ast {
    2626
    27 void assertAcyclic( const std::list< ast::ptr< ast::Decl > > translationUnit );
     27void assertAcyclic( const std::list< ast::ptr< ast::Decl > > & translationUnit );
    2828
    2929}
  • src/AST/Convert.cpp

    r866545b r46438e4  
    1616#include "Convert.hpp"
    1717
     18#include <deque>
    1819#include <unordered_map>
    1920
     
    575576
    576577                if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {
    577                         const ast::InferredParams &srcParams = srcInferred.inferParamsConst();
     578                        const ast::InferredParams &srcParams = srcInferred.inferParams();
    578579                        for (auto srcParam : srcParams) {
    579580                                tgtInferParams[srcParam.first] = ParamEntry(
     
    585586                        }
    586587                } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots  ) {
    587                         const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst();
     588                        const ast::ResnSlots &srcSlots = srcInferred.resnSlots();
    588589                        for (auto srcSlot : srcSlots) {
    589590                                tgtResnSlots.push_back(srcSlot);
     
    735736                expr->var = get<DeclarationWithType>().accept1(node->var);
    736737                Type * type = expr->var->get_type()->clone();
     738                if(FunctionType * ft = dynamic_cast<FunctionType*>(type)) {
     739                        if(node->result.as<ast::PointerType>()) {
     740                                type = new PointerType({}, ft);
     741                        }
     742                }
     743
    737744                type->set_lvalue( true );
    738                 expr->set_result( type );
     745                expr->result = type ;
    739746                this->node = expr;
    740747                return nullptr;
     
    782789                        assert (!rslt->isType);
    783790                }
    784                 if (node->type) {
     791                else {
     792                        assert(node->type);
    785793                        rslt = new SizeofExpr(
    786794                                get<Type>().accept1(node->type)
     
    803811                        assert (!rslt->isType);
    804812                }
    805                 if (node->type) {
     813                else {
     814                        assert(node->type);
    806815                        rslt = new AlignofExpr(
    807816                                get<Type>().accept1(node->type)
     
    14131422#       define GET_ACCEPT_V(child, type) \
    14141423                getAcceptV< ast::type, decltype( old->child ) >( old->child )
     1424       
     1425        template<typename NewT, typename OldC>
     1426        std::deque< ast::ptr<NewT> > getAcceptD( OldC& old ) {
     1427                std::deque< ast::ptr<NewT> > ret;
     1428                for ( auto a : old ) {
     1429                        a->accept( *this );
     1430                        ret.emplace_back( strict_dynamic_cast< NewT * >(node) );
     1431                        node = nullptr;
     1432                }
     1433                return ret;
     1434        }
     1435
     1436#       define GET_ACCEPT_D(child, type) \
     1437                getAcceptD< ast::type, decltype( old->child ) >( old->child )
    14151438
    14161439        ast::Label make_label(Label* old) {
     
    21492172                );
    21502173
    2151                 visitBaseExpr( old,
     2174                visitBaseExpr_SkipResultType( old,
    21522175                        expr
    21532176                );
     
    21552178                expr->var = GET_ACCEPT_1(var, DeclWithType);
    21562179                expr->result = expr->var->get_type();
     2180                if(const ast::FunctionType * ft = expr->result.as<ast::FunctionType>()) {
     2181                        if(dynamic_cast<PointerType *>(old->result)) {
     2182                                expr->result = new ast::PointerType(ft);
     2183                        }
     2184                }
    21572185                add_qualifiers( expr->result, ast::CV::Lvalue );
    21582186                this->node = expr;
     
    24492477
    24502478        virtual void visit( UntypedInitExpr * old ) override final {
    2451                 std::vector<ast::InitAlternative> initAlts;
     2479                std::deque<ast::InitAlternative> initAlts;
    24522480                for (auto ia : old->initAlts) {
    24532481                        initAlts.push_back(ast::InitAlternative(
     
    27142742                this->node = new ast::Designation(
    27152743                        old->location,
    2716                         GET_ACCEPT_V(designators, Expr)
     2744                        GET_ACCEPT_D(designators, Expr)
    27172745                );
    27182746        }
  • src/AST/Expr.cpp

    r866545b r46438e4  
    163163        result = mem->get_type();
    164164        // substitute aggregate generic parameters into member type
    165         genericSubsitution( aggregate->result ).apply( result );
     165        genericSubstitution( aggregate->result ).apply( result );
    166166        // ensure lvalue and appropriate restrictions from aggregate type
    167167        add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue );
  • src/AST/Expr.hpp

    r866545b r46438e4  
    1717
    1818#include <cassert>
     19#include <deque>
    1920#include <map>
    2021#include <string>
     
    111112                }
    112113
    113                 const ResnSlots& resnSlotsConst() const {
     114                const ResnSlots& resnSlots() const {
    114115                        if (mode == Slots) {
    115116                                return data.resnSlots;
     
    128129                }
    129130
    130                 const InferredParams& inferParamsConst() const {
     131                const InferredParams& inferParams() const {
    131132                        if (mode == Params) {
    132133                                return data.inferParams;
     
    134135                        assert(!"Mode was not already Params");
    135136                        return *((InferredParams*)nullptr);
     137                }
     138
     139                /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode
     140                /// and the other is in `Params`.
     141                void splice( InferUnion && o ) {
     142                        if ( o.mode == Empty ) return;
     143                        if ( mode == Empty ) { init_from( o ); return; }
     144                        assert( mode == o.mode && "attempt to splice incompatible InferUnion" );
     145
     146                        if ( mode == Slots ){
     147                                data.resnSlots.insert(
     148                                        data.resnSlots.end(), o.data.resnSlots.begin(), o.data.resnSlots.end() );
     149                        } else if ( mode == Params ) {
     150                                for ( const auto & p : o.data.inferParams ) {
     151                                        data.inferParams[p.first] = std::move(p.second);
     152                                }
     153                        } else assert(!"invalid mode");
    136154                }
    137155        };
     
    695713public:
    696714        ptr<Expr> expr;
    697         std::vector<InitAlternative> initAlts;
    698 
    699         UntypedInitExpr( const CodeLocation & loc, const Expr * e, std::vector<InitAlternative> && as )
     715        std::deque<InitAlternative> initAlts;
     716
     717        UntypedInitExpr( const CodeLocation & loc, const Expr * e, std::deque<InitAlternative> && as )
    700718        : Expr( loc ), expr( e ), initAlts( std::move(as) ) {}
    701719
  • src/AST/GenericSubstitution.cpp

    r866545b r46438e4  
    3131                TypeSubstitution sub;
    3232
    33                 void previsit( const Type * ty ) {
    34                         assertf( false, "Attempted generic substitution for non-aggregate type: %s",
    35                                 toString( ty ).c_str() );
     33                void previsit( const Type * ) {
     34                        // allow empty substitution for non-generic type
     35                        visit_children = false;
    3636                }
    3737
     
    4040                }
    4141
    42                 void previsit( const ReferenceToType * ty ) {
     42        private:
     43                // make substitution for generic type
     44                void makeSub( const ReferenceToType * ty ) {
    4345                        visit_children = false;
    44                         // build substitution from base parameters
    4546                        const AggregateDecl * aggr = ty->aggr();
    4647                        sub = TypeSubstitution{ aggr->params.begin(), aggr->params.end(), ty->params.begin() };
     48                }
     49
     50        public:
     51                void previsit( const StructInstType * ty ) {
     52                        makeSub( ty );
     53                }
     54
     55                void previsit( const UnionInstType * ty ) {
     56                        makeSub( ty );
    4757                }
    4858        };
    4959}
    5060
    51 TypeSubstitution genericSubsitution( const Type * ty ) {
     61TypeSubstitution genericSubstitution( const Type * ty ) {
    5262        Pass<GenericSubstitutionBuilder> builder;
    5363        maybe_accept( ty, builder );
  • src/AST/GenericSubstitution.hpp

    r866545b r46438e4  
    2222class Type;
    2323
    24 TypeSubstitution genericSubsitution( const Type * );
     24TypeSubstitution genericSubstitution( const Type * );
    2525
    2626}
  • src/AST/Init.hpp

    r866545b r46438e4  
    1616#pragma once
    1717
     18#include <deque>
    1819#include <utility>        // for move
    1920#include <vector>
     
    3536class Designation final : public ParseNode {
    3637public:
    37         std::vector<ptr<Expr>> designators;
     38        std::deque<ptr<Expr>> designators;
    3839
    39         Designation( const CodeLocation& loc, std::vector<ptr<Expr>>&& ds = {} )
     40        Designation( const CodeLocation& loc, std::deque<ptr<Expr>>&& ds = {} )
    4041        : ParseNode( loc ), designators( std::move(ds) ) {}
    4142
  • src/AST/Node.hpp

    r866545b r46438e4  
    154154
    155155        template< enum Node::ref_type o_ref_t >
    156         ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.node) {
     156        ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.get()) {
    157157                if( node ) _inc(node);
    158158        }
    159159
    160160        template< enum Node::ref_type o_ref_t >
    161         ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) {
     161        ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.get()) {
    162162                if( node ) _inc(node);
    163163        }
     
    184184        template< enum Node::ref_type o_ref_t >
    185185        ptr_base & operator=( const ptr_base<node_t, o_ref_t> & o ) {
    186                 assign(o.node);
     186                assign(o.get());
    187187                return *this;
    188188        }
     
    190190        template< enum Node::ref_type o_ref_t >
    191191        ptr_base & operator=( ptr_base<node_t, o_ref_t> && o ) {
    192                 assign(o.node);
     192                assign(o.get());
    193193                return *this;
    194194        }
     
    228228        void _check() const;
    229229
    230 protected:
    231230        const node_t * node;
    232231};
  • src/AST/Pass.hpp

    r866545b r46438e4  
    287287                at_cleanup( [func](void *) { func(); }, nullptr );
    288288        }
     289
     290        /// When this node is finished being visited, call a member of an object.
     291        template<typename T>
     292        void GuardMethod( T * obj, void (T::*method)() ) {
     293                at_cleanup( [ method ]( void * object ) {
     294                        static_cast< T * >( object )->method();
     295                }, static_cast< void * >( obj ) );
     296        }
    289297};
    290298
  • src/AST/porting.md

    r866545b r46438e4  
    238238    * also now returns `const AggregateDecl *`
    239239* `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp`
     240  * subsumes old `makeGenericSubstitution()`
    240241
    241242`BasicType`
Note: See TracChangeset for help on using the changeset viewer.