Changeset 89c2f7c9
- Timestamp:
- May 15, 2019, 4:13:44 PM (4 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:
- 54e41b3, 8a5530c, e0d19f8
- Parents:
- 3648d98 (diff), 1e97287 (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:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/tls-fetch_add.c
r3648d98 r89c2f7c9 6 6 #define thread_local _Thread_local 7 7 8 volatile thread_localbool value;8 thread_local volatile bool value; 9 9 10 10 void __attribute__((noinline)) do_call() { -
src/AST/Decl.hpp
r3648d98 r89c2f7c9 57 57 static readonly<Decl> fromId( UniqueId id ); 58 58 59 virtualconst Decl * accept( Visitor & v ) const override = 0;60 private: 61 virtualDecl * clone() const override = 0;59 const Decl * accept( Visitor & v ) const override = 0; 60 private: 61 Decl * clone() const override = 0; 62 62 }; 63 63 … … 87 87 virtual const Type * get_type() const = 0; 88 88 /// Set type of this declaration. May be verified by subclass 89 virtual void set_type(Type *) = 0;90 91 virtualconst DeclWithType * accept( Visitor & v ) const override = 0;92 private: 93 virtualDeclWithType * clone() const override = 0;89 virtual void set_type(Type *) = 0; 90 91 const DeclWithType * accept( Visitor & v ) const override = 0; 92 private: 93 DeclWithType * clone() const override = 0; 94 94 }; 95 95 … … 108 108 109 109 const Type* get_type() const override { return type; } 110 void set_type( Type* ty ) override { type = ty; } 111 112 virtual const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); } 113 private: 114 virtual ObjectDecl * clone() const override { return new ObjectDecl{ *this }; } 110 void set_type( Type * ty ) override { type = ty; } 111 112 const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); } 113 private: 114 ObjectDecl * clone() const override { return new ObjectDecl{ *this }; } 115 116 /// Must be copied in ALL derived classes 117 template<typename node_t> 118 friend auto mutate(const node_t * node); 119 }; 120 121 class FunctionDecl : public DeclWithType { 122 public: 123 ptr<FunctionType> type; 124 ptr<CompoundStmt> stmts; 125 std::list< ptr<Expr> > withExprs; 126 127 FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type, 128 CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, 129 std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}) 130 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ), 131 stmts( stmts ) {} 132 133 const Type * get_type() const override { return type.get(); } 134 void set_type(Type * t) override { type = strict_dynamic_cast< FunctionType* >( t ); } 135 136 bool has_body() const { return stmts; } 137 138 const DeclWithType * accept( Visitor &v ) const override { return v.visit( this ); } 139 private: 140 FunctionDecl * clone() const override { return new FunctionDecl( *this ); } 115 141 116 142 /// Must be copied in ALL derived classes … … 173 199 bool isComplete() { return sized; } 174 200 175 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 176 private: 177 virtual TypeDecl * clone() const override { return new TypeDecl{ *this }; } 201 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 202 private: 203 TypeDecl * clone() const override { return new TypeDecl{ *this }; } 204 205 /// Must be copied in ALL derived classes 206 template<typename node_t> 207 friend auto mutate(const node_t * node); 178 208 }; 179 209 … … 187 217 std::string typeString() const override { return "typedef"; } 188 218 189 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 190 private: 191 virtual TypedefDecl * clone() const override { return new TypedefDecl{ *this }; } 219 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 220 private: 221 TypedefDecl * clone() const override { return new TypedefDecl{ *this }; } 222 223 /// Must be copied in ALL derived classes 224 template<typename node_t> 225 friend auto mutate(const node_t * node); 192 226 }; 193 227 … … 227 261 bool is_thread() { return kind == DeclarationNode::Thread; } 228 262 229 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 230 private: 231 virtual StructDecl * clone() const override { return new StructDecl{ *this }; } 263 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 264 private: 265 StructDecl * clone() const override { return new StructDecl{ *this }; } 266 267 /// Must be copied in ALL derived classes 268 template<typename node_t> 269 friend auto mutate(const node_t * node); 232 270 233 271 std::string typeString() const override { return "struct"; } … … 241 279 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 242 280 243 virtual const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 244 private: 245 virtual UnionDecl * clone() const override { return new UnionDecl{ *this }; } 281 const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 282 private: 283 UnionDecl * clone() const override { return new UnionDecl{ *this }; } 284 285 /// Must be copied in ALL derived classes 286 template<typename node_t> 287 friend auto mutate(const node_t * node); 246 288 247 289 std::string typeString() const override { return "union"; } … … 258 300 bool valueOf( Decl* enumerator, long long& value ) const; 259 301 260 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 261 private: 262 virtual EnumDecl * clone() const override { return new EnumDecl{ *this }; } 302 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 303 private: 304 EnumDecl * clone() const override { return new EnumDecl{ *this }; } 305 306 /// Must be copied in ALL derived classes 307 template<typename node_t> 308 friend auto mutate(const node_t * node); 263 309 264 310 std::string typeString() const override { return "enum"; } … … 275 321 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 276 322 277 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 278 private: 279 virtual TraitDecl * clone() const override { return new TraitDecl{ *this }; } 323 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 324 private: 325 TraitDecl * clone() const override { return new TraitDecl{ *this }; } 326 327 /// Must be copied in ALL derived classes 328 template<typename node_t> 329 friend auto mutate(const node_t * node); 280 330 281 331 std::string typeString() const override { return "trait"; } 282 332 }; 283 333 334 class AsmDecl : public Decl { 335 public: 336 ptr<AsmStmt> stmt; 337 338 AsmDecl( const CodeLocation & loc, AsmStmt *stmt ) 339 : Decl( loc, "", {}, {} ), stmt(stmt) {} 340 341 const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); } 342 private: 343 AsmDecl *clone() const override { return new AsmDecl( *this ); } 344 345 /// Must be copied in ALL derived classes 346 template<typename node_t> 347 friend auto mutate(const node_t * node); 348 }; 349 350 class StaticAssertDecl : public Decl { 351 public: 352 ptr<Expr> condition; 353 ptr<ConstantExpr> msg; // string literal 354 355 StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg ) 356 : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {} 357 358 const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); } 359 private: 360 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 361 362 /// Must be copied in ALL derived classes 363 template<typename node_t> 364 friend auto mutate(const node_t * node); 365 }; 284 366 285 367 //================================================================================================= … … 294 376 inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); } 295 377 inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); } 296 //inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }297 //inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }378 inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); } 379 inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); } 298 380 inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); } 299 381 inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); } … … 310 392 inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); } 311 393 inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); } 312 // inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }313 // inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }314 // inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }315 // inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }316 394 inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); } 317 395 inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); } 318 //inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }319 //inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }320 //inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }321 //inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }396 inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); } 397 inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); } 398 inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); } 399 inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); } 322 400 323 401 } -
src/AST/Expr.hpp
r3648d98 r89c2f7c9 123 123 virtual const Expr * accept( Visitor & v ) const override = 0; 124 124 private: 125 virtualExpr * clone() const override = 0;125 Expr * clone() const override = 0; 126 126 }; 127 127 -
src/AST/Fwd.hpp
r3648d98 r89c2f7c9 33 33 class NamedTypeDecl; 34 34 class TypeDecl; 35 class FtypeDecl;36 class DtypeDecl;37 35 class TypedefDecl; 38 36 class AsmDecl; … … 170 168 inline void increment( const class TypeDecl *, Node::ref_type ); 171 169 inline void decrement( const class TypeDecl *, Node::ref_type ); 172 inline void increment( const class FtypeDecl *, Node::ref_type );173 inline void decrement( const class FtypeDecl *, Node::ref_type );174 inline void increment( const class DtypeDecl *, Node::ref_type );175 inline void decrement( const class DtypeDecl *, Node::ref_type );176 170 inline void increment( const class TypedefDecl *, Node::ref_type ); 177 171 inline void decrement( const class TypedefDecl *, Node::ref_type ); -
src/AST/Init.hpp
r3648d98 r89c2f7c9 37 37 : ParseNode( loc ), designators( std::move(ds) ) {} 38 38 39 virtualconst Designation* accept( Visitor& v ) const override { return v.visit( this ); }39 const Designation* accept( Visitor& v ) const override { return v.visit( this ); } 40 40 private: 41 virtualDesignation* clone() const override { return new Designation{ *this }; }41 Designation* clone() const override { return new Designation{ *this }; } 42 42 }; 43 43 … … 52 52 Init( const CodeLocation& loc, ConstructFlag mc ) : ParseNode( loc ), maybeConstructed( mc ) {} 53 53 54 virtualconst Init * accept( Visitor& v ) const override = 0;54 const Init * accept( Visitor& v ) const override = 0; 55 55 private: 56 virtualconst Init * clone() const override = 0;56 const Init * clone() const override = 0; 57 57 }; 58 58 … … 66 66 : Init( loc, mc ), value( val ) {} 67 67 68 virtualconst Init * accept( Visitor & v ) const override { return v.visit( this ); }68 const Init * accept( Visitor & v ) const override { return v.visit( this ); } 69 69 private: 70 virtualSingleInit * clone() const override { return new SingleInit{ *this }; }70 SingleInit * clone() const override { return new SingleInit{ *this }; } 71 71 72 72 /// Must be copied in ALL derived classes … … 94 94 const_iterator end() const { return initializers.end(); } 95 95 96 virtualconst Init * accept( Visitor & v ) const override { return v.visit( this ); }96 const Init * accept( Visitor & v ) const override { return v.visit( this ); } 97 97 private: 98 virtualListInit * clone() const override { return new ListInit{ *this }; }98 ListInit * clone() const override { return new ListInit{ *this }; } 99 99 100 100 /// Must be copied in ALL derived classes … … 117 117 : Init( loc, DoConstruct ), ctor( ctor ), dtor( dtor ), init( init ) {} 118 118 119 virtualconst Init * accept( Visitor & v ) const override { return v.visit( this ); }119 const Init * accept( Visitor & v ) const override { return v.visit( this ); } 120 120 private: 121 virtualConstructorInit * clone() const override { return new ConstructorInit{ *this }; }121 ConstructorInit * clone() const override { return new ConstructorInit{ *this }; } 122 122 123 123 /// Must be copied in ALL derived classes -
src/AST/Node.hpp
r3648d98 r89c2f7c9 9 9 // Author : Thierry Delisle 10 10 // Created On : Wed May 8 10:27:04 2019 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 11:00:00 201913 // Update Count : 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 15 16:02:00 2019 13 // Update Count : 3 14 14 // 15 15 -
src/AST/Pass.hpp
r3648d98 r89c2f7c9 85 85 86 86 /// Visit function declarations 87 virtualconst ast::DeclWithType * visit( const ast::ObjectDecl * ) override final;88 virtualconst ast::DeclWithType * visit( const ast::FunctionDecl * ) override final;89 virtualconst ast::Decl * visit( const ast::StructDecl * ) override final;90 virtualconst ast::Decl * visit( const ast::UnionDecl * ) override final;91 virtualconst ast::Decl * visit( const ast::EnumDecl * ) override final;92 virtualconst ast::Decl * visit( const ast::TraitDecl * ) override final;93 virtualconst ast::Decl * visit( const ast::TypeDecl * ) override final;94 virtualconst ast::Decl * visit( const ast::TypedefDecl * ) override final;95 virtualconst ast::AsmDecl * visit( const ast::AsmDecl * ) override final;96 virtualconst ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * ) override final;97 virtualconst ast::CompoundStmt * visit( const ast::CompoundStmt * ) override final;98 virtualconst ast::Stmt * visit( const ast::ExprStmt * ) override final;99 virtualconst ast::Stmt * visit( const ast::AsmStmt * ) override final;100 virtualconst ast::Stmt * visit( const ast::DirectiveStmt * ) override final;101 virtualconst ast::Stmt * visit( const ast::IfStmt * ) override final;102 virtualconst ast::Stmt * visit( const ast::WhileStmt * ) override final;103 virtualconst ast::Stmt * visit( const ast::ForStmt * ) override final;104 virtualconst ast::Stmt * visit( const ast::SwitchStmt * ) override final;105 virtualconst ast::Stmt * visit( const ast::CaseStmt * ) override final;106 virtualconst ast::Stmt * visit( const ast::BranchStmt * ) override final;107 virtualconst ast::Stmt * visit( const ast::ReturnStmt * ) override final;108 virtualconst ast::Stmt * visit( const ast::ThrowStmt * ) override final;109 virtualconst ast::Stmt * visit( const ast::TryStmt * ) override final;110 virtualconst ast::Stmt * visit( const ast::CatchStmt * ) override final;111 virtualconst ast::Stmt * visit( const ast::FinallyStmt * ) override final;112 virtualconst ast::Stmt * visit( const ast::WaitForStmt * ) override final;113 virtualconst ast::Stmt * visit( const ast::WithStmt * ) override final;114 virtualconst ast::NullStmt * visit( const ast::NullStmt * ) override final;115 virtualconst ast::Stmt * visit( const ast::DeclStmt * ) override final;116 virtualconst ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * ) override final;117 virtualconst ast::Expr * visit( const ast::ApplicationExpr * ) override final;118 virtualconst ast::Expr * visit( const ast::UntypedExpr * ) override final;119 virtualconst ast::Expr * visit( const ast::NameExpr * ) override final;120 virtualconst ast::Expr * visit( const ast::AddressExpr * ) override final;121 virtualconst ast::Expr * visit( const ast::LabelAddressExpr * ) override final;122 virtualconst ast::Expr * visit( const ast::CastExpr * ) override final;123 virtualconst ast::Expr * visit( const ast::KeywordCastExpr * ) override final;124 virtualconst ast::Expr * visit( const ast::VirtualCastExpr * ) override final;125 virtualconst ast::Expr * visit( const ast::UntypedMemberExpr * ) override final;126 virtualconst ast::Expr * visit( const ast::MemberExpr * ) override final;127 virtualconst ast::Expr * visit( const ast::VariableExpr * ) override final;128 virtualconst ast::Expr * visit( const ast::ConstantExpr * ) override final;129 virtualconst ast::Expr * visit( const ast::SizeofExpr * ) override final;130 virtualconst ast::Expr * visit( const ast::AlignofExpr * ) override final;131 virtualconst ast::Expr * visit( const ast::UntypedOffsetofExpr * ) override final;132 virtualconst ast::Expr * visit( const ast::OffsetofExpr * ) override final;133 virtualconst ast::Expr * visit( const ast::OffsetPackExpr * ) override final;134 virtualconst ast::Expr * visit( const ast::AttrExpr * ) override final;135 virtualconst ast::Expr * visit( const ast::LogicalExpr * ) override final;136 virtualconst ast::Expr * visit( const ast::ConditionalExpr * ) override final;137 virtualconst ast::Expr * visit( const ast::CommaExpr * ) override final;138 virtualconst ast::Expr * visit( const ast::TypeExpr * ) override final;139 virtualconst ast::Expr * visit( const ast::AsmExpr * ) override final;140 virtualconst ast::Expr * visit( const ast::ImplicitCopyCtorExpr * ) override final;141 virtualconst ast::Expr * visit( const ast::ConstructorExpr * ) override final;142 virtualconst ast::Expr * visit( const ast::CompoundLiteralExpr * ) override final;143 virtualconst ast::Expr * visit( const ast::RangeExpr * ) override final;144 virtualconst ast::Expr * visit( const ast::UntypedTupleExpr * ) override final;145 virtualconst ast::Expr * visit( const ast::TupleExpr * ) override final;146 virtualconst ast::Expr * visit( const ast::TupleIndexExpr * ) override final;147 virtualconst ast::Expr * visit( const ast::TupleAssignExpr * ) override final;148 virtualconst ast::Expr * visit( const ast::StmtExpr * ) override final;149 virtualconst ast::Expr * visit( const ast::UniqueExpr * ) override final;150 virtualconst ast::Expr * visit( const ast::UntypedInitExpr * ) override final;151 virtualconst ast::Expr * visit( const ast::InitExpr * ) override final;152 virtualconst ast::Expr * visit( const ast::DeletedExpr * ) override final;153 virtualconst ast::Expr * visit( const ast::DefaultArgExpr * ) override final;154 virtualconst ast::Expr * visit( const ast::GenericExpr * ) override final;155 virtualconst ast::Type * visit( const ast::VoidType * ) override final;156 virtualconst ast::Type * visit( const ast::BasicType * ) override final;157 virtualconst ast::Type * visit( const ast::PointerType * ) override final;158 virtualconst ast::Type * visit( const ast::ArrayType * ) override final;159 virtualconst ast::Type * visit( const ast::ReferenceType * ) override final;160 virtualconst ast::Type * visit( const ast::QualifiedType * ) override final;161 virtualconst ast::Type * visit( const ast::FunctionType * ) override final;162 virtualconst ast::Type * visit( const ast::StructInstType * ) override final;163 virtualconst ast::Type * visit( const ast::UnionInstType * ) override final;164 virtualconst ast::Type * visit( const ast::EnumInstType * ) override final;165 virtualconst ast::Type * visit( const ast::TraitInstType * ) override final;166 virtualconst ast::Type * visit( const ast::TypeInstType * ) override final;167 virtualconst ast::Type * visit( const ast::TupleType * ) override final;168 virtualconst ast::Type * visit( const ast::TypeofType * ) override final;169 virtualconst ast::Type * visit( const ast::VarArgsType * ) override final;170 virtualconst ast::Type * visit( const ast::ZeroType * ) override final;171 virtualconst ast::Type * visit( const ast::OneType * ) override final;172 virtualconst ast::Type * visit( const ast::GlobalScopeType * ) override final;173 virtualconst ast::Designation * visit( const ast::Designation * ) override final;174 virtualconst ast::Init * visit( const ast::SingleInit * ) override final;175 virtualconst ast::Init * visit( const ast::ListInit * ) override final;176 virtualconst ast::Init * visit( const ast::ConstructorInit * ) override final;177 virtualconst ast::Constant * visit( const ast::Constant * ) override final;178 virtualconst ast::Attribute * visit( const ast::Attribute * ) override final;179 virtualconst ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) override final;87 const ast::DeclWithType * visit( const ast::ObjectDecl * ) override final; 88 const ast::DeclWithType * visit( const ast::FunctionDecl * ) override final; 89 const ast::Decl * visit( const ast::StructDecl * ) override final; 90 const ast::Decl * visit( const ast::UnionDecl * ) override final; 91 const ast::Decl * visit( const ast::EnumDecl * ) override final; 92 const ast::Decl * visit( const ast::TraitDecl * ) override final; 93 const ast::Decl * visit( const ast::TypeDecl * ) override final; 94 const ast::Decl * visit( const ast::TypedefDecl * ) override final; 95 const ast::AsmDecl * visit( const ast::AsmDecl * ) override final; 96 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * ) override final; 97 const ast::CompoundStmt * visit( const ast::CompoundStmt * ) override final; 98 const ast::Stmt * visit( const ast::ExprStmt * ) override final; 99 const ast::Stmt * visit( const ast::AsmStmt * ) override final; 100 const ast::Stmt * visit( const ast::DirectiveStmt * ) override final; 101 const ast::Stmt * visit( const ast::IfStmt * ) override final; 102 const ast::Stmt * visit( const ast::WhileStmt * ) override final; 103 const ast::Stmt * visit( const ast::ForStmt * ) override final; 104 const ast::Stmt * visit( const ast::SwitchStmt * ) override final; 105 const ast::Stmt * visit( const ast::CaseStmt * ) override final; 106 const ast::Stmt * visit( const ast::BranchStmt * ) override final; 107 const ast::Stmt * visit( const ast::ReturnStmt * ) override final; 108 const ast::Stmt * visit( const ast::ThrowStmt * ) override final; 109 const ast::Stmt * visit( const ast::TryStmt * ) override final; 110 const ast::Stmt * visit( const ast::CatchStmt * ) override final; 111 const ast::Stmt * visit( const ast::FinallyStmt * ) override final; 112 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; 113 const ast::Stmt * visit( const ast::WithStmt * ) override final; 114 const ast::NullStmt * visit( const ast::NullStmt * ) override final; 115 const ast::Stmt * visit( const ast::DeclStmt * ) override final; 116 const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * ) override final; 117 const ast::Expr * visit( const ast::ApplicationExpr * ) override final; 118 const ast::Expr * visit( const ast::UntypedExpr * ) override final; 119 const ast::Expr * visit( const ast::NameExpr * ) override final; 120 const ast::Expr * visit( const ast::AddressExpr * ) override final; 121 const ast::Expr * visit( const ast::LabelAddressExpr * ) override final; 122 const ast::Expr * visit( const ast::CastExpr * ) override final; 123 const ast::Expr * visit( const ast::KeywordCastExpr * ) override final; 124 const ast::Expr * visit( const ast::VirtualCastExpr * ) override final; 125 const ast::Expr * visit( const ast::UntypedMemberExpr * ) override final; 126 const ast::Expr * visit( const ast::MemberExpr * ) override final; 127 const ast::Expr * visit( const ast::VariableExpr * ) override final; 128 const ast::Expr * visit( const ast::ConstantExpr * ) override final; 129 const ast::Expr * visit( const ast::SizeofExpr * ) override final; 130 const ast::Expr * visit( const ast::AlignofExpr * ) override final; 131 const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) override final; 132 const ast::Expr * visit( const ast::OffsetofExpr * ) override final; 133 const ast::Expr * visit( const ast::OffsetPackExpr * ) override final; 134 const ast::Expr * visit( const ast::AttrExpr * ) override final; 135 const ast::Expr * visit( const ast::LogicalExpr * ) override final; 136 const ast::Expr * visit( const ast::ConditionalExpr * ) override final; 137 const ast::Expr * visit( const ast::CommaExpr * ) override final; 138 const ast::Expr * visit( const ast::TypeExpr * ) override final; 139 const ast::Expr * visit( const ast::AsmExpr * ) override final; 140 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * ) override final; 141 const ast::Expr * visit( const ast::ConstructorExpr * ) override final; 142 const ast::Expr * visit( const ast::CompoundLiteralExpr * ) override final; 143 const ast::Expr * visit( const ast::RangeExpr * ) override final; 144 const ast::Expr * visit( const ast::UntypedTupleExpr * ) override final; 145 const ast::Expr * visit( const ast::TupleExpr * ) override final; 146 const ast::Expr * visit( const ast::TupleIndexExpr * ) override final; 147 const ast::Expr * visit( const ast::TupleAssignExpr * ) override final; 148 const ast::Expr * visit( const ast::StmtExpr * ) override final; 149 const ast::Expr * visit( const ast::UniqueExpr * ) override final; 150 const ast::Expr * visit( const ast::UntypedInitExpr * ) override final; 151 const ast::Expr * visit( const ast::InitExpr * ) override final; 152 const ast::Expr * visit( const ast::DeletedExpr * ) override final; 153 const ast::Expr * visit( const ast::DefaultArgExpr * ) override final; 154 const ast::Expr * visit( const ast::GenericExpr * ) override final; 155 const ast::Type * visit( const ast::VoidType * ) override final; 156 const ast::Type * visit( const ast::BasicType * ) override final; 157 const ast::Type * visit( const ast::PointerType * ) override final; 158 const ast::Type * visit( const ast::ArrayType * ) override final; 159 const ast::Type * visit( const ast::ReferenceType * ) override final; 160 const ast::Type * visit( const ast::QualifiedType * ) override final; 161 const ast::Type * visit( const ast::FunctionType * ) override final; 162 const ast::Type * visit( const ast::StructInstType * ) override final; 163 const ast::Type * visit( const ast::UnionInstType * ) override final; 164 const ast::Type * visit( const ast::EnumInstType * ) override final; 165 const ast::Type * visit( const ast::TraitInstType * ) override final; 166 const ast::Type * visit( const ast::TypeInstType * ) override final; 167 const ast::Type * visit( const ast::TupleType * ) override final; 168 const ast::Type * visit( const ast::TypeofType * ) override final; 169 const ast::Type * visit( const ast::VarArgsType * ) override final; 170 const ast::Type * visit( const ast::ZeroType * ) override final; 171 const ast::Type * visit( const ast::OneType * ) override final; 172 const ast::Type * visit( const ast::GlobalScopeType * ) override final; 173 const ast::Designation * visit( const ast::Designation * ) override final; 174 const ast::Init * visit( const ast::SingleInit * ) override final; 175 const ast::Init * visit( const ast::ListInit * ) override final; 176 const ast::Init * visit( const ast::ConstructorInit * ) override final; 177 const ast::Constant * visit( const ast::Constant * ) override final; 178 const ast::Attribute * visit( const ast::Attribute * ) override final; 179 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) override final; 180 180 181 181 friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor ); … … 215 215 Pass<pass_t> & pass; 216 216 }; 217 218 private: 219 bool inFunction = false; 217 220 }; 218 221 -
src/AST/Pass.impl.hpp
r3648d98 r89c2f7c9 158 158 // These may be modified by subnode but most be restored once we exit this statemnet. 159 159 ValueGuardPtr< const ast::TypeSubstitution * > __old_env ( __pass::env( pass, 0) ); 160 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > > __old_decls_before( stmts_before );161 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > > __old_decls_after ( stmts_after );162 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > > __old_stmts_before( decls_before );163 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > > __old_stmts_after ( decls_after );160 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); 161 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); 162 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before ); 163 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after ); 164 164 165 165 // Now is the time to actually visit the node … … 212 212 213 213 // These may be modified by subnode but most be restored once we exit this statemnet. 214 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > > __old_decls_before( stmts_before );215 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > > __old_decls_after ( stmts_after );216 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > > __old_stmts_before( decls_before );217 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > > __old_stmts_after ( decls_after );214 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); 215 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); 216 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before ); 217 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after ); 218 218 219 219 // update pass statitistics … … 390 390 { 391 391 guard_indexer guard { *this }; 392 maybe_accept( node, & ast::ObjectDecl::type );393 } 394 maybe_accept( node, & ast::ObjectDecl::init );395 maybe_accept( node, & ast::ObjectDecl::bitfieldWidth );396 maybe_accept( node, & ast::ObjectDecl::attributes );392 maybe_accept( node, &ObjectDecl::type ); 393 } 394 maybe_accept( node, &ObjectDecl::init ); 395 maybe_accept( node, &ObjectDecl::bitfieldWidth ); 396 maybe_accept( node, &ObjectDecl::attributes ); 397 397 ) 398 398 … … 401 401 VISIT_END( DeclWithType, node ); 402 402 } 403 404 //-------------------------------------------------------------------------- 405 // FunctionDecl 406 template< typename pass_t > 407 const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::FunctionDecl * node ) { 408 VISIT_START( node ); 409 410 __pass::indexer::addId( pass, 0, node ); 411 412 VISIT(maybe_accept( node, &FunctionDecl::withExprs );) 413 { 414 // with clause introduces a level of scope (for the with expression members). 415 // with clause exprs are added to the indexer before parameters so that parameters 416 // shadow with exprs and not the other way around. 417 guard_indexer guard { *this }; 418 __pass::indexer::addWith( pass, 0, node->withExprs, node ); 419 { 420 guard_indexer guard { *this }; 421 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 422 static ast::ObjectDecl func( 423 node->location, "__func__", 424 new ast::ArrayType( 425 new ast::BasicType( ast::BasicType::Char, ast::CV::Qualifiers( ast::CV::Const ) ), 426 nullptr, true, false 427 ) 428 ); 429 __pass::indexer::addId( pass, 0, &func ); 430 VISIT( 431 maybe_accept( node, &FunctionDecl::type ); 432 // function body needs to have the same scope as parameters - CompoundStmt will not enter 433 // a new scope if inFunction is true 434 ValueGuard< bool > oldInFunction( inFunction ); 435 inFunction = true; 436 maybe_accept( node, &FunctionDecl::statements ); 437 maybe_accept( node, &FunctionDecl::attributes ); 438 ) 439 } 440 } 441 442 VISIT_END( DeclWithType, node ); 443 } 444 445 //-------------------------------------------------------------------------- 446 // StructDecl 447 template< typename pass_t > 448 const ast::Decl * ast::Pass< pass_t >::visit( const ast::StructDecl * node ) { 449 VISIT_START( node ); 450 451 // make up a forward declaration and add it before processing the members 452 // needs to be on the heap because addStruct saves the pointer 453 __pass::indexer::addStructFwd( pass, 0, node ); 454 455 VISIT({ 456 guard_indexer guard { * this }; 457 maybe_accept( node, &StructDecl::parameters ); 458 maybe_accept( node, &StructDecl::members ); 459 }) 460 461 // this addition replaces the forward declaration 462 __pass::indexer::addStruct( pass, 0, node ); 463 464 VISIT_END( Decl, node ); 465 } 466 467 //-------------------------------------------------------------------------- 468 // UnionDecl 469 template< typename pass_t > 470 const ast::Decl * ast::Pass< pass_t >::visit( const ast::UnionDecl * node ) { 471 VISIT_START( node ); 472 473 // make up a forward declaration and add it before processing the members 474 __pass::indexer::addUnionFwd( pass, 0, node ); 475 476 VISIT({ 477 guard_indexer guard { * this }; 478 maybe_accept( node, &UnionDecl::parameters ); 479 maybe_accept( node, &UnionDecl::members ); 480 }) 481 482 __pass::indexer::addUnion( pass, 0, node ); 483 484 VISIT_END( Decl, node ); 485 } 486 487 //-------------------------------------------------------------------------- 488 // EnumDecl 489 template< typename pass_t > 490 const ast::Decl * ast::Pass< pass_t >::visit( const ast::EnumDecl * node ) { 491 VISIT_START( node ); 492 493 __pass::indexer::addEnum( pass, 0, node ); 494 495 VISIT( 496 // unlike structs, traits, and unions, enums inject their members into the global scope 497 maybe_accept( node, &EnumDecl::parameters ); 498 maybe_accept( node, &EnumDecl::members ); 499 ) 500 501 VISIT_END( Decl, node ); 502 } 503 504 //-------------------------------------------------------------------------- 505 // TraitDecl 506 template< typename pass_t > 507 const ast::Decl * ast::Pass< pass_t >::visit( const ast::TraitDecl * node ) { 508 VISIT_START( node ); 509 510 VISIT({ 511 guard_indexer guard { *this }; 512 maybe_accept( node, &TraitDecl::parameters ); 513 maybe_accept( node, &TraitDecl::members ); 514 }) 515 516 __pass::indexer::addTrait( pass, 0, node ); 517 518 VISIT_END( Decl, node ); 519 } 520 521 //-------------------------------------------------------------------------- 522 // TypeDecl 523 template< typename pass_t > 524 const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypeDecl * node ) { 525 VISIT_START( node ); 526 527 VISIT({ 528 guard_indexer guard { *this }; 529 maybe_accept( node, &TypeDecl::parameters ); 530 maybe_accept( node, &TypeDecl::base ); 531 }) 532 533 // see A NOTE ON THE ORDER OF TRAVERSAL, above 534 // note that assertions come after the type is added to the symtab, since they are not part of the type proper 535 // and may depend on the type itself 536 __pass::indexer::addType( pass, 0, node ); 537 538 VISIT( 539 maybe_accept( node, &TypeDecl::assertions, *this ); 540 541 { 542 guard_indexer guard { *this }; 543 maybe_accept( node, &TypeDecl::init ); 544 } 545 ) 546 547 VISIT_END( Decl, node ); 548 } 549 550 //-------------------------------------------------------------------------- 551 // TypedefDecl 552 template< typename pass_t > 553 const ast::Decl * ast::Pass< pass_t >::visit( const ast::TypedefDecl * node ) { 554 VISIT_START( node ); 555 556 VISIT({ 557 guard_indexer guard { *this }; 558 maybe_accept( node, &TypedefDecl::parameters ); 559 maybe_accept( node, &TypedefDecl::base ); 560 }) 561 562 __pass::indexer::addType( pass, 0, node ); 563 564 maybe_accept( node, &TypedefDecl::assertions ); 565 566 VISIT_END( Decl, node ); 567 } 568 569 //-------------------------------------------------------------------------- 570 // AsmDecl 571 template< typename pass_t > 572 const ast::AsmDecl * ast::Pass< pass_t >::visit( const ast::AsmDecl * node ) { 573 VISIT_START( node ); 574 575 VISIT( 576 maybe_accept( node, &AsmDecl::stmt ); 577 ) 578 579 VISIT_END( AsmDecl, node ); 580 } 581 582 //-------------------------------------------------------------------------- 583 // StaticAssertDecl 584 template< typename pass_t > 585 const ast::StaticAssertDecl * ast::Pass< pass_t >::visit( const ast::StaticAssertDecl * node ) { 586 VISIT_START( node ); 587 588 VISIT( 589 maybe_accept( node, &StaticAssertDecl::condition ); 590 maybe_accept( node, &StaticAssertDecl::msg ); 591 ) 592 593 VISIT_END( StaticAssertDecl, node ); 594 } 595 596 //-------------------------------------------------------------------------- 597 // CompoundStmt 598 template< typename pass_t > 599 const ast::CompoundStmt * ast::Pass< pass_t >::visit( const ast::CompoundStmt * node ) { 600 VISIT_START( node ); 601 VISIT({ 602 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 603 auto guard1 = makeFuncGuard( [this, inFunction = this->inFunction]() { 604 if ( ! inFunction ) __pass::indexer::enter(pass, 0); 605 }, [this, inFunction = this->inFunction]() { 606 if ( ! inFunction ) __pass::indexer::leave(pass, 0); 607 }); 608 ValueGuard< bool > guard2( inFunction ); 609 guard_scope guard3 { *this }; 610 inFunction = false; 611 maybe_accept( node, &CompoundStmt::kids ); 612 }) 613 VISIT_END( CompoundStmt, node ); 614 } 615 403 616 404 617 //-------------------------------------------------------------------------- -
src/AST/Stmt.cpp
r3648d98 r89c2f7c9 8 8 // 9 9 // Author : Aaron B. Moss 10 // Created On : Wed May 8 13:00:00 201911 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 13:00:00 201913 // Update Count : 110 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 15 15:53:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 18 18 #include "DeclReplacer.hpp" 19 19 20 namespace ast { 21 20 22 // --- CompoundStmt 23 CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) { 24 assert(!"implemented"); 25 } 21 26 22 namespace ast { 23 CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) { 24 assert(!"implemented"); 25 } 27 // --- BranchStmt 28 BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels ) 29 : Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) { 30 // Make sure a syntax error hasn't slipped through. 31 assert( Goto != kind || !target.empty() ); 32 } 33 34 const char * BranchStmt::kindNames[] = { 35 "Goto", "Break", "Continue", "FallThrough", "FallThroughDefault" 36 } 37 26 38 } 27 39 -
src/AST/Stmt.hpp
r3648d98 r89c2f7c9 8 8 // 9 9 // Author : Aaron B. Moss 10 // Created On : Wed May 8 13:00:00 201911 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 13:00:00 201913 // Update Count : 110 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 15 16:01:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 40 40 Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {} 41 41 42 virtualconst Stmt* accept( Visitor& v ) const override = 0;43 private: 44 virtualStmt* clone() const override = 0;42 const Stmt* accept( Visitor& v ) const override = 0; 43 private: 44 Stmt* clone() const override = 0; 45 45 }; 46 46 … … 59 59 void push_front( Stmt* s ) { kids.emplace_front( s ); } 60 60 61 virtualconst CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); }62 private: 63 virtualCompoundStmt* clone() const override { return new CompoundStmt{ *this }; }61 const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); } 62 private: 63 CompoundStmt* clone() const override { return new CompoundStmt{ *this }; } 64 64 }; 65 65 … … 70 70 : Stmt(loc, std::move(labels)) {} 71 71 72 virtual const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); }73 private: 74 virtual NullStmt* clone() const override { return new NullStmt{ *this }; }72 const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); } 73 private: 74 NullStmt* clone() const override { return new NullStmt{ *this }; } 75 75 }; 76 76 … … 80 80 ptr<Expr> expr; 81 81 82 ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {} 83 84 virtual const Stmt * accept( Visitor& v ) const override { return v.visit( this ); } 85 private: 86 virtual ExprStmt * clone() const override { return new ExprStmt{ *this }; } 87 }; 88 89 82 ExprStmt( const CodeLocation& loc, const Expr* e ) : Stmt(loc), expr(e) {} 83 84 const Stmt * accept( Visitor& v ) const override { return v.visit( this ); } 85 private: 86 ExprStmt * clone() const override { return new ExprStmt{ *this }; } 87 }; 88 89 class AsmStmt final : public Stmt { 90 public: 91 bool isVolatile; 92 ptr<Expr> instruction; 93 std::vector<ptr<Expr>> output, input; 94 std::vector<ptr<ConstantExpr>> clobber; 95 std::vector<Label> gotoLabels; 96 97 AsmStmt( const CodeLocation& loc, bool isVolatile, const Expr * instruction, 98 std::vector<ptr<Expr>>&& output, std::vector<ptr<Expr>>&& input, 99 std::vector<ptr<ConstantExpr>>&& clobber, std::vector<Label>&& gotoLabels, 100 std::vector<Label>&& labels = {}) 101 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction), 102 output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)), 103 gotoLabels(std::move(gotoLabels)) {} 104 105 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 106 private: 107 AsmStmt* clone() const override { return new AsmStmt{ *this }; } 108 }; 109 110 class DirectiveStmt final : public Stmt { 111 public: 112 std::string directive; 113 114 DirectiveStmt( const CodeLocation& loc, const std::string & directive, 115 std::vector<Label>&& labels = {} ) 116 : Stmt(loc, std::move(labels)), directive(directive) {} 117 118 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 119 private: 120 DirectiveStmt* clone() const override { return new DirectiveStmt{ *this }; } 121 }; 122 123 class IfStmt final : public Stmt { 124 public: 125 ptr<Expr> cond; 126 ptr<Stmt> thenPart; 127 ptr<Stmt> elsePart; 128 std::vector<ptr<Stmt>> inits; 129 130 IfStmt( const CodeLocation& loc, const Expr* cond, const Stmt* thenPart, 131 Stmt * const elsePart, std::vector<ptr<Stmt>>&& inits, 132 std::vector<Label>&& labels = {} ) 133 : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart), 134 inits(std::move(inits)) {} 135 136 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 137 private: 138 IfStmt* clone() const override { return new IfStmt{ *this }; } 139 }; 140 141 class SwitchStmt final : public Stmt { 142 public: 143 ptr<Expr> cond; 144 std::vector<ptr<Stmt>> stmts; 145 146 SwitchStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts, 147 std::vector<Label>&& labels = {} ) 148 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 149 150 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 151 private: 152 SwitchStmt* clone() const override { return new SwitchStmt{ *this }; } 153 }; 154 155 class CaseStmt final : public Stmt { 156 public: 157 ptr<Expr> cond; 158 std::vector<ptr<Stmt>> stmts; 159 160 CaseStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts, 161 std::vector<Label>&& labels = {} ) 162 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 163 164 bool isDefault() { return !cond; } 165 166 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 167 private: 168 CaseStmt* clone() const override { return new CaseStmt{ *this }; } 169 }; 170 171 class WhileStmt final : public Stmt { 172 public: 173 ptr<Expr> cond; 174 ptr<Stmt> body; 175 std::vector<ptr<Stmt>> inits; 176 bool isDoWhile; 177 178 WhileStmt( const CodeLocation& loc, const Expr* cond, const Stmt* body, 179 std::vector<ptr<Stmt>>&& inits, bool isDoWhile = false, std::vector<Label>&& labels = {} ) 180 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), 181 isDoWhile(isDoWhile) {} 182 183 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 184 private: 185 WhileStmt* clone() const override { return new WhileStmt{ *this }; } 186 }; 187 188 class ForStmt final : public Stmt { 189 public: 190 std::vector<ptr<Stmt>> inits; 191 ptr<Expr> cond; 192 ptr<Expr> increment; 193 ptr<Stmt> body; 194 195 ForStmt( const CodeLocation& loc, std::vector<ptr<Stmt>>&& inits, const Expr* cond, 196 const Expr* increment, const Stmt* body, std::vector<Label>&& labels = {} ) 197 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), increment(increment), 198 body(body) {} 199 200 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 201 private: 202 ForStmt* clone() const override { return new ForStmt{ *this }; } 203 }; 204 205 class BranchStmt final : public Stmt { 206 public: 207 enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault }; 208 static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault; 209 210 const Label originalTarget; 211 Label target; 212 ptr<Expr> computedTarget; 213 Kind kind; 214 215 BranchStmt( const CodeLocation& loc, Kind kind, Label target, 216 std::vector<Label>&& labels = {} ); 217 BranchStmt( const CodeLocation& loc, const Expr* computedTarget, 218 std::vector<Label>&& labels = {} ) 219 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), 220 computedTarget(computedTarget), kind(Goto) {} 221 222 const char * kindName() { return kindNames[kind]; } 223 224 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 225 private: 226 BranchStmt* clone() const override { return new BranchStmt{ *this }; } 227 static const char * kindNames[kindEnd]; 228 }; 229 230 class ReturnStmt final : public Stmt { 231 public: 232 ptr<Expr> expr; 233 234 ReturnStmt( const CodeLocation& loc, const Expr* expr, std::vector<Label>&& labels = {} ) 235 : Stmt(loc, std::move(labels)), expr(expr) {} 236 237 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 238 private: 239 ReturnStmt* clone() const override { return new ReturnStmt{ *this }; } 240 }; 241 242 class ThrowStmt final : public Stmt { 243 public: 244 enum Kind { Terminate, Resume }; 245 246 ptr<Expr> expr; 247 ptr<Expr> target; 248 Kind kind; 249 250 ThrowStmt( const CodeLocation& loc, Kind kind, const Expr* expr, const Expr* target, 251 std::vector<Label>&& labels = {} ) 252 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} 253 254 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 255 private: 256 ThrowStmt* clone() const override { return new ThrowStmt{ *this }; } 257 }; 258 259 class TryStmt final : public Stmt { 260 public: 261 ptr<CompoundStmt> body; 262 std::vector<ptr<CatchStmt>> handlers; 263 ptr<FinallyStmt> finally; 264 265 TryStmt( const CodeLocation& loc, const CompoundStmt* body, 266 std::vector<ptr<CatchStmt>>&& handlers, const FinallyStmt* finally, 267 std::vector<Label>&& labels = {} ) 268 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} 269 270 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 271 private: 272 TryStmt* clone() const override { return new TryStmt{ *this }; } 273 }; 274 275 class CatchStmt final : public Stmt { 276 public: 277 enum Kind { Terminate, Resume }; 278 279 ptr<Decl> decl; 280 ptr<Expr> cond; 281 ptr<Stmt> body; 282 Kind kind; 283 284 CatchStmt( const CodeLocation& loc, Kind kind, const Decl* decl, const Expr* cond, 285 const Stmt* body, std::vector<Label>&& labels = {} ) 286 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} 287 288 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 289 private: 290 CatchStmt* clone() const override { return new CatchStmt{ *this }; } 291 }; 292 293 class FinallyStmt final : public Stmt { 294 public: 295 ptr<CompoundStmt> body; 296 297 FinallyStmt( const CodeLocation& loc, const CompoundStmt* body, 298 std::vector<Label>&& labels = {} ) 299 : Stmt(loc, std::move(labels)), body(body) {} 300 301 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 302 private: 303 FinallyStmt* clone() const override { return new FinallyStmt{ *this }; } 304 }; 305 306 class WaitForStmt final : public Stmt { 307 public: 308 struct Target { 309 ptr<Expr> function; 310 std::vector<ptr<Expr>> arguments; 311 }; 312 313 struct Clause { 314 Target target; 315 ptr<Stmt> stmt; 316 ptr<Expr> cond; 317 }; 318 319 struct Timeout { 320 ptr<Expr> time; 321 ptr<Stmt> stmt; 322 ptr<Expr> cond; 323 }; 324 325 struct OrElse { 326 ptr<Stmt> stmt; 327 ptr<Expr> cond; 328 }; 329 330 std::vector<Clause> clauses; 331 Timeout timeout; 332 OrElse orElse; 333 334 WaitForStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} ) 335 : Stmt(loc, std::move(labels)) {} 336 337 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 338 private: 339 WaitForStmt* clone() const override { return new WaitForStmt{ *this }; } 340 }; 341 342 class WithStmt final : public Stmt { 343 public: 344 std::vector<ptr<Expr>> exprs; 345 ptr<Stmt> stmt; 346 347 WithStmt( const CodeLocation& loc, std::vector<ptr<Expr>>&& exprs, const Stmt* stmt, 348 std::vector<Label>&& labels = {} ) 349 : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {} 350 351 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 352 private: 353 WithStmt* clone() const override { return new WithStmt{ *this }; } 354 }; 355 356 class DeclStmt final : public Stmt { 357 public: 358 ptr<Decl> decl; 359 360 DeclStmt( const CodeLocation& loc, const Decl* decl, std::vector<Label>&& labels = {} ) 361 : Stmt(loc, std::move(labels)), decl(decl) {} 362 363 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 364 private: 365 DeclStmt* clone() const override { return new DeclStmt{ *this }; } 366 }; 367 368 class ImplicitCtorDtorStmt final : public Stmt { 369 public: 370 readonly<Stmt> callStmt; 371 372 ImplicitCtorDtorStmt( const CodeLocation& loc, const Stmt* callStmt, 373 std::vector<Label>&& labels = {} ) 374 : Stmt(loc, std::move(labels)), callStmt(callStmt) {} 375 376 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 377 private: 378 ImplicitCtorDtorStmt* clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 379 }; 90 380 91 381 //================================================================================================= -
src/AST/porting.md
r3648d98 r89c2f7c9 122 122 * `get_statement()` exclusively used for code location, replaced with `CodeLocation` field 123 123 124 `CaseStmt` 125 * `_isDefault` has been removed 126 * `isDefault` calculates value from `cond` 127 * default may not have a condition. I believe case (!default) requires a condition. 128 129 `BranchStmt` 130 * `Type` -> `Kind` and `type` -> `kind` 131 * Constructors no longer throw SemanticErrorException: 132 * `label` constructor claims it is now considered a syntax error, replaced with assert. 133 * `computedTarget` constructor assumes `Goto`, other check would have SegFaulted. 134 135 `TryStmt` 136 * `block` -> `body` and `finallyBlock` -> `finally` 137 138 `FinallyStmt` 139 * `block` -> `body` 140 124 141 `CompoundStmt` 125 142 * **TODO** port copy operator
Note: See TracChangeset
for help on using the changeset viewer.