Fix exporting classes

This commit removes checking for missing base object in favour of being able to export a class.
This commit is contained in:
konqoro 2016-11-13 14:02:52 +02:00 • committed by Flaviu Tamas
commit 587098c158

View file

@ -49,15 +49,10 @@ macro class*(head, body: untyped): untyped =
var typeName, baseName: NimNode var typeName, baseName: NimNode
if head.kind == nnkIdent: # flag if object should be exported
# `head` is expression `typeName` var exported: bool
# echo head.treeRepr
# --------------------
# Ident !"Animal"
typeName = head
baseName = newIdentNode("RootObj")
elif head.kind == nnkInfix and $head[0] == "of": if head.kind == nnkInfix and head[0].ident == !"of":
# `head` is expression `typeName of baseClass` # `head` is expression `typeName of baseClass`
# echo head.treeRepr # echo head.treeRepr
# -------------------- # --------------------
@ -68,6 +63,21 @@ macro class*(head, body: untyped): untyped =
typeName = head[1] typeName = head[1]
baseName = head[2] baseName = head[2]
elif head.kind == nnkInfix and head[0].ident == !"*" and
head[2].kind == nnkPrefix and head[2][0].ident == !"of":
# `head` is expression `typeName* of baseClass`
# echo head.treeRepr
# --------------------
# Infix
# Ident !"*"
# Ident !"Animal"
# Prefix
# Ident !"of"
# Ident !"RootObj"
typeName = head[1]
baseName = head[2][1]
exported = true
else: else:
quit "Invalid node: " & head.lispRepr quit "Invalid node: " & head.lispRepr
@ -96,8 +106,13 @@ macro class*(head, body: untyped): untyped =
# create a type section in the result # create a type section in the result
result = result =
quote do: if exported:
type `typeName` = ref object of `baseName` # mark `typeName` with an asterisk
quote do:
type `typeName`* = ref object of `baseName`
else:
quote do:
type `typeName` = ref object of `baseName`
# echo treeRepr(body) # echo treeRepr(body)
# -------------------- # --------------------