diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2014-02-22 10:18:33 +0100 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2014-02-22 10:21:24 +0100 |
commit | 3aa7f65240005a7d5ce26519248fa435f3ed3e5b (patch) | |
tree | f8e0c7fcec39cf294dbf3b3bbeb9f937daf3baf2 /compiler | |
parent | adb390af4bfbb3549672280007e9c46bf7a223c2 (diff) | |
download | Nim-3aa7f65240005a7d5ce26519248fa435f3ed3e5b.tar.gz |
Addresses issues raised on #947. Refs #800.
* 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.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/msgs.nim | 3 | ||||
-rw-r--r-- | compiler/pragmas.nim | 20 |
2 files changed, 10 insertions, 13 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 8c41a8191..0140d1ac4 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -105,7 +105,7 @@ type errThreadvarCannotInit, errWrongSymbolX, errIllegalCaptureX, errXCannotBeClosure, errXMustBeCompileTime, errCannotInferTypeOfTheLiteral, - errBadExport, errUser + errUser, warnCannotOpenFile, warnOctalEscape, warnXIsNeverRead, warnXmightNotBeenInit, warnDeprecated, warnConfigDeprecated, @@ -350,7 +350,6 @@ const errXCannotBeClosure: "'$1' cannot have 'closure' calling convention", errXMustBeCompileTime: "'$1' can only be used in compile-time context", errCannotInferTypeOfTheLiteral: "cannot infer the type of the $1", - errBadExport: "invalid exported symbol, $1", errUser: "$1", warnCannotOpenFile: "cannot open \'$1\' [CannotOpenFile]", warnOctalEscape: "octal escape sequences do not exist; leading zero is ignored [OctalEscape]", diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 6e21a85b9..75c16f6cd 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -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) = |