Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace enum fields idents with syms #14048

Merged
merged 4 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
x.val = nil
```

- getImpl() on enum type symbols now returns field syms instead of idents. This helps
with writing typed macros. Old behavior for backwards compatiblity can be restored
with command line switch `--oldast`.

## Compiler changes

- Specific warnings can now be turned into errors via `--warningAsError[X]:on|off`.
Expand Down
10 changes: 9 additions & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
counter, x: BiggestInt
e: PSym
base: PType
identToReplace: ptr PNode
counter = 0
base = nil
result = newOrPrevType(tyEnum, prev, c)
Expand All @@ -83,9 +84,11 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
of nkEnumFieldDef:
if n[i][0].kind == nkPragmaExpr:
e = newSymS(skEnumField, n[i][0][0], c)
identToReplace = addr n[i][0][0]
pragma(c, e, n[i][0][1], enumFieldPragmas)
else:
e = newSymS(skEnumField, n[i][0], c)
identToReplace = addr n[i][0]
var v = semConstExpr(c, n[i][1])
var strVal: PNode = nil
case skipTypes(v.typ, abstractInst-{tyTypeDesc}).kind
Expand Down Expand Up @@ -118,19 +121,24 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
e = n[i].sym
of nkIdent, nkAccQuoted:
e = newSymS(skEnumField, n[i], c)
identToReplace = addr n[i]
of nkPragmaExpr:
e = newSymS(skEnumField, n[i][0], c)
pragma(c, e, n[i][1], enumFieldPragmas)
identToReplace = addr n[i][0]
else:
illFormedAst(n[i], c.config)
e.typ = result
e.position = int(counter)
let symNode = newSymNode(e)
if optOldAst notin c.config.options and identToReplace != nil:
identToReplace[] = symNode
if e.position == 0: hasNull = true
if result.sym != nil and sfExported in result.sym.flags:
incl(e.flags, sfUsed)
incl(e.flags, sfExported)
if not isPure: strTableAdd(c.module.tab, e)
result.n.add newSymNode(e)
result.n.add symNode
styleCheckDef(c.config, e)
onDef(e.info, e)
if sfGenSym notin e.flags:
Expand Down