Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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,
        ))
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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")
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
class Decl(FooNode):
    decl_kind = AbstractProperty(DeclKind, public=True)
    with_kind = Property(DeclAndKind.new(dcl=Self, knd=Self.decl_kind),
                         public=True)
Exemplo n.º 16
0
class FooNode(ASTNode):
    prop = AbstractProperty(runtime_check=True, type=Int, public=True)
Exemplo n.º 17
0
    class AbstractNode(RootNode):
        prop = AbstractProperty(Bool, dynamic_vars=abstract_dyn_vars)

        use_prop = Property(Env.bind(Self.node_env, Self.prop), public=True)
Exemplo n.º 18
0
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)))
Exemplo n.º 19
0
class FooNode(ASTNode):
    prop = AbstractProperty(runtime_check=True, type=LongType)
Exemplo n.º 20
0
class FooNode(ASTNode):
    get_num = AbstractProperty(T.LongType)
Exemplo n.º 21
0
 class MiddleNode(FooNode):
     get_random_node = AbstractProperty(type=T.MiddleNode)
     public_prop = Property(Self.get_random_node.as_bare_entity,
                            public=True)
Exemplo n.º 22
0
class Expression(FooNode):
    result = AbstractProperty(type=Int, public=True)
Exemplo n.º 23
0
 class MiddleNode(FooNode):
     get_random_node = AbstractProperty(type=T.MiddleNode)
Exemplo n.º 24
0
class Expression(FooNode):
    result = AbstractProperty(type=LongType)
Exemplo n.º 25
0
class Name(FooNode):
    resolve = AbstractProperty(T.FooNode.entity, public=True)
Exemplo n.º 26
0
 class BaseNode(FooNode):
     prop = AbstractProperty(T.Bool, public=True)
Exemplo n.º 27
0
class Decl(FooNode):
    decl_kind = AbstractProperty(DeclKind, public=True)
Exemplo n.º 28
0
 class Example(BaseNode):
     prop = AbstractProperty(T.Bool, runtime_check=runtime_check)
Exemplo n.º 29
0
class FooNode(ASTNode):
    get_num = AbstractProperty(T.Int)
Exemplo n.º 30
0
class Expr(FooNode):
    evaluate = AbstractProperty(type=BigInt, public=True)

    @langkit_property(public=True)
    def evaluate_as_int():
        return Self.evaluate.as_int