Changeset fc72845d for src/GenPoly
- Timestamp:
- Sep 25, 2017, 6:36:46 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:
- 201182a
- Parents:
- cf90b88
- Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
rcf90b88 rfc72845d 61 61 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars ); 62 62 63 class BoxPass { 64 protected: 65 BoxPass() : scopeTyVars( TypeDecl::Data{} ) {} 66 TyVarMap scopeTyVars; 67 }; 68 63 69 /// Adds layout-generation functions to polymorphic types 64 70 class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting { … … 197 203 198 204 /// 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. 199 class Pass3 final : public PolyMutator { 200 public: 205 struct Pass3 final : public BoxPass, public WithGuards { 201 206 template< typename DeclClass > 202 DeclClass *handleDecl( DeclClass *decl, Type *type ); 203 204 using PolyMutator::mutate; 205 virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override; 206 virtual Declaration *mutate( StructDecl *structDecl ) override; 207 virtual Declaration *mutate( UnionDecl *unionDecl ) override; 208 virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override; 209 virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override; 210 virtual TypeDecl *mutate( TypeDecl *objectDecl ) override; 211 virtual Type *mutate( PointerType *pointerType ) override; 212 virtual Type *mutate( FunctionType *funcType ) override; 213 private: 207 void handleDecl( DeclClass * decl, Type * type ); 208 209 void premutate( ObjectDecl * objectDecl ); 210 void premutate( FunctionDecl * functionDecl ); 211 void premutate( TypedefDecl * typedefDecl ); 212 void premutate( StructDecl * structDecl ); 213 void premutate( UnionDecl * unionDecl ); 214 void premutate( TypeDecl * typeDecl ); 215 void premutate( PointerType * pointerType ); 216 void premutate( FunctionType * funcType ); 214 217 }; 215 218 } // anonymous namespace … … 247 250 Pass2 pass2; 248 251 PassVisitor<PolyGenericCalculator> polyCalculator; 249 Pass 3pass3;252 PassVisitor<Pass3> pass3; 250 253 251 254 acceptAll( translationUnit, layoutBuilder ); … … 253 256 mutateTranslationUnit/*All*/( translationUnit, pass2 ); 254 257 mutateAll( translationUnit, polyCalculator ); 255 mutate TranslationUnit/*All*/( translationUnit, pass3 );258 mutateAll( translationUnit, pass3 ); 256 259 } 257 260 … … 1825 1828 1826 1829 template< typename DeclClass > 1827 DeclClass * Pass3::handleDecl( DeclClass *decl, Type *type ) {1828 scopeTyVars.beginScope();1830 void Pass3::handleDecl( DeclClass * decl, Type * type ) { 1831 GuardScope( scopeTyVars ); 1829 1832 makeTyVarMap( type, scopeTyVars ); 1830 1831 DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );1832 // ScrubTyVars::scrub( decl, scopeTyVars );1833 1833 ScrubTyVars::scrubAll( decl ); 1834 1835 scopeTyVars.endScope(); 1836 return ret; 1837 } 1838 1839 ObjectDecl * Pass3::mutate( ObjectDecl *objectDecl ) { 1840 return handleDecl( objectDecl, objectDecl->get_type() ); 1841 } 1842 1843 DeclarationWithType * Pass3::mutate( FunctionDecl *functionDecl ) { 1844 return handleDecl( functionDecl, functionDecl->get_functionType() ); 1845 } 1846 1847 TypedefDecl * Pass3::mutate( TypedefDecl *typedefDecl ) { 1848 return handleDecl( typedefDecl, typedefDecl->get_base() ); 1834 } 1835 1836 void Pass3::premutate( ObjectDecl * objectDecl ) { 1837 handleDecl( objectDecl, objectDecl->type ); 1838 } 1839 1840 void Pass3::premutate( FunctionDecl * functionDecl ) { 1841 handleDecl( functionDecl, functionDecl->type ); 1842 } 1843 1844 void Pass3::premutate( TypedefDecl * typedefDecl ) { 1845 handleDecl( typedefDecl, typedefDecl->base ); 1849 1846 } 1850 1847 1851 1848 /// Strips the members from a generic aggregate 1852 void stripGenericMembers(AggregateDecl * decl) {1853 if ( ! decl-> get_parameters().empty() ) decl->get_members().clear();1854 } 1855 1856 Declaration *Pass3::mutate( StructDecl *structDecl ) {1849 void stripGenericMembers(AggregateDecl * decl) { 1850 if ( ! decl->parameters.empty() ) decl->members.clear(); 1851 } 1852 1853 void Pass3::premutate( StructDecl * structDecl ) { 1857 1854 stripGenericMembers( structDecl ); 1858 return structDecl; 1859 } 1860 1861 Declaration *Pass3::mutate( UnionDecl *unionDecl ) { 1855 } 1856 1857 void Pass3::premutate( UnionDecl * unionDecl ) { 1862 1858 stripGenericMembers( unionDecl ); 1863 return unionDecl; 1864 } 1865 1866 TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) { 1867 // Initializer *init = 0; 1868 // std::list< Expression *> designators; 1869 // addToTyVarMap( typeDecl, scopeTyVars ); 1870 // if ( typeDecl->get_base() ) { 1871 // init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators ); 1872 // } 1873 // return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init ); 1874 1859 } 1860 1861 void Pass3::premutate( TypeDecl * typeDecl ) { 1875 1862 addToTyVarMap( typeDecl, scopeTyVars ); 1876 return dynamic_cast<TypeDecl*>( Mutator::mutate( typeDecl ) ); 1877 } 1878 1879 Type * Pass3::mutate( PointerType *pointerType ) { 1880 scopeTyVars.beginScope(); 1863 } 1864 1865 void Pass3::premutate( PointerType * pointerType ) { 1866 GuardScope( scopeTyVars ); 1881 1867 makeTyVarMap( pointerType, scopeTyVars ); 1882 1883 Type *ret = Mutator::mutate( pointerType ); 1884 1885 scopeTyVars.endScope(); 1886 return ret; 1887 } 1888 1889 Type * Pass3::mutate( FunctionType *functionType ) { 1890 scopeTyVars.beginScope(); 1868 } 1869 1870 void Pass3::premutate( FunctionType * functionType ) { 1871 GuardScope( scopeTyVars ); 1891 1872 makeTyVarMap( functionType, scopeTyVars ); 1892 1893 Type *ret = Mutator::mutate( functionType );1894 1895 scopeTyVars.endScope();1896 return ret;1897 1873 } 1898 1874 } // anonymous namespace -
src/GenPoly/Specialize.cc
rcf90b88 rfc72845d 29 29 #include "InitTweak/InitTweak.h" // for isIntrinsicCallExpr 30 30 #include "Parser/LinkageSpec.h" // for C 31 #include "PolyMutator.h" // for PolyMutator32 31 #include "ResolvExpr/FindOpenVars.h" // for findOpenVars 33 32 #include "ResolvExpr/TypeEnvironment.h" // for OpenVarSet, AssertionSet
Note: See TracChangeset
for help on using the changeset viewer.