I noticed there were no way to inspect and navigate in lib-related nodes like lib, fun, and C-struct/union/enum. I think it is missing.
The macro methods I suggest would be:
LibNodenamestructs, unions, enums, aliases, typedefs (or simply types to access all these?), functions, constantsTypeNode: has_constant?, has_method?, etc..FunDef
real_name, varargs?name, args, return_type, bodyTypedef (not sure about this one)
name, typeStructDef & UnionDef (or simply on CStructOrUnionDef?)
namefieldsunion? (if on CStructOrUnionDef)EnumDef
namemembersbase_typeExternalVar (e.g: $errno : Int32)
namereal_nametypeI attempted to add them, first to LibDef but I realized that a lib node is currently recognized as a TypeNode in macros:
lib LibFoo
fun bar
end
macro describe_lib(lib_name)
{% l = lib_name.resolve %}
{% puts l.class_name %}
{% puts l.methods %}
end
describe_lib LibFoo
Gives (https://carc.in/#/r/3178):
"TypeNode"
[]
Which I think is wrong, a lib is more a namespace than a type, it cannot respond to a type-like node methods like methods, union?, ancestors, etc... It should be recognized as a LibDef, like its AST node.
Any use cases?
I don't think we need usecases, completeness of the language is enough of an argument. It is surprising that macros can't traverse or inspect lib AST nodes, we should remove that surprise.
I actually started to work on this some time ago, it works pretty well for accessing the lib functions and the types (struct/enum/union) nodes, but I'm not sure I did it the right way (still in the process of understanding how the macros actully works, how it get the types and stuff..), and I'm stuck on accessing the types fields..
I'll probably re-work on this in the next few days and try a pr to have some feedback on it.
Edit in 2019: well thoses days are long... :innocent:
Most helpful comment
I don't think we need usecases, completeness of the language is enough of an argument. It is surprising that macros can't traverse or inspect
libAST nodes, we should remove that surprise.