示例#1
0
struct watchman_expression *
watchman_not_expression(struct watchman_expression *expression)
{
    struct watchman_expression *not_expr = alloc_expr(WATCHMAN_EXPR_TY_NOT);
    not_expr->e.not_expr.clause = expression;
    return not_expr;
}
示例#2
0
struct watchman_expression *
watchman_type_expression(char c)
{
    struct watchman_expression *result = alloc_expr(WATCHMAN_EXPR_TY_TYPE);
    result->e.type_expr.type = c;
    return result;
}
示例#3
0
/* 関数呼び出し(f(式, 式, ...))の式ノードを作る 
   f : 関数名. args : 引数のリスト */
expr_t mk_expr_call(char * filename, int line, char * f, expr_list_t args)
{
  expr_t e = alloc_expr(filename, line, expr_kind_app);
  e->u.a.o = op_kind_fun;
  e->u.a.f = f;
  e->u.a.args = args;
  return e;
}
示例#4
0
struct watchman_expression *
watchman_suffix_expression(const char *suffix)
{
    assert(suffix);
    struct watchman_expression *expr = alloc_expr(WATCHMAN_EXPR_TY_SUFFIX);
    expr->e.suffix_expr.suffix = strdup(suffix);
    return expr;
}
示例#5
0
/* Construct a subscription expression for the given group entry */
static char *
alloc_sub(usenet_sub_t self,
          int has_not,
          const char *pattern,
          struct usenet_expr *expressions,
          size_t count)
{
    struct usenet_expr *pointer;
    const char *not_string = has_not ? "!" : "";
    char *result;
    size_t length;

    /* Shortcut -- if there are no expressions then we don't need parens */
    if (count == 0) {
        length = strlen(PATTERN_ONLY) + strlen(not_string) +
                 strlen(pattern) - 3;
        result = malloc(length);
        if (result == NULL) {
            return NULL;
        }

        snprintf(result, length, PATTERN_ONLY, not_string, pattern);
        return result;
    }

    /* Otherwise we have to do this the hard way.  Allocate space for
     * the initial pattern and then extend it for each of the expressions */
    length = strlen(PATTERN_PLUS) + strlen(not_string) + strlen(pattern) - 3;
    result = malloc(length);
    if (result == NULL) {
        return NULL;
    }

    snprintf(result, length, PATTERN_PLUS, not_string, pattern);

    /* Insert the expressions */
    for (pointer = expressions; pointer < expressions + count; pointer++) {
        /* Get the string for the expression */
        char *expr = alloc_expr(self, pointer);
        size_t new_length = length + strlen(expr) + 4;

        /* Expand the buffer */
        result = realloc(result, new_length);
        if (result == NULL) {
            free(expr);
            return NULL;
        }

        /* Overwrite the trailing right paren with the new stuff */
        snprintf(result + length - 2, new_length - length + 2,
                 " && %s)", expr);
        length = new_length;
        free(expr);
    }

    return result;
}
示例#6
0
/* 単項演算式の式ノードを作る  */
expr_t mk_expr_un_op(char * filename, int line, op_kind_t op, expr_t a)
{
  expr_t e = alloc_expr(filename, line, expr_kind_app);
  expr_list_t args = mk_expr_list();
  expr_list_add(args, a);
  e->u.a.o = op;
  e->u.a.f = NULL;
  e->u.a.args = args;
  return e;
}
示例#7
0
struct watchman_expression *
watchman_since_expression_time_t(time_t time, enum watchman_clockspec
                                 spec)
{
    struct watchman_expression *expr = alloc_expr(WATCHMAN_EXPR_TY_SINCE);
    expr->e.since_expr.is_str = 0;
    expr->e.since_expr.t.time = time;
    expr->e.since_expr.clockspec = spec;
    return expr;
}
示例#8
0
struct watchman_expression *
watchman_since_expression(const char *since, enum watchman_clockspec spec)
{
    assert(since);
    struct watchman_expression *expr = alloc_expr(WATCHMAN_EXPR_TY_SINCE);
    expr->e.since_expr.is_str = 1;
    expr->e.since_expr.t.since = strdup(since);
    expr->e.since_expr.clockspec = spec;
    return expr;
}
示例#9
0
/* 括弧 ( 式 ) の式ノードを作る */
expr_t mk_expr_paren(char * filename, int line, expr_t p)
{
  expr_t e = alloc_expr(filename, line, expr_kind_paren);
  e->u.p = p;
  return e;
}
示例#10
0
/* 変数 (x, y, foo, bar, ...) の式ノードを作る */
expr_t mk_expr_id(char * filename, int line, char * v)
{
  expr_t e = alloc_expr(filename, line, expr_kind_id);
  e->u.s = v;
  return e;
}
示例#11
0
/* 整数リテラル (0, 1, 2, ...) の式ノードを作る */
expr_t mk_expr_int_literal(char * filename, int line, char * i)
{
  expr_t e = alloc_expr(filename, line, expr_kind_int_literal);
  e->u.s = i;
  return e;
}