Changeset 69bafd2
- Timestamp:
- May 15, 2019, 3:57:26 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 3648d98
- Parents:
- 9e1d485 (diff), be567e9 (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:
-
- 4 added
- 1 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/vtable.md
r9e1d485 r69bafd2 1 1 Proposal For Use of Virtual Tables 2 2 ================================== 3 4 This is an adaptation of the earlier virtual proposal, updating it with new5 ideas, re-framing it and laying out more design decisions. It should6 eventually replace the earlier proposal, but not all features and syntax have7 been converted to the new design.8 3 9 4 The basic concept of a virtual table (vtable) is the same here as in most … … 93 88 } 94 89 } 90 91 With a more complete widget trait you could, for example, construct a UI tool 92 kit that can declare containers that hold widgets without knowing about the 93 widget types. Making it reasonable to extend the tool kit. 95 94 96 95 The trait types can also be used in the types of assertions on traits as well. … … 244 243 We would also like to implement hierarchical relations between types. 245 244 246 AstNode 247 |-ParseNode 248 | |-Declaration 249 | | |-DeclarationWithType 250 | | |-StructureDeclaration 251 | |-Statement 252 | | |-CompoundStatement 253 | |-Expression 254 |-Type 245 ast_node 246 |-expression_node 247 | |-operator_expression 248 | 249 |-statement_node 250 | |-goto_statement 251 | 252 |-declaration_node 253 |-using_declaration 254 |-variable_declaration 255 255 256 256 Virtual tables by themselves are not quite enough to implement this system. … … 315 315 } 316 316 317 This system does not support multiple inheritance. The system could be 318 extended to support it or a limited form (ex. you may have multiple parents 319 but they may not have a common ancestor). However this proposal focuses just 320 on using hierachy as organization. Other uses for reusable/genaric code or 321 shared interfaces is left for other features of the language. 322 317 323 ### Extension: Structural Inheritance 318 324 An extension would be allow structures to be used as internal nodes on the … … 354 360 solution but only works if we have exactly 1 vtable for each type. The second 355 361 is to put a pointer to the type id in each vtable. This has more overhead but 356 allows multiple vtables .362 allows multiple vtables per type. 357 363 358 364 struct <trait>_vtable { … … 367 373 // Trait dependent list of vtable members. 368 374 }; 375 376 One important restriction is that only one instance of each typeid in memory. 377 There is a ".gnu.linkonce" feature in the linker that might solve the issue. 369 378 370 379 ### Virtual Casts … … 423 432 io_error * error = (virtual)exc; 424 433 434 #### Sample Implementation 435 This cast implementation assumes a type id layout similar to the one given 436 above. Also this code is definitely in the underlying C. Functions that give 437 this functionality could exist in the standard library but these are meant to 438 be produced by code translation of the virtual cast. 439 440 bool is_in_subtree(typeid const * root, typeid const * id) { 441 if (root == id) { 442 return true 443 } else if (NULL == id->parent) { 444 return false; 445 } else { 446 return is_in_subtree(root, id->parent); 447 } 448 } 449 450 void * virtual_cast(typeid const * target, void * value) { 451 return is_in_subtree(target, *(typeid const **)value) ? value : NULL; 452 } 453 454 The virtual cast function might have to be wrapped with some casts to make it 455 compile without warning. 456 457 For the implicate target type we may be able to lean on the type resolution 458 system that already exists. If the casting to ancestor type is built into 459 the resolution then the impicate target could be decided by picking an 460 overload, generated for each hierarchial type (here io_error and its root 461 type exception). 462 463 io_error * virtual_cast(exception * value) { 464 return virtual_cast(io_error_typeid, value); 465 } 466 425 467 ### Extension: Inline vtables 426 468 Since the structures here are usually made to be turned into trait objects … … 436 478 to allow access to all three options. 437 479 480 The pointer to virtual table field on structures might implicately added (the 481 types have to declare they are a child here) or created with a declaration, 482 possibly like the one used to create the assertion. 483 438 484 ### Virtual Tables as Types 439 485 Here we consider encoding plus the implementation of functions on it to be a … … 442 488 and implementation. 443 489 490 ### Question: Wrapping Structures 491 One issue is what to do with concrete types at the base of the type tree. 492 When we are working with the concrete type generally it would like them to be 493 regular structures with direct calls. On the other hand for interactions with 494 other types in the hierarchy it is more convenent for the type already to be 495 cast. 496 497 Which of these two should we use? Should we support both and if so how do we 498 choose which one is being used at any given time. 499 500 On a related note I have been using pointers two trait types here, as that 501 is how many existing languages handle it. However the generic objects might 502 be only one or two pointers wide passing the objects as a whole would not 503 be very expensive and all operations on the generic objects probably have 504 to be defined anyways. 505 444 506 Resolution Scope 445 507 ---------------- … … 534 596 Stack allocated functions interact badly with this because they are not 535 597 static. There are several ways to try to resolve this, however without a 536 general solution most can only buy time. 598 general solution most can keep vtables from making the existing thunk problem 599 worse, they don't do anything to solve it. 537 600 538 601 Filling in some fields of a static vtable could cause issues on a recursive … … 549 612 shortest lifetime of a function assigned to it. However this still limits the 550 613 lifetime "implicitly" and returns to the original problem with thunks. 614 615 Odds And Ends 616 ------------- 617 618 In addition to the main design there are a few extras that should be 619 considered. They are not part of the core design but make the new uses fully 620 featured. 621 622 ### Extension: Parent-Child Assertion 623 For hierarchy types in regular traits, generic functions or generic structures 624 we may want to be able to check parent-child relationships between two types 625 given. For this we might have to add another primitive assertion. It would 626 have the following form if declared in code: 627 628 trait is_parent_child(dtype Parent, dtype Child) { <built-in magic> } 629 630 This assertion is satified if Parent is an ancestor of Child in a hierarchy. 631 In other words Child can be statically cast to Parent. The cast from Parent 632 to child would be dynamically checked as usual. 633 634 However in this form there are two concerns. The first that Parent will 635 usually be consistent for a given use, it will not be a variable. Second is 636 that we may also need the assertion functions. To do any casting/conversions 637 anyways. 638 TODO: Talk about when we wrap a concrete type and how that leads to "may". 639 640 To this end it may be better that the parent trait combines the usual 641 assertions plus this new primitive assertion. There may or may not be use 642 cases for accessing just one half and providing easy access to them may be 643 required depending on how that turns out. 644 645 trait Parent(dtype T | interface(T)) virtual(<grand-parent?>) { } 646 647 ### Extension: sizeof Compatablity 648 Trait types are always sized, it may even be a fixed size like how pointers 649 have the same size regardless of what they point at. However their contents 650 may or may not be of a known size (if the `sized(...)` assertion is used). 651 652 Currently there is no way to access this information. If it is needed a 653 special syntax would have to be added. Here a special case of `sizeof` is 654 used. 655 656 struct line aLine; 657 trait drawable widget = aLine; 658 659 size_t x = sizeof(widget); 660 size_t y = sizeof(trait drawable); 661 662 As usual `y`, size of the type, is the size of the local storage used to put 663 the value into. The other case `x` checks the saved stored value in the 664 virtual table and returns that. -
src/AST/Attribute.hpp
r9e1d485 r69bafd2 19 19 #include <vector> 20 20 21 #include "Fwd.hpp" 21 22 #include "Node.hpp" // for ptr 22 23 #include "Visitor.hpp" … … 31 32 std::vector<ptr<Expr>> parameters; 32 33 33 Attribute( const std::string & name = "", std::vector<ptr<Expr>>&& params = {})34 Attribute( const std::string & name = "", std::vector<ptr<Expr>> && params = {}) 34 35 : name( name ), parameters( params ) {} 36 virtual ~Attribute() = default; 35 37 36 38 bool empty() const { return name.empty(); } … … 42 44 bool isValidOnFuncParam() const; 43 45 44 Attribute* accept( Visitor& v )override { return v.visit( this ); }46 const Attribute * accept( Visitor & v ) const override { return v.visit( this ); } 45 47 private: 46 Attribute* clone() const override { return new Attribute{ *this }; } 48 Attribute * clone() const override { return new Attribute{ *this }; } 49 50 /// Must be copied in ALL derived classes 51 template<typename node_t> 52 friend auto mutate(const node_t * node); 47 53 }; 48 54 -
src/AST/Decl.hpp
r9e1d485 r69bafd2 57 57 static readonly<Decl> fromId( UniqueId id ); 58 58 59 virtual Decl* accept( Visitor& v )override = 0;60 private: 61 virtual Decl * clone() const override = 0;59 virtual const Decl * accept( Visitor & v ) const override = 0; 60 private: 61 virtual Decl * clone() const override = 0; 62 62 }; 63 63 … … 85 85 86 86 /// Get type of this declaration. May be generated by subclass 87 virtual const Type * get_type() const = 0;87 virtual const Type * get_type() const = 0; 88 88 /// Set type of this declaration. May be verified by subclass 89 89 virtual void set_type(Type*) = 0; 90 90 91 virtual DeclWithType* accept( Visitor& v )override = 0;92 private: 93 virtual DeclWithType * clone() const override = 0;91 virtual const DeclWithType * accept( Visitor & v ) const override = 0; 92 private: 93 virtual DeclWithType * clone() const override = 0; 94 94 }; 95 95 … … 110 110 void set_type( Type* ty ) override { type = ty; } 111 111 112 DeclWithType* accept( Visitor& v ) override { return v.visit( this ); } 113 private: 114 ObjectDecl* clone() const override { return new ObjectDecl{ *this }; } 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 }; } 115 116 /// Must be copied in ALL derived classes 117 template<typename node_t> 118 friend auto mutate(const node_t * node); 115 119 }; 116 120 … … 169 173 bool isComplete() { return sized; } 170 174 171 Decl* accept( Visitor& v )override { return v.visit( this ); }172 private: 173 TypeDecl* clone() const override { return new TypeDecl{ *this }; }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 }; } 174 178 }; 175 179 … … 183 187 std::string typeString() const override { return "typedef"; } 184 188 185 Decl* accept( Visitor& v )override { return v.visit( this ); }186 private: 187 TypedefDecl* clone() const override { return new TypedefDecl{ *this }; }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 }; } 188 192 }; 189 193 … … 223 227 bool is_thread() { return kind == DeclarationNode::Thread; } 224 228 225 Decl* accept( Visitor& v )override { return v.visit( this ); }226 private: 227 StructDecl* clone() const override { return new StructDecl{ *this }; }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 }; } 228 232 229 233 std::string typeString() const override { return "struct"; } … … 237 241 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 238 242 239 Decl* accept( Visitor& v )override { return v.visit( this ); }240 private: 241 UnionDecl* clone() const override { return new UnionDecl{ *this }; }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 }; } 242 246 243 247 std::string typeString() const override { return "union"; } … … 254 258 bool valueOf( Decl* enumerator, long long& value ) const; 255 259 256 Decl* accept( Visitor& v )override { return v.visit( this ); }257 private: 258 EnumDecl* clone() const override { return new EnumDecl{ *this }; }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 }; } 259 263 260 264 std::string typeString() const override { return "enum"; } … … 271 275 : AggregateDecl( loc, name, std::move(attrs), linkage ) {} 272 276 273 Decl* accept( Visitor& v )override { return v.visit( this ); }274 private: 275 TraitDecl* clone() const override { return new TraitDecl{ *this }; }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 }; } 276 280 277 281 std::string typeString() const override { return "trait"; } … … 290 294 inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); } 291 295 inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); } 292 inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }293 inline void decrement( const class FunctionDecl * 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); } 294 298 inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); } 295 299 inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); } … … 306 310 inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); } 307 311 inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); } 308 inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }309 inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }310 inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }311 inline void decrement( const class DtypeDecl * 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); } 312 316 inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); } 313 317 inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); } 314 inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }315 inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }316 inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }317 inline void decrement( const class StaticAssertDecl * 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); } 318 322 319 323 } -
src/AST/Expr.hpp
r9e1d485 r69bafd2 27 27 namespace ast { 28 28 29 /// Contains the ID of a declaration and a type that is derived from that declaration, 29 /// Contains the ID of a declaration and a type that is derived from that declaration, 30 30 /// but subject to decay-to-pointer and type parameter renaming 31 31 struct ParamEntry { … … 74 74 case Empty: return; 75 75 case Slots: new(&data.resnSlots) ResnSlots{ std::move(o.data.resnSlots) }; return; 76 case Params: 76 case Params: 77 77 new(&data.inferParams) InferredParams{ std::move(o.data.inferParams) }; return; 78 78 } … … 121 121 Expr * set_extension( bool ex ) { extension = ex; return this; } 122 122 123 virtual Expr * accept( Visitor & v )override = 0;123 virtual const Expr * accept( Visitor & v ) const override = 0; 124 124 private: 125 125 virtual Expr * clone() const override = 0; … … 133 133 TypeExpr( const CodeLocation & loc, const Type * t ) : Expr(loc), type(t) {} 134 134 135 Expr * accept( Visitor & v )override { return v.visit( this ); }135 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 136 136 private: 137 137 TypeExpr * clone() const override { return new TypeExpr{ *this }; } 138 138 }; 139 139 140 141 //================================================================================================= 142 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency 143 /// remove only if there is a better solution 144 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with 145 /// forward declarations 146 inline void increment( const class Expr * node, Node::ref_type ref ) { node->increment(ref); } 147 inline void decrement( const class Expr * node, Node::ref_type ref ) { node->decrement(ref); } 148 // inline void increment( const class ApplicationExpr * node, Node::ref_type ref ) { node->increment(ref); } 149 // inline void decrement( const class ApplicationExpr * node, Node::ref_type ref ) { node->decrement(ref); } 150 // inline void increment( const class UntypedExpr * node, Node::ref_type ref ) { node->increment(ref); } 151 // inline void decrement( const class UntypedExpr * node, Node::ref_type ref ) { node->decrement(ref); } 152 // inline void increment( const class NameExpr * node, Node::ref_type ref ) { node->increment(ref); } 153 // inline void decrement( const class NameExpr * node, Node::ref_type ref ) { node->decrement(ref); } 154 // inline void increment( const class AddressExpr * node, Node::ref_type ref ) { node->increment(ref); } 155 // inline void decrement( const class AddressExpr * node, Node::ref_type ref ) { node->decrement(ref); } 156 // inline void increment( const class LabelAddressExpr * node, Node::ref_type ref ) { node->increment(ref); } 157 // inline void decrement( const class LabelAddressExpr * node, Node::ref_type ref ) { node->decrement(ref); } 158 // inline void increment( const class CastExpr * node, Node::ref_type ref ) { node->increment(ref); } 159 // inline void decrement( const class CastExpr * node, Node::ref_type ref ) { node->decrement(ref); } 160 // inline void increment( const class KeywordCastExpr * node, Node::ref_type ref ) { node->increment(ref); } 161 // inline void decrement( const class KeywordCastExpr * node, Node::ref_type ref ) { node->decrement(ref); } 162 // inline void increment( const class VirtualCastExpr * node, Node::ref_type ref ) { node->increment(ref); } 163 // inline void decrement( const class VirtualCastExpr * node, Node::ref_type ref ) { node->decrement(ref); } 164 // inline void increment( const class MemberExpr * node, Node::ref_type ref ) { node->increment(ref); } 165 // inline void decrement( const class MemberExpr * node, Node::ref_type ref ) { node->decrement(ref); } 166 // inline void increment( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->increment(ref); } 167 // inline void decrement( const class UntypedMemberExpr * node, Node::ref_type ref ) { node->decrement(ref); } 168 // inline void increment( const class VariableExpr * node, Node::ref_type ref ) { node->increment(ref); } 169 // inline void decrement( const class VariableExpr * node, Node::ref_type ref ) { node->decrement(ref); } 170 // inline void increment( const class ConstantExpr * node, Node::ref_type ref ) { node->increment(ref); } 171 // inline void decrement( const class ConstantExpr * node, Node::ref_type ref ) { node->decrement(ref); } 172 // inline void increment( const class SizeofExpr * node, Node::ref_type ref ) { node->increment(ref); } 173 // inline void decrement( const class SizeofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 174 // inline void increment( const class AlignofExpr * node, Node::ref_type ref ) { node->increment(ref); } 175 // inline void decrement( const class AlignofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 176 // inline void increment( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); } 177 // inline void decrement( const class UntypedOffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 178 // inline void increment( const class OffsetofExpr * node, Node::ref_type ref ) { node->increment(ref); } 179 // inline void decrement( const class OffsetofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 180 // inline void increment( const class OffsetPackExpr * node, Node::ref_type ref ) { node->increment(ref); } 181 // inline void decrement( const class OffsetPackExpr * node, Node::ref_type ref ) { node->decrement(ref); } 182 // inline void increment( const class AttrExpr * node, Node::ref_type ref ) { node->increment(ref); } 183 // inline void decrement( const class AttrExpr * node, Node::ref_type ref ) { node->decrement(ref); } 184 // inline void increment( const class LogicalExpr * node, Node::ref_type ref ) { node->increment(ref); } 185 // inline void decrement( const class LogicalExpr * node, Node::ref_type ref ) { node->decrement(ref); } 186 // inline void increment( const class ConditionalExpr * node, Node::ref_type ref ) { node->increment(ref); } 187 // inline void decrement( const class ConditionalExpr * node, Node::ref_type ref ) { node->decrement(ref); } 188 // inline void increment( const class CommaExpr * node, Node::ref_type ref ) { node->increment(ref); } 189 // inline void decrement( const class CommaExpr * node, Node::ref_type ref ) { node->decrement(ref); } 190 // inline void increment( const class TypeExpr * node, Node::ref_type ref ) { node->increment(ref); } 191 // inline void decrement( const class TypeExpr * node, Node::ref_type ref ) { node->decrement(ref); } 192 // inline void increment( const class AsmExpr * node, Node::ref_type ref ) { node->increment(ref); } 193 // inline void decrement( const class AsmExpr * node, Node::ref_type ref ) { node->decrement(ref); } 194 // inline void increment( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->increment(ref); } 195 // inline void decrement( const class ImplicitCopyCtorExpr * node, Node::ref_type ref ) { node->decrement(ref); } 196 // inline void increment( const class ConstructorExpr * node, Node::ref_type ref ) { node->increment(ref); } 197 // inline void decrement( const class ConstructorExpr * node, Node::ref_type ref ) { node->decrement(ref); } 198 // inline void increment( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->increment(ref); } 199 // inline void decrement( const class CompoundLiteralExpr * node, Node::ref_type ref ) { node->decrement(ref); } 200 // inline void increment( const class UntypedValofExpr * node, Node::ref_type ref ) { node->increment(ref); } 201 // inline void decrement( const class UntypedValofExpr * node, Node::ref_type ref ) { node->decrement(ref); } 202 // inline void increment( const class RangeExpr * node, Node::ref_type ref ) { node->increment(ref); } 203 // inline void decrement( const class RangeExpr * node, Node::ref_type ref ) { node->decrement(ref); } 204 // inline void increment( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->increment(ref); } 205 // inline void decrement( const class UntypedTupleExpr * node, Node::ref_type ref ) { node->decrement(ref); } 206 // inline void increment( const class TupleExpr * node, Node::ref_type ref ) { node->increment(ref); } 207 // inline void decrement( const class TupleExpr * node, Node::ref_type ref ) { node->decrement(ref); } 208 // inline void increment( const class TupleIndexExpr * node, Node::ref_type ref ) { node->increment(ref); } 209 // inline void decrement( const class TupleIndexExpr * node, Node::ref_type ref ) { node->decrement(ref); } 210 // inline void increment( const class TupleAssignExpr * node, Node::ref_type ref ) { node->increment(ref); } 211 // inline void decrement( const class TupleAssignExpr * node, Node::ref_type ref ) { node->decrement(ref); } 212 // inline void increment( const class StmtExpr * node, Node::ref_type ref ) { node->increment(ref); } 213 // inline void decrement( const class StmtExpr * node, Node::ref_type ref ) { node->decrement(ref); } 214 // inline void increment( const class UniqueExpr * node, Node::ref_type ref ) { node->increment(ref); } 215 // inline void decrement( const class UniqueExpr * node, Node::ref_type ref ) { node->decrement(ref); } 216 // inline void increment( const class UntypedInitExpr * node, Node::ref_type ref ) { node->increment(ref); } 217 // inline void decrement( const class UntypedInitExpr * node, Node::ref_type ref ) { node->decrement(ref); } 218 // inline void increment( const class InitExpr * node, Node::ref_type ref ) { node->increment(ref); } 219 // inline void decrement( const class InitExpr * node, Node::ref_type ref ) { node->decrement(ref); } 220 // inline void increment( const class DeletedExpr * node, Node::ref_type ref ) { node->increment(ref); } 221 // inline void decrement( const class DeletedExpr * node, Node::ref_type ref ) { node->decrement(ref); } 222 // inline void increment( const class DefaultArgExpr * node, Node::ref_type ref ) { node->increment(ref); } 223 // inline void decrement( const class DefaultArgExpr * node, Node::ref_type ref ) { node->decrement(ref); } 224 // inline void increment( const class GenericExpr * node, Node::ref_type ref ) { node->increment(ref); } 225 // inline void decrement( const class GenericExpr * node, Node::ref_type ref ) { node->decrement(ref); } 140 226 } 141 227 -
src/AST/Fwd.hpp
r9e1d485 r69bafd2 136 136 137 137 class TypeSubstitution; 138 139 std::string toString( const Node * ); 138 140 139 141 //================================================================================================= … … 352 354 inline void increment( const class Constant *, Node::ref_type ); 353 355 inline void decrement( const class Constant *, Node::ref_type ); 354 inline void increment( const class Label *, Node::ref_type );355 inline void decrement( const class Label *, Node::ref_type );356 356 inline void increment( const class Attribute *, Node::ref_type ); 357 357 inline void decrement( const class Attribute *, Node::ref_type ); -
src/AST/Init.hpp
r9e1d485 r69bafd2 37 37 : ParseNode( loc ), designators( std::move(ds) ) {} 38 38 39 Designation* accept( Visitor& v )override { return v.visit( this ); }39 virtual const Designation* accept( Visitor& v ) const override { return v.visit( this ); } 40 40 private: 41 Designation* clone() const override { return new Designation{ *this }; }41 virtual 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 virtual Init* accept( Visitor& v )override = 0;54 virtual const Init * accept( Visitor& v ) const override = 0; 55 55 private: 56 virtual Init* clone() const override = 0;56 virtual const Init * clone() const override = 0; 57 57 }; 58 58 … … 66 66 : Init( loc, mc ), value( val ) {} 67 67 68 Init* accept( Visitor& v )override { return v.visit( this ); }68 virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); } 69 69 private: 70 SingleInit* clone() const override { return new SingleInit{ *this }; } 70 virtual SingleInit * clone() const override { return new SingleInit{ *this }; } 71 72 /// Must be copied in ALL derived classes 73 template<typename node_t> 74 friend auto mutate(const node_t * node); 71 75 }; 72 76 … … 90 94 const_iterator end() const { return initializers.end(); } 91 95 92 Init* accept( Visitor& v )override { return v.visit( this ); }96 virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); } 93 97 private: 94 ListInit* clone() const override { return new ListInit{ *this }; } 98 virtual ListInit * clone() const override { return new ListInit{ *this }; } 99 100 /// Must be copied in ALL derived classes 101 template<typename node_t> 102 friend auto mutate(const node_t * node); 95 103 }; 96 104 … … 109 117 : Init( loc, DoConstruct ), ctor( ctor ), dtor( dtor ), init( init ) {} 110 118 111 Init* accept( Visitor& v )override { return v.visit( this ); }119 virtual const Init * accept( Visitor & v ) const override { return v.visit( this ); } 112 120 private: 113 ConstructorInit* clone() const override { return new ConstructorInit{ *this }; } 121 virtual ConstructorInit * clone() const override { return new ConstructorInit{ *this }; } 122 123 /// Must be copied in ALL derived classes 124 template<typename node_t> 125 friend auto mutate(const node_t * node); 114 126 }; 115 127 -
src/AST/Label.hpp
r9e1d485 r69bafd2 35 35 36 36 Label( CodeLocation loc, const std::string& name = "", 37 const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )37 std::vector<ptr<Attribute>> && attrs = std::vector<ptr<Attribute>>{} ) 38 38 : location( loc ), name( name ), attributes( attrs ) {} 39 39 … … 48 48 inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; } 49 49 50 51 //=================================================================================================52 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency53 /// remove only if there is a better solution54 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with55 /// forward declarations56 inline void increment( const class Label * node, Node::ref_type ref ) { node->increment( ref ); }57 inline void decrement( const class Label * node, Node::ref_type ref ) { node->decrement( ref ); }58 59 50 } 60 51 -
src/AST/Node.hpp
r9e1d485 r69bafd2 30 30 // change/share reference counts 31 31 Node() = default; 32 Node(const Node&) : strong_ ref(0), weak_ref(0) {}33 Node(Node&&) : strong_ ref(0), weak_ref(0) {}32 Node(const Node&) : strong_count(0), weak_count(0) {} 33 Node(Node&&) : strong_count(0), weak_count(0) {} 34 34 Node& operator= (const Node&) = delete; 35 35 Node& operator= (Node&&) = delete; 36 36 virtual ~Node() = default; 37 37 38 virtual Node* accept( Visitor& v )= 0;38 virtual const Node * accept( Visitor & v ) const = 0; 39 39 40 40 /// Types of node references … … 46 46 inline void increment(ref_type ref) const { 47 47 switch (ref) { 48 case ref_type::strong: strong_ ref++; break;49 case ref_type::weak : weak_ ref++; break;48 case ref_type::strong: strong_count++; break; 49 case ref_type::weak : weak_count ++; break; 50 50 } 51 51 } … … 53 53 inline void decrement(ref_type ref) const { 54 54 switch (ref) { 55 case ref_type::strong: strong_ ref--; break;56 case ref_type::weak : weak_ ref--; break;55 case ref_type::strong: strong_count--; break; 56 case ref_type::weak : weak_count --; break; 57 57 } 58 58 59 if(!strong_ ref && !weak_ref) {59 if(!strong_count && !weak_count) { 60 60 delete this; 61 61 } 62 62 } 63 private: 64 /// Make a copy of this node; should be overridden in subclass with more precise return type 65 virtual const Node * clone() const = 0; 63 66 67 /// Must be copied in ALL derived classes 64 68 template<typename node_t> 65 69 friend auto mutate(const node_t * node); 66 70 67 private: 68 /// Make a copy of this node; should be overridden in subclass with more precise return type 69 virtual Node* clone() const = 0; 70 71 mutable size_t strong_ref = 0; 72 mutable size_t weak_ref = 0; 71 mutable size_t strong_count = 0; 72 mutable size_t weak_count = 0; 73 73 }; 74 74 … … 100 100 public: 101 101 ptr_base() : node(nullptr) {} 102 ptr_base( const node_t * n ) : node(n) { if( node ) node->increment(ref_t); }103 ~ptr_base() { if( node ) node->decrement(ref_t); }102 ptr_base( const node_t * n ) : node(n) { if( node ) increment(node, ref_t); } 103 ~ptr_base() { if( node ) decrement(node, ref_t); } 104 104 105 105 template< enum Node::ref_type o_ref_t > 106 106 ptr_base( const ptr_base<node_t, o_ref_t> & o ) : node(o.node) { 107 if( node ) node->increment(ref_t);107 if( node ) increment(node, ref_t); 108 108 } 109 109 110 110 template< enum Node::ref_type o_ref_t > 111 111 ptr_base( ptr_base<node_t, o_ref_t> && o ) : node(o.node) { 112 if( node ) node->increment(ref_t); 112 if( node ) increment(node, ref_t); 113 } 114 115 template<typename o_node_t> 116 ptr_base & operator=( const o_node_t * node ) { 117 assign(strict_dynamic_cast<const node_t *>(node)); 118 return *this; 113 119 } 114 120 … … 138 144 private: 139 145 void assign( const node_t * other ) { 140 if( other ) other->increment(ref_t);141 if( node ) node ->decrement(ref_t);146 if( other ) increment(other, ref_t); 147 if( node ) decrement(node , ref_t); 142 148 node = other; 143 149 } -
src/AST/Pass.hpp
r9e1d485 r69bafd2 23 23 #include "AST/Fwd.hpp" 24 24 #include "AST/Node.hpp" 25 26 #include "AST/Attribute.hpp" 25 27 #include "AST/Decl.hpp" 28 #include "AST/Expr.hpp" 29 #include "AST/Init.hpp" 30 #include "AST/Stmt.hpp" 31 26 32 #include "AST/Visitor.hpp" 27 33 … … 79 85 80 86 /// Visit function declarations 81 virtual DeclWithType * visit( constObjectDecl * ) override final;82 virtual DeclWithType * visit( constFunctionDecl * ) override final;83 virtual Decl * visit( constStructDecl * ) override final;84 virtual Decl * visit( constUnionDecl * ) override final;85 virtual Decl * visit( constEnumDecl * ) override final;86 virtual Decl * visit( constTraitDecl * ) override final;87 virtual Decl * visit( constTypeDecl * ) override final;88 virtual Decl * visit( constTypedefDecl * ) override final;89 virtual AsmDecl * visit( constAsmDecl * ) override final;90 virtual StaticAssertDecl * visit( constStaticAssertDecl * ) override final;91 virtual CompoundStmt * visit( constCompoundStmt * ) override final;92 virtual Stmt * visit( constExprStmt * ) override final;93 virtual Stmt * visit( constAsmStmt * ) override final;94 virtual Stmt * visit( constDirectiveStmt * ) override final;95 virtual Stmt * visit( constIfStmt * ) override final;96 virtual Stmt * visit( constWhileStmt * ) override final;97 virtual Stmt * visit( constForStmt * ) override final;98 virtual Stmt * visit( constSwitchStmt * ) override final;99 virtual Stmt * visit( constCaseStmt * ) override final;100 virtual Stmt * visit( constBranchStmt * ) override final;101 virtual Stmt * visit( constReturnStmt * ) override final;102 virtual Stmt * visit( constThrowStmt * ) override final;103 virtual Stmt * visit( constTryStmt * ) override final;104 virtual Stmt * visit( constCatchStmt * ) override final;105 virtual Stmt * visit( constFinallyStmt * ) override final;106 virtual Stmt * visit( constWaitForStmt * ) override final;107 virtual Stmt * visit( constWithStmt * ) override final;108 virtual NullStmt * visit( constNullStmt * ) override final;109 virtual Stmt * visit( constDeclStmt * ) override final;110 virtual Stmt * visit( constImplicitCtorDtorStmt * ) override final;111 virtual Expr * visit( constApplicationExpr * ) override final;112 virtual Expr * visit( constUntypedExpr * ) override final;113 virtual Expr * visit( constNameExpr * ) override final;114 virtual Expr * visit( constAddressExpr * ) override final;115 virtual Expr * visit( constLabelAddressExpr * ) override final;116 virtual Expr * visit( constCastExpr * ) override final;117 virtual Expr * visit( constKeywordCastExpr * ) override final;118 virtual Expr * visit( constVirtualCastExpr * ) override final;119 virtual Expr * visit( constUntypedMemberExpr * ) override final;120 virtual Expr * visit( constMemberExpr * ) override final;121 virtual Expr * visit( constVariableExpr * ) override final;122 virtual Expr * visit( constConstantExpr * ) override final;123 virtual Expr * visit( constSizeofExpr * ) override final;124 virtual Expr * visit( constAlignofExpr * ) override final;125 virtual Expr * visit( constUntypedOffsetofExpr * ) override final;126 virtual Expr * visit( constOffsetofExpr * ) override final;127 virtual Expr * visit( constOffsetPackExpr * ) override final;128 virtual Expr * visit( constAttrExpr * ) override final;129 virtual Expr * visit( constLogicalExpr * ) override final;130 virtual Expr * visit( constConditionalExpr * ) override final;131 virtual Expr * visit( constCommaExpr * ) override final;132 virtual Expr * visit( constTypeExpr * ) override final;133 virtual Expr * visit( constAsmExpr * ) override final;134 virtual Expr * visit( constImplicitCopyCtorExpr * ) override final;135 virtual Expr * visit( constConstructorExpr * ) override final;136 virtual Expr * visit( constCompoundLiteralExpr * ) override final;137 virtual Expr * visit( constRangeExpr * ) override final;138 virtual Expr * visit( constUntypedTupleExpr * ) override final;139 virtual Expr * visit( constTupleExpr * ) override final;140 virtual Expr * visit( constTupleIndexExpr * ) override final;141 virtual Expr * visit( constTupleAssignExpr * ) override final;142 virtual Expr * visit( constStmtExpr * ) override final;143 virtual Expr * visit( constUniqueExpr * ) override final;144 virtual Expr * visit( constUntypedInitExpr * ) override final;145 virtual Expr * visit( constInitExpr * ) override final;146 virtual Expr * visit( constDeletedExpr * ) override final;147 virtual Expr * visit( constDefaultArgExpr * ) override final;148 virtual Expr * visit( constGenericExpr * ) override final;149 virtual Type * visit( constVoidType * ) override final;150 virtual Type * visit( constBasicType * ) override final;151 virtual Type * visit( constPointerType * ) override final;152 virtual Type * visit( constArrayType * ) override final;153 virtual Type * visit( constReferenceType * ) override final;154 virtual Type * visit( constQualifiedType * ) override final;155 virtual Type * visit( constFunctionType * ) override final;156 virtual Type * visit( constStructInstType * ) override final;157 virtual Type * visit( constUnionInstType * ) override final;158 virtual Type * visit( constEnumInstType * ) override final;159 virtual Type * visit( constTraitInstType * ) override final;160 virtual Type * visit( constTypeInstType * ) override final;161 virtual Type * visit( constTupleType * ) override final;162 virtual Type * visit( constTypeofType * ) override final;163 virtual Type * visit( constVarArgsType * ) override final;164 virtual Type * visit( constZeroType * ) override final;165 virtual Type * visit( constOneType * ) override final;166 virtual Type * visit( constGlobalScopeType * ) override final;167 virtual Designation * visit( constDesignation * ) override final;168 virtual Init * visit( constSingleInit * ) override final;169 virtual Init * visit( constListInit * ) override final;170 virtual Init * visit( constConstructorInit * ) override final;171 virtual Constant * visit( constConstant * ) override final;172 virtual Attribute * visit( constAttribute * ) override final;173 virtual TypeSubstitution * visit( constTypeSubstitution * ) override final;87 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * ) override final; 88 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * ) override final; 89 virtual const ast::Decl * visit( const ast::StructDecl * ) override final; 90 virtual const ast::Decl * visit( const ast::UnionDecl * ) override final; 91 virtual const ast::Decl * visit( const ast::EnumDecl * ) override final; 92 virtual const ast::Decl * visit( const ast::TraitDecl * ) override final; 93 virtual const ast::Decl * visit( const ast::TypeDecl * ) override final; 94 virtual const ast::Decl * visit( const ast::TypedefDecl * ) override final; 95 virtual const ast::AsmDecl * visit( const ast::AsmDecl * ) override final; 96 virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * ) override final; 97 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * ) override final; 98 virtual const ast::Stmt * visit( const ast::ExprStmt * ) override final; 99 virtual const ast::Stmt * visit( const ast::AsmStmt * ) override final; 100 virtual const ast::Stmt * visit( const ast::DirectiveStmt * ) override final; 101 virtual const ast::Stmt * visit( const ast::IfStmt * ) override final; 102 virtual const ast::Stmt * visit( const ast::WhileStmt * ) override final; 103 virtual const ast::Stmt * visit( const ast::ForStmt * ) override final; 104 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) override final; 105 virtual const ast::Stmt * visit( const ast::CaseStmt * ) override final; 106 virtual const ast::Stmt * visit( const ast::BranchStmt * ) override final; 107 virtual const ast::Stmt * visit( const ast::ReturnStmt * ) override final; 108 virtual const ast::Stmt * visit( const ast::ThrowStmt * ) override final; 109 virtual const ast::Stmt * visit( const ast::TryStmt * ) override final; 110 virtual const ast::Stmt * visit( const ast::CatchStmt * ) override final; 111 virtual const ast::Stmt * visit( const ast::FinallyStmt * ) override final; 112 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) override final; 113 virtual const ast::Stmt * visit( const ast::WithStmt * ) override final; 114 virtual const ast::NullStmt * visit( const ast::NullStmt * ) override final; 115 virtual const ast::Stmt * visit( const ast::DeclStmt * ) override final; 116 virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * ) override final; 117 virtual const ast::Expr * visit( const ast::ApplicationExpr * ) override final; 118 virtual const ast::Expr * visit( const ast::UntypedExpr * ) override final; 119 virtual const ast::Expr * visit( const ast::NameExpr * ) override final; 120 virtual const ast::Expr * visit( const ast::AddressExpr * ) override final; 121 virtual const ast::Expr * visit( const ast::LabelAddressExpr * ) override final; 122 virtual const ast::Expr * visit( const ast::CastExpr * ) override final; 123 virtual const ast::Expr * visit( const ast::KeywordCastExpr * ) override final; 124 virtual const ast::Expr * visit( const ast::VirtualCastExpr * ) override final; 125 virtual const ast::Expr * visit( const ast::UntypedMemberExpr * ) override final; 126 virtual const ast::Expr * visit( const ast::MemberExpr * ) override final; 127 virtual const ast::Expr * visit( const ast::VariableExpr * ) override final; 128 virtual const ast::Expr * visit( const ast::ConstantExpr * ) override final; 129 virtual const ast::Expr * visit( const ast::SizeofExpr * ) override final; 130 virtual const ast::Expr * visit( const ast::AlignofExpr * ) override final; 131 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) override final; 132 virtual const ast::Expr * visit( const ast::OffsetofExpr * ) override final; 133 virtual const ast::Expr * visit( const ast::OffsetPackExpr * ) override final; 134 virtual const ast::Expr * visit( const ast::AttrExpr * ) override final; 135 virtual const ast::Expr * visit( const ast::LogicalExpr * ) override final; 136 virtual const ast::Expr * visit( const ast::ConditionalExpr * ) override final; 137 virtual const ast::Expr * visit( const ast::CommaExpr * ) override final; 138 virtual const ast::Expr * visit( const ast::TypeExpr * ) override final; 139 virtual const ast::Expr * visit( const ast::AsmExpr * ) override final; 140 virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * ) override final; 141 virtual const ast::Expr * visit( const ast::ConstructorExpr * ) override final; 142 virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * ) override final; 143 virtual const ast::Expr * visit( const ast::RangeExpr * ) override final; 144 virtual const ast::Expr * visit( const ast::UntypedTupleExpr * ) override final; 145 virtual const ast::Expr * visit( const ast::TupleExpr * ) override final; 146 virtual const ast::Expr * visit( const ast::TupleIndexExpr * ) override final; 147 virtual const ast::Expr * visit( const ast::TupleAssignExpr * ) override final; 148 virtual const ast::Expr * visit( const ast::StmtExpr * ) override final; 149 virtual const ast::Expr * visit( const ast::UniqueExpr * ) override final; 150 virtual const ast::Expr * visit( const ast::UntypedInitExpr * ) override final; 151 virtual const ast::Expr * visit( const ast::InitExpr * ) override final; 152 virtual const ast::Expr * visit( const ast::DeletedExpr * ) override final; 153 virtual const ast::Expr * visit( const ast::DefaultArgExpr * ) override final; 154 virtual const ast::Expr * visit( const ast::GenericExpr * ) override final; 155 virtual const ast::Type * visit( const ast::VoidType * ) override final; 156 virtual const ast::Type * visit( const ast::BasicType * ) override final; 157 virtual const ast::Type * visit( const ast::PointerType * ) override final; 158 virtual const ast::Type * visit( const ast::ArrayType * ) override final; 159 virtual const ast::Type * visit( const ast::ReferenceType * ) override final; 160 virtual const ast::Type * visit( const ast::QualifiedType * ) override final; 161 virtual const ast::Type * visit( const ast::FunctionType * ) override final; 162 virtual const ast::Type * visit( const ast::StructInstType * ) override final; 163 virtual const ast::Type * visit( const ast::UnionInstType * ) override final; 164 virtual const ast::Type * visit( const ast::EnumInstType * ) override final; 165 virtual const ast::Type * visit( const ast::TraitInstType * ) override final; 166 virtual const ast::Type * visit( const ast::TypeInstType * ) override final; 167 virtual const ast::Type * visit( const ast::TupleType * ) override final; 168 virtual const ast::Type * visit( const ast::TypeofType * ) override final; 169 virtual const ast::Type * visit( const ast::VarArgsType * ) override final; 170 virtual const ast::Type * visit( const ast::ZeroType * ) override final; 171 virtual const ast::Type * visit( const ast::OneType * ) override final; 172 virtual const ast::Type * visit( const ast::GlobalScopeType * ) override final; 173 virtual const ast::Designation * visit( const ast::Designation * ) override final; 174 virtual const ast::Init * visit( const ast::SingleInit * ) override final; 175 virtual const ast::Init * visit( const ast::ListInit * ) override final; 176 virtual const ast::Init * visit( const ast::ConstructorInit * ) override final; 177 virtual const ast::Constant * visit( const ast::Constant * ) override final; 178 virtual const ast::Attribute * visit( const ast::Attribute * ) override final; 179 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) override final; 174 180 175 181 friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor ); … … 179 185 180 186 private: 187 const ast::Stmt * call_accept( const ast::Stmt * ); 188 const ast::Expr * call_accept( const ast::Expr * ); 189 190 template< typename node_t > 191 auto call_accept( const node_t * node ) -> decltype( node->accept(*this) ); 192 193 template< template <class...> class container_t > 194 container_t< ptr<Stmt> > call_accept( const container_t< ptr<Stmt> > & ); 195 196 template< template <class...> class container_t, typename node_t > 197 container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container ); 198 181 199 /// Logic to call the accept and mutate the parent if needed, delegates call to accept 182 template<typename parent_t, typename child_t> 183 void maybe_accept(parent_t * & , typename parent_t::child_t *); 184 185 Stmt * call_accept( const Stmt * ); 186 Expr * call_accept( const Expr * ); 187 188 template< template <class> class container_t > 189 container_t< ptr<Stmt> > call_accept( const container_t< ptr<Stmt> > & ); 190 191 template< template <class> class container_t, typename node_t > 192 container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container ); 200 template<typename node_t, typename parent_t, typename child_t> 201 void maybe_accept(const node_t * &, child_t parent_t::* child); 193 202 194 203 private: … … 209 218 210 219 template<typename pass_t> 211 void accept All( std::list< ptr<Decl> >, Pass<pass_t>& visitor );220 void accept_all( std::list< ast::ptr<ast::Decl> > &, ast::Pass<pass_t> & visitor ); 212 221 213 222 //------------------------------------------------------------------------------------------------- … … 215 224 //------------------------------------------------------------------------------------------------- 216 225 217 template<typename T>218 using std_list = std::list<T>;219 220 226 /// Keep track of the polymorphic const TypeSubstitution * env for the current expression 221 227 struct WithConstTypeSubstitution { … … 225 231 /// Used if visitor requires added statements before or after the current node. 226 232 /// The Pass template handles what *before* and *after* means automatically 227 template< template<class > class container_t = std_list >233 template< template<class...> class container_t = std::list > 228 234 struct WithStmtsToAdd { 229 235 container_t< ptr<Stmt> > stmtsToAddBefore; … … 233 239 /// Used if visitor requires added declarations before or after the current node. 234 240 /// The Pass template handles what *before* and *after* means automatically 235 template< template<class > class container_t = std_list >241 template< template<class...> class container_t = std::list > 236 242 struct WithDeclsToAdd { 237 243 container_t< ptr<Decl> > declsToAddBefore; … … 285 291 }; 286 292 } 293 294 #include "Common/Stats.h" 295 296 extern struct PassVisitorStats { 297 size_t depth = 0; 298 Stats::Counters::MaxCounter<double> * max = nullptr; 299 Stats::Counters::AverageCounter<double> * avg = nullptr; 300 } pass_visitor_stats; 301 302 #include "AST/Pass.impl.hpp" -
src/AST/Pass.impl.hpp
r9e1d485 r69bafd2 16 16 #pragma once 17 17 // IWYU pragma: private, include "AST/Pass.hpp" 18 19 #include <type_traits> 20 #include <unordered_map> 18 21 19 22 #define VISIT_START( node ) \ … … 26 29 __pass::previsit( pass, node, 0 ); 27 30 28 #define VISIT( code ) \31 #define VISIT( code... ) \ 29 32 /* if this node should visit its children */ \ 30 33 if ( __visit_children() ) { \ … … 35 38 #define VISIT_END( type, node ) \ 36 39 /* call the implementation of the postvisit of this pass */ \ 37 auto __return = __pass::postvisit < type * >( node); \40 auto __return = __pass::postvisit( pass, node, 0 ); \ 38 41 assertf(__return, "post visit should never return null"); \ 39 42 return __return; 40 43 41 44 #ifdef PEDANTIC_PASS_ASSERT 42 #define __pedantic_pass_assert (...) assert (__VAR_ARGS__)43 #define __pedantic_pass_assertf(...) assertf(__VA R_ARGS__)45 #define __pedantic_pass_assert(...) assert (__VA_ARGS__) 46 #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__) 44 47 #else 45 #define __pedantic_pass_assert 48 #define __pedantic_pass_assert(...) 46 49 #define __pedantic_pass_assertf(...) 47 50 #endif … … 55 58 } 56 59 57 template<typename it_t, template <class> class container_t> 58 static inline void take_all( it_t it, container_t<ast::ptr<ast::Declaration>> * decls, bool * mutated = nullptr ) { 60 //------------------------------ 61 template<typename it_t, template <class...> class container_t> 62 static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) { 59 63 if(empty(decls)) return; 60 64 61 std::transform(decls->begin(), decls->end(), it, []( Declaration* decl) -> auto {65 std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto { 62 66 return new DeclStmt( decl ); 63 67 }); … … 66 70 } 67 71 68 template<typename it_t, template <class > class container_t>69 static inline void take_all( it_t it, container_t<ast::ptr<ast::St atement>> * decls, bool * mutated = nullptr ) {72 template<typename it_t, template <class...> class container_t> 73 static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * decls, bool * mutated = nullptr ) { 70 74 if(empty(decls)) return; 71 75 … … 75 79 } 76 80 81 //------------------------------ 82 /// Check if should be skipped, different for pointers and containers 77 83 template<typename node_t> 78 bool differs( const node_t * old_val, const node_t * new_val ) { 84 bool skip( const ast::ptr<node_t> & val) { 85 return !val; 86 } 87 88 template< template <class...> class container_t, typename node_t > 89 bool skip( const container_t<ast::ptr< node_t >> & val ) { 90 return val.empty(); 91 } 92 93 //------------------------------ 94 /// Get the value to visit, different for pointers and containers 95 template<typename node_t> 96 auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) { 97 return val.get(); 98 } 99 100 template<typename node_t> 101 const node_t & get( const node_t & val, long) { 102 return val; 103 } 104 105 106 //------------------------------ 107 /// Check if value was mutated, different for pointers and containers 108 template<typename lhs_t, typename rhs_t> 109 bool differs( const lhs_t * old_val, const rhs_t * new_val ) { 79 110 return old_val != new_val; 80 111 } 81 112 82 template< template <class > class container_t >83 bool differs( const container_t<ast::ptr< ast::Statement >> &, const container_t<ast::ptr< ast::Statement >> & new_val ) {113 template< template <class...> class container_t, typename node_t > 114 bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) { 84 115 return !new_val.empty(); 85 }86 }87 88 template<typename parent_t, typename child_t>89 template< typename pass_t >90 void Pass< pass_t >::maybe_accept(91 const parent_t * & parent,92 const typename parent_t::child_t * child93 ) {94 const auto & old_val = parent->*child;95 if(!old_val) return;96 97 auto new_val = call_accept(old_val);98 99 if( __pass::differs(old_val, new_val) ) {100 auto new_parent = mutate(parent);101 new_parent->*child = new_val;102 parent = new_parent;103 116 } 104 117 } … … 106 119 template< typename pass_t > 107 120 template< typename node_t > 108 auto Pass< pass_t >::call_accept( const node_t * node ) {121 auto Pass< pass_t >::call_accept( const node_t * node ) -> decltype( node->accept(*this) ) { 109 122 __pedantic_pass_assert( __visit_children() ); 110 123 __pedantic_pass_assert( expr ); 111 124 125 static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR"); 126 static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR"); 127 112 128 return node->accept( *this ); 113 129 } 114 130 115 131 template< typename pass_t > 116 ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {132 const ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) { 117 133 __pedantic_pass_assert( __visit_children() ); 118 134 __pedantic_pass_assert( expr ); … … 127 143 128 144 template< typename pass_t > 129 Stmt * Pass< pass_t >::call_accept( constStmt * stmt ) {145 const ast::Stmt * Pass< pass_t >::call_accept( const ast::Stmt * stmt ) { 130 146 __pedantic_pass_assert( __visit_children() ); 131 147 __pedantic_pass_assert( stmt ); … … 141 157 142 158 // These may be modified by subnode but most be restored once we exit this statemnet. 143 ValueGuardPtr< const ast::TypeSubstitution * > __old_env ( __pass::env( pass, 0) ;);144 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );145 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after );146 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );147 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after );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 ); 148 164 149 165 // Now is the time to actually visit the node 150 ast::Statement * nstmt = stmt->accept( *this );166 const ast::Stmt * nstmt = stmt->accept( *this ); 151 167 152 168 // If the pass doesn't want to add anything then we are done … … 161 177 162 178 // Create a new Compound Statement to hold the new decls/stmts 163 ast::CompoundStmt * compound = new ast::CompoundStmt( parent->*child.location );179 ast::CompoundStmt * compound = new ast::CompoundStmt( stmt->location ); 164 180 165 181 // Take all the declarations that go before … … 168 184 169 185 // Insert the original declaration 170 compound->kids. push_back( nstmt );186 compound->kids.emplace_back( nstmt ); 171 187 172 188 // Insert all the declarations that go before … … 178 194 179 195 template< typename pass_t > 180 template< template <class > class container_t >196 template< template <class...> class container_t > 181 197 container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { 182 198 __pedantic_pass_assert( __visit_children() ); … … 196 212 197 213 // These may be modified by subnode but most be restored once we exit this statemnet. 198 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );199 ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after );200 ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );201 ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after );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 ); 202 218 203 219 // update pass statitistics … … 211 227 try { 212 228 __pedantic_pass_assert( stmt ); 213 const ast::St atment * new_stmt = stmt->accept( visitor);229 const ast::Stmt * new_stmt = stmt->accept( *this ); 214 230 assert( new_stmt ); 215 231 if(new_stmt != stmt ) mutated = true; … … 240 256 if ( !errors.isEmpty() ) { throw errors; } 241 257 242 return mutated ? new_kids : {};258 return mutated ? new_kids : container_t< ptr<Stmt> >(); 243 259 } 244 260 245 261 template< typename pass_t > 246 template< template <class > class container_t, typename node_t >262 template< template <class...> class container_t, typename node_t > 247 263 container_t< ast::ptr<node_t> > Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { 248 264 __pedantic_pass_assert( __visit_children() ); … … 259 275 try { 260 276 __pedantic_pass_assert( node ); 261 const node_t * new_ node= strict_dynamic_cast< const node_t * >( node->accept( *this ) );262 if(new_stmt != stmt) mutated = true;277 const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) ); 278 if(new_stmt != node ) mutated = true; 263 279 264 280 new_kids.emplace_back( new_stmt ); … … 271 287 if ( ! errors.isEmpty() ) { throw errors; } 272 288 273 return mutated ? new_kids : {}; 274 } 289 return mutated ? new_kids : container_t< ast::ptr<node_t> >(); 290 } 291 292 template< typename pass_t > 293 template<typename node_t, typename parent_t, typename child_t> 294 void Pass< pass_t >::maybe_accept( 295 const node_t * & parent, 296 child_t parent_t::*child 297 ) { 298 static_assert( std::is_base_of<parent_t, node_t>::value, "Error deductiing member object" ); 299 300 if(__pass::skip(parent->*child)) return; 301 const auto & old_val = __pass::get(parent->*child, 0); 302 303 static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR"); 304 305 auto new_val = call_accept( old_val ); 306 307 static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR"); 308 309 if( __pass::differs(old_val, new_val) ) { 310 auto new_parent = mutate(parent); 311 new_parent->*child = new_val; 312 parent = new_parent; 313 } 314 } 315 275 316 } 276 317 … … 284 325 285 326 template< typename pass_t > 286 inline void ast::accept All( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {327 inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) { 287 328 // We are going to aggregate errors for all these statements 288 329 SemanticErrorException errors; … … 292 333 293 334 // get the stmts/decls that will need to be spliced in 294 auto decls_before = __pass::declsToAddBefore( pass, 0);295 auto decls_after = __pass::declsToAddAfter ( pass, 0);335 auto decls_before = __pass::declsToAddBefore( visitor.pass, 0); 336 auto decls_after = __pass::declsToAddAfter ( visitor.pass, 0); 296 337 297 338 // update pass statitistics … … 343 384 // ObjectDecl 344 385 template< typename pass_t > 345 ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {386 const ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) { 346 387 VISIT_START( node ); 347 388 348 389 VISIT( 349 390 { 350 indexer_guardguard { *this };351 maybe_accept( node, ObjectDecl::type );352 } 353 maybe_accept( node, ObjectDecl::init );354 maybe_accept( node, ObjectDecl::bitfieldWidth );355 maybe_accept( node, ObjectDecl::attributes );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 ); 356 397 ) 357 398 358 __pass::indexer:: AddId( pass, 0, node );399 __pass::indexer::addId( pass, 0, node ); 359 400 360 401 VISIT_END( DeclWithType, node ); 402 } 403 404 //-------------------------------------------------------------------------- 405 // SingleInit 406 template< typename pass_t > 407 const ast::Init * ast::Pass< pass_t >::visit( const ast::SingleInit * node ) { 408 VISIT_START( node ); 409 410 VISIT( 411 maybe_accept( node, &SingleInit::value ); 412 ) 413 414 VISIT_END( Init, node ); 415 } 416 417 //-------------------------------------------------------------------------- 418 // ListInit 419 template< typename pass_t > 420 const ast::Init * ast::Pass< pass_t >::visit( const ast::ListInit * node ) { 421 VISIT_START( node ); 422 423 VISIT( 424 maybe_accept( node, &ListInit::designations ); 425 maybe_accept( node, &ListInit::initializers ); 426 ) 427 428 VISIT_END( Init, node ); 429 } 430 431 //-------------------------------------------------------------------------- 432 // ConstructorInit 433 template< typename pass_t > 434 const ast::Init * ast::Pass< pass_t >::visit( const ast::ConstructorInit * node ) { 435 VISIT_START( node ); 436 437 VISIT( 438 maybe_accept( node, &ConstructorInit::ctor ); 439 maybe_accept( node, &ConstructorInit::dtor ); 440 maybe_accept( node, &ConstructorInit::init ); 441 ) 442 443 VISIT_END( Init, node ); 361 444 } 362 445 363 446 //-------------------------------------------------------------------------- 364 447 // Attribute 365 template< typename pass_t ype>366 ast::Attribute * ast::Pass< pass_type>::visit( const ast::Attribute * node ) {367 VISIT_START( node);448 template< typename pass_t > 449 const ast::Attribute * ast::Pass< pass_t >::visit( const ast::Attribute * node ) { 450 VISIT_START( node ); 368 451 369 452 VISIT( 370 maybe_accept( node, ast::Attribute::parameters );453 maybe_accept( node, &Attribute::parameters ); 371 454 ) 372 455 373 VISIT_END( ast::Attribute *, node );456 VISIT_END( Attribute *, node ); 374 457 } 375 458 376 459 //-------------------------------------------------------------------------- 377 460 // TypeSubstitution 378 template< typename pass_type > 379 TypeSubstitution * PassVisitor< pass_type >::mutate( const TypeSubstitution * node ) { 380 MUTATE_START( node ); 381 382 #error this is broken 383 384 for ( auto & p : node->typeEnv ) { 385 indexerScopedMutate( p.second, *this ); 386 } 387 for ( auto & p : node->varEnv ) { 388 indexerScopedMutate( p.second, *this ); 389 } 390 391 MUTATE_END( TypeSubstitution, node ); 461 template< typename pass_t > 462 const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) { 463 VISIT_START( node ); 464 465 VISIT( 466 { 467 bool mutated = false; 468 std::unordered_map< std::string, ast::ptr< ast::Type > > new_map; 469 for ( const auto & p : node->typeEnv ) { 470 guard_indexer guard { *this }; 471 auto new_node = p.second->accept( *this ); 472 if (new_node != p.second) mutated = false; 473 new_map.insert({ p.first, new_node }); 474 } 475 if (mutated) { 476 auto new_node = mutate( node ); 477 new_node->typeEnv.swap( new_map ); 478 node = new_node; 479 } 480 } 481 482 { 483 bool mutated = false; 484 std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map; 485 for ( const auto & p : node->varEnv ) { 486 guard_indexer guard { *this }; 487 auto new_node = p.second->accept( *this ); 488 if (new_node != p.second) mutated = false; 489 new_map.insert({ p.first, new_node }); 490 } 491 if (mutated) { 492 auto new_node = mutate( node ); 493 new_node->varEnv.swap( new_map ); 494 node = new_node; 495 } 496 } 497 ) 498 499 VISIT_END( TypeSubstitution, node ); 392 500 } 393 501 -
src/AST/Pass.proto.hpp
r9e1d485 r69bafd2 162 162 163 163 // List of fields and their expected types 164 FIELD_PTR( env, const ast::TypeSubstitution )164 FIELD_PTR( env, const ast::TypeSubstitution * ) 165 165 FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > ) 166 166 FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > ) … … 235 235 static inline void func( pass_t &, long, type1, type2 ) {} 236 236 237 INDEXER_FUNC1( addId , DeclWithType * );238 INDEXER_FUNC1( addType , NamedTypeDecl * );239 INDEXER_FUNC1( addStruct , StructDecl * );240 INDEXER_FUNC1( addEnum , EnumDecl * );241 INDEXER_FUNC1( addUnion , UnionDecl * );242 INDEXER_FUNC1( addTrait , TraitDecl * );243 INDEXER_FUNC2( addWith , std::list< Expression * > &,Node * );237 INDEXER_FUNC1( addId , const DeclWithType * ); 238 INDEXER_FUNC1( addType , const NamedTypeDecl * ); 239 INDEXER_FUNC1( addStruct , const StructDecl * ); 240 INDEXER_FUNC1( addEnum , const EnumDecl * ); 241 INDEXER_FUNC1( addUnion , const UnionDecl * ); 242 INDEXER_FUNC1( addTrait , const TraitDecl * ); 243 INDEXER_FUNC2( addWith , const std::list< Expression * > &, const Node * ); 244 244 245 245 // A few extra functions have more complicated behaviour, they are hand written 246 //template<typename pass_t>247 // static inline auto addStructFwd( pass_t & pass, int,ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {248 //ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );249 //fwd->parameters = decl->parameters;250 //pass.indexer.addStruct( fwd );251 //}252 253 //template<typename pass_t>254 // static inline void addStructFwd( pass_t &, long,ast::StructDecl * ) {}255 256 //template<typename pass_t>257 // static inline auto addUnionFwd( pass_t & pass, int,ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {258 // UnionDecl * fwd = new UnionDecl(decl->name );259 //fwd->parameters = decl->parameters;260 //pass.indexer.addUnion( fwd );261 //}262 263 //template<typename pass_t>264 // static inline void addUnionFwd( pass_t &, long,ast::UnionDecl * ) {}265 266 //template<typename pass_t>267 //static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {268 //if ( ! pass.indexer.lookupStruct( str ) ) {269 //pass.indexer.addStruct( str );270 //}271 //}272 273 //template<typename pass_t>274 //static inline void addStruct( pass_t &, long, const std::string & ) {}275 276 //template<typename pass_t>277 //static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {278 //if ( ! pass.indexer.lookupUnion( str ) ) {279 //pass.indexer.addUnion( str );280 //}281 //}282 283 //template<typename pass_t>284 //static inline void addUnion( pass_t &, long, const std::string & ) {}246 template<typename pass_t> 247 static inline auto addStructFwd( pass_t & pass, int, const ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) { 248 ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name ); 249 fwd->parameters = decl->parameters; 250 pass.indexer.addStruct( fwd ); 251 } 252 253 template<typename pass_t> 254 static inline void addStructFwd( pass_t &, long, const ast::StructDecl * ) {} 255 256 template<typename pass_t> 257 static inline auto addUnionFwd( pass_t & pass, int, const ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) { 258 UnionDecl * fwd = new UnionDecl( decl->location, decl->name ); 259 fwd->parameters = decl->parameters; 260 pass.indexer.addUnion( fwd ); 261 } 262 263 template<typename pass_t> 264 static inline void addUnionFwd( pass_t &, long, const ast::UnionDecl * ) {} 265 266 template<typename pass_t> 267 static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) { 268 if ( ! pass.indexer.lookupStruct( str ) ) { 269 pass.indexer.addStruct( str ); 270 } 271 } 272 273 template<typename pass_t> 274 static inline void addStruct( pass_t &, long, const std::string & ) {} 275 276 template<typename pass_t> 277 static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) { 278 if ( ! pass.indexer.lookupUnion( str ) ) { 279 pass.indexer.addUnion( str ); 280 } 281 } 282 283 template<typename pass_t> 284 static inline void addUnion( pass_t &, long, const std::string & ) {} 285 285 286 286 #undef INDEXER_FUNC1 -
src/AST/Stmt.hpp
r9e1d485 r69bafd2 40 40 Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {} 41 41 42 virtual Stmt* accept( Visitor& v )override = 0;42 virtual const Stmt* accept( Visitor& v ) const override = 0; 43 43 private: 44 44 virtual Stmt* clone() const override = 0; … … 59 59 void push_front( Stmt* s ) { kids.emplace_front( s ); } 60 60 61 CompoundStmt* accept( Visitor& v )override { return v.visit( this ); }61 virtual const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); } 62 62 private: 63 CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }63 virtual CompoundStmt* clone() const override { return new CompoundStmt{ *this }; } 64 64 }; 65 65 … … 70 70 : Stmt(loc, std::move(labels)) {} 71 71 72 NullStmt* accept( Visitor& v )override { return v.visit( this ); }72 virtual const NullStmt * accept( Visitor& v ) const override { return v.visit( this ); } 73 73 private: 74 NullStmt* clone() const override { return new NullStmt{ *this }; }74 virtual 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 Stmt* accept( Visitor& v )override { return v.visit( this ); }84 virtual const Stmt * accept( Visitor& v ) const override { return v.visit( this ); } 85 85 private: 86 ExprStmt* clone() const override { return new ExprStmt{ *this }; }86 virtual ExprStmt * clone() const override { return new ExprStmt{ *this }; } 87 87 }; 88 88 … … 100 100 inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); } 101 101 inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 102 inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }103 inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }104 inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }105 inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }106 inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }107 inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }108 inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }109 inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }110 inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }111 inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }112 inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }113 inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }114 inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }115 inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }116 inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }117 inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }118 inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }119 inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }120 inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }121 inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }122 inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }123 inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }124 inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }125 inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }126 inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }127 inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }128 inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }129 inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }130 inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }131 inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }132 inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }133 inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }102 // inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); } 103 // inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 104 // inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); } 105 // inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 106 // inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); } 107 // inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 108 // inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); } 109 // inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 110 // inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); } 111 // inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 112 // inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); } 113 // inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 114 // inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); } 115 // inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 116 // inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); } 117 // inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 118 // inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); } 119 // inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 120 // inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); } 121 // inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 122 // inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); } 123 // inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 124 // inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); } 125 // inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 126 // inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); } 127 // inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 128 // inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); } 129 // inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 130 // inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); } 131 // inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 132 // inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); } 133 // inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 134 134 inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); } 135 135 inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 136 inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }137 inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }136 // inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); } 137 // inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); } 138 138 139 139 } -
src/AST/Type.hpp
r9e1d485 r69bafd2 67 67 virtual bool isComplete() const { return true; } 68 68 69 virtual Type * accept( Visitor & v )override = 0;69 virtual const Type * accept( Visitor & v ) const override = 0; 70 70 private: 71 71 virtual Type * clone() const override = 0; … … 81 81 bool isComplete() const override { return false; } 82 82 83 Type * accept( Visitor & v )override { return v.visit( this ); }83 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 84 84 private: 85 85 VoidType * clone() const override { return new VoidType{ *this }; } … … 143 143 bool isInteger() const { return kind <= MAX_INTEGER_TYPE; } 144 144 145 Type * accept( Visitor & v )override { return v.visit( this ); }145 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 146 146 private: 147 147 BasicType * clone() const override { return new BasicType{ *this }; } … … 173 173 bool isComplete() const override { return ! isVarLen; } 174 174 175 Type * accept( Visitor & v )override { return v.visit( this ); }175 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 176 176 private: 177 177 PointerType * clone() const override { return new PointerType{ *this }; } … … 194 194 bool isComplete() const override { return dimension || isVarLen; } 195 195 196 Type * accept( Visitor & v )override { return v.visit( this ); }196 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 197 197 private: 198 198 ArrayType * clone() const override { return new ArrayType{ *this }; } … … 213 213 unsigned size() const override { return base->size(); } 214 214 215 Type * accept( Visitor & v )override { return v.visit( this ); }215 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 216 216 private: 217 217 ReferenceType * clone() const override { return new ReferenceType{ *this }; } … … 227 227 : Type(q), parent(p), child(c) {} 228 228 229 Type * accept( Visitor & v )override { return v.visit( this ); }229 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 230 230 private: 231 231 QualifiedType * clone() const override { return new QualifiedType{ *this }; } … … 271 271 bool isUnprototyped() const { return isVarArgs && parameters.size() == 0; } 272 272 273 Type * accept( Visitor & v )override { return v.visit( this ); }273 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 274 274 private: 275 275 FunctionType * clone() const override { return new FunctionType{ *this }; } … … 316 316 const StructDecl * aggr() const override { return base; } 317 317 318 Type * accept( Visitor & v )override { return v.visit( this ); }318 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 319 319 private: 320 320 StructInstType * clone() const override { return new StructInstType{ *this }; } … … 338 338 const UnionDecl * aggr() const override { return base; } 339 339 340 Type * accept( Visitor & v )override { return v.visit( this ); }340 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 341 341 private: 342 342 UnionInstType * clone() const override { return new UnionInstType{ *this }; } … … 360 360 const EnumDecl * aggr() const override { return base; } 361 361 362 Type * accept( Visitor & v )override { return v.visit( this ); }362 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 363 363 private: 364 364 EnumInstType * clone() const override { return new EnumInstType{ *this }; } … … 383 383 const TraitDecl * aggr() const override { return base; } 384 384 385 Type * accept( Visitor & v )override { return v.visit( this ); }385 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 386 386 private: 387 387 TraitInstType * clone() const override { return new TraitInstType{ *this }; } … … 411 411 const AggregateDecl * aggr() const override { assert(false); } 412 412 413 Type * accept( Visitor & v )override { return v.visit( this ); }413 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 414 414 private: 415 415 TypeInstType * clone() const override { return new TypeInstType{ *this }; } … … 439 439 } 440 440 441 Type * accept( Visitor & v )override { return v.visit( this ); }441 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 442 442 private: 443 443 TupleType * clone() const override { return new TupleType{ *this }; } … … 453 453 : Type(q), expr(e), kind(k) {} 454 454 455 Type * accept( Visitor & v )override { return v.visit( this ); }455 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 456 456 private: 457 457 TypeofType * clone() const override { return new TypeofType{ *this }; } … … 463 463 VarArgsType( CV::Qualifiers q = {} ) : Type( q ) {} 464 464 465 Type * accept( Visitor & v )override { return v.visit( this ); }465 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 466 466 private: 467 467 VarArgsType * clone() const override { return new VarArgsType{ *this }; } … … 473 473 ZeroType( CV::Qualifiers q = {} ) : Type( q ) {} 474 474 475 Type * accept( Visitor & v )override { return v.visit( this ); }475 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 476 476 private: 477 477 ZeroType * clone() const override { return new ZeroType{ *this }; } … … 483 483 OneType( CV::Qualifiers q = {} ) : Type( q ) {} 484 484 485 Type * accept( Visitor & v )override { return v.visit( this ); }485 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 486 486 private: 487 487 OneType * clone() const override { return new OneType{ *this }; } … … 493 493 GlobalScopeType( CV::Qualifiers q = {} ) : Type( q ) {} 494 494 495 Type * accept( Visitor & v )override { return v.visit( this ); }495 const Type * accept( Visitor & v ) const override { return v.visit( this ); } 496 496 private: 497 497 GlobalScopeType * clone() const override { return new GlobalScopeType{ *this }; } -
src/AST/Visitor.hpp
r9e1d485 r69bafd2 22 22 class Visitor { 23 23 public: 24 virtual DeclWithType * visit( constObjectDecl * ) = 0;25 virtual DeclWithType * visit( constFunctionDecl * ) = 0;26 virtual Decl * visit( constStructDecl * ) = 0;27 virtual Decl * visit( constUnionDecl * ) = 0;28 virtual Decl * visit( constEnumDecl * ) = 0;29 virtual Decl * visit( constTraitDecl * ) = 0;30 virtual Decl * visit( constTypeDecl * ) = 0;31 virtual Decl * visit( constTypedefDecl * ) = 0;32 virtual AsmDecl * visit( constAsmDecl * ) = 0;33 virtual StaticAssertDecl * visit( constStaticAssertDecl * ) = 0;34 virtual CompoundStmt * visit( constCompoundStmt * ) = 0;35 virtual Stmt * visit( constExprStmt * ) = 0;36 virtual Stmt * visit( constAsmStmt * ) = 0;37 virtual Stmt * visit( constDirectiveStmt * ) = 0;38 virtual Stmt * visit( constIfStmt * ) = 0;39 virtual Stmt * visit( constWhileStmt * ) = 0;40 virtual Stmt * visit( constForStmt * ) = 0;41 virtual Stmt * visit( constSwitchStmt * ) = 0;42 virtual Stmt * visit( constCaseStmt * ) = 0;43 virtual Stmt * visit( constBranchStmt * ) = 0;44 virtual Stmt * visit( constReturnStmt * ) = 0;45 virtual Stmt * visit( constThrowStmt * ) = 0;46 virtual Stmt * visit( constTryStmt * ) = 0;47 virtual Stmt * visit( constCatchStmt * ) = 0;48 virtual Stmt * visit( constFinallyStmt * ) = 0;49 virtual Stmt * visit( constWaitForStmt * ) = 0;50 virtual Stmt * visit( constWithStmt * ) = 0;51 virtual NullStmt * visit( constNullStmt * ) = 0;52 virtual Stmt * visit( constDeclStmt * ) = 0;53 virtual Stmt * visit( constImplicitCtorDtorStmt * ) = 0;54 virtual Expr * visit( constApplicationExpr * ) = 0;55 virtual Expr * visit( constUntypedExpr * ) = 0;56 virtual Expr * visit( constNameExpr * ) = 0;57 virtual Expr * visit( constAddressExpr * ) = 0;58 virtual Expr * visit( constLabelAddressExpr * ) = 0;59 virtual Expr * visit( constCastExpr * ) = 0;60 virtual Expr * visit( constKeywordCastExpr * ) = 0;61 virtual Expr * visit( constVirtualCastExpr * ) = 0;62 virtual Expr * visit( constUntypedMemberExpr * ) = 0;63 virtual Expr * visit( constMemberExpr * ) = 0;64 virtual Expr * visit( constVariableExpr * ) = 0;65 virtual Expr * visit( constConstantExpr * ) = 0;66 virtual Expr * visit( constSizeofExpr * ) = 0;67 virtual Expr * visit( constAlignofExpr * ) = 0;68 virtual Expr * visit( constUntypedOffsetofExpr * ) = 0;69 virtual Expr * visit( constOffsetofExpr * ) = 0;70 virtual Expr * visit( constOffsetPackExpr * ) = 0;71 virtual Expr * visit( constAttrExpr * ) = 0;72 virtual Expr * visit( constLogicalExpr * ) = 0;73 virtual Expr * visit( constConditionalExpr * ) = 0;74 virtual Expr * visit( constCommaExpr * ) = 0;75 virtual Expr * visit( constTypeExpr * ) = 0;76 virtual Expr * visit( constAsmExpr * ) = 0;77 virtual Expr * visit( constImplicitCopyCtorExpr * ) = 0;78 virtual Expr * visit( constConstructorExpr * ) = 0;79 virtual Expr * visit( constCompoundLiteralExpr * ) = 0;80 virtual Expr * visit( constRangeExpr * ) = 0;81 virtual Expr * visit( constUntypedTupleExpr * ) = 0;82 virtual Expr * visit( constTupleExpr * ) = 0;83 virtual Expr * visit( constTupleIndexExpr * ) = 0;84 virtual Expr * visit( constTupleAssignExpr * ) = 0;85 virtual Expr * visit( constStmtExpr * ) = 0;86 virtual Expr * visit( constUniqueExpr * ) = 0;87 virtual Expr * visit( constUntypedInitExpr * ) = 0;88 virtual Expr * visit( constInitExpr * ) = 0;89 virtual Expr * visit( constDeletedExpr * ) = 0;90 virtual Expr * visit( constDefaultArgExpr * ) = 0;91 virtual Expr * visit( constGenericExpr * ) = 0;92 virtual Type * visit( constVoidType * ) = 0;93 virtual Type * visit( constBasicType * ) = 0;94 virtual Type * visit( constPointerType * ) = 0;95 virtual Type * visit( constArrayType * ) = 0;96 virtual Type * visit( constReferenceType * ) = 0;97 virtual Type * visit( constQualifiedType * ) = 0;98 virtual Type * visit( constFunctionType * ) = 0;99 virtual Type * visit( constStructInstType * ) = 0;100 virtual Type * visit( constUnionInstType * ) = 0;101 virtual Type * visit( constEnumInstType * ) = 0;102 virtual Type * visit( constTraitInstType * ) = 0;103 virtual Type * visit( constTypeInstType * ) = 0;104 virtual Type * visit( constTupleType * ) = 0;105 virtual Type * visit( constTypeofType * ) = 0;106 virtual Type * visit( constVarArgsType * ) = 0;107 virtual Type * visit( constZeroType * ) = 0;108 virtual Type * visit( constOneType * ) = 0;109 virtual Type * visit( constGlobalScopeType * ) = 0;110 virtual Designation * visit( constDesignation * ) = 0;111 virtual Init * visit( constSingleInit * ) = 0;112 virtual Init * visit( constListInit * ) = 0;113 virtual Init * visit( constConstructorInit * ) = 0;114 virtual Constant * visit( constConstant * ) = 0;115 virtual Attribute * visit( constAttribute * ) = 0;116 virtual TypeSubstitution * visit( constTypeSubstitution * ) = 0;24 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * ) = 0; 25 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * ) = 0; 26 virtual const ast::Decl * visit( const ast::StructDecl * ) = 0; 27 virtual const ast::Decl * visit( const ast::UnionDecl * ) = 0; 28 virtual const ast::Decl * visit( const ast::EnumDecl * ) = 0; 29 virtual const ast::Decl * visit( const ast::TraitDecl * ) = 0; 30 virtual const ast::Decl * visit( const ast::TypeDecl * ) = 0; 31 virtual const ast::Decl * visit( const ast::TypedefDecl * ) = 0; 32 virtual const ast::AsmDecl * visit( const ast::AsmDecl * ) = 0; 33 virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * ) = 0; 34 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * ) = 0; 35 virtual const ast::Stmt * visit( const ast::ExprStmt * ) = 0; 36 virtual const ast::Stmt * visit( const ast::AsmStmt * ) = 0; 37 virtual const ast::Stmt * visit( const ast::DirectiveStmt * ) = 0; 38 virtual const ast::Stmt * visit( const ast::IfStmt * ) = 0; 39 virtual const ast::Stmt * visit( const ast::WhileStmt * ) = 0; 40 virtual const ast::Stmt * visit( const ast::ForStmt * ) = 0; 41 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) = 0; 42 virtual const ast::Stmt * visit( const ast::CaseStmt * ) = 0; 43 virtual const ast::Stmt * visit( const ast::BranchStmt * ) = 0; 44 virtual const ast::Stmt * visit( const ast::ReturnStmt * ) = 0; 45 virtual const ast::Stmt * visit( const ast::ThrowStmt * ) = 0; 46 virtual const ast::Stmt * visit( const ast::TryStmt * ) = 0; 47 virtual const ast::Stmt * visit( const ast::CatchStmt * ) = 0; 48 virtual const ast::Stmt * visit( const ast::FinallyStmt * ) = 0; 49 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0; 50 virtual const ast::Stmt * visit( const ast::WithStmt * ) = 0; 51 virtual const ast::NullStmt * visit( const ast::NullStmt * ) = 0; 52 virtual const ast::Stmt * visit( const ast::DeclStmt * ) = 0; 53 virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * ) = 0; 54 virtual const ast::Expr * visit( const ast::ApplicationExpr * ) = 0; 55 virtual const ast::Expr * visit( const ast::UntypedExpr * ) = 0; 56 virtual const ast::Expr * visit( const ast::NameExpr * ) = 0; 57 virtual const ast::Expr * visit( const ast::AddressExpr * ) = 0; 58 virtual const ast::Expr * visit( const ast::LabelAddressExpr * ) = 0; 59 virtual const ast::Expr * visit( const ast::CastExpr * ) = 0; 60 virtual const ast::Expr * visit( const ast::KeywordCastExpr * ) = 0; 61 virtual const ast::Expr * visit( const ast::VirtualCastExpr * ) = 0; 62 virtual const ast::Expr * visit( const ast::UntypedMemberExpr * ) = 0; 63 virtual const ast::Expr * visit( const ast::MemberExpr * ) = 0; 64 virtual const ast::Expr * visit( const ast::VariableExpr * ) = 0; 65 virtual const ast::Expr * visit( const ast::ConstantExpr * ) = 0; 66 virtual const ast::Expr * visit( const ast::SizeofExpr * ) = 0; 67 virtual const ast::Expr * visit( const ast::AlignofExpr * ) = 0; 68 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) = 0; 69 virtual const ast::Expr * visit( const ast::OffsetofExpr * ) = 0; 70 virtual const ast::Expr * visit( const ast::OffsetPackExpr * ) = 0; 71 virtual const ast::Expr * visit( const ast::AttrExpr * ) = 0; 72 virtual const ast::Expr * visit( const ast::LogicalExpr * ) = 0; 73 virtual const ast::Expr * visit( const ast::ConditionalExpr * ) = 0; 74 virtual const ast::Expr * visit( const ast::CommaExpr * ) = 0; 75 virtual const ast::Expr * visit( const ast::TypeExpr * ) = 0; 76 virtual const ast::Expr * visit( const ast::AsmExpr * ) = 0; 77 virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * ) = 0; 78 virtual const ast::Expr * visit( const ast::ConstructorExpr * ) = 0; 79 virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * ) = 0; 80 virtual const ast::Expr * visit( const ast::RangeExpr * ) = 0; 81 virtual const ast::Expr * visit( const ast::UntypedTupleExpr * ) = 0; 82 virtual const ast::Expr * visit( const ast::TupleExpr * ) = 0; 83 virtual const ast::Expr * visit( const ast::TupleIndexExpr * ) = 0; 84 virtual const ast::Expr * visit( const ast::TupleAssignExpr * ) = 0; 85 virtual const ast::Expr * visit( const ast::StmtExpr * ) = 0; 86 virtual const ast::Expr * visit( const ast::UniqueExpr * ) = 0; 87 virtual const ast::Expr * visit( const ast::UntypedInitExpr * ) = 0; 88 virtual const ast::Expr * visit( const ast::InitExpr * ) = 0; 89 virtual const ast::Expr * visit( const ast::DeletedExpr * ) = 0; 90 virtual const ast::Expr * visit( const ast::DefaultArgExpr * ) = 0; 91 virtual const ast::Expr * visit( const ast::GenericExpr * ) = 0; 92 virtual const ast::Type * visit( const ast::VoidType * ) = 0; 93 virtual const ast::Type * visit( const ast::BasicType * ) = 0; 94 virtual const ast::Type * visit( const ast::PointerType * ) = 0; 95 virtual const ast::Type * visit( const ast::ArrayType * ) = 0; 96 virtual const ast::Type * visit( const ast::ReferenceType * ) = 0; 97 virtual const ast::Type * visit( const ast::QualifiedType * ) = 0; 98 virtual const ast::Type * visit( const ast::FunctionType * ) = 0; 99 virtual const ast::Type * visit( const ast::StructInstType * ) = 0; 100 virtual const ast::Type * visit( const ast::UnionInstType * ) = 0; 101 virtual const ast::Type * visit( const ast::EnumInstType * ) = 0; 102 virtual const ast::Type * visit( const ast::TraitInstType * ) = 0; 103 virtual const ast::Type * visit( const ast::TypeInstType * ) = 0; 104 virtual const ast::Type * visit( const ast::TupleType * ) = 0; 105 virtual const ast::Type * visit( const ast::TypeofType * ) = 0; 106 virtual const ast::Type * visit( const ast::VarArgsType * ) = 0; 107 virtual const ast::Type * visit( const ast::ZeroType * ) = 0; 108 virtual const ast::Type * visit( const ast::OneType * ) = 0; 109 virtual const ast::Type * visit( const ast::GlobalScopeType * ) = 0; 110 virtual const ast::Designation * visit( const ast::Designation * ) = 0; 111 virtual const ast::Init * visit( const ast::SingleInit * ) = 0; 112 virtual const ast::Init * visit( const ast::ListInit * ) = 0; 113 virtual const ast::Init * visit( const ast::ConstructorInit * ) = 0; 114 virtual const ast::Constant * visit( const ast::Constant * ) = 0; 115 virtual const ast::Attribute * visit( const ast::Attribute * ) = 0; 116 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * ) = 0; 117 117 }; 118 118 -
src/AST/porting.md
r9e1d485 r69bafd2 10 10 ## Visitors ## 11 11 * `Visitor` and `Mutator` are combined into a single `ast::Visitor` class 12 * Base nodes now override ` Node* accept( Visitor& v ) = 0` with, e.g. `Stmt* accept( Visitor& v )override = 0`12 * Base nodes now override `const Node * accept( Visitor & v ) const = 0` with, e.g. `const Stmt * accept( Visitor & v ) const override = 0` 13 13 * `PassVisitor` is replaced with `ast::Pass` 14 14 … … 26 26 `clone` is private to `Node` now 27 27 * still needs to be overriden to return appropriate type 28 * e.g. `private: virtual Stmt* clone() const override = 0;` 28 * e.g. `private: virtual Stmt * clone() const override = 0;` 29 * because friendship is not inherited, all implementations of clone need 30 /// Must be copied in ALL derived classes 31 template<typename node_t> 32 friend auto mutate(const node_t * node); 29 33 30 34 All leaves of the `Node` inheritance tree are now declared `final` … … 170 174 171 175 `AttrType` 172 * did not port due to (likely) disuse173 * best guess at use (from printing code) is deprecated handling for attributes176 * did not port due to deprecation of feature 177 * feature is `type@thing` e.g. `int@MAX` 174 178 175 179 [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Type-Attributes.html#Type-Attributes -
src/Common/PassVisitor.h
r9e1d485 r69bafd2 155 155 virtual void visit( ConstructorInit * ctorInit ) override final; 156 156 157 virtual void visit( Subrange * subrange ) override final;158 159 157 virtual void visit( Constant * constant ) override final; 160 158 … … 257 255 virtual Initializer * mutate( ConstructorInit * ctorInit ) override final; 258 256 259 virtual Subrange * mutate( Subrange * subrange ) override final;260 261 257 virtual Constant * mutate( Constant * constant ) override final; 262 258 -
src/Common/PassVisitor.impl.h
r9e1d485 r69bafd2 2712 2712 2713 2713 //-------------------------------------------------------------------------- 2714 // Subrange2715 template< typename pass_type >2716 void PassVisitor< pass_type >::visit( Subrange * node ) {2717 VISIT_START( node );2718 2719 VISIT_END( node );2720 }2721 2722 template< typename pass_type >2723 Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) {2724 MUTATE_START( node );2725 2726 MUTATE_END( Subrange, node );2727 }2728 2729 //--------------------------------------------------------------------------2730 2714 // Attribute 2731 2715 template< typename pass_type > -
src/SynTree/Declaration.h
r9e1d485 r69bafd2 245 245 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 246 246 247 private:248 247 Kind kind; 249 248 }; … … 306 305 virtual void accept( Visitor &v ) override { v.visit( this ); } 307 306 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 308 private:309 307 DeclarationNode::Aggregate kind; 308 private: 310 309 virtual std::string typeString() const override; 311 310 }; -
src/SynTree/Label.h
r9e1d485 r69bafd2 35 35 operator std::string() const { return name; } 36 36 bool empty() { return name.empty(); } 37 private: 37 38 38 std::string name; 39 39 Statement * labelled; -
src/SynTree/Mutator.h
r9e1d485 r69bafd2 121 121 virtual Initializer * mutate( ConstructorInit * ctorInit ) = 0 ; 122 122 123 virtual Subrange * mutate( Subrange * subrange ) = 0;124 125 123 virtual Constant * mutate( Constant * constant ) = 0; 126 124 -
src/SynTree/SynTree.h
r9e1d485 r69bafd2 132 132 class ConstructorInit; 133 133 134 class Subrange;135 136 134 //template <class T> // emulate a union with templates? 137 135 class Constant; -
src/SynTree/Visitor.h
r9e1d485 r69bafd2 123 123 virtual void visit( ConstructorInit * ctorInit ) = 0; 124 124 125 virtual void visit( Subrange * subrange ) = 0;126 127 125 virtual void visit( Constant * constant ) = 0; 128 126
Note: See TracChangeset
for help on using the changeset viewer.