Changeset 9236060 for src/GenPoly/Box.cc


Ignore:
Timestamp:
Aug 14, 2017, 2:03:39 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
74b007ba
Parents:
fd344aa (diff), 54cd58b (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' into references

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rfd344aa r9236060  
    2727#include "Box.h"
    2828#include "DeclMutator.h"
     29#include "Lvalue.h"
     30#include "FindFunction.h"
    2931#include "PolyMutator.h"
    30 #include "FindFunction.h"
    3132#include "ScopedSet.h"
    3233#include "ScrubTyVars.h"
     
    204205                };
    205206
    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
     207                /// 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.
    207208                class Pass3 final : public PolyMutator {
    208209                  public:
     
    212213                        using PolyMutator::mutate;
    213214                        virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override;
     215                        virtual Declaration *mutate( StructDecl *structDecl ) override;
     216                        virtual Declaration *mutate( UnionDecl *unionDecl ) override;
    214217                        virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override;
    215218                        virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override;
     
    757760                        assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() );
    758761                        if ( isPolyType( param, exprTyVars ) ) {
    759                                 if ( isPolyType( arg->get_result() ) ) {
     762                                Type * newType = arg->get_result()->clone();
     763                                if ( env ) env->apply( newType );
     764                                std::auto_ptr<Type> manager( newType );
     765                                if ( isPolyType( newType ) ) {
    760766                                        // if the argument's type is polymorphic, we don't need to box again!
    761767                                        return;
    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                                         }
     768                                } else if ( arg->get_result()->get_lvalue() ) {
     769                                        // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations.
     770                                        arg =  generalizedLvalue( new AddressExpr( arg ) );
    771771                                        if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
    772772                                                // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
     
    17601760
    17611761                Expression *PolyGenericCalculator::mutate( SizeofExpr *sizeofExpr ) {
    1762                         Type *ty = sizeofExpr->get_type();
     1762                        Type *ty = sizeofExpr->get_isType() ? sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result();
    17631763                        if ( findGeneric( ty ) ) {
    17641764                                Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) );
     
    17701770
    17711771                Expression *PolyGenericCalculator::mutate( AlignofExpr *alignofExpr ) {
    1772                         Type *ty = alignofExpr->get_type();
     1772                        Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result();
    17731773                        if ( findGeneric( ty ) ) {
    17741774                                Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) );
     
    18801880                }
    18811881
     1882                /// Strips the members from a generic aggregate
     1883                void stripGenericMembers(AggregateDecl* decl) {
     1884                        if ( ! decl->get_parameters().empty() ) decl->get_members().clear();
     1885                }
     1886
     1887                Declaration *Pass3::mutate( StructDecl *structDecl ) {
     1888                        stripGenericMembers( structDecl );
     1889                        return structDecl;
     1890                }
     1891
     1892                Declaration *Pass3::mutate( UnionDecl *unionDecl ) {
     1893                        stripGenericMembers( unionDecl );
     1894                        return unionDecl;
     1895                }
     1896
    18821897                TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
    18831898//   Initializer *init = 0;
Note: See TracChangeset for help on using the changeset viewer.