Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    racd7c5dd r83794e1  
    2727#include "Box.h"
    2828#include "DeclMutator.h"
    29 #include "Lvalue.h"
     29#include "PolyMutator.h"
    3030#include "FindFunction.h"
    31 #include "PolyMutator.h"
    3231#include "ScopedSet.h"
    3332#include "ScrubTyVars.h"
     
    5655#include "Common/UniqueName.h"
    5756#include "Common/utility.h"
     57
     58#include "CodeGen/OperatorTable.h"
    5859
    5960#include "InitTweak/InitTweak.h"
     
    203204                };
    204205
    205                 /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, sizeof expressions of polymorphic types with the proper variable, and strips fields from generic struct declarations.
     206                /// 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
    206207                class Pass3 final : public PolyMutator {
    207208                  public:
     
    211212                        using PolyMutator::mutate;
    212213                        virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override;
    213                         virtual Declaration *mutate( StructDecl *structDecl ) override;
    214                         virtual Declaration *mutate( UnionDecl *unionDecl ) override;
    215214                        virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override;
    216215                        virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override;
     
    570569                        // To compound the issue, the right side can be *x, etc. because of lvalue-returning functions
    571570                        if ( UntypedExpr * assign = dynamic_cast< UntypedExpr * >( commaExpr->get_arg1() ) ) {
    572                                 if ( InitTweak::isAssignment( InitTweak::getFunctionName( assign ) ) ) {
     571                                if ( CodeGen::isAssignment( InitTweak::getFunctionName( assign ) ) ) {
    573572                                        assert( assign->get_args().size() == 2 );
    574573                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( assign->get_args().back() ) ) {
     
    610609                                                }
    611610                                        } else {
    612                                                 throw SemanticError( "Cannot pass non-struct type for generic struct" );
     611                                                throw SemanticError( "Cannot pass non-struct type for generic struct: ", argBaseType );
    613612                                        }
    614613                                }
     
    758757                        assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() );
    759758                        if ( isPolyType( param, exprTyVars ) ) {
    760                                 Type * newType = arg->get_result()->clone();
    761                                 if ( env ) env->apply( newType );
    762                                 std::auto_ptr<Type> manager( newType );
    763                                 if ( isPolyType( newType ) ) {
     759                                if ( isPolyType( arg->get_result() ) ) {
    764760                                        // if the argument's type is polymorphic, we don't need to box again!
    765761                                        return;
    766                                 } else if ( arg->get_result()->get_lvalue() ) {
    767                                         // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations.
    768                                         arg =  generalizedLvalue( new AddressExpr( arg ) );
     762                                } else if ( arg->get_result()->get_lvalue() ) {  // xxx - is this still right??
     763                                // xxx - dynamic_cast<ReferenceType *>( arg->get_result() )??
     764                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
     765                                        // xxx - need to test that this code is still reachable
     766                                        if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) {
     767                                                commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) );
     768                                        } else {
     769                                                arg = new AddressExpr( arg );
     770                                        }
    769771                                        if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
    770772                                                // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
     
    10251027                                                } // if
    10261028                                                if ( baseType1 || baseType2 ) {
     1029                                                        delete ret->get_result();
    10271030                                                        ret->set_result( appExpr->get_result()->clone() );
    10281031                                                        if ( appExpr->get_env() ) {
     
    10381041                                                assert( ! appExpr->get_args().empty() );
    10391042                                                if ( isPolyType( appExpr->get_result(), scopeTyVars, env ) ) {
     1043                                                        // remove dereference from polymorphic types since they are boxed.
    10401044                                                        Expression *ret = appExpr->get_args().front();
     1045                                                        // fix expr type to remove pointer
    10411046                                                        delete ret->get_result();
    10421047                                                        ret->set_result( appExpr->get_result()->clone() );
     
    11281133
    11291134                        assert( appExpr->get_function()->has_result() );
    1130                         PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );
    1131                         FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );
     1135                        FunctionType * function = getFunctionType( appExpr->get_function()->get_result() );
     1136                        assertf( function, "ApplicationExpr has non-function type: %s", toString( appExpr->get_function()->get_result() ).c_str() );
    11321137
    11331138                        if ( Expression *newExpr = handleIntrinsics( appExpr ) ) {
     
    12061211                                                        if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
    12071212                                                                assert( appExpr->get_function()->has_result() );
    1208                                                                 PointerType *pointer = safe_dynamic_cast< PointerType *>( appExpr->get_function()->get_result() );
    1209                                                                 FunctionType *function = safe_dynamic_cast< FunctionType *>( pointer->get_base() );
     1213                                                                FunctionType *function = getFunctionType( appExpr->get_function()->get_result() );
     1214                                                                assert( function );
    12101215                                                                needs = needsAdapter( function, scopeTyVars );
    12111216                                                        } // if
     
    12161221                        // isPolyType check needs to happen before mutating addrExpr arg, so pull it forward
    12171222                        // out of the if condition.
     1223                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
     1224                        // ... but must happen after mutate, since argument might change (e.g. intrinsic *?, ?[?]) - re-evaluate above comment
    12181225                        bool polytype = isPolyType( addrExpr->get_arg()->get_result(), scopeTyVars, env );
    1219                         addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    12201226                        if ( polytype || needs ) {
    12211227                                Expression *ret = addrExpr->get_arg();
     
    12841290                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
    12851291                                        std::string adapterName = makeAdapterName( mangleName );
    1286                                         paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0 ) );
     1292                                        // adapter may not be used in body, pass along with unused attribute.
     1293                                        paramList.push_front( new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, 0, new PointerType( Type::Qualifiers(), makeAdapterType( *funType, scopeTyVars ) ), 0, { new Attribute( "unused" ) } ) );
    12871294                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
    12881295                                }
     
    13901397                        std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
    13911398                        std::list< DeclarationWithType *> inferredParams;
    1392                         ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
     1399                        // size/align/offset parameters may not be used in body, pass along with unused attribute.
     1400                        ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0,
     1401                                           { new Attribute( "unused" ) } );
    13931402                        ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0,
    13941403                                           new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
     
    14131422                                for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
    14141423//      *assert = (*assert)->acceptMutator( *this );
     1424                                        // assertion parameters may not be used in body, pass along with unused attribute.
     1425                                        (*assert)->get_attributes().push_back( new Attribute( "unused" ) );
    14151426                                        inferredParams.push_back( *assert );
    14161427                                }
     
    17491760
    17501761                Expression *PolyGenericCalculator::mutate( SizeofExpr *sizeofExpr ) {
    1751                         Type *ty = sizeofExpr->get_isType() ? sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result();
     1762                        Type *ty = sizeofExpr->get_type();
    17521763                        if ( findGeneric( ty ) ) {
    17531764                                Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) );
     
    17591770
    17601771                Expression *PolyGenericCalculator::mutate( AlignofExpr *alignofExpr ) {
    1761                         Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result();
     1772                        Type *ty = alignofExpr->get_type();
    17621773                        if ( findGeneric( ty ) ) {
    17631774                                Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) );
     
    18691880                }
    18701881
    1871                 /// Strips the members from a generic aggregate
    1872                 void stripGenericMembers(AggregateDecl* decl) {
    1873                         if ( ! decl->get_parameters().empty() ) decl->get_members().clear();
    1874                 }
    1875 
    1876                 Declaration *Pass3::mutate( StructDecl *structDecl ) {
    1877                         stripGenericMembers( structDecl );
    1878                         return structDecl;
    1879                 }
    1880 
    1881                 Declaration *Pass3::mutate( UnionDecl *unionDecl ) {
    1882                         stripGenericMembers( unionDecl );
    1883                         return unionDecl;
    1884                 }
    1885 
    18861882                TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
    18871883//   Initializer *init = 0;
Note: See TracChangeset for help on using the changeset viewer.