Branch: Tag:

2008-04-14

2008-04-14 10:14:41 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Pike compiler mega patch.
Added predef::CompilerEnvironment, which is a wrapper for struct compilation.
Moved the definition of struct compilation to the new header file "pike_compiler.h".
The compilation struct is now contained in the current context in the current_object during compilation.
The global variable lex is no more, it has moved into the compilation struct.
Added enter_compiler() and exit_compiler().
predef::compile() is now shorthand for predef::CompilerContext()->compile().

Rev: src/builtin_functions.c:1.652
Rev: src/compilation.h:1.35
Rev: src/docode.c:1.197
Rev: src/docode.h:1.20
Rev: src/dynamic_load.c:1.90
Rev: src/encode.c:1.263
Rev: src/language.yacc:1.411
Rev: src/las.c:1.406
Rev: src/lex.c:1.121
Rev: src/lex.h:1.36
Rev: src/lexer.h:1.66
Rev: src/module.c:1.52
Rev: src/object.c:1.284
Rev: src/operators.c:1.230
Rev: src/pike_compiler.h:1.1
Rev: src/pike_types.c:1.321
Rev: src/program.c:1.660
Rev: src/program.h:1.237

2:   || 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: pike_types.c,v 1.320 2008/04/01 13:20:07 mast Exp $ + || $Id: pike_types.c,v 1.321 2008/04/14 10:14:41 grubba Exp $   */      #include "global.h"
27:   #include "opcodes.h"   #include "cyclic.h"   #include "gc.h" + #include "pike_compiler.h"   #include "block_alloc.h"      #ifdef PIKE_DEBUG
55:    * Perform weaker checking for OR-nodes. */   #define LE_A_B_GROUPED 0/*12*/ /* Both the above two flags. */   #endif + #define LE_USE_HANDLERS 16 /* Call handlers if appropriate. */      /*    * Flags used by low_get_first_arg_type()
1871:    break;       case PIKE_T_ATTRIBUTE: +  { +  struct pike_string *deprecated; +  MAKE_CONST_STRING(deprecated, "deprecated"); +  if (((struct pike_string *)s->car) == deprecated) { +  fprintf(stderr, "__deprecated__("); +  } else {    fprintf(stderr, "__attribute__(\"%s\", ",    ((struct pike_string *)s->car)->str); -  +  }    simple_describe_type(s->cdr);    fprintf(stderr, ")"); -  +  }    break;       case T_SCOPE:
2214:       case PIKE_T_ATTRIBUTE:    if (!((struct pike_string *)t->car)->size_shift) { +  struct pike_string *deprecated; +  MAKE_CONST_STRING(deprecated, "deprecated"); +  if (((struct pike_string *)t->car) == deprecated) { +  my_strcat("__deprecated__("); +  } else {    my_strcat("__attribute__(\"");    my_binary_strcat(((struct pike_string *)t->car)->str,    ((struct pike_string *)t->car)->len);    my_strcat("\", "); -  +  }    my_describe_type(t->cdr);    my_strcat(")");    } else {
3727:   #endif    /* FALL_THROUGH */    case PIKE_T_NAME: +  a = a->cdr; +  goto recurse;    case PIKE_T_ATTRIBUTE: -  +  if ((b->type == PIKE_T_ATTRIBUTE) && (a->car == b->car)) {    a = a->cdr; -  +  b = b->cdr;    goto recurse; -  +  } + #if 0 +  if (!flags & LE_USE_HANDLERS) { +  a = a->cdr; +  goto recurse; +  } + #endif /* 0 */ +  if (!low_pike_types_le(a->cdr, b, array_cnt, flags)) return 0; + #if 0 +  ref_push_string((struct pike_string *)a->car); +  ref_push_type_value(a->cdr); +  ref_push_type_value(b); +  push_int(1); +  if (safe_apply_handler("handle_attribute", error_handler, compat_handler, +  4, 0)) { +  if ((Pike_sp[-1].type == T_INT) && +  (Pike_sp[-1].subtype == NUMBER_NUMBER) && +  (!Pike_sp[-1].u.integer)) { +  pop_stack(); +  return 0; +  } +  pop_stack(); +  } + #endif /* 0 */ +  return 1;       case T_NOT:    if (b->type == T_NOT) {
3863:    b = b->car;    goto recurse;    +  case PIKE_T_ATTRIBUTE: + #if 0 +  if (!flags & LE_USE_HANDLERS) { +  b = b->cdr; +  goto recurse; +  } + #endif /* 0 */ +  if (!low_pike_types_le(a, b->cdr, array_cnt, flags)) return 0; + #if 0 +  ref_push_string((struct pike_string *)b->car); +  ref_push_type_value(a); +  ref_push_type_value(b->cdr); +  push_int(2); +  if (safe_apply_handler("handle_attribute", error_handler, compat_handler, +  4, 0)) { +  if ((Pike_sp[-1].type == T_INT) && +  (Pike_sp[-1].subtype == NUMBER_NUMBER) && +  (!Pike_sp[-1].u.integer)) { +  pop_stack(); +  return 0; +  } +  pop_stack(); +  } + #endif /* 0 */ +  return 1;    case PIKE_T_SCOPE:   #ifdef TYPE_GROUPING    flags |= LE_B_GROUPED;   #endif    /* FALL_THROUGH */    case PIKE_T_NAME: -  case PIKE_T_ATTRIBUTE: +     b = b->cdr;    goto recurse;   
4318:    */   static int low_get_return_type(struct pike_type *a, struct pike_type *b)   { +  struct compilation *c = THIS_COMPILATION;    int tmp; -  +  CHECK_COMPILER();    switch(a->type)    {    case T_OR:
4380:    if(a)    {   #if 0 -  if ((lex.pragmas & ID_STRICT_TYPES) && +  if ((c->lex.pragmas & ID_STRICT_TYPES) &&    !low_pike_types_le(a, b, 0, 0)) {    yywarning("Type mismatch");    }
4441:   {    struct pike_type *tmp;    struct program *p; +  int pragmas = 0;    -  +  if (n) { +  struct compilation *c = THIS_COMPILATION; +  CHECK_COMPILER(); +  pragmas = c->lex.pragmas; +  } +     switch(low_check_indexing(t, index_type, n))    {    case 0: return 0;
4519:    return mixed_type_string;       case T_MIXED: -  if (lex.pragmas & ID_STRICT_TYPES) { +  if (pragmas & ID_STRICT_TYPES) {    yywarning("Indexing mixed.");    }    add_ref(mixed_type_string);
4633:    struct pike_type *index1_type,    struct pike_type *index2_type)   { +  struct compilation *c = THIS_COMPILATION;    struct pike_type *tmp;    struct program *p;    -  +  CHECK_COMPILER(); +     while((t->type == PIKE_T_NAME) ||    (t->type == PIKE_T_ATTRIBUTE)) {    t = t->cdr;
4736:    yywarning("Ranging object without index operator.");    return 0;    } -  if (lex.pragmas & ID_STRICT_TYPES) { +  if (c->lex.pragmas & ID_STRICT_TYPES) {    yywarning("Ranging generic object.");    }    add_ref(mixed_type_string);
4744:    }       case T_MIXED: -  if (lex.pragmas & ID_STRICT_TYPES) { +  if (c->lex.pragmas & ID_STRICT_TYPES) {    yywarning("Ranging mixed.");    }    add_ref(mixed_type_string);
5892:    }       if (tmp2->type == PIKE_T_ATTRIBUTE) { +  struct compilation *c = MAYBE_THIS_COMPILATION;    /* Perform extra argument checking based on the attribute. */    /* FIXME: Support multiple attributes. */    ref_push_string((struct pike_string *)tmp2->car);    push_svalue(sval);    ref_push_type_value(tmp2->cdr);    ref_push_type_value(res); -  if (safe_apply_handler("handle_attribute_constant", error_handler, -  compat_handler, 4, 0)) { +  if (safe_apply_handler("handle_attribute_constant", +  c?c->handler:NULL, +  c?c->compat_handler:NULL, 4, 0)) {    if ((Pike_sp[-1].type == PIKE_T_TYPE)) {    type_stack_mark();    push_finished_type(Pike_sp[-1].u.type);
6454:    struct pike_type *fun_type,    node *args, INT32 *argno)   { +  struct compilation *c = THIS_COMPILATION;    struct pike_type *tmp = NULL;    struct pike_type *res = NULL;    struct svalue *sval = NULL;    int flags = 0;    -  +  CHECK_COMPILER(); +     debug_malloc_touch(fun_type);       while (args && (args->token == F_ARG_LIST) && fun_type) {
6549:    if (cnt == 256) {    yywarning("In argument %d to %S: The @-operator argument must be an empty array.",    *argno, fun_name); -  } else if (lex.pragmas & ID_STRICT_TYPES) { +  } else if (c->lex.pragmas & ID_STRICT_TYPES) {    yywarning("In argument %d to %S: The @-operator argument has a max length of %d.",    *argno, fun_name, 256-cnt);    }
6571: Inside #if defined(PIKE_DEBUG)
   fprintf(stderr, " OK.\n");    }   #endif /* PIKE_DEBUG */ -  if (lex.pragmas & ID_STRICT_TYPES) { +  if (c->lex.pragmas & ID_STRICT_TYPES) {    if (!(tmp = low_new_check_call(fun_type, args->type,    flags|CALL_STRICT, sval))) {    yywarning("Type mismatch in argument %d to %S.",