diff options
author | Mark Spruiell <mes@zeroc.com> | 2010-07-23 16:02:04 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2010-07-23 16:02:04 -0700 |
commit | 2414545a397baa35e90fbc04c807b2b96ed7cc93 (patch) | |
tree | 271b74750e65d3eb64ef39299b14658b420eb6d9 /cpp | |
parent | Bug-fix for 4793. As well as some refactoring. (diff) | |
download | ice-2414545a397baa35e90fbc04c807b2b96ed7cc93.tar.bz2 ice-2414545a397baa35e90fbc04c807b2b96ed7cc93.tar.xz ice-2414545a397baa35e90fbc04c807b2b96ed7cc93.zip |
bug 4794 - allow default values to refer to constants
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Slice/Parser.h | 13 | ||||
-rw-r--r-- | cpp/src/Slice/Grammar.cpp | 424 | ||||
-rw-r--r-- | cpp/src/Slice/Grammar.y | 48 | ||||
-rwxr-xr-x | cpp/src/Slice/Parser.cpp | 152 | ||||
-rwxr-xr-x | cpp/src/Slice/PythonUtil.cpp | 243 | ||||
-rwxr-xr-x | cpp/src/Slice/RubyUtil.cpp | 243 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 107 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 104 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.h | 2 | ||||
-rw-r--r-- | cpp/src/slice2java/Gen.cpp | 181 | ||||
-rw-r--r-- | cpp/src/slice2java/Gen.h | 3 | ||||
-rw-r--r-- | cpp/src/slice2php/Main.cpp | 267 | ||||
-rw-r--r-- | cpp/test/Ice/defaultValue/AllTests.cpp | 15 | ||||
-rw-r--r-- | cpp/test/Ice/defaultValue/Test.ice | 25 | ||||
-rw-r--r-- | cpp/test/Slice/errorDetection/ConstDef.err | 3 | ||||
-rw-r--r-- | cpp/test/Slice/errorDetection/ConstDef.ice | 18 |
16 files changed, 1022 insertions, 826 deletions
diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index ad390b12b4e..df5a7dca024 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -857,6 +857,7 @@ public: TypePtr type() const; StringList typeMetaData() const; + SyntaxTreeBasePtr valueType() const; std::string value() const; std::string literal() const; virtual bool uses(const ContainedPtr&) const; @@ -866,12 +867,13 @@ public: protected: - Const(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, const std::string&, - const std::string&); + Const(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, const SyntaxTreeBasePtr&, + const std::string&, const std::string&); friend class Container; TypePtr _type; StringList _typeMetaData; + SyntaxTreeBasePtr _valueType; std::string _value; std::string _literal; }; @@ -909,9 +911,9 @@ class SLICE_API DataMember : virtual public Contained public: TypePtr type() const; - bool hasDefaultValue() const; std::string defaultValue() const; std::string defaultLiteral() const; + SyntaxTreeBasePtr defaultValueType() const; virtual ContainedType containedType() const; virtual bool uses(const ContainedPtr&) const; virtual std::string kindOf() const; @@ -919,13 +921,14 @@ public: protected: - DataMember(const ContainerPtr&, const std::string&, const TypePtr&, bool, const std::string&, const std::string&); + DataMember(const ContainerPtr&, const std::string&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&, + const std::string&); friend class ClassDef; friend class Struct; friend class Exception; TypePtr _type; - bool _hasDefaultValue; + SyntaxTreeBasePtr _defaultValueType; std::string _defaultValue; std::string _defaultLiteral; }; diff --git a/cpp/src/Slice/Grammar.cpp b/cpp/src/Slice/Grammar.cpp index de92ef06589..66faa07f532 100644 --- a/cpp/src/Slice/Grammar.cpp +++ b/cpp/src/Slice/Grammar.cpp @@ -162,7 +162,7 @@ /* Copy the first part of user declarations. */ -#line 1 "../Slice/Grammar.y" +#line 1 "Grammar.y" // ********************************************************************** @@ -599,19 +599,19 @@ static const yytype_uint16 yyrline[] = 265, 276, 287, 286, 313, 322, 330, 339, 342, 347, 354, 367, 373, 377, 388, 399, 398, 434, 443, 446, 451, 458, 464, 468, 479, 493, 492, 532, 567, 575, - 580, 588, 597, 600, 605, 612, 635, 662, 684, 710, - 711, 720, 744, 768, 792, 822, 821, 844, 843, 866, - 867, 873, 877, 888, 903, 902, 937, 972, 1007, 1017, - 1022, 1030, 1039, 1042, 1047, 1054, 1060, 1067, 1079, 1091, - 1102, 1111, 1126, 1137, 1154, 1158, 1170, 1169, 1193, 1208, - 1214, 1222, 1234, 1242, 1251, 1258, 1269, 1271, 1289, 1307, - 1319, 1331, 1342, 1358, 1363, 1371, 1374, 1380, 1393, 1397, - 1401, 1405, 1409, 1413, 1417, 1421, 1425, 1429, 1433, 1437, - 1456, 1497, 1503, 1511, 1518, 1530, 1537, 1547, 1560, 1573, - 1608, 1619, 1630, 1646, 1655, 1670, 1673, 1676, 1679, 1682, - 1685, 1688, 1691, 1694, 1697, 1700, 1703, 1706, 1709, 1712, - 1715, 1718, 1721, 1724, 1727, 1730, 1733, 1736, 1739, 1742, - 1745, 1748, 1751 + 580, 588, 597, 600, 605, 612, 635, 660, 682, 708, + 709, 718, 742, 766, 790, 820, 819, 842, 841, 864, + 865, 871, 875, 886, 901, 900, 935, 970, 1005, 1015, + 1020, 1028, 1037, 1040, 1045, 1052, 1058, 1065, 1077, 1089, + 1100, 1109, 1124, 1135, 1152, 1156, 1168, 1167, 1191, 1206, + 1212, 1220, 1232, 1240, 1249, 1256, 1267, 1269, 1287, 1305, + 1317, 1329, 1340, 1356, 1361, 1369, 1372, 1378, 1391, 1395, + 1399, 1403, 1407, 1411, 1415, 1419, 1423, 1427, 1431, 1435, + 1454, 1495, 1501, 1509, 1516, 1528, 1535, 1545, 1558, 1571, + 1617, 1628, 1639, 1655, 1664, 1678, 1681, 1684, 1687, 1690, + 1693, 1696, 1699, 1702, 1705, 1708, 1711, 1714, 1717, 1720, + 1723, 1726, 1729, 1732, 1735, 1738, 1741, 1744, 1747, 1750, + 1753, 1756, 1759 }; #endif @@ -1821,34 +1821,34 @@ yyreduce: switch (yyn) { case 2: -#line 105 "../Slice/Grammar.y" +#line 105 "Grammar.y" { ;} break; case 3: -#line 113 "../Slice/Grammar.y" +#line 113 "Grammar.y" { (yyval) = (yyvsp[(2) - (3)]); ;} break; case 4: -#line 122 "../Slice/Grammar.y" +#line 122 "Grammar.y" { (yyval) = (yyvsp[(2) - (3)]); ;} break; case 5: -#line 126 "../Slice/Grammar.y" +#line 126 "Grammar.y" { (yyval) = new StringListTok; ;} break; case 6: -#line 135 "../Slice/Grammar.y" +#line 135 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (1)])); if(!metaData->v.empty()) @@ -1859,7 +1859,7 @@ yyreduce: break; case 8: -#line 144 "../Slice/Grammar.y" +#line 144 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (2)])); ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -1871,118 +1871,118 @@ yyreduce: break; case 10: -#line 154 "../Slice/Grammar.y" +#line 154 "Grammar.y" { yyerrok; ;} break; case 12: -#line 159 "../Slice/Grammar.y" +#line 159 "Grammar.y" { unit->error("`;' missing after definition"); ;} break; case 13: -#line 163 "../Slice/Grammar.y" +#line 163 "Grammar.y" { ;} break; case 14: -#line 171 "../Slice/Grammar.y" +#line 171 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ModulePtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 15: -#line 175 "../Slice/Grammar.y" +#line 175 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ClassDeclPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 16: -#line 179 "../Slice/Grammar.y" +#line 179 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ClassDefPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 17: -#line 183 "../Slice/Grammar.y" +#line 183 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ClassDeclPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 18: -#line 187 "../Slice/Grammar.y" +#line 187 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ClassDefPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 19: -#line 191 "../Slice/Grammar.y" +#line 191 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0); ;} break; case 20: -#line 195 "../Slice/Grammar.y" +#line 195 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ExceptionPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 21: -#line 199 "../Slice/Grammar.y" +#line 199 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0); ;} break; case 22: -#line 203 "../Slice/Grammar.y" +#line 203 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || StructPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 23: -#line 207 "../Slice/Grammar.y" +#line 207 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || SequencePtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 24: -#line 211 "../Slice/Grammar.y" +#line 211 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || DictionaryPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 25: -#line 215 "../Slice/Grammar.y" +#line 215 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || EnumPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 26: -#line 219 "../Slice/Grammar.y" +#line 219 "Grammar.y" { assert((yyvsp[(1) - (1)]) == 0 || ConstPtr::dynamicCast((yyvsp[(1) - (1)]))); ;} break; case 27: -#line 228 "../Slice/Grammar.y" +#line 228 "Grammar.y" { unit->setSeenDefinition(); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -2002,7 +2002,7 @@ yyreduce: break; case 28: -#line 245 "../Slice/Grammar.y" +#line 245 "Grammar.y" { if((yyvsp[(3) - (6)])) { @@ -2017,14 +2017,14 @@ yyreduce: break; case 29: -#line 262 "../Slice/Grammar.y" +#line 262 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 30: -#line 266 "../Slice/Grammar.y" +#line 266 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); unit->error("keyword `" + ident->v + "' cannot be used as exception name"); @@ -2033,7 +2033,7 @@ yyreduce: break; case 31: -#line 277 "../Slice/Grammar.y" +#line 277 "Grammar.y" { unit->error("exceptions cannot be forward declared"); (yyval) = 0; @@ -2041,7 +2041,7 @@ yyreduce: break; case 32: -#line 287 "../Slice/Grammar.y" +#line 287 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (3)])); @@ -2058,7 +2058,7 @@ yyreduce: break; case 33: -#line 301 "../Slice/Grammar.y" +#line 301 "Grammar.y" { if((yyvsp[(4) - (7)])) { @@ -2069,7 +2069,7 @@ yyreduce: break; case 34: -#line 314 "../Slice/Grammar.y" +#line 314 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); ContainerPtr cont = unit->currentContainer(); @@ -2080,14 +2080,14 @@ yyreduce: break; case 35: -#line 322 "../Slice/Grammar.y" +#line 322 "Grammar.y" { (yyval) = 0; ;} break; case 36: -#line 331 "../Slice/Grammar.y" +#line 331 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); @@ -2099,26 +2099,26 @@ yyreduce: break; case 37: -#line 340 "../Slice/Grammar.y" +#line 340 "Grammar.y" { ;} break; case 38: -#line 343 "../Slice/Grammar.y" +#line 343 "Grammar.y" { unit->error("`;' missing after definition"); ;} break; case 39: -#line 347 "../Slice/Grammar.y" +#line 347 "Grammar.y" { ;} break; case 40: -#line 355 "../Slice/Grammar.y" +#line 355 "Grammar.y" { TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (2)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -2129,14 +2129,14 @@ yyreduce: break; case 42: -#line 374 "../Slice/Grammar.y" +#line 374 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 43: -#line 378 "../Slice/Grammar.y" +#line 378 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); unit->error("keyword `" + ident->v + "' cannot be used as struct name"); @@ -2145,7 +2145,7 @@ yyreduce: break; case 44: -#line 389 "../Slice/Grammar.y" +#line 389 "Grammar.y" { unit->error("structs cannot be forward declared"); (yyval) = 0; // Dummy @@ -2153,7 +2153,7 @@ yyreduce: break; case 45: -#line 399 "../Slice/Grammar.y" +#line 399 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -2169,7 +2169,7 @@ yyreduce: break; case 46: -#line 412 "../Slice/Grammar.y" +#line 412 "Grammar.y" { if((yyvsp[(3) - (6)])) { @@ -2190,7 +2190,7 @@ yyreduce: break; case 47: -#line 435 "../Slice/Grammar.y" +#line 435 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); @@ -2202,33 +2202,33 @@ yyreduce: break; case 48: -#line 444 "../Slice/Grammar.y" +#line 444 "Grammar.y" { ;} break; case 49: -#line 447 "../Slice/Grammar.y" +#line 447 "Grammar.y" { unit->error("`;' missing after definition"); ;} break; case 50: -#line 451 "../Slice/Grammar.y" +#line 451 "Grammar.y" { ;} break; case 52: -#line 465 "../Slice/Grammar.y" +#line 465 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 53: -#line 469 "../Slice/Grammar.y" +#line 469 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); unit->error("keyword `" + ident->v + "' cannot be used as class name"); @@ -2237,7 +2237,7 @@ yyreduce: break; case 54: -#line 480 "../Slice/Grammar.y" +#line 480 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -2248,7 +2248,7 @@ yyreduce: break; case 55: -#line 493 "../Slice/Grammar.y" +#line 493 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (4)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (4)])); @@ -2274,7 +2274,7 @@ yyreduce: break; case 56: -#line 516 "../Slice/Grammar.y" +#line 516 "Grammar.y" { if((yyvsp[(5) - (8)])) { @@ -2289,7 +2289,7 @@ yyreduce: break; case 57: -#line 533 "../Slice/Grammar.y" +#line 533 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); ContainerPtr cont = unit->currentContainer(); @@ -2326,28 +2326,28 @@ yyreduce: break; case 58: -#line 567 "../Slice/Grammar.y" +#line 567 "Grammar.y" { (yyval) = 0; ;} break; case 59: -#line 576 "../Slice/Grammar.y" +#line 576 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 60: -#line 580 "../Slice/Grammar.y" +#line 580 "Grammar.y" { (yyval) = new ClassListTok; ;} break; case 61: -#line 589 "../Slice/Grammar.y" +#line 589 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); @@ -2359,26 +2359,26 @@ yyreduce: break; case 62: -#line 598 "../Slice/Grammar.y" +#line 598 "Grammar.y" { ;} break; case 63: -#line 601 "../Slice/Grammar.y" +#line 601 "Grammar.y" { unit->error("`;' missing after definition"); ;} break; case 64: -#line 605 "../Slice/Grammar.y" +#line 605 "Grammar.y" { ;} break; case 65: -#line 613 "../Slice/Grammar.y" +#line 613 "Grammar.y" { TypePtr type = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (1)]))->v.first; string name = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (1)]))->v.second; @@ -2404,29 +2404,27 @@ yyreduce: break; case 66: -#line 636 "../Slice/Grammar.y" +#line 636 "Grammar.y" { TypePtr type = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (3)]))->v.first; string name = TypeStringTokPtr::dynamicCast((yyvsp[(1) - (3)]))->v.second; ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(3) - (3)])); - SyntaxTreeBasePtr defaultLiteralType = value->v.value; - string defaultValue = value->v.valueAsString; - string defaultLiteral = value->v.valueAsLiteral; + ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); DataMemberPtr dm; if(cl) { - dm = cl->createDataMember(name, type, defaultLiteralType, defaultValue, defaultLiteral); + dm = cl->createDataMember(name, type, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); } StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); if(st) { - dm = st->createDataMember(name, type, defaultLiteralType, defaultValue, defaultLiteral); + dm = st->createDataMember(name, type, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); } ExceptionPtr ex = ExceptionPtr::dynamicCast(unit->currentContainer()); if(ex) { - dm = ex->createDataMember(name, type, defaultLiteralType, defaultValue, defaultLiteral); + dm = ex->createDataMember(name, type, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); } unit->currentContainer()->checkIntroduced(name, dm); (yyval) = dm; @@ -2434,7 +2432,7 @@ yyreduce: break; case 67: -#line 663 "../Slice/Grammar.y" +#line 661 "Grammar.y" { TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (2)])); string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; @@ -2459,7 +2457,7 @@ yyreduce: break; case 68: -#line 685 "../Slice/Grammar.y" +#line 683 "Grammar.y" { TypePtr type = TypePtr::dynamicCast((yyvsp[(1) - (1)])); ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); @@ -2483,14 +2481,14 @@ yyreduce: break; case 70: -#line 712 "../Slice/Grammar.y" +#line 710 "Grammar.y" { (yyval) = 0; ;} break; case 71: -#line 721 "../Slice/Grammar.y" +#line 719 "Grammar.y" { TypePtr returnType = TypePtr::dynamicCast((yyvsp[(1) - (2)])); string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; @@ -2517,7 +2515,7 @@ yyreduce: break; case 72: -#line 745 "../Slice/Grammar.y" +#line 743 "Grammar.y" { TypePtr returnType = TypePtr::dynamicCast((yyvsp[(2) - (3)])); string name = StringTokPtr::dynamicCast((yyvsp[(3) - (3)]))->v; @@ -2544,7 +2542,7 @@ yyreduce: break; case 73: -#line 769 "../Slice/Grammar.y" +#line 767 "Grammar.y" { TypePtr returnType = TypePtr::dynamicCast((yyvsp[(1) - (2)])); string name = StringTokPtr::dynamicCast((yyvsp[(2) - (2)]))->v; @@ -2571,7 +2569,7 @@ yyreduce: break; case 74: -#line 793 "../Slice/Grammar.y" +#line 791 "Grammar.y" { TypePtr returnType = TypePtr::dynamicCast((yyvsp[(2) - (3)])); string name = StringTokPtr::dynamicCast((yyvsp[(3) - (3)]))->v; @@ -2598,7 +2596,7 @@ yyreduce: break; case 75: -#line 822 "../Slice/Grammar.y" +#line 820 "Grammar.y" { if((yyvsp[(1) - (3)])) { @@ -2613,7 +2611,7 @@ yyreduce: break; case 76: -#line 834 "../Slice/Grammar.y" +#line 832 "Grammar.y" { OperationPtr op = OperationPtr::dynamicCast((yyvsp[(4) - (5)])); ExceptionListTokPtr el = ExceptionListTokPtr::dynamicCast((yyvsp[(5) - (5)])); @@ -2626,7 +2624,7 @@ yyreduce: break; case 77: -#line 844 "../Slice/Grammar.y" +#line 842 "Grammar.y" { if((yyvsp[(1) - (3)])) { @@ -2637,7 +2635,7 @@ yyreduce: break; case 78: -#line 852 "../Slice/Grammar.y" +#line 850 "Grammar.y" { OperationPtr op = OperationPtr::dynamicCast((yyvsp[(4) - (5)])); ExceptionListTokPtr el = ExceptionListTokPtr::dynamicCast((yyvsp[(5) - (5)])); @@ -2650,14 +2648,14 @@ yyreduce: break; case 81: -#line 874 "../Slice/Grammar.y" +#line 872 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 82: -#line 878 "../Slice/Grammar.y" +#line 876 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); unit->error("keyword `" + ident->v + "' cannot be used as interface name"); @@ -2666,7 +2664,7 @@ yyreduce: break; case 83: -#line 889 "../Slice/Grammar.y" +#line 887 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -2678,7 +2676,7 @@ yyreduce: break; case 84: -#line 903 "../Slice/Grammar.y" +#line 901 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (3)])); @@ -2699,7 +2697,7 @@ yyreduce: break; case 85: -#line 921 "../Slice/Grammar.y" +#line 919 "Grammar.y" { if((yyvsp[(4) - (7)])) { @@ -2714,7 +2712,7 @@ yyreduce: break; case 86: -#line 938 "../Slice/Grammar.y" +#line 936 "Grammar.y" { ClassListTokPtr intfs = ClassListTokPtr::dynamicCast((yyvsp[(3) - (3)])); StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (3)])); @@ -2752,7 +2750,7 @@ yyreduce: break; case 87: -#line 973 "../Slice/Grammar.y" +#line 971 "Grammar.y" { ClassListTokPtr intfs = new ClassListTok; StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); @@ -2790,7 +2788,7 @@ yyreduce: break; case 88: -#line 1008 "../Slice/Grammar.y" +#line 1006 "Grammar.y" { unit->error("illegal inheritance from type Object"); (yyval) = new ClassListTok; // Dummy @@ -2798,21 +2796,21 @@ yyreduce: break; case 89: -#line 1018 "../Slice/Grammar.y" +#line 1016 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 90: -#line 1022 "../Slice/Grammar.y" +#line 1020 "Grammar.y" { (yyval) = new ClassListTok; ;} break; case 91: -#line 1031 "../Slice/Grammar.y" +#line 1029 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(1) - (4)])); ContainedPtr contained = ContainedPtr::dynamicCast((yyvsp[(2) - (4)])); @@ -2824,26 +2822,26 @@ yyreduce: break; case 92: -#line 1040 "../Slice/Grammar.y" +#line 1038 "Grammar.y" { ;} break; case 93: -#line 1043 "../Slice/Grammar.y" +#line 1041 "Grammar.y" { unit->error("`;' missing after definition"); ;} break; case 94: -#line 1047 "../Slice/Grammar.y" +#line 1045 "Grammar.y" { ;} break; case 96: -#line 1061 "../Slice/Grammar.y" +#line 1059 "Grammar.y" { ExceptionPtr exception = ExceptionPtr::dynamicCast((yyvsp[(1) - (3)])); ExceptionListTokPtr exceptionList = ExceptionListTokPtr::dynamicCast((yyvsp[(3) - (3)])); @@ -2853,7 +2851,7 @@ yyreduce: break; case 97: -#line 1068 "../Slice/Grammar.y" +#line 1066 "Grammar.y" { ExceptionPtr exception = ExceptionPtr::dynamicCast((yyvsp[(1) - (1)])); ExceptionListTokPtr exceptionList = new ExceptionListTok; @@ -2863,7 +2861,7 @@ yyreduce: break; case 98: -#line 1080 "../Slice/Grammar.y" +#line 1078 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); ContainerPtr cont = unit->currentContainer(); @@ -2878,7 +2876,7 @@ yyreduce: break; case 99: -#line 1092 "../Slice/Grammar.y" +#line 1090 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); unit->error("keyword `" + ident->v + "' cannot be used as exception name"); @@ -2887,7 +2885,7 @@ yyreduce: break; case 100: -#line 1103 "../Slice/Grammar.y" +#line 1101 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (7)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(7) - (7)])); @@ -2899,7 +2897,7 @@ yyreduce: break; case 101: -#line 1112 "../Slice/Grammar.y" +#line 1110 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (7)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(7) - (7)])); @@ -2912,7 +2910,7 @@ yyreduce: break; case 102: -#line 1127 "../Slice/Grammar.y" +#line 1125 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (10)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(10) - (10)])); @@ -2926,7 +2924,7 @@ yyreduce: break; case 103: -#line 1138 "../Slice/Grammar.y" +#line 1136 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (10)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(10) - (10)])); @@ -2941,14 +2939,14 @@ yyreduce: break; case 104: -#line 1155 "../Slice/Grammar.y" +#line 1153 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 105: -#line 1159 "../Slice/Grammar.y" +#line 1157 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); unit->error("keyword `" + ident->v + "' cannot be used as enumeration name"); @@ -2957,7 +2955,7 @@ yyreduce: break; case 106: -#line 1170 "../Slice/Grammar.y" +#line 1168 "Grammar.y" { BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (2)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -2969,7 +2967,7 @@ yyreduce: break; case 107: -#line 1179 "../Slice/Grammar.y" +#line 1177 "Grammar.y" { EnumPtr en = EnumPtr::dynamicCast((yyvsp[(3) - (6)])); if(en) @@ -2986,7 +2984,7 @@ yyreduce: break; case 108: -#line 1194 "../Slice/Grammar.y" +#line 1192 "Grammar.y" { unit->error("missing enumeration name"); BoolTokPtr local = BoolTokPtr::dynamicCast((yyvsp[(1) - (5)])); @@ -2999,7 +2997,7 @@ yyreduce: break; case 109: -#line 1209 "../Slice/Grammar.y" +#line 1207 "Grammar.y" { EnumeratorListTokPtr ens = EnumeratorListTokPtr::dynamicCast((yyvsp[(1) - (3)])); ens->v.splice(ens->v.end(), EnumeratorListTokPtr::dynamicCast((yyvsp[(3) - (3)]))->v); @@ -3008,13 +3006,13 @@ yyreduce: break; case 110: -#line 1215 "../Slice/Grammar.y" +#line 1213 "Grammar.y" { ;} break; case 111: -#line 1223 "../Slice/Grammar.y" +#line 1221 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); EnumeratorListTokPtr ens = new EnumeratorListTok; @@ -3029,7 +3027,7 @@ yyreduce: break; case 112: -#line 1235 "../Slice/Grammar.y" +#line 1233 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); unit->error("keyword `" + ident->v + "' cannot be used as enumerator"); @@ -3039,7 +3037,7 @@ yyreduce: break; case 113: -#line 1242 "../Slice/Grammar.y" +#line 1240 "Grammar.y" { EnumeratorListTokPtr ens = new EnumeratorListTok; (yyval) = ens; // Dummy @@ -3047,7 +3045,7 @@ yyreduce: break; case 114: -#line 1252 "../Slice/Grammar.y" +#line 1250 "Grammar.y" { BoolTokPtr out = new BoolTok; out->v = true; @@ -3056,7 +3054,7 @@ yyreduce: break; case 115: -#line 1258 "../Slice/Grammar.y" +#line 1256 "Grammar.y" { BoolTokPtr out = new BoolTok; out->v = false; @@ -3065,13 +3063,13 @@ yyreduce: break; case 116: -#line 1269 "../Slice/Grammar.y" +#line 1267 "Grammar.y" { ;} break; case 117: -#line 1272 "../Slice/Grammar.y" +#line 1270 "Grammar.y" { BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); TypeStringTokPtr tsp = TypeStringTokPtr::dynamicCast((yyvsp[(3) - (3)])); @@ -3092,7 +3090,7 @@ yyreduce: break; case 118: -#line 1290 "../Slice/Grammar.y" +#line 1288 "Grammar.y" { BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(3) - (5)])); TypeStringTokPtr tsp = TypeStringTokPtr::dynamicCast((yyvsp[(5) - (5)])); @@ -3113,7 +3111,7 @@ yyreduce: break; case 119: -#line 1308 "../Slice/Grammar.y" +#line 1306 "Grammar.y" { BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(1) - (4)])); TypePtr type = TypePtr::dynamicCast((yyvsp[(3) - (4)])); @@ -3128,7 +3126,7 @@ yyreduce: break; case 120: -#line 1320 "../Slice/Grammar.y" +#line 1318 "Grammar.y" { BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(3) - (6)])); TypePtr type = TypePtr::dynamicCast((yyvsp[(5) - (6)])); @@ -3143,7 +3141,7 @@ yyreduce: break; case 121: -#line 1332 "../Slice/Grammar.y" +#line 1330 "Grammar.y" { BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(1) - (3)])); TypePtr type = TypePtr::dynamicCast((yyvsp[(3) - (3)])); @@ -3157,7 +3155,7 @@ yyreduce: break; case 122: -#line 1343 "../Slice/Grammar.y" +#line 1341 "Grammar.y" { BoolTokPtr isOutParam = BoolTokPtr::dynamicCast((yyvsp[(3) - (5)])); TypePtr type = TypePtr::dynamicCast((yyvsp[(5) - (5)])); @@ -3171,27 +3169,27 @@ yyreduce: break; case 123: -#line 1359 "../Slice/Grammar.y" +#line 1357 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); ;} break; case 124: -#line 1363 "../Slice/Grammar.y" +#line 1361 "Grammar.y" { (yyval) = new ExceptionListTok; ;} break; case 125: -#line 1372 "../Slice/Grammar.y" +#line 1370 "Grammar.y" { ;} break; case 126: -#line 1375 "../Slice/Grammar.y" +#line 1373 "Grammar.y" { StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); ident->v = "::" + ident->v; @@ -3200,7 +3198,7 @@ yyreduce: break; case 127: -#line 1381 "../Slice/Grammar.y" +#line 1379 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (3)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(3) - (3)])); @@ -3211,84 +3209,84 @@ yyreduce: break; case 128: -#line 1394 "../Slice/Grammar.y" +#line 1392 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindByte); ;} break; case 129: -#line 1398 "../Slice/Grammar.y" +#line 1396 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindBool); ;} break; case 130: -#line 1402 "../Slice/Grammar.y" +#line 1400 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindShort); ;} break; case 131: -#line 1406 "../Slice/Grammar.y" +#line 1404 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindInt); ;} break; case 132: -#line 1410 "../Slice/Grammar.y" +#line 1408 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindLong); ;} break; case 133: -#line 1414 "../Slice/Grammar.y" +#line 1412 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindFloat); ;} break; case 134: -#line 1418 "../Slice/Grammar.y" +#line 1416 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindDouble); ;} break; case 135: -#line 1422 "../Slice/Grammar.y" +#line 1420 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindString); ;} break; case 136: -#line 1426 "../Slice/Grammar.y" +#line 1424 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindObject); ;} break; case 137: -#line 1430 "../Slice/Grammar.y" +#line 1428 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindObjectProxy); ;} break; case 138: -#line 1434 "../Slice/Grammar.y" +#line 1432 "Grammar.y" { (yyval) = unit->builtin(Builtin::KindLocalObject); ;} break; case 139: -#line 1438 "../Slice/Grammar.y" +#line 1436 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); ContainerPtr cont = unit->currentContainer(); @@ -3310,7 +3308,7 @@ yyreduce: break; case 140: -#line 1457 "../Slice/Grammar.y" +#line 1455 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (2)])); ContainerPtr cont = unit->currentContainer(); @@ -3349,7 +3347,7 @@ yyreduce: break; case 141: -#line 1498 "../Slice/Grammar.y" +#line 1496 "Grammar.y" { StringTokPtr str1 = StringTokPtr::dynamicCast((yyvsp[(1) - (2)])); StringTokPtr str2 = StringTokPtr::dynamicCast((yyvsp[(2) - (2)])); @@ -3358,13 +3356,13 @@ yyreduce: break; case 142: -#line 1504 "../Slice/Grammar.y" +#line 1502 "Grammar.y" { ;} break; case 143: -#line 1512 "../Slice/Grammar.y" +#line 1510 "Grammar.y" { StringTokPtr str = StringTokPtr::dynamicCast((yyvsp[(3) - (3)])); StringListTokPtr stringList = StringListTokPtr::dynamicCast((yyvsp[(1) - (3)])); @@ -3374,7 +3372,7 @@ yyreduce: break; case 144: -#line 1519 "../Slice/Grammar.y" +#line 1517 "Grammar.y" { StringTokPtr str = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); StringListTokPtr stringList = new StringListTok; @@ -3384,7 +3382,7 @@ yyreduce: break; case 145: -#line 1531 "../Slice/Grammar.y" +#line 1529 "Grammar.y" { BoolTokPtr local = new BoolTok; local->v = true; @@ -3393,7 +3391,7 @@ yyreduce: break; case 146: -#line 1537 "../Slice/Grammar.y" +#line 1535 "Grammar.y" { BoolTokPtr local = new BoolTok; local->v = false; @@ -3402,7 +3400,7 @@ yyreduce: break; case 147: -#line 1548 "../Slice/Grammar.y" +#line 1546 "Grammar.y" { BuiltinPtr type = unit->builtin(Builtin::KindLong); IntegerTokPtr intVal = IntegerTokPtr::dynamicCast((yyvsp[(1) - (1)])); @@ -3418,7 +3416,7 @@ yyreduce: break; case 148: -#line 1561 "../Slice/Grammar.y" +#line 1559 "Grammar.y" { BuiltinPtr type = unit->builtin(Builtin::KindDouble); FloatingTokPtr floatVal = FloatingTokPtr::dynamicCast((yyvsp[(1) - (1)])); @@ -3434,7 +3432,7 @@ yyreduce: break; case 149: -#line 1574 "../Slice/Grammar.y" +#line 1572 "Grammar.y" { StringTokPtr scoped = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); ConstDefTokPtr def = new ConstDefTok; @@ -3442,14 +3440,30 @@ yyreduce: if(cl.empty()) { def->v.type = TypePtr(0); - def->v.value = TypePtr(0); + def->v.value = SyntaxTreeBasePtr(0); def->v.valueAsString = scoped->v; def->v.valueAsLiteral = scoped->v; } else { EnumeratorPtr enumerator = EnumeratorPtr::dynamicCast(cl.front()); - if(!enumerator) + ConstPtr constant = ConstPtr::dynamicCast(cl.front()); + if(enumerator) + { + unit->currentContainer()->checkIntroduced(scoped->v, enumerator); + def->v.type = enumerator->type(); + def->v.value = enumerator; + def->v.valueAsString = scoped->v; + def->v.valueAsLiteral = scoped->v; + } + else if(constant) + { + unit->currentContainer()->checkIntroduced(scoped->v, constant); + def->v.value = constant; + def->v.valueAsString = constant->value(); + def->v.valueAsLiteral = constant->value(); + } + else { string msg = "illegal initializer: `" + scoped->v + "' is a"; static const string vowels = "aeiou"; @@ -3461,18 +3475,13 @@ yyreduce: msg += " " + kindOf; unit->error(msg); // $$ is dummy } - unit->currentContainer()->checkIntroduced(scoped->v, enumerator); - def->v.type = enumerator->type(); - def->v.value = enumerator; - def->v.valueAsString = scoped->v; - def->v.valueAsLiteral = scoped->v; } (yyval) = def; ;} break; case 150: -#line 1609 "../Slice/Grammar.y" +#line 1618 "Grammar.y" { BuiltinPtr type = unit->builtin(Builtin::KindString); StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); @@ -3486,229 +3495,228 @@ yyreduce: break; case 151: -#line 1620 "../Slice/Grammar.y" +#line 1629 "Grammar.y" { BuiltinPtr type = unit->builtin(Builtin::KindBool); StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; - def->v.valueAsString = literal->v; + def->v.valueAsString = "false"; def->v.valueAsLiteral = "false"; (yyval) = def; ;} break; case 152: -#line 1631 "../Slice/Grammar.y" +#line 1640 "Grammar.y" { BuiltinPtr type = unit->builtin(Builtin::KindBool); StringTokPtr literal = StringTokPtr::dynamicCast((yyvsp[(1) - (1)])); ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; - def->v.valueAsString = literal->v; + def->v.valueAsString = "true"; def->v.valueAsLiteral = "true"; (yyval) = def; ;} break; case 153: -#line 1647 "../Slice/Grammar.y" +#line 1656 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(2) - (6)])); TypePtr const_type = TypePtr::dynamicCast((yyvsp[(3) - (6)])); StringTokPtr ident = StringTokPtr::dynamicCast((yyvsp[(4) - (6)])); ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(6) - (6)])); - (yyval) = unit->currentContainer()->createConst(ident->v, const_type, metaData->v, - value->v.value, value->v.valueAsString, value->v.valueAsLiteral); + (yyval) = unit->currentContainer()->createConst(ident->v, const_type, metaData->v, value->v.value, + value->v.valueAsString, value->v.valueAsLiteral); ;} break; case 154: -#line 1656 "../Slice/Grammar.y" +#line 1665 "Grammar.y" { StringListTokPtr metaData = StringListTokPtr::dynamicCast((yyvsp[(2) - (5)])); TypePtr const_type = TypePtr::dynamicCast((yyvsp[(3) - (5)])); ConstDefTokPtr value = ConstDefTokPtr::dynamicCast((yyvsp[(5) - (5)])); unit->error("missing constant name"); - (yyval) = unit->currentContainer()->createConst(IceUtil::generateUUID(), const_type, metaData->v, - value->v.value, value->v.valueAsString, - value->v.valueAsLiteral, Dummy); // Dummy + (yyval) = unit->currentContainer()->createConst(IceUtil::generateUUID(), const_type, metaData->v, value->v.value, + value->v.valueAsString, value->v.valueAsLiteral, Dummy); // Dummy ;} break; case 155: -#line 1671 "../Slice/Grammar.y" +#line 1679 "Grammar.y" { ;} break; case 156: -#line 1674 "../Slice/Grammar.y" +#line 1682 "Grammar.y" { ;} break; case 157: -#line 1677 "../Slice/Grammar.y" +#line 1685 "Grammar.y" { ;} break; case 158: -#line 1680 "../Slice/Grammar.y" +#line 1688 "Grammar.y" { ;} break; case 159: -#line 1683 "../Slice/Grammar.y" +#line 1691 "Grammar.y" { ;} break; case 160: -#line 1686 "../Slice/Grammar.y" +#line 1694 "Grammar.y" { ;} break; case 161: -#line 1689 "../Slice/Grammar.y" +#line 1697 "Grammar.y" { ;} break; case 162: -#line 1692 "../Slice/Grammar.y" +#line 1700 "Grammar.y" { ;} break; case 163: -#line 1695 "../Slice/Grammar.y" +#line 1703 "Grammar.y" { ;} break; case 164: -#line 1698 "../Slice/Grammar.y" +#line 1706 "Grammar.y" { ;} break; case 165: -#line 1701 "../Slice/Grammar.y" +#line 1709 "Grammar.y" { ;} break; case 166: -#line 1704 "../Slice/Grammar.y" +#line 1712 "Grammar.y" { ;} break; case 167: -#line 1707 "../Slice/Grammar.y" +#line 1715 "Grammar.y" { ;} break; case 168: -#line 1710 "../Slice/Grammar.y" +#line 1718 "Grammar.y" { ;} break; case 169: -#line 1713 "../Slice/Grammar.y" +#line 1721 "Grammar.y" { ;} break; case 170: -#line 1716 "../Slice/Grammar.y" +#line 1724 "Grammar.y" { ;} break; case 171: -#line 1719 "../Slice/Grammar.y" +#line 1727 "Grammar.y" { ;} break; case 172: -#line 1722 "../Slice/Grammar.y" +#line 1730 "Grammar.y" { ;} break; case 173: -#line 1725 "../Slice/Grammar.y" +#line 1733 "Grammar.y" { ;} break; case 174: -#line 1728 "../Slice/Grammar.y" +#line 1736 "Grammar.y" { ;} break; case 175: -#line 1731 "../Slice/Grammar.y" +#line 1739 "Grammar.y" { ;} break; case 176: -#line 1734 "../Slice/Grammar.y" +#line 1742 "Grammar.y" { ;} break; case 177: -#line 1737 "../Slice/Grammar.y" +#line 1745 "Grammar.y" { ;} break; case 178: -#line 1740 "../Slice/Grammar.y" +#line 1748 "Grammar.y" { ;} break; case 179: -#line 1743 "../Slice/Grammar.y" +#line 1751 "Grammar.y" { ;} break; case 180: -#line 1746 "../Slice/Grammar.y" +#line 1754 "Grammar.y" { ;} break; case 181: -#line 1749 "../Slice/Grammar.y" +#line 1757 "Grammar.y" { ;} break; case 182: -#line 1752 "../Slice/Grammar.y" +#line 1760 "Grammar.y" { ;} break; /* Line 1267 of yacc.c. */ -#line 3712 "Grammar.tab.c" +#line 3720 "Grammar.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -3922,6 +3930,6 @@ yyreturn: } -#line 1756 "../Slice/Grammar.y" +#line 1764 "Grammar.y" diff --git a/cpp/src/Slice/Grammar.y b/cpp/src/Slice/Grammar.y index 16a514b50b0..899ec94a982 100644 --- a/cpp/src/Slice/Grammar.y +++ b/cpp/src/Slice/Grammar.y @@ -637,24 +637,22 @@ data_member TypePtr type = TypeStringTokPtr::dynamicCast($1)->v.first; string name = TypeStringTokPtr::dynamicCast($1)->v.second; ConstDefTokPtr value = ConstDefTokPtr::dynamicCast($3); - SyntaxTreeBasePtr defaultLiteralType = value->v.value; - string defaultValue = value->v.valueAsString; - string defaultLiteral = value->v.valueAsLiteral; + ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); DataMemberPtr dm; if(cl) { - dm = cl->createDataMember(name, type, defaultLiteralType, defaultValue, defaultLiteral); + dm = cl->createDataMember(name, type, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); } StructPtr st = StructPtr::dynamicCast(unit->currentContainer()); if(st) { - dm = st->createDataMember(name, type, defaultLiteralType, defaultValue, defaultLiteral); + dm = st->createDataMember(name, type, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); } ExceptionPtr ex = ExceptionPtr::dynamicCast(unit->currentContainer()); if(ex) { - dm = ex->createDataMember(name, type, defaultLiteralType, defaultValue, defaultLiteral); + dm = ex->createDataMember(name, type, value->v.value, value->v.valueAsString, value->v.valueAsLiteral); } unit->currentContainer()->checkIntroduced(name, dm); $$ = dm; @@ -1578,14 +1576,30 @@ const_initializer if(cl.empty()) { def->v.type = TypePtr(0); - def->v.value = TypePtr(0); + def->v.value = SyntaxTreeBasePtr(0); def->v.valueAsString = scoped->v; def->v.valueAsLiteral = scoped->v; } else { EnumeratorPtr enumerator = EnumeratorPtr::dynamicCast(cl.front()); - if(!enumerator) + ConstPtr constant = ConstPtr::dynamicCast(cl.front()); + if(enumerator) + { + unit->currentContainer()->checkIntroduced(scoped->v, enumerator); + def->v.type = enumerator->type(); + def->v.value = enumerator; + def->v.valueAsString = scoped->v; + def->v.valueAsLiteral = scoped->v; + } + else if(constant) + { + unit->currentContainer()->checkIntroduced(scoped->v, constant); + def->v.value = constant; + def->v.valueAsString = constant->value(); + def->v.valueAsLiteral = constant->value(); + } + else { string msg = "illegal initializer: `" + scoped->v + "' is a"; static const string vowels = "aeiou"; @@ -1597,11 +1611,6 @@ const_initializer msg += " " + kindOf; unit->error(msg); // $$ is dummy } - unit->currentContainer()->checkIntroduced(scoped->v, enumerator); - def->v.type = enumerator->type(); - def->v.value = enumerator; - def->v.valueAsString = scoped->v; - def->v.valueAsLiteral = scoped->v; } $$ = def; } @@ -1623,7 +1632,7 @@ const_initializer ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; - def->v.valueAsString = literal->v; + def->v.valueAsString = "false"; def->v.valueAsLiteral = "false"; $$ = def; } @@ -1634,7 +1643,7 @@ const_initializer ConstDefTokPtr def = new ConstDefTok; def->v.type = type; def->v.value = type; - def->v.valueAsString = literal->v; + def->v.valueAsString = "true"; def->v.valueAsLiteral = "true"; $$ = def; } @@ -1649,8 +1658,8 @@ const_def TypePtr const_type = TypePtr::dynamicCast($3); StringTokPtr ident = StringTokPtr::dynamicCast($4); ConstDefTokPtr value = ConstDefTokPtr::dynamicCast($6); - $$ = unit->currentContainer()->createConst(ident->v, const_type, metaData->v, - value->v.value, value->v.valueAsString, value->v.valueAsLiteral); + $$ = unit->currentContainer()->createConst(ident->v, const_type, metaData->v, value->v.value, + value->v.valueAsString, value->v.valueAsLiteral); } | ICE_CONST meta_data type '=' const_initializer { @@ -1658,9 +1667,8 @@ const_def TypePtr const_type = TypePtr::dynamicCast($3); ConstDefTokPtr value = ConstDefTokPtr::dynamicCast($5); unit->error("missing constant name"); - $$ = unit->currentContainer()->createConst(IceUtil::generateUUID(), const_type, metaData->v, - value->v.value, value->v.valueAsString, - value->v.valueAsLiteral, Dummy); // Dummy + $$ = unit->currentContainer()->createConst(IceUtil::generateUUID(), const_type, metaData->v, value->v.value, + value->v.valueAsString, value->v.valueAsLiteral, Dummy); // Dummy } ; diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index b4269abccf4..0460bf38122 100755 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -1033,7 +1033,7 @@ Slice::Container::createEnumerator(const string& name) ConstPtr Slice::Container::createConst(const string name, const TypePtr& constType, const StringList& metaData, - const SyntaxTreeBasePtr& literalType, const string& value, const string& literal, + const SyntaxTreeBasePtr& valueType, const string& value, const string& literal, NodeType nt) { checkIdentifier(name); @@ -1074,12 +1074,12 @@ Slice::Container::createConst(const string name, const TypePtr& constType, const // // Validate the constant and its value. // - if(nt == Real && !validateConstant(name, constType, literalType, value, true)) + if(nt == Real && !validateConstant(name, constType, valueType, value, true)) { return 0; } - ConstPtr p = new Const(this, name, constType, metaData, value, literal); + ConstPtr p = new Const(this, name, constType, metaData, valueType, value, literal); _contents.push_back(p); return p; } @@ -2270,16 +2270,27 @@ Slice::Container::checkGlobalMetaData(const StringList& m1, const StringList& m2 } bool -Slice::Container::validateConstant(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& literalType, - const string& value, bool constant) +Slice::Container::validateConstant(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& valueType, + const string& value, bool isConstant) { - const string desc = constant ? "constant" : "data member"; + // + // isConstant indicates whether a constant or a data member (with a default value) is + // being defined. + // - if(type == 0) + if(!type) { return false; } + const string desc = isConstant ? "constant" : "data member"; + + // + // If valueType is a ConstPtr, it means the constant or data member being defined + // refers to another constant. + // + const ConstPtr constant = ConstPtr::dynamicCast(valueType); + // // First verify that it is legal to specify a constant or default value for the given type. // @@ -2302,7 +2313,7 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons break; default: { - if(constant) + if(isConstant) { _unit->error("constant `" + name + "' has illegal type: `" + b->kindAsString() + "'"); } @@ -2317,7 +2328,7 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons } else if(!e) { - if(constant) + if(isConstant) { _unit->error("constant `" + name + "' has illegal type"); } @@ -2334,13 +2345,28 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons if(b) { + BuiltinPtr lt; + + if(constant) + { #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530) - // Strange Sun C++ 5.3 bug. - const IceUtil::HandleBase<SyntaxTreeBase>& hb = literalType; - BuiltinPtr lt = BuiltinPtr::dynamicCast(hb); + // Strange Sun C++ 5.3 bug. + const IceUtil::HandleBase<SyntaxTreeBase>& hb = constant->type(); + lt = BuiltinPtr::dynamicCast(hb); #else - BuiltinPtr lt = BuiltinPtr::dynamicCast(literalType); + lt = BuiltinPtr::dynamicCast(constant->type()); #endif + } + else + { +#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530) + // Strange Sun C++ 5.3 bug. + const IceUtil::HandleBase<SyntaxTreeBase>& hb = valueType; + lt = BuiltinPtr::dynamicCast(hb); +#else + lt = BuiltinPtr::dynamicCast(valueType); +#endif + } if(lt) { @@ -2360,18 +2386,34 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons case Builtin::KindInt: case Builtin::KindLong: { - if(lt->kind() != Builtin::KindLong) + switch(lt->kind()) { + case Builtin::KindByte: + case Builtin::KindShort: + case Builtin::KindInt: + case Builtin::KindLong: + break; + default: ok = false; + break; } break; } case Builtin::KindFloat: case Builtin::KindDouble: { - if(lt->kind() != Builtin::KindDouble) + switch(lt->kind()) { + case Builtin::KindByte: + case Builtin::KindShort: + case Builtin::KindInt: + case Builtin::KindLong: + case Builtin::KindFloat: + case Builtin::KindDouble: + break; + default: ok = false; + break; } break; } @@ -2383,7 +2425,6 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons } break; } - case Builtin::KindObject: case Builtin::KindObjectProxy: case Builtin::KindLocalObject: @@ -2457,19 +2498,33 @@ Slice::Container::validateConstant(const string& name, const TypePtr& type, cons if(e) { - EnumeratorPtr lte = EnumeratorPtr::dynamicCast(literalType); - if(!lte) + if(constant) { - string msg = "type of initializer is incompatible with the type of " + desc + " `" + name + "'"; - _unit->error(msg); - return false; + EnumPtr ec = EnumPtr::dynamicCast(constant->type()); + if(e != ec) + { + string msg = "type of initializer is incompatible with the type of " + desc + " `" + name + "'"; + _unit->error(msg); + return false; + } } - EnumeratorList elist = e->getEnumerators(); - if(find(elist.begin(), elist.end(), lte) == elist.end()) + else { - string msg = "enumerator `" + value + "' is not defined in enumeration `" + e->scoped() + "'"; - _unit->error(msg); - return false; + EnumeratorPtr lte = EnumeratorPtr::dynamicCast(valueType); + + if(!lte) + { + string msg = "type of initializer is incompatible with the type of " + desc + " `" + name + "'"; + _unit->error(msg); + return false; + } + EnumeratorList elist = e->getEnumerators(); + if(find(elist.begin(), elist.end(), lte) == elist.end()) + { + string msg = "enumerator `" + value + "' is not defined in enumeration `" + e->scoped() + "'"; + _unit->error(msg); + return false; + } } } @@ -2954,7 +3009,7 @@ Slice::ClassDef::createOperation(const string& name, } DataMemberPtr -Slice::ClassDef::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultLiteralType, +Slice::ClassDef::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultValueType, const string& defaultValue, const string& defaultLiteral) { checkIdentifier(name); @@ -3077,7 +3132,7 @@ Slice::ClassDef::createDataMember(const string& name, const TypePtr& type, const _unit->error(msg); } - SyntaxTreeBasePtr dlt = defaultLiteralType; + SyntaxTreeBasePtr dlt = defaultValueType; string dv = defaultValue; string dl = defaultLiteral; @@ -3335,7 +3390,7 @@ Slice::ClassDef::hasDefaultValues() const DataMemberList dml = dataMembers(); for(DataMemberList::const_iterator i = dml.begin(); i != dml.end(); ++i) { - if((*i)->hasDefaultValue()) + if((*i)->defaultValueType()) { return true; } @@ -3462,7 +3517,7 @@ Slice::Exception::destroy() } DataMemberPtr -Slice::Exception::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultLiteralType, +Slice::Exception::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultValueType, const string& defaultValue, const string& defaultLiteral) { checkIdentifier(name); @@ -3574,7 +3629,7 @@ Slice::Exception::createDataMember(const string& name, const TypePtr& type, cons _unit->error(msg); } - SyntaxTreeBasePtr dlt = defaultLiteralType; + SyntaxTreeBasePtr dlt = defaultValueType; string dv = defaultValue; string dl = defaultLiteral; @@ -3764,7 +3819,7 @@ Slice::Exception::hasDefaultValues() const DataMemberList dml = dataMembers(); for(DataMemberList::const_iterator i = dml.begin(); i != dml.end(); ++i) { - if((*i)->hasDefaultValue()) + if((*i)->defaultValueType()) { return true; } @@ -3803,7 +3858,7 @@ Slice::Exception::Exception(const ContainerPtr& container, const string& name, c // ---------------------------------------------------------------------- DataMemberPtr -Slice::Struct::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultLiteralType, +Slice::Struct::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultValueType, const string& defaultValue, const string& defaultLiteral) { checkIdentifier(name); @@ -3897,7 +3952,7 @@ Slice::Struct::createDataMember(const string& name, const TypePtr& type, const S _unit->error(msg); } - SyntaxTreeBasePtr dlt = defaultLiteralType; + SyntaxTreeBasePtr dlt = defaultValueType; string dv = defaultValue; string dl = defaultLiteral; @@ -4021,7 +4076,7 @@ Slice::Struct::hasDefaultValues() const DataMemberList dml = dataMembers(); for(DataMemberList::const_iterator i = dml.begin(); i != dml.end(); ++i) { - if((*i)->hasDefaultValue()) + if((*i)->defaultValueType()) { return true; } @@ -4482,6 +4537,12 @@ Slice::Const::typeMetaData() const return _typeMetaData; } +SyntaxTreeBasePtr +Slice::Const::valueType() const +{ + return _valueType; +} + string Slice::Const::value() const { @@ -4520,11 +4581,13 @@ Slice::Const::visit(ParserVisitor* visitor, bool) } Slice::Const::Const(const ContainerPtr& container, const string& name, const TypePtr& type, - const StringList& typeMetaData, const string& value, const string& literal) : + const StringList& typeMetaData, const SyntaxTreeBasePtr& valueType, const string& value, + const string& literal) : SyntaxTreeBase(container->unit()), Contained(container, name), _type(type), _typeMetaData(typeMetaData), + _valueType(valueType), _value(value), _literal(literal) { @@ -5026,12 +5089,6 @@ Slice::DataMember::type() const return _type; } -bool -Slice::DataMember::hasDefaultValue() const -{ - return _hasDefaultValue; -} - string Slice::DataMember::defaultValue() const { @@ -5044,6 +5101,12 @@ Slice::DataMember::defaultLiteral() const return _defaultLiteral; } +SyntaxTreeBasePtr +Slice::DataMember::defaultValueType() const +{ + return _defaultValueType; +} + Contained::ContainedType Slice::DataMember::containedType() const { @@ -5075,11 +5138,12 @@ Slice::DataMember::visit(ParserVisitor* visitor, bool) } Slice::DataMember::DataMember(const ContainerPtr& container, const string& name, const TypePtr& type, - bool hasDefaultValue, const string& defaultValue, const string& defaultLiteral) : + const SyntaxTreeBasePtr& defaultValueType, const string& defaultValue, + const string& defaultLiteral) : SyntaxTreeBase(container->unit()), Contained(container, name), _type(type), - _hasDefaultValue(hasDefaultValue), + _defaultValueType(defaultValueType), _defaultValue(defaultValue), _defaultLiteral(defaultLiteral) { diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index b479d8c4a44..da80807751e 100755 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -119,9 +119,9 @@ private: void writeType(const TypePtr&); // - // Write a default value for a given type. + // Write an initializer value for a given type. // - void writeDefaultValue(const TypePtr&); + void writeInitializer(const TypePtr&); // // Add a value to a hash code. @@ -154,7 +154,7 @@ private: // // Write a constant value. // - void writeConstantValue(const TypePtr&, const string&); + void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const string&); // // Write constructor parameters with default values. @@ -1509,11 +1509,10 @@ void Slice::Python::CodeVisitor::visitConst(const ConstPtr& p) { Slice::TypePtr type = p->type(); - string value = p->value(); string name = fixIdent(p->name()); _out << sp << nl << "_M_" << getAbsolute(p) << " = "; - writeConstantValue(type, value); + writeConstantValue(type, p->valueType(), p->value()); } string @@ -1613,7 +1612,7 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p) } void -Slice::Python::CodeVisitor::writeDefaultValue(const TypePtr& p) +Slice::Python::CodeVisitor::writeInitializer(const TypePtr& p) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(p); if(builtin) @@ -1769,131 +1768,140 @@ Slice::Python::CodeVisitor::writeAssign(const MemberInfo& info) } void -Slice::Python::CodeVisitor::writeConstantValue(const TypePtr& type, const string& value) +Slice::Python::CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& valueType, + const string& value) { - Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type); - Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type); - if(b) + ConstPtr constant = ConstPtr::dynamicCast(valueType); + if(constant) { - switch(b->kind()) - { - case Slice::Builtin::KindBool: - { - _out << (value == "true" ? "True" : "False"); - break; - } - case Slice::Builtin::KindByte: - case Slice::Builtin::KindShort: - case Slice::Builtin::KindInt: - case Slice::Builtin::KindFloat: - case Slice::Builtin::KindDouble: - case Slice::Builtin::KindLong: - { - _out << value; - break; - } - case Slice::Builtin::KindString: + _out << "_M_" << getAbsolute(constant); + } + else + { + Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type); + Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type); + if(b) { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=, '"; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - - _out << "\""; // Opening " - - for(string::const_iterator c = value.begin(); c != value.end(); ++c) + switch(b->kind()) { - switch(*c) - { - case '"': - { - _out << "\\\""; - break; - } - case '\\': - { - _out << "\\\\"; - break; - } - case '\r': - { - _out << "\\r"; - break; - } - case '\n': - { - _out << "\\n"; - break; - } - case '\t': - { - _out << "\\t"; - break; - } - case '\b': - { - _out << "\\b"; - break; - } - case '\f': - { - _out << "\\f"; - break; - } - default: + case Slice::Builtin::KindBool: + { + _out << (value == "true" ? "True" : "False"); + break; + } + case Slice::Builtin::KindByte: + case Slice::Builtin::KindShort: + case Slice::Builtin::KindInt: + case Slice::Builtin::KindFloat: + case Slice::Builtin::KindDouble: + case Slice::Builtin::KindLong: + { + _out << value; + break; + } + case Slice::Builtin::KindString: + { + // + // Expand strings into the basic source character set. We can't use isalpha() and the like + // here because they are sensitive to the current locale. + // + static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "_{}[]#()<>%:;.?*+-/^&|~!=, '"; + static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); + + _out << "\""; // Opening " + + for(string::const_iterator c = value.begin(); c != value.end(); ++c) { - if(charSet.find(*c) == charSet.end()) + switch(*c) { - unsigned char uc = *c; // Char may be signed, so make it positive. - stringstream s; - s << "\\"; // Print as octal if not in basic source character set. - s.flags(ios_base::oct); - s.width(3); - s.fill('0'); - s << static_cast<unsigned>(uc); - _out << s.str(); + case '"': + { + _out << "\\\""; + break; } - else + case '\\': { - _out << *c; // Print normally if in basic source character set. + _out << "\\\\"; + break; + } + case '\r': + { + _out << "\\r"; + break; + } + case '\n': + { + _out << "\\n"; + break; + } + case '\t': + { + _out << "\\t"; + break; + } + case '\b': + { + _out << "\\b"; + break; + } + case '\f': + { + _out << "\\f"; + break; + } + default: + { + if(charSet.find(*c) == charSet.end()) + { + unsigned char uc = *c; // Char may be signed, so make it positive. + stringstream s; + s << "\\"; // Print as octal if not in basic source character set. + s.flags(ios_base::oct); + s.width(3); + s.fill('0'); + s << static_cast<unsigned>(uc); + _out << s.str(); + } + else + { + _out << *c; // Print normally if in basic source character set. + } + break; + } } - break; - } } - } - _out << "\""; // Closing " - break; - } - case Slice::Builtin::KindObject: - case Slice::Builtin::KindObjectProxy: - case Slice::Builtin::KindLocalObject: - assert(false); + _out << "\""; // Closing " + break; + } + case Slice::Builtin::KindObject: + case Slice::Builtin::KindObjectProxy: + case Slice::Builtin::KindLocalObject: + assert(false); + } } - } - else if(en) - { - string enumName = getSymbol(en); - string::size_type colon = value.rfind(':'); - string enumerator; - if(colon != string::npos) + else if(en) { - enumerator = fixIdent(value.substr(colon + 1)); + string enumName = getSymbol(en); + string::size_type colon = value.rfind(':'); + string enumerator; + if(colon != string::npos) + { + enumerator = fixIdent(value.substr(colon + 1)); + } + else + { + enumerator = fixIdent(value); + } + _out << enumName << '.' << enumerator; } else { - enumerator = fixIdent(value); + assert(false); // Unknown const type. } - _out << enumName << '.' << enumerator; - } - else - { - assert(false); // Unknown const type. } } @@ -1904,13 +1912,14 @@ Slice::Python::CodeVisitor::writeConstructorParams(const MemberInfoList& members { _out << ", " << p->fixedName << "="; - if(p->dataMember->hasDefaultValue()) + const DataMemberPtr member = p->dataMember; + if(member->defaultValueType()) { - writeConstantValue(p->dataMember->type(), p->dataMember->defaultValue()); + writeConstantValue(member->type(), member->defaultValueType(), member->defaultValue()); } else { - writeDefaultValue(p->dataMember->type()); + writeInitializer(member->type()); } } } diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp index f62dbc124fe..bca5dbfd05a 100755 --- a/cpp/src/Slice/RubyUtil.cpp +++ b/cpp/src/Slice/RubyUtil.cpp @@ -62,9 +62,9 @@ private: void writeType(const TypePtr&); // - // Get a default value for a given type. + // Get an initializer value for a given type. // - string getDefaultValue(const TypePtr&); + string getInitializer(const TypePtr&); // // Add a value to a hash code. @@ -74,7 +74,7 @@ private: // // Write a constant value. // - void writeConstantValue(const TypePtr&, const string&); + void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const string&); struct MemberInfo { @@ -1287,11 +1287,10 @@ void Slice::Ruby::CodeVisitor::visitConst(const ConstPtr& p) { Slice::TypePtr type = p->type(); - string value = p->value(); string name = fixIdent(p->name(), IdentToUpper); _out << sp << nl << name << " = "; - writeConstantValue(type, value); + writeConstantValue(type, p->valueType(), p->value()); } void @@ -1374,7 +1373,7 @@ Slice::Ruby::CodeVisitor::writeType(const TypePtr& p) } string -Slice::Ruby::CodeVisitor::getDefaultValue(const TypePtr& p) +Slice::Ruby::CodeVisitor::getInitializer(const TypePtr& p) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(p); if(builtin) @@ -1433,133 +1432,142 @@ Slice::Ruby::CodeVisitor::writeHash(const string& name, const TypePtr& p, int& i } void -Slice::Ruby::CodeVisitor::writeConstantValue(const TypePtr& type, const string& value) +Slice::Ruby::CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& valueType, + const string& value) { - Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type); - Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type); - if(b) + ConstPtr constant = ConstPtr::dynamicCast(valueType); + if(constant) { - switch(b->kind()) - { - case Slice::Builtin::KindBool: - case Slice::Builtin::KindByte: - case Slice::Builtin::KindShort: - case Slice::Builtin::KindInt: - case Slice::Builtin::KindFloat: - case Slice::Builtin::KindDouble: - { - _out << value; - break; - } - case Slice::Builtin::KindLong: - { - IceUtil::Int64 l; - IceUtilInternal::stringToInt64(value, l); - _out << value; - break; - } - case Slice::Builtin::KindString: + _out << fixIdent(constant->scoped(), IdentToUpper); + } + else + { + Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type); + Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type); + if(b) { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=, '"; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - - _out << "\""; // Opening " - - for(string::const_iterator c = value.begin(); c != value.end(); ++c) + switch(b->kind()) { - switch(*c) - { - case '"': - { - _out << "\\\""; - break; - } - case '\\': - { - _out << "\\\\"; - break; - } - case '\r': - { - _out << "\\r"; - break; - } - case '\n': - { - _out << "\\n"; - break; - } - case '\t': - { - _out << "\\t"; - break; - } - case '\b': - { - _out << "\\b"; - break; - } - case '\f': - { - _out << "\\f"; - break; - } - default: + case Slice::Builtin::KindBool: + case Slice::Builtin::KindByte: + case Slice::Builtin::KindShort: + case Slice::Builtin::KindInt: + case Slice::Builtin::KindFloat: + case Slice::Builtin::KindDouble: + { + _out << value; + break; + } + case Slice::Builtin::KindLong: + { + IceUtil::Int64 l; + IceUtilInternal::stringToInt64(value, l); + _out << value; + break; + } + case Slice::Builtin::KindString: + { + // + // Expand strings into the basic source character set. We can't use isalpha() and the like + // here because they are sensitive to the current locale. + // + static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "_{}[]#()<>%:;.?*+-/^&|~!=, '"; + static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); + + _out << "\""; // Opening " + + for(string::const_iterator c = value.begin(); c != value.end(); ++c) { - if(charSet.find(*c) == charSet.end()) + switch(*c) { - unsigned char uc = *c; // Char may be signed, so make it positive. - stringstream s; - s << "\\"; // Print as octal if not in basic source character set. - s.flags(ios_base::oct); - s.width(3); - s.fill('0'); - s << static_cast<unsigned>(uc); - _out << s.str(); + case '"': + { + _out << "\\\""; + break; } - else + case '\\': { - _out << *c; // Print normally if in basic source character set. + _out << "\\\\"; + break; + } + case '\r': + { + _out << "\\r"; + break; + } + case '\n': + { + _out << "\\n"; + break; + } + case '\t': + { + _out << "\\t"; + break; + } + case '\b': + { + _out << "\\b"; + break; + } + case '\f': + { + _out << "\\f"; + break; + } + default: + { + if(charSet.find(*c) == charSet.end()) + { + unsigned char uc = *c; // Char may be signed, so make it positive. + stringstream s; + s << "\\"; // Print as octal if not in basic source character set. + s.flags(ios_base::oct); + s.width(3); + s.fill('0'); + s << static_cast<unsigned>(uc); + _out << s.str(); + } + else + { + _out << *c; // Print normally if in basic source character set. + } + break; + } } - break; - } } - } - _out << "\""; // Closing " - break; - } + _out << "\""; // Closing " + break; + } - case Slice::Builtin::KindObject: - case Slice::Builtin::KindObjectProxy: - case Slice::Builtin::KindLocalObject: - assert(false); + case Slice::Builtin::KindObject: + case Slice::Builtin::KindObjectProxy: + case Slice::Builtin::KindLocalObject: + assert(false); + } } - } - else if(en) - { - _out << getAbsolute(en, IdentToUpper) << "::"; - string::size_type colon = value.rfind(':'); - if(colon != string::npos) + else if(en) { - _out << fixIdent(value.substr(colon + 1), IdentToUpper); + _out << getAbsolute(en, IdentToUpper) << "::"; + string::size_type colon = value.rfind(':'); + if(colon != string::npos) + { + _out << fixIdent(value.substr(colon + 1), IdentToUpper); + } + else + { + _out << fixIdent(value, IdentToUpper); + } } else { - _out << fixIdent(value, IdentToUpper); + assert(false); // Unknown const type. } } - else - { - assert(false); // Unknown const type. - } } void @@ -1573,13 +1581,14 @@ Slice::Ruby::CodeVisitor::writeConstructorParams(const MemberInfoList& members) } _out << p->lowerName << "="; - if(p->dataMember->hasDefaultValue()) + const DataMemberPtr member = p->dataMember; + if(member->defaultValueType()) { - writeConstantValue(p->dataMember->type(), p->dataMember->defaultValue()); + writeConstantValue(member->type(), member->defaultValueType(), member->defaultValue()); } else { - _out << getDefaultValue(p->dataMember->type()); + _out << getInitializer(member->type()); } } } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 9442aea8675..a20ab684b07 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -39,63 +39,75 @@ getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2) } static void -writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const string& value, int useWstring, - const StringList& metaData) +writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const SyntaxTreeBasePtr& valueType, + const string& value, int useWstring, const StringList& metaData) { - BuiltinPtr bp = BuiltinPtr::dynamicCast(type); - if(bp && bp->kind() == Builtin::KindString) + ConstPtr constant = ConstPtr::dynamicCast(valueType); + if(constant) { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' "; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - - if((useWstring & TypeContextUseWstring) || findMetaData(metaData) == "wstring") + out << fixKwd(constant->scoped()); + } + else + { + BuiltinPtr bp = BuiltinPtr::dynamicCast(type); + if(bp && bp->kind() == Builtin::KindString) { - out << 'L'; - } - out << "\""; // Opening " + // + // Expand strings into the basic source character set. We can't use isalpha() and the like + // here because they are sensitive to the current locale. + // + static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' "; + static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - for(string::const_iterator c = value.begin(); c != value.end(); ++c) - { - if(charSet.find(*c) == charSet.end()) + if((useWstring & TypeContextUseWstring) || findMetaData(metaData) == "wstring") { - unsigned char uc = *c; // char may be signed, so make it positive - ostringstream s; - s << "\\"; // Print as octal if not in basic source character set - s.width(3); - s.fill('0'); - s << oct; - s << static_cast<unsigned>(uc); - out << s.str(); + out << 'L'; } - else + out << "\""; // Opening " + + for(string::const_iterator c = value.begin(); c != value.end(); ++c) { - out << *c; // Print normally if in basic source character set + if(charSet.find(*c) == charSet.end()) + { + unsigned char uc = *c; // char may be signed, so make it positive + ostringstream s; + s << "\\"; // Print as octal if not in basic source character set + s.width(3); + s.fill('0'); + s << oct; + s << static_cast<unsigned>(uc); + out << s.str(); + } + else + { + out << *c; // Print normally if in basic source character set + } } - } - out << "\""; // Closing " - } - else if(bp && bp->kind() == Builtin::KindLong) - { - out << "ICE_INT64(" << value << ")"; - } - else - { - EnumPtr ep = EnumPtr::dynamicCast(type); - if(ep) + out << "\""; // Closing " + } + else if(bp && bp->kind() == Builtin::KindLong) { - out << fixKwd(value); + out << "ICE_INT64(" << value << ")"; + } + else if(bp && bp->kind() == Builtin::KindFloat) + { + out << value << "F"; } else { - out << value; + EnumPtr ep = EnumPtr::dynamicCast(type); + if(ep) + { + out << fixKwd(value); + } + else + { + out << value; + } } } } @@ -106,7 +118,7 @@ writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& me bool first = true; for(DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p) { - if((*p)->hasDefaultValue()) + if((*p)->defaultValueType()) { string memberName = fixKwd((*p)->name()); @@ -119,7 +131,8 @@ writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& me C << ','; } C << nl << memberName << '('; - writeConstantValue(C, (*p)->type(), (*p)->defaultValue(), useWstring, (*p)->getMetaData()); + writeConstantValue(C, (*p)->type(), (*p)->defaultValueType(), (*p)->defaultValue(), useWstring, + (*p)->getMetaData()); C << ')'; } } @@ -1842,7 +1855,7 @@ Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) H << sp; H << nl << "const " << typeToString(p->type(), p->typeMetaData(), _useWstring) << " " << fixKwd(p->name()) << " = "; - writeConstantValue(H, p->type(), p->value(), _useWstring, p->typeMetaData()); + writeConstantValue(H, p->type(), p->valueType(), p->value(), _useWstring, p->typeMetaData()); H << ';'; } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 7a089e90fbf..ea4a62b7752 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -1218,62 +1218,70 @@ Slice::CsVisitor::writeValue(const TypePtr& type) } void -Slice::CsVisitor::writeConstantValue(const TypePtr& type, const string& value) +Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& valueType, const string& value) { - BuiltinPtr bp = BuiltinPtr::dynamicCast(type); - if(bp && bp->kind() == Builtin::KindString) + ConstPtr constant = ConstPtr::dynamicCast(valueType); + if(constant) { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' "; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); + _out << fixId(constant->scoped()) << ".value"; + } + else + { + BuiltinPtr bp = BuiltinPtr::dynamicCast(type); + if(bp && bp->kind() == Builtin::KindString) + { + // + // Expand strings into the basic source character set. We can't use isalpha() and the like + // here because they are sensitive to the current locale. + // + static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' "; + static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - _out << "\""; // Opening " + _out << "\""; // Opening " - for(string::const_iterator c = value.begin(); c != value.end(); ++c) - { - if(charSet.find(*c) == charSet.end()) + for(string::const_iterator c = value.begin(); c != value.end(); ++c) { - unsigned char uc = *c; // char may be signed, so make it positive - ostringstream s; - s << "\\u"; // Print as unicode if not in basic source character set - s << hex; - s.width(4); - s.fill('0'); - s << static_cast<unsigned>(uc); - _out << s.str(); - } - else - { - _out << *c; // Print normally if in basic source character set + if(charSet.find(*c) == charSet.end()) + { + unsigned char uc = *c; // char may be signed, so make it positive + ostringstream s; + s << "\\u"; // Print as unicode if not in basic source character set + s << hex; + s.width(4); + s.fill('0'); + s << static_cast<unsigned>(uc); + _out << s.str(); + } + else + { + _out << *c; // Print normally if in basic source character set + } } - } - _out << "\""; // Closing " - } - else if(bp && bp->kind() == Builtin::KindLong) - { - _out << value << "L"; - } - else if(bp && bp->kind() == Builtin::KindFloat) - { - _out << value << "F"; - } - else - { - EnumPtr ep = EnumPtr::dynamicCast(type); - if(ep) + _out << "\""; // Closing " + } + else if(bp && bp->kind() == Builtin::KindLong) + { + _out << value << "L"; + } + else if(bp && bp->kind() == Builtin::KindFloat) { - _out << typeToString(type) << "." << fixId(value); + _out << value << "F"; } else { - _out << value; + EnumPtr ep = EnumPtr::dynamicCast(type); + if(ep) + { + _out << typeToString(type) << "." << fixId(value); + } + else + { + _out << value; + } } } } @@ -1283,11 +1291,11 @@ Slice::CsVisitor::writeDataMemberInitializers(const DataMemberList& members, int { for(DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p) { - if((*p)->hasDefaultValue()) + if((*p)->defaultValueType()) { string memberName = fixId((*p)->name(), baseTypes); _out << nl << "this." << memberName << " = "; - writeConstantValue((*p)->type(), (*p)->defaultValue()); + writeConstantValue((*p)->type(), (*p)->defaultValueType(), (*p)->defaultValue()); _out << ';'; } } @@ -3543,7 +3551,7 @@ Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) _out << nl << "public abstract class " << name; _out << sb; _out << sp << nl << "public const " << typeToString(p->type()) << " value = "; - writeConstantValue(p->type(), p->value()); + writeConstantValue(p->type(), p->valueType(), p->value()); _out << ";"; _out << eb; } diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h index 7e304218f35..77ba3cba775 100644 --- a/cpp/src/slice2cs/Gen.h +++ b/cpp/src/slice2cs/Gen.h @@ -43,7 +43,7 @@ protected: std::string writeValue(const TypePtr&); - void writeConstantValue(const TypePtr&, const std::string&); + void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const std::string&); // // Generate assignment statements for those data members that have default values. diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index a1c79ed201d..4af08b247d4 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -1234,113 +1234,122 @@ Slice::JavaVisitor::writeDispatchAndMarshalling(Output& out, const ClassDefPtr& } void -Slice::JavaVisitor::writeConstantValue(Output& out, const TypePtr& type, const string& value, const string& package) +Slice::JavaVisitor::writeConstantValue(Output& out, const TypePtr& type, const SyntaxTreeBasePtr& valueType, + const string& value, const string& package) { - BuiltinPtr bp; - EnumPtr ep; - if(bp = BuiltinPtr::dynamicCast(type)) + ConstPtr constant = ConstPtr::dynamicCast(valueType); + if(constant) { - switch(bp->kind()) + out << getAbsolute(constant, package) << ".value"; + } + else + { + BuiltinPtr bp; + EnumPtr ep; + if(bp = BuiltinPtr::dynamicCast(type)) { - case Builtin::KindString: + switch(bp->kind()) { - out << "\""; - - for(string::const_iterator c = value.begin(); c != value.end(); ++c) + case Builtin::KindString: { - if(isascii(static_cast<unsigned char>(*c)) && isprint(static_cast<unsigned char>(*c))) + out << "\""; + + for(string::const_iterator c = value.begin(); c != value.end(); ++c) { - switch(*c) + if(isascii(static_cast<unsigned char>(*c)) && isprint(static_cast<unsigned char>(*c))) { - case '\\': - case '"': + switch(*c) { - out << "\\"; - break; + case '\\': + case '"': + { + out << "\\"; + break; + } } + out << *c; } - out << *c; - } - else - { - switch(*c) + else { - case '\r': + switch(*c) { - out << "\\r"; - break; - } - case '\n': - { - out << "\\n"; - break; - } - default: - { - unsigned char uc = *c; - ostringstream s; - s << "\\u"; - s.flags(ios_base::hex); - s.width(4); - s.fill('0'); - s << static_cast<unsigned>(uc); - out << s.str(); - break; + case '\r': + { + out << "\\r"; + break; + } + case '\n': + { + out << "\\n"; + break; + } + default: + { + unsigned char uc = *c; + ostringstream s; + s << "\\u"; + s.flags(ios_base::hex); + s.width(4); + s.fill('0'); + s << static_cast<unsigned>(uc); + out << s.str(); + break; + } } } } - } - out << "\""; - break; - } - case Builtin::KindByte: - { - int i = atoi(value.c_str()); - if(i > 127) + out << "\""; + break; + } + case Builtin::KindByte: { - i -= 256; + int i = atoi(value.c_str()); + if(i > 127) + { + i -= 256; + } + out << i; // Slice byte runs from 0-255, Java byte runs from -128 - 127. + break; + } + case Builtin::KindLong: + { + out << value << "L"; // Need to append "L" modifier for long constants. + break; + } + case Builtin::KindBool: + case Builtin::KindShort: + case Builtin::KindInt: + case Builtin::KindDouble: + case Builtin::KindObject: + case Builtin::KindObjectProxy: + case Builtin::KindLocalObject: + { + out << value; + break; + } + case Builtin::KindFloat: + { + out << value << "F"; + break; } - out << i; // Slice byte runs from 0-255, Java byte runs from -128 - 127. - break; - } - case Builtin::KindLong: - { - out << value << "L"; // Need to append "L" modifier for long constants. - break; - } - case Builtin::KindBool: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindDouble: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << value; - break; } - case Builtin::KindFloat: + + } + else if(ep = EnumPtr::dynamicCast(type)) + { + string val = value; + string::size_type pos = val.rfind(':'); + if(pos != string::npos) { - out << value << "F"; - break; + val.erase(0, pos + 1); } + out << getAbsolute(ep, package) << '.' << fixKwd(val); } - - } - else if(ep = EnumPtr::dynamicCast(type)) - { - string val = value; - string::size_type pos = val.rfind(':'); - if(pos != string::npos) + else { - val.erase(0, pos + 1); + out << value; } - out << getAbsolute(ep, package) << '.' << fixKwd(val); - } - else - { - out << value; } } @@ -1349,11 +1358,11 @@ Slice::JavaVisitor::writeDataMemberInitializers(Output& out, const DataMemberLis { for(DataMemberList::const_iterator p = members.begin(); p != members.end(); ++p) { - if((*p)->hasDefaultValue()) + if((*p)->defaultValueType()) { string memberName = fixKwd((*p)->name()); out << nl << memberName << " = "; - writeConstantValue(out, (*p)->type(), (*p)->defaultValue(), package); + writeConstantValue(out, (*p)->type(), (*p)->defaultValueType(), (*p)->defaultValue(), package); out << ';'; } } @@ -3542,7 +3551,7 @@ Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) out << nl << "public interface " << name; out << sb; out << nl << typeToString(type, TypeModeIn, package) << " value = "; - writeConstantValue(out, type, p->value(), package); + writeConstantValue(out, type, p->valueType(), p->value(), package); out << ';' << eb; close(); } diff --git a/cpp/src/slice2java/Gen.h b/cpp/src/slice2java/Gen.h index 5e3f828c9fe..afa86d94f4a 100644 --- a/cpp/src/slice2java/Gen.h +++ b/cpp/src/slice2java/Gen.h @@ -70,7 +70,8 @@ protected: // // Write a constant or default value initializer. // - void writeConstantValue(::IceUtilInternal::Output&, const TypePtr&, const std::string&, const std::string&); + void writeConstantValue(::IceUtilInternal::Output&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&, + const std::string&); // // Generate assignment statements for those data members that have default values. diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index 4e05affbaf7..53904232da5 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -102,7 +102,7 @@ private: // // Write constant value. // - void writeConstantValue(const TypePtr&, const string&); + void writeConstantValue(const TypePtr&, const SyntaxTreeBasePtr&, const string&); // // Write constructor parameters with default values. @@ -939,8 +939,6 @@ CodeVisitor::visitConst(const ConstPtr& p) string name = getName(p); string type = getTypeVar(p); string abs = getAbsolute(p, _ns); - string value = p->value(); - Slice::TypePtr valueType = p->type(); startNamespace(p); @@ -955,7 +953,7 @@ CodeVisitor::visitConst(const ConstPtr& p) _out << sp << nl << "define('" << name << "', "; } - writeConstantValue(valueType, value); + writeConstantValue(p->type(), p->valueType(), p->value()); _out << ");"; _out << eb; @@ -1168,153 +1166,161 @@ CodeVisitor::writeAssign(const MemberInfo& info) } void -CodeVisitor::writeConstantValue(const TypePtr& type, const string& value) +CodeVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePtr& valueType, const string& value) { - Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type); - Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type); - if(b) + ConstPtr constant = ConstPtr::dynamicCast(valueType); + if(constant) { - switch(b->kind()) - { - case Slice::Builtin::KindBool: - case Slice::Builtin::KindByte: - case Slice::Builtin::KindShort: - case Slice::Builtin::KindInt: - case Slice::Builtin::KindFloat: - case Slice::Builtin::KindDouble: - { - _out << value; - break; - } - case Slice::Builtin::KindLong: + _out << getAbsolute(constant, _ns); + } + else + { + Slice::BuiltinPtr b = Slice::BuiltinPtr::dynamicCast(type); + Slice::EnumPtr en = Slice::EnumPtr::dynamicCast(type); + if(b) { - IceUtil::Int64 l; - IceUtilInternal::stringToInt64(value, l); - // - // The platform's 'long' type may not be 64 bits, so we store 64-bit - // values as a string. - // - if(sizeof(IceUtil::Int64) > sizeof(long) && (l < LONG_MIN || l > LONG_MAX)) + switch(b->kind()) { - _out << "'" << value << "'"; - } - else + case Slice::Builtin::KindBool: + case Slice::Builtin::KindByte: + case Slice::Builtin::KindShort: + case Slice::Builtin::KindInt: + case Slice::Builtin::KindFloat: + case Slice::Builtin::KindDouble: { _out << value; + break; } - break; - } - case Slice::Builtin::KindString: - { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=, '"; - static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); - - _out << "\""; // Opening " - - for(string::const_iterator c = value.begin(); c != value.end(); ++c) + case Slice::Builtin::KindLong: { - switch(*c) - { - case '$': + IceUtil::Int64 l; + IceUtilInternal::stringToInt64(value, l); + // + // The platform's 'long' type may not be 64 bits, so we store 64-bit + // values as a string. + // + if(sizeof(IceUtil::Int64) > sizeof(long) && (l < LONG_MIN || l > LONG_MAX)) { - _out << "\\$"; - break; + _out << "'" << value << "'"; } - case '"': - { - _out << "\\\""; - break; - } - case '\\': - { - _out << "\\\\"; - break; - } - case '\r': - { - _out << "\\r"; - break; - } - case '\n': - { - _out << "\\n"; - break; - } - case '\t': - { - _out << "\\t"; - break; - } - case '\b': - { - _out << "\\b"; - break; - } - case '\f': + else { - _out << "\\f"; - break; + _out << value; } - default: + break; + } + case Slice::Builtin::KindString: + { + // + // Expand strings into the basic source character set. We can't use isalpha() and the like + // here because they are sensitive to the current locale. + // + static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "_{}[]#()<>%:;.?*+-/^&|~!=, '"; + static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end()); + + _out << "\""; // Opening " + + for(string::const_iterator c = value.begin(); c != value.end(); ++c) { - if(charSet.find(*c) == charSet.end()) + switch(*c) + { + case '$': { - unsigned char uc = *c; // Char may be signed, so make it positive. - stringstream s; - s << "\\"; // Print as octal if not in basic source character set. - s.flags(ios_base::oct); - s.width(3); - s.fill('0'); - s << static_cast<unsigned>(uc); - _out << s.str(); + _out << "\\$"; + break; } - else + case '"': { - _out << *c; // Print normally if in basic source character set. + _out << "\\\""; + break; + } + case '\\': + { + _out << "\\\\"; + break; + } + case '\r': + { + _out << "\\r"; + break; + } + case '\n': + { + _out << "\\n"; + break; + } + case '\t': + { + _out << "\\t"; + break; + } + case '\b': + { + _out << "\\b"; + break; + } + case '\f': + { + _out << "\\f"; + break; + } + default: + { + if(charSet.find(*c) == charSet.end()) + { + unsigned char uc = *c; // Char may be signed, so make it positive. + stringstream s; + s << "\\"; // Print as octal if not in basic source character set. + s.flags(ios_base::oct); + s.width(3); + s.fill('0'); + s << static_cast<unsigned>(uc); + _out << s.str(); + } + else + { + _out << *c; // Print normally if in basic source character set. + } + break; + } } - break; - } } - } - _out << "\""; // Closing " - break; - } - case Slice::Builtin::KindObject: - case Slice::Builtin::KindObjectProxy: - case Slice::Builtin::KindLocalObject: - assert(false); - } - } - else if(en) - { - string val = value; - string::size_type colon = val.rfind(':'); - if(colon != string::npos) - { - val = val.substr(colon + 1); + _out << "\""; // Closing " + break; + } + case Slice::Builtin::KindObject: + case Slice::Builtin::KindObjectProxy: + case Slice::Builtin::KindLocalObject: + assert(false); + } } - Slice::EnumeratorList l = en->getEnumerators(); - Slice::EnumeratorList::iterator q; - for(q = l.begin(); q != l.end(); ++q) + else if(en) { - if((*q)->name() == val) + string val = value; + string::size_type colon = val.rfind(':'); + if(colon != string::npos) { - _out << getAbsolute(en, _ns) << "::" << fixIdent(val); - break; + val = val.substr(colon + 1); + } + Slice::EnumeratorList l = en->getEnumerators(); + Slice::EnumeratorList::iterator q; + for(q = l.begin(); q != l.end(); ++q) + { + if((*q)->name() == val) + { + _out << getAbsolute(en, _ns) << "::" << fixIdent(val); + break; + } } } - } - else - { - assert(false); // Unknown const type. + else + { + assert(false); // Unknown const type. + } } } @@ -1329,13 +1335,14 @@ CodeVisitor::writeConstructorParams(const MemberInfoList& members) } _out << '$' << p->fixedName << "="; - if(p->dataMember->hasDefaultValue()) + const DataMemberPtr member = p->dataMember; + if(member->defaultValueType()) { - writeConstantValue(p->dataMember->type(), p->dataMember->defaultValue()); + writeConstantValue(member->type(), member->defaultValueType(), member->defaultValue()); } else { - writeDefaultValue(p->dataMember->type()); + writeDefaultValue(member->type()); } } } diff --git a/cpp/test/Ice/defaultValue/AllTests.cpp b/cpp/test/Ice/defaultValue/AllTests.cpp index 2bf0fa2d535..30dd341b35f 100644 --- a/cpp/test/Ice/defaultValue/AllTests.cpp +++ b/cpp/test/Ice/defaultValue/AllTests.cpp @@ -35,7 +35,20 @@ allTests() } { - Struct2Ptr v = new Struct2; + Struct2 v; + test(v.boolTrue == ConstBool); + test(v.b == ConstByte); + test(v.s == ConstShort); + test(v.i == ConstInt); + test(v.l == ConstLong); + test(v.f == ConstFloat); + test(v.d == ConstDouble); + test(v.str == ConstString); + test(v.c == ConstColor); + } + + { + Struct3Ptr v = new Struct3; test(!v->boolFalse); test(v->boolTrue); test(v->b == 1); diff --git a/cpp/test/Ice/defaultValue/Test.ice b/cpp/test/Ice/defaultValue/Test.ice index 760ab0ebb8c..1ca6df58536 100644 --- a/cpp/test/Ice/defaultValue/Test.ice +++ b/cpp/test/Ice/defaultValue/Test.ice @@ -30,9 +30,32 @@ struct Struct1 string noDefault; }; -["cpp:class"] +const bool ConstBool = true; +const byte ConstByte = 254; +const short ConstShort = 16000; +const int ConstInt = 3; +const long ConstLong = 4; +const float ConstFloat = 5.1; +const double ConstDouble = 6.2; +const string ConstString = "foo bar"; +const Color ConstColor = red; + struct Struct2 { + bool boolTrue = ConstBool; + byte b = ConstByte; + short s = ConstShort; + int i = ConstInt; + long l = ConstLong; + float f = ConstFloat; + double d = ConstDouble; + string str = ConstString; + Color c = ConstColor; +}; + +["cpp:class"] +struct Struct3 +{ bool boolFalse = false; bool boolTrue = true; byte b = 1; diff --git a/cpp/test/Slice/errorDetection/ConstDef.err b/cpp/test/Slice/errorDetection/ConstDef.err index 01ab3ae9938..4765aa8da62 100644 --- a/cpp/test/Slice/errorDetection/ConstDef.err +++ b/cpp/test/Slice/errorDetection/ConstDef.err @@ -21,3 +21,6 @@ ConstDef.ice:124: initializer `-1' for constant `b3' out of range for type byte ConstDef.ice:125: initializer `256' for constant `b4' out of range for type byte ConstDef.ice:127: illegal NUL character in string constant ConstDef.ice:128: illegal NUL character in string constant +ConstDef.ice:135: initializer `32767' for constant `c5' out of range for type byte +ConstDef.ice:136: initializer `2147483647' for constant `c6' out of range for type short +ConstDef.ice:137: initializer `9223372036854775807' for constant `c7' out of range for type int diff --git a/cpp/test/Slice/errorDetection/ConstDef.ice b/cpp/test/Slice/errorDetection/ConstDef.ice index 7219380f54b..04ec71a4c57 100644 --- a/cpp/test/Slice/errorDetection/ConstDef.ice +++ b/cpp/test/Slice/errorDetection/ConstDef.ice @@ -127,4 +127,22 @@ const byte b4 = 256; // overflow const string nullstring1 = "a\000"; const string nullstring2 = "a\x000"; +const byte c1 = l1; // OK +const short c2 = l1; // OK +const int c3 = l1; // OK +const long c4 = l1; // OK + +const byte c5 = s2; // overflow +const short c6 = i2; // overflow +const int c7 = r5; // overflow + +const float c8 = f1; // OK +const float c9 = doubleconst; // OK +const double c10 = f1; // OK +const double c11 = doubleconst; // OK + +const string c12 = stringconst; // OK + +const color c13 = colorconst; // OK + }; |