Appearance
| 1 | namespace Semantic is | |
| 2 | use Source.LOCATION | |
| 3 | ||
| 4 | use Collections.LIST | |
| 5 | use Collections.MAP | |
| 6 | ||
| 7 | // One origin per expression whose result type the body's walks have | |
| 8 | // to settle, kept for as long as that body is being compiled. The | |
| 9 | // walks of a body revisit the same expression, and the bounds each | |
| 10 | // walk records have to land on the same origin for the next walk to | |
| 11 | // read them, so an expression is its own key. A body compiled during | |
| 12 | // another's walk has an origin table of its own. | |
| 13 | class RESULT_ORIGINS is | |
| 14 | _bodies: LIST[MAP[object, Symbols.INFERRED_RESULT_ORIGIN]] static | |
| 15 | ||
| 16 | init() static is | |
| 17 | _bodies = LIST[MAP[object, Symbols.INFERRED_RESULT_ORIGIN]]() | |
| 18 | si | |
| 19 | ||
| 20 | begin_body() static is | |
| 21 | _bodies.add(MAP[object, Symbols.INFERRED_RESULT_ORIGIN]()) | |
| 22 | si | |
| 23 | ||
| 24 | end_body() static is | |
| 25 | if _bodies.count > 0 then | |
| 26 | _bodies.remove_at(_bodies.count - 1) | |
| 27 | fi | |
| 28 | si | |
| 29 | ||
| 30 | // The origin standing for `node`'s result in the body being | |
| 31 | // compiled, made on first request. Outside any body there are no | |
| 32 | // walks to settle an origin, so there is none to give. | |
| 33 | origin_for(node: object, location: LOCATION, owner: Scope, name: string) -> Symbols.INFERRED_RESULT_ORIGIN? static is | |
| 34 | if _bodies.count == 0 then | |
| 35 | return null | |
| 36 | fi | |
| 37 | ||
| 38 | let origins = _bodies[_bodies.count - 1] | |
| 39 | ||
| 40 | if origins.contains_key(node) then | |
| 41 | return origins[node] | |
| 42 | fi | |
| 43 | ||
| 44 | let result = Symbols.INFERRED_RESULT_ORIGIN(location, owner, name) | |
| 45 | ||
| 46 | origins[node] = result | |
| 47 | ||
| 48 | return result | |
| 49 | si | |
| 50 | si | |
| 51 | si |