* Uses errGenerated instead of deprecated extending of enums. * Reduces bloat and usefulness of end user error messages. * Limits checks to C, Cpp and Objc targets.
This commit is contained in:
parent
adb390af4b
commit
3aa7f65240
2 changed files with 10 additions and 13 deletions
|
|
@ -99,25 +99,23 @@ proc makeExternImport(s: PSym, extname: string) =
|
|||
|
||||
const invalidIdentChars = AllChars - IdentChars
|
||||
|
||||
proc validateExternName(s: PSym, info: TLineInfo) =
|
||||
proc validateExternCName(s: PSym, info: TLineInfo) =
|
||||
## Validates that the symbol name in s.loc.r is a valid C identifier.
|
||||
##
|
||||
## Valid identifiers are those alphanumeric including the underscore not
|
||||
## starting with a number. If the check fails, a friendly error will be
|
||||
## starting with a number. If the check fails, a generic error will be
|
||||
## displayed to the user.
|
||||
let target = ropeToStr(s.loc.r)
|
||||
if target.len < 1:
|
||||
localError(info, errBadExport, "can't be zero length")
|
||||
if not (target[0] in IdentStartChars):
|
||||
localError(info, errBadExport, "'" & target & "' can't start with a number")
|
||||
if not target.allCharsInSet(IdentChars):
|
||||
let pos = target.find(invalidIdentChars, 1)
|
||||
localError(info, errBadExport, "'" & target &
|
||||
"' contains bad character at byte " & $pos)
|
||||
if target.len < 1 or (not (target[0] in IdentStartChars)) or
|
||||
(not target.allCharsInSet(IdentChars)):
|
||||
localError(info, errGenerated, "invalid exported symbol")
|
||||
|
||||
proc makeExternExport(s: PSym, extname: string, info: TLineInfo) =
|
||||
setExternName(s, extname)
|
||||
validateExternName(s, info)
|
||||
case gCmd
|
||||
of cmdCompileToC, cmdCompileToCpp, cmdCompileToOC:
|
||||
validateExternCName(s, info)
|
||||
else: discard
|
||||
incl(s.flags, sfExportc)
|
||||
|
||||
proc processImportCompilerProc(s: PSym, extname: string) =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue