~ubuntu-branches/ubuntu/jaunty/aspectc++/jaunty

« back to all changes in this revision

Viewing changes to Puma/src/parser/cparser/CSemVisitor.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-07-07 14:41:02 UTC
  • mfrom: (1.1.3 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707144102-lzml7t07f3sl00r5
Tags: 1.0pre4~svn.20080711-1
* new upstream snapshot.
* include all upstream documentation. Clarifying emails regarding
  licensing has been included into debian/copyright.
* reformat description following recomendations of
  http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
  (Closes: #480316)

Show diffs side-by-side

added added

removed removed

Lines of Context:
290
290
}
291
291
 
292
292
void CSemVisitor::pre_action (CT_GotoStmt *node) {
 
293
  if (! current_scope->LocalScope ())
 
294
    SEM_ERROR (node, "`goto' outside of function");
 
295
  else
 
296
    check_goto_label (node->Label ());
 
297
}
 
298
 
 
299
void CSemVisitor::check_goto_label (CTree *tree) {
293
300
  CFunctionInfo *finfo;
294
301
  const char *name;
295
302
  
296
 
  if (! current_scope->LocalScope ())
297
 
    SEM_ERROR (node, "`goto' outside of function");
298
 
  else {
299
 
    finfo = current_scope->LocalScope ()->Function ();
300
 
    if (finfo) {
301
 
      name = node->Label ()->Text ();
302
 
      if (! finfo->Label (name))
303
 
        SEM_ERROR (node, "label `" << name << "' used but not defined");
304
 
    }
 
303
  finfo = current_scope->LocalScope ()->Function ();
 
304
  if (finfo) {
 
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");
305
309
  }
306
310
}
307
311
 
364
368
 
365
369
void CSemVisitor::pre_action (CT_ArrayDeclarator *node) {
366
370
  CT_SimpleName *name;
 
371
  CObjectInfo *info;
367
372
  const char *array;
 
373
  CTypeArray *atype;
368
374
  CTypeInfo *type;
369
375
  CConstant *v;
370
376
  CTree *expr;
371
377
  
 
378
  name = findName (node);
 
379
  if (name) {
 
380
    array = name->Text ();
 
381
    info = name->Object ();
 
382
  } else {
 
383
    array = "";
 
384
    info = 0;
 
385
  }
372
386
  expr = node->Delimiter ()->Expr ();
 
387
 
373
388
  if (expr) {
374
 
    name = findName (node);
375
 
    array = name ? name->Text () : "";
376
 
    type = resolveExpr (expr, node->Delimiter ());
377
 
    expr = node->Delimiter ()->Expr ();
378
 
    
 
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 ());
387
396
    }
 
397
  } 
 
398
 
 
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);
 
410
      } else do {
 
411
        if (! atype->hasDimension ()) {
 
412
          SEM_ERROR (node, "array size missing in `" << array << "'");
 
413
          break;
 
414
        }
 
415
        atype = atype->BaseType ()->VirtualType ()->TypeArray ();
 
416
      } while (atype && ! atype->isVarArray ());
 
417
    } 
388
418
  }
389
419
}
390
420