Changeset aac5dfd
- Timestamp:
- Dec 12, 2020, 7:30:31 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5d1aa2f
- Parents:
- 6ce9a4f2 (diff), 4803a901 (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. - Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
r6ce9a4f2 raac5dfd 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 8 18:27:22202013 // Update Count : 5 2412 // Last Modified On : Sat Dec 12 13:52:34 2020 13 // Update Count : 536 14 14 // 15 15 … … 49 49 50 50 static inline forall( dtype T | sized(T) ) { 51 // C forallsafe equivalents, i.e., implicit size specification51 // CFA safe equivalents, i.e., implicit size specification 52 52 53 53 T * malloc( void ) { … … 234 234 235 235 static inline forall( dtype T | sized(T) ) { 236 // C forallsafe initialization/copy, i.e., implicit size specification, non-array types236 // CFA safe initialization/copy, i.e., implicit size specification, non-array types 237 237 T * memset( T * dest, char fill ) { 238 238 return (T *)memset( dest, fill, sizeof(T) ); … … 243 243 } // memcpy 244 244 245 // C forallsafe initialization/copy, i.e., implicit size specification, array types245 // CFA safe initialization/copy, i.e., implicit size specification, array types 246 246 T * amemset( T dest[], char fill, size_t dim ) { 247 247 return (T *)(void *)memset( dest, fill, dim * sizeof(T) ); // C memset … … 253 253 } // distribution 254 254 255 // Cforall deallocation for multiple objects 255 // CFA deallocation for multiple objects 256 static inline forall( dtype T ) // FIX ME, problems with 0p in list 257 void free( T * ptr ) { 258 free( (void *)ptr ); // C free 259 } // free 256 260 static inline forall( dtype T, ttype TT | { void free( TT ); } ) 257 void free( T * addr, TT rest ) {258 free( ( void *)addr ); // use C free261 void free( T * ptr, TT rest ) { 262 free( ptr ); 259 263 free( rest ); 260 264 } // free 261 265 262 // C forallallocation/deallocation and constructor/destructor, non-array types266 // CFA allocation/deallocation and constructor/destructor, non-array types 263 267 static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) 264 268 T * new( TT p ) { … … 272 276 ^(*ptr){}; // run destructor 273 277 } // if 274 free( ptr ); 278 free( ptr ); // always call free 275 279 } // delete 276 277 280 static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } ) 278 281 void delete( T * ptr, TT rest ) { … … 281 284 } // delete 282 285 283 // C forallallocation/deallocation and constructor/destructor, array types286 // CFA allocation/deallocation and constructor/destructor, array types 284 287 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p ); 285 288 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] ); -
src/AST/Convert.cpp
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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
r6ce9a4f2 raac5dfd 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 ); -
src/GenPoly/GenPoly.cc
r6ce9a4f2 raac5dfd 567 567 568 568 void makeTyVarMap(const ast::Type * type, TyVarMap & tyVarMap) { 569 if (auto ptype = dynamic_cast<const ast:: ParameterizedType *>(type)) {569 if (auto ptype = dynamic_cast<const ast::FunctionType *>(type)) { 570 570 for (auto & tyVar : ptype->forall) { 571 571 assert (tyVar); -
src/ResolvExpr/CandidateFinder.cpp
r6ce9a4f2 raac5dfd 220 220 221 221 void makeUnifiableVars( 222 const ast:: ParameterizedType * type, ast::OpenVarSet & unifiableVars,222 const ast::FunctionType * type, ast::OpenVarSet & unifiableVars, 223 223 ast::AssertionSet & need 224 224 ) { -
src/ResolvExpr/CastCost.cc
r6ce9a4f2 raac5dfd 165 165 } else { 166 166 ast::TypeEnvironment newEnv{ env }; 167 if ( auto wParams = pointerType->base.as< ast:: ParameterizedType >() ) {167 if ( auto wParams = pointerType->base.as< ast::FunctionType >() ) { 168 168 newEnv.add( wParams->forall ); 169 169 } -
src/ResolvExpr/RenameVars.cc
r6ce9a4f2 raac5dfd 93 93 } 94 94 95 template<typename NodeT> 96 const NodeT * openLevel( const NodeT * type ) { 95 const ast::FunctionType * openLevel( const ast::FunctionType * type ) { 97 96 if ( type->forall.empty() ) return type; 98 97 … … 100 99 101 100 // Load new names from this forall clause and perform renaming. 102 NodeT *mutType = ast::mutate( type );101 auto mutType = ast::mutate( type ); 103 102 assert( type == mutType && "mutated type must be unique from ForallSubstitutor" ); 104 103 for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) { 104 assertf(dynamic_cast<ast::FunctionType *>(mutType), "renaming vars in non-function type"); 105 105 std::ostringstream output; 106 106 output << "_" << resetCount << "_" << level << "_" << td->name; … … 119 119 } 120 120 121 void closeLevel( const ast:: ParameterizedType * type ) {121 void closeLevel( const ast::FunctionType * type ) { 122 122 if ( type->forall.empty() ) return; 123 123 … … 149 149 return renaming.openLevel( type ); 150 150 } 151 152 /* 151 153 const ast::StructInstType * previsit( const ast::StructInstType * type ) { 152 154 return renaming.openLevel( type ); … … 158 160 return renaming.openLevel( type ); 159 161 } 162 */ 163 160 164 const ast::TypeInstType * previsit( const ast::TypeInstType * type ) { 161 return renaming.rename( renaming.openLevel( type ));165 return renaming.rename( type ); 162 166 } 163 void postvisit( const ast:: ParameterizedType * type ) {167 void postvisit( const ast::FunctionType * type ) { 164 168 renaming.closeLevel( type ); 165 169 } -
src/ResolvExpr/Resolver.cc
r6ce9a4f2 raac5dfd 968 968 namespace { 969 969 /// Finds deleted expressions in an expression tree 970 struct DeleteFinder_new final : public ast::WithShortCircuiting {970 struct DeleteFinder_new final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder_new> { 971 971 const ast::DeletedExpr * result = nullptr; 972 972 … … 976 976 } 977 977 978 void previsit( const ast::Expr * ) {978 void previsit( const ast::Expr * expr ) { 979 979 if ( result ) { visit_children = false; } 980 if (expr->inferred.hasParams()) { 981 for (auto & imp : expr->inferred.inferParams() ) { 982 imp.second.expr->accept(*visitor); 983 } 984 } 980 985 } 981 986 }; -
src/ResolvExpr/SatisfyAssertions.cpp
r6ce9a4f2 raac5dfd 194 194 // if we should implement the same rule here 195 195 // (i.e. error if unique best match is deleted) 196 if (candidate->isDeleted ) continue;196 if (candidate->isDeleted && candidate->linkage == ast::Linkage::AutoGen) continue; 197 197 198 198 // build independent unification context for candidate -
src/ResolvExpr/Unify.cc
r6ce9a4f2 raac5dfd 898 898 static void markAssertions( 899 899 ast::AssertionSet & assn1, ast::AssertionSet & assn2, 900 const ast:: ParameterizedType * type900 const ast::FunctionType * type 901 901 ) { 902 902 for ( const auto & tyvar : type->forall ) { -
src/SymTab/Mangler.cc
r6ce9a4f2 raac5dfd 666 666 // skip if not including qualifiers 667 667 if ( typeMode ) return; 668 if ( auto ptype = dynamic_cast< const ast:: ParameterizedType * >(type) ) {668 if ( auto ptype = dynamic_cast< const ast::FunctionType * >(type) ) { 669 669 if ( ! ptype->forall.empty() ) { 670 670 std::list< std::string > assertionNames; -
src/SymTab/Validate.cc
r6ce9a4f2 raac5dfd 1793 1793 static const node_t * forallFixer( 1794 1794 const CodeLocation & loc, const node_t * node, 1795 ast:: ParameterizedType::ForallList parent_t::* forallField1795 ast::FunctionType::ForallList parent_t::* forallField 1796 1796 ) { 1797 1797 for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) {
Note: See TracChangeset
for help on using the changeset viewer.