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 RegularBlock(FooNode): id = Field(type=T.Identifier) env_spec = EnvSpec(set_initial_env(named_env(Self.id.symbol))) @lazy_field(public=True) def synth(): return T.SynthNode.new(id=Self.id)
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 SubpDecl(FooNode): name = Field(type=T.Name) @langkit_property(return_type=T.Name) def self_name(): return Self.name env_spec = EnvSpec( set_initial_env(Self.initial_env), add_to_env_kv(Self.name.base_name.to_symbol, Self), )
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 SubpBody(FooNode): name = Field(type=T.Name) decls = Field(type=T.SubpBodyDecls) stmts = Field(type=T.FooNode.list) @langkit_property(return_type=T.Name) def self_name(): return Self.name env_spec = EnvSpec(set_initial_env(Self.initial_env), # TODO: add __nextpart to the spec )
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 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 == String(""), 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( If( Self.is_toplevel, Self.decl_parent_scope_name, No(T.Symbol), ).then( lambda name: named_env(name), default_val=direct_env(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 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(), )
class Scope(FooNode): name = Field() deps = Field() defs = Field() annotations = Annotations(ple_unit_root=True) @langkit_property() def initial_env(): return Self.name.match( lambda p=T.Prefix: p.prefix.referenced_unit.root.cast_or_raise( T.Scope.list).filter(lambda scope: scope.name.symbols == p. prefix.symbols).at_or_raise(0). children_env, lambda _: Self.children_env, ) env_spec = EnvSpec( set_initial_env(Self.initial_env, unsound=True), add_to_env_kv(key=Self.name.suffix_symbol, val=Self), add_env(), )
class Example(FooNode): env_spec = EnvSpec( set_initial_env(direct_env(Self.parent.parent.children_env)))
class Example(FooNode): token_node = True env_spec = EnvSpec( set_initial_env(direct_env(Self.parent.children_env.env_orphan)), )
class PackageBody(FooNode): name = Field(type=T.Name) decls = Field(type=T.DeclarativePart) @langkit_property(return_type=T.Name) def self_name(): return Self.name @langkit_property(return_type=T.LexicalEnv) def body_decl_scope(): """ Assuming this PackageBody is not in the top-level list, return the environment of its PackageDecl that it should reference. """ pkg_decl = Var(Self.lookup_decl_part) return If(pkg_decl.private_part.is_null, pkg_decl.children_env, pkg_decl.private_part.children_env) @langkit_property(return_type=T.PackageDecl) def lookup_decl_part(): """ Assuming this PackageBody is not in the top-level list, return the the corresponding package declaration. """ return (Self.parent.children_env.get_first( Self.name.base_name.to_symbol).cast(T.PackageDecl).node) env_spec = EnvSpec( # The initial environment for package bodies is the private part of the # corresponding package specs (or the public part if there is no # private part). set_initial_env( If( Self.is_toplevel, named_env( Self.suffixed_full_name( String('__privatepart')).to_symbol), direct_env(Self.parent.children_env), ), ), add_to_env_kv( '__nextpart', Self, If( Self.can_have_name, named_env( Self.suffixed_full_name( String('__privatepart')).to_symbol), direct_env(Self.body_decl_scope))), add_env(names=[Self.suffixed_full_name(String('__body')).to_symbol]), reference( Self.cast(FooNode).singleton, through=T.PackageBody.body_decl_scope, cond=Not(Self.is_toplevel), kind=RefKind.prioritary, ), ) @langkit_property(return_type=T.PackageDecl.entity, public=True) def decl_part(): """ Return the PackageDecl node corresponding to this PackageBody. """ env = Var(Self.parent.children_env) return Self.name.resolve(env).cast(T.PackageDecl)