Mercurial > hg > CbC > old > device
comparison mc-parse.c @ 873:509a394c5ff9
temp4 passed.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Apr 2014 18:02:03 +0900 |
parents | 11abda130b91 |
children | 3454953b3df0 |
comparison
equal
deleted
inserted
replaced
872:11abda130b91 | 873:509a394c5ff9 |
---|---|
1556 */ | 1556 */ |
1557 | 1557 |
1558 #define LOCAL_STRUCT_INIT_STATIC 1 | 1558 #define LOCAL_STRUCT_INIT_STATIC 1 |
1559 | 1559 |
1560 static int | 1560 static int |
1561 decl_data_1(int type0,int v,int offset) | |
1562 { | |
1563 // casted initializer (sturct hoge){.a=3,.b=c,...} | |
1564 | |
1565 getsym(0); | |
1566 if (sym==LPAR) { | |
1567 offset = decl_data_1(type,v,offset); | |
1568 checksym(RPAR); | |
1569 } else if (typeid(sym)) { | |
1570 int t = typename(); | |
1571 checksym(RPAR); | |
1572 offset = decl_data(t,v,offset,1); | |
1573 if (inmode) | |
1574 offset = list4(CAST,offset,t,type); | |
1575 } else { | |
1576 return 0; | |
1577 } | |
1578 return offset; | |
1579 } | |
1580 | |
1581 static int | |
1582 decl_data_field(int type1,int v,int offset) | 1561 decl_data_field(int type1,int v,int offset) |
1583 { | 1562 { |
1584 int t1,t2,period=0; | 1563 int t1,t2,period=0; |
1585 int foffset; | 1564 int foffset; |
1586 // int offset0 = offset+size(type); | 1565 // int offset0 = offset+size(type); |
1594 } | 1573 } |
1595 t1 = caddr(type0); /* list of fields */ | 1574 t1 = caddr(type0); /* list of fields */ |
1596 if (sym==LC) { | 1575 if (sym==LC) { |
1597 mode = STAT; | 1576 mode = STAT; |
1598 getsym(0); | 1577 getsym(0); |
1599 } else if (sym==LPAR) { | 1578 } else if (sym != PERIOD ) { |
1600 // have to be a value, no comma cascading values | 1579 // have to be a value, no comma cascading values |
1601 // .__tcp_lhash_lock = (rwlock_t) { }, | 1580 int mode_save = mode; |
1602 // We cannot distinguish this case and cascading comma here. | 1581 int stype = type; |
1603 // Do it more upper syntactical node; | 1582 mode=STAT; |
1604 if (inmode) { | 1583 int e=expr1(); |
1605 int offset1=decl_data_1(car(t1),v,0); | 1584 mode = mode_save; |
1606 offset1 = reverse0(offset1); | 1585 int t2 = type; |
1607 offset=list3(DECL_DATA,offset1,car(t1)); | 1586 type = stype; |
1608 } else { | 1587 if (size(t2)==size(type0)) { |
1609 offset=decl_data_1(car(t1),v,offset); | 1588 // direct assingn case , including (struct hoge){ ... } |
1610 if (!offset) checksym(RPAR); | 1589 if (inmode) { |
1611 } | 1590 offset = list3(DECL_DATA,e,type0); |
1612 return offset; | 1591 return offset; |
1613 } else { | 1592 } |
1614 int mode_save = mode; | 1593 offset = assign_data(e,type0,v,offset); |
1615 int stype = type; | 1594 return offset; |
1616 mode=STAT; | 1595 } |
1617 int e=expr1(); | 1596 // missing brace case |
1618 mode = mode_save; | 1597 error(SIERR); |
1619 type = stype; | 1598 if (inmode) { |
1620 if (inmode) { | 1599 offset = list3(DECL_DATA,e,car(t1)); |
1621 offset = list3(DECL_DATA,e,car(t1)); | 1600 return offset; |
1622 return offset; | 1601 } |
1623 } | 1602 offset = assign_data(e,car(t1),v,offset); |
1624 offset = assign_data(e,car(t1),v,offset); | 1603 t1 = cadr(t1); |
1625 return offset; | 1604 if (! ( t1 && sym==COMMA)) return offset; |
1605 conv->comma_(); getsym(0); // fall thru | |
1626 } | 1606 } |
1627 mode=SFDINIT; | 1607 mode=SFDINIT; |
1628 while(1) { | 1608 while(1) { |
1629 if (sym==PERIOD) { /* struct/union field initializaer */ | 1609 if (sym==PERIOD) { /* struct/union field initializaer */ |
1630 period=1; | 1610 period=1; |
1889 local_struct_static(v); | 1869 local_struct_static(v); |
1890 // change mode to STADECL | 1870 // change mode to STADECL |
1891 // decl_data_field(t,n,offset) is called inside; | 1871 // decl_data_field(t,n,offset) is called inside; |
1892 } else | 1872 } else |
1893 #endif | 1873 #endif |
1874 // we cannot handle direct struct assign ( struct hoge a = f(); ) here, because of missing brace case | |
1894 if (inmode) { | 1875 if (inmode) { |
1895 int offset1=decl_data_field(t,v,0); | 1876 int offset1=decl_data_field(t,v,0); |
1896 offset1 = reverse0(offset1); | 1877 offset1 = reverse0(offset1); |
1897 offset=list3(DECL_DATA,offset1,t); | 1878 offset=list3(DECL_DATA,offset1,t); |
1898 } else { | 1879 } else { |