You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the part of #3274 that deals with type definitions, i.e. AnnotationDef, ClassDef, CStructOrUnionDef, EnumDef, LibDef, and ModuleDef.
I am proposing a unified API across those nodes:
#kind : MacroId
The keyword used in the definition. For example, ClassDef returns either class or struct, CStructOrUnionDef returns either struct or union, and the other node kinds always return the same value.
#name(*, generic_args : BoolLiteral = true) : Path | Generic
Returns the type name, which will be a Generic for a generic type, or a Path otherwise. Passing generic_args: false strips the generic type parameters and always returns a Path. This parameter is supported but ignored on nodes that cannot be generic.
#body : ASTNode
The body, except this will always be a Nop for AnnotationDef because currently nothing is supported inside. Nodes that internally store their bodies as Array(ASTNode) will run them through Crystal::Expressions.from.
All these nodes therefore have (mostly) the same identity interpolation:
Below are the extra methods for specific node kinds:
ModuleDef#type_vars : ArrayLiteral, ModuleDef#splat_index : NumberLiteral | NilLiteral
Since internally they are stored separately, these methods allow direct access without going through #name. The same goes for ClassDef.
ClassDef#abstract? : BoolLiteral
True if the class or struct is abstract.
ClassDef#struct? : BoolLiteral
True if a struct is defined, false if it is a class.
ClassDef#superclass : Path | Generic | Self | Nop
Superclass of the class or struct, or Nop if there is none. (Yes, you can inherit from self if your class is nested inside another one)
EnumDef#base_type : ASTNode
The base type of an enum, or Nop if there is none. Note that syntactically the base type can be things like {x: Int32} or ->, even though in practice only Path nodes are semantically valid as the other node kinds cannot represent primitive integer types.
CStructOrUnionDef#union? : BoolLiteral
True if this node defines an extern union, false if it is an extern struct.
The text was updated successfully, but these errors were encountered:
macrom(x)
{%p@type%}
endclassFoo
m classBar<selfendend
then @type == Foo, and that self will also resolve to Foo if m isn't there. But clearly this doesn't define Foo::Bar at all, or m could define something else entirely:
macrom(x)
classBaz
{{ x }}
endendclassFoo
m classBar<selfendend
{{ Foo::Baz::Bar.superclass }} # => Foo::Baz
So I don't think ClassDef#superclass should touch that, especially since it is required for the identity interpolation...?
This is the part of #3274 that deals with type definitions, i.e.
AnnotationDef
,ClassDef
,CStructOrUnionDef
,EnumDef
,LibDef
, andModuleDef
.I am proposing a unified API across those nodes:
#kind : MacroId
The keyword used in the definition. For example,
ClassDef
returns eitherclass
orstruct
,CStructOrUnionDef
returns eitherstruct
orunion
, and the other node kinds always return the same value.#name(*, generic_args : BoolLiteral = true) : Path | Generic
Returns the type name, which will be a
Generic
for a generic type, or aPath
otherwise. Passinggeneric_args: false
strips the generic type parameters and always returns aPath
. This parameter is supported but ignored on nodes that cannot be generic.#body : ASTNode
The body, except this will always be a
Nop
forAnnotationDef
because currently nothing is supported inside. Nodes that internally store their bodies asArray(ASTNode)
will run them throughCrystal::Expressions.from
.All these nodes therefore have (mostly) the same identity interpolation:
Below are the extra methods for specific node kinds:
ModuleDef#type_vars : ArrayLiteral
,ModuleDef#splat_index : NumberLiteral | NilLiteral
Since internally they are stored separately, these methods allow direct access without going through
#name
. The same goes forClassDef
.ClassDef#abstract? : BoolLiteral
True if the class or struct is abstract.
ClassDef#struct? : BoolLiteral
True if a struct is defined, false if it is a class.
ClassDef#superclass : Path | Generic | Self | Nop
Superclass of the class or struct, or
Nop
if there is none. (Yes, you can inherit fromself
if your class is nested inside another one)EnumDef#base_type : ASTNode
The base type of an enum, or
Nop
if there is none. Note that syntactically the base type can be things like{x: Int32}
or->
, even though in practice onlyPath
nodes are semantically valid as the other node kinds cannot represent primitive integer types.CStructOrUnionDef#union? : BoolLiteral
True if this node defines an extern union, false if it is an extern struct.
The text was updated successfully, but these errors were encountered: