diff options
author | Tristan Gingold | 2015-11-07 09:46:13 +0100 |
---|---|---|
committer | Tristan Gingold | 2015-11-07 09:46:13 +0100 |
commit | 10bf1b5f306734e98c98612e00cfd275290318c1 (patch) | |
tree | c0f02b804f91a6f860f12365939fa30904352264 /src | |
parent | 5cccf1ca28d378a8044ec1990edb8eec628e6920 (diff) | |
download | ghdl-10bf1b5f306734e98c98612e00cfd275290318c1.tar.gz ghdl-10bf1b5f306734e98c98612e00cfd275290318c1.tar.bz2 ghdl-10bf1b5f306734e98c98612e00cfd275290318c1.zip |
Fix crash on invalid individual association.
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/iirs.ads | 4 | ||||
-rw-r--r-- | src/vhdl/nodes_meta.adb | 466 | ||||
-rw-r--r-- | src/vhdl/sem_assocs.adb | 67 | ||||
-rw-r--r-- | src/vhdl/sem_expr.adb | 465 | ||||
-rw-r--r-- | src/vhdl/sem_expr.ads | 13 |
5 files changed, 545 insertions, 470 deletions
diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads index 70072f6..ba22be9 100644 --- a/src/vhdl/iirs.ads +++ b/src/vhdl/iirs.ads @@ -401,6 +401,10 @@ package Iirs is -- Get/Set_Actual_Type (Field3) -- -- Only for Iir_Kind_Association_Element_By_Individual: + -- Must be Locally unless there is an error on one choice. + -- Get/Set_Choice_Staticness (State2) + -- + -- Only for Iir_Kind_Association_Element_By_Individual: -- Get/Set_Individual_Association_Chain (Field4) -- -- Only for Iir_Kind_Association_Element_Package: diff --git a/src/vhdl/nodes_meta.adb b/src/vhdl/nodes_meta.adb index 2af55d4..16fb1f4 100644 --- a/src/vhdl/nodes_meta.adb +++ b/src/vhdl/nodes_meta.adb @@ -2147,6 +2147,7 @@ package body Nodes_Meta is -- Iir_Kind_Association_Element_By_Individual Field_Whole_Association_Flag, Field_Collapse_Signal_Flag, + Field_Choice_Staticness, Field_Formal, Field_Chain, Field_Actual_Type, @@ -3984,237 +3985,237 @@ package body Nodes_Meta is Iir_Kind_Waveform_Element => 86, Iir_Kind_Conditional_Waveform => 89, Iir_Kind_Association_Element_By_Expression => 96, - Iir_Kind_Association_Element_By_Individual => 102, - Iir_Kind_Association_Element_Open => 107, - Iir_Kind_Association_Element_Package => 113, - Iir_Kind_Choice_By_Others => 118, - Iir_Kind_Choice_By_Expression => 125, - Iir_Kind_Choice_By_Range => 132, - Iir_Kind_Choice_By_None => 137, - Iir_Kind_Choice_By_Name => 143, - Iir_Kind_Entity_Aspect_Entity => 145, - Iir_Kind_Entity_Aspect_Configuration => 146, - Iir_Kind_Entity_Aspect_Open => 146, - Iir_Kind_Block_Configuration => 152, - Iir_Kind_Block_Header => 156, - Iir_Kind_Component_Configuration => 162, - Iir_Kind_Binding_Indication => 168, - Iir_Kind_Entity_Class => 170, - Iir_Kind_Attribute_Value => 178, - Iir_Kind_Signature => 181, - Iir_Kind_Aggregate_Info => 188, - Iir_Kind_Procedure_Call => 192, - Iir_Kind_Record_Element_Constraint => 198, - Iir_Kind_Array_Element_Resolution => 199, - Iir_Kind_Record_Resolution => 200, - Iir_Kind_Record_Element_Resolution => 203, - Iir_Kind_Attribute_Specification => 211, - Iir_Kind_Disconnection_Specification => 216, - Iir_Kind_Configuration_Specification => 221, - Iir_Kind_Access_Type_Definition => 228, - Iir_Kind_Incomplete_Type_Definition => 235, - Iir_Kind_File_Type_Definition => 242, - Iir_Kind_Protected_Type_Declaration => 251, - Iir_Kind_Record_Type_Definition => 261, - Iir_Kind_Array_Type_Definition => 273, - Iir_Kind_Array_Subtype_Definition => 288, - Iir_Kind_Record_Subtype_Definition => 299, - Iir_Kind_Access_Subtype_Definition => 307, - Iir_Kind_Physical_Subtype_Definition => 316, - Iir_Kind_Floating_Subtype_Definition => 326, - Iir_Kind_Integer_Subtype_Definition => 335, - Iir_Kind_Enumeration_Subtype_Definition => 344, - Iir_Kind_Enumeration_Type_Definition => 353, - Iir_Kind_Integer_Type_Definition => 359, - Iir_Kind_Floating_Type_Definition => 365, - Iir_Kind_Physical_Type_Definition => 374, - Iir_Kind_Range_Expression => 380, - Iir_Kind_Protected_Type_Body => 387, - Iir_Kind_Subtype_Definition => 391, - Iir_Kind_Scalar_Nature_Definition => 395, - Iir_Kind_Overload_List => 396, - Iir_Kind_Type_Declaration => 402, - Iir_Kind_Anonymous_Type_Declaration => 407, - Iir_Kind_Subtype_Declaration => 415, - Iir_Kind_Nature_Declaration => 421, - Iir_Kind_Subnature_Declaration => 427, - Iir_Kind_Package_Declaration => 437, - Iir_Kind_Package_Instantiation_Declaration => 448, - Iir_Kind_Package_Body => 455, - Iir_Kind_Configuration_Declaration => 464, - Iir_Kind_Entity_Declaration => 476, - Iir_Kind_Architecture_Body => 488, - Iir_Kind_Context_Declaration => 494, - Iir_Kind_Package_Header => 496, - Iir_Kind_Unit_Declaration => 505, - Iir_Kind_Library_Declaration => 512, - Iir_Kind_Component_Declaration => 522, - Iir_Kind_Attribute_Declaration => 529, - Iir_Kind_Group_Template_Declaration => 535, - Iir_Kind_Group_Declaration => 542, - Iir_Kind_Element_Declaration => 549, - Iir_Kind_Non_Object_Alias_Declaration => 557, - Iir_Kind_Psl_Declaration => 565, - Iir_Kind_Terminal_Declaration => 571, - Iir_Kind_Free_Quantity_Declaration => 580, - Iir_Kind_Across_Quantity_Declaration => 592, - Iir_Kind_Through_Quantity_Declaration => 604, - Iir_Kind_Enumeration_Literal => 615, - Iir_Kind_Function_Declaration => 639, - Iir_Kind_Procedure_Declaration => 662, - Iir_Kind_Function_Body => 672, - Iir_Kind_Procedure_Body => 683, - Iir_Kind_Object_Alias_Declaration => 695, - Iir_Kind_File_Declaration => 710, - Iir_Kind_Guard_Signal_Declaration => 723, - Iir_Kind_Signal_Declaration => 740, - Iir_Kind_Variable_Declaration => 753, - Iir_Kind_Constant_Declaration => 767, - Iir_Kind_Iterator_Declaration => 779, - Iir_Kind_Interface_Constant_Declaration => 795, - Iir_Kind_Interface_Variable_Declaration => 811, - Iir_Kind_Interface_Signal_Declaration => 832, - Iir_Kind_Interface_File_Declaration => 848, - Iir_Kind_Interface_Package_Declaration => 857, - Iir_Kind_Identity_Operator => 861, - Iir_Kind_Negation_Operator => 865, - Iir_Kind_Absolute_Operator => 869, - Iir_Kind_Not_Operator => 873, - Iir_Kind_Condition_Operator => 877, - Iir_Kind_Reduction_And_Operator => 881, - Iir_Kind_Reduction_Or_Operator => 885, - Iir_Kind_Reduction_Nand_Operator => 889, - Iir_Kind_Reduction_Nor_Operator => 893, - Iir_Kind_Reduction_Xor_Operator => 897, - Iir_Kind_Reduction_Xnor_Operator => 901, - Iir_Kind_And_Operator => 906, - Iir_Kind_Or_Operator => 911, - Iir_Kind_Nand_Operator => 916, - Iir_Kind_Nor_Operator => 921, - Iir_Kind_Xor_Operator => 926, - Iir_Kind_Xnor_Operator => 931, - Iir_Kind_Equality_Operator => 936, - Iir_Kind_Inequality_Operator => 941, - Iir_Kind_Less_Than_Operator => 946, - Iir_Kind_Less_Than_Or_Equal_Operator => 951, - Iir_Kind_Greater_Than_Operator => 956, - Iir_Kind_Greater_Than_Or_Equal_Operator => 961, - Iir_Kind_Match_Equality_Operator => 966, - Iir_Kind_Match_Inequality_Operator => 971, - Iir_Kind_Match_Less_Than_Operator => 976, - Iir_Kind_Match_Less_Than_Or_Equal_Operator => 981, - Iir_Kind_Match_Greater_Than_Operator => 986, - Iir_Kind_Match_Greater_Than_Or_Equal_Operator => 991, - Iir_Kind_Sll_Operator => 996, - Iir_Kind_Sla_Operator => 1001, - Iir_Kind_Srl_Operator => 1006, - Iir_Kind_Sra_Operator => 1011, - Iir_Kind_Rol_Operator => 1016, - Iir_Kind_Ror_Operator => 1021, - Iir_Kind_Addition_Operator => 1026, - Iir_Kind_Substraction_Operator => 1031, - Iir_Kind_Concatenation_Operator => 1036, - Iir_Kind_Multiplication_Operator => 1041, - Iir_Kind_Division_Operator => 1046, - Iir_Kind_Modulus_Operator => 1051, - Iir_Kind_Remainder_Operator => 1056, - Iir_Kind_Exponentiation_Operator => 1061, - Iir_Kind_Function_Call => 1069, - Iir_Kind_Aggregate => 1075, - Iir_Kind_Parenthesis_Expression => 1078, - Iir_Kind_Qualified_Expression => 1082, - Iir_Kind_Type_Conversion => 1087, - Iir_Kind_Allocator_By_Expression => 1091, - Iir_Kind_Allocator_By_Subtype => 1097, - Iir_Kind_Selected_Element => 1103, - Iir_Kind_Dereference => 1108, - Iir_Kind_Implicit_Dereference => 1113, - Iir_Kind_Slice_Name => 1120, - Iir_Kind_Indexed_Name => 1126, - Iir_Kind_Psl_Expression => 1128, - Iir_Kind_Sensitized_Process_Statement => 1148, - Iir_Kind_Process_Statement => 1168, - Iir_Kind_Concurrent_Conditional_Signal_Assignment => 1179, - Iir_Kind_Concurrent_Selected_Signal_Assignment => 1191, - Iir_Kind_Concurrent_Assertion_Statement => 1199, - Iir_Kind_Psl_Default_Clock => 1203, - Iir_Kind_Psl_Assert_Statement => 1212, - Iir_Kind_Psl_Cover_Statement => 1221, - Iir_Kind_Concurrent_Procedure_Call_Statement => 1228, - Iir_Kind_Block_Statement => 1241, - Iir_Kind_If_Generate_Statement => 1251, - Iir_Kind_For_Generate_Statement => 1260, - Iir_Kind_Component_Instantiation_Statement => 1270, - Iir_Kind_Simple_Simultaneous_Statement => 1277, - Iir_Kind_Generate_Statement_Body => 1288, - Iir_Kind_If_Generate_Else_Clause => 1293, - Iir_Kind_Signal_Assignment_Statement => 1302, - Iir_Kind_Null_Statement => 1306, - Iir_Kind_Assertion_Statement => 1313, - Iir_Kind_Report_Statement => 1319, - Iir_Kind_Wait_Statement => 1326, - Iir_Kind_Variable_Assignment_Statement => 1332, - Iir_Kind_Return_Statement => 1338, - Iir_Kind_For_Loop_Statement => 1347, - Iir_Kind_While_Loop_Statement => 1355, - Iir_Kind_Next_Statement => 1361, - Iir_Kind_Exit_Statement => 1367, - Iir_Kind_Case_Statement => 1375, - Iir_Kind_Procedure_Call_Statement => 1381, - Iir_Kind_If_Statement => 1390, - Iir_Kind_Elsif => 1395, - Iir_Kind_Character_Literal => 1402, - Iir_Kind_Simple_Name => 1409, - Iir_Kind_Selected_Name => 1417, - Iir_Kind_Operator_Symbol => 1422, - Iir_Kind_Selected_By_All_Name => 1427, - Iir_Kind_Parenthesis_Name => 1431, - Iir_Kind_External_Constant_Name => 1440, - Iir_Kind_External_Signal_Name => 1449, - Iir_Kind_External_Variable_Name => 1458, - Iir_Kind_Package_Pathname => 1461, - Iir_Kind_Absolute_Pathname => 1462, - Iir_Kind_Relative_Pathname => 1463, - Iir_Kind_Pathname_Element => 1467, - Iir_Kind_Base_Attribute => 1469, - Iir_Kind_Left_Type_Attribute => 1474, - Iir_Kind_Right_Type_Attribute => 1479, - Iir_Kind_High_Type_Attribute => 1484, - Iir_Kind_Low_Type_Attribute => 1489, - Iir_Kind_Ascending_Type_Attribute => 1494, - Iir_Kind_Image_Attribute => 1500, - Iir_Kind_Value_Attribute => 1506, - Iir_Kind_Pos_Attribute => 1512, - Iir_Kind_Val_Attribute => 1518, - Iir_Kind_Succ_Attribute => 1524, - Iir_Kind_Pred_Attribute => 1530, - Iir_Kind_Leftof_Attribute => 1536, - Iir_Kind_Rightof_Attribute => 1542, - Iir_Kind_Delayed_Attribute => 1550, - Iir_Kind_Stable_Attribute => 1558, - Iir_Kind_Quiet_Attribute => 1566, - Iir_Kind_Transaction_Attribute => 1574, - Iir_Kind_Event_Attribute => 1578, - Iir_Kind_Active_Attribute => 1582, - Iir_Kind_Last_Event_Attribute => 1586, - Iir_Kind_Last_Active_Attribute => 1590, - Iir_Kind_Last_Value_Attribute => 1594, - Iir_Kind_Driving_Attribute => 1598, - Iir_Kind_Driving_Value_Attribute => 1602, - Iir_Kind_Behavior_Attribute => 1602, - Iir_Kind_Structure_Attribute => 1602, - Iir_Kind_Simple_Name_Attribute => 1609, - Iir_Kind_Instance_Name_Attribute => 1614, - Iir_Kind_Path_Name_Attribute => 1619, - Iir_Kind_Left_Array_Attribute => 1626, - Iir_Kind_Right_Array_Attribute => 1633, - Iir_Kind_High_Array_Attribute => 1640, - Iir_Kind_Low_Array_Attribute => 1647, - Iir_Kind_Length_Array_Attribute => 1654, - Iir_Kind_Ascending_Array_Attribute => 1661, - Iir_Kind_Range_Array_Attribute => 1668, - Iir_Kind_Reverse_Range_Array_Attribute => 1675, - Iir_Kind_Attribute_Name => 1683 + Iir_Kind_Association_Element_By_Individual => 103, + Iir_Kind_Association_Element_Open => 108, + Iir_Kind_Association_Element_Package => 114, + Iir_Kind_Choice_By_Others => 119, + Iir_Kind_Choice_By_Expression => 126, + Iir_Kind_Choice_By_Range => 133, + Iir_Kind_Choice_By_None => 138, + Iir_Kind_Choice_By_Name => 144, + Iir_Kind_Entity_Aspect_Entity => 146, + Iir_Kind_Entity_Aspect_Configuration => 147, + Iir_Kind_Entity_Aspect_Open => 147, + Iir_Kind_Block_Configuration => 153, + Iir_Kind_Block_Header => 157, + Iir_Kind_Component_Configuration => 163, + Iir_Kind_Binding_Indication => 169, + Iir_Kind_Entity_Class => 171, + Iir_Kind_Attribute_Value => 179, + Iir_Kind_Signature => 182, + Iir_Kind_Aggregate_Info => 189, + Iir_Kind_Procedure_Call => 193, + Iir_Kind_Record_Element_Constraint => 199, + Iir_Kind_Array_Element_Resolution => 200, + Iir_Kind_Record_Resolution => 201, + Iir_Kind_Record_Element_Resolution => 204, + Iir_Kind_Attribute_Specification => 212, + Iir_Kind_Disconnection_Specification => 217, + Iir_Kind_Configuration_Specification => 222, + Iir_Kind_Access_Type_Definition => 229, + Iir_Kind_Incomplete_Type_Definition => 236, + Iir_Kind_File_Type_Definition => 243, + Iir_Kind_Protected_Type_Declaration => 252, + Iir_Kind_Record_Type_Definition => 262, + Iir_Kind_Array_Type_Definition => 274, + Iir_Kind_Array_Subtype_Definition => 289, + Iir_Kind_Record_Subtype_Definition => 300, + Iir_Kind_Access_Subtype_Definition => 308, + Iir_Kind_Physical_Subtype_Definition => 317, + Iir_Kind_Floating_Subtype_Definition => 327, + Iir_Kind_Integer_Subtype_Definition => 336, + Iir_Kind_Enumeration_Subtype_Definition => 345, + Iir_Kind_Enumeration_Type_Definition => 354, + Iir_Kind_Integer_Type_Definition => 360, + Iir_Kind_Floating_Type_Definition => 366, + Iir_Kind_Physical_Type_Definition => 375, + Iir_Kind_Range_Expression => 381, + Iir_Kind_Protected_Type_Body => 388, + Iir_Kind_Subtype_Definition => 392, + Iir_Kind_Scalar_Nature_Definition => 396, + Iir_Kind_Overload_List => 397, + Iir_Kind_Type_Declaration => 403, + Iir_Kind_Anonymous_Type_Declaration => 408, + Iir_Kind_Subtype_Declaration => 416, + Iir_Kind_Nature_Declaration => 422, + Iir_Kind_Subnature_Declaration => 428, + Iir_Kind_Package_Declaration => 438, + Iir_Kind_Package_Instantiation_Declaration => 449, + Iir_Kind_Package_Body => 456, + Iir_Kind_Configuration_Declaration => 465, + Iir_Kind_Entity_Declaration => 477, + Iir_Kind_Architecture_Body => 489, + Iir_Kind_Context_Declaration => 495, + Iir_Kind_Package_Header => 497, + Iir_Kind_Unit_Declaration => 506, + Iir_Kind_Library_Declaration => 513, + Iir_Kind_Component_Declaration => 523, + Iir_Kind_Attribute_Declaration => 530, + Iir_Kind_Group_Template_Declaration => 536, + Iir_Kind_Group_Declaration => 543, + Iir_Kind_Element_Declaration => 550, + Iir_Kind_Non_Object_Alias_Declaration => 558, + Iir_Kind_Psl_Declaration => 566, + Iir_Kind_Terminal_Declaration => 572, + Iir_Kind_Free_Quantity_Declaration => 581, + Iir_Kind_Across_Quantity_Declaration => 593, + Iir_Kind_Through_Quantity_Declaration => 605, + Iir_Kind_Enumeration_Literal => 616, + Iir_Kind_Function_Declaration => 640, + Iir_Kind_Procedure_Declaration => 663, + Iir_Kind_Function_Body => 673, + Iir_Kind_Procedure_Body => 684, + Iir_Kind_Object_Alias_Declaration => 696, + Iir_Kind_File_Declaration => 711, + Iir_Kind_Guard_Signal_Declaration => 724, + Iir_Kind_Signal_Declaration => 741, + Iir_Kind_Variable_Declaration => 754, + Iir_Kind_Constant_Declaration => 768, + Iir_Kind_Iterator_Declaration => 780, + Iir_Kind_Interface_Constant_Declaration => 796, + Iir_Kind_Interface_Variable_Declaration => 812, + Iir_Kind_Interface_Signal_Declaration => 833, + Iir_Kind_Interface_File_Declaration => 849, + Iir_Kind_Interface_Package_Declaration => 858, + Iir_Kind_Identity_Operator => 862, + Iir_Kind_Negation_Operator => 866, + Iir_Kind_Absolute_Operator => 870, + Iir_Kind_Not_Operator => 874, + Iir_Kind_Condition_Operator => 878, + Iir_Kind_Reduction_And_Operator => 882, + Iir_Kind_Reduction_Or_Operator => 886, + Iir_Kind_Reduction_Nand_Operator => 890, + Iir_Kind_Reduction_Nor_Operator => 894, + Iir_Kind_Reduction_Xor_Operator => 898, + Iir_Kind_Reduction_Xnor_Operator => 902, + Iir_Kind_And_Operator => 907, + Iir_Kind_Or_Operator => 912, + Iir_Kind_Nand_Operator => 917, + Iir_Kind_Nor_Operator => 922, + Iir_Kind_Xor_Operator => 927, + Iir_Kind_Xnor_Operator => 932, + Iir_Kind_Equality_Operator => 937, + Iir_Kind_Inequality_Operator => 942, + Iir_Kind_Less_Than_Operator => 947, + Iir_Kind_Less_Than_Or_Equal_Operator => 952, + Iir_Kind_Greater_Than_Operator => 957, + Iir_Kind_Greater_Than_Or_Equal_Operator => 962, + Iir_Kind_Match_Equality_Operator => 967, + Iir_Kind_Match_Inequality_Operator => 972, + Iir_Kind_Match_Less_Than_Operator => 977, + Iir_Kind_Match_Less_Than_Or_Equal_Operator => 982, + Iir_Kind_Match_Greater_Than_Operator => 987, + Iir_Kind_Match_Greater_Than_Or_Equal_Operator => 992, + Iir_Kind_Sll_Operator => 997, + Iir_Kind_Sla_Operator => 1002, + Iir_Kind_Srl_Operator => 1007, + Iir_Kind_Sra_Operator => 1012, + Iir_Kind_Rol_Operator => 1017, + Iir_Kind_Ror_Operator => 1022, + Iir_Kind_Addition_Operator => 1027, + Iir_Kind_Substraction_Operator => 1032, + Iir_Kind_Concatenation_Operator => 1037, + Iir_Kind_Multiplication_Operator => 1042, + Iir_Kind_Division_Operator => 1047, + Iir_Kind_Modulus_Operator => 1052, + Iir_Kind_Remainder_Operator => 1057, + Iir_Kind_Exponentiation_Operator => 1062, + Iir_Kind_Function_Call => 1070, + Iir_Kind_Aggregate => 1076, + Iir_Kind_Parenthesis_Expression => 1079, + Iir_Kind_Qualified_Expression => 1083, + Iir_Kind_Type_Conversion => 1088, + Iir_Kind_Allocator_By_Expression => 1092, + Iir_Kind_Allocator_By_Subtype => 1098, + Iir_Kind_Selected_Element => 1104, + Iir_Kind_Dereference => 1109, + Iir_Kind_Implicit_Dereference => 1114, + Iir_Kind_Slice_Name => 1121, + Iir_Kind_Indexed_Name => 1127, + Iir_Kind_Psl_Expression => 1129, + Iir_Kind_Sensitized_Process_Statement => 1149, + Iir_Kind_Process_Statement => 1169, + Iir_Kind_Concurrent_Conditional_Signal_Assignment => 1180, + Iir_Kind_Concurrent_Selected_Signal_Assignment => 1192, + Iir_Kind_Concurrent_Assertion_Statement => 1200, + Iir_Kind_Psl_Default_Clock => 1204, + Iir_Kind_Psl_Assert_Statement => 1213, + Iir_Kind_Psl_Cover_Statement => 1222, + Iir_Kind_Concurrent_Procedure_Call_Statement => 1229, + Iir_Kind_Block_Statement => 1242, + Iir_Kind_If_Generate_Statement => 1252, + Iir_Kind_For_Generate_Statement => 1261, + Iir_Kind_Component_Instantiation_Statement => 1271, + Iir_Kind_Simple_Simultaneous_Statement => 1278, + Iir_Kind_Generate_Statement_Body => 1289, + Iir_Kind_If_Generate_Else_Clause => 1294, + Iir_Kind_Signal_Assignment_Statement => 1303, + Iir_Kind_Null_Statement => 1307, + Iir_Kind_Assertion_Statement => 1314, + Iir_Kind_Report_Statement => 1320, + Iir_Kind_Wait_Statement => 1327, + Iir_Kind_Variable_Assignment_Statement => 1333, + Iir_Kind_Return_Statement => 1339, + Iir_Kind_For_Loop_Statement => 1348, + Iir_Kind_While_Loop_Statement => 1356, + Iir_Kind_Next_Statement => 1362, + Iir_Kind_Exit_Statement => 1368, + Iir_Kind_Case_Statement => 1376, + Iir_Kind_Procedure_Call_Statement => 1382, + Iir_Kind_If_Statement => 1391, + Iir_Kind_Elsif => 1396, + Iir_Kind_Character_Literal => 1403, + Iir_Kind_Simple_Name => 1410, + Iir_Kind_Selected_Name => 1418, + Iir_Kind_Operator_Symbol => 1423, + Iir_Kind_Selected_By_All_Name => 1428, + Iir_Kind_Parenthesis_Name => 1432, + Iir_Kind_External_Constant_Name => 1441, + Iir_Kind_External_Signal_Name => 1450, + Iir_Kind_External_Variable_Name => 1459, + Iir_Kind_Package_Pathname => 1462, + Iir_Kind_Absolute_Pathname => 1463, + Iir_Kind_Relative_Pathname => 1464, + Iir_Kind_Pathname_Element => 1468, + Iir_Kind_Base_Attribute => 1470, + Iir_Kind_Left_Type_Attribute => 1475, + Iir_Kind_Right_Type_Attribute => 1480, + Iir_Kind_High_Type_Attribute => 1485, + Iir_Kind_Low_Type_Attribute => 1490, + Iir_Kind_Ascending_Type_Attribute => 1495, + Iir_Kind_Image_Attribute => 1501, + Iir_Kind_Value_Attribute => 1507, + Iir_Kind_Pos_Attribute => 1513, + Iir_Kind_Val_Attribute => 1519, + Iir_Kind_Succ_Attribute => 1525, + Iir_Kind_Pred_Attribute => 1531, + Iir_Kind_Leftof_Attribute => 1537, + Iir_Kind_Rightof_Attribute => 1543, + Iir_Kind_Delayed_Attribute => 1551, + Iir_Kind_Stable_Attribute => 1559, + Iir_Kind_Quiet_Attribute => 1567, + Iir_Kind_Transaction_Attribute => 1575, + Iir_Kind_Event_Attribute => 1579, + Iir_Kind_Active_Attribute => 1583, + Iir_Kind_Last_Event_Attribute => 1587, + Iir_Kind_Last_Active_Attribute => 1591, + Iir_Kind_Last_Value_Attribute => 1595, + Iir_Kind_Driving_Attribute => 1599, + Iir_Kind_Driving_Value_Attribute => 1603, + Iir_Kind_Behavior_Attribute => 1603, + Iir_Kind_Structure_Attribute => 1603, + Iir_Kind_Simple_Name_Attribute => 1610, + Iir_Kind_Instance_Name_Attribute => 1615, + Iir_Kind_Path_Name_Attribute => 1620, + Iir_Kind_Left_Array_Attribute => 1627, + Iir_Kind_Right_Array_Attribute => 1634, + Iir_Kind_High_Array_Attribute => 1641, + Iir_Kind_Low_Array_Attribute => 1648, + Iir_Kind_Length_Array_Attribute => 1655, + Iir_Kind_Ascending_Array_Attribute => 1662, + Iir_Kind_Range_Array_Attribute => 1669, + Iir_Kind_Reverse_Range_Array_Attribute => 1676, + Iir_Kind_Attribute_Name => 1684 ); function Get_Fields (K : Iir_Kind) return Fields_Array @@ -9109,7 +9110,8 @@ package body Nodes_Meta is function Has_Choice_Staticness (K : Iir_Kind) return Boolean is begin case K is - when Iir_Kind_Choice_By_Expression + when Iir_Kind_Association_Element_By_Individual + | Iir_Kind_Choice_By_Expression | Iir_Kind_Choice_By_Range => return True; when others => diff --git a/src/vhdl/sem_assocs.adb b/src/vhdl/sem_assocs.adb index 841f503..3123fbd 100644 --- a/src/vhdl/sem_assocs.adb +++ b/src/vhdl/sem_assocs.adb @@ -427,11 +427,13 @@ package body Sem_Assocs is procedure Add_Individual_Assoc_Indexed_Name (Sub_Assoc : in out Iir; Formal : Iir) is + Base_Assoc : constant Iir := Sub_Assoc; Choice : Iir; Last_Choice : Iir; Index_List : Iir_List; Index : Iir; Nbr : Natural; + Staticness : Iir_Staticness; begin -- Find element. Index_List := Get_Index_List (Formal); @@ -440,8 +442,14 @@ package body Sem_Assocs is Index := Get_Nth_Element (Index_List, I); -- Evaluate index. - Index := Eval_Expr (Index); - Replace_Nth_Element (Index_List, I, Index); + Staticness := Get_Expr_Staticness (Index); + if Staticness = Locally then + Index := Eval_Expr (Index); + Replace_Nth_Element (Index_List, I, Index); + else + Error_Msg_Sem ("index expression must be locally static", Index); + Set_Choice_Staticness (Base_Assoc, None); + end if; -- Find index in choice list. Last_Choice := Null_Iir; @@ -476,6 +484,7 @@ package body Sem_Assocs is -- If not found, append it. Choice := Create_Iir (Iir_Kind_Choice_By_Expression); Set_Choice_Expression (Choice, Index); + Set_Choice_Staticness (Choice, Staticness); Location_Copy (Choice, Formal); if Last_Choice = Null_Iir then Set_Individual_Association_Chain (Sub_Assoc, Choice); @@ -492,6 +501,7 @@ package body Sem_Assocs is (Iir_Kind_Association_Element_By_Individual); Location_Copy (Sub_Assoc, Index); Set_Associated_Expr (Choice, Sub_Assoc); + Set_Choice_Staticness (Sub_Assoc, Locally); end if; else Sub_Assoc := Choice; @@ -504,6 +514,7 @@ package body Sem_Assocs is is Choice : Iir; Index : Iir; + Staticness : Iir_Staticness; begin -- FIXME: handle cases such as param(5 to 6)(5) @@ -511,15 +522,20 @@ package body Sem_Assocs is Index := Get_Suffix (Formal); -- Evaluate index. - if Get_Expr_Staticness (Index) = Locally then + Staticness := Get_Expr_Staticness (Index); + if Staticness = Locally then Index := Eval_Range (Index); Set_Suffix (Formal, Index); + else + Error_Msg_Sem ("range expression must be locally static", Index); + Set_Choice_Staticness (Sub_Assoc, None); end if; Choice := Create_Iir (Iir_Kind_Choice_By_Range); Location_Copy (Choice, Formal); Set_Choice_Range (Choice, Index); Set_Chain (Choice, Get_Individual_Association_Chain (Sub_Assoc)); + Set_Choice_Staticness (Choice, Staticness); Set_Individual_Association_Chain (Sub_Assoc, Choice); Sub_Assoc := Choice; @@ -541,11 +557,14 @@ package body Sem_Assocs is procedure Add_Individual_Association_1 (Iassoc : in out Iir; Formal : Iir) is + Base_Assoc : constant Iir := Iassoc; + Formal_Object : constant Iir := Name_To_Object (Formal); Sub : Iir; - Formal_Object : Iir; begin - -- Recurse. - Formal_Object := Name_To_Object (Formal); + pragma Assert + (Get_Kind (Base_Assoc) = Iir_Kind_Association_Element_By_Individual); + + -- Recurse to start from the basename of the formal. case Get_Kind (Formal_Object) is when Iir_Kind_Indexed_Name | Iir_Kind_Slice_Name @@ -565,6 +584,7 @@ package body Sem_Assocs is if Sub = Null_Iir then Sub := Create_Iir (Iir_Kind_Association_Element_By_Individual); Location_Copy (Sub, Formal); + Set_Choice_Staticness (Sub, Locally); Set_Formal (Sub, Iassoc); Set_Associated_Expr (Iassoc, Sub); Iassoc := Sub; @@ -585,6 +605,7 @@ package body Sem_Assocs is Error_Kind ("add_individual_association_1(2)", Iassoc); end case; + Sub := Iassoc; case Get_Kind (Formal_Object) is when Iir_Kind_Indexed_Name => Add_Individual_Assoc_Indexed_Name (Iassoc, Formal_Object); @@ -595,26 +616,32 @@ package body Sem_Assocs is when others => Error_Kind ("add_individual_association_1(3)", Formal); end case; + + if Get_Choice_Staticness (Sub) /= Locally then + -- Propagate error. + Set_Choice_Staticness (Base_Assoc, None); + end if; end Add_Individual_Association_1; -- Insert ASSOC into the tree of individual assoc rooted by IASSOC. procedure Add_Individual_Association (Iassoc : Iir; Assoc : Iir) is - Formal : Iir; - Iass : Iir; + Formal : constant Iir := Get_Formal (Assoc); + Res_Iass : Iir; Prev : Iir; begin - Formal := Get_Formal (Assoc); - Iass := Iassoc; - Add_Individual_Association_1 (Iass, Formal); - Prev := Get_Associated_Expr (Iass); + -- Create the individual association for the formal. + Res_Iass := Iassoc; + Add_Individual_Association_1 (Res_Iass, Formal); + + Prev := Get_Associated_Expr (Res_Iass); if Prev /= Null_Iir then Error_Msg_Sem ("individual association of " & Disp_Node (Get_Association_Interface (Assoc)) & " conflicts with that at " & Disp_Location (Prev), Assoc); else - Set_Associated_Expr (Iass, Assoc); + Set_Associated_Expr (Res_Iass, Assoc); end if; end Add_Individual_Association; @@ -623,15 +650,14 @@ package body Sem_Assocs is is Index_Tlist : constant Iir_List := Get_Index_Subtype_List (Atype); Nbr_Dims : constant Natural := Get_Nbr_Elements (Index_Tlist); - Index_Type : Iir; + Index_Type : constant Iir := Get_Nth_Element (Index_Tlist, Dim - 1); Low, High : Iir; Chain : Iir; El : Iir; begin - Index_Type := Get_Nth_Element (Index_Tlist, Dim - 1); Chain := Get_Individual_Association_Chain (Assoc); - Sem_Choices_Range - (Chain, Index_Type, False, False, Get_Location (Assoc), Low, High); + Sem_Check_Continuous_Choices + (Chain, Index_Type, False, Get_Location (Assoc), Low, High); Set_Individual_Association_Chain (Assoc, Chain); if Dim < Nbr_Dims then El := Chain; @@ -763,7 +789,7 @@ package body Sem_Assocs is Atype : Iir; begin -- Guard. - if Assoc = Null_Iir then + if Assoc = Null_Iir or else Get_Choice_Staticness (Assoc) /= Locally then return; end if; @@ -821,9 +847,8 @@ package body Sem_Assocs is Iassoc := Create_Iir (Iir_Kind_Association_Element_By_Individual); Location_Copy (Iassoc, Assoc); - if Cur_Iface = Null_Iir then - raise Internal_Error; - end if; + Set_Choice_Staticness (Iassoc, Locally); + pragma Assert (Cur_Iface /= Null_Iir); Set_Formal (Iassoc, Cur_Iface); -- Insert IASSOC. if Prev_Assoc = Null_Iir then diff --git a/src/vhdl/sem_expr.adb b/src/vhdl/sem_expr.adb index ec796b9..2956019 100644 --- a/src/vhdl/sem_expr.adb +++ b/src/vhdl/sem_expr.adb @@ -2310,17 +2310,19 @@ package body Sem_Expr is end if; end Sem_String_Choices_Range; - procedure Sem_Choices_Range - (Choice_Chain : in out Iir; + procedure Sem_Check_Continuous_Choices + (Choice_Chain : Iir; Sub_Type : Iir; Is_Sub_Range : Boolean; - Is_Case_Stmt : Boolean; Loc : Location_Type; Low : out Iir; High : out Iir) is - -- Number of positionnal choice. - Nbr_Pos : Iir_Int64; + -- Nodes that can appear. + subtype Iir_Kinds_Case_Choice is Iir_Kind range + Iir_Kind_Choice_By_Others .. + --Iir_Kind_Choice_By_Expression + Iir_Kind_Choice_By_Range; -- Number of named choices. Nbr_Named : Natural; @@ -2328,113 +2330,12 @@ package body Sem_Expr is -- True if others choice is present. Has_Others : Boolean; - Has_Error : Boolean; - -- True if SUB_TYPE has bounds. Type_Has_Bounds : Boolean; Arr : Iir_Array_Acc; Index : Natural; - Pos_Max : Iir_Int64; El : Iir; - Prev_El : Iir; - - -- Staticness of the current choice. - Choice_Staticness : Iir_Staticness; - - -- Staticness of all the choices. - Staticness : Iir_Staticness; - - function Replace_By_Range_Choice (Name : Iir; Range_Type : Iir) - return Boolean - is - N_Choice : Iir; - Name1 : Iir; - begin - if Are_Types_Compatible (Range_Type, Sub_Type) = Not_Compatible then - Not_Match (Name, Sub_Type); - return False; - end if; - - Name1 := Finish_Sem_Name (Name); - N_Choice := Create_Iir (Iir_Kind_Choice_By_Range); - Location_Copy (N_Choice, El); - Set_Chain (N_Choice, Get_Chain (El)); - Set_Associated_Expr (N_Choice, Get_Associated_Expr (El)); - Set_Associated_Chain (N_Choice, Get_Associated_Chain (El)); - Set_Same_Alternative_Flag (N_Choice, Get_Same_Alternative_Flag (El)); - Set_Choice_Range (N_Choice, Eval_Range_If_Static (Name1)); - Set_Choice_Staticness (N_Choice, Get_Type_Staticness (Range_Type)); - Free_Iir (El); - - if Prev_El = Null_Iir then - Choice_Chain := N_Choice; - else - Set_Chain (Prev_El, N_Choice); - end if; - El := N_Choice; - - return True; - end Replace_By_Range_Choice; - - -- Analyze a simple (by expression or by range) choice. - -- Return FALSE in case of error. - function Sem_Simple_Choice return Boolean - is - Expr : Iir; - Ent : Iir; - begin - if Get_Kind (El) = Iir_Kind_Choice_By_Range then - Expr := Get_Choice_Range (El); - Expr := Sem_Discrete_Range_Expression (Expr, Sub_Type, True); - if Expr = Null_Iir then - return False; - end if; - Expr := Eval_Range_If_Static (Expr); - Set_Choice_Range (El, Expr); - else - Expr := Get_Choice_Expression (El); - case Get_Kind (Expr) is - when Iir_Kind_Selected_Name - | Iir_Kind_Simple_Name - | Iir_Kind_Character_Literal - | Iir_Kind_Parenthesis_Name - | Iir_Kind_Selected_By_All_Name - | Iir_Kind_Attribute_Name => - Sem_Name (Expr); - Ent := Get_Named_Entity (Expr); - if Ent = Error_Mark then - return False; - end if; - - -- So range or expression ? - -- FIXME: share code with sem_name for slice/index. - case Get_Kind (Ent) is - when Iir_Kind_Range_Array_Attribute - | Iir_Kind_Reverse_Range_Array_Attribute - | Iir_Kind_Range_Expression => - return Replace_By_Range_Choice (Expr, Ent); - when Iir_Kind_Subtype_Declaration - | Iir_Kind_Type_Declaration => - Ent := Is_Type_Name (Expr); - Set_Expr_Staticness (Expr, Get_Type_Staticness (Ent)); - return Replace_By_Range_Choice (Expr, Ent); - when others => - Expr := Name_To_Expression - (Expr, Get_Base_Type (Sub_Type)); - end case; - when others => - Expr := Sem_Expression_Ov (Expr, Get_Base_Type (Sub_Type)); - end case; - if Expr = Null_Iir then - return False; - end if; - Expr := Eval_Expr_If_Static (Expr); - Set_Choice_Expression (El, Expr); - end if; - Set_Choice_Staticness (El, Get_Expr_Staticness (Expr)); - return True; - end Sem_Simple_Choice; -- Get low limit of ASSOC. -- First, get the expression of the association, then the low limit. @@ -2452,12 +2353,7 @@ package body Sem_Expr is Expr := Get_Choice_Range (Assoc); case Get_Kind (Expr) is when Iir_Kind_Range_Expression => - case Get_Direction (Expr) is - when Iir_To => - return Get_Left_Limit (Expr); - when Iir_Downto => - return Get_Right_Limit (Expr); - end case; + return Get_Low_Limit (Expr); when others => return Expr; end case; @@ -2477,12 +2373,7 @@ package body Sem_Expr is Expr := Get_Choice_Range (Assoc); case Get_Kind (Expr) is when Iir_Kind_Range_Expression => - case Get_Direction (Expr) is - when Iir_To => - return Get_Right_Limit (Expr); - when Iir_Downto => - return Get_Left_Limit (Expr); - end case; + return Get_High_Limit (Expr); when others => return Expr; end case; @@ -2514,112 +2405,23 @@ package body Sem_Expr is Low := Null_Iir; High := Null_Iir; - -- First: - -- Analyze the choices - -- compute the range of positionnal choices - -- compute the number of choice elements (extracted from lists). - -- check for others presence. - Nbr_Pos := 0; + -- Compute the number of elements, return early if a choice is not + -- static. Nbr_Named := 0; Has_Others := False; - Has_Error := False; - Staticness := Locally; El := Choice_Chain; - Prev_El := Null_Iir; while El /= Null_Iir loop - case Get_Kind (El) is - when Iir_Kind_Choice_By_None => - Nbr_Pos := Nbr_Pos + 1; + case Iir_Kinds_Case_Choice (Get_Kind (El)) is when Iir_Kind_Choice_By_Expression | Iir_Kind_Choice_By_Range => - if Sem_Simple_Choice then - Choice_Staticness := Get_Choice_Staticness (El); - Staticness := Min (Staticness, Choice_Staticness); - if Choice_Staticness /= Locally - and then Is_Case_Stmt - then - -- FIXME: explain why - Error_Msg_Sem ("choice is not locally static", El); - end if; - else - Has_Error := True; - end if; + pragma Assert (Get_Choice_Staticness (El) = Locally); Nbr_Named := Nbr_Named + 1; - when Iir_Kind_Choice_By_Name => - -- It is not possible to have such a choice in an array - -- aggregate. - -- Should have been caught previously. - raise Internal_Error; when Iir_Kind_Choice_By_Others => - if Has_Others then - Error_Msg_Sem ("duplicate others choice", El); - elsif Get_Chain (El) /= Null_Iir then - Error_Msg_Sem - ("choice others should be the last alternative", El); - end if; Has_Others := True; - when others => - Error_Kind ("sem_choices_range", El); end case; - Prev_El := El; El := Get_Chain (El); end loop; - if Has_Error then - -- Nothing can be done here... - return; - end if; - if Nbr_Pos > 0 and then Nbr_Named > 0 then - -- LRM93 7.3.2.2 - -- Apart from the final element with the single choice OTHERS, the - -- rest (if any) of the element associations of an array aggregate - -- must be either all positionnal or all named. - Error_Msg_Sem - ("element associations must be all positional or all named", Loc); - return; - end if; - - -- For a positional aggregate. - if Nbr_Pos > 0 then - -- Check number of elements match, but only if it is possible. - if Get_Type_Staticness (Sub_Type) /= Locally then - return; - end if; - Pos_Max := Eval_Discrete_Type_Length (Sub_Type); - if (not Has_Others and not Is_Sub_Range) - and then Nbr_Pos < Pos_Max - then - Error_Msg_Sem ("not enough elements associated", Loc); - elsif Nbr_Pos > Pos_Max then - Error_Msg_Sem ("too many elements associated", Loc); - end if; - return; - end if; - - -- Second: - -- Create the list of choices - if Nbr_Named = 0 and then Has_Others then - -- This is only a others association. - return; - end if; - if Staticness /= Locally then - -- Emit a message for aggregrate. The message has already been - -- emitted for a case stmt. - -- FIXME: what about individual associations? - if not Is_Case_Stmt then - -- LRM93 §7.3.2.2 - -- A named association of an array aggregate is allowed to have - -- a choice that is not locally static, or likewise a choice that - -- is a null range, only if the aggregate includes a single - -- element association and the element association has a single - -- choice. - if Nbr_Named > 1 or Has_Others then - Error_Msg_Sem ("not static choice exclude others choice", Loc); - end if; - end if; - return; - end if; - -- Set TYPE_HAS_BOUNDS case Get_Kind (Sub_Type) is when Iir_Kind_Enumeration_Type_Definition @@ -2670,17 +2472,12 @@ package body Sem_Expr is -- Fill the array. El := Choice_Chain; while El /= Null_Iir loop - case Get_Kind (El) is - when Iir_Kind_Choice_By_None => - -- Only named associations are considered. - raise Internal_Error; + case Iir_Kinds_Case_Choice (Get_Kind (El)) is when Iir_Kind_Choice_By_Expression | Iir_Kind_Choice_By_Range => Add_Choice (El, Sub_Type); when Iir_Kind_Choice_By_Others => null; - when others => - Error_Kind ("sem_choices_range(2)", El); end case; El := Get_Chain (El); end loop; @@ -2779,6 +2576,240 @@ package body Sem_Expr is end; Free (Arr); + end Sem_Check_Continuous_Choices; + + procedure Sem_Choices_Range + (Choice_Chain : in out Iir; + Sub_Type : Iir; + Is_Sub_Range : Boolean; + Is_Case_Stmt : Boolean; + Loc : Location_Type; + Low : out Iir; + High : out Iir) + is + -- Number of positionnal choice. + Nbr_Pos : Iir_Int64; + + -- Number of named choices. + Nbr_Named : Natural; + + -- True if others choice is present. + Has_Others : Boolean; + + Has_Error : Boolean; + + Pos_Max : Iir_Int64; + El : Iir; + Prev_El : Iir; + + -- Staticness of the current choice. + Choice_Staticness : Iir_Staticness; + + -- Staticness of all the choices. + Staticness : Iir_Staticness; + + function Replace_By_Range_Choice (Name : Iir; Range_Type : Iir) + return Boolean + is + N_Choice : Iir; + Name1 : Iir; + begin + if Are_Types_Compatible (Range_Type, Sub_Type) = Not_Compatible then + Not_Match (Name, Sub_Type); + return False; + end if; + + Name1 := Finish_Sem_Name (Name); + N_Choice := Create_Iir (Iir_Kind_Choice_By_Range); + Location_Copy (N_Choice, El); + Set_Chain (N_Choice, Get_Chain (El)); + Set_Associated_Expr (N_Choice, Get_Associated_Expr (El)); + Set_Associated_Chain (N_Choice, Get_Associated_Chain (El)); + Set_Same_Alternative_Flag (N_Choice, Get_Same_Alternative_Flag (El)); + Set_Choice_Range (N_Choice, Eval_Range_If_Static (Name1)); + Set_Choice_Staticness (N_Choice, Get_Type_Staticness (Range_Type)); + Free_Iir (El); + + if Prev_El = Null_Iir then + Choice_Chain := N_Choice; + else + Set_Chain (Prev_El, N_Choice); + end if; + El := N_Choice; + + return True; + end Replace_By_Range_Choice; + + -- Analyze a simple (by expression or by range) choice. + -- Return FALSE in case of error. + function Sem_Simple_Choice return Boolean + is + Expr : Iir; + Ent : Iir; + begin + if Get_Kind (El) = Iir_Kind_Choice_By_Range then + Expr := Get_Choice_Range (El); + Expr := Sem_Discrete_Range_Expression (Expr, Sub_Type, True); + if Expr = Null_Iir then + return False; + end if; + Expr := Eval_Range_If_Static (Expr); + Set_Choice_Range (El, Expr); + else + Expr := Get_Choice_Expression (El); + case Get_Kind (Expr) is + when Iir_Kind_Selected_Name + | Iir_Kind_Simple_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Parenthesis_Name + | Iir_Kind_Selected_By_All_Name + | Iir_Kind_Attribute_Name => + Sem_Name (Expr); + Ent := Get_Named_Entity (Expr); + if Ent = Error_Mark then + return False; + end if; + + -- So range or expression ? + -- FIXME: share code with sem_name for slice/index. + case Get_Kind (Ent) is + when Iir_Kind_Range_Array_Attribute + | Iir_Kind_Reverse_Range_Array_Attribute + | Iir_Kind_Range_Expression => + return Replace_By_Range_Choice (Expr, Ent); + when Iir_Kind_Subtype_Declaration + | Iir_Kind_Type_Declaration => + Ent := Is_Type_Name (Expr); + Set_Expr_Staticness (Expr, Get_Type_Staticness (Ent)); + return Replace_By_Range_Choice (Expr, Ent); + when others => + Expr := Name_To_Expression + (Expr, Get_Base_Type (Sub_Type)); + end case; + when others => + Expr := Sem_Expression_Ov (Expr, Get_Base_Type (Sub_Type)); + end case; + if Expr = Null_Iir then + return False; + end if; + Expr := Eval_Expr_If_Static (Expr); + Set_Choice_Expression (El, Expr); + end if; + Set_Choice_Staticness (El, Get_Expr_Staticness (Expr)); + return True; + end Sem_Simple_Choice; + begin + Low := Null_Iir; + High := Null_Iir; + + -- First: + -- Analyze the choices + -- compute the range of positionnal choices + -- compute the number of choice elements (extracted from lists). + -- check for others presence. + Nbr_Pos := 0; + Nbr_Named := 0; + Has_Others := False; + Has_Error := False; + Staticness := Locally; + El := Choice_Chain; + Prev_El := Null_Iir; + while El /= Null_Iir loop + case Get_Kind (El) is + when Iir_Kind_Choice_By_None => + Nbr_Pos := Nbr_Pos + 1; + when Iir_Kind_Choice_By_Expression + | Iir_Kind_Choice_By_Range => + if Sem_Simple_Choice then + Choice_Staticness := Get_Choice_Staticness (El); + Staticness := Min (Staticness, Choice_Staticness); + if Choice_Staticness /= Locally + and then Is_Case_Stmt + then + -- FIXME: explain why + Error_Msg_Sem ("choice is not locally static", El); + end if; + else + Has_Error := True; + end if; + Nbr_Named := Nbr_Named + 1; + when Iir_Kind_Choice_By_Name => + -- It is not possible to have such a choice in an array + -- aggregate. + -- Should have been caught previously. + raise Internal_Error; + when Iir_Kind_Choice_By_Others => + if Has_Others then + Error_Msg_Sem ("duplicate others choice", El); + elsif Get_Chain (El) /= Null_Iir then + Error_Msg_Sem + ("choice others should be the last alternative", El); + end if; + Has_Others := True; + when others => + Error_Kind ("sem_choices_range", El); + end case; + Prev_El := El; + El := Get_Chain (El); + end loop; + + if Has_Error then + -- Nothing can be done here... + return; + end if; + if Nbr_Pos > 0 and then Nbr_Named > 0 then + -- LRM93 7.3.2.2 + -- Apart from the final element with the single choice OTHERS, the + -- rest (if any) of the element associations of an array aggregate + -- must be either all positionnal or all named. + Error_Msg_Sem + ("element associations must be all positional or all named", Loc); + return; + end if; + + -- For a positional aggregate. + if Nbr_Pos > 0 then + -- Check number of elements match, but only if it is possible. + if Get_Type_Staticness (Sub_Type) /= Locally then + return; + end if; + Pos_Max := Eval_Discrete_Type_Length (Sub_Type); + if (not Has_Others and not Is_Sub_Range) + and then Nbr_Pos < Pos_Max + then + Error_Msg_Sem ("not enough elements associated", Loc); + elsif Nbr_Pos > Pos_Max then + Error_Msg_Sem ("too many elements associated", Loc); + end if; + return; + end if; + + -- Second: + -- Create the list of choices + if Nbr_Named = 0 and then Has_Others then + -- This is only a others association. + return; + end if; + if Staticness /= Locally then + -- Emit a message for aggregrate. The message has already been + -- emitted for a case stmt. + -- FIXME: what about individual associations? + if not Is_Case_Stmt then + -- LRM93 §7.3.2.2 + -- A named association of an array aggregate is allowed to have + -- a choice that is not locally static, or likewise a choice that + -- is a null range, only if the aggregate includes a single + -- element association and the element association has a single + -- choice. + if Nbr_Named > 1 or Has_Others then + Error_Msg_Sem ("not static choice exclude others choice", Loc); + end if; + end if; + return; + end if; + + Sem_Check_Continuous_Choices + (Choice_Chain, Sub_Type, Is_Sub_Range, Loc, Low, High); end Sem_Choices_Range; -- -- Find out the MIN and the MAX of an all named association choice list. diff --git a/src/vhdl/sem_expr.ads b/src/vhdl/sem_expr.ads index 1a1c32b..5d84902 100644 --- a/src/vhdl/sem_expr.ads +++ b/src/vhdl/sem_expr.ads @@ -164,6 +164,19 @@ package Sem_Expr is Low : out Iir; High : out Iir); + -- Check that the values of CHOICE_CHAIN are a continuous range, and + -- extract the lower LOW and upper HIGH bound (useful to create the + -- corresponding subtype). The values must be of type SUB_TYPE, and if + -- IS_SUB_RANGE True, they must be within SUB_TYPE. + -- The choices must be locally static. + procedure Sem_Check_Continuous_Choices + (Choice_Chain : Iir; + Sub_Type : Iir; + Is_Sub_Range : Boolean; + Loc : Location_Type; + Low : out Iir; + High : out Iir); + -- Semantize CHOICE_LIST when the choice expression SEL is of a -- one-dimensional character array type. procedure Sem_String_Choices_Range (Choice_Chain : Iir; Sel : Iir); |