292
292
void CSemVisitor::pre_action (CT_GotoStmt *node) {
293
if (! current_scope->LocalScope ())
294
SEM_ERROR (node, "`goto' outside of function");
296
check_goto_label (node->Label ());
299
void CSemVisitor::check_goto_label (CTree *tree) {
293
300
CFunctionInfo *finfo;
294
301
const char *name;
296
if (! current_scope->LocalScope ())
297
SEM_ERROR (node, "`goto' outside of function");
299
finfo = current_scope->LocalScope ()->Function ();
301
name = node->Label ()->Text ();
302
if (! finfo->Label (name))
303
SEM_ERROR (node, "label `" << name << "' used but not defined");
303
finfo = current_scope->LocalScope ()->Function ();
305
CT_SimpleName *label = (CT_SimpleName *)tree;
306
name = label->Text ();
307
if (! finfo->Label (name))
308
SEM_ERROR (label, "label `" << name << "' used but not defined");
365
369
void CSemVisitor::pre_action (CT_ArrayDeclarator *node) {
366
370
CT_SimpleName *name;
367
372
const char *array;
378
name = findName (node);
380
array = name->Text ();
381
info = name->Object ();
372
386
expr = node->Delimiter ()->Expr ();
374
name = findName (node);
375
array = name ? name->Text () : "";
376
type = resolveExpr (expr, node->Delimiter ());
377
expr = node->Delimiter ()->Expr ();
389
type = expr->Type ();
379
390
if (! type->isInteger ())
380
391
SEM_ERROR (node, "size of array `" << array << "' has non-integer type");
381
392
else if (CSemExpr::isConstIntExpr (expr)) {
382
393
v = expr->Value ()->Constant ();
383
394
if (/*v->isNull () ||*/ v->isNegative ())
384
395
SEM_ERROR (node, "array `" << array << "' has invalid size");
385
else if (node->Type ()->TypeArray ())
386
node->Type ()->TypeArray ()->Dimension (v->convert_to_uint ());
399
// check the array size on the top level array declarator only
400
// to avoid redundant error messages, extern arrays can have
401
// unspecified dimension
402
if (info && ! info->isExtern () &&
403
node->Parent ()->NodeName () != CT_ArrayDeclarator::NodeId ()) {
404
atype = name->Object ()->TypeInfo ()->VirtualType ()->TypeArray ();
405
if (atype && ! atype->isVarArray ()) {
406
if (! atype->BaseType ()->isArray () && ! atype->hasDimension ()) {
407
// assume dimension 1
408
SEM_WARNING (node, "array `" << array << "' assumed to have one element");
409
atype->Dimension (1);
411
if (! atype->hasDimension ()) {
412
SEM_ERROR (node, "array size missing in `" << array << "'");
415
atype = atype->BaseType ()->VirtualType ()->TypeArray ();
416
} while (atype && ! atype->isVarArray ());