Ignore:
Timestamp:
Aug 5, 2016, 12:06:29 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, 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:
d9e2280
Parents:
9706554 (diff), a2f920f (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r9706554 r71a3593  
    2424#include "SynTree/Initializer.h"
    2525#include "SymTab/Indexer.h"
     26#include "SymTab/Autogen.h"
    2627#include "Common/utility.h"
    2728#include "InitTweak/InitTweak.h"
     
    4142
    4243                virtual void visit( ArrayType * at );
     44                virtual void visit( PointerType * at );
    4345
    4446                virtual void visit( ExprStmt *exprStmt );
     
    5254                virtual void visit( BranchStmt *branchStmt );
    5355                virtual void visit( ReturnStmt *returnStmt );
    54                 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );
    5556
    5657                virtual void visit( SingleInit *singleInit );
     
    5960          private:
    6061        typedef std::list< Initializer * >::iterator InitIterator;
     62
     63                template< typename PtrType >
     64                void handlePtrType( PtrType * type );
    6165
    6266          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
     
    192196        }
    193197
     198        template< typename PtrType >
     199        void Resolver::handlePtrType( PtrType * type ) {
     200                if ( type->get_dimension() ) {
     201                        CastExpr *castExpr = new CastExpr( type->get_dimension(), SymTab::SizeType->clone() );
     202                        Expression *newExpr = findSingleExpression( castExpr, *this );
     203                        delete type->get_dimension();
     204                        type->set_dimension( newExpr );
     205                }
     206        }
     207
    194208        void Resolver::visit( ArrayType * at ) {
    195                 if ( at->get_dimension() ) {
    196                         BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    197                         CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() );
    198                         Expression *newExpr = findSingleExpression( castExpr, *this );
    199                         delete at->get_dimension();
    200                         at->set_dimension( newExpr );
    201                 }
     209                handlePtrType( at );
    202210                Visitor::visit( at );
     211        }
     212
     213        void Resolver::visit( PointerType * pt ) {
     214                handlePtrType( pt );
     215                Visitor::visit( pt );
    203216        }
    204217
     
    422435
    423436        void Resolver::visit( ListInit * listInit ) {
    424                 InitIterator iter = listInit->begin_initializers();
    425                 InitIterator end = listInit->end_initializers();
     437                InitIterator iter = listInit->begin();
     438                InitIterator end = listInit->end();
    426439
    427440                if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
     
    521534                // implicitly generated, there's no way for it to have side effects, so get rid of it
    522535                // to clean up generated code.
    523                 if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     536                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
    524537                        delete ctorInit->get_ctor();
    525538                        ctorInit->set_ctor( NULL );
    526539                }
    527                 if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     540
     541                // xxx - todo
     542                // if ( InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {
     543                //      // can reduce the constructor down to a SingleInit using the
     544                //      // second argument from the ctor call
     545                // }
     546
     547                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) {
    528548                        delete ctorInit->get_dtor();
    529549                        ctorInit->set_dtor( NULL );
    530550                }
    531         }
    532 
    533         void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {
    534                 // before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).
    535                 // Do this through a cast expression to greatly simplify the code.
    536                 Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );
    537                 assert( callExpr );
    538                 Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );
    539                 Type * type = 0;
    540 
    541                 // need to find the type of the first argument, which is unfortunately not uniform since array construction
    542                 // includes an untyped '+' expression.
    543                 if ( UntypedExpr * plusExpr = dynamic_cast< UntypedExpr * >( constructee ) ) {
    544                         // constructee is <array>+<index>
    545                         // get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed
    546                         Expression * arr = InitTweak::getCallArg( plusExpr, 0 );
    547                         assert( dynamic_cast< VariableExpr * >( arr ) || dynamic_cast< MemberExpr *>( arr ) );
    548                         assert( arr && arr->get_results().size() == 1 );
    549                         type = arr->get_results().front()->clone();
    550                 } else {
    551                         // otherwise, constructing a plain object, which means the object's address is being taken.
    552                         // Need to get the type of the VariableExpr object, because the AddressExpr is rebuilt and uses the
    553                         // type of the VariableExpr to do so.
    554                         assert( constructee->get_results().size() == 1 );
    555                         AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );
    556                         assert( addrExpr && addrExpr->get_results().size() == 1 );
    557                         type = addrExpr->get_results().front()->clone();
    558                 }
    559                 // cast to T* with qualifiers removed.
    560                 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
    561                 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
    562                 // remove lvalue as a qualifier, this can change to
    563                 //   type->get_qualifiers() = Type::Qualifiers();
    564                 Type * base = InitTweak::getPointerBase( type );
    565                 assert( base );
    566                 base->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
    567                 // if pointer has lvalue qualifier, cast won't appear in output
    568                 type->set_isLvalue( false );
    569                 constructee = new CastExpr( constructee, type );
    570 
    571                 // finally, resolve the ctor/dtor
    572                 impCtorDtorStmt->get_callStmt()->accept( *this );
    573551        }
    574552} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.