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.441 2008/06/29 12:50:04 nilsson Exp $ + || $Id: language.yacc,v 1.442 2008/07/08 19:19:33 grubba Exp $   */      %pure_parser      %token TOK_ARROW      /*    * Basic value pushing    */   %token TOK_CONSTANT TOK_FLOAT TOK_STRING
pike.git/src/language.yacc:150:   #define YYDEBUG 1   #endif /* YYDEBUG */   #endif      /* Get verbose parse error reporting. */   #define YYERROR_VERBOSE 1      /* #define LAMBDA_DEBUG 1 */      static void yyerror_reserved(const char *keyword); - static struct pike_string *get_new_name(); + static struct pike_string *get_new_name(struct pike_string *prefix);   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 void mark_lvalues_as_used(node *n);   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:1274:   magic_identifiers2:    TOK_VOID_ID { $$ = "void"; }    | TOK_MIXED_ID { $$ = "mixed"; }    | TOK_ARRAY_ID { $$ = "array"; }    | TOK_ATTRIBUTE_ID { $$ = "__attribute__"; }    | TOK_DEPRECATED_ID { $$ = "__deprecated__"; }    | TOK_MAPPING_ID { $$ = "mapping"; }    | TOK_MULTISET_ID { $$ = "multiset"; }    | TOK_OBJECT_ID { $$ = "object"; }    | TOK_FUNCTION_ID { $$ = "function"; } -  | TOK_FUNCTION_NAME { $$ = "__FUNCTION__"; } +  | TOK_FUNCTION_NAME { $$ = "__func__"; }    | TOK_PROGRAM_ID { $$ = "program"; }    | TOK_STRING_ID { $$ = "string"; }    | TOK_FLOAT_ID { $$ = "float"; }    | TOK_INT_ID { $$ = "int"; }    | TOK_ENUM { $$ = "enum"; }    | TOK_TYPEDEF { $$ = "typedef"; }    ;      magic_identifiers3:    TOK_IF { $$ = "if"; }
pike.git/src/language.yacc:2145:      push_compiler_frame1: /* empty */    {    push_compiler_frame(SCOPE_LOCAL);    }    ;      implicit_identifier: /* empty */    {    struct pike_string *name; -  $$=mkstrnode(name = get_new_name()); +  $$=mkstrnode(name = get_new_name(NULL));    free_string(name);    }    ;      lambda: TOK_LAMBDA line_number_info implicit_identifier push_compiler_frame1    {    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:2333:    }    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(); +  name = get_new_name($1->u.sval.u.string);      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",    Pike_compiler->compiler_pass, name->str,    (long)Pike_compiler->new_program->id,    Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */       if(Pike_compiler->compiler_pass > 1)    {
pike.git/src/language.yacc:2466:    }    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(); +  name = get_new_name($2->u.sval.u.string);      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",    Pike_compiler->compiler_pass, name->str,    (long)Pike_compiler->new_program->id,    Pike_compiler->local_class_counter-1);   #endif /* LAMBDA_DEBUG */       if(Pike_compiler->compiler_pass > 1)    {
pike.git/src/language.yacc:3500:    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();    -  name = get_new_name(); +  name = get_new_name(NULL);      #ifdef LAMBDA_DEBUG    fprintf(stderr, "%d: IMPLICIT LAMBDA: %s 0x%08lx 0x%08lx\n",    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,
pike.git/src/language.yacc:4298:      string_segment: TOK_STRING    | TOK_FUNCTION_NAME    {    struct compiler_frame *f = Pike_compiler->compiler_frame;    if (!f || (f->current_function_number < 0)) {    $$ = mkstrnode(lfun_strings[LFUN___INIT]);    } else {    struct identifier *id =    ID_FROM_INT(Pike_compiler->new_program, f->current_function_number); +  if (!id->name->size_shift) { +  int len; +  if ((len = strlen(id->name->str)) == id->name->len) { +  /* Most common case. */    $$ = mkstrnode(id->name); -  +  } else { +  struct pike_string *str = +  make_shared_binary_string(id->name->str, len); +  $$ = mkstrnode(str); +  free_string(str);    } -  +  } else { +  struct pike_string *str; +  struct array *split; +  MAKE_CONST_STRING(str, "\0"); +  split = explode(id->name, str); +  $$ = mkstrnode(split->item->u.string); +  free_array(split);    } -  +  } +  }    ;      string: string_segment    | string string_segment    {    struct pike_string *a,*b;    copy_shared_string(a,$1->u.sval.u.string);    copy_shared_string(b,$2->u.sval.u.string);    free_node($1);    free_node($2);
pike.git/src/language.yacc:4448:      /* empty: ; */ /* line_number_info is now used in these cases. */      %%      static void yyerror_reserved(const char *keyword)   {    my_yyerror("%s is a reserved word.", keyword);   }    - static struct pike_string *get_new_name() + static struct pike_string *get_new_name(struct pike_string *prefix)   {    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) THIS_COMPILATION->lex.current_line); -  +  if (prefix) { +  struct string_builder sb; +  init_string_builder_alloc(&sb, prefix->len + strlen(buf) + 1, +  prefix->size_shift); +  string_builder_shared_strcat(&sb, prefix); +  string_builder_putchar(&sb, 0); +  string_builder_strcat(&sb, buf); +  return finish_string_builder(&sb); +  }    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) {
pike.git/src/language.yacc:4619:    if (!p->previous) {    my_yyerror("Too many levels of protected (%d, max:%d).",    depth, depth - (i+1));    parent_depth -= i+1;    break;    }    p->new_program->flags |= PROGRAM_USES_PARENT;    p = p->previous;    }    -  tmp_name = get_new_name(); +  tmp_name = get_new_name(name);    id = define_parent_variable(p, tmp_name, type,    ID_PROTECTED|ID_PRIVATE|ID_INLINE);    free_string(tmp_name);    if (id >= 0) {    if (def) {    p->init_node =    mknode(F_COMMA_EXPR, Pike_compiler->init_node,    mkcastnode(void_type_string,    mknode(F_ASSIGN, initializer,    mkidentifiernode(id))));    initializer = NULL;    }    n = mkexternalnode(id, parent_depth);    }    } else if (depth) {    f->lexical_scope|=SCOPE_SCOPE_USED; -  tmp_name = get_new_name(); +  tmp_name = get_new_name(name);    id = low_add_local_name(f, tmp_name, type, NULL);    free_string(tmp_name);    if(f->min_number_of_locals < id+1)    f->min_number_of_locals = id+1;    if (initializer) {    /* FIXME! */    yyerror("Initializers not yet supported for protected variables with function scope.");    }    n = mklocalnode(id, depth);    }