Changeset 4389966 for src/GenPoly/Box.cc


Ignore:
Timestamp:
Dec 15, 2015, 4:14:01 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, string, with_gc
Children:
5f6c42c
Parents:
cf16f94 (diff), 78dd0da (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:

fix comment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rcf16f94 r4389966  
    2828#include "Parser/ParseNode.h"
    2929
     30#include "SynTree/Constant.h"
    3031#include "SynTree/Type.h"
    3132#include "SynTree/Expression.h"
     
    5051                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    5152
     53                /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call
    5254                class Pass1 : public PolyMutator {
    5355                  public:
     
    8890                };
    8991
     92                /// Moves polymorphic returns in function types to pointer-type parameters, adds type size and assertion parameters to parameter lists as well
    9093                class Pass2 : public PolyMutator {
    9194                  public:
    92                         Pass2();
    9395                        template< typename DeclClass >
    9496                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    105107                };
    106108
     109                /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, and sizeof expressions of polymorphic types with the proper variable
    107110                class Pass3 : public PolyMutator {
    108111                  public:
     
    178181                }
    179182
    180                 Pass1::Pass1()
    181                         : useRetval( false ), tempNamer( "_temp" ) {
     183                Pass1::Pass1() : useRetval( false ), tempNamer( "_temp" ) {
    182184                        adapters.push(AdapterMap());
    183185                }
     
    312314                                        if ( concrete ) {
    313315                                                arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) );
     316                                                arg++;
     317                                                arg = appExpr->get_args().insert( arg, new AlignofExpr( concrete->clone() ) );
    314318                                                arg++;
    315319                                        } else {
     
    647651                }
    648652
    649                 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, std::string polyName, bool isIncr ) {
     653                Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) {
    650654                        NameExpr *opExpr;
    651655                        if ( isIncr ) {
     
    660664                                addAssign->get_args().push_back( appExpr->get_args().front() );
    661665                        } // if
    662                         addAssign->get_args().push_back( new NameExpr( polyName ) );
     666                        addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) );
    663667                        addAssign->get_results().front() = appExpr->get_results().front()->clone();
    664668                        if ( appExpr->get_env() ) {
     
    687691                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    688692                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    689                                                         multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
     693                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );
    690694                                                        ret->get_args().push_back( appExpr->get_args().front() );
    691695                                                        ret->get_args().push_back( multiply );
     
    693697                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    694698                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    695                                                         multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );
     699                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) );
    696700                                                        ret->get_args().push_back( multiply );
    697701                                                        ret->get_args().push_back( appExpr->get_args().back() );
     
    739743                                                                assignExpr->get_args().push_back( appExpr->get_args().front()->clone() );
    740744                                                        } // if
    741                                                         CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst->get_name(), varExpr->get_var()->get_name() == "?++" ) );
     745                                                        CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "?++" ) );
    742746                                                        return new CommaExpr( firstComma, tempExpr );
    743747                                                } // if
     
    746750                                                assert( appExpr->get_args().size() == 1 );
    747751                                                if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
    748                                                         return makeIncrDecrExpr( appExpr, typeInst->get_name(), varExpr->get_var()->get_name() == "++?" );
     752                                                        return makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "++?" );
    749753                                                } // if
    750754                                        } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
     
    756760                                                        UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
    757761                                                        divide->get_args().push_back( appExpr );
    758                                                         divide->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
     762                                                        divide->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );
    759763                                                        divide->get_results().push_front( appExpr->get_results().front()->clone() );
    760764                                                        if ( appExpr->get_env() ) {
     
    766770                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    767771                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    768                                                         multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
     772                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );
    769773                                                        appExpr->get_args().back() = multiply;
    770774                                                } else if ( typeInst2 ) {
    771775                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    772776                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    773                                                         multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );
     777                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) );
    774778                                                        appExpr->get_args().front() = multiply;
    775779                                                } // if
     
    781785                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    782786                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    783                                                         multiply->get_args().push_back( new NameExpr( typeInst->get_name() ) );
     787                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) );
    784788                                                        appExpr->get_args().back() = multiply;
    785789                                                } // if
     
    963967////////////////////////////////////////// Pass2 ////////////////////////////////////////////////////
    964968
    965                 Pass2::Pass2() {}
    966 
    967969                void Pass2::addAdapters( FunctionType *functionType ) {
    968970                        std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
     
    10371039                        std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
    10381040                        std::list< DeclarationWithType *> inferredParams;
    1039                         ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
    1040 ///   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
     1041                        ObjectDecl newObj( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
     1042//   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
    10411043                        for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    1042                                 ObjectDecl *thisParm;
    1043                                 // add all size parameters to parameter list
     1044                                ObjectDecl *sizeParm, *alignParm;
     1045                                // add all size and alignment parameters to parameter list
    10441046                                if ( (*tyParm)->get_kind() == TypeDecl::Any ) {
    1045                                         thisParm = newObj->clone();
    1046                                         thisParm->set_name( (*tyParm)->get_name() );
    1047                                         last = funcType->get_parameters().insert( last, thisParm );
     1047                                        TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
     1048                                       
     1049                                        sizeParm = newObj.clone();
     1050                                        sizeParm->set_name( sizeofName( &parmType ) );
     1051                                        last = funcType->get_parameters().insert( last, sizeParm );
     1052                                        ++last;
     1053
     1054                                        alignParm = newObj.clone();
     1055                                        alignParm->set_name( alignofName( &parmType ) );
     1056                                        last = funcType->get_parameters().insert( last, alignParm );
    10481057                                        ++last;
    10491058                                }
    10501059                                // move all assertions into parameter list
    10511060                                for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
    1052 ///      *assert = (*assert)->acceptMutator( *this );
     1061//      *assert = (*assert)->acceptMutator( *this );
    10531062                                        inferredParams.push_back( *assert );
    10541063                                }
    10551064                                (*tyParm)->get_assertions().clear();
    10561065                        }
    1057                         delete newObj;
    10581066                        funcType->get_parameters().splice( last, inferredParams );
    10591067                        addAdapters( funcType );
     
    10921100
    10931101                TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
    1094 ///   Initializer *init = 0;
    1095 ///   std::list< Expression *> designators;
    1096 ///   scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
    1097 ///   if ( typeDecl->get_base() ) {
    1098 ///     init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );
    1099 ///   }
    1100 ///   return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );
     1102//   Initializer *init = 0;
     1103//   std::list< Expression *> designators;
     1104//   scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
     1105//   if ( typeDecl->get_base() ) {
     1106//     init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );
     1107//   }
     1108//   return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );
    11011109
    11021110                        scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
     
    11311139                                        assert( typeInst );
    11321140                                        UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
    1133                                         alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) );
     1141                                        alloc->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) );
    11341142
    11351143                                        delete objectDecl->get_init();
Note: See TracChangeset for help on using the changeset viewer.