Changeset 23f99e1
- Timestamp:
- May 15, 2019, 3:46:36 PM (5 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:
- 1e97287
- Parents:
- 54db6ba
- Location:
- src/AST
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.hpp
r54db6ba r23f99e1 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 … … 170 196 std::string genTypeString() const; 171 197 172 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 173 private: 174 virtual TypeDecl * clone() const override { return new TypeDecl{ *this }; } 198 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 199 private: 200 TypeDecl * clone() const override { return new TypeDecl{ *this }; } 201 202 /// Must be copied in ALL derived classes 203 template<typename node_t> 204 friend auto mutate(const node_t * node); 175 205 }; 176 206 … … 184 214 std::string typeString() const override { return "typedef"; } 185 215 186 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 187 private: 188 virtual TypedefDecl * clone() const override { return new TypedefDecl{ *this }; } 216 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 217 private: 218 TypedefDecl * clone() const override { return new TypedefDecl{ *this }; } 219 220 /// Must be copied in ALL derived classes 221 template<typename node_t> 222 friend auto mutate(const node_t * node); 189 223 }; 190 224 … … 224 258 bool is_thread() { return kind == DeclarationNode::Thread; } 225 259 226 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 227 private: 228 virtual StructDecl * clone() const override { return new StructDecl{ *this }; } 260 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 261 private: 262 StructDecl * clone() const override { return new StructDecl{ *this }; } 263 264 /// Must be copied in ALL derived classes 265 template<typename node_t> 266 friend auto mutate(const node_t * node); 229 267 230 268 std::string typeString() const override { return "struct"; } … … 238 276 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 239 277 240 virtual const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 241 private: 242 virtual UnionDecl * clone() const override { return new UnionDecl{ *this }; } 278 const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 279 private: 280 UnionDecl * clone() const override { return new UnionDecl{ *this }; } 281 282 /// Must be copied in ALL derived classes 283 template<typename node_t> 284 friend auto mutate(const node_t * node); 243 285 244 286 std::string typeString() const override { return "union"; } … … 255 297 bool valueOf( Decl* enumerator, long long& value ) const; 256 298 257 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 258 private: 259 virtual EnumDecl * clone() const override { return new EnumDecl{ *this }; } 299 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 300 private: 301 EnumDecl * clone() const override { return new EnumDecl{ *this }; } 302 303 /// Must be copied in ALL derived classes 304 template<typename node_t> 305 friend auto mutate(const node_t * node); 260 306 261 307 std::string typeString() const override { return "enum"; } … … 272 318 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 273 319 274 virtual const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 275 private: 276 virtual TraitDecl * clone() const override { return new TraitDecl{ *this }; } 320 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 321 private: 322 TraitDecl * clone() const override { return new TraitDecl{ *this }; } 323 324 /// Must be copied in ALL derived classes 325 template<typename node_t> 326 friend auto mutate(const node_t * node); 277 327 278 328 std::string typeString() const override { return "trait"; } 279 329 }; 280 330 331 class AsmDecl : public Decl { 332 public: 333 ptr<AsmStmt> stmt; 334 335 AsmDecl( const CodeLocation & loc, AsmStmt *stmt ) 336 : Decl( loc, "", {}, {} ), stmt(stmt) {} 337 338 const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); } 339 private: 340 AsmDecl *clone() const override { return new AsmDecl( *this ); } 341 342 /// Must be copied in ALL derived classes 343 template<typename node_t> 344 friend auto mutate(const node_t * node); 345 }; 346 347 class StaticAssertDecl : public Decl { 348 public: 349 ptr<Expr> condition; 350 ptr<ConstantExpr> msg; // string literal 351 352 StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg ) 353 : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {} 354 355 const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); } 356 private: 357 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 358 359 /// Must be copied in ALL derived classes 360 template<typename node_t> 361 friend auto mutate(const node_t * node); 362 }; 281 363 282 364 //================================================================================================= … … 291 373 inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); } 292 374 inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); } 293 //inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }294 //inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }375 inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); } 376 inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); } 295 377 inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); } 296 378 inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); } … … 307 389 inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); } 308 390 inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); } 309 // inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }310 // inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }311 // inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }312 // inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }313 391 inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); } 314 392 inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); } 315 //inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }316 //inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }317 //inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }318 //inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }393 inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); } 394 inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); } 395 inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); } 396 inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); } 319 397 320 398 } -
src/AST/Expr.hpp
r54db6ba r23f99e1 121 121 Expr* set_extension( bool ex ) { extension = ex; return this; } 122 122 123 virtualconst Expr * accept( Visitor& v ) const override = 0;123 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
r54db6ba r23f99e1 33 33 class NamedTypeDecl; 34 34 class TypeDecl; 35 class FtypeDecl;36 class DtypeDecl;37 35 class TypedefDecl; 38 36 class AsmDecl; … … 171 169 inline void increment( const class TypeDecl *, Node::ref_type ); 172 170 inline void decrement( const class TypeDecl *, Node::ref_type ); 173 inline void increment( const class FtypeDecl *, Node::ref_type );174 inline void decrement( const class FtypeDecl *, Node::ref_type );175 inline void increment( const class DtypeDecl *, Node::ref_type );176 inline void decrement( const class DtypeDecl *, Node::ref_type );177 171 inline void increment( const class TypedefDecl *, Node::ref_type ); 178 172 inline void decrement( const class TypedefDecl *, Node::ref_type ); -
src/AST/Init.hpp
r54db6ba r23f99e1 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 … … 49 49 Init( const CodeLocation& loc, bool mc ) : ParseNode( loc ), maybeConstructed( mc ) {} 50 50 51 virtualconst Init * accept( Visitor& v ) const override = 0;51 const Init * accept( Visitor& v ) const override = 0; 52 52 private: 53 virtualconst Init * clone() const override = 0;53 const Init * clone() const override = 0; 54 54 }; 55 55 … … 63 63 : Init( loc, mc ), value( val ) {} 64 64 65 virtualconst Init * accept( Visitor & v ) const override { return v.visit( this ); }65 const Init * accept( Visitor & v ) const override { return v.visit( this ); } 66 66 private: 67 virtualSingleInit * clone() const override { return new SingleInit{ *this }; }67 SingleInit * clone() const override { return new SingleInit{ *this }; } 68 68 69 69 /// Must be copied in ALL derived classes … … 91 91 const_iterator end() const { return initializers.end(); } 92 92 93 virtualconst Init * accept( Visitor & v ) const override { return v.visit( this ); }93 const Init * accept( Visitor & v ) const override { return v.visit( this ); } 94 94 private: 95 virtualListInit * clone() const override { return new ListInit{ *this }; }95 ListInit * clone() const override { return new ListInit{ *this }; } 96 96 97 97 /// Must be copied in ALL derived classes … … 114 114 : Init( loc, true ), ctor( ctor ), dtor( dtor ), init( init ) {} 115 115 116 virtualconst Init * accept( Visitor & v ) const override { return v.visit( this ); }116 const Init * accept( Visitor & v ) const override { return v.visit( this ); } 117 117 private: 118 virtualConstructorInit * clone() const override { return new ConstructorInit{ *this }; }118 ConstructorInit * clone() const override { return new ConstructorInit{ *this }; } 119 119 120 120 /// Must be copied in ALL derived classes -
src/AST/Pass.hpp
r54db6ba r23f99e1 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::AttrType * ) override final;170 virtualconst ast::Type * visit( const ast::VarArgsType * ) override final;171 virtualconst ast::Type * visit( const ast::ZeroType * ) override final;172 virtualconst ast::Type * visit( const ast::OneType * ) override final;173 virtualconst ast::Type * visit( const ast::GlobalScopeType * ) override final;174 virtualconst ast::Designation * visit( const ast::Designation * ) override final;175 virtualconst ast::Init * visit( const ast::SingleInit * ) override final;176 virtualconst ast::Init * visit( const ast::ListInit * ) override final;177 virtualconst ast::Init * visit( const ast::ConstructorInit * ) override final;178 virtualconst ast::Constant * visit( const ast::Constant * ) override final;179 virtualconst ast::Attribute * visit( const ast::Attribute * ) override final;180 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::AttrType * ) override final; 170 const ast::Type * visit( const ast::VarArgsType * ) override final; 171 const ast::Type * visit( const ast::ZeroType * ) override final; 172 const ast::Type * visit( const ast::OneType * ) override final; 173 const ast::Type * visit( const ast::GlobalScopeType * ) override final; 174 const ast::Designation * visit( const ast::Designation * ) override final; 175 const ast::Init * visit( const ast::SingleInit * ) override final; 176 const ast::Init * visit( const ast::ListInit * ) override final; 177 const ast::Init * visit( const ast::ConstructorInit * ) override final; 178 const ast::Constant * visit( const ast::Constant * ) override final; 179 const ast::Attribute * visit( const ast::Attribute * ) override final; 180 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) override final; 181 181 182 182 friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor ); … … 216 216 Pass<pass_t> & pass; 217 217 }; 218 219 private: 220 bool inFunction = false; 218 221 }; 219 222 -
src/AST/Pass.impl.hpp
r54db6ba r23f99e1 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.hpp
r54db6ba r23f99e1 40 40 Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {} 41 41 42 virtualconst Stmt* accept( Visitor& v ) const override = 0;42 const Stmt* accept( Visitor& v ) const override = 0; 43 43 private: 44 virtualStmt* clone() const override = 0;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 ); }61 const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); } 62 62 private: 63 virtualCompoundStmt* clone() const override { return new CompoundStmt{ *this }; }63 CompoundStmt* clone() const override { return new CompoundStmt{ *this }; } 64 64 }; 65 65 … … 70 70 : Stmt(loc, std::move(labels)) {} 71 71 72 virtualconst NullStmt * accept( Visitor& v ) const override { return v.visit( this ); }72 const NullStmt * accept( Visitor& v ) const override { return v.visit( this ); } 73 73 private: 74 virtualNullStmt * clone() const override { return new NullStmt{ *this }; }74 NullStmt * clone() const override { return new NullStmt{ *this }; } 75 75 }; 76 76 … … 82 82 ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {} 83 83 84 virtualconst Stmt * accept( Visitor& v ) const override { return v.visit( this ); }84 const Stmt * accept( Visitor& v ) const override { return v.visit( this ); } 85 85 private: 86 virtualExprStmt * clone() const override { return new ExprStmt{ *this }; }86 ExprStmt * clone() const override { return new ExprStmt{ *this }; } 87 87 }; 88 88
Note: See TracChangeset
for help on using the changeset viewer.