Example #1
0
def serialize_project(node, context):
    return IR.select(
        node.kind_name,
        filters=IR.filter(
            IR.attribute(None, "name"), IR.literal(node.name), "="
        ),
        limit=1,
    )
Example #2
0
def compile_constant(node, state):
    expr = IR.literal(node.value)

    # Constants are represented as repr(obj) in the
    # serialization part, so we have to re-cast it.
    if state.match == "Constant":
        expr.value = repr(expr.value)

    return IR.filter(state.compute_path(), expr, "=")
Example #3
0
 def compile_query(self):
     query = compile_query(self.reiz_ql, limit=None, offset=0)
     query.filters = IR.combine_filters(
         query.filters,
         IR.filter(
             IR.attribute(IR.attribute(None, "_module"), "filename"),
             IR.literal(self.expected_filename),
             "=",
         ),
     )
     return IR.construct(query)
Example #4
0
def metadata_parent(parent_node, state):
    state.ensure(parent_node, len(parent_node.filters) == 1)

    parent_field, filter_value = parent_node.filters.popitem()
    state.ensure(parent_node, filter_value is grammar.Ignore)

    with state.temp_pointer("_parent_types"):
        return IR.filter(
            IR.tuple(
                [parent_node.bound_node.type_id,
                 IR.literal(parent_field)]),
            state.compute_path(),
            "IN",
        )
Example #5
0
def convert_length(node, state, arguments):
    state.ensure(node, any((arguments.min, arguments.max)))

    count = IR.call("count", [state.compute_path()])
    filters = None
    for value, operator in [
        (arguments.min, IR.as_operator(">=")),
        (arguments.max, IR.as_operator("<=")),
    ]:
        if value is None:
            continue

        state.ensure(value, isinstance(value, grammar.Constant))
        state.ensure(value, isinstance(value.value, int))
        filters = IR.combine_filters(
            filters, IR.filter(count, IR.literal(value.value), operator))

    assert filters is not None
    return filters
Example #6
0
def serialize_string(value, context):
    return IR.literal(value)
Example #7
0
def compile_match_string(node, state):
    expr = IR.literal(node.value)
    return IR.filter(state.compute_path(), expr, "LIKE")
Example #8
0
def convert_intensive(node, state, arguments):
    match_str = arguments.match_str
    state.ensure(node, isinstance(match_str, grammar.MatchString))
    return IR.filter(state.compute_path(), IR.literal(match_str.value),
                     "ILIKE")