class Example(FooNode): name = Field(type=T.Id) dest_scope = Field(type=T.Id) content = Field(type=T.Id.list) @langkit_property() def has_kw(kw=T.Symbol): """ Return whether "content" contains the ``kw`` keyword. """ return Self.content.map(lambda c: c.symbol).contains(kw) env_spec = EnvSpec( add_env(names=[Self.name.symbol]), add_to_env_kv( key=Self.name.symbol, value=Self, # Check correct behavior when the env argument is null or not (when # it's not, add to the parents' env), and when or_current=True is # passed or not (current = Self's env). dest_env=Let(lambda name=If( Self.has_kw("null_name"), No(T.Symbol), Self.dest_scope.symbol, ): If( Self.has_kw("or_current"), named_env(name, or_current=True), named_env(name), ))), )
class Example(FooNode): token_node = True env_spec = EnvSpec( handle_children(), add_env(), )
class Scope(FooNode): name = Field(type=Name) content = Field() env_spec = EnvSpec(set_initial_env(Self.name.referenced_parent_scope), add_to_env_kv(key=Self.name.referenced_name, val=Self), add_env())
class Def(FooNode): name = Field(type=T.Name) cat1 = Field(type=T.Cat1) cat2 = Field(type=T.Cat2) example = Field(type=T.Example) env_spec = EnvSpec(add_env())
class Scope(FooNode): name = Field(type=T.SimpleId) content = Field() env_spec = EnvSpec( add_to_env(New(T.env_assoc, key=Self.name.symbol, val=Self)), add_env())
class Decl(FooNode): name = Field() refs = Field() env_spec = EnvSpec( add_to_env(New(T.env_assoc, key=Self.name.symbol, val=Self)), add_env())
class Def(Stmt): id = Field() body = Field() env_spec = EnvSpec(add_to_env(Self.id.symbol, Self), add_env()) faulty_prop = Property(Self._env_mappings_0)
class PrivatePart(DeclarativePart): env_spec = EnvSpec( add_env(names=[ Self.parent.suffixed_full_name(String('__privatepart')).to_symbol ], transitive_parent=True), )
class Decl(FooNode): names = Field() env_spec = EnvSpec(do(PropertyError(T.FooNode)), add_env()) @langkit_property(public=True) def lookup(n=T.Name.entity): return Entity.node_env.get_first(n.symbol)
class Block(DefNode): params = Field(type=T.Params) name_field = Field(type=T.Name) vars = Field(type=T.BlockVar.list) name = Property(Self.name_field.symbol) @langkit_property(public=True) def rebind(from_block=T.Block.entity, to_block=T.Block.entity): rbdng = Var(Entity.info.rebindings.append_rebinding( from_block.params.children_env, to_block.children_env )) e_info = Var(New(T.entity_info, md=Entity.info.md, rebindings=rbdng, from_rebound=False)) return New(Block.entity, node=Self, info=e_info) env_spec = EnvSpec( add_to_env_kv(key=Self.name, val=Self), add_env() )
class Block(FooNode): name = Field() decls = Field() usings = Field() refs = Field() env_spec = EnvSpec( add_to_env(New(T.env_assoc, key=Self.name.sym, val=Self)), add_env())
class Block(FooNode): name = Field(type=T.Identifier) items = Field(type=T.Item.list) env_spec = EnvSpec( add_to_env_kv(Self.name.symbol, Self), add_env(names=[Self.name.symbol]), )
class Block(FooNode): name = Field() decls = Field() usings = Field() refs = Field() env_spec = EnvSpec(add_to_env_kv(key=Self.name.symbol, val=Self), add_env())
class Block(FooNode): name = Field(type=Name) content = Field(type=Ref.list) env_spec = EnvSpec( add_env(), add_to_env_kv(key=Self.name.symbol, val=Self, dest_env=Self.node_env), )
class Scope(DefNode): name = Field() defs = Field() env_spec = EnvSpec( add_to_env(New(T.env_assoc, key=Self.name.symbol, val=Self)), add_env(), )
class Id(FooNode): token_node = True @langkit_property(return_type=T.FooNode.entity, public=True) def get_scope(): return Self.children_env.get_first("Scope", lookup=LookupKind.minimal) env_spec = EnvSpec(add_env())
class Scope(DefNode): name = Field() defs = Field() env_spec = EnvSpec( add_to_env_kv(key=Self.name.symbol, val=Self), add_env(), )
class Block(FooNode): name = Field(type=TokenType) content = Field(type=Ref.list) env_spec = EnvSpec( add_env(), add_to_env(T.env_assoc.new(key=Self.name.symbol, val=Self), dest_env=Self.node_env), )
class Scope(FooNode): name = Field(type=T.Id) content = Field() env_spec = EnvSpec( set_initial_env(Self.name.designated_scope(Self.parent.children_env)), add_to_env_kv(key=Self.name.designated_symbol, val=Self), add_env(), )
class Example(FooNode): token_node = True env_spec = EnvSpec( add_env(), add_to_env( new_env_assoc(key="foo", val=Self, dest_env=Self.children_env.env_orphan)))
class Decl(FooNode): name = Field() refs = Field() env_spec = EnvSpec( add_to_env_kv( key=Self.name.symbol, val=Self ), add_env() )
class Scope(Def): error = Field() name = Field() defs = Field() env_spec = EnvSpec( add_to_env(New(T.env_assoc, key=Self.name.symbol, val=Self)), add_env(), do(If(Self.error.as_bool, PropertyError(T.FooNode), No(T.FooNode))), )
class Scope(FooNode): name = Field(type=Name) content = Field() env_spec = EnvSpec( set_initial_env( Self.name.scope_fqn.then( lambda s: named_env(s.to_symbol), default_val=direct_env(Self.parent.children_env), ), ), add_to_env_kv(key=Self.name.referenced_name, value=Self), add_env(names=[Self.name.fqn.to_symbol]))
class Example(FooNode): token_node = True @langkit_property() def resolve(): return PropertyError(T.LexicalEnv) env_spec = EnvSpec( add_env(), reference([Self.cast(FooNode), Self.cast(FooNode)], T.Example.resolve), )
class PackageDecl(FooNode): name = Field(type=T.Name) public_part = Field(type=T.PublicPart) private_part = Field(type=T.PrivatePart) @langkit_property(return_type=T.Name) def self_name(): return Self.name @langkit_property(return_type=T.Symbol.array) def new_env_names(): """ Return the names for the environment that this package creates. """ # Always register the "regular" name for this package result = Self.full_name # If there is a private part, that's all we need. Otherwise, register # this environment with the name of the private part as well, so that # package bodies can assume there is always a private part. return If( result.length == 0, No(T.Symbol.array), If( Self.private_part.is_null, [result, result.concat(String('.__privatepart'))], [result], ).map(lambda s: s.to_symbol) ) env_spec = EnvSpec( set_initial_env_by_name( If( Self.is_toplevel, Self.decl_parent_scope_name, No(T.Symbol), ), Self.parent.children_env ), add_to_env_kv(Self.name.base_name.to_symbol, Self), add_env(names=Self.new_env_names) ) @langkit_property(return_type=T.PackageBody.entity, public=True) def body_part(): """ Return the PackageBody node corresponding to this PackageDecl. """ return Self.private_part.then( lambda pp: pp, default_val=Self, ).children_env.get_first('__nextpart').cast(T.PackageBody)
class SubpBodyDecls(DeclarativePart): """ Top-level list of declaration in a subprogam body. """ env_spec = EnvSpec( # The only case where we need a declarative part to have a name is when # it is top-level in subprogram body (A), so that separate subprogram # bodies (B) can use this environment as their initial env. Note that # this case is legal only when that (A) is the syntactic root. add_env(names=If( Self.parent.is_a(T.SubpBody) & Self.parent.parent.is_null, [Self.parent.cast(T.SubpBody).name.scope_name.to_symbol], No(T.Symbol.array), )))
class Scope(FooNode): name = Field() deps = Field() defs = Field() env_spec = EnvSpec( set_initial_env( Self.name.scope_fqn.then( lambda s: named_env(s.to_symbol), direct_env(Self.parent.children_env), ), ), add_to_env_kv(key=Self.name.suffix_symbol, value=Self), add_env(names=[Self.name.fqn.to_symbol]), )
class Scope(FooNode): name = Field(type=T.Id) content = Field(type=T.FooNode.list) env_spec = EnvSpec( add_env(), handle_children(), add_to_env( Self.content.children.map(lambda r: new_env_assoc( key="Scope", val=Self, dest_env=r.match(lambda s=T.Scope: s.name.children_env, lambda _: r.children_env)))), )
class Def(FooNode): name = Field() imports = Field() vars = Field() expr = Field() env_spec = EnvSpec( add_to_env(mappings=New(T.env_assoc, key=Self.name.symbol, val=Self)), add_env(), reference(Self.imports.map(lambda i: i.cast(T.FooNode)), # If PropertyDef rewriting omits the following references, # env lookup will never reach DerivedRef.referenced_env, so # resolution will sometimes fail to reach definition. T.MiddleRef.referenced_env) )
class Scope(FooNode): name = Field() deps = Field() defs = Field() @langkit_property() def initial_env(): return Self.name.match( lambda p=T.Prefix: p.prefix.referenced_unit.root.children_env, lambda _: Self.children_env, ) env_spec = EnvSpec( set_initial_env(Self.initial_env), add_to_env_kv(key=Self.name.suffix_symbol, val=Self), add_env(), )