# # # The Nim Compiler # (c) Copyright 2017 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # # included from cgen.nim # ------------------------- Name Mangling -------------------------------- import sighashes from lowerings import createObj proc genProcHeader(m: BModule, prc: PSym): Rope proc isKeyword(w: PIdent): bool = # Nim and C++ share some keywords # it's more efficient to test the whole Nim keywords range case w.id of ccgKeywordsLow..ccgKeywordsHigh, nimKeywordsLow..nimKeywordsHigh, ord(wInline): return true else: return false proc mangleField(m: BModule; name: PIdent): string = result = mangle(name.s) # fields are tricky to get right and thanks to generic types producing # duplicates we can end up mangling the same field multiple times. However # if we do so, the 'cppDefines' table might be modified in the meantime # meaning we produce inconsistent field names (see bug #5404). # Hence we do not check for ``m.g.config.cppDefines.contains(result)`` here # anymore: if isKeyword(name): result.add "_0" when false: proc hashOwner(s: PSym): SigHash = var m = s while m.kind != skModule: m = m.owner let p = m.owner assert p.kind == skPackage result = gDebugInfo.register(p.name.s, m.name.s) proc mangleName(m: BModule; s: PSym): Rope = result = s.loc.r if result == nil: result = s.name.s.mangle.rope add(result, idOrSig(s, m.module.name.s.mangle, m.sigConflicts)) s.loc.r = result writeMangledName(m.ndi, s, m.config) proc mangleParamName(m: BModule; s: PSym): Rope = ## we cannot use 'sigConflicts' here since we have a BModule, not a BProc. ## Fortunately C's scoping rules are sane enough so that that doesn't ## cause any trouble. result = s.loc.r if result == nil: var res = s.name.s.mangle if isKeyword(s.name) or m.g.config.cppDefines.contains(res): res.add "_0" result = res.rope s.loc.r = result writeMangledName(m.ndi, s, m.config) proc mangleLocalName(p: BProc; s: PSym): Rope = assert s.kind in skLocalVars+{skTemp} #assert sfGlobal notin s.flags result = s.loc.r if result == nil: var key = s.name.s.mangle shallow(key) let counter = p.sigConflicts.getOrDefault(key) result = key.rope if s.kind == skTemp: # speed up conflict search for temps (these are quite common): if counter != 0: result.add "_" & rope(counter+1) elif counter != 0 or isKeyword(s.name) or p.module.g.config.cppDefines.contains(key): result.add "_" & rope(counter+1) p.sigConflicts.inc(key) s.loc.r = result if s.kind != skTemp: writeMangledName(p.module.ndi, s, p.config) proc scopeMangledParam(p: BProc; param: PSym) = ## parameter generation only takes BModule, not a BProc, so we have to ## remember these parameter names are already in scope to be able to ## generate unique identifiers reliably (consider that ``var a = a`` is ## even an idiom in Nim). var key = param.name.s.mangle shallow(key) p.sigConflicts.inc(key) const irrelevantForBackend = {tyGenericBody, tyGenericInst, tyGenericInvocation, tyDistinct, tyRange, tyStatic, tyAlias, tySink, tyInferred} proc typeName(typ: PType): Rope = let typ = typ.skipTypes(irrelevantForBackend) result = if typ.sym != nil and typ.kind in {tyObject, tyEnum}: rope($typ.kind & '_' & typ.sym.name.s.mangle) else: rope($typ.kind) proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope = var t = typ while true: if t.sym != nil and {sfImportc, sfExportc} * t.sym.flags != {}: return t.sym.loc.r if t.kind in irrelevantForBackend: t = t.lastSon else: break let typ = if typ.kind in {tyAlias, tySink}: typ.lastSon else: typ if typ.loc.r == nil: typ.loc.r = typ.typeName & $sig else: when defined(debugSigHashes): # check consistency: assert
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: package ranger.container</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.container</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/container/__init__.py">/home/hut/ranger/ranger/container/__init__.py</a></font></td></tr></table>
<p><tt>This package includes container-objects which are<br>
used to manage stored data</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Package Contents</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="ranger.container.bookmarks.html">bookmarks</a><br>
<a href="ranger.container.commandlist.html">commandlist</a><br>
</td><td width="25%" valign=top><a href="ranger.container.environment.html">environment</a><br>
<a href="ranger.container.history.html">history</a><br>
</td><td width="25%" valign=top><a href="ranger.container.keybuffer.html">keybuffer</a><br>
<a href="ranger.container.tags.html">tags</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table>
</body></html>