Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r98735ef rbd85400  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Feb 05 12:23:10 2016
    13 // Update Count     : 280
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Feb  5 16:45:07 2016
     13// Update Count     : 286
    1414//
    1515
     
    549549                                        arg = new AddressExpr( arg );
    550550                                } else {
    551                                         ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, arg->get_results().front()->clone(), 0 );
     551                                        // use type computed in unification to declare boxed variables
     552                                        Type * newType = param->clone();
     553                                        if ( env ) env->apply( newType );
     554                                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, newType, 0 );
    552555                                        newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right???
    553556                                        stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) );
     
    989992                }
    990993
    991                 /// Wraps a function declaration in a new pointer-to-function variable expression
    992                 VariableExpr *wrapFunctionDecl( DeclarationWithType *functionDecl ) {
    993                         // line below cloned from FixFunction.cc
    994                         ObjectDecl *functionObj = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0,
    995                                                                   new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
    996                         functionObj->set_mangleName( functionDecl->get_mangleName() );
    997                         return new VariableExpr( functionObj );
    998                 }
    999                
    1000994                Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
    1001995                        if ( retval && returnStmt->get_expr() ) {
     
    10131007
    10141008                                // find assignment operator for (polymorphic) return type
    1015                                 ApplicationExpr *assignExpr = 0;
     1009                                DeclarationWithType *assignDecl = 0;
    10161010                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() ) ) {
    1017                                         // find assignment operator for type variable
    10181011                                        std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
    10191012                                        if ( assignIter == assignOps.end() ) {
    10201013                                                throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() );
    10211014                                        } // if
    1022                                         assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
     1015                                        assignDecl = assignIter->second;
    10231016                                } else if ( ReferenceToType *refType = dynamic_cast< ReferenceToType *>( retval->get_type() ) ) {
    1024                                         // find assignment operator for generic type
    10251017                                        ScopedMap< std::string, DeclarationWithType *>::const_iterator assignIter = scopedAssignOps.find( refType->get_name() );
    10261018                                        if ( assignIter == scopedAssignOps.end() ) {
    10271019                                                throw SemanticError( "Attempt to return dtype or ftype generic object in ", returnStmt->get_expr() );
    10281020                                        }
    1029 
    1030                                         // wrap it up in an application expression
    10311021                                        DeclarationWithType *functionDecl = assignIter->second;
    1032                                         assignExpr = new ApplicationExpr( wrapFunctionDecl( functionDecl ) );
    1033                                         assignExpr->set_env( env->clone() );
    1034 
    1035                                         // find each of its needed secondary assignment operators
    1036                                         std::list< Expression* > &tyParams = refType->get_parameters();
    1037                                         std::list< TypeDecl* > &forallParams = functionDecl->get_type()->get_forall();
    1038                                         std::list< Expression* >::const_iterator tyIt = tyParams.begin();
    1039                                         std::list< TypeDecl* >::const_iterator forallIt = forallParams.begin();
    1040                                         for ( ; tyIt != tyParams.end() && forallIt != forallParams.end(); ++tyIt, ++forallIt ) {
    1041                                                 if ( (*forallIt)->get_kind() != TypeDecl::Any ) continue; // skip types with no assign op (ftype/dtype)
    1042 
    1043                                                 std::list< DeclarationWithType* > &asserts = (*forallIt)->get_assertions();
    1044                                                 assert( ! asserts.empty() && "Type param needs assignment operator assertion" );
    1045                                                 DeclarationWithType *actualDecl = asserts.front();
    1046                                                 ReferenceToType *actualType = isAssignment( actualDecl );
    1047                                                 assert( actualType && "First assertion of type with assertions should be assignment operator" );
    1048                                                 TypeExpr *formalTypeExpr = dynamic_cast< TypeExpr* >( *tyIt );
    1049                                                 assert( formalTypeExpr && "type parameters must be type expressions" );
    1050                                                 Type *formalType = formalTypeExpr->get_type();
    1051                                                 assignExpr->get_env()->add( actualType->get_name(), formalType );
    1052                                                
    1053                                                 DeclarationWithType *assertAssign = 0;
    1054                                                 if ( TypeInstType *formalTypeInstType = dynamic_cast< TypeInstType* >( formalType ) ) {
    1055                                                         std::map< std::string, DeclarationWithType *>::const_iterator assertAssignIt = assignOps.find( formalTypeInstType->get_name() );
    1056                                                         if ( assertAssignIt == assignOps.end() ) {
    1057                                                                 throw SemanticError( "No assignment operation found for ", formalTypeInstType );
    1058                                                         }
    1059                                                         assertAssign = assertAssignIt->second;
    1060                                                         //assignExpr->get_env()->add( formalTypeInstType->get_name(), actualType );
    1061                                                 } else if ( ReferenceToType *formalReferenceType = dynamic_cast< ReferenceToType* >( formalType ) )  {
    1062                                                         ScopedMap< std::string, DeclarationWithType *>::const_iterator assertAssignIt = scopedAssignOps.find( formalReferenceType->get_name() );
    1063                                                         if ( assertAssignIt == scopedAssignOps.end() ) {
    1064                                                                 throw SemanticError( "No assignment operation found for ", formalReferenceType );
    1065                                                         }
    1066                                                         assertAssign = assertAssignIt->second;
    1067                                                 } else assert( false && "returning polymorphic types with non struct/polymorphic parameters not yet supported" );
    1068                                                
    1069 
    1070                                                 assignExpr->get_inferParams()[ actualDecl->get_uniqueId() ]
    1071                                                         = ParamEntry( assertAssign->get_uniqueId(), assertAssign->get_type()->clone(), actualDecl->get_type()->clone(), wrapFunctionDecl( assertAssign ) );
    1072                                         }
     1022                                        // line below cloned from FixFunction.cc
     1023                                        assignDecl = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0,
     1024                                                                     new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
     1025                                        assignDecl->set_mangleName( functionDecl->get_mangleName() );
    10731026                                }
    1074                                 assert( assignExpr );
     1027                                assert( assignDecl );
    10751028
    10761029                                // replace return statement with appropriate assignment to out parameter
     1030                                ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignDecl ) );
    10771031                                Expression *retParm = new NameExpr( retval->get_name() );
    10781032                                retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
     
    13991353                                delete memberExpr;
    14001354                                return fieldLoc;
    1401                         } else if ( dynamic_cast< UnionInstType* >( objectType ) ) {
     1355                        } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( objectType ) ) {
    14021356                                // union members are all at offset zero, so build appropriately-dereferenced variable
    14031357                                Expression *derefdVar = makeDerefdVar( varExpr->clone(), varDepth );
Note: See TracChangeset for help on using the changeset viewer.