mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
allow non-pragma special words as user pragmas (#22526)
allow non-pragma special words as macro pragmas
fixes #22525
(cherry picked from commit 602f537eb2)
This commit is contained in:
@@ -133,10 +133,12 @@ proc whichPragma*(n: PNode): TSpecialWord =
|
||||
case key.kind
|
||||
of nkIdent: result = whichKeyword(key.ident)
|
||||
of nkSym: result = whichKeyword(key.sym.name)
|
||||
of nkCast: result = wCast
|
||||
of nkCast: return wCast
|
||||
of nkClosedSymChoice, nkOpenSymChoice:
|
||||
result = whichPragma(key[0])
|
||||
else: result = wInvalid
|
||||
return whichPragma(key[0])
|
||||
else: return wInvalid
|
||||
if result in nonPragmaWordsLow..nonPragmaWordsHigh:
|
||||
result = wInvalid
|
||||
|
||||
proc isNoSideEffectPragma*(n: PNode): bool =
|
||||
var k = whichPragma(n)
|
||||
|
||||
@@ -91,28 +91,36 @@ type
|
||||
wRedefine = "redefine", wCallsite = "callsite",
|
||||
wQuirky = "quirky",
|
||||
|
||||
# codegen keywords, but first the ones that are also pragmas:
|
||||
wExtern = "extern", wGoto = "goto", wRegister = "register",
|
||||
wUnion = "union", wPacked = "packed", wVirtual = "virtual",
|
||||
wVolatile = "volatile", wMember = "member",
|
||||
wByCopy = "bycopy", wByRef = "byref",
|
||||
|
||||
# codegen keywords but not pragmas:
|
||||
wAuto = "auto", wBool = "bool", wCatch = "catch", wChar = "char",
|
||||
wClass = "class", wCompl = "compl", wConstCast = "const_cast", wDefault = "default",
|
||||
wDelete = "delete", wDouble = "double", wDynamicCast = "dynamic_cast",
|
||||
wExplicit = "explicit", wExtern = "extern", wFalse = "false", wFloat = "float",
|
||||
wFriend = "friend", wGoto = "goto", wInt = "int", wLong = "long", wMutable = "mutable",
|
||||
wExplicit = "explicit", wFalse = "false", wFloat = "float",
|
||||
wFriend = "friend", wInt = "int", wLong = "long", wMutable = "mutable",
|
||||
wNamespace = "namespace", wNew = "new", wOperator = "operator", wPrivate = "private",
|
||||
wProtected = "protected", wPublic = "public", wRegister = "register",
|
||||
wProtected = "protected", wPublic = "public",
|
||||
wReinterpretCast = "reinterpret_cast", wRestrict = "restrict", wShort = "short",
|
||||
wSigned = "signed", wSizeof = "sizeof", wStaticCast = "static_cast", wStruct = "struct",
|
||||
wSwitch = "switch", wThis = "this", wThrow = "throw", wTrue = "true", wTypedef = "typedef",
|
||||
wTypeid = "typeid", wTypeof = "typeof", wTypename = "typename",
|
||||
wUnion = "union", wPacked = "packed", wUnsigned = "unsigned", wVirtual = "virtual",
|
||||
wVoid = "void", wVolatile = "volatile", wWchar = "wchar_t",
|
||||
wUnsigned = "unsigned", wVoid = "void",
|
||||
|
||||
wAlignas = "alignas", wAlignof = "alignof", wConstexpr = "constexpr", wDecltype = "decltype",
|
||||
wNullptr = "nullptr", wNoexcept = "noexcept",
|
||||
wThreadLocal = "thread_local", wStaticAssert = "static_assert",
|
||||
wChar16 = "char16_t", wChar32 = "char32_t",
|
||||
wChar16 = "char16_t", wChar32 = "char32_t", wWchar = "wchar_t",
|
||||
|
||||
wStdIn = "stdin", wStdOut = "stdout", wStdErr = "stderr",
|
||||
|
||||
wInOut = "inout", wByCopy = "bycopy", wByRef = "byref", wOneWay = "oneway",
|
||||
wInOut = "inout", wOneWay = "oneway",
|
||||
# end of codegen keywords
|
||||
|
||||
wBitsize = "bitsize", wImportHidden = "all",
|
||||
wSendable = "sendable"
|
||||
|
||||
@@ -125,12 +133,15 @@ const
|
||||
nimKeywordsLow* = ord(wAsm)
|
||||
nimKeywordsHigh* = ord(wYield)
|
||||
|
||||
ccgKeywordsLow* = ord(wAuto)
|
||||
ccgKeywordsLow* = ord(wExtern)
|
||||
ccgKeywordsHigh* = ord(wOneWay)
|
||||
|
||||
cppNimSharedKeywords* = {
|
||||
wAsm, wBreak, wCase, wConst, wContinue, wDo, wElse, wEnum, wExport,
|
||||
wFor, wIf, wReturn, wStatic, wTemplate, wTry, wWhile, wUsing}
|
||||
|
||||
nonPragmaWordsLow* = wAuto
|
||||
nonPragmaWordsHigh* = wOneWay
|
||||
|
||||
|
||||
from std/enumutils import genEnumCaseStmt
|
||||
|
||||
@@ -68,3 +68,8 @@ block: # issue #10994
|
||||
|
||||
proc a {.bar.} = discard # works
|
||||
proc b {.bar, foo.} = discard # doesn't
|
||||
|
||||
block: # issue #22525
|
||||
macro catch(x: typed) = x
|
||||
proc thing {.catch.} = discard
|
||||
thing()
|
||||
|
||||
Reference in New Issue
Block a user