Building Scope Trees for Classes
Classes are like structs in that they can inherit members from another class (the superclass). That means classes have two parent scopes: the usual enclosing scope (physical location) and a superclass scope. To resolve symbols, sometimes we’ll chase the enclosing scope pointer, and sometimes we’ll chase the superclass pointer. Let’s start by looking at the scope tree for the following Cymbol code (see Figure 17, Scope tree for classes A and B).
symtab/class/AB.cymbol | |
① | // start of global scope // |
② | class A { |
| public: |
| int x; |
③ | void foo() |
④ | { ; } |
| }; ... |
Get Language Implementation Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.