pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:310:   %type <n> soft_cast   %type <n> real_string_constant   %type <n> real_string_or_identifier   %type <n> string_constant   %type <n> string_or_identifier   %type <n> string_segment   %type <n> string   %type <n> TOK_STRING   %type <n> TOK_NUMBER   %type <n> TOK_BITS + %type <n> optional_default_value   %type <n> optional_rename_inherit   %type <n> optional_identifier   %type <n> implicit_identifier   %type <n> TOK_IDENTIFIER   %type <n> TOK_RESERVED   %type <n> TOK_VERSION   %type <n> annotation   %type <n> annotation_list   %type <n> attribute   %type <n> assoc_pair
pike.git/src/language.yacc:817:    add_local_name(empty_pike_string, id->type, 0);    /* Note: add_local_name() above will return e. */    Pike_compiler->compiler_frame->variable[e].flags |=    LOCAL_VAR_IS_USED;    }    }    $<number>$ = e;    }    }    } -  arguments close_paren_or_missing +  arguments ')'    {    int e;       /* Adjust opt_flags in case we've got an optional_constant. */    Pike_compiler->compiler_frame->opt_flags = $4;       /* construct the function type */    push_finished_type(Pike_compiler->compiler_frame->current_return_type);       if ($1 & ID_GENERATOR) {
pike.git/src/language.yacc:892:    pop_type_stack(T_ARRAY);    compiler_discard_top_type();    }    }else{    push_type(T_VOID);    }    push_type(T_MANY);    for(; e>=0; e--)    {    push_finished_type(Pike_compiler->compiler_frame->variable[e].type); +  if (Pike_compiler->compiler_frame->variable[e].def) { +  push_type(T_VOID); +  push_type(T_OR); +  }    push_type(T_FUNCTION);    }       if (Pike_compiler->current_attributes) {    node *n = Pike_compiler->current_attributes;    while (n) {    push_type_attribute(CDR(n)->u.sval.u.string);    n = CAR(n);    }    }
pike.git/src/language.yacc:1015:    }       for(e=0; e<$<number>8+$9; e++)    {    if((e >= $<number>8) &&    (!Pike_compiler->compiler_frame->variable[e].name ||    !Pike_compiler->compiler_frame->variable[e].name->len))    {    my_yyerror("Missing name for argument %d.", e - $<number>8);    } else { +  node *def = Pike_compiler->compiler_frame->variable[e].def; +  if (def) { +  /* if (undefinedp($e)) { $e = def; } */ +  check_args = +  mknode(F_COMMA_EXPR, check_args, +  mknode(F_POP_VALUE, +  mknode(F_LAND, +  mkefuncallnode("undefinedp", +  mklocalnode(e, 0)), +  mknode(F_ASSIGN, +  mklocalnode(e, 0), +  def)), NULL)); +  add_ref(def); +  } +     if (Pike_compiler->compiler_pass == COMPILER_PASS_LAST) {    /* FIXME: Should probably use some other flag. */    if ((runtime_options & RUNTIME_CHECK_TYPES) &&    (Pike_compiler->compiler_frame->variable[e].type !=    mixed_type_string)) {    node *local_node;       /* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/       local_node = mkcastnode(mixed_type_string, mklocalnode(e, 0));
pike.git/src/language.yacc:1139:   #ifdef PIKE_DEBUG    if (Pike_compiler->compiler_frame != $6) {    Pike_fatal("Lost track of compiler_frame!\n"    " Got: %p (Expected: %p) Previous: %p\n",    Pike_compiler->compiler_frame, $6,    Pike_compiler->compiler_frame->previous);    }   #endif    pop_compiler_frame();    free_node($5); -  free_node($10); +     free_node($<n>11);    }    | modifiers optional_attributes simple_type    optional_constant TOK_IDENTIFIER start_function    error    {   #ifdef PIKE_DEBUG    if (Pike_compiler->compiler_frame != $6) {    Pike_fatal("Lost track of compiler_frame!\n"    " Got: %p (Expected: %p) Previous: %p\n",
pike.git/src/language.yacc:1242:    $$=1;    }    | /* empty */ { $$=0; }    ;      optional_identifier: TOK_IDENTIFIER    | bad_identifier { $$=0; }    | /* empty */ { $$=0; }    ;    + optional_default_value: '=' expr0 { $$ = $2; } +  | /* empty */ { $$ = NULL; } +  ; +    new_arg_name: full_type optional_dot_dot_dot optional_identifier -  +  optional_default_value    {    int i;    if(Pike_compiler->varargs) yyerror("Can't define more arguments after ...");       if (TEST_COMPAT(8, 0) &&    !pike_types_le(zero_type_string, peek_type_stack(), 0, 0)) {    push_type(PIKE_T_ZERO);    push_type(T_OR);    }       if($2)    {    push_unlimited_array_type(T_ARRAY); -  +     Pike_compiler->varargs=1;    }    -  +  if ($4) { +  if ($2) { +  yyerror("Varargs variable with default value."); +  free_node($4); +  $4 = NULL; +  } else if (!$3) { +  yywarning("Unnamed variable with default value."); +  } +  } +     if(!$3)    {    $3=mkstrnode(empty_pike_string);    }       if($3->u.sval.u.string->len &&    islocal($3->u.sval.u.string) >= 0)    my_yyerror("Variable %S appears twice in argument list.",    $3->u.sval.u.string);    -  i = add_local_name($3->u.sval.u.string, compiler_pop_type(),0); +  i = add_local_name($3->u.sval.u.string, compiler_pop_type(), $4);    if (i >= 0) {    /* Don't warn about unused arguments. */    Pike_compiler->compiler_frame->variable[i].flags |= LOCAL_VAR_IS_USED; -  +  if ($4) { +  Pike_compiler->compiler_frame->variable[i].flags |= +  LOCAL_VAR_IS_ARGUMENT;    } -  +  }    free_node($3);    }    ;    - func_args: '(' arguments close_paren_or_missing + func_args: '(' arguments ')'    { -  free_node($3); +     $$=$2;    }    ;      arguments: /* empty */ optional_comma { $$=0; }    | arguments2 optional_comma    ;      arguments2: new_arg_name { $$ = 1; }    | arguments2 ',' new_arg_name { $$ = $1 + 1; }
pike.git/src/language.yacc:2471:    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);    e--;    pop_type_stack(T_ARRAY);    compiler_discard_top_type();    }else{    push_type(T_VOID);    }    Pike_compiler->varargs=0;    push_type(T_MANY);    for(; e>=0; e--) { +  node *def = Pike_compiler->compiler_frame->variable[e].def;    push_finished_type(Pike_compiler->compiler_frame->variable[e].type); -  +  if (def) { +  push_type(T_VOID); +  push_type(T_OR); +  +  /* if (undefinedp($e)) { $e = def; } */ +  $7 = mknode(F_COMMA_EXPR, +  mknode(F_POP_VALUE, +  mknode(F_LAND, +  mkefuncallnode("undefinedp", +  mklocalnode(e, 0)), +  mknode(F_ASSIGN, +  mklocalnode(e, 0), +  def)), NULL), +  $7); +  add_ref(def); +  }    push_type(T_FUNCTION);    }       type=compiler_pop_type();       name = $3->u.sval.u.string;      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n%d: type: ",    Pike_compiler->compiler_pass, name->str,
pike.git/src/language.yacc:2568:    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);    e--;    pop_type_stack(T_ARRAY);    compiler_discard_top_type();    }else{    push_type(T_VOID);    }    push_type(T_MANY);    for(; e>=0; e--) {    push_finished_type(Pike_compiler->compiler_frame->variable[e].type); +  if (Pike_compiler->compiler_frame->variable[e].def) { +  push_type(T_VOID); +  push_type(T_OR); +  }    push_type(T_FUNCTION);    }       type=compiler_pop_type();    /***/       name = get_new_name($1->u.sval.u.string);      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
pike.git/src/language.yacc:2621:    $<number>$=id;    free_string(name);    }    failsafe_block    {    int localid;    struct identifier *i=ID_FROM_INT(Pike_compiler->new_program, $<number>4);    struct compilation *c = THIS_COMPILATION;    struct pike_string *save_file = c->lex.current_file;    int save_line = c->lex.current_line; +  int e = $3 - 1;    c->lex.current_file = $1->current_file;    c->lex.current_line = $1->line_number;    -  +  if (Pike_compiler->varargs) e--; +  for(; e>=0; e--) { +  node *def = Pike_compiler->compiler_frame->variable[e].def; +  if (def) { +  /* if (undefinedp($e)) { $e = def; } */ +  $5 = mknode(F_COMMA_EXPR, +  mknode(F_POP_VALUE, +  mknode(F_LAND, +  mkefuncallnode("undefinedp", +  mklocalnode(e, 0)), +  mknode(F_ASSIGN, +  mklocalnode(e, 0), +  def)), NULL), +  $5); +  add_ref(def); +  } +  } +     $5=mknode(F_COMMA_EXPR,$5,mknode(F_RETURN,mkintnode(0),0));       debug_malloc_touch($5);    dooptcode(i->name,    $5,    i->type,    ID_PROTECTED | ID_PRIVATE | ID_INLINE);       i->opt_flags = Pike_compiler->compiler_frame->opt_flags;   
pike.git/src/language.yacc:2749:    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);    e--;    pop_type_stack(T_ARRAY);    compiler_discard_top_type();    }else{    push_type(T_VOID);    }    push_type(T_MANY);    for(; e>=0; e--) {    push_finished_type(Pike_compiler->compiler_frame->variable[e].type); +  if (Pike_compiler->compiler_frame->variable[e].def) { +  push_type(T_VOID); +  push_type(T_OR); +  }    push_type(T_FUNCTION);    }       type=compiler_pop_type();    /***/       name = get_new_name($1->u.sval.u.string);      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
pike.git/src/language.yacc:2806:    {    int localid;    struct identifier *i=ID_FROM_INT(Pike_compiler->new_program, $<number>4);    struct compilation *c = THIS_COMPILATION;    struct pike_string *save_file = c->lex.current_file;    int save_line = c->lex.current_line;    struct pike_type *generator_type;    struct pike_string *name;    int generator_stack_local;    int f; +  int e = $3 - 1;       c->lex.current_file = $1->current_file;    c->lex.current_line = $1->line_number;       ref_push_string($1->u.sval.u.string);    push_constant_text("\0generator");    f_add(2);    name = get_new_name(Pike_sp[-1].u.string);    pop_stack();   
pike.git/src/language.yacc:2859:    generator_stack_local =    Pike_compiler->compiler_frame->generator_local + 1;    Pike_compiler->compiler_frame->generator_local = -1;    free_type(Pike_compiler->compiler_frame->current_return_type);    Pike_compiler->compiler_frame->current_return_type = generator_type;    $5 = mknode(F_COMMA_EXPR,    mknode(F_ASSIGN, mklocalnode(generator_stack_local, 0),    mkefuncallnode("aggregate", NULL)),    mknode(F_RETURN, mkgeneratornode(f), NULL));    +  if(Pike_compiler->varargs) e--; +  for(; e>=0; e--) { +  node *def = Pike_compiler->compiler_frame->variable[e].def; +  if (def) { +  /* if (undefinedp($e)) { $e = def; } */ +  $5 = mknode(F_COMMA_EXPR, +  mknode(F_POP_VALUE, +  mknode(F_LAND, +  mkefuncallnode("undefinedp", +  mklocalnode(e, 0)), +  mknode(F_ASSIGN, +  mklocalnode(e, 0), +  def)), NULL), +  $5); +  add_ref(def); +  } +  } +     debug_malloc_touch($5);    f = dooptcode(i->name,    $5,    i->type,    ID_PROTECTED | ID_PRIVATE | ID_INLINE | ID_USED);       i->opt_flags = Pike_compiler->compiler_frame->opt_flags;       c->lex.current_line = save_line;    c->lex.current_file = save_file;
pike.git/src/language.yacc:5459:    }       if(depth) {    q->lexical_scope|=SCOPE_SCOPE_USED;       if(q->min_number_of_locals < e+1)    q->min_number_of_locals = e+1;    q->variable[e].flags |= LOCAL_VAR_USED_IN_SCOPE;    }    -  if(f->variable[e].def) { +  if(f->variable[e].def && +  !(f->variable[e].flags & LOCAL_VAR_IS_ARGUMENT)) {    /*fprintf(stderr, "Found prior definition of \"%s\"\n", str->str); */    return copy_node(f->variable[e].def);    }       return mklocalnode(e,depth);    }    }    if(!(f->lexical_scope & SCOPE_LOCAL)) return 0;    depth++;    f=f->previous;