- Timestamp:
- Jun 7, 2019, 11:21:07 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1e6ea4e1
- Parents:
- 866545b (diff), 05d55ff (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:
-
- 11 edited
-
AssertAcyclic.cpp (modified) (3 diffs)
-
AssertAcyclic.hpp (modified) (2 diffs)
-
Convert.cpp (modified) (11 diffs)
-
Expr.cpp (modified) (1 diff)
-
Expr.hpp (modified) (5 diffs)
-
GenericSubstitution.cpp (modified) (2 diffs)
-
GenericSubstitution.hpp (modified) (1 diff)
-
Init.hpp (modified) (2 diffs)
-
Node.hpp (modified) (4 diffs)
-
Pass.hpp (modified) (1 diff)
-
porting.md (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/AssertAcyclic.cpp
r866545b r46438e4 10 10 // Created On : Thu Jun 06 15:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 06 15:00:00 201913 // Update Count : 012 // Last Modified On : Fri Jun 07 14:32:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 20 20 namespace { 21 21 22 class NoStrongCyclesCore : public ast::WithGuards{22 class NoStrongCyclesCore { 23 23 std::vector<const ast::Node *> parents; 24 24 public: 25 void previsit ( const ast::Node * node ) {26 for (auto & p : parents) {27 assert(p != node);25 void previsit( const ast::Node * node ) { 26 for (auto & parent : parents) { 27 assert(parent != node); 28 28 } 29 29 parents.push_back(node); 30 GuardAction( [this]() { parents.pop_back(); } ); 30 } 31 void postvisit( const ast::Node * ) { 32 parents.pop_back(); 31 33 } 32 34 }; … … 36 38 namespace ast { 37 39 38 void assertAcyclic( const std::list< ast::ptr< ast::Decl > > translationUnit ) {40 void assertAcyclic( const std::list< ast::ptr< ast::Decl > > & translationUnit ) { 39 41 Pass<NoStrongCyclesCore> visitor; 40 42 for ( auto & decl : translationUnit ) { -
src/AST/AssertAcyclic.hpp
r866545b r46438e4 8 8 // 9 9 // Author : Andrew Beach 10 // Created On : Thr May6 15:00:00 201910 // Created On : Thr Jun 6 15:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 6 15:00:00 201913 // Update Count : 012 // Last Modified On : Fri Jun 7 14:32:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 25 25 namespace ast { 26 26 27 void assertAcyclic( const std::list< ast::ptr< ast::Decl > > translationUnit );27 void assertAcyclic( const std::list< ast::ptr< ast::Decl > > & translationUnit ); 28 28 29 29 } -
src/AST/Convert.cpp
r866545b r46438e4 16 16 #include "Convert.hpp" 17 17 18 #include <deque> 18 19 #include <unordered_map> 19 20 … … 575 576 576 577 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) { 577 const ast::InferredParams &srcParams = srcInferred.inferParams Const();578 const ast::InferredParams &srcParams = srcInferred.inferParams(); 578 579 for (auto srcParam : srcParams) { 579 580 tgtInferParams[srcParam.first] = ParamEntry( … … 585 586 } 586 587 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots ) { 587 const ast::ResnSlots &srcSlots = srcInferred.resnSlots Const();588 const ast::ResnSlots &srcSlots = srcInferred.resnSlots(); 588 589 for (auto srcSlot : srcSlots) { 589 590 tgtResnSlots.push_back(srcSlot); … … 735 736 expr->var = get<DeclarationWithType>().accept1(node->var); 736 737 Type * type = expr->var->get_type()->clone(); 738 if(FunctionType * ft = dynamic_cast<FunctionType*>(type)) { 739 if(node->result.as<ast::PointerType>()) { 740 type = new PointerType({}, ft); 741 } 742 } 743 737 744 type->set_lvalue( true ); 738 expr-> set_result( type );745 expr->result = type ; 739 746 this->node = expr; 740 747 return nullptr; … … 782 789 assert (!rslt->isType); 783 790 } 784 if (node->type) { 791 else { 792 assert(node->type); 785 793 rslt = new SizeofExpr( 786 794 get<Type>().accept1(node->type) … … 803 811 assert (!rslt->isType); 804 812 } 805 if (node->type) { 813 else { 814 assert(node->type); 806 815 rslt = new AlignofExpr( 807 816 get<Type>().accept1(node->type) … … 1413 1422 # define GET_ACCEPT_V(child, type) \ 1414 1423 getAcceptV< ast::type, decltype( old->child ) >( old->child ) 1424 1425 template<typename NewT, typename OldC> 1426 std::deque< ast::ptr<NewT> > getAcceptD( OldC& old ) { 1427 std::deque< ast::ptr<NewT> > ret; 1428 for ( auto a : old ) { 1429 a->accept( *this ); 1430 ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); 1431 node = nullptr; 1432 } 1433 return ret; 1434 } 1435 1436 # define GET_ACCEPT_D(child, type) \ 1437 getAcceptD< ast::type, decltype( old->child ) >( old->child ) 1415 1438 1416 1439 ast::Label make_label(Label* old) { … … 2149 2172 ); 2150 2173 2151 visitBaseExpr ( old,2174 visitBaseExpr_SkipResultType( old, 2152 2175 expr 2153 2176 ); … … 2155 2178 expr->var = GET_ACCEPT_1(var, DeclWithType); 2156 2179 expr->result = expr->var->get_type(); 2180 if(const ast::FunctionType * ft = expr->result.as<ast::FunctionType>()) { 2181 if(dynamic_cast<PointerType *>(old->result)) { 2182 expr->result = new ast::PointerType(ft); 2183 } 2184 } 2157 2185 add_qualifiers( expr->result, ast::CV::Lvalue ); 2158 2186 this->node = expr; … … 2449 2477 2450 2478 virtual void visit( UntypedInitExpr * old ) override final { 2451 std:: vector<ast::InitAlternative> initAlts;2479 std::deque<ast::InitAlternative> initAlts; 2452 2480 for (auto ia : old->initAlts) { 2453 2481 initAlts.push_back(ast::InitAlternative( … … 2714 2742 this->node = new ast::Designation( 2715 2743 old->location, 2716 GET_ACCEPT_ V(designators, Expr)2744 GET_ACCEPT_D(designators, Expr) 2717 2745 ); 2718 2746 } -
src/AST/Expr.cpp
r866545b r46438e4 163 163 result = mem->get_type(); 164 164 // substitute aggregate generic parameters into member type 165 genericSubs itution( aggregate->result ).apply( result );165 genericSubstitution( aggregate->result ).apply( result ); 166 166 // ensure lvalue and appropriate restrictions from aggregate type 167 167 add_qualifiers( result, aggregate->result->qualifiers | CV::Lvalue ); -
src/AST/Expr.hpp
r866545b r46438e4 17 17 18 18 #include <cassert> 19 #include <deque> 19 20 #include <map> 20 21 #include <string> … … 111 112 } 112 113 113 const ResnSlots& resnSlots Const() const {114 const ResnSlots& resnSlots() const { 114 115 if (mode == Slots) { 115 116 return data.resnSlots; … … 128 129 } 129 130 130 const InferredParams& inferParams Const() const {131 const InferredParams& inferParams() const { 131 132 if (mode == Params) { 132 133 return data.inferParams; … … 134 135 assert(!"Mode was not already Params"); 135 136 return *((InferredParams*)nullptr); 137 } 138 139 /// splices other InferUnion into this one. Will fail if one union is in `Slots` mode 140 /// and the other is in `Params`. 141 void splice( InferUnion && o ) { 142 if ( o.mode == Empty ) return; 143 if ( mode == Empty ) { init_from( o ); return; } 144 assert( mode == o.mode && "attempt to splice incompatible InferUnion" ); 145 146 if ( mode == Slots ){ 147 data.resnSlots.insert( 148 data.resnSlots.end(), o.data.resnSlots.begin(), o.data.resnSlots.end() ); 149 } else if ( mode == Params ) { 150 for ( const auto & p : o.data.inferParams ) { 151 data.inferParams[p.first] = std::move(p.second); 152 } 153 } else assert(!"invalid mode"); 136 154 } 137 155 }; … … 695 713 public: 696 714 ptr<Expr> expr; 697 std:: vector<InitAlternative> initAlts;698 699 UntypedInitExpr( const CodeLocation & loc, const Expr * e, std:: vector<InitAlternative> && as )715 std::deque<InitAlternative> initAlts; 716 717 UntypedInitExpr( const CodeLocation & loc, const Expr * e, std::deque<InitAlternative> && as ) 700 718 : Expr( loc ), expr( e ), initAlts( std::move(as) ) {} 701 719 -
src/AST/GenericSubstitution.cpp
r866545b r46438e4 31 31 TypeSubstitution sub; 32 32 33 void previsit( const Type * ty) {34 assertf( false, "Attempted generic substitution for non-aggregate type: %s",35 toString( ty ).c_str() );33 void previsit( const Type * ) { 34 // allow empty substitution for non-generic type 35 visit_children = false; 36 36 } 37 37 … … 40 40 } 41 41 42 void previsit( const ReferenceToType * ty ) { 42 private: 43 // make substitution for generic type 44 void makeSub( const ReferenceToType * ty ) { 43 45 visit_children = false; 44 // build substitution from base parameters45 46 const AggregateDecl * aggr = ty->aggr(); 46 47 sub = TypeSubstitution{ aggr->params.begin(), aggr->params.end(), ty->params.begin() }; 48 } 49 50 public: 51 void previsit( const StructInstType * ty ) { 52 makeSub( ty ); 53 } 54 55 void previsit( const UnionInstType * ty ) { 56 makeSub( ty ); 47 57 } 48 58 }; 49 59 } 50 60 51 TypeSubstitution genericSubs itution( const Type * ty ) {61 TypeSubstitution genericSubstitution( const Type * ty ) { 52 62 Pass<GenericSubstitutionBuilder> builder; 53 63 maybe_accept( ty, builder ); -
src/AST/GenericSubstitution.hpp
r866545b r46438e4 22 22 class Type; 23 23 24 TypeSubstitution genericSubs itution( const Type * );24 TypeSubstitution genericSubstitution( const Type * ); 25 25 26 26 } -
src/AST/Init.hpp
r866545b r46438e4 16 16 #pragma once 17 17 18 #include <deque> 18 19 #include <utility> // for move 19 20 #include <vector> … … 35 36 class Designation final : public ParseNode { 36 37 public: 37 std:: vector<ptr<Expr>> designators;38 std::deque<ptr<Expr>> designators; 38 39 39 Designation( const CodeLocation& loc, std:: vector<ptr<Expr>>&& ds = {} )40 Designation( const CodeLocation& loc, std::deque<ptr<Expr>>&& ds = {} ) 40 41 : ParseNode( loc ), designators( std::move(ds) ) {} 41 42 -
src/AST/Node.hpp
r866545b r46438e4 154 154 155 155 template< enum Node::ref_type o_ref_t > 156 ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o. node) {156 ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.get()) { 157 157 if( node ) _inc(node); 158 158 } 159 159 160 160 template< enum Node::ref_type o_ref_t > 161 ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o. node) {161 ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.get()) { 162 162 if( node ) _inc(node); 163 163 } … … 184 184 template< enum Node::ref_type o_ref_t > 185 185 ptr_base & operator=( const ptr_base<node_t, o_ref_t> & o ) { 186 assign(o. node);186 assign(o.get()); 187 187 return *this; 188 188 } … … 190 190 template< enum Node::ref_type o_ref_t > 191 191 ptr_base & operator=( ptr_base<node_t, o_ref_t> && o ) { 192 assign(o. node);192 assign(o.get()); 193 193 return *this; 194 194 } … … 228 228 void _check() const; 229 229 230 protected:231 230 const node_t * node; 232 231 }; -
src/AST/Pass.hpp
r866545b r46438e4 287 287 at_cleanup( [func](void *) { func(); }, nullptr ); 288 288 } 289 290 /// When this node is finished being visited, call a member of an object. 291 template<typename T> 292 void GuardMethod( T * obj, void (T::*method)() ) { 293 at_cleanup( [ method ]( void * object ) { 294 static_cast< T * >( object )->method(); 295 }, static_cast< void * >( obj ) ); 296 } 289 297 }; 290 298 -
src/AST/porting.md
r866545b r46438e4 238 238 * also now returns `const AggregateDecl *` 239 239 * `genericSubstitution()` moved to own visitor in `AST/GenericSubstitution.hpp` 240 * subsumes old `makeGenericSubstitution()` 240 241 241 242 `BasicType`
Note:
See TracChangeset
for help on using the changeset viewer.