Branch: Tag:

2016-01-04

2016-01-04 14:57:56 by Per Hedbor <ph@opera.com>

First stage of the 'auto' type.

Works, but for now only for variable declarations, not return types
(entirely, most of the plumbing is done) or for variables declared in
foreach and sscanf.

Since the loop variables in foreach is really the most important
location, this is of somewhat limited use so far.

Commited for safekeeping.

Conflicts:
src/language.yacc
src/lexer.h
src/pike_types.c
src/svalue.h

3259:    copy_pike_type(n->type, CAR(n)->type);    } else {    /* Ensure that the type-fields are up to date. */ +  struct pike_type *t;    fix_type_field(CAR(n));    fix_type_field(CDR(n)); -  +  if( CDR(n)->type == PIKE_T_AUTO ) +  { +  /* Update to actual type. */ +  free_type( CDR(n)->type ); +  copy_pike_type( CDR(n)->type, CAR(n)->type ); +  }   #if 0    /* This test isn't sufficient, see below. */    check_node_type(CAR(n), CDR(n)->type, "Bad type in assignment.");
3546:    copy_pike_type(n->type, CDAR(n)->type);    }    break; -  } else if(Pike_compiler->compiler_frame && -  Pike_compiler->compiler_frame->current_return_type) { +  } +  else if(Pike_compiler->compiler_frame && +  Pike_compiler->compiler_frame->current_return_type) +  {    if ((Pike_compiler->compiler_frame->current_return_type != -  void_type_string) || -  (CAR(n)->token != F_CONSTANT) || -  !SAFE_IS_ZERO(& CAR(n)->u.sval)) { -  check_node_type(CAR(n), -  Pike_compiler->compiler_frame->current_return_type, -  "Wrong return type."); +  void_type_string)) { +  struct pike_type *t = Pike_compiler->compiler_frame->current_return_type; +  +  if( t->type == PIKE_T_AUTO ) +  { +  if( t->car ) +  { +  /* Not the first one.. */ +  push_auto_typed_type( or_pike_types( t->car, CAR(n)->type, 0 ) );    } -  +  else +  { +  /* first one.. */ +  push_auto_typed_type( CAR(n)->type );    } -  +  free_type( t ); +  t = pop_type(); +  Pike_compiler->compiler_frame->current_return_type = t; +  } +  else if(CAR(n)->token != F_CONSTANT || !SAFE_IS_ZERO(&CAR(n)->u.sval)) +  check_node_type(CAR(n), t, "Wrong return type."); +  } +  }    copy_pike_type(n->type, void_type_string);    break;