pike.git / src / language.yacc

version» Context lines:

pike.git/src/language.yacc:105:   %left TOK_LSH TOK_RSH   %left '+' '-'   %left '*' '%' '/'   %right TOK_NOT '~'   %nonassoc TOK_INC TOK_DEC      %{   /* This is the grammar definition of Pike. */      #include "global.h" - RCSID("$Id: language.yacc,v 1.259 2001/08/16 00:36:47 mast Exp $"); + RCSID("$Id: language.yacc,v 1.260 2001/08/16 04:38:51 mast Exp $");   #ifdef HAVE_MEMORY_H   #include <memory.h>   #endif      #include "interpret.h"   #include "array.h"   #include "object.h"   #include "stralloc.h"   #include "las.h"   #include "interpret.h"
pike.git/src/language.yacc:143:   #endif /* YYDEBUG */   #endif      /* #define LAMBDA_DEBUG 1 */      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;      /*    * Kludge for Bison not using prototypes.    */   #ifndef __GNUC__   #ifndef __cplusplus   static void __yy_memcpy(char *to, char *from, YY_COUNT_TYPE count);
pike.git/src/language.yacc:367:    | ':' error { $$=0; }    | { $$=0; }    ;      /* NOTE: This rule pushes a string "name" on the stack in addition    * to resolving the program reference.    */   low_program_ref: string_constant    {    ref_push_string($1->u.sval.u.string); -  ref_push_string($1->u.sval.u.string); -  ref_push_string(lex.current_file); -  -  if (error_handler && error_handler->prog) { -  ref_push_object(error_handler); -  SAFE_APPLY_MASTER("handle_inherit", 3); -  } else { -  SAFE_APPLY_MASTER("handle_inherit", 2); -  } -  -  if(Pike_sp[-1].type != T_PROGRAM) -  my_yyerror("Couldn't cast string \"%s\" to program", -  $1->u.sval.u.string->str); -  free_node($1); +  if (call_handle_inherit($1->u.sval.u.string)) {    $$=mksvaluenode(Pike_sp-1); -  if($$->name) free_string($$->name); -  add_ref( $$->name=Pike_sp[-2].u.string ); +     pop_stack();    } -  +  else +  $$=mknewintnode(0); +  if($$->name) free_string($$->name); +  add_ref( $$->name=Pike_sp[-1].u.string ); +  free_node($1); +  }    | idents    {    if(Pike_compiler->last_identifier)    {    ref_push_string(Pike_compiler->last_identifier);    }else{    push_constant_text("");    }    $$=$1;    }
pike.git/src/language.yacc:453:      import: TOK_IMPORT idents ';'    {    resolv_constant($2);    free_node($2);    use_module(Pike_sp-1);    pop_stack();    }    | TOK_IMPORT string ';'    { -  ref_push_string($2->u.sval.u.string); -  free_node($2); -  ref_push_string(lex.current_file); -  if (error_handler && error_handler->prog) { -  ref_push_object(error_handler); -  SAFE_APPLY_MASTER("handle_import", 3); -  } else { -  SAFE_APPLY_MASTER("handle_import", 2); -  } +  if (call_handle_import($2->u.sval.u.string)) {    use_module(Pike_sp-1);    pop_stack();    } -  +  free_node($2); +  }    | TOK_IMPORT error ';' { yyerrok; }    | TOK_IMPORT error TOK_LEX_EOF    {    yyerror("Missing ';'.");    yyerror("Unexpected end of file.");    }    | TOK_IMPORT error '}' { yyerror("Missing ';'."); }    ;      constant_name: TOK_IDENTIFIER '=' safe_expr0
pike.git/src/language.yacc:3178:    {    $$=index_node($1, Pike_compiler->last_identifier?Pike_compiler->last_identifier->str:NULL,    $3->u.sval.u.string);    free_node($1);    if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier);    copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);    free_node($3);    }    | '.' TOK_IDENTIFIER    { -  node *tmp; -  push_text("."); -  ref_push_string(lex.current_file); -  if (error_handler && error_handler->prog) { -  ref_push_object(error_handler); -  SAFE_APPLY_MASTER("handle_import", 3); -  } else { -  SAFE_APPLY_MASTER("handle_import", 2); -  } -  tmp=mkconstantsvaluenode(Pike_sp-1); +  struct pike_string *dot; +  MAKE_CONSTANT_SHARED_STRING(dot, "."); +  if (call_handle_import(dot)) { +  node *tmp=mkconstantsvaluenode(Pike_sp-1);    pop_stack();    $$=index_node(tmp, ".", $2->u.sval.u.string);    free_node(tmp); -  +  } +  else +  $$=mknewintnode(0); +  free_string(dot);    if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier);    copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);    free_node($2);    }    | idents '.' bad_identifier {}    | idents '.' error {}    ;      inherit_specifier: TOK_IDENTIFIER TOK_COLON_COLON    {
pike.git/src/language.yacc:3706:    if (lex.current_file) {    ref_push_string(lex.current_file);    } else {    /* yyerror() can be called from define_function(), which    * can be called by the C module initialization code.    */    push_constant_text("");    }    push_int(lex.current_line);    push_text(str); -  safe_apply_handler("compile_error", error_handler, compat_handler, 3); +  low_safe_apply_handler("compile_error", error_handler, compat_handler, 3);    pop_stack();    }else{    if (lex.current_file) {    (void)fprintf(stderr, "%s:%ld: %s\n",    lex.current_file->str,    (long)lex.current_line,    str);    } else {    (void)fprintf(stderr, "NULL:%ld: %s\n",    (long)lex.current_line,
pike.git/src/language.yacc:3873:    JMP_BUF recovery;       if (SETJMP(recovery)) {    struct svalue s;    assign_svalue_no_free(&s, &throw_value);       yyerror("Bad implicit enum value (failed to add 1).");    while(Pike_sp > save_sp) pop_stack();       push_svalue(&s); -  safe_apply_handler("compile_exception", error_handler, compat_handler, 1); +  low_safe_apply_handler("compile_exception", error_handler, compat_handler, 1);    if (IS_ZERO(sp-1)) yy_describe_exception(&s);    pop_stack();    free_svalue(&s);    } else {    push_int(1);    f_add(2);    }    UNSETJMP(recovery);   #ifdef PIKE_DEBUG    if (Pike_sp != save_sp) {    fatal("stack thrashed in enum.\n");    }   #endif /* PIKE_DEBUG */   }    -  +  + static int call_handle_import(struct pike_string *s) + { +  int args; +  +  ref_push_string(s); +  ref_push_string(lex.current_file); +  if (error_handler && error_handler->prog) { +  ref_push_object(error_handler); +  args = 3; +  } +  else args = 2; +  +  if (safe_apply_handler("handle_import", error_handler, compat_handler, +  args, BIT_MAPPING|BIT_OBJECT|BIT_PROGRAM|BIT_ZERO)) +  if (Pike_sp[-1].type != T_INT) +  return 1; +  else { +  pop_stack(); +  if (!s->size_shift) +  my_yyerror("Couldn't find module to import: %s",s->str); +  else +  yyerror("Couldn't find module to import"); +  } +  else { +  struct svalue thrown = throw_value; +  throw_value.type = T_INT; +  my_yyerror("Error finding module to import"); +  push_svalue(&thrown); +  low_safe_apply_handler("compile_exception", error_handler, compat_handler, 1); +  if (IS_ZERO(sp-1)) yy_describe_exception(&thrown); +  pop_stack(); +  free_svalue(&thrown); +  } +  +  return 0; + } +    void cleanup_compiler(void)   {   }