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

« back to all changes in this revision

Viewing changes to Puma/src/parser/cparser/CSemExpr.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:
44
44
#include "Puma/WChar.h"    /* wcslen() */
45
45
#include <ctype.h>         /* isdigit(); isxdigit() */
46
46
#include <string.h>
 
47
 
47
48
using namespace std;
48
49
 
49
50
namespace Puma {
74
75
  SEM_WARNING (node__, \
75
76
    "assignment from incompatible pointer type")
76
77
 
 
78
#define SEM_WARNING__init(node__,name__,type__) \
 
79
  SEM_WARNING (node__, type__ << " object `" << name__->Name () \
 
80
    << "' may not be initialized")
 
81
 
77
82
#define SEM_ERROR__type_mismatch(node__,where__) \
78
83
  SEM_ERROR (node__, "type mismatch in " << where__)
79
84
 
86
91
#define SEM_ERROR__non_lvalue(node__) \
87
92
  SEM_ERROR (node__, "non-lvalue in assignment")
88
93
 
89
 
#define SEM_ERROR__init(node__,name__,type__) \
90
 
  SEM_ERROR (node__, type__ << " object `" << name__->Name () \
91
 
    << "' may not be initialized")
92
 
 
93
94
#define SEM_ERROR__num_args_too(node__,what__,num__,info__) \
94
95
  SEM_ERROR (node__, "too " << what__ << " arguments (" << num__ << ") in call to function `" \
95
96
    << info__->Name () << "'")
1009
1010
  }
1010
1011
 
1011
1012
  info = findObject (op1);
1012
 
  if (! (t1->isFunction () || 
1013
 
         base->NodeName () == CT_DerefExpr::NodeId () ||
1014
 
         base->NodeName () == CT_IndexExpr::NodeId () ||
1015
 
         (isLvalue (op1) && 
1016
 
          (info ? ! info->TypeInfo ()->TypeBitField () : true)))) {
1017
 
    SEM_ERROR__invalid_op (node, "unary", "&");
1018
 
  } else {
 
1013
  if (t1->isFunction () || 
 
1014
      t1->isArray () ||
 
1015
      base->NodeName () == CT_DerefExpr::NodeId () ||
 
1016
      base->NodeName () == CT_IndexExpr::NodeId () ||
 
1017
      (isLvalue (op1) && (info ? ! info->TypeInfo ()->TypeBitField () : true))) {
1019
1018
    result = new CTypePointer (t1->Duplicate ());
1020
1019
    cast_to (result, op1, node, false);
 
1020
  } else {
 
1021
    SEM_ERROR__invalid_op (node, "unary", "&");
1021
1022
  }
1022
1023
  
1023
1024
  node->setTypeRef (result);
1585
1586
      ! (type->isArray () && ! type->isComplete () && 
1586
1587
         type->VirtualType ()->BaseType ()->isObject (pos)))) {
1587
1588
    if (type->isFunction ()) {
1588
 
      SEM_ERROR__init (node, info, "function-type");
 
1589
      SEM_WARNING__init (node, info, "function-type");
1589
1590
    } else if (! type->isComplete (pos)) {
1590
 
      SEM_ERROR__init (node, info, "incomplete-type");
 
1591
      SEM_WARNING__init (node, info, "incomplete-type");
1591
1592
    } else {
1592
 
      SEM_ERROR__init (node, info, "variable-sized");
 
1593
      SEM_WARNING__init (node, info, "variable-sized");
1593
1594
    }
1594
1595
  }    
1595
1596
 
1630
1631
          if (d->Sons () == 2) { 
1631
1632
            name = d->Son (1)->token ()->text ();
1632
1633
            if (! type->isRecord ()) {
1633
 
              SEM_ERROR (d, "`" << curr->Name () 
 
1634
              SEM_WARNING (d, "`" << curr->Name () 
1634
1635
                << "' is not a struct or union type object");
1635
1636
              SEM_MSG (d, "and cannot be used to access a member named `" 
1636
1637
                << name << "'");
1640
1641
            sinfo = sinfo->DefObject ()->Record ();
1641
1642
            obj = sinfo->Attribute (name);
1642
1643
            if (! obj) {
1643
 
              SEM_ERROR (d, "`" << name << "' is not a member of `" 
 
1644
              SEM_WARNING (d, "`" << name << "' is not a member of `" 
1644
1645
                << (sinfo->ClassInfo () ? "struct " : "union ")
1645
1646
                << sinfo->Name () << "'");
1646
1647
              break;
1653
1654
          } else {               
1654
1655
            resolveExpr (d->Son (1), d); // compute element index
1655
1656
            if (! type->isArray ()) {
1656
 
              SEM_ERROR (d, "`" << curr->Name () 
1657
 
                << "' is not an array type object");
 
1657
              SEM_WARNING (d, "`" << curr->Name () << "' is not an array type object");
1658
1658
              SEM_MSG (d, "and cannot be initialized like array type objects");
1659
1659
              break;
1660
1660
            }  
1661
1661
            if (! isConstIntExpr (d)) {
1662
 
              SEM_ERROR (d, 
1663
 
                "element index is not a valid integer constant expression");
 
1662
              SEM_WARNING (d, "element index is not a valid integer constant expression");
1664
1663
              break;
1665
1664
            }
1666
1665
            v = d->Son (1)->Value ()->Constant ();
1667
1666
            if (v->isNegative ()) {
1668
 
              SEM_ERROR (d, "negative element index");
 
1667
              SEM_WARNING (d, "negative element index");
1669
1668
              break;
1670
1669
            }
1671
1670
            size = v->convert_to_uint () + 1;
1672
1671
            if (objs.top ().size < size)
1673
1672
              objs.top ().size = size;
1674
1673
            if (type->isFixedArray () && type->Dimension () < size) {
1675
 
              SEM_ERROR (d, "element index out of range for fixed-size array `"
 
1674
              SEM_WARNING (d, "element index out of range for fixed-size array `"
1676
1675
                << curr->Name () << "'");
1677
1676
              break;
1678
1677
            } else if (! type->isFixedArray () && type->Dimension () < size) {
1732
1731
    } else
1733
1732
      size = ++objs.top ().size;
1734
1733
    if (size > 1)
1735
 
      SEM_ERROR (item, "too many elements in scalar initializer");
 
1734
      SEM_WARNING (item, "too many elements in scalar initializer");
1736
1735
    return;
1737
1736
  } else if (type->isArray ()) {
1738
1737
    if ((type->VirtualType ()->BaseType ()->VirtualType ()->is_char () && 
1745
1744
    } else {
1746
1745
      size = ++objs.top ().size;
1747
1746
      if (type->isFixedArray () && type->Dimension () < size) {
1748
 
        SEM_ERROR (item, "too many elements in fixed-size array initializer");
 
1747
        SEM_WARNING (item, "too many elements in fixed-size array initializer");
1749
1748
      } else if (! type->isFixedArray () && type->Dimension () < size)
1750
1749
        type->VirtualType ()->TypeArray ()->Dimension (size);
1751
1750
      pushSubObj (type, obj, objs);
1776
1775
        return;
1777
1776
    } else { // curr has no members (?)
1778
1777
      if (*type == *info->TypeInfo ()) {
1779
 
        SEM_ERROR (item, "too many elements in record initializer");
 
1778
        SEM_WARNING (item, "too many elements in record initializer");
1780
1779
      } else {
1781
1780
        popSubObj (type, curr, obj, objs);
1782
1781
        findNext (item, type, curr, obj, info, objs, braced);
1811
1810
    size = objs.top ().size + 1;
1812
1811
    if (type->isFixedArray () && type->Dimension () < size) {
1813
1812
      if (*type == *info->TypeInfo ()) {
1814
 
        SEM_ERROR (item, "too many elements in fixed-size array initializer");
 
1813
        SEM_WARNING (item, "too many elements in fixed-size array initializer");
1815
1814
        return;
1816
1815
      } else
1817
1816
        popSubObj (otype, curr, obj, objs);
1841
1840
      return;
1842
1841
    } else { // all members of curr initialized
1843
1842
      if (*type == *info->TypeInfo ()) {
1844
 
        SEM_ERROR (item, "too many elements in record initializer");
 
1843
        SEM_WARNING (item, "too many elements in record initializer");
1845
1844
        return;
1846
1845
      } else
1847
1846
        popSubObj (otype, curr, obj, objs);
1866
1865
  t2 = resolveExpr (node, base);
1867
1866
  conv_to_ptr = 1;
1868
1867
  if (is_const && ! isConstExpr (node)) 
1869
 
    SEM_ERROR (node, "initializer element is not constant");
 
1868
    SEM_WARNING (node, "initializer element is not constant");
1870
1869
  v = node->Value () ? node->Value ()->Constant () : 0;
1871
1870
    
1872
1871
  if (type->isScalar ()) {
1874
1873
      if (*type != *t2)
1875
1874
        cast_to (type->VirtualType (), node, base);
1876
1875
    } else if (! compatible (type, t2, v)) {
1877
 
      SEM_ERROR (node, "invalid initializer");
 
1876
      SEM_WARNING (node, "invalid initializer");
1878
1877
    } else if (*type != *t2)
1879
1878
      cast_to (type->VirtualType (), node, base);
1880
1879
  } else if (type->isArray ()) {
1886
1885
          node->NodeName () == CT_WideString::NodeId ()))) {
1887
1886
      if (type->isFixedArray ()) { 
1888
1887
        if (type->Dimension () < t2->Dimension ()) 
1889
 
          SEM_ERROR (node, "initializer-string for array is too long");
 
1888
          SEM_WARNING (node, "initializer-string for array is too long");
1890
1889
      } else
1891
1890
        type->VirtualType ()->TypeArray ()->Dimension (t2->Dimension ());
1892
1891
    } else 
1893
 
      SEM_ERROR (node, "invalid initializer");
 
1892
      SEM_WARNING (node, "invalid initializer");
1894
1893
  } else if (type->isRecord ()) {
1895
1894
    if (! compatible (type, t2, v))
1896
 
      SEM_ERROR (node, "invalid initializer");
 
1895
      SEM_WARNING (node, "invalid initializer");
1897
1896
  } else
1898
 
    SEM_ERROR (node, "invalid initializer");
 
1897
    SEM_WARNING (node, "invalid initializer");
1899
1898
}
1900
1899
 
1901
1900
void CSemExpr::popSubObj (CTypeInfo *&type, CObjectInfo *&curr, 
2142
2141
  
2143
2142
  id = node->NodeName ();
2144
2143
  type = node->Type ();
2145
 
  if (type->isUndefined () || type->isVoid () || type->isFunction ())
 
2144
  if (type->isUndefined () || type->isVoid () || type->isFunction () || type->isArray ())
2146
2145
    return false;
2147
2146
  if (type->isPointer () && type->VirtualType ()->BaseType ()->isArray ()) {
2148
2147
    CTree *tn = node;
2214
2213
      id == CT_UnaryExpr::NodeId ()) {
2215
2214
    return findObject (node->Son (1));
2216
2215
  } else if (id == CT_ImplicitCast::NodeId () ||
2217
 
             id == CT_PostfixExpr::NodeId ()) {
 
2216
             id == CT_PostfixExpr::NodeId () ||
 
2217
             id == CT_IndexExpr::NodeId ()) {
2218
2218
    return findObject (node->Son (0));
2219
2219
  } else if (id == CT_CastExpr::NodeId ()) {
2220
2220
    return findObject (node->Son (3));