Appearance
| 1 | namespace Syntax.Trees.Definitions is | |
| 2 | ||
| 3 | use Source | |
| 4 | ||
| 5 | class USE(location: LOCATION, name: Identifiers.Identifier?, `use: Identifiers.Identifier?): Definition is | |
| 6 | // Set by the first use-resolution round when the used name bound. | |
| 7 | // A name that resolves only once members exist - a static method, | |
| 8 | // a global function, an enum member - stays unset and is retried | |
| 9 | // by the second round, after declare-members; the flag is written | |
| 10 | // unconditionally by round one, so it never carries stale state | |
| 11 | // across builds on a retained tree. | |
| 12 | is_import_resolved: bool public | |
| 13 | ||
| 14 | // A type alias - `use NAME[T] = <type expression>;` - names a type | |
| 15 | // rather than importing a symbol, so it carries a target type | |
| 16 | // expression and optional type parameters in place of `use`. | |
| 17 | arguments: TypeExpressions.LIST? public | |
| 18 | target: TypeExpressions.TypeExpression? public | |
| 19 | ||
| 20 | // The symbol declared for an alias clause, set by resolve-uses and | |
| 21 | // read by resolve-type-expressions. | |
| 22 | alias_symbol: Semantic.Symbols.TYPE_ALIAS? public | |
| 23 | ||
| 24 | is_alias: bool => target? | |
| 25 | ||
| 26 | // `use default` - the clause stands for the set of imports the | |
| 27 | // project declares, or the compiler's curated set. It carries no | |
| 28 | // name of its own, so it is the one clause with neither a `use` | |
| 29 | // identifier nor an alias target. | |
| 30 | is_default: bool public | |
| 31 | ||
| 32 | // `use X.*` - imports every usable member of the type or namespace | |
| 33 | // named by `` `use ``, rather than one symbol. A namespace target | |
| 34 | // resolves in the same round as a plain `use X;`; a class, struct, | |
| 35 | // union or enum target has no members to enumerate until | |
| 36 | // declare-members has run, so resolution stashes the resolved | |
| 37 | // container here and expands it in the second use-resolution round. | |
| 38 | is_all: bool public | |
| 39 | wildcard_target: Semantic.Symbols.Symbol? public | |
| 40 | ||
| 41 | super(location) | |
| 42 | ||
| 43 | init( | |
| 44 | .., | |
| 45 | arguments: TypeExpressions.LIST?, | |
| 46 | target: TypeExpressions.TypeExpression? | |
| 47 | ) is | |
| 48 | self.arguments = arguments | |
| 49 | self.target = target | |
| 50 | si | |
| 51 | ||
| 52 | accept(visitor: Visitor) is | |
| 53 | visitor.visit(self) | |
| 54 | si | |
| 55 | ||
| 56 | // wildcard_target is read as an authoritative cache before it is | |
| 57 | // ever reassigned (RESOLVE_USES._resolve_use_all reuses it rather | |
| 58 | // than re-resolving), unlike is_import_resolved and alias_symbol, | |
| 59 | // which round one always overwrites before either is read for a | |
| 60 | // decision. A retained node whose symbol table has since been | |
| 61 | // rebuilt would otherwise hand round one a dangling symbol. | |
| 62 | clear() is | |
| 63 | super.clear() | |
| 64 | ||
| 65 | is_import_resolved = false | |
| 66 | alias_symbol = null | |
| 67 | wildcard_target = null | |
| 68 | si | |
| 69 | ||
| 70 | walk(visitor: Visitor) is | |
| 71 | if !visitor.pre(self) then | |
| 72 | if name? then | |
| 73 | name.walk(visitor) | |
| 74 | fi | |
| 75 | ||
| 76 | if `use? then | |
| 77 | `use.walk(visitor) | |
| 78 | fi | |
| 79 | ||
| 80 | if let a = arguments then | |
| 81 | a.walk(visitor) | |
| 82 | fi | |
| 83 | ||
| 84 | if let t = target then | |
| 85 | t.walk(visitor) | |
| 86 | fi | |
| 87 | fi | |
| 88 | ||
| 89 | accept(visitor) | |
| 90 | si | |
| 91 | si | |
| 92 | si |