mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
RA22-015: Emit correct names for user defined list types
This commit is contained in:
@@ -502,8 +502,16 @@ def type_name(type):
|
||||
from langkit.compiled_types import ASTNodeType, resolve_type
|
||||
|
||||
type = resolve_type(type)
|
||||
|
||||
def bases(typ):
|
||||
t = typ.base
|
||||
while t is not None:
|
||||
yield t
|
||||
t = t.base
|
||||
|
||||
if isinstance(type, ASTNodeType):
|
||||
if type.is_list_type:
|
||||
if (type.is_list_type
|
||||
and not any(t.is_generic_list_type for t in bases(type.base))):
|
||||
return "ASTList[{}]".format(type_name(type.element_type))
|
||||
else:
|
||||
return type.raw_name.camel
|
||||
|
||||
@@ -32,7 +32,7 @@ tests = sorted(((P.join(root, f), P.basename(root))
|
||||
# parse them all.
|
||||
test_whitelist = [
|
||||
'dflt_arg_val', 'rewriting', 'ghost_nodes', 'import_argcount',
|
||||
'symbol_type', 'unicode_buffer',
|
||||
'symbol_type', 'unicode_buffer',
|
||||
]
|
||||
whitelisted_tests = [t for t in tests if t[1] in test_whitelist]
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class FooNode {
|
||||
fun unique_id (s : SymbolType): FooNode = self.unit.root.make_id(s)
|
||||
}
|
||||
|
||||
class ASTList[Insert] : ASTList[Insert] {
|
||||
class Program : ASTList[Insert] {
|
||||
}
|
||||
|
||||
class Id : FooNode {
|
||||
|
||||
@@ -44,7 +44,7 @@ class Example : FooNode {
|
||||
## * ${node_name(T.Null)}
|
||||
## * ${node_name(T.StringLiteral)}
|
||||
## * ${node_name(T.Var)}
|
||||
class ASTList[FooNode] : ASTList[FooNode] {
|
||||
class Sequence : ASTList[FooNode] {
|
||||
|
||||
@export fun all_items (): Array[Entity[FooNode]] = entity.map((i) => i)
|
||||
|
||||
@@ -65,5 +65,5 @@ class StringLiteral : FooNode {
|
||||
}
|
||||
|
||||
class Var : FooNode {
|
||||
@parse_field arg : ASTList[FooNode]
|
||||
@parse_field arg : Sequence
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class FooNode {
|
||||
}
|
||||
}
|
||||
|
||||
class ASTList[Name] : ASTList[Name] {
|
||||
class Scope : ASTList[Name] {
|
||||
}
|
||||
|
||||
class Name : FooNode {
|
||||
|
||||
@@ -18,7 +18,7 @@ class DefNode : FooNode {
|
||||
}
|
||||
|
||||
class Block : DefNode {
|
||||
@parse_field params : ASTList[Param]
|
||||
@parse_field params : Params
|
||||
@parse_field name_field : Name
|
||||
@parse_field vars : ASTList[BlockVar]
|
||||
|
||||
@@ -63,7 +63,7 @@ class Param : DefNode {
|
||||
fun name (): SymbolType = self.name_field.symbol
|
||||
}
|
||||
|
||||
class ASTList[Param] : ASTList[Param] {
|
||||
class Params : ASTList[Param] {
|
||||
}
|
||||
|
||||
class Name : FooNode {
|
||||
|
||||
@@ -9,7 +9,7 @@ class FooNode {
|
||||
@export fun node_unit (): InternalUnit = (self.to[Name]) then (n => n.unit)
|
||||
}
|
||||
|
||||
class ASTList[Name] : ASTList[Name] {
|
||||
class Scope : ASTList[Name] {
|
||||
}
|
||||
|
||||
class Name : FooNode {
|
||||
|
||||
@@ -18,7 +18,7 @@ class Example : FooNode {
|
||||
##
|
||||
## * ${node_name(T.Example)}
|
||||
## * ${node_name(T.NullNode)}
|
||||
class ASTList[FooNode] : ASTList[FooNode] {
|
||||
class Sequence : ASTList[FooNode] {
|
||||
|
||||
@export fun all_items (): Array[Entity[FooNode]] = entity.map((i) => i)
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class DefNode : FooNode {
|
||||
}
|
||||
|
||||
class Block : DefNode {
|
||||
@parse_field params : ASTList[Param]
|
||||
@parse_field params : Params
|
||||
@parse_field name_field : Name
|
||||
@parse_field vars : ASTList[BlockVar]
|
||||
|
||||
@@ -49,7 +49,7 @@ class Param : DefNode {
|
||||
fun name (): SymbolType = self.name_field.symbol
|
||||
}
|
||||
|
||||
class ASTList[Param] : ASTList[Param] {
|
||||
class Params : ASTList[Param] {
|
||||
}
|
||||
|
||||
class Name : FooNode {
|
||||
|
||||
@@ -12,5 +12,5 @@ class FooNode {
|
||||
class Atom : FooNode {
|
||||
}
|
||||
|
||||
class ASTList[FooNode] : ASTList[FooNode] {
|
||||
class Sequence : ASTList[FooNode] {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user