Changeset 98a8290 for src/AST


Ignore:
Timestamp:
Jun 4, 2019, 2:03:25 PM (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:
1867c96, bc4bea8, de8dfac2
Parents:
0e315a5 (diff), 4ae2364 (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:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r0e315a5 r98a8290  
    102102        ptr<Expr> bitfieldWidth;
    103103
    104         ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, Init * init = nullptr,
    105                 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, Expr * bitWd = nullptr,
    106                 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {})
     104        ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type,
     105                Init * init = nullptr, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
     106                Expr * bitWd = nullptr, std::vector< ptr<Attribute> > && attrs = {},
     107                Function::Specs fs = {} )
    107108        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ),
    108109          init( init ), bitfieldWidth( bitWd ) {}
  • src/AST/Node.hpp

    r0e315a5 r98a8290  
    1010// Created On       : Wed May 8 10:27:04 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 23 16:00:00 2019
    13 // Update Count     : 4
     12// Last Modified On : Mon Jun  3 13:26:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    107107        ptr_base() : node(nullptr) {}
    108108        ptr_base( const node_t * n ) : node(n) { if( node ) _inc(node); }
    109         ~ptr_base() { if( node ) _dec(node); }
     109        ~ptr_base() { if( node ) { auto tmp = node; node = nullptr; _dec(tmp); } }
    110110
    111111        ptr_base( const ptr_base & o ) : node(o.node) {
     
    127127        template<typename o_node_t>
    128128        ptr_base & operator=( const o_node_t * node ) {
    129                 assign( node ? strict_dynamic_cast<const node_t *>(node) : nullptr );
     129                assign( strict_dynamic_cast<const node_t *, nullptr>(node) );
    130130                return *this;
    131131        }
  • src/AST/Type.hpp

    r0e315a5 r98a8290  
    4848
    4949        Type * set_const( bool v ) { qualifiers.is_const = v; return this; }
     50        Type * set_volatile( bool v ) { qualifiers.is_volatile = v; return this; }
    5051        Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; }
    5152        Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; }
  • src/AST/TypeEnvironment.cpp

    r0e315a5 r98a8290  
    4646}
    4747
    48 void print( std::ostream & out, const OpenVarSet & openVars, Indenter indent ) {
     48void print( std::ostream & out, const OpenVarSet & open, Indenter indent ) {
    4949        out << indent;
    5050        bool first = true;
    51         for ( const auto & i : openVars ) {
     51        for ( const auto & i : open ) {
    5252                if ( first ) { first = false; } else { out << ' '; }
    5353                out << i.first << "(" << i.second << ")";
     
    166166
    167167bool TypeEnvironment::combine(
    168                 const TypeEnvironment & o, OpenVarSet & openVars, const SymbolTable & symtab ) {
     168                const TypeEnvironment & o, OpenVarSet & open, const SymbolTable & symtab ) {
    169169        // short-circuit easy cases
    170170        if ( o.empty() ) return true;
     
    189189                        EqvClass & r = *rt;
    190190                        // merge bindings
    191                         if ( ! mergeBound( r, c, openVars, symtab ) ) return false;
     191                        if ( ! mergeBound( r, c, open, symtab ) ) return false;
    192192                        // merge previous unbound variables into this class, checking occurs if needed
    193193                        if ( r.bound ) for ( const auto & u : c.vars ) {
     
    204204                                } else if ( st != rt ) {
    205205                                        // bound, but not to the same class
    206                                         if ( ! mergeClasses( rt, st, openVars, symtab ) ) return false;
     206                                        if ( ! mergeClasses( rt, st, open, symtab ) ) return false;
    207207                                }       // ignore bound into the same class
    208208                        }
     
    216216}
    217217
    218 void TypeEnvironment::extractOpenVars( OpenVarSet & openVars ) const {
     218void TypeEnvironment::extractOpenVars( OpenVarSet & open ) const {
    219219        for ( const auto & clz : env ) {
    220220                for ( const auto & var : clz.vars ) {
    221                         openVars[ var ] = clz.data;
    222                 }
    223         }
    224 }
    225 
    226 void TypeEnvironment::addActual( const TypeEnvironment & actualEnv, OpenVarSet & openVars ) {
     221                        open[ var ] = clz.data;
     222                }
     223        }
     224}
     225
     226void TypeEnvironment::addActual( const TypeEnvironment & actualEnv, OpenVarSet & open ) {
    227227        for ( const auto & clz : actualEnv ) {
    228228                EqvClass c = clz;
    229229                c.allowWidening = false;
    230230                for ( const auto & var : c.vars ) {
    231                         openVars[ var ] = c.data;
     231                        open[ var ] = c.data;
    232232                }
    233233                env.emplace_back( std::move(c) );
     
    268268bool TypeEnvironment::bindVar(
    269269                const TypeInstType * typeInst, const Type * bindTo, const TypeDecl::Data & data,
    270                 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars,
    271                 WidenMode widenMode, const SymbolTable & symtab ) {
     270                AssertionSet & need, AssertionSet & have, const OpenVarSet & open, WidenMode widen,
     271                const SymbolTable & symtab
     272) {
    272273        // remove references from bound type, so that type variables can only bind to value types
    273         bindTo = bindTo->stripReferences();
    274         auto tyvar = openVars.find( typeInst->name );
    275         assert( tyvar != openVars.end() );
    276         if ( ! tyVarCompatible( tyvar->second, bindTo ) ) return false;
    277         if ( occurs( bindTo, typeInst->name, *this ) ) return false;
     274        ptr<Type> target = bindTo->stripReferences();
     275        auto tyvar = open.find( typeInst->name );
     276        assert( tyvar != open.end() );
     277        if ( ! tyVarCompatible( tyvar->second, target ) ) return false;
     278        if ( occurs( target, typeInst->name, *this ) ) return false;
    278279
    279280        auto it = internal_lookup( typeInst->name );
     
    282283                        // attempt to unify equivalence class type with type to bind to.
    283284                        // equivalence class type has stripped qualifiers which must be restored
    284                         const Type * common = nullptr;
     285                        ptr<Type> common;
    285286                        ptr<Type> newType = it->bound;
    286287                        newType.get_and_mutate()->qualifiers = typeInst->qualifiers;
    287288                        if ( unifyInexact(
    288                                         newType, bindTo, *this, need, have, openVars,
    289                                         widenMode & WidenMode{ it->allowWidening, true }, symtab, common ) ) {
     289                                        newType, target, *this, need, have, open,
     290                                        widen & WidenMode{ it->allowWidening, true }, symtab, common ) ) {
    290291                                if ( common ) {
    291                                         it->bound = common;
     292                                        it->bound = std::move(common);
    292293                                        clear_qualifiers( it->bound );
    293294                                }
    294295                        } else return false;
    295296                } else {
    296                         it->bound = bindTo;
     297                        it->bound = std::move(target);
    297298                        clear_qualifiers( it->bound );
    298                         it->allowWidening = widenMode.widenFirst && widenMode.widenSecond;
     299                        it->allowWidening = widen.first && widen.second;
    299300                }
    300301        } else {
    301302                env.emplace_back(
    302                         typeInst->name, bindTo, widenMode.widenFirst && widenMode.widenSecond, data );
     303                        typeInst->name, target, widen.first && widen.second, data );
    303304        }
    304305        return true;
     
    307308bool TypeEnvironment::bindVarToVar(
    308309                const TypeInstType * var1, const TypeInstType * var2, TypeDecl::Data && data,
    309                 AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars,
    310                 WidenMode widenMode, const SymbolTable & symtab ) {
     310                AssertionSet & need, AssertionSet & have, const OpenVarSet & open,
     311                WidenMode widen, const SymbolTable & symtab
     312) {
    311313        auto c1 = internal_lookup( var1->name );
    312314        auto c2 = internal_lookup( var2->name );
     
    314316        // exit early if variables already bound together
    315317        if ( c1 != env.end() && c1 == c2 ) {
    316                 c1->allowWidening &= widenMode;
     318                c1->allowWidening &= widen;
    317319                return true;
    318320        }
     
    327329                        type1 = c1->bound;
    328330                }
    329                 widen1 = widenMode.widenFirst && c1->allowWidening;
     331                widen1 = widen.first && c1->allowWidening;
    330332        }
    331333        if ( c2 != env.end() ) {
     
    334336                        type2 = c2->bound;
    335337                }
    336                 widen2 = widenMode.widenSecond && c2->allowWidening;
     338                widen2 = widen.second && c2->allowWidening;
    337339        }
    338340
     
    341343                ptr<Type> newType1{ type1 }, newType2{ type2 };
    342344                WidenMode newWidenMode{ widen1, widen2 };
    343                 const Type * common = nullptr;
     345                ptr<Type> common;
    344346
    345347                if ( unifyInexact(
    346                                 newType1, newType2, *this, need, have, openVars, newWidenMode, symtab, common ) ) {
     348                                newType1, newType2, *this, need, have, open, newWidenMode, symtab, common ) ) {
    347349                        c1->vars.insert( c2->vars.begin(), c2->vars.end() );
    348350                        c1->allowWidening = widen1 && widen2;
    349351                        if ( common ) {
    350                                 c1->bound = common;
     352                                c1->bound = std::move(common);
    351353                                clear_qualifiers( c1->bound );
    352354                        }
     
    395397
    396398bool TypeEnvironment::mergeBound(
    397                 EqvClass & to, const EqvClass & from, OpenVarSet & openVars, const SymbolTable & symtab ) {
     399                EqvClass & to, const EqvClass & from, OpenVarSet & open, const SymbolTable & symtab ) {
    398400        if ( from.bound ) {
    399401                if ( to.bound ) {
    400402                        // attempt to unify bound types
    401403                        ptr<Type> toType{ to.bound }, fromType{ from.bound };
    402                         WidenMode widenMode{ to.allowWidening, from.allowWidening };
    403                         const Type * common = nullptr;
     404                        WidenMode widen{ to.allowWidening, from.allowWidening };
     405                        ptr<Type> common;
    404406                        AssertionSet need, have;
    405407
    406408                        if ( unifyInexact(
    407                                         toType, fromType, *this, need, have, openVars, widenMode, symtab, common ) ) {
     409                                        toType, fromType, *this, need, have, open, widen, symtab, common ) ) {
    408410                                // unifies, set common type if necessary
    409411                                if ( common ) {
    410                                         to.bound = common;
     412                                        to.bound = std::move(common);
    411413                                        clear_qualifiers( to.bound );
    412414                                }
     
    423425
    424426bool TypeEnvironment::mergeClasses(
    425                 ClassList::iterator to, ClassList::iterator from, OpenVarSet & openVars,
    426                 const SymbolTable & symtab ) {
     427        ClassList::iterator to, ClassList::iterator from, OpenVarSet & open, const SymbolTable & symtab
     428) {
    427429        EqvClass & r = *to, & s = *from;
    428430
    429431        // ensure bounds match
    430         if ( ! mergeBound( r, s, openVars, symtab ) ) return false;
     432        if ( ! mergeBound( r, s, open, symtab ) ) return false;
    431433
    432434        // check safely bindable
  • src/AST/TypeEnvironment.hpp

    r0e315a5 r98a8290  
    178178                const TypeInstType * typeInst, const Type * bindTo, const TypeDecl::Data & data,
    179179                AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars,
    180                 ResolvExpr::WidenMode widenMode, const SymbolTable & symtab );
     180                ResolvExpr::WidenMode widen, const SymbolTable & symtab );
    181181       
    182182        /// Binds the type classes represented by `var1` and `var2` together; will add one or both
     
    185185                const TypeInstType * var1, const TypeInstType * var2, TypeDecl::Data && data,
    186186                AssertionSet & need, AssertionSet & have, const OpenVarSet & openVars,
    187                 ResolvExpr::WidenMode widenMode, const SymbolTable & symtab );
     187                ResolvExpr::WidenMode widen, const SymbolTable & symtab );
    188188
    189189        /// Disallows widening for all bindings in the environment
  • src/AST/TypeSubstitution.cpp

    r0e315a5 r98a8290  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 15:54:35 2017
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jun  3 13:26:00 2017
     13// Update Count     : 5
    1414//
    1515
     
    2626}
    2727
    28 TypeSubstitution::~TypeSubstitution() {
    29         for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
    30                 delete( i->second );
    31         }
    32         for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {
    33                 delete( i->second );
    34         }
    35 }
     28TypeSubstitution::~TypeSubstitution() {}
    3629
    3730TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) {
  • src/AST/porting.md

    r0e315a5 r98a8290  
    291291* moved to be helper function in `TypeEnvironment.cpp` (its only use)
    292292
     293`WidenMode`
     294* changed `widenFirst`, `widenSecond` => `first`, `second`
     295* changed `WidenMode widenMode` => `WidenMode widen`
     296
    293297[1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes
    294298
Note: See TracChangeset for help on using the changeset viewer.