- Timestamp:
- Sep 19, 2022, 8:11:02 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- aa9f215
- Parents:
- ebf8ca5 (diff), ae1d151 (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/AST
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.hpp
rebf8ca5 r23a08aa0 217 217 218 218 /// convenience accessor to match Type::isComplete() 219 bool isComplete() { return sized; }219 bool isComplete() const { return sized; } 220 220 221 221 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/DeclReplacer.cpp
rebf8ca5 r23a08aa0 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 13:00:00 201913 // Update Count : 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Sep 15 11:55:00 2022 13 // Update Count : 2 14 14 // 15 15 16 16 #include "DeclReplacer.hpp" 17 17 18 #include "Expr.hpp" 19 #include "Pass.hpp" 18 20 #include "Type.hpp" 19 20 #include "Pass.hpp"21 21 22 22 namespace ast { 23 23 24 24 namespace DeclReplacer { 25 namespace {26 struct DeclReplacer {27 private:28 const DeclMap & declMap;29 const TypeMap & typeMap;30 bool debug;31 25 32 public: 33 DeclReplacer(const DeclMap & declMap, const TypeMap & typeMap, bool debug) 34 : declMap( declMap ), typeMap( typeMap ), debug( debug ) 35 {} 26 namespace { 27 struct DeclReplacer { 28 private: 29 const DeclMap & declMap; 30 const TypeMap & typeMap; 31 bool debug; 36 32 37 const ast::VariableExpr * previsit( const ast::VariableExpr * ); 38 const ast::TypeInstType * previsit( const ast::TypeInstType * ); 39 }; 33 public: 34 DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) 35 : declMap( declMap ), typeMap( typeMap ), debug( debug ) 36 {} 40 37 41 struct VarExprReplacer { 42 private: 43 const ExprMap & exprMap; 44 45 public: 46 VarExprReplacer(const ExprMap & exprMap): exprMap (exprMap) {} 38 const ast::VariableExpr * previsit( const ast::VariableExpr * ); 39 const ast::TypeInstType * previsit( const ast::TypeInstType * ); 40 }; 47 41 48 const Expr * postvisit (const VariableExpr *); 49 }; 42 struct VarExprReplacer { 43 private: 44 const ExprMap & exprMap; 45 46 public: 47 VarExprReplacer( const ExprMap & exprMap ) : exprMap( exprMap ) {} 48 49 const Expr * postvisit( const VariableExpr * ); 50 }; 51 } // namespace 52 53 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 54 if(!node) return nullptr; 55 Pass<DeclReplacer> replacer = { declMap, typeMap, debug }; 56 return node->accept( replacer ); 57 } 58 59 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug ) { 60 TypeMap typeMap; 61 return replace( node, declMap, typeMap, debug ); 62 } 63 64 const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) { 65 DeclMap declMap; 66 return replace( node, declMap, typeMap, debug ); 67 } 68 69 const ast::Node * replace( const ast::Node * node, const ExprMap & exprMap ) { 70 Pass<VarExprReplacer> replacer = {exprMap}; 71 return node->accept( replacer ); 72 } 73 74 namespace { 75 // replace variable with new node from decl map 76 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) { 77 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 78 if ( !declMap.count( varExpr->var ) ) return varExpr; 79 80 auto replacement = declMap.at( varExpr->var ); 81 if ( debug ) { 82 std::cerr << "replacing variable reference: " 83 << (void*)varExpr->var.get() << " " << varExpr->var 84 << " with " << (void*)replacement << " " << replacement 85 << std::endl; 86 } 87 auto nexpr = mutate(varExpr); 88 nexpr->var = replacement; 89 return nexpr; 50 90 } 51 91 52 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 53 if(!node) return nullptr; 54 Pass<DeclReplacer> replacer = { declMap, typeMap, debug }; 55 return node->accept( replacer ); 92 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) { 93 if ( !typeMap.count( inst->base ) ) return inst; 94 95 auto replacement = typeMap.at( inst->base ); 96 if ( debug ) { 97 std::cerr << "replacing type reference: " 98 << (void*)inst->base.get() << " " << inst->base 99 << " with " << (void*)replacement << " " << replacement 100 << std::endl; 101 } 102 auto ninst = mutate(inst); 103 ninst->base = replacement; 104 return ninst; 56 105 } 57 106 58 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug) {59 TypeMap typeMap;60 return replace( node, declMap, typeMap, debug);107 const Expr * VarExprReplacer::postvisit( const VariableExpr * expr ) { 108 if ( !exprMap.count( expr->var ) ) return expr; 109 return exprMap.at( expr->var ); 61 110 } 111 } // namespace 62 112 63 const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) { 64 DeclMap declMap; 65 return replace( node, declMap, typeMap, debug ); 66 } 113 } // namespace DeclReplacer 67 114 68 const ast::Node * replace( const ast::Node * node, const ExprMap & exprMap) { 69 Pass<VarExprReplacer> replacer = {exprMap}; 70 return node->accept( replacer ); 71 } 72 73 namespace { 74 // replace variable with new node from decl map 75 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) { 76 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 77 if ( !declMap.count( varExpr->var ) ) return varExpr; 78 79 auto replacement = declMap.at( varExpr->var ); 80 if ( debug ) { 81 std::cerr << "replacing variable reference: " 82 << (void*)varExpr->var.get() << " " << varExpr->var 83 << " with " << (void*)replacement << " " << replacement 84 << std::endl; 85 } 86 auto nexpr = mutate(varExpr); 87 nexpr->var = replacement; 88 return nexpr; 89 } 90 91 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) { 92 if ( !typeMap.count( inst->base ) ) return inst; 93 94 auto replacement = typeMap.at( inst->base ); 95 if ( debug ) { 96 std::cerr << "replacing type reference: " 97 << (void*)inst->base.get() << " " << inst->base 98 << " with " << (void*)replacement << " " << replacement 99 << std::endl; 100 } 101 auto ninst = mutate(inst); 102 ninst->base = replacement; 103 return ninst; 104 } 105 106 const Expr * VarExprReplacer::postvisit( const VariableExpr * expr ) { 107 if (!exprMap.count(expr->var)) return expr; 108 109 return exprMap.at(expr->var); 110 } 111 112 } 113 } 114 115 } 115 } // namespace ast 116 116 117 117 // Local Variables: // -
src/AST/Pass.hpp
rebf8ca5 r23a08aa0 327 327 struct PureVisitor {}; 328 328 329 struct WithCodeLocation { 330 const CodeLocation * location = nullptr; 331 }; 332 329 333 /// Keep track of the polymorphic const TypeSubstitution * typeSubs for the current expression. 330 334 struct WithConstTypeSubstitution { -
src/AST/Pass.impl.hpp
rebf8ca5 r23a08aa0 25 25 #define VISIT_START( node ) \ 26 26 using namespace ast; \ 27 /* back-up the last known code location */ \ 28 __attribute__((unused)) auto loc_guard = ast::__pass::make_location_guard( core, node, 0 ); \ 27 29 /* back-up the visit children */ \ 28 30 __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \ -
src/AST/Pass.proto.hpp
rebf8ca5 r23a08aa0 326 326 } 327 327 328 template< typename core_t, typename node_t > 329 static auto make_location_guard( core_t & core, node_t * node, int ) 330 -> decltype( node->location, ValueGuardPtr<const CodeLocation *>( &core.location ) ) { 331 ValueGuardPtr<const CodeLocation *> guard( &core.location ); 332 core.location = &node->location; 333 return guard; 334 } 335 336 template< typename core_t, typename node_t > 337 static auto make_location_guard( core_t &, node_t *, long ) -> int { 338 return 0; 339 } 340 328 341 // Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement. 329 342 // All passes which have such functions are assumed desire this behaviour -
src/AST/Print.cpp
rebf8ca5 r23a08aa0 33 33 { 34 34 return array<C,sizeof...(T)>{ 35 forward<T>(values)...35 std::forward<T>(values)... 36 36 }; 37 37 } … … 86 86 87 87 static constexpr auto StorageClasses = make_array<const char*>( 88 "extern", "static", "auto", "register", "_ Thread_local"88 "extern", "static", "auto", "register", "__thread", "_Thread_local" 89 89 ); 90 90 … … 215 215 ++indent; 216 216 ptrToEnum->base->accept( *this ); 217 --indent; 217 --indent; 218 218 } 219 219 … … 1623 1623 // if the wrong size is specified 1624 1624 constexpr array<const char*, 3> Printer::Names::FuncSpecifiers; 1625 constexpr array<const char*, 5> Printer::Names::StorageClasses;1625 constexpr array<const char*, 6> Printer::Names::StorageClasses; 1626 1626 constexpr array<const char*, 6> Printer::Names::Qualifiers; 1627 1627 } -
src/AST/StorageClasses.hpp
rebf8ca5 r23a08aa0 24 24 /// Bitflags for storage classes 25 25 enum { 26 Extern = 1 << 0, 27 Static = 1 << 1, 28 Auto = 1 << 2, 29 Register = 1 << 3, 30 ThreadLocal = 1 << 4, 31 NumClasses = 5 26 Extern = 1 << 0, 27 Static = 1 << 1, 28 Auto = 1 << 2, 29 Register = 1 << 3, 30 ThreadLocalGcc = 1 << 4, 31 ThreadLocalC11 = 1 << 5, 32 NumClasses = 6 32 33 }; 33 34 … … 37 38 unsigned int val; 38 39 struct { 39 bool is_extern : 1; 40 bool is_static : 1; 41 bool is_auto : 1; 42 bool is_register : 1; 43 bool is_threadlocal : 1; 40 bool is_extern : 1; 41 bool is_static : 1; 42 bool is_auto : 1; 43 bool is_register : 1; 44 bool is_threadlocalGcc : 1; 45 bool is_threadlocalC11 : 1; 44 46 }; 45 47 … … 48 50 49 51 constexpr class_flags( unsigned int val = 0 ) : val(val) {} 52 53 bool is_threadlocal_any() { return this->is_threadlocalC11 || this->is_threadlocalGcc; } 50 54 }; 51 55 -
src/AST/Type.cpp
rebf8ca5 r23a08aa0 143 143 TraitInstType::TraitInstType( 144 144 const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as ) 145 : BaseInstType( b->name, q, move(as) ), base( b ) {}145 : BaseInstType( b->name, q, std::move(as) ), base( b ) {} 146 146 147 147 // --- TypeInstType … … 149 149 TypeInstType::TypeInstType( const TypeDecl * b, 150 150 CV::Qualifiers q, std::vector<ptr<Attribute>> && as ) 151 : BaseInstType( b->name, q, move(as) ), base( b ), kind( b->kind ) {}151 : BaseInstType( b->name, q, std::move(as) ), base( b ), kind( b->kind ) {} 152 152 153 153 void TypeInstType::set_base( const TypeDecl * b ) { … … 161 161 162 162 TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q ) 163 : Type( q ), types( move(ts) ), members() {163 : Type( q ), types( std::move(ts) ), members() { 164 164 // This constructor is awkward. `TupleType` needs to contain objects so that members can be 165 165 // named, but members without initializer nodes end up getting constructors, which breaks -
src/AST/Type.hpp
rebf8ca5 r23a08aa0 83 83 template< enum Node::ref_type ref_t > 84 84 void reset_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q = {} ) { 85 if ( p->qualifiers .val != q.val) p.get_and_mutate()->qualifiers = q;85 if ( p->qualifiers != q ) p.get_and_mutate()->qualifiers = q; 86 86 } 87 87 … … 89 89 template< enum Node::ref_type ref_t > 90 90 void add_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 91 if ( ( p->qualifiers .val & q.val ) != q.val) p.get_and_mutate()->qualifiers |= q;91 if ( ( p->qualifiers & q ) != q ) p.get_and_mutate()->qualifiers |= q; 92 92 } 93 93 … … 95 95 template< enum Node::ref_type ref_t > 96 96 void remove_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 97 if ( ( p->qualifiers .val & q.val) != 0 ) p.get_and_mutate()->qualifiers -= q;97 if ( ( p->qualifiers & q ) != 0 ) p.get_and_mutate()->qualifiers -= q; 98 98 } 99 99 … … 412 412 std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; } 413 413 bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; } 414 415 414 }; 416 415
Note:
See TracChangeset
for help on using the changeset viewer.