pike.git/
src/
las.c
Branch:
Tag:
Non-build tags
All tags
No tags
2018-05-27
2018-05-27 13:05:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>
eda0e7de065fa100430dfefa0ffb7cb320591fbb (
39
lines) (+
30
/-
9
)
[
Show
|
Annotate
]
Branch:
master
Compiler: Clean up auto handling in foreach.
3097:
static int function_type_max=0;
-
void
check
_
foreach
_
type
(node *
expression
,
node *lvalues,
-
struct pike_type *
*ind_
type
,
-
struct pike_type **val_type
)
+
static
void
fix
_
auto
_
node
(node *
n
, struct pike_type *type)
{
-
+
free_type(n->type);
+
copy_pike_type(n->type, type);
+
if ((n->token == F_LOCAL) && !n->u.integer.b) {
+
struct local_variable *var =
+
&Pike_compiler->compiler_frame->variable[n->u.integer.a];
+
if (var->type) free_type(var->type);
+
copy_pike_type(var->type, type);
+
}
+
}
+
+
void fix_foreach_type(node *val_lval)
+
{
struct compilation *c = THIS_COMPILATION;
-
+
node *expression, *lvalues;
-
+
if (!val_lval || (val_lval->token != F_FOREACH_VAL_LVAL)) return;
+
+
fix_type_field(val_lval);
+
expression = CAR(val_lval);
+
lvalues = CDR(val_lval);
+
if (!expression || pike_types_le(expression->type, void_type_string)) { yyerror("foreach(): Looping over a void expression."); } else {
3153:
} else { if( CAR(lvalues)->type->type == PIKE_T_AUTO ) {
-
if(ind
_
type)copy
_
pike_type
(
*ind_type
,index_type);
+
fix
_
auto
_
node
(
CAR(lvalues)
,
index_type);
} else if (!pike_types_le(index_type, CAR(lvalues)->type)) { int level = REPORT_NOTICE;
3193:
} else { if( CDR(lvalues)->type->type == PIKE_T_AUTO ) {
-
if(val
_
type) copy
_
pike_type
(
*val_type
,value_type);
+
fix
_
auto
_
node
(
CDR(lvalues)
,
value_type);
} else if (!pike_types_le(value_type, CDR(lvalues)->type)) { int level = REPORT_NOTICE;
3236:
/* No loop variable. Will be converted to a counted loop * by treeopt. */ } else if( lvalues->type->type == PIKE_T_AUTO ) {
-
if(val
_
type)
-
copy
_
pike_type
(
*val_type
, expression->type->car
);
+
fix
_
auto
_
node
(
lvalues
, expression->type->car);
} else if (pike_types_le(lvalues->type, void_type_string)) {
-
yyerror
("Bad argument 2 to foreach().");
+
yytype_report
(
REPORT_ERROR,
+
NULL, 0, lvalues->type,
+
NULL, 0, expression->type->car,
+
0,
+
"Bad argument 2 to foreach().");
} else { struct pike_type *array_value_type;
3967:
if (!CAAR(n) || pike_types_le(CAAR(n)->type, void_type_string)) { yyerror("foreach(): Looping over a void expression."); } else {
-
check
_foreach_type(
CAAR
(n)
, CDAR(n
)
, NULL, NULL)
;
+
fix
_foreach_type(
CAR
(n));
} } copy_pike_type(n->type, void_type_string);