diff options
author | Neelesh Chandola <neelesh.chandola@outlook.com> | 2018-12-30 14:13:59 +0530 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-12-30 09:43:59 +0100 |
commit | c5ad4c10cb976960a37656a55ad2fdbb0add8861 (patch) | |
tree | 3b8c89ec5a9269788471ea227f49ae3ccf669709 /compiler | |
parent | a6633b965891a7f5e70ac6fcf41d4142145b69c2 (diff) | |
download | Nim-c5ad4c10cb976960a37656a55ad2fdbb0add8861.tar.gz |
Deprecated pragma is now supported on enum fields (#10113)
* {.deprecated.} pragma is now supported for enum fields * Add tests * Simplify code
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/parser.nim | 32 | ||||
-rw-r--r-- | compiler/pragmas.nim | 1 | ||||
-rw-r--r-- | compiler/semtypes.nim | 10 |
3 files changed, 31 insertions, 12 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index c2c8427c8..163ad6455 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1765,7 +1765,7 @@ proc parseSection(p: var TParser, kind: TNodeKind, parMessage(p, errIdentifierExpected, p.tok) proc parseEnum(p: var TParser): PNode = - #| enum = 'enum' optInd (symbol optInd ('=' optInd expr COMMENT?)? comma?)+ + #| enum = 'enum' optInd (symbol optPragmas optInd ('=' optInd expr COMMENT?)? comma?)+ result = newNodeP(nkEnumTy, p) getTok(p) addSon(result, p.emptyNode) @@ -1775,25 +1775,35 @@ proc parseEnum(p: var TParser): PNode = while true: var a = parseSymbol(p) if a.kind == nkEmpty: return + + var symPragma = a + var pragma: PNode + if p.tok.tokType == tkCurlyDotLe: + pragma = optPragmas(p) + symPragma = newNodeP(nkPragmaExpr, p) + addSon(symPragma, a) + addSon(symPragma, pragma) + if p.tok.indent >= 0 and p.tok.indent <= p.currInd: - add(result, a) + add(result, symPragma) break + if p.tok.tokType == tkEquals and p.tok.indent < 0: getTok(p) - optInd(p, a) - var b = a - a = newNodeP(nkEnumFieldDef, p) - addSon(a, b) - addSon(a, parseExpr(p)) + optInd(p, symPragma) + var b = symPragma + symPragma = newNodeP(nkEnumFieldDef, p) + addSon(symPragma, b) + addSon(symPragma, parseExpr(p)) if p.tok.indent < 0 or p.tok.indent >= p.currInd: - rawSkipComment(p, a) + rawSkipComment(p, symPragma) if p.tok.tokType == tkComma and p.tok.indent < 0: getTok(p) - rawSkipComment(p, a) + rawSkipComment(p, symPragma) else: if p.tok.indent < 0 or p.tok.indent >= p.currInd: - rawSkipComment(p, a) - addSon(result, a) + rawSkipComment(p, symPragma) + addSon(result, symPragma) if p.tok.indent >= 0 and p.tok.indent <= p.currInd or p.tok.tokType == tkEof: break diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 78021667e..58f64f7b0 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -73,6 +73,7 @@ const wThread, wRaises, wLocks, wTags, wGcSafe} forVarPragmas* = {wInject, wGensym} allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas + enumFieldPragmas* = {wDeprecated} proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode = let p = procAst[pragmasPos] diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index e0f04c22f..200b247ca 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -80,9 +80,14 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = if isPure: initStrTable(symbols) var hasNull = false for i in countup(1, sonsLen(n) - 1): + if n.sons[i].kind == nkEmpty: continue case n.sons[i].kind of nkEnumFieldDef: - e = newSymS(skEnumField, n.sons[i].sons[0], c) + if n.sons[i].sons[0].kind == nkPragmaExpr: + e = newSymS(skEnumField, n.sons[i].sons[0].sons[0], c) + pragma(c, e, n.sons[i].sons[0].sons[1], enumFieldPragmas) + else: + e = newSymS(skEnumField, n.sons[i].sons[0], c) var v = semConstExpr(c, n.sons[i].sons[1]) var strVal: PNode = nil case skipTypes(v.typ, abstractInst-{tyTypeDesc}).kind @@ -115,6 +120,9 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = e = n.sons[i].sym of nkIdent, nkAccQuoted: e = newSymS(skEnumField, n.sons[i], c) + of nkPragmaExpr: + e = newSymS(skEnumField, n.sons[i].sons[0], c) + pragma(c, e, n.sons[i].sons[1], enumFieldPragmas) else: illFormedAst(n[i], c.config) e.typ = result |