Changeset 10a1225
- Timestamp:
- May 17, 2019, 12:09:51 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 896737b
- Parents:
- 77bfc80
- Location:
- src/AST
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.hpp
r77bfc80 r10a1225 101 101 ptr<Expr> bitfieldWidth; 102 102 103 ObjectDecl( const CodeLocation & loc, const std::string& name, Type* type, Init* init = nullptr,104 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, Expr * bitWd = nullptr,105 std::vector< ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})103 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, Init * init = nullptr, 104 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, Expr * bitWd = nullptr, 105 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {}) 106 106 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ), 107 107 init( init ), bitfieldWidth( bitWd ) {} -
src/AST/DeclReplacer.cpp
r77bfc80 r10a1225 14 14 // 15 15 16 # errorunimplemented16 #warning unimplemented 17 17 18 18 // Local Variables: // -
src/AST/Expr.cpp
r77bfc80 r10a1225 95 95 Type * addrType( const Type * type ) { 96 96 if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * >( type ) ) { 97 CV::Qualifiers quals = refType->qualifiers;98 97 return new ReferenceType{ addrType( refType->base ), refType->qualifiers }; 99 98 } else { … … 118 117 result = res; 119 118 } else { 120 SemanticError( loc, arg->result ,119 SemanticError( loc, arg->result.get(), 121 120 "Attempt to take address of non-lvalue expression: " ); 122 121 } … … 283 282 // --- ConstructorExpr 284 283 285 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) 284 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) 286 285 : Expr( loc ), callExpr( call ) { 287 // allow resolver to type a constructor used as an expression if it has the same type as its 286 // allow resolver to type a constructor used as an expression if it has the same type as its 288 287 // first argument 289 288 assert( callExpr ); … … 310 309 TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i ) 311 310 : Expr( loc ), tuple( t ), index( i ) { 312 const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result );311 const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result.get() ); 313 312 assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested " 314 313 "index %d in expr %s", type->size(), index, toString( tuple ).c_str() ); … … 319 318 // --- TupleAssignExpr 320 319 321 TupleAssignExpr::TupleAssignExpr( 322 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 320 TupleAssignExpr::TupleAssignExpr( 321 const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 323 322 std::vector<ptr<ObjectDecl>> && tempDecls ) 324 323 : Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() { 325 // convert internally into a StmtExpr which contains the declarations and produces the tuple of 324 // convert internally into a StmtExpr which contains the declarations and produces the tuple of 326 325 // the assignments 327 326 std::list<ptr<Stmt>> stmts; … … 337 336 // --- StmtExpr 338 337 339 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) 338 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) 340 339 : Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); } 341 340 … … 344 343 const std::list<ptr<Stmt>> & body = stmts->kids; 345 344 if ( ! returnDecls.empty() ) { 346 // prioritize return decl for result type, since if a return decl exists, then the StmtExpr 345 // prioritize return decl for result type, since if a return decl exists, then the StmtExpr 347 346 // is currently in an intermediate state where the body will always give a void result type 348 347 result = returnDecls.front()->get_type(); … … 360 359 unsigned long long UniqueExpr::nextId = 0; 361 360 362 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1)361 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) 363 362 : Expr( loc, e->result ), id( i ) { 364 363 assert( expr ); 365 if ( id == -1 ) {366 assert( nextId != -1 );364 if ( id == -1ull ) { 365 assert( nextId != -1ull ); 367 366 id = nextId++; 368 367 } 368 } 369 369 370 } 370 371 -
src/AST/Fwd.hpp
r77bfc80 r10a1225 125 125 class ConstructorInit; 126 126 127 class Constant;128 129 127 class Label; 130 128 … … 135 133 std::string toString( const Node * ); 136 134 135 template < typename ... Params > 136 std::string toString( const Params & ... params ); 137 137 138 typedef unsigned int UniqueId; 138 139 -
src/AST/Node.cpp
r77bfc80 r10a1225 16 16 #include "Node.hpp" 17 17 #include "Fwd.hpp" 18 19 #include "Attribute.hpp" 18 20 #include "Decl.hpp" 19 21 #include "Expr.hpp" 22 #include "Init.hpp" 20 23 #include "Stmt.hpp" 21 24 #include "Type.hpp" 25 #include "TypeSubstitution.hpp" 22 26 23 27 template< typename node_t, enum ast::Node::ref_type ref_t > … … 26 30 template< typename node_t, enum ast::Node::ref_type ref_t > 27 31 void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); } 32 33 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere. 34 /// Returns a mutable version of the pointer in this node. 35 template< typename node_t, enum ast::Node::ref_type ref_t > 36 node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) { 37 // ensure ownership of `n` by this node to avoid spurious single-owner mutates 38 assign( n ); 39 // get mutable version of `n` 40 auto r = mutate( node ); 41 // re-assign mutable version in case `mutate()` produced a new pointer 42 assign( r ); 43 return r; 44 } 28 45 29 46 template class ast::ptr_base< ast::Node, ast::Node::ref_type::weak >; … … 227 244 template class ast::ptr_base< ast::ConstructorInit, ast::Node::ref_type::weak >; 228 245 template class ast::ptr_base< ast::ConstructorInit, ast::Node::ref_type::strong >; 229 template class ast::ptr_base< ast::Constant, ast::Node::ref_type::weak >;230 template class ast::ptr_base< ast::Constant, ast::Node::ref_type::strong >;231 246 template class ast::ptr_base< ast::Attribute, ast::Node::ref_type::weak >; 232 247 template class ast::ptr_base< ast::Attribute, ast::Node::ref_type::strong >; -
src/AST/Node.hpp
r77bfc80 r10a1225 143 143 /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere. 144 144 /// Returns a mutable version of the pointer in this node. 145 node_t * set_and_mutate( const node_t * n ) { 146 // ensure ownership of `n` by this node to avoid spurious single-owner mutates 147 assign( n ); 148 // get mutable version of `n` 149 auto r = mutate( node ); 150 // re-assign mutable version in case `mutate()` produced a new pointer 151 assign( r ); 152 return r; 153 } 145 node_t * set_and_mutate( const node_t * n ); 154 146 155 147 using ptr = const node_t *; -
src/AST/Pass.hpp
r77bfc80 r10a1225 175 175 const ast::Init * visit( const ast::ListInit * ) override final; 176 176 const ast::Init * visit( const ast::ConstructorInit * ) override final; 177 const ast::Constant * visit( const ast::Constant * ) override final;178 177 const ast::Attribute * visit( const ast::Attribute * ) override final; 179 178 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) override final; -
src/AST/Pass.impl.hpp
r77bfc80 r10a1225 791 791 792 792 //-------------------------------------------------------------------------- 793 // CatchStmt 794 template< typename pass_t > 795 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CatchStmt * node ) { 796 VISIT_START( node ); 797 798 VISIT({ 799 // catch statements introduce a level of scope (for the caught exception) 800 guard_indexer guard { *this }; 801 maybe_accept( node, &CatchStmt::decl ); 802 maybe_accept( node, &CatchStmt::cond ); 803 maybe_accept( node, &CatchStmt::body ); 804 }) 805 806 VISIT_END( Stmt, node ); 807 } 808 809 //-------------------------------------------------------------------------- 810 // FinallyStmt 811 template< typename pass_t > 812 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::FinallyStmt * node ) { 813 VISIT_START( node ); 814 815 VISIT( 816 maybe_accept( node, &FinallyStmt::body ); 817 ) 818 819 VISIT_END( Stmt, node ); 820 } 821 822 //-------------------------------------------------------------------------- 823 // WaitForStmt 824 template< typename pass_t > 825 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WaitForStmt * node ) { 826 VISIT_START( node ); 827 // for( auto & clause : node->clauses ) { 828 // maybeAccept_impl( clause.target.function, *this ); 829 // maybeAccept_impl( clause.target.arguments, *this ); 830 831 // maybeAccept_impl( clause.statement, *this ); 832 // maybeAccept_impl( clause.condition, *this ); 833 // } 834 835 #define maybe_accept(field) \ 836 if(node->field) { \ 837 auto nval = call_accept( node->field ); \ 838 if(nval != node->field ) { \ 839 auto nparent = mutate(node); \ 840 nparent->field = nval; \ 841 node = nparent; \ 842 } \ 843 } 844 845 VISIT( 846 maybe_accept( timeout.time ); 847 maybe_accept( timeout.stmt ); 848 maybe_accept( timeout.cond ); 849 maybe_accept( orElse.stmt ); 850 maybe_accept( orElse.cond ); 851 ) 852 853 #undef maybe_accept 854 855 VISIT_END( Stmt, node ); 856 } 857 858 //-------------------------------------------------------------------------- 859 // WithStmt 860 template< typename pass_t > 861 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) { 862 VISIT_START( node ); 863 864 VISIT( 865 maybe_accept( node, &WithStmt::exprs ); 866 { 867 // catch statements introduce a level of scope (for the caught exception) 868 guard_indexer guard { *this }; 869 __pass::indexer::addWith( pass, 0, node->exprs, node ); 870 maybe_accept( node, &WithStmt::stmt ); 871 } 872 ) 873 VISIT_END( Stmt, node ); 874 } 875 876 //-------------------------------------------------------------------------- 877 // NullStmt 878 template< typename pass_t > 879 const ast::NullStmt * ast::Pass< pass_t >::visit( const ast::NullStmt * node ) { 880 VISIT_START( node ); 881 VISIT_END( NullStmt, node ); 882 } 883 884 //-------------------------------------------------------------------------- 885 // DeclStmt 886 template< typename pass_t > 887 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::DeclStmt * node ) { 888 VISIT_START( node ); 889 890 VISIT( 891 maybe_accept( node, &DeclStmt::decl ); 892 ) 893 894 VISIT_END( Stmt, node ); 895 } 896 897 //-------------------------------------------------------------------------- 898 // ImplicitCtorDtorStmt 899 template< typename pass_t > 900 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ImplicitCtorDtorStmt * node ) { 901 VISIT_START( node ); 902 903 // For now this isn't visited, it is unclear if this causes problem 904 // if all tests are known to pass, remove this code 905 // VISIT( 906 // maybe_accept( node, &ImplicitCtorDtorStmt::callStmt ); 907 // ) 908 909 VISIT_END( Stmt, node ); 910 } 911 912 913 914 915 916 917 //-------------------------------------------------------------------------- 793 918 // SingleInit 794 919 template< typename pass_t > -
src/AST/Pass.proto.hpp
r77bfc80 r10a1225 241 241 INDEXER_FUNC1( addUnion , const UnionDecl * ); 242 242 INDEXER_FUNC1( addTrait , const TraitDecl * ); 243 INDEXER_FUNC2( addWith , const std::list< ptr<Expr> > &, const Node * ); 243 INDEXER_FUNC2( addWith , const std::vector< ptr<Expr> > &, const Node * ); 244 INDEXER_FUNC2( addWith , const std::list < ptr<Expr> > &, const Node * ); 244 245 245 246 // A few extra functions have more complicated behaviour, they are hand written -
src/AST/Visitor.hpp
r77bfc80 r10a1225 111 111 virtual const ast::Init * visit( const ast::ListInit * ) = 0; 112 112 virtual const ast::Init * visit( const ast::ConstructorInit * ) = 0; 113 virtual const ast::Constant * visit( const ast::Constant * ) = 0;114 113 virtual const ast::Attribute * visit( const ast::Attribute * ) = 0; 115 114 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) = 0;
Note: See TracChangeset
for help on using the changeset viewer.