Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    racd7c5dd r2a7b3ca  
    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"
     
    203202                };
    204203
    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.
     204                /// 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
    206205                class Pass3 final : public PolyMutator {
    207206                  public:
     
    211210                        using PolyMutator::mutate;
    212211                        virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override;
    213                         virtual Declaration *mutate( StructDecl *structDecl ) override;
    214                         virtual Declaration *mutate( UnionDecl *unionDecl ) override;
    215212                        virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override;
    216213                        virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override;
     
    756753
    757754                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    758                         assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() );
     755                        assert( arg->has_result() );
    759756                        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 ) ) {
     757                                if ( isPolyType( arg->get_result() ) ) {
    764758                                        // if the argument's type is polymorphic, we don't need to box again!
    765759                                        return;
    766760                                } 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 ) );
     761                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
     762                                        // xxx - need to test that this code is still reachable
     763                                        if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) {
     764                                                commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) );
     765                                        } else {
     766                                                arg = new AddressExpr( arg );
     767                                        }
    769768                                        if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
    770769                                                // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
     
    17491748
    17501749                Expression *PolyGenericCalculator::mutate( SizeofExpr *sizeofExpr ) {
    1751                         Type *ty = sizeofExpr->get_isType() ? sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result();
     1750                        Type *ty = sizeofExpr->get_type();
    17521751                        if ( findGeneric( ty ) ) {
    17531752                                Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) );
     
    17591758
    17601759                Expression *PolyGenericCalculator::mutate( AlignofExpr *alignofExpr ) {
    1761                         Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result();
     1760                        Type *ty = alignofExpr->get_type();
    17621761                        if ( findGeneric( ty ) ) {
    17631762                                Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) );
     
    18691868                }
    18701869
    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 
    18861870                TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
    18871871//   Initializer *init = 0;
Note: See TracChangeset for help on using the changeset viewer.