Changeset e7f8119 for src/AST


Ignore:
Timestamp:
Jun 10, 2019, 10:52:03 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
6355ba7
Parents:
9856ca9 (diff), 61c7239 (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:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r9856ca9 re7f8119  
    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);
     
    14211422#       define GET_ACCEPT_V(child, type) \
    14221423                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 )
    14231438
    14241439        ast::Label make_label(Label* old) {
     
    24622477
    24632478        virtual void visit( UntypedInitExpr * old ) override final {
    2464                 std::vector<ast::InitAlternative> initAlts;
     2479                std::deque<ast::InitAlternative> initAlts;
    24652480                for (auto ia : old->initAlts) {
    24662481                        initAlts.push_back(ast::InitAlternative(
     
    27272742                this->node = new ast::Designation(
    27282743                        old->location,
    2729                         GET_ACCEPT_V(designators, Expr)
     2744                        GET_ACCEPT_D(designators, Expr)
    27302745                );
    27312746        }
  • src/AST/Expr.cpp

    r9856ca9 re7f8119  
    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

    r9856ca9 re7f8119  
    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

    r9856ca9 re7f8119  
    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

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

    r9856ca9 re7f8119  
    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

    r9856ca9 re7f8119  
    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/porting.md

    r9856ca9 re7f8119  
    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.