Skip to content

Commit

Permalink
finally de-deprecate the .define and .undef pragmas
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Apr 4, 2020
1 parent 9c46927 commit a890aa7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## Compiler changes

- Specific warnings can now be turned into errors via `--warningAsError[X]:on|off`.
- The `define` and `undef` pragmas have been de-deprecated.

## Tool changes

2 changes: 0 additions & 2 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,12 @@ proc processPop(c: PContext, n: PNode) =
proc processDefine(c: PContext, n: PNode) =
if (n.kind in nkPragmaCallKinds and n.len == 2) and (n[1].kind == nkIdent):
defineSymbol(c.config.symbols, n[1].ident.s)
message(c.config, n.info, warnDeprecated, "define is deprecated")
else:
invalidPragma(c, n)

proc processUndef(c: PContext, n: PNode) =
if (n.kind in nkPragmaCallKinds and n.len == 2) and (n[1].kind == nkIdent):
undefSymbol(c.config.symbols, n[1].ident.s)
message(c.config, n.info, warnDeprecated, "undef is deprecated")
else:
invalidPragma(c, n)

Expand Down

3 comments on commit a890aa7

@timotheecour
Copy link
Member

Choose a reason for hiding this comment

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

it works inside {.push.} but {.pop.} won't pop it. Could symbols be attached to c.features instead of c.config.symbols instead (like {.experimental.} flags that can be localized)?

proc main()=
  echo defined(foo) # false
  {.push define:foo.}
  echo defined(foo) # true
  {.pop.}
  echo defined(foo) # true: not popped
main()

@Clyybber
Copy link
Contributor

@Clyybber Clyybber commented on a890aa7 Apr 5, 2020

Choose a reason for hiding this comment

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

It wouldn't make sense. Theres no need for it. Instead of this push, pop use define, undef.

@timotheecour
Copy link
Member

Choose a reason for hiding this comment

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

define is by itself kind of like a push pop. You define a symbol then you undefine it. No need for this.

it's not. push/pop doesn't affect outside scope. undef does:

when true:
  proc main()=
    echo defined(foo)
    {.define:foo.}
    echo defined(foo)
    {.undef:foo.}
    echo defined(foo)
  main()

nim c -r -d:foo main.nim

true
true
false

Please sign in to comment.