Changeset 9236060 for src/GenPoly
- Timestamp:
- Aug 14, 2017, 2:03:39 PM (7 years ago)
- 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. - Location:
- src/GenPoly
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
rfd344aa r9236060 27 27 #include "Box.h" 28 28 #include "DeclMutator.h" 29 #include "Lvalue.h" 30 #include "FindFunction.h" 29 31 #include "PolyMutator.h" 30 #include "FindFunction.h"31 32 #include "ScopedSet.h" 32 33 #include "ScrubTyVars.h" … … 204 205 }; 205 206 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 variable207 /// 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. 207 208 class Pass3 final : public PolyMutator { 208 209 public: … … 212 213 using PolyMutator::mutate; 213 214 virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override; 215 virtual Declaration *mutate( StructDecl *structDecl ) override; 216 virtual Declaration *mutate( UnionDecl *unionDecl ) override; 214 217 virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override; 215 218 virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override; … … 757 760 assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() ); 758 761 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 ) ) { 760 766 // if the argument's type is polymorphic, we don't need to box again! 761 767 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 ) ); 771 771 if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) { 772 772 // silence warnings by casting boxed parameters when the actual type does not match up with the formal type. … … 1760 1760 1761 1761 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(); 1763 1763 if ( findGeneric( ty ) ) { 1764 1764 Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) ); … … 1770 1770 1771 1771 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(); 1773 1773 if ( findGeneric( ty ) ) { 1774 1774 Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) ); … … 1880 1880 } 1881 1881 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 1882 1897 TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) { 1883 1898 // Initializer *init = 0; -
src/GenPoly/Box.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 17:24:01 201513 // Update Count : 512 // Last Modified On : Sat Jul 22 09:23:52 2017 13 // Update Count : 6 14 14 // 15 15 16 #ifndef _BOX_H 17 #define _BOX_H 16 #pragma once 18 17 19 18 #include <list> … … 25 24 } // namespace GenPoly 26 25 27 #endif // _BOX_H28 29 26 // Local Variables: // 30 27 // tab-width: 4 // -
src/GenPoly/CopyParams.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:34:25 201513 // Update Count : 112 // Last Modified On : Sat Jul 22 09:23:09 2017 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _COPYPARAMS_H 17 #define _COPYPARAMS_H 16 #pragma once 18 17 19 18 #include "SynTree/SynTree.h" … … 24 23 } // namespace GenPoly 25 24 26 #endif // _COPYPARAMS_H27 28 25 // Local Variables: // 29 26 // tab-width: 4 // -
src/GenPoly/DeclMutator.h
rfd344aa r9236060 10 10 // Created On : Fri Nov 27 14:44:00 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 12 17:39:01 201613 // Update Count : 212 // Last Modified On : Sat Jul 22 09:21:12 2017 13 // Update Count : 4 14 14 // 15 15 16 #ifndef _DECLMUTATOR_H 17 #define _DECLMUTATOR_H 16 #pragma once 18 17 19 18 #include <list> … … 27 26 /// Mutates a list of declarations, providing a means of adding new declarations into the list 28 27 class DeclMutator : public Mutator { 29 public:28 public: 30 29 typedef Mutator Parent; 31 30 … … 50 49 /// Called on exit from a scope; overriders should call this as a super-class call 51 50 virtual void doEndScope(); 52 protected:51 protected: 53 52 /// Mutate a statement that forms its own scope 54 53 Statement* mutateStatement( Statement *stmt ); … … 59 58 /// Add a declaration to the list to be added after the current position 60 59 void addDeclarationAfter( Declaration* decl ); 61 private:60 private: 62 61 /// A stack of declarations to add before the current declaration or statement 63 62 std::vector< std::list< Declaration* > > declsToAdd; … … 67 66 } // namespace 68 67 69 #endif // _DECLMUTATOR_H70 71 68 // Local Variables: // 72 69 // tab-width: 4 // -
src/GenPoly/ErasableScopedMap.h
rfd344aa r9236060 9 9 // Author : Aaron B. Moss 10 10 // 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 18 17 19 18 #include <cassert> … … 278 277 } // namespace GenPoly 279 278 280 #endif // _ERASABLESCOPEDMAP_H281 282 279 // Local Variables: // 283 280 // tab-width: 4 // -
src/GenPoly/FindFunction.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:36:35 201513 // Update Count : 112 // Last Modified On : Sat Jul 22 09:23:36 2017 13 // Update Count : 2 14 14 // 15 15 16 #ifndef FINDFUNCTION_H 17 #define FINDFUNCTION_H 16 #pragma once 18 17 19 18 #include "SynTree/SynTree.h" … … 29 28 } // namespace GenPoly 30 29 31 #endif // FINDFUNCTION_H32 33 30 // Local Variables: // 34 31 // tab-width: 4 // -
src/GenPoly/GenPoly.h
rfd344aa r9236060 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Nov 24 15:24:38 201513 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:22:57 2017 13 // Update Count : 7 14 14 // 15 15 16 #ifndef GENPOLY_H 17 #define GENPOLY_H 16 #pragma once 18 17 19 18 #include <string> … … 111 110 } // namespace GenPoly 112 111 113 #endif // GENPOLY_H114 115 112 // Local Variables: // 116 113 // tab-width: 4 // -
src/GenPoly/InstantiateGeneric.h
rfd344aa r9236060 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu Aug 04 18:33:00 2016 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu Aug 04 18:33:00 201613 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:22:42 2017 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _INSTANTIATEGENERIC_H 17 #define _INSTANTIATEGENERIC_H 16 #pragma once 18 17 19 18 #include "SynTree/SynTree.h" … … 26 25 } // namespace GenPoly 27 26 28 #endif // _INSTANTIATEGENERIC_H29 30 27 // Local Variables: // 31 28 // tab-width: 4 // -
src/GenPoly/Lvalue.cc
rfd344aa r9236060 30 30 31 31 #include "ResolvExpr/Resolver.h" 32 #include "ResolvExpr/TypeEnvironment.h" 32 33 #include "ResolvExpr/typeops.h" 34 #include "ResolvExpr/Unify.h" 33 35 34 36 #include "Common/UniqueName.h" … … 64 66 65 67 struct ReferenceConversions final { 66 void premutate( AddressExpr * addrExpr );67 68 68 Expression * postmutate( CastExpr * castExpr ); 69 69 Expression * postmutate( AddressExpr * addrExpr ); … … 89 89 struct GeneralizedLvalue final : public WithVisitorRef<GeneralizedLvalue> { 90 90 Expression * postmutate( AddressExpr * addressExpr ); 91 Expression * postmutate( MemberExpr * memExpr ); 92 93 template<typename Func> 94 Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr ); 91 95 }; 92 96 … … 133 137 // from this point forward, no other pass should create reference types. 134 138 referencesEliminated = true; 139 } 140 141 Expression * generalizedLvalue( Expression * expr ) { 142 PassVisitor<GeneralizedLvalue> genLval; 143 return expr->acceptMutator( genLval ); 135 144 } 136 145 … … 359 368 } 360 369 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 ) ) { 363 373 Expression * arg1 = commaExpr->get_arg1()->clone(); 364 374 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 * >( a ddrExpr->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 ) ) { 371 381 Expression * arg1 = condExpr->get_arg1()->clone(); 372 382 Expression * arg2 = condExpr->get_arg2()->clone(); 373 383 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 ); } ); 381 408 } 382 409 -
src/GenPoly/Lvalue.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:42:09 201513 // Update Count : 112 // Last Modified On : Sat Jul 22 09:21:59 2017 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _LVALUE_H 17 #define _LVALUE_H 16 #pragma once 18 17 19 18 #include <list> … … 27 26 /// true after reference types have been eliminated from the source code. After this point, reference types should not be added to the AST. 28 27 bool referencesPermissable(); 28 29 /// applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b) 30 Expression * generalizedLvalue( Expression * expr ); 29 31 } // namespace GenPoly 30 31 #endif // _LVALUE_H32 32 33 33 // Local Variables: // -
src/GenPoly/PolyMutator.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 12 17:39:41 201613 // Update Count : 612 // Last Modified On : Sat Jul 22 09:20:31 2017 13 // Update Count : 7 14 14 // 15 15 16 #ifndef _POLYMUTATOR_H 17 #define _POLYMUTATOR_H 16 #pragma once 18 17 19 18 #include <map> … … 66 65 } // namespace 67 66 68 #endif // _POLYMUTATOR_H69 70 67 // Local Variables: // 71 68 // tab-width: 4 // -
src/GenPoly/ScopedSet.h
rfd344aa r9236060 9 9 // Author : Aaron B. Moss 10 10 // 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 18 17 19 18 #include <iterator> … … 247 246 } // namespace GenPoly 248 247 249 #endif // _SCOPEDSET_H250 251 248 // Local Variables: // 252 249 // tab-width: 4 // -
src/GenPoly/ScrubTyVars.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:48:14 201513 // Update Count : 112 // Last Modified On : Sat Jul 22 09:21:47 2017 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _SCRUBTYVARS_H 17 #define _SCRUBTYVARS_H 16 #pragma once 18 17 19 18 #include <string> … … 95 94 } // namespace GenPoly 96 95 97 #endif // _SCRUBTYVARS_H98 99 96 // Local Variables: // 100 97 // tab-width: 4 // -
src/GenPoly/Specialize.h
rfd344aa r9236060 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:53:58 201513 // Update Count : 112 // Last Modified On : Sat Jul 22 09:22:31 2017 13 // Update Count : 2 14 14 // 15 15 16 #ifndef _SPECIALIZE_H 17 #define _SPECIALIZE_H 16 #pragma once 18 17 19 18 #include <list> … … 26 25 } // namespace GenPoly 27 26 28 #endif // _SPECIALIZE_H29 30 27 // Local Variables: // 31 28 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.