pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:1:   /* -*- c -*-   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: language.yacc,v 1.376 2007/09/14 18:13:26 grubba Exp $ + || $Id: language.yacc,v 1.377 2007/09/15 13:03:42 grubba Exp $   */      %pure_parser      %token TOK_ARROW      /*    * Basic value pushing    */   %token TOK_CONSTANT TOK_FLOAT TOK_STRING
pike.git/src/language.yacc:145:   /* May also be defined by machine.h */   #define YYDEBUG 1   #endif /* YYDEBUG */   #endif      /* Get verbose parse error reporting. */   #define YYERROR_VERBOSE 1      /* #define LAMBDA_DEBUG 1 */    + static struct pike_string *get_new_name();   int add_local_name(struct pike_string *, struct pike_type *, node *);   int low_add_local_name(struct compiler_frame *,    struct pike_string *, struct pike_type *, node *);   static node *lexical_islocal(struct pike_string *);   static void safe_inc_enum(void);   static int call_handle_import(struct pike_string *s);      static int inherit_depth;   static struct program_state *inherit_state = NULL;   
pike.git/src/language.yacc:326:   %type <n> local_name_list2   %type <n> low_idents   %type <n> safe_lvalue   %type <n> lvalue   %type <n> lvalue_list   %type <n> low_lvalue_list   %type <n> m_expr_list   %type <n> m_expr_list2   %type <n> new_local_name   %type <n> new_local_name2 + %type <n> new_static_name + %type <n> new_static_name2   %type <n> normal_label_statement   %type <n> optional_else_part   %type <n> optional_label   %type <n> return   %type <n> sscanf   %type <n> statement   %type <n> statements   %type <n> statement_with_semicolon -  + %type <n> static_name_list + %type <n> static_name_list2   %type <n> switch   %type <n> typeof   %type <n> unused   %type <n> unused2   %type <n> while   %type <n> optional_comma_expr   %type <n> low_program_ref   %type <n> inherit_ref   %type <n> local_function   %type <n> local_function2
pike.git/src/language.yacc:1739:    id = add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.type, 0);    if (id >= 0)    $$=mknode(F_ASSIGN,$3, mklocalnode(id,0));    else    $$ = 0;    free_node($1);    }    | bad_identifier '=' safe_expr0 { $$=$3; }    ;    + new_static_name: optional_stars TOK_IDENTIFIER +  { +  int id; +  struct pike_type *type; +  struct pike_string *name; +  node *n = NULL; +  +  push_finished_type($<n>0->u.sval.u.type); +  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) { +  yywarning("The *-syntax in types is obsolete. Use array instead."); +  } +  while($1--) push_type(T_ARRAY); +  type = compiler_pop_type(); +  +  name = get_new_name(); +  +  add_ref(type); +  id = define_variable(name, type, ID_STATIC|ID_PRIVATE|ID_INLINE); +  free_string(name); +  if (id >= 0) { +  n = mkidentifiernode(id); +  } +  +  id = add_local_name($2->u.sval.u.string, type, n); +  if (id >= 0) { +  /* FIXME: Consider using mklocalnode(id, -1). */ +  $$ = mklocalnode(id, 0); +  } else +  $$ = 0; +  free_node($2); +  } +  | optional_stars bad_identifier { $$=0; } +  | optional_stars TOK_IDENTIFIER '=' expr0 +  { +  int id; +  struct pike_type *type; +  struct pike_string *name; +  node *n = NULL; +  +  push_finished_type($<n>0->u.sval.u.type); +  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) { +  yywarning("The *-syntax in types is obsolete. Use array instead."); +  } +  while($1--) push_type(T_ARRAY); +  type = compiler_pop_type(); +  +  name = get_new_name(); +  +  add_ref(type); +  id = define_variable(name, type, ID_STATIC|ID_PRIVATE|ID_INLINE); +  free_string(name); +  if (id >= 0) { +  n = mkidentifiernode(id); +  Pike_compiler->init_node = +  mknode(F_COMMA_EXPR, Pike_compiler->init_node, +  mkcastnode(void_type_string, +  mknode(F_ASSIGN, $4, mkidentifiernode(id)))); +  } +  id = add_local_name($2->u.sval.u.string, type, n); + #if 0 +  if (id >= 0) +  $$ = mklocalnode(id, 0); +  else + #endif +  $$ = 0; +  if (!n) free_node($4); +  free_node($2); +  } +  | optional_stars bad_identifier '=' expr0 +  { +  free_node($4); +  $$=0; +  } +  | optional_stars TOK_IDENTIFIER '=' error +  { +  free_node($2); +  /* No yyerok here since we aren't done yet. */ +  $$=0; +  } +  | optional_stars TOK_IDENTIFIER '=' TOK_LEX_EOF +  { +  yyerror("Unexpected end of file in local variable definition."); +  free_node($2); +  /* No yyerok here since we aren't done yet. */ +  $$=0; +  } +  ; +  + new_static_name2: TOK_IDENTIFIER +  { +  int id; +  struct pike_type *type = $<n>0->u.sval.u.type; +  struct pike_string *name; +  node *n = NULL; +  +  name = get_new_name(); +  +  add_ref(type); +  id = define_variable(name, type, ID_STATIC|ID_PRIVATE|ID_INLINE); +  if (id >= 0) { +  n = mkidentifiernode(id); +  } +  add_ref(type); +  id = add_local_name($1->u.sval.u.string, type, n); +  if (id >= 0) { +  $$ = mklocalnode(id, 0); +  } else +  $$ = 0; +  free_node($1); +  } +  | bad_identifier { $$=0; } +  | TOK_IDENTIFIER '=' safe_expr0 +  { +  int id; +  struct pike_type *type = $<n>0->u.sval.u.type; +  struct pike_string *name; +  node *n = NULL; +  +  name = get_new_name(); +  +  add_ref(type); +  id = define_variable(name, type, ID_STATIC|ID_PRIVATE|ID_INLINE); +  if (id >= 0) { +  n = mkidentifiernode(id); +  add_ref(n); +  Pike_compiler->init_node = +  mknode(F_COMMA_EXPR, Pike_compiler->init_node, +  mkcastnode(void_type_string, +  mknode(F_ASSIGN, $3, n))); +  } +  add_ref(type); +  id = add_local_name($1->u.sval.u.string, type, n); +  if (id >= 0) +  $$ = mklocalnode(id, 0); +  else +  $$ = 0; +  free_node($1); +  } +  | bad_identifier '=' safe_expr0 { $$=$3; } +  ; +    line_number_info: /* empty */    {    /* Used to hold line-number info */    $$ = mkintnode(0);    }    ;      block:'{'    {    $<number>1=Pike_compiler->num_used_modules;
pike.git/src/language.yacc:1796:   local_name_list: new_local_name    | local_name_list ',' { $<n>$=$<n>0; } new_local_name    { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); }    ;      local_name_list2: new_local_name2    | local_name_list2 ',' { $<n>$=$<n>0; } new_local_name    { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); }    ;    + static_name_list: new_static_name +  | static_name_list ',' { $<n>$=$<n>0; } new_static_name +  { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); } +  ;    -  + static_name_list2: new_static_name2 +  | static_name_list2 ',' { $<n>$=$<n>0; } new_static_name +  { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); } +  ; +  +    local_constant_name: TOK_IDENTIFIER '=' safe_expr0    {    struct pike_type *type;       /* Ugly hack to make sure that $3 is optimized */    {    int tmp=Pike_compiler->compiler_pass;    $3=mknode(F_COMMA_EXPR,$3,0);    optimize_node($3);    Pike_compiler->compiler_pass=tmp;
pike.git/src/language.yacc:1955:    any_type_string);    }    func_args    {    $<number>$ = Pike_compiler->varargs;    Pike_compiler->varargs = 0;    }    failsafe_block    {    struct pike_type *type; -  char buf[80]; +     int f,e;    struct pike_string *name;    struct pike_string *save_file = lex.current_file;    int save_line = lex.current_line;    lex.current_file = $2->current_file;    lex.current_line = $2->line_number;       debug_malloc_touch($7);    $7=mknode(F_COMMA_EXPR,$7,mknode(F_RETURN,mkintnode(0),0));    if (Pike_compiler->compiler_pass == 2) {
pike.git/src/language.yacc:1999:    }    Pike_compiler->varargs=0;    push_type(T_MANY);    for(; e>=0; e--) {    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);    push_type(T_FUNCTION);    }       type=compiler_pop_type();    -  sprintf(buf,"__lambda_%ld_%ld_line_%d", -  (long)Pike_compiler->new_program->id, -  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ -  (int) lex.current_line); -  name=make_shared_string(buf); +  name = get_new_name();      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n%d: type: ", -  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1, Pike_compiler->compiler_pass); +  Pike_compiler->compiler_pass, name->str, +  (long)Pike_compiler->new_program->id, +  Pike_compiler->local_class_counter-1, +  Pike_compiler->compiler_pass);    simple_describe_type(type);    fprintf(stderr, "\n");   #endif /* LAMBDA_DEBUG */    if(Pike_compiler->compiler_pass == 2)    Pike_compiler->compiler_frame->current_function_number=isidentifier(name);       f=dooptcode(name,    $7,    type,    ID_STATIC | ID_PRIVATE | ID_INLINE);
pike.git/src/language.yacc:2048:    {    pop_compiler_frame();    $$ = mkintnode(0);    COPY_LINE_NUMBER_INFO($$, $2);    free_node($2);    }    ;      local_function: TOK_IDENTIFIER push_compiler_frame1 func_args    { -  char buf[40]; +     struct pike_string *name;    struct pike_type *type;    int id,e;    node *n;    struct identifier *i=0;       debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type);    if(Pike_compiler->compiler_frame->current_return_type)    free_type(Pike_compiler->compiler_frame->current_return_type);    copy_pike_type(Pike_compiler->compiler_frame->current_return_type,
pike.git/src/language.yacc:2083:    }    push_type(T_MANY);    for(; e>=0; e--) {    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);    push_type(T_FUNCTION);    }       type=compiler_pop_type();    /***/    -  sprintf(buf,"__lambda_%ld_%ld_line_%d", -  (long)Pike_compiler->new_program->id, -  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ -  (int) $1->line_number); +  name = get_new_name();      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n", -  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1); +  Pike_compiler->compiler_pass, name->str, +  (long)Pike_compiler->new_program->id, +  Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */    -  name=make_shared_string(buf); -  +     if(Pike_compiler->compiler_pass > 1)    {    id=isidentifier(name);    }else{    id=define_function(name,    type,    ID_INLINE,    IDENTIFIER_PIKE_FUNCTION |    (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),    0,
pike.git/src/language.yacc:2178:    }    | TOK_IDENTIFIER push_compiler_frame1 error    {    pop_compiler_frame();    $$=mkintnode(0);    }    ;      local_function2: optional_stars TOK_IDENTIFIER push_compiler_frame1 func_args    { -  char buf[40]; +     struct pike_string *name;    struct pike_type *type;    int id,e;    node *n;    struct identifier *i=0;       /***/    debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type);       push_finished_type($<n>0->u.sval.u.type);
pike.git/src/language.yacc:2219:    }    push_type(T_MANY);    for(; e>=0; e--) {    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);    push_type(T_FUNCTION);    }       type=compiler_pop_type();    /***/    +  name = get_new_name();    -  sprintf(buf,"__lambda_%ld_%ld_line_%d", -  (long)Pike_compiler->new_program->id, -  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ -  (int) $2->line_number); -  +    #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n", -  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1); +  Pike_compiler->compiler_pass, name->str, +  (long)Pike_compiler->new_program->id, +  Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */    -  name=make_shared_string(buf); -  +     if(Pike_compiler->compiler_pass > 1)    {    id=isidentifier(name);    }else{    id=define_function(name,    type,    ID_INLINE,    IDENTIFIER_PIKE_FUNCTION|    (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),    0,
pike.git/src/language.yacc:2966:   optional_comma_expr: { $$=0; }    | safe_comma_expr    ;      safe_comma_expr: comma_expr    | error { $$=0; }    ;      comma_expr: comma_expr2    | simple_type2 local_name_list { $$=$2; free_node($1); } +  | TOK_STATIC simple_type2 static_name_list { $$=$3; free_node($2); }    | simple_identifier_type local_name_list2 { $$=$2; free_node($1); } -  +  | TOK_STATIC simple_identifier_type static_name_list2 { $$=$3; free_node($2); }    | simple_identifier_type local_function { $$=$2; free_node($1); }    | simple_type2 local_function2 { $$=$2; free_node($1); }    ;         comma_expr2: expr0    | comma_expr2 ',' expr0    {    $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $3);    }
pike.git/src/language.yacc:3154:    copy_pike_type(Pike_compiler->compiler_frame->current_return_type,    any_type_string);       /* block code */    $<number>1=Pike_compiler->num_used_modules;    $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;    }    statements end_block    {    struct pike_type *type; -  char buf[40]; +     int f/*, e */;    struct pike_string *name;    struct pike_string *save_file = lex.current_file;    int save_line = lex.current_line;    lex.current_file = $2->current_file;    lex.current_line = $2->line_number;       /* block code */    unuse_modules(Pike_compiler->num_used_modules - $<number>1);    pop_local_variables($<number>4);
pike.git/src/language.yacc:3194:    push_type(T_VOID);    push_type(T_MANY);   /*    e=$5-1;    for(; e>=0; e--)    push_finished_type(Pike_compiler->compiler_frame->variable[e].type);   */       type=compiler_pop_type();    -  sprintf(buf,"__lambda_%ld_%ld_line_%d", -  (long)Pike_compiler->new_program->id, -  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ -  (int) lex.current_line); -  name=make_shared_string(buf); +  name = get_new_name();      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: IMPLICIT LAMBDA: %s 0x%08lx 0x%08lx\n", -  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1); +  Pike_compiler->compiler_pass, name->str, +  (long)Pike_compiler->new_program->id, +  Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */       f=dooptcode(name,    $5,    type,    ID_STATIC | ID_PRIVATE | ID_INLINE);       if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED) {    $$ = mktrampolinenode(f,Pike_compiler->compiler_frame->previous);    } else {
pike.git/src/language.yacc:4115:    pop_stack();   }      static void yyerror_reserved(char *keyword)   {    char fmt[100];    SNPRINTF(fmt, sizeof(fmt), "%s is a reserved word.", keyword);    yyerror(fmt);   }    + static struct pike_string *get_new_name() + { +  char buf[40]; +  /* Generate a name for a global symbol... */ +  sprintf(buf,"__lambda_%ld_%ld_line_%d", +  (long)Pike_compiler->new_program->id, +  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ +  (int) lex.current_line); +  return make_shared_string(buf); + } +  +    static int low_islocal(struct compiler_frame *f,    struct pike_string *str)   {    int e;    for(e=f->current_number_of_locals-1;e>=0;e--)    if(f->variable[e].name==str)    return e;    return -1;   }