~ubuntu-branches/ubuntu/hardy/swig1.3/hardy

« back to all changes in this revision

Viewing changes to Source/CParse/parser.y

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
#define yylex yylex
19
19
 
20
 
char cvsroot_parser_y[] = "$Header: /cvsroot/swig/SWIG/Source/CParse/parser.y,v 1.104 2004/12/14 06:47:19 marcelomatus Exp $";
 
20
char cvsroot_parser_y[] = "$Header: /cvsroot/swig/SWIG/Source/CParse/parser.y,v 1.124 2005/10/13 09:24:35 marcelomatus Exp $";
21
21
 
22
22
#include "swig.h"
23
23
#include "cparse.h"
140
140
    }
141
141
    if ((Strcmp(key,"parms") == 0) || (Strcmp(key,"pattern") == 0) || (Strcmp(key,"throws") == 0)
142
142
        || (Strcmp(key,"kwargs") == 0)) {
143
 
      Setattr(nn,key,CopyParmList(k.item));
 
143
      ParmList *pl = CopyParmList(k.item);
 
144
      Setattr(nn,key,pl);
 
145
      Delete(pl);
144
146
      continue;
145
147
    }
146
148
    /* Looks okay.  Just copy the data using Copy */
164
166
#define  CPLUS_PRIVATE   2
165
167
#define  CPLUS_PROTECTED 3
166
168
 
 
169
/* include types */
 
170
static int   import_mode = 0;
 
171
 
167
172
void SWIG_typemap_lang(const char *tm_lang) {
168
173
  typemap_lang = Swig_copy_string(tm_lang);
169
174
}
433
438
    }
434
439
    if (strncmp(Char(symname),"$ignore",7) == 0) {
435
440
      char *c = Char(symname)+7;
436
 
      Setattr(n,"feature:ignore","1");
 
441
      SetFlag(n,"feature:ignore");
437
442
      if (strlen(c)) {
438
443
        SWIG_WARN_NODE_BEGIN(n);
439
444
        Swig_warning(0,Getfile(n), Getline(n), "%s\n",c+1);
443
448
    } else {
444
449
      Node *c;
445
450
      if ((wrn) && (Len(wrn))) {
446
 
        SWIG_WARN_NODE_BEGIN(n);
447
 
        Swig_warning(0,Getfile(n),Getline(n), "%s\n", wrn);
448
 
        SWIG_WARN_NODE_END(n);
 
451
        String *metaname = symname;
 
452
        if (!Getmeta(metaname,"already_warned")) {
 
453
          SWIG_WARN_NODE_BEGIN(n);
 
454
          Swig_warning(0,Getfile(n),Getline(n), "%s\n", wrn);
 
455
          SWIG_WARN_NODE_END(n);
 
456
          Setmeta(metaname,"already_warned","1");
 
457
        }
449
458
      }
450
459
      c = Swig_symbol_add(symname,n);
451
460
 
1069
1078
     } else {
1070
1079
       Swig_feature_set(features_hash, name, decl, fname, val, featureattribs);
1071
1080
     }
 
1081
     Delete(decl);
1072
1082
   } else if (SwigType_ispointer(t)) {
1073
1083
     String *nname = NewStringf("*%s",name);
1074
1084
     Swig_feature_set(features_hash,nname,0,fname,val, featureattribs);
1130
1140
static void default_arguments(Node *n) {
1131
1141
  Node *function = n;
1132
1142
 
1133
 
  /* Do not add in functions if kwargs is being used or if user wants old default argument wrapping
1134
 
    (one wrapped method per function irrespective of number of default arguments) */
1135
1143
  if (function) {
 
1144
    ParmList *varargs = Getattr(function,"feature:varargs");
 
1145
    if (varargs) {
 
1146
      /* Handles the %varargs directive by looking for "feature:varargs" and 
 
1147
       * substituting ... with an alternative set of arguments.  */
 
1148
      Parm     *p = Getattr(function,"parms");
 
1149
      Parm     *pp = 0;
 
1150
      while (p) {
 
1151
        SwigType *t = Getattr(p,"type");
 
1152
        if (Strcmp(t,"v(...)") == 0) {
 
1153
          if (pp) {
 
1154
            set_nextSibling(pp,Copy(varargs));
 
1155
          } else {
 
1156
            Setattr(function,"parms", Copy(varargs));
 
1157
          }
 
1158
          break;
 
1159
        }
 
1160
        pp = p;
 
1161
        p = nextSibling(p);
 
1162
      }
 
1163
    }
 
1164
 
 
1165
    /* Do not add in functions if kwargs is being used or if user wants old default argument wrapping
 
1166
      (one wrapped method per function irrespective of number of default arguments) */
1136
1167
    if (compact_default_args 
1137
1168
        || is_cfunction(function) 
1138
 
        || Getattr(function,"feature:compactdefaultargs") 
1139
 
        || Getattr(function,"feature:kwargs")) {
 
1169
        || GetFlag(function,"feature:compactdefaultargs") 
 
1170
        || GetFlag(function,"feature:kwargs")) {
1140
1171
      ParmList *p = Getattr(function,"parms");
1141
1172
      if (p) 
1142
1173
        Setattr(p,"compactdefargs", "1"); /* mark parameters for special handling */
1173
1204
 
1174
1205
        {
1175
1206
          Node *throws = Getattr(function,"throws");
1176
 
          if (throws) Setattr(new_function,"throws",CopyParmList(throws));
 
1207
          ParmList *pl = CopyParmList(throws);
 
1208
          if (throws) Setattr(new_function,"throws",pl);
 
1209
          Delete(pl);
1177
1210
        }
1178
1211
 
1179
1212
        /* copy specific attributes for global (or in a namespace) template functions - these are not templated class methods */
1184
1217
          if (templatetype) Setattr(new_function,"templatetype",Copy(templatetype));
1185
1218
          if (symtypename) Setattr(new_function,"sym:typename",Copy(symtypename));
1186
1219
          if (templateparms) Setattr(new_function,"templateparms",CopyParmList(templateparms));
 
1220
        } else if (Strcmp(nodeType(function),"constructor") == 0) {
 
1221
          /* only copied for constructors as this is not a user defined feature - it is hard coded in the parser */
 
1222
          if (GetFlag(function,"feature:new")) SetFlag(new_function,"feature:new");
1187
1223
        }
1188
1224
 
1189
1225
        add_symbols(new_function);
1254
1290
%token <str> CHARCONST 
1255
1291
%token <dtype> NUM_INT NUM_FLOAT NUM_UNSIGNED NUM_LONG NUM_ULONG NUM_LONGLONG NUM_ULONGLONG
1256
1292
%token <ivalue> TYPEDEF
1257
 
%token <type> TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW
 
1293
%token <type> TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_WCHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_COMPLEX TYPE_TYPEDEF TYPE_RAW
1258
1294
%token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD
1259
1295
%token CONST_QUAL VOLATILE REGISTER STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET
1260
1296
%token ILLEGAL CONSTANT
1394
1430
                  if (!Swig_error_count()) {
1395
1431
                    static int last_error_line = -1;
1396
1432
                    if (last_error_line != cparse_line) {
1397
 
                      Swig_error(cparse_file, cparse_line,"Syntax error in input.\n");
 
1433
                      Swig_error(cparse_file, cparse_line,"Syntax error in input(1).\n");
1398
1434
                      last_error_line = cparse_line;
1399
1435
                      skip_decl();
1400
1436
                    }
1555
1591
                     Setattr($$,"value",$4.val);
1556
1592
                     if ($4.rawval) Setattr($$,"rawval", $4.rawval);
1557
1593
                     Setattr($$,"storage","%constant");
1558
 
                     Setattr($$,"feature:immutable","1");
 
1594
                     SetFlag($$,"feature:immutable");
1559
1595
                     add_symbols($$);
1560
1596
                   } else {
1561
1597
                     if ($4.type == T_ERROR) {
1579
1615
                   Setattr($$,"value",$4.val);
1580
1616
                   if ($4.rawval) Setattr($$,"rawval", $4.rawval);
1581
1617
                   Setattr($$,"storage","%constant");
1582
 
                   Setattr($$,"feature:immutable","1");
 
1618
                   SetFlag($$,"feature:immutable");
1583
1619
                   add_symbols($$);
1584
1620
                 } else {
1585
1621
                     if ($4.type == T_ERROR) {
1655
1691
   ------------------------------------------------------------ */
1656
1692
 
1657
1693
/* fragment keyword arguments */
1658
 
stringtype    : string LBRACE type RBRACE {              
 
1694
stringtype    : string LBRACE parm RBRACE {              
1659
1695
                 $$ = NewHash();
1660
1696
                 Setattr($$,"value",$1);
1661
 
                 Setattr($$,"type",$3);
 
1697
                 Setattr($$,"type",Getattr($3,"type"));
1662
1698
               }
1663
1699
               ;
1664
1700
 
1711
1747
                     cparse_file = Swig_copy_string($3);
1712
1748
                     cparse_line = 0;
1713
1749
               } interface RBRACKET {
 
1750
                     String *mname = 0;
1714
1751
                     $$ = $6;
1715
1752
                     cparse_file = $1.filename;
1716
1753
                     cparse_line = $1.line;
1717
1754
                     if (strcmp($1.type,"include") == 0) set_nodeType($$,"include");
1718
 
                     if (strcmp($1.type,"import") == 0) set_nodeType($$,"import");
 
1755
                     if (strcmp($1.type,"import") == 0) {
 
1756
                       mname = $2 ? Getattr($2,"module") : 0;
 
1757
                       set_nodeType($$,"import");
 
1758
                       if (import_mode) --import_mode;
 
1759
                     }
 
1760
                     
1719
1761
                     Setattr($$,"name",$3);
1720
1762
                     /* Search for the module (if any) */
1721
1763
                     {
1722
1764
                         Node *n = firstChild($$);
1723
1765
                         while (n) {
1724
1766
                             if (Strcmp(nodeType(n),"module") == 0) {
 
1767
                                 if (mname) {
 
1768
                                   Setattr(n,"name", mname);
 
1769
                                   mname = 0;
 
1770
                                 }
1725
1771
                                 Setattr($$,"module",Getattr(n,"name"));
1726
1772
                                 break;
1727
1773
                             }
1728
1774
                             n = nextSibling(n);
1729
1775
                         }
 
1776
                         if (mname) {
 
1777
                           /* There is no module node in the import
 
1778
                              node, ie, you imported a .h file
 
1779
                              directly.  We are forced then to create
 
1780
                              a new import node with a module node.
 
1781
                           */                         
 
1782
                           Node *nint = new_node("import");
 
1783
                           Node *mnode = new_node("module");
 
1784
                           Setattr(mnode,"name", mname);
 
1785
                           appendChild(nint,mnode);
 
1786
                           appendChild(nint,firstChild($$));
 
1787
                           $$ = nint;
 
1788
                           Setattr($$,"module",mname);
 
1789
                         }
1730
1790
                     }
1731
1791
                     Setattr($$,"options",$2);
1732
1792
               }
1733
1793
               ;
1734
1794
 
1735
1795
includetype    : INCLUDE { $$.type = (char *) "include"; }
1736
 
               | IMPORT  { $$.type = (char *) "import"; }
 
1796
               | IMPORT  { $$.type = (char *) "import"; ++import_mode;}
1737
1797
               ;
1738
1798
 
1739
1799
/* ------------------------------------------------------------
1823
1883
 
1824
1884
module_directive: MODULE options idstring {
1825
1885
                 $$ = new_node("module");
1826
 
                 Setattr($$,"name",$3);
1827
1886
                 if ($2) {
1828
1887
                   Setattr($$,"options",$2);
1829
1888
                   if (Getattr($2,"directors")) {
1839
1898
                   }
1840
1899
                 }
1841
1900
                 if (!ModuleName) ModuleName = NewString($3);
 
1901
                 if (!import_mode) {
 
1902
                   /* first module included, we apply global
 
1903
                      ModuleName, which can be modify by -module */
 
1904
                   Setattr($$,"name",Copy(ModuleName));
 
1905
                 } else { 
 
1906
                   /* import mode, we just pass the idstring */
 
1907
                   Setattr($$,"name",$3);   
 
1908
                 }               
1842
1909
                 if (!module_node) module_node = $$;
1843
1910
               }
1844
1911
               ;
1960
2027
                        namewarn_add(Char(fixname),decl,$3);
1961
2028
                      }
1962
2029
                    }
 
2030
                    Delete(decl);
1963
2031
                  } else if (SwigType_ispointer(t)) {
1964
2032
                    String *nname = NewStringf("*%s",fixname);
1965
2033
                    if ($1) {
2108
2176
                     } else {
2109
2177
                       Swig_feature_set(features_hash, name, decl, "feature:varargs", val, 0);
2110
2178
                     }
 
2179
                     Delete(decl);
2111
2180
                   } else if (SwigType_ispointer(t)) {
2112
2181
                     String *nname = NewStringf("*%s",name);
2113
2182
                     Swig_feature_set(features_hash,nname,0,"feature:varargs",val, 0);
2153
2222
typemap_directive :  TYPEMAP LPAREN typemap_type RPAREN tm_list stringbrace {
2154
2223
                   $$ = 0;
2155
2224
                   if ($3.op) {
 
2225
                     String *code = 0;
2156
2226
                     $$ = new_node("typemap");
2157
2227
                     Setattr($$,"method",$3.op);
2158
 
                     Setattr($$,"code",NewString($6));
2159
2228
                     if ($3.kwargs) {
 
2229
                       Parm *kw = $3.kwargs;
 
2230
                       /* check for 'noblock' option, which remove the block braces */
 
2231
                       while (kw) {
 
2232
                         String *name = Getattr(kw,"name");
 
2233
                         if (name && (Cmp(name,"noblock") == 0)) {
 
2234
                           char *cstr = Char($6);
 
2235
                           size_t len = Len($6);
 
2236
                           if (len && cstr[0] == '{') {
 
2237
                             --len; ++cstr; 
 
2238
                             if (len && cstr[len - 1] == '}') { --len; }
 
2239
                             /* we now remove the extra spaces */
 
2240
                             while (len && isspace(cstr[0])) { --len; ++cstr; }
 
2241
                             while (len && isspace(cstr[len - 1])) { --len; }
 
2242
                             code = NewStringWithSize(cstr, len);
 
2243
                           }
 
2244
                         }
 
2245
                         kw = nextSibling(kw);
 
2246
                       }
2160
2247
                       Setattr($$,"kwargs", $3.kwargs);
2161
2248
                     }
 
2249
                     Setattr($$,"code", code ? code : NewString($6));
2162
2250
                     appendChild($$,$5);
2163
2251
                   }
2164
2252
               }
2387
2475
                            String *nname = NewStringf("__dummy_%d__", cnt++);
2388
2476
                            Swig_cparse_template_expand(templnode,nname,temparms,tscope);
2389
2477
                            Setattr(templnode,"sym:name",nname);
2390
 
                            if (!Swig_template_extmode()) {
2391
 
                              Setattr(templnode,"feature:ignore","1");
2392
 
                            } else {
2393
 
                              Setattr(templnode,"feature:onlychildren",
2394
 
                                      "typemap,typemapitem,typemapcopy,typedef,types,fragment");
2395
 
                            }
 
2478
                            Setattr(templnode,"feature:onlychildren",
 
2479
                                    "typemap,typemapitem,typemapcopy,typedef,types,fragment");
2396
2480
                          }
2397
2481
                          Delattr(templnode,"templatetype");
2398
2482
                          Setattr(templnode,"template",nn);
2799
2883
                      }
2800
2884
                    }
2801
2885
                    if (err) {
2802
 
                      Swig_error(cparse_file,cparse_line,"Syntax error in input.\n");
 
2886
                      Swig_error(cparse_file,cparse_line,"Syntax error in input(2).\n");
2803
2887
                    }
2804
2888
                }
2805
2889
                ;
2974
3058
                   }
2975
3059
                   appendChild($$,dump_nested(Char(name)));
2976
3060
                 }
 
3061
 
 
3062
                 if (cplus_mode != CPLUS_PUBLIC) {
 
3063
                 /* we 'open' the class at the end, to allow %template
 
3064
                    to add new members */
 
3065
                   Node *pa = new_node("access");
 
3066
                   Setattr(pa,"kind","public");
 
3067
                   cplus_mode = CPLUS_PUBLIC;
 
3068
                   appendChild($$,pa);
 
3069
                 }
 
3070
 
2977
3071
                 Setattr($$,"symtab",Swig_symbol_popscope());
2978
3072
 
2979
3073
                 Classprefix = 0;
3240
3334
                              p1 = nextSibling(p1);
3241
3335
                            }
3242
3336
                            Setattr($$,"templateparms",tp);
 
3337
                            Delete(tp);
3243
3338
                          }
3244
3339
#if 0
3245
3340
                          /* Patch the parameter list */
3259
3354
                              p1 = nextSibling(p1);
3260
3355
                            }
3261
3356
                            Setattr($$,"templateparms",tp);
 
3357
                            Delete(tp);
3262
3358
                          } else {
3263
3359
                            Setattr($$,"templateparms",$3);
3264
3360
                          }
3322
3418
                        } else {
3323
3419
                          /* Need to resolve exact specialization name */
3324
3420
                          /* add default args from generic template */
3325
 
                          String *fname = Swig_cparse_template_deftype(tname,0);
 
3421
                          String *ty = Swig_symbol_template_deftype(tname,0);
 
3422
                          String *fname = Swig_symbol_type_qualify(ty,0);
3326
3423
                          Swig_symbol_cadd(fname,$$);
 
3424
                          Delete(ty);
 
3425
                          Delete(fname);
3327
3426
                        }
3328
3427
                      }  else if ($$) {
3329
3428
                        Setattr($$,"templatetype",nodeType($6));
3550
3649
                   {
3551
3650
                     static int last_error_line = -1;
3552
3651
                     if (last_error_line != cparse_line) {
3553
 
                       Swig_error(cparse_file, cparse_line,"Syntax error in input.\n");
 
3652
                       Swig_error(cparse_file, cparse_line,"Syntax error in input(3).\n");
3554
3653
                       last_error_line = cparse_line;
3555
3654
                     }
3556
3655
                   }
3618
3717
                 if (Len(scanner_ccode)) {
3619
3718
                   Setattr($$,"code",Copy(scanner_ccode));
3620
3719
                 }
3621
 
                 Setattr($$,"feature:new","1");
 
3720
                 SetFlag($$,"feature:new");
3622
3721
              } else {
3623
3722
                $$ = 0;
3624
3723
              }
3839
3938
                  Swig_warning(WARN_PARSE_NESTED_CLASS,cparse_file, cparse_line,"Nested class not currently supported (ignored)\n");
3840
3939
                }
3841
3940
              }
 
3941
/*
 
3942
              | TEMPLATE LESSTHAN template_parms GREATERTHAN cpptype idcolon LBRACE { cparse_start_line = cparse_line; skip_balanced('{','}');
 
3943
              } SEMI {
 
3944
                $$ = 0;
 
3945
                if (cplus_mode == CPLUS_PUBLIC) {
 
3946
                  Swig_warning(WARN_PARSE_NESTED_CLASS,cparse_file, cparse_line,"Nested class not currently supported (ignored)\n");
 
3947
                }
 
3948
              }
 
3949
*/
3842
3950
              ;
3843
3951
 
3844
3952
nested_decl   : declarator { $$ = $1;}
4748
4856
                    $$.type = NewString("char");
4749
4857
                    $$.us = 0;
4750
4858
                }
 
4859
               | TYPE_WCHAR { 
 
4860
                    $$.type = NewString("wchar_t");
 
4861
                    $$.us = 0;
 
4862
                }
4751
4863
               | TYPE_FLOAT { 
4752
4864
                    $$.type = NewString("float");
4753
4865
                    $$.us = 0;
4838
4950
                   $$ = new_node("enumitem");
4839
4951
                   Setattr($$,"name",$1);
4840
4952
                   Setattr($$,"type",NewSwigType(T_INT));
4841
 
                   Setattr($$,"feature:immutable","1");
 
4953
                   SetFlag($$,"feature:immutable");
4842
4954
                 }
4843
4955
                 | ID EQUAL etype {
4844
4956
                   $$ = new_node("enumitem");
4851
4963
                     Setattr($$,"value",$1);
4852
4964
                     Setattr($$,"type",NewSwigType(T_INT));
4853
4965
                   }
4854
 
                   Setattr($$,"feature:immutable","1");
 
4966
                   SetFlag($$,"feature:immutable");
4855
4967
                 }
4856
4968
                 | empty { $$ = 0; }
4857
4969
                 ;