lfFullExternalName for 'nimrod pretty'

This commit is contained in:
Araq 2013-07-30 17:15:58 +02:00
commit d640121ce6
3 changed files with 14 additions and 7 deletions

View file

@ -795,6 +795,9 @@ const
skLocalVars* = {skVar, skLet, skForVar, skParam, skResult} skLocalVars* = {skVar, skLet, skForVar, skParam, skResult}
lfFullExternalName* = lfParamCopy # \
# only used when 'gCmd == cmdPretty': Indicates that the symbol has been
# imported via 'importc: "fullname"' and no format string.
# creator procs: # creator procs:
proc NewSym*(symKind: TSymKind, Name: PIdent, owner: PSym, proc NewSym*(symKind: TSymKind, Name: PIdent, owner: PSym,

View file

@ -84,8 +84,11 @@ proc pragmaAsm*(c: PContext, n: PNode): char =
else: else:
invalidPragma(it) invalidPragma(it)
proc setExternName(s: PSym, extname: string) = proc setExternName(s: PSym, extname: string) =
s.loc.r = toRope(extname % s.name.s) s.loc.r = toRope(extname % s.name.s)
if gCmd == cmdPretty and '$' notin extname:
# note that '{.importc.}' is transformed into '{.importc: "$1".}'
s.loc.flags.incl(lfFullExternalName)
proc MakeExternImport(s: PSym, extname: string) = proc MakeExternImport(s: PSym, extname: string) =
setExternName(s, extname) setExternName(s, extname)
@ -513,11 +516,11 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
if k in validPragmas: if k in validPragmas:
case k case k
of wExportc: of wExportc:
makeExternExport(sym, getOptionalStr(c, it, sym.name.s)) makeExternExport(sym, getOptionalStr(c, it, "$1"))
incl(sym.flags, sfUsed) # avoid wrong hints incl(sym.flags, sfUsed) # avoid wrong hints
of wImportc: makeExternImport(sym, getOptionalStr(c, it, sym.name.s)) of wImportc: makeExternImport(sym, getOptionalStr(c, it, "$1"))
of wImportCompilerProc: of wImportCompilerProc:
processImportCompilerProc(sym, getOptionalStr(c, it, sym.name.s)) processImportCompilerProc(sym, getOptionalStr(c, it, "$1"))
of wExtern: setExternName(sym, expectStrLit(c, it)) of wExtern: setExternName(sym, expectStrLit(c, it))
of wImmediate: of wImmediate:
if sym.kind in {skTemplate, skMacro}: incl(sym.flags, sfImmediate) if sym.kind in {skTemplate, skMacro}: incl(sym.flags, sfImmediate)
@ -526,9 +529,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
if sym.kind == skTemplate: incl(sym.flags, sfDirty) if sym.kind == skTemplate: incl(sym.flags, sfDirty)
else: invalidPragma(it) else: invalidPragma(it)
of wImportCpp: of wImportCpp:
processImportCpp(sym, getOptionalStr(c, it, sym.name.s)) processImportCpp(sym, getOptionalStr(c, it, "$1"))
of wImportObjC: of wImportObjC:
processImportObjC(sym, getOptionalStr(c, it, sym.name.s)) processImportObjC(sym, getOptionalStr(c, it, "$1"))
of wAlign: of wAlign:
if sym.typ == nil: invalidPragma(it) if sym.typ == nil: invalidPragma(it)
var align = expectIntLit(c, it) var align = expectIntLit(c, it)

View file

@ -119,7 +119,8 @@ proc processSym(c: PPassContext, n: PNode): PNode =
if {sfImportc, sfExportc} * s.flags != {}: if {sfImportc, sfExportc} * s.flags != {}:
# careful, we must ensure the resulting name still matches the external # careful, we must ensure the resulting name still matches the external
# name: # name:
if newName != s.name.s and newName != s.loc.r.ropeToStr: if newName != s.name.s and newName != s.loc.r.ropeToStr and
lfFullExternalName notin s.loc.flags:
Message(n.info, errGenerated, Message(n.info, errGenerated,
"cannot rename $# to $# due to external name" % [s.name.s, newName]) "cannot rename $# to $# due to external name" % [s.name.s, newName])
cannotRename.incl(s.id) cannotRename.incl(s.id)