Changeset c8c03683 for src/ResolvExpr


Ignore:
Timestamp:
Jun 14, 2016, 12:53:26 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
7ff30d07
Parents:
e04ef3a (diff), d14d96a (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 plg2:software/cfa/cfa-cc

Location:
src/ResolvExpr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    re04ef3a rc8c03683  
    3939#include "Tuples/NameMatcher.h"
    4040#include "Common/utility.h"
     41#include "InitTweak/InitTweak.h"
    4142
    4243extern bool resolvep;
     
    546547
    547548                {
    548                         NameExpr *fname = 0;;
    549                         if ( ( fname = dynamic_cast<NameExpr *>( untypedExpr->get_function()))
    550                                  && ( fname->get_name() == std::string("&&")) ) {
     549                        std::string fname = InitTweak::getFunctionName( untypedExpr );
     550                        if ( fname == "&&" ) {
    551551                                VoidType v = Type::Qualifiers();                // resolve to type void *
    552552                                PointerType pt( Type::Qualifiers(), v.clone() );
  • src/ResolvExpr/CommonType.cc

    re04ef3a rc8c03683  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // CommonType.cc -- 
     7// CommonType.cc --
    88//
    99// Author           : Richard C. Bilson
     
    134134                                result = new BasicType( basicType->get_qualifiers() + otherBasic->get_qualifiers(), newType );
    135135                        } // if
     136                } else if ( EnumInstType *enumInstType = dynamic_cast< EnumInstType * > ( type2 ) ) {
     137                        // use signed int in lieu of the enum type
     138                        BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ];
     139                        if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= enumInstType->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= enumInstType->get_qualifiers() ) || widenSecond ) ) {
     140                                result = new BasicType( basicType->get_qualifiers() + enumInstType->get_qualifiers(), newType );
     141                        } // if
    136142                } // if
    137143        }
     
    183189        }
    184190
    185         void CommonType::visit( EnumInstType *aggregateUseType ) {
     191        void CommonType::visit( EnumInstType *enumInstType ) {
     192                if ( dynamic_cast< BasicType * >( type2 ) ) {
     193                        // reuse BasicType, EnumInstType code by swapping type2 with enumInstType
     194                        Type * temp = type2;
     195                        type2 = enumInstType;
     196                        temp->accept( *this );
     197                        type2 = temp;
     198                } // if
    186199        }
    187200
  • src/ResolvExpr/ConversionCost.cc

    re04ef3a rc8c03683  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ConversionCost.cc -- 
     7// ConversionCost.cc --
    88//
    99// Author           : Richard C. Bilson
     
    157157                                cost = Cost( 0, 0, tableResult );
    158158                        } // if
    159                 } // if
     159                } else if ( dynamic_cast< EnumInstType *>( dest ) ) {
     160                        // xxx - not positive this is correct, but appears to allow casting int => enum
     161                        cost = Cost( 1, 0, 0 );
     162    } // if
    160163        }
    161164
  • src/ResolvExpr/Resolver.cc

    re04ef3a rc8c03683  
    3838                virtual void visit( ObjectDecl *functionDecl );
    3939                virtual void visit( TypeDecl *typeDecl );
     40                virtual void visit( EnumDecl * enumDecl );
    4041
    4142                virtual void visit( ArrayType * at );
     
    5253                virtual void visit( BranchStmt *branchStmt );
    5354                virtual void visit( ReturnStmt *returnStmt );
     55                virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );
    5456
    5557                virtual void visit( SingleInit *singleInit );
     
    6567                Type *initContext;
    6668                Type *switchType;
     69                bool inEnumDecl = false;
    6770        };
    6871
     
    177180                Type *temp = initContext;
    178181                initContext = new_type;
     182                if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) {
     183                        // enumerator initializers should not use the enum type to initialize, since
     184                        // the enum type is still incomplete at this point. Use signed int instead.
     185                        initContext = new BasicType( Type::Qualifiers(), BasicType::SignedInt );
     186                }
    179187                SymTab::Indexer::visit( objectDecl );
     188                if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) {
     189                        // delete newly created signed int type
     190                        delete initContext;
     191                }
    180192                initContext = temp;
    181193        }
     
    215227                SymTab::Indexer::visit( functionDecl );
    216228                functionReturn = oldFunctionReturn;
     229        }
     230
     231        void Resolver::visit( EnumDecl * enumDecl ) {
     232                // in case we decide to allow nested enums
     233                bool oldInEnumDecl = inEnumDecl;
     234                inEnumDecl = true;
     235                SymTab::Indexer::visit( enumDecl );
     236                inEnumDecl = oldInEnumDecl;
    217237        }
    218238
     
    492512                } catch ( SemanticError ) {
    493513                        // no alternatives for the constructor initializer - fallback on C-style initializer
    494                         // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation?
     514                        // xxx - not sure if this makes a ton of sense - should maybe never be able to have this situation?
    495515                        fallbackInit( ctorInit );
    496516                        return;
     
    513533                }
    514534        }
     535
     536        void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {
     537                // before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).
     538                // Do this through a cast expression to greatly simplify the code.
     539                Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );
     540                assert( callExpr );
     541                Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );
     542                Type * type = 0;
     543
     544                // need to find the type of the first argument, which is unfortunately not uniform since array construction
     545                // includes an untyped '+' expression.
     546                if ( UntypedExpr * plusExpr = dynamic_cast< UntypedExpr * >( constructee ) ) {
     547                        // constructee is <array>+<index>
     548                        // get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed
     549                        Expression * arr = InitTweak::getCallArg( plusExpr, 0 );
     550                        assert( dynamic_cast< VariableExpr * >( arr ) );
     551                        assert( arr && arr->get_results().size() == 1 );
     552                        type = arr->get_results().front()->clone();
     553                } else {
     554                        // otherwise, constructing a plain object, which means the object's address is being taken.
     555                        // Need to get the type of the VariableExpr object, because the AddressExpr is rebuilt and uses the
     556                        // type of the VariableExpr to do so.
     557                        assert( constructee->get_results().size() == 1 );
     558                        AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );
     559                        assert( addrExpr && addrExpr->get_results().size() == 1);
     560                        type = addrExpr->get_results().front()->clone();
     561                }
     562                // cast to T* with qualifiers removed.
     563                // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
     564                // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
     565                // remove lvalue as a qualifier, this can change to
     566                //   type->get_qualifiers() = Type::Qualifiers();
     567                Type * base = InitTweak::getPointerBase( type );
     568                assert( base );
     569                base->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
     570                // if pointer has lvalue qualifier, cast won't appear in output
     571                type->set_isLvalue( false );
     572                constructee = new CastExpr( constructee, type );
     573
     574                // finally, resolve the ctor/dtor
     575                impCtorDtorStmt->get_callStmt()->accept( *this );
     576        }
    515577} // namespace ResolvExpr
    516578
Note: See TracChangeset for help on using the changeset viewer.