class Name(FooNode): resolve = AbstractProperty(T.FooNode.entity, public=True) suffix_symbol = AbstractProperty(T.Symbol, public=True) @langkit_property(return_type=T.AnalysisUnit, external=True, uses_entity_info=False, uses_envs=False) def referenced_unit_or_error(or_error=T.Bool): pass @langkit_property(public=True, return_type=T.AnalysisUnit) def referenced_unit(): return Self.referenced_unit_or_error(False) @langkit_property(return_type=T.String) def scope_fqn(): return Self.match( lambda p=T.Prefix: p.prefix.fqn, lambda _=T.Id: No(T.String), ) @langkit_property(return_type=T.String) def fqn(): return Self.match(lambda p=T.Prefix: p.prefix.fqn.concat( String(".").concat(p.suffix.fqn)), lambda i=T.Id: i.text)
class Expr(FooNode): prop1 = AbstractProperty(T.LongType, public=True) # Warning: all concrete subclasses override this (concrete root property) prop2 = Property(0, public=True) # Warning: all concrete subclasses override this (runtime check) prop3 = AbstractProperty(T.LongType, public=True, runtime_check=True)
class Expr(FooNode): evaluate_abstract = AbstractProperty(T.Int, public=True) evaluate_rtcheck = AbstractProperty(T.Int, public=True, runtime_check=True) @langkit_property(public=True) def evaluate_concrete(): return 1 evaluate_entity = AbstractProperty(T.Int, public=True)
class Expression(FooNode): # This property and all its children are private. Only Literal.result is # called by a public property, so all others are unused. result = AbstractProperty(type=Int) # This property is private, but is called from "referenced_units", so # "names" and all its overriding properties are used. names = AbstractProperty(type=T.Name.array) referenced_units = Property(Self.names.map(lambda n: n.designated_unit), public=True)
class Name(FooNode): resolve = AbstractProperty(T.FooNode.entity, public=True) suffix_symbol = AbstractProperty(T.Symbol, public=True) @langkit_property(return_type=T.AnalysisUnit, external=True, uses_entity_info=False, uses_envs=False) def referenced_unit_or_error(or_error=T.Bool): pass @langkit_property(public=True, return_type=T.AnalysisUnit) def referenced_unit(): return Self.referenced_unit_or_error(False)
class Literal(FooNode): tok = Field() a = AbstractProperty(runtime_check=True, type=FooNode.env_el()) var = UserField(LogicVarType, is_private=True) b = Property(Bind(Self.var, Self.a), private=True)
def import_enum_node_attributes(mcs, dct, qualifier, alts, fields): from langkit.expressions import AbstractProperty from langkit.parsers import Opt, _Row, _Transform def create_parser_bool_node(cls, *args): # If the node is a boolean node, then we want to parse the # sub-parsers as an optional parser that will be booleanized. return Opt(*args).as_bool(cls) def create_parser_enum_node(cls, alt_typeref, *args): # Otherwise, we want to parse the sub-parsers as a row + transform return _Transform(_Row(*args), alt_typeref) def constructor(cls, *args): """ This constructor can be used in the grammar to create a parser for this enum node. This is valid only when qualifier is set to True. """ assert qualifier return create_parser_bool_node(cls, *args) dct['__new__'] = constructor dct['_create_parser'] = classmethod( create_parser_bool_node if qualifier else create_parser_enum_node ) dct['_alternatives'] = alts dct['_qualifier'] = qualifier # Make _EnumNodeAlternative instances available as attributes of the # enum node class for a convenient way to create parsers for them. for alt in alts: attr_name = (names.Name('Alt') + alt.name).lower dct[attr_name] = alt if qualifier: # Add the synthetic "as_bool" abstract property present_alt = alts[0] prop = AbstractProperty( type=T.Bool, public=True, doc='Return whether this is an instance of {}'.format( (dct['_name'] + present_alt.name).camel ) ) prop.location = dct['_location'] fields.append(('as_bool', prop))
class Literal(FooNode): token_node = True a = AbstractProperty(runtime_check=True, type=FooNode.entity) var = UserField(LogicVar, public=False) b = Property(Bind(Self.var, Self.a)) public_prop = Property(Let(lambda _=Self.b: Self.as_bare_entity), public=True)
class Literal(FooNode): tok = Field() a = AbstractProperty(runtime_check=True, type=FooNode.env_el()) b = Property( Self.a.match( lambda b=BarNode.env_el(): b.prop, lambda c=FooNode.env_el(): c.prop, ))
class Literal(FooNode): token_node = True a = AbstractProperty(runtime_check=True, type=FooNode.entity) b = Property(Self.a.cast(BarNode.entity)) c = Property(Self.b, public=True) d = Property(Self.a.cast(BarNode), type=BarNode.entity, public=True)
class Declaration(LkqlNode): """ Root node class for LKQL declarations. """ annotation = Field(type=DeclAnnotation) doc = AbstractProperty(type=T.BaseStringLiteral, public=True, doc="Return the documentation for this declaration")
class Literal(FooNode): tok = Field() a = AbstractProperty(runtime_check=True, type=FooNode.entity) var = UserField(LogicVarType, public=False) @langkit_property(return_type=BoolType) def is_eq(other=T.Literal.entity): return (Self.as_entity == other) b = Property(Bind(Self.var, Self.a, eq_prop=Self.is_eq)) @langkit_property(public=True) def public_prop(): return Let(lambda _=Self.b: Self.as_bare_entity)
class Literal(FooNode): token_node = True a = AbstractProperty(runtime_check=True, type=FooNode.entity) var = UserField(LogicVar, public=False) @langkit_property(return_type=T.Literal.entity) def node(): return Self.as_entity b = Property(Bind(Self.var, Self.a, Self.node)) @langkit_property(public=True) def public_pro(): return Let(lambda _=Self.b: Self.as_bare_entity)
class Literal(FooNode): tok = Field() get_num = Property(3) a = AbstractProperty(runtime_check=True, type=FooNode.entity) b = Property(Self.a.match( lambda e=Example.entity: e.get_num, lambda c=FooNode.entity: c.get_num, ), public=True) c = Property(Self.a.match( lambda e=Example: e.get_num, lambda c=FooNode: c.get_num, ), public=True)
class Decl(FooNode): decl_kind = AbstractProperty(DeclKind, public=True) with_kind = Property(DeclAndKind.new(dcl=Self, knd=Self.decl_kind), public=True)
class FooNode(ASTNode): prop = AbstractProperty(runtime_check=True, type=Int, public=True)
class AbstractNode(RootNode): prop = AbstractProperty(Bool, dynamic_vars=abstract_dyn_vars) use_prop = Property(Env.bind(Self.node_env, Self.prop), public=True)
class Def(FooNode): name = AbstractProperty(T.SymbolType, public=True) env_spec = EnvSpec( add_to_env(mappings=New(T.env_assoc, key=Self.name, val=Self)))
class FooNode(ASTNode): prop = AbstractProperty(runtime_check=True, type=LongType)
class FooNode(ASTNode): get_num = AbstractProperty(T.LongType)
class MiddleNode(FooNode): get_random_node = AbstractProperty(type=T.MiddleNode) public_prop = Property(Self.get_random_node.as_bare_entity, public=True)
class Expression(FooNode): result = AbstractProperty(type=Int, public=True)
class MiddleNode(FooNode): get_random_node = AbstractProperty(type=T.MiddleNode)
class Expression(FooNode): result = AbstractProperty(type=LongType)
class Name(FooNode): resolve = AbstractProperty(T.FooNode.entity, public=True)
class BaseNode(FooNode): prop = AbstractProperty(T.Bool, public=True)
class Decl(FooNode): decl_kind = AbstractProperty(DeclKind, public=True)
class Example(BaseNode): prop = AbstractProperty(T.Bool, runtime_check=runtime_check)
class FooNode(ASTNode): get_num = AbstractProperty(T.Int)
class Expr(FooNode): evaluate = AbstractProperty(type=BigInt, public=True) @langkit_property(public=True) def evaluate_as_int(): return Self.evaluate.as_int