Changeset 9236060 for src/GenPoly


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

Location:
src/GenPoly
Files:
14 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;
  • src/GenPoly/Box.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:24:01 2015
    13 // Update Count     : 5
     12// Last Modified On : Sat Jul 22 09:23:52 2017
     13// Update Count     : 6
    1414//
    1515
    16 #ifndef _BOX_H
    17 #define _BOX_H
     16#pragma once
    1817
    1918#include <list>
     
    2524} // namespace GenPoly
    2625
    27 #endif // _BOX_H
    28 
    2926// Local Variables: //
    3027// tab-width: 4 //
  • src/GenPoly/CopyParams.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:34:25 2015
    13 // Update Count     : 1
     12// Last Modified On : Sat Jul 22 09:23:09 2017
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef _COPYPARAMS_H
    17 #define _COPYPARAMS_H
     16#pragma once
    1817
    1918#include "SynTree/SynTree.h"
     
    2423} // namespace GenPoly
    2524
    26 #endif // _COPYPARAMS_H
    27 
    2825// Local Variables: //
    2926// tab-width: 4 //
  • src/GenPoly/DeclMutator.h

    rfd344aa r9236060  
    1010// Created On       : Fri Nov 27 14:44:00 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 17:39:01 2016
    13 // Update Count     : 2
     12// Last Modified On : Sat Jul 22 09:21:12 2017
     13// Update Count     : 4
    1414//
    1515
    16 #ifndef _DECLMUTATOR_H
    17 #define _DECLMUTATOR_H
     16#pragma once
    1817
    1918#include <list>
     
    2726        /// Mutates a list of declarations, providing a means of adding new declarations into the list
    2827        class DeclMutator : public Mutator {
    29         public:
     28          public:
    3029                typedef Mutator Parent;
    3130
     
    5049                /// Called on exit from a scope; overriders should call this as a super-class call
    5150                virtual void doEndScope();
    52         protected:
     51          protected:
    5352                /// Mutate a statement that forms its own scope
    5453                Statement* mutateStatement( Statement *stmt );
     
    5958                /// Add a declaration to the list to be added after the current position
    6059                void addDeclarationAfter( Declaration* decl );
    61         private:
     60          private:
    6261                /// A stack of declarations to add before the current declaration or statement
    6362                std::vector< std::list< Declaration* > > declsToAdd;
     
    6766} // namespace
    6867
    69 #endif // _DECLMUTATOR_H
    70 
    7168// Local Variables: //
    7269// tab-width: 4 //
  • src/GenPoly/ErasableScopedMap.h

    rfd344aa r9236060  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed Dec 2 11:37:00 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed Dec 2 11:37:00 2015
    13 // Update Count     : 1
    14 //
    15 
    16 #ifndef _ERASABLESCOPEDMAP_H
    17 #define _ERASABLESCOPEDMAP_H
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:23:24 2017
     13// Update Count     : 2
     14//
     15
     16#pragma once
    1817
    1918#include <cassert>
     
    278277} // namespace GenPoly
    279278
    280 #endif // _ERASABLESCOPEDMAP_H
    281 
    282279// Local Variables: //
    283280// tab-width: 4 //
  • src/GenPoly/FindFunction.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:36:35 2015
    13 // Update Count     : 1
     12// Last Modified On : Sat Jul 22 09:23:36 2017
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef FINDFUNCTION_H
    17 #define FINDFUNCTION_H
     16#pragma once
    1817
    1918#include "SynTree/SynTree.h"
     
    2928} // namespace GenPoly
    3029
    31 #endif // FINDFUNCTION_H
    32 
    3330// Local Variables: //
    3431// tab-width: 4 //
  • src/GenPoly/GenPoly.h

    rfd344aa r9236060  
    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 : Tue Nov 24 15:24:38 2015
    13 // Update Count     : 6
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:22:57 2017
     13// Update Count     : 7
    1414//
    1515
    16 #ifndef GENPOLY_H
    17 #define GENPOLY_H
     16#pragma once
    1817
    1918#include <string>
     
    111110} // namespace GenPoly
    112111
    113 #endif // GENPOLY_H
    114 
    115112// Local Variables: //
    116113// tab-width: 4 //
  • src/GenPoly/InstantiateGeneric.h

    rfd344aa r9236060  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu Aug 04 18:33:00 2016
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu Aug 04 18:33:00 2016
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:22:42 2017
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef _INSTANTIATEGENERIC_H
    17 #define _INSTANTIATEGENERIC_H
     16#pragma once
    1817
    1918#include "SynTree/SynTree.h"
     
    2625} // namespace GenPoly
    2726
    28 #endif // _INSTANTIATEGENERIC_H
    29 
    3027// Local Variables: //
    3128// tab-width: 4 //
  • src/GenPoly/Lvalue.cc

    rfd344aa r9236060  
    3030
    3131#include "ResolvExpr/Resolver.h"
     32#include "ResolvExpr/TypeEnvironment.h"
    3233#include "ResolvExpr/typeops.h"
     34#include "ResolvExpr/Unify.h"
    3335
    3436#include "Common/UniqueName.h"
     
    6466
    6567                struct ReferenceConversions final {
    66                         void premutate( AddressExpr * addrExpr );
    67 
    6868                        Expression * postmutate( CastExpr * castExpr );
    6969                        Expression * postmutate( AddressExpr * addrExpr );
     
    8989                struct GeneralizedLvalue final : public WithVisitorRef<GeneralizedLvalue> {
    9090                        Expression * postmutate( AddressExpr * addressExpr );
     91                        Expression * postmutate( MemberExpr * memExpr );
     92
     93                        template<typename Func>
     94                        Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr );
    9195                };
    9296
     
    133137                // from this point forward, no other pass should create reference types.
    134138                referencesEliminated = true;
     139        }
     140
     141        Expression * generalizedLvalue( Expression * expr ) {
     142                PassVisitor<GeneralizedLvalue> genLval;
     143                return expr->acceptMutator( genLval );
    135144        }
    136145
     
    359368                }
    360369
    361                 Expression * GeneralizedLvalue::postmutate( AddressExpr * addrExpr ) {
    362                         if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( addrExpr->get_arg() ) ) {
     370                template<typename Func>
     371                Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) {
     372                        if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) {
    363373                                Expression * arg1 = commaExpr->get_arg1()->clone();
    364374                                Expression * arg2 = commaExpr->get_arg2()->clone();
    365                                 Expression * ret = new CommaExpr( arg1, (new AddressExpr( arg2 ))->acceptMutator( *visitor ) );
    366                                 ret->set_env( addrExpr->get_env() );
    367                                 addrExpr->set_env( nullptr );
    368                                 delete addrExpr;
    369                                 return ret;
    370                         } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( addrExpr->get_arg() ) ) {
     375                                Expression * ret = new CommaExpr( arg1, mkExpr( arg2 )->acceptMutator( *visitor ) );
     376                                ret->set_env( expr->get_env() );
     377                                expr->set_env( nullptr );
     378                                delete expr;
     379                                return ret;
     380                        } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) {
    371381                                Expression * arg1 = condExpr->get_arg1()->clone();
    372382                                Expression * arg2 = condExpr->get_arg2()->clone();
    373383                                Expression * arg3 = condExpr->get_arg3()->clone();
    374                                 Expression * ret = new ConditionalExpr( arg1, (new AddressExpr( arg2 ))->acceptMutator( *visitor ), (new AddressExpr( arg3 ))->acceptMutator( *visitor ) );
    375                                 ret->set_env( addrExpr->get_env() );
    376                                 addrExpr->set_env( nullptr );
    377                                 delete addrExpr;
    378                                 return ret;
    379                         }
    380                         return addrExpr;
     384                                ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 )->acceptMutator( *visitor ), mkExpr( arg3 )->acceptMutator( *visitor ) );
     385                                ret->set_env( expr->get_env() );
     386                                expr->set_env( nullptr );
     387                                delete expr;
     388
     389                                // conditional expr type may not be either of the argument types, need to unify
     390                                using namespace ResolvExpr;
     391                                Type* commonType = nullptr;
     392                                TypeEnvironment newEnv;
     393                                AssertionSet needAssertions, haveAssertions;
     394                                OpenVarSet openVars;
     395                                unify( ret->get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType );
     396                                ret->set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone() );
     397                                return ret;
     398                        }
     399                        return expr;
     400                }
     401
     402                Expression * GeneralizedLvalue::postmutate( MemberExpr * memExpr ) {
     403                        return applyTransformation( memExpr, memExpr->get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } );
     404                }
     405
     406                Expression * GeneralizedLvalue::postmutate( AddressExpr * addrExpr ) {
     407                        return applyTransformation( addrExpr, addrExpr->get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } );
    381408                }
    382409
  • src/GenPoly/Lvalue.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:42:09 2015
    13 // Update Count     : 1
     12// Last Modified On : Sat Jul 22 09:21:59 2017
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef _LVALUE_H
    17 #define _LVALUE_H
     16#pragma once
    1817
    1918#include <list>
     
    2726        /// true after reference types have been eliminated from the source code. After this point, reference types should not be added to the AST.
    2827        bool referencesPermissable();
     28
     29        /// applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b)
     30        Expression * generalizedLvalue( Expression * expr );
    2931} // namespace GenPoly
    30 
    31 #endif // _LVALUE_H
    3232
    3333// Local Variables: //
  • src/GenPoly/PolyMutator.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 17:39:41 2016
    13 // Update Count     : 6
     12// Last Modified On : Sat Jul 22 09:20:31 2017
     13// Update Count     : 7
    1414//
    1515
    16 #ifndef _POLYMUTATOR_H
    17 #define _POLYMUTATOR_H
     16#pragma once
    1817
    1918#include <map>
     
    6665} // namespace
    6766
    68 #endif // _POLYMUTATOR_H
    69 
    7067// Local Variables: //
    7168// tab-width: 4 //
  • src/GenPoly/ScopedSet.h

    rfd344aa r9236060  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu Dec 3 11:51:00 2015
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu Dec 3 11:51:00 2015
    13 // Update Count     : 1
    14 //
    15 
    16 #ifndef _SCOPEDSET_H
    17 #define _SCOPEDSET_H
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:22:17 2017
     13// Update Count     : 2
     14//
     15
     16#pragma once
    1817
    1918#include <iterator>
     
    247246} // namespace GenPoly
    248247
    249 #endif // _SCOPEDSET_H
    250 
    251248// Local Variables: //
    252249// tab-width: 4 //
  • src/GenPoly/ScrubTyVars.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:48:14 2015
    13 // Update Count     : 1
     12// Last Modified On : Sat Jul 22 09:21:47 2017
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef _SCRUBTYVARS_H
    17 #define _SCRUBTYVARS_H
     16#pragma once
    1817
    1918#include <string>
     
    9594} // namespace GenPoly
    9695
    97 #endif // _SCRUBTYVARS_H
    98 
    9996// Local Variables: //
    10097// tab-width: 4 //
  • src/GenPoly/Specialize.h

    rfd344aa r9236060  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:53:58 2015
    13 // Update Count     : 1
     12// Last Modified On : Sat Jul 22 09:22:31 2017
     13// Update Count     : 2
    1414//
    1515
    16 #ifndef _SPECIALIZE_H
    17 #define _SPECIALIZE_H
     16#pragma once
    1817
    1918#include <list>
     
    2625} // namespace GenPoly
    2726
    28 #endif // _SPECIALIZE_H
    29 
    3027// Local Variables: //
    3128// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.