Skip to content

Commit fbe1a64

Browse files
committed
~~unmangle~~ demangle
1 parent b90ae1d commit fbe1a64

File tree

2 files changed

+147
-147
lines changed

2 files changed

+147
-147
lines changed

src/Lean/Compiler/NameMangling.lean

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,31 @@ public def mkModuleInitializationFunctionName (moduleName : Name) : String :=
165165
"initialize_" ++ moduleName.mangle ""
166166

167167
-- assumes `s` has been generated `Name.mangle n ""`
168-
def Name.unmangleAux (s : String) (p : s.ValidPos) (res : Name)
168+
def Name.demangleAux (s : String) (p : s.ValidPos) (res : Name)
169169
(acc : String) (ucount : Nat) : Name :=
170170
if h : p = s.endValidPos then res.str (acc.pushn '_' (ucount / 2)) else
171171
let ch := p.get h
172172
let p := p.next h
173-
if ch = '_' then unmangleAux s p res acc (ucount + 1) else
173+
if ch = '_' then demangleAux s p res acc (ucount + 1) else
174174
if ucount % 2 = 0 then
175-
unmangleAux s p res (acc.pushn '_' (ucount / 2) |>.push ch) 0
175+
demangleAux s p res (acc.pushn '_' (ucount / 2) |>.push ch) 0
176176
else if ch.isDigit then
177177
let res := res.str (acc.pushn '_' (ucount / 2))
178178
if h : ch = '0' ∧ ∃ h : p ≠ s.endValidPos, p.get h = '0' then
179-
unmangleAux s (p.next h.2.1) res "" 0
179+
demangleAux s (p.next h.2.1) res "" 0
180180
else
181181
decodeNum s p res (ch.val - 48).toNat
182182
else if h : ch = 'x' ∧ checkLowerHex 2 s p then
183183
let acc := acc.pushn '_' (ucount / 2)
184-
unmangleAux s ⟨_, valid_of_checkLowerHex h.2⟩ res (acc.push (Char.ofNat (parseLowerHex 2 s p h.2 0))) 0
184+
demangleAux s ⟨_, valid_of_checkLowerHex h.2⟩ res (acc.push (Char.ofNat (parseLowerHex 2 s p h.2 0))) 0
185185
else if h : ch = 'u' ∧ checkLowerHex 4 s p then
186186
let acc := acc.pushn '_' (ucount / 2)
187-
unmangleAux s ⟨_, valid_of_checkLowerHex h.2⟩ res (acc.push (Char.ofNat (parseLowerHex 4 s p h.2 0))) 0
187+
demangleAux s ⟨_, valid_of_checkLowerHex h.2⟩ res (acc.push (Char.ofNat (parseLowerHex 4 s p h.2 0))) 0
188188
else if h : ch = 'U' ∧ checkLowerHex 8 s p then
189189
let acc := acc.pushn '_' (ucount / 2)
190-
unmangleAux s ⟨_, valid_of_checkLowerHex h.2⟩ res (acc.push (Char.ofNat (parseLowerHex 8 s p h.2 0))) 0
190+
demangleAux s ⟨_, valid_of_checkLowerHex h.2⟩ res (acc.push (Char.ofNat (parseLowerHex 8 s p h.2 0))) 0
191191
else
192-
unmangleAux s p (res.str acc) ("".pushn '_' (ucount / 2) |>.push ch) 0
192+
demangleAux s p (res.str acc) ("".pushn '_' (ucount / 2) |>.push ch) 0
193193
termination_by p.remainingBytes
194194
decreasing_by
195195
· apply String.ValidPos.remainingBytes_next_lt
@@ -226,29 +226,29 @@ where
226226
let p := p.next h
227227
if ch.isDigit then
228228
if h : ch = '0' ∧ ∃ h : p ≠ s.endValidPos, p.get h = '0' then
229-
unmangleAux s (p.next h.2.1) res "" 0
229+
demangleAux s (p.next h.2.1) res "" 0
230230
else
231231
decodeNum s p res (ch.val - 48).toNat
232232
else if ch = '_' then
233-
unmangleAux s p res "" 1
233+
demangleAux s p res "" 1
234234
else
235-
unmangleAux s p res (String.singleton ch) 0
235+
demangleAux s p res (String.singleton ch) 0
236236
termination_by p.remainingBytes
237237
decreasing_by
238238
· apply String.ValidPos.remainingBytes_next_lt_of_lt
239239
(Nat.lt_trans (String.ValidPos.lt_next _) (String.ValidPos.lt_next _))
240240
all_goals apply String.ValidPos.remainingBytes_next_lt
241241

242242
/-- Assuming `s` has been produced by `Name.mangle _ ""`, return the original name. -/
243-
public def Name.unmangle (s : String) : Name :=
244-
unmangleAux.nameStart s s.startValidPos .anonymous
243+
public def Name.demangle (s : String) : Name :=
244+
demangleAux.nameStart s s.startValidPos .anonymous
245245

246246
/--
247-
Returns the unmangled version of `s`, if it's the result of `Name.mangle _ ""`. Otherwise returns
247+
Returns the demangled version of `s`, if it's the result of `Name.mangle _ ""`. Otherwise returns
248248
`none`.
249249
-/
250-
public def Name.unmangle? (s : String) : Option Name :=
251-
let n := unmangle s
250+
public def Name.demangle? (s : String) : Option Name :=
251+
let n := demangle s
252252
if mangleAux n = s then some n else none
253253

254254
end Lean

0 commit comments

Comments
 (0)