Appearance
| 1 | namespace Semantic.DotNet is | |
| 2 | use TYPE = System.Type; | |
| 3 | ||
| 4 | use System.Reflection.Assembly; | |
| 5 | ||
| 6 | use IO.Std; | |
| 7 | ||
| 8 | use Collections.MAP; | |
| 9 | use Collections.SET; | |
| 10 | use Collections.LIST; | |
| 11 | use Collections.Iterable; | |
| 12 | ||
| 13 | use Logging.TIMERS; | |
| 14 | ||
| 15 | class GHUL_NAMESPACE_CREATOR( | |
| 16 | _timers: TIMERS, | |
| 17 | _ghul_symbol_table: Semantic.SYMBOL_TABLE, | |
| 18 | _namespaces: NAMESPACES, | |
| 19 | _type_details_lookup: TYPE_DETAILS_LOOKUP | |
| 20 | ) is | |
| 21 | _is_enabled: bool; | |
| 22 | _is_started: bool; | |
| 23 | ||
| 24 | init(..) is | |
| 25 | _is_enabled = true; | |
| 26 | si | |
| 27 | ||
| 28 | disable() is | |
| 29 | _is_enabled = false; | |
| 30 | si | |
| 31 | ||
| 32 | create_namespaces() is | |
| 33 | if !_is_enabled then | |
| 34 | return; | |
| 35 | fi | |
| 36 | ||
| 37 | let current mut = LIST[string](); | |
| 38 | ||
| 39 | let namespaces = LIST[string](); | |
| 40 | ||
| 41 | for ns in _type_details_lookup.ghul_namespaces do | |
| 42 | namespaces.add(ns); | |
| 43 | od | |
| 44 | ||
| 45 | namespaces.sort(); | |
| 46 | ||
| 47 | for a in namespaces do | |
| 48 | let to_create = LIST(a.split(['.'])); | |
| 49 | ||
| 50 | while current.count > to_create.count do | |
| 51 | _namespaces.leave_namespace(null, null); | |
| 52 | _ghul_symbol_table.leave_scope(); | |
| 53 | current.remove_at(current.count - 1); | |
| 54 | od | |
| 55 | ||
| 56 | let index mut = 0; | |
| 57 | ||
| 58 | while index < current.count /\ current[index] =~ to_create[index] do | |
| 59 | index = index + 1; | |
| 60 | od | |
| 61 | ||
| 62 | while current.count > index do | |
| 63 | _namespaces.leave_namespace(null, null); | |
| 64 | _ghul_symbol_table.leave_scope(); | |
| 65 | current.remove_at(current.count - 1); | |
| 66 | od | |
| 67 | ||
| 68 | for i in index..to_create.count do | |
| 69 | let ns = _namespaces.declare_and_enter_namespace(Source.LOCATION.internal, to_create[i], null, false); | |
| 70 | _ghul_symbol_table.enter_scope(ns); | |
| 71 | od | |
| 72 | ||
| 73 | current = to_create; | |
| 74 | od | |
| 75 | ||
| 76 | while current.count > 0 do | |
| 77 | _namespaces.leave_namespace(null, null); | |
| 78 | _ghul_symbol_table.leave_scope(); | |
| 79 | current.remove_at(current.count - 1); | |
| 80 | od | |
| 81 | si | |
| 82 | si | |
| 83 | si |