From 1d47617d1b72c642fac5543f38aa24330b0f9a19 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Wed, 13 May 2015 22:32:10 +0200 Subject: Macros: Introduce getType(t: typedesc): NimNode Since typedesc are exception in macros and they are not implicitly converted to NimNode on macro call, we need some means to perform such conversion on demand. Fortunately it is as simple as declaring new magic "NGetType" proc with typedesc parameter. NOTE: Keeping actual macro exceptional behavior for typedesc is important, since it allows passing typedesc macro parameter to other procs or macros expecting type parameter. If typedesc parameter was implicitly converted, then we would lost this ability. --- tests/macros/tgettype.nim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/macros/tgettype.nim (limited to 'tests') diff --git a/tests/macros/tgettype.nim b/tests/macros/tgettype.nim new file mode 100644 index 000000000..0eab6c0a0 --- /dev/null +++ b/tests/macros/tgettype.nim @@ -0,0 +1,20 @@ +discard """ +msg: '''ObjectTy(Sym(Model), RecList(Sym(name), Sym(password))) +BracketExpr(Sym(typeDesc), Sym(User))''' +""" +import strutils, macros + +type + Model = object of RootObj + User = object of Model + name : string + password : string + +macro testUser: expr = + return newLit(User.getType.lispRepr) + +macro testGeneric(T: typedesc[Model]): expr = + return newLit(T.getType.lispRepr) + +echo testUser +echo User.testGeneric -- cgit 1.4.1-2-gfad0