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