Changeset 06d75931 for src/ResolvExpr


Ignore:
Timestamp:
Oct 26, 2024, 8:17:20 AM (3 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
14c31eb
Parents:
3a08cb1 (diff), d031f7f (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/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r3a08cb1 r06d75931  
    21362136}
    21372137
     2138/// If the target enum is a child, get the offset from the base to the target.
     2139static unsigned findChildOffset(
     2140                const ast::EnumDecl * decl, const ast::EnumDecl * target ) {
     2141        unsigned offset = 0;
     2142        for ( auto inlined : decl->inlinedDecl ) {
     2143                auto childDecl = inlined->base;
     2144                if ( childDecl == target ) {
     2145                        return offset;
     2146                }
     2147                offset += childDecl->members.size();
     2148        }
     2149        SemanticError( decl, "Cannot find the target enum." );
     2150}
     2151
    21382152const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src,
    21392153        const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {
     
    21472161                ast::CastExpr * castToDst;
    21482162                if (c<minCost) {
    2149                         unsigned offset = dstDecl->calChildOffset(dstChild.get());
     2163                        unsigned offset = findChildOffset( dstDecl, dstChild.get()->base );
    21502164                        if (offset > 0) {
    21512165                                auto untyped = ast::UntypedExpr::createCall(
    2152                                         expr->location, 
    2153                                         "?+?", 
     2166                                        expr->location,
     2167                                        "?+?",
    21542168                                        { new ast::CastExpr( expr->location,
    21552169                                                expr,
  • src/ResolvExpr/CommonType.cpp

    r3a08cb1 r06d75931  
    636636        void postvisit( const ast::UnionInstType * ) {}
    637637
     638        /// Is the target enum a child of the base enum?
     639        static bool isChildEnum(
     640                        const ast::EnumDecl * decl, const ast::EnumDecl * target ) {
     641                if ( decl == target ) return true;
     642                for ( auto inlined : decl->inlinedDecl ) {
     643                        if ( isChildEnum( inlined->base, target ) ) return true;
     644                }
     645                return false;
     646        }
     647
    638648        void postvisit( const ast::EnumInstType * param ) {
    639649                auto argAsEnumInst = dynamic_cast<const ast::EnumInstType *>(type2);
     
    641651                        const ast::EnumDecl* paramDecl = param->base;
    642652                        const ast::EnumDecl* argDecl = argAsEnumInst->base;
    643                         if (argDecl->isSubTypeOf(paramDecl)) result = param;
     653                        if ( isChildEnum( paramDecl, argDecl ) ) {
     654                                result = param;
     655                        }
    644656                } else if ( param->base && !param->base->isCfa ) {
    645657                        auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt );
  • src/ResolvExpr/CurrentObject.cpp

    r3a08cb1 r06d75931  
    6060        /// Retrieve the list of possible (Type,Designation) pairs for the
    6161        /// current position in the current object.
    62         virtual std::deque< InitAlternative > operator* () const = 0;
     62        virtual std::deque< InitAlternative > getOptions() const = 0;
    6363
    6464        /// True if the iterator is not currently at the end.
     
    7777        virtual const Type * getNext() = 0;
    7878
    79         /// Helper for operator*; aggregates must add designator to each init
    80         /// alternative, but adding designators in operator* creates duplicates.
     79        /// Helper for getOptions; aggregates must add designator to each init
     80        /// alternative, but adding designators in getOptions creates duplicates.
    8181        virtual std::deque< InitAlternative > first() const = 0;
    8282};
     
    103103        }
    104104
    105         std::deque< InitAlternative > operator* () const override { return first(); }
     105        std::deque< InitAlternative > getOptions() const override { return first(); }
    106106
    107107        operator bool() const override { return type; }
     
    169169        }
    170170
    171         std::deque< InitAlternative > operator* () const override { return first(); }
     171        std::deque< InitAlternative > getOptions() const override { return first(); }
    172172
    173173        operator bool() const override { return index < size; }
     
    297297        }
    298298
    299         std::deque< InitAlternative > operator* () const final {
     299        std::deque< InitAlternative > getOptions() const final {
    300300                if ( memberIter && *memberIter ) {
    301301                        std::deque< InitAlternative > ret = memberIter->first();
     
    594594        PRINT( std::cerr << "____getting current options" << std::endl; )
    595595        assertf( ! objStack.empty(), "objstack empty in getOptions" );
    596         return **objStack.back();
     596        return objStack.back()->getOptions();
    597597}
    598598
Note: See TracChangeset for help on using the changeset viewer.