def find_atoms(): return Entity.match( # This should match Lit .. Ref lambda a=T.Atom: a.singleton, # This should match Def | Plus .. FooNode.list lambda _: No(T.Atom.entity.array), ).concat(Entity.children.mapcat(lambda c: c.find_atoms))
def find_atoms_or_exprs(): return Entity.match( # This should match Lit .. Ref lambda a=T.Atom: a.cast(T.Expr).singleton, # This should match the only remaining expression: Plus lambda e=T.Expr: e.singleton, # This should match Def | FooNode.list lambda _: No(T.Expr.entity.array), ).concat(Entity.children.mapcat(lambda c: c.find_atoms_or_exprs))
def find_exprs(): return Entity.match( # This should match Lit .. Plus lambda e=T.Expr: e.singleton, # This should match nothing (Atom is an Expr subclass), so emit a # warning. lambda a=T.Atom: a.cast(T.Expr).singleton, # This should match Def | FooNode.list lambda _: No(T.Expr.entity.array), ).concat(Entity.children.mapcat(lambda c: c.find_exprs))
def find_refs(): return Entity.match( # This should match Ref lambda r=T.Ref: r.singleton, # This should match Lit lambda _: No(T.Ref.entity.array), # ... and we should not get CASE coverage errors in generated code, # even though we did not cover all possible FooNode kinds. ).concat( Entity.children.mapcat( lambda c: c.cast_or_raise(T.Expr).find_refs))
def reset_langkit(): """ Reset global state in Langkit. TODO: this is a hack to workaround another hack. At some point in the future, we should get rid of this global state in Langkit. """ CompiledTypeMetaclass.root_grammar_class = None CompiledTypeMetaclass.astnode_types = [] CompiledTypeMetaclass.struct_types = [] CompiledTypeMetaclass.env_metadata = None CompiledTypeMetaclass.entity_info = None Self.unfreeze() Entity.unfreeze() CompiledTypeMetaclass.type_dict.clear() create_builtin_types() _StructMetaclass.reset() _ASTNodeMetaclass.reset() _EnumNodeMetaclass.reset() reset_memoized()
class Sequence(FooNode.list): all_items = Property(Entity.map(lambda i: i), public=True) example_items = Property(Entity.filtermap( lambda i: i.cast_or_raise(T.Example), lambda i: i.is_a(T.Example)), public=True)
def resolve(): return Entity.match( lambda l=T.Literal: l, lambda r=T.Ref: Entity.node_env.get_first(r.name.symbol).cast( T.ConsDecl).cons_expr.resolve, )
def root3(): return Entity.super()
def entity_parents_without_self(): return Entity.parents(with_self=False)