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 1 commit
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
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
x.val = nil
```

- getImpl() on enum type symbols now return field syms instead of idents. This helps
with writing typed macros.

## 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: PNode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer identToReplace: ptr PNode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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 = n[i][0][0]
pragma(c, e, n[i][0][1], enumFieldPragmas)
else:
e = newSymS(skEnumField, n[i][0], c)
identToReplace = 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 = n[i]
of nkPragmaExpr:
e = newSymS(skEnumField, n[i][0], c)
pragma(c, e, n[i][1], enumFieldPragmas)
identToReplace = n[i][0]
else:
illFormedAst(n[i], c.config)
e.typ = result
e.position = int(counter)
let symNode = newSymNode(e)
if 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