- Timestamp:
- Dec 11, 2020, 11:20:45 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5b9a0ae
- Parents:
- a6e0e4c
- Location:
- src/AST
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
ra6e0e4c r361bf01 1217 1217 1218 1218 const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) { 1219 ty->forall = get<TypeDecl>().acceptL( old->forall );1220 1219 ty->parameters = get<Expression>().acceptL( old->params ); 1221 1220 ty->hoistType = old->hoistType; … … 2616 2615 2617 2616 void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) { 2618 ty->forall = GET_ACCEPT_V( forall, TypeDecl );2619 2617 ty->params = GET_ACCEPT_V( parameters, Expr ); 2620 2618 ty->hoistType = old->hoistType; -
src/AST/ForallSubstitutor.hpp
ra6e0e4c r361bf01 29 29 30 30 /// Make new forall-list clone 31 ParameterizedType::ForallList operator() ( const ParameterizedType::ForallList & o ) {31 FunctionType::ForallList operator() ( const FunctionType::ForallList & o ) { 32 32 return subs.clone( o, *visitor ); 33 33 } -
src/AST/Pass.hpp
ra6e0e4c r361bf01 287 287 /// Internal RAII guard for forall substitutions 288 288 struct guard_forall_subs { 289 guard_forall_subs( Pass<core_t> & pass, const ParameterizedType * type )289 guard_forall_subs( Pass<core_t> & pass, const FunctionType * type ) 290 290 : pass( pass ), type( type ) { __pass::forall::enter(pass.core, 0, type ); } 291 291 ~guard_forall_subs() { __pass::forall::leave(pass.core, 0, type ); } 292 292 Pass<core_t> & pass; 293 const ParameterizedType * type;293 const FunctionType * type; 294 294 }; 295 295 -
src/AST/Pass.impl.hpp
ra6e0e4c r361bf01 1777 1777 VISIT({ 1778 1778 guard_symtab guard { *this }; 1779 guard_forall_subs forall_guard { *this, node };1780 mutate_forall( node );1781 1779 maybe_accept( node, &StructInstType::params ); 1782 1780 }) … … 1795 1793 VISIT({ 1796 1794 guard_symtab guard { *this }; 1797 guard_forall_subs forall_guard { *this, node };1798 mutate_forall( node );1799 1795 maybe_accept( node, &UnionInstType::params ); 1800 1796 }) … … 1810 1806 1811 1807 VISIT({ 1812 guard_forall_subs forall_guard { *this, node };1813 mutate_forall( node );1814 1808 maybe_accept( node, &EnumInstType::params ); 1815 1809 }) … … 1825 1819 1826 1820 VISIT({ 1827 guard_forall_subs forall_guard { *this, node };1828 mutate_forall( node );1829 1821 maybe_accept( node, &TraitInstType::params ); 1830 1822 }) … … 1841 1833 VISIT( 1842 1834 { 1843 guard_forall_subs forall_guard { *this, node };1844 mutate_forall( node );1845 1835 maybe_accept( node, &TypeInstType::params ); 1846 1836 } -
src/AST/Pass.proto.hpp
ra6e0e4c r361bf01 396 396 // Some simple scoping rules 397 397 template<typename core_t> 398 static inline auto enter( core_t & core, int, const ast:: ParameterizedType * type )398 static inline auto enter( core_t & core, int, const ast::FunctionType * type ) 399 399 -> decltype( core.subs, void() ) { 400 400 if ( ! type->forall.empty() ) core.subs.beginScope(); … … 402 402 403 403 template<typename core_t> 404 static inline auto enter( core_t &, long, const ast:: ParameterizedType * ) {}405 406 template<typename core_t> 407 static inline auto leave( core_t & core, int, const ast:: ParameterizedType * type )404 static inline auto enter( core_t &, long, const ast::FunctionType * ) {} 405 406 template<typename core_t> 407 static inline auto leave( core_t & core, int, const ast::FunctionType * type ) 408 408 -> decltype( core.subs, void() ) { 409 409 if ( ! type->forall.empty() ) { core.subs.endScope(); } … … 411 411 412 412 template<typename core_t> 413 static inline auto leave( core_t &, long, const ast:: ParameterizedType * ) {}413 static inline auto leave( core_t &, long, const ast::FunctionType * ) {} 414 414 415 415 // Get the substitution table, if present -
src/AST/Print.cpp
ra6e0e4c r361bf01 146 146 } 147 147 148 void print( const ast:: ParameterizedType::ForallList & forall ) {148 void print( const ast::FunctionType::ForallList & forall ) { 149 149 if ( forall.empty() ) return; 150 150 os << "forall" << endl; … … 259 259 } 260 260 261 void preprint( const ast:: ParameterizedType * node ) {261 void preprint( const ast::FunctionType * node ) { 262 262 print( node->forall ); 263 263 print( node->qualifiers ); … … 265 265 266 266 void preprint( const ast::BaseInstType * node ) { 267 print( node->forall );268 267 print( node->attributes ); 269 268 print( node->qualifiers ); -
src/AST/Type.cpp
ra6e0e4c r361bf01 94 94 // --- ParameterizedType 95 95 96 void ParameterizedType::initWithSub(97 const ParameterizedType & o, Pass< ForallSubstitutor > & sub96 void FunctionType::initWithSub( 97 const FunctionType & o, Pass< ForallSubstitutor > & sub 98 98 ) { 99 99 forall = sub.core( o.forall ); … … 104 104 105 105 FunctionType::FunctionType( const FunctionType & o ) 106 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), returns(), params(),106 : Type( o.qualifiers, copy( o.attributes ) ), returns(), params(), 107 107 isVarArgs( o.isVarArgs ) { 108 108 Pass< ForallSubstitutor > sub; … … 125 125 } 126 126 127 // --- BaseInstType128 129 void BaseInstType::initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub ) {130 ParameterizedType::initWithSub( o, sub ); // initialize substitution131 params = sub.core( o.params ); // apply to parameters132 }133 134 BaseInstType::BaseInstType( const BaseInstType & o )135 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), params(), name( o.name ),136 hoistType( o.hoistType ) {137 Pass< ForallSubstitutor > sub;138 initWithSub( o, sub );139 }140 141 127 std::vector<readonly<Decl>> BaseInstType::lookup( const std::string& name ) const { 142 128 assertf( aggr(), "Must have aggregate to perform lookup" ); … … 176 162 const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as ) 177 163 : BaseInstType( b->name, q, move(as) ), base( b ) {} 178 179 // --- TypeInstType180 181 TypeInstType::TypeInstType( const TypeInstType & o )182 : BaseInstType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {183 Pass< ForallSubstitutor > sub;184 initWithSub( o, sub ); // initialize substitution185 base = sub.core( o.base ); // apply to base type186 }187 164 188 165 void TypeInstType::set_base( const TypeDecl * b ) { -
src/AST/Type.hpp
ra6e0e4c r361bf01 267 267 }; 268 268 269 /// Base type for potentially forall-qualified types270 class ParameterizedType : public Type {271 protected:272 /// initializes forall with substitutor273 void initWithSub( const ParameterizedType & o, Pass< ForallSubstitutor > & sub );274 public:275 using ForallList = std::vector<ptr<TypeDecl>>;276 277 ForallList forall;278 279 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {},280 std::vector<ptr<Attribute>> && as = {} )281 : Type(q, std::move(as)), forall(std::move(fs)) {}282 283 ParameterizedType( CV::Qualifiers q, std::vector<ptr<Attribute>> && as = {} )284 : Type(q, std::move(as)), forall() {}285 286 // enforce use of ForallSubstitutor to copy parameterized type287 ParameterizedType( const ParameterizedType & ) = delete;288 289 ParameterizedType( ParameterizedType && ) = default;290 291 // no need to change destructor, and operator= deleted in Node292 293 private:294 virtual ParameterizedType * clone() const override = 0;295 MUTATE_FRIEND296 };297 298 269 /// Function variable arguments flag 299 270 enum ArgumentFlag { FixedArgs, VariableArgs }; 300 271 301 272 /// Type of a function `[R1, R2](*)(P1, P2, P3)` 302 class FunctionType final : public ParameterizedType { 303 public: 273 class FunctionType final : public Type { 274 protected: 275 /// initializes forall with substitutor 276 void initWithSub( const FunctionType & o, Pass< ForallSubstitutor > & sub ); 277 public: 278 using ForallList = std::vector<ptr<TypeDecl>>; 279 ForallList forall; 280 304 281 std::vector<ptr<Type>> returns; 305 282 std::vector<ptr<Type>> params; … … 313 290 314 291 FunctionType( ArgumentFlag va = FixedArgs, CV::Qualifiers q = {} ) 315 : ParameterizedType(q), returns(), params(), isVarArgs(va) {}292 : Type(q), returns(), params(), isVarArgs(va) {} 316 293 317 294 FunctionType( const FunctionType & o ); … … 329 306 330 307 /// base class for types that refer to types declared elsewhere (aggregates and typedefs) 331 class BaseInstType : public ParameterizedType { 332 protected: 333 /// Initializes forall and parameters based on substitutor 334 void initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub ); 308 class BaseInstType : public Type { 335 309 public: 336 310 std::vector<ptr<Expr>> params; … … 340 314 BaseInstType( 341 315 const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 342 : ParameterizedType(q, std::move(as)), params(), name(n) {}316 : Type(q, std::move(as)), params(), name(n) {} 343 317 344 318 BaseInstType( 345 319 const std::string& n, std::vector<ptr<Expr>> && params, 346 320 CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 347 : ParameterizedType(q, std::move(as)), params(std::move(params)), name(n) {}348 349 BaseInstType( const BaseInstType & o ) ;321 : Type(q, std::move(as)), params(std::move(params)), name(n) {} 322 323 BaseInstType( const BaseInstType & o ) = default; 350 324 351 325 /// Gets aggregate declaration this type refers to … … 433 407 : BaseInstType( n, q, std::move(as) ), base(), kind( k ) {} 434 408 435 TypeInstType( const TypeInstType & o ) ;409 TypeInstType( const TypeInstType & o ) = default; 436 410 437 411 /// sets `base`, updating `kind` correctly -
src/AST/TypeEnvironment.cpp
ra6e0e4c r361bf01 105 105 } 106 106 107 void TypeEnvironment::add( const ParameterizedType::ForallList & tyDecls ) {107 void TypeEnvironment::add( const FunctionType::ForallList & tyDecls ) { 108 108 for ( const TypeDecl * tyDecl : tyDecls ) { 109 109 env.emplace_back( tyDecl ); -
src/AST/TypeEnvironment.hpp
ra6e0e4c r361bf01 134 134 135 135 /// Add a new equivalence class for each type variable 136 void add( const ParameterizedType::ForallList & tyDecls );136 void add( const FunctionType::ForallList & tyDecls ); 137 137 138 138 /// Add a new equivalence class for each branch of the substitution, checking for conflicts -
src/AST/TypeSubstitution.cpp
ra6e0e4c r361bf01 166 166 } 167 167 168 void TypeSubstitution::Substituter::previsit( const ParameterizedType * ptype ) {168 void TypeSubstitution::Substituter::previsit( const FunctionType * ptype ) { 169 169 GuardValue( boundVars ); 170 170 // bind type variables from forall-qualifiers … … 180 180 // bind type variables from forall-qualifiers 181 181 if ( freeOnly ) { 182 for ( const TypeDecl * tyvar : type->forall ) {183 boundVars.insert( tyvar->name );184 } // for185 182 // bind type variables from generic type instantiations 186 183 if ( auto decl = type->aggr() ) { -
src/AST/TypeSubstitution.hpp
ra6e0e4c r361bf01 167 167 168 168 /// Records type variable bindings from forall-statements 169 void previsit( const ParameterizedType * type );169 void previsit( const FunctionType * type ); 170 170 /// Records type variable bindings from forall-statements and instantiations of generic types 171 171 void handleAggregateType( const BaseInstType * type );
Note: See TracChangeset
for help on using the changeset viewer.