diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-05-29 08:45:55 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-05-29 08:45:55 +0200 |
commit | 5035b126d932529683640867cdf8fe686d7f7cac (patch) | |
tree | 7a48dd954794cf10938509a459a5a9cabf7fd86c /src/vhdl | |
parent | 7619ac406427a30e2963e11ad67b43b6aae26ee5 (diff) | |
download | ghdl-5035b126d932529683640867cdf8fe686d7f7cac.tar.gz ghdl-5035b126d932529683640867cdf8fe686d7f7cac.tar.bz2 ghdl-5035b126d932529683640867cdf8fe686d7f7cac.zip |
vhdl-disp_vhdl: print literals and identifiers from the source.
Add Literal_Length and set it in the parser.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/python/libghdl/thin/vhdl/nodes.py | 4 | ||||
-rw-r--r-- | src/vhdl/python/libghdl/thin/vhdl/nodes_meta.py | 586 | ||||
-rw-r--r-- | src/vhdl/vhdl-disp_vhdl.adb | 88 | ||||
-rw-r--r-- | src/vhdl/vhdl-nodes.adb | 16 | ||||
-rw-r--r-- | src/vhdl/vhdl-nodes.ads | 46 | ||||
-rw-r--r-- | src/vhdl/vhdl-nodes_meta.adb | 556 | ||||
-rw-r--r-- | src/vhdl/vhdl-nodes_meta.ads | 2 | ||||
-rw-r--r-- | src/vhdl/vhdl-parse.adb | 20 | ||||
-rw-r--r-- | src/vhdl/vhdl-scanner.adb | 5 | ||||
-rw-r--r-- | src/vhdl/vhdl-scanner.ads | 1 |
10 files changed, 738 insertions, 586 deletions
diff --git a/src/vhdl/python/libghdl/thin/vhdl/nodes.py b/src/vhdl/python/libghdl/thin/vhdl/nodes.py index 07d440896..6ed04bb2a 100644 --- a/src/vhdl/python/libghdl/thin/vhdl/nodes.py +++ b/src/vhdl/python/libghdl/thin/vhdl/nodes.py @@ -1199,6 +1199,10 @@ Get_Has_Length = libghdl.vhdl__nodes__get_has_length Set_Has_Length = libghdl.vhdl__nodes__set_has_length +Get_Literal_Length = libghdl.vhdl__nodes__get_literal_length + +Set_Literal_Length = libghdl.vhdl__nodes__set_literal_length + Get_Literal_Origin = libghdl.vhdl__nodes__get_literal_origin Set_Literal_Origin = libghdl.vhdl__nodes__set_literal_origin diff --git a/src/vhdl/python/libghdl/thin/vhdl/nodes_meta.py b/src/vhdl/python/libghdl/thin/vhdl/nodes_meta.py index 523dc43de..8d717732e 100644 --- a/src/vhdl/python/libghdl/thin/vhdl/nodes_meta.py +++ b/src/vhdl/python/libghdl/thin/vhdl/nodes_meta.py @@ -96,297 +96,298 @@ class fields: Has_Signed = 32 Has_Sign = 33 Has_Length = 34 - Literal_Origin = 35 - Range_Origin = 36 - Literal_Subtype = 37 - Allocator_Subtype = 38 - Entity_Class = 39 - Entity_Name_List = 40 - Attribute_Designator = 41 - Attribute_Specification_Chain = 42 - Attribute_Specification = 43 - Signal_List = 44 - Designated_Entity = 45 - Formal = 46 - Actual = 47 - Actual_Conversion = 48 - Formal_Conversion = 49 - Whole_Association_Flag = 50 - Collapse_Signal_Flag = 51 - Artificial_Flag = 52 - Open_Flag = 53 - After_Drivers_Flag = 54 - We_Value = 55 - Time = 56 - Choice_Order = 57 - Associated_Expr = 58 - Associated_Block = 59 - Associated_Chain = 60 - Choice_Name = 61 - Choice_Expression = 62 - Choice_Range = 63 - Same_Alternative_Flag = 64 - Element_Type_Flag = 65 - Architecture = 66 - Block_Specification = 67 - Prev_Block_Configuration = 68 - Configuration_Item_Chain = 69 - Attribute_Value_Chain = 70 - Spec_Chain = 71 - Value_Chain = 72 - Attribute_Value_Spec_Chain = 73 - Entity_Name = 74 - Package = 75 - Package_Body = 76 - Instance_Package_Body = 77 - Need_Body = 78 - Macro_Expanded_Flag = 79 - Need_Instance_Bodies = 80 - Block_Configuration = 81 - Concurrent_Statement_Chain = 82 - Chain = 83 - Port_Chain = 84 - Generic_Chain = 85 - Type = 86 - Subtype_Indication = 87 - Discrete_Range = 88 - Type_Definition = 89 - Subtype_Definition = 90 - Incomplete_Type_Declaration = 91 - Interface_Type_Subprograms = 92 - Nature = 93 - Mode = 94 - Guarded_Signal_Flag = 95 - Signal_Kind = 96 - Base_Name = 97 - Interface_Declaration_Chain = 98 - Subprogram_Specification = 99 - Sequential_Statement_Chain = 100 - Subprogram_Body = 101 - Overload_Number = 102 - Subprogram_Depth = 103 - Subprogram_Hash = 104 - Impure_Depth = 105 - Return_Type = 106 - Implicit_Definition = 107 - Default_Value = 108 - Deferred_Declaration = 109 - Deferred_Declaration_Flag = 110 - Shared_Flag = 111 - Design_Unit = 112 - Block_Statement = 113 - Signal_Driver = 114 - Declaration_Chain = 115 - File_Logical_Name = 116 - File_Open_Kind = 117 - Element_Position = 118 - Use_Clause_Chain = 119 - Context_Reference_Chain = 120 - Selected_Name = 121 - Type_Declarator = 122 - Complete_Type_Definition = 123 - Incomplete_Type_Ref_Chain = 124 - Associated_Type = 125 - Enumeration_Literal_List = 126 - Entity_Class_Entry_Chain = 127 - Group_Constituent_List = 128 - Unit_Chain = 129 - Primary_Unit = 130 - Identifier = 131 - Label = 132 - Visible_Flag = 133 - Range_Constraint = 134 - Direction = 135 - Left_Limit = 136 - Right_Limit = 137 - Left_Limit_Expr = 138 - Right_Limit_Expr = 139 - Base_Type = 140 - Resolution_Indication = 141 - Record_Element_Resolution_Chain = 142 - Tolerance = 143 - Plus_Terminal = 144 - Minus_Terminal = 145 - Simultaneous_Left = 146 - Simultaneous_Right = 147 - Text_File_Flag = 148 - Only_Characters_Flag = 149 - Is_Character_Type = 150 - Type_Staticness = 151 - Constraint_State = 152 - Index_Subtype_List = 153 - Index_Subtype_Definition_List = 154 - Element_Subtype_Indication = 155 - Element_Subtype = 156 - Index_Constraint_List = 157 - Array_Element_Constraint = 158 - Elements_Declaration_List = 159 - Owned_Elements_Chain = 160 - Designated_Type = 161 - Designated_Subtype_Indication = 162 - Index_List = 163 - Reference = 164 - Nature_Declarator = 165 - Across_Type = 166 - Through_Type = 167 - Target = 168 - Waveform_Chain = 169 - Guard = 170 - Delay_Mechanism = 171 - Reject_Time_Expression = 172 - Sensitivity_List = 173 - Process_Origin = 174 - Package_Origin = 175 - Condition_Clause = 176 - Timeout_Clause = 177 - Postponed_Flag = 178 - Callees_List = 179 - Passive_Flag = 180 - Resolution_Function_Flag = 181 - Wait_State = 182 - All_Sensitized_State = 183 - Seen_Flag = 184 - Pure_Flag = 185 - Foreign_Flag = 186 - Resolved_Flag = 187 - Signal_Type_Flag = 188 - Has_Signal_Flag = 189 - Purity_State = 190 - Elab_Flag = 191 - Configuration_Mark_Flag = 192 - Configuration_Done_Flag = 193 - Index_Constraint_Flag = 194 - Hide_Implicit_Flag = 195 - Assertion_Condition = 196 - Report_Expression = 197 - Severity_Expression = 198 - Instantiated_Unit = 199 - Generic_Map_Aspect_Chain = 200 - Port_Map_Aspect_Chain = 201 - Configuration_Name = 202 - Component_Configuration = 203 - Configuration_Specification = 204 - Default_Binding_Indication = 205 - Default_Configuration_Declaration = 206 - Expression = 207 - Conditional_Expression = 208 - Allocator_Designated_Type = 209 - Selected_Waveform_Chain = 210 - Conditional_Waveform_Chain = 211 - Guard_Expression = 212 - Guard_Decl = 213 - Guard_Sensitivity_List = 214 - Signal_Attribute_Chain = 215 - Block_Block_Configuration = 216 - Package_Header = 217 - Block_Header = 218 - Uninstantiated_Package_Name = 219 - Uninstantiated_Package_Decl = 220 - Instance_Source_File = 221 - Generate_Block_Configuration = 222 - Generate_Statement_Body = 223 - Alternative_Label = 224 - Generate_Else_Clause = 225 - Condition = 226 - Else_Clause = 227 - Parameter_Specification = 228 - Parent = 229 - Loop_Label = 230 - Component_Name = 231 - Instantiation_List = 232 - Entity_Aspect = 233 - Default_Entity_Aspect = 234 - Binding_Indication = 235 - Named_Entity = 236 - Alias_Declaration = 237 - Referenced_Name = 238 - Expr_Staticness = 239 - Error_Origin = 240 - Operand = 241 - Left = 242 - Right = 243 - Unit_Name = 244 - Name = 245 - Group_Template_Name = 246 - Name_Staticness = 247 - Prefix = 248 - Signature_Prefix = 249 - External_Pathname = 250 - Pathname_Suffix = 251 - Pathname_Expression = 252 - In_Formal_Flag = 253 - Slice_Subtype = 254 - Suffix = 255 - Index_Subtype = 256 - Parameter = 257 - Attr_Chain = 258 - Signal_Attribute_Declaration = 259 - Actual_Type = 260 - Actual_Type_Definition = 261 - Association_Chain = 262 - Individual_Association_Chain = 263 - Subprogram_Association_Chain = 264 - Aggregate_Info = 265 - Sub_Aggregate_Info = 266 - Aggr_Dynamic_Flag = 267 - Aggr_Min_Length = 268 - Aggr_Low_Limit = 269 - Aggr_High_Limit = 270 - Aggr_Others_Flag = 271 - Aggr_Named_Flag = 272 - Aggregate_Expand_Flag = 273 - Association_Choices_Chain = 274 - Case_Statement_Alternative_Chain = 275 - Choice_Staticness = 276 - Procedure_Call = 277 - Implementation = 278 - Parameter_Association_Chain = 279 - Method_Object = 280 - Subtype_Type_Mark = 281 - Type_Conversion_Subtype = 282 - Type_Mark = 283 - File_Type_Mark = 284 - Return_Type_Mark = 285 - Has_Disconnect_Flag = 286 - Has_Active_Flag = 287 - Is_Within_Flag = 288 - Type_Marks_List = 289 - Implicit_Alias_Flag = 290 - Alias_Signature = 291 - Attribute_Signature = 292 - Overload_List = 293 - Simple_Name_Identifier = 294 - Simple_Name_Subtype = 295 - Protected_Type_Body = 296 - Protected_Type_Declaration = 297 - Use_Flag = 298 - End_Has_Reserved_Id = 299 - End_Has_Identifier = 300 - End_Has_Postponed = 301 - Has_Label = 302 - Has_Begin = 303 - Has_End = 304 - Has_Is = 305 - Has_Pure = 306 - Has_Body = 307 - Has_Parameter = 308 - Has_Component = 309 - Has_Identifier_List = 310 - Has_Mode = 311 - Has_Class = 312 - Suspend_Flag = 313 - Is_Ref = 314 - Is_Forward_Ref = 315 - Psl_Property = 316 - Psl_Sequence = 317 - Psl_Declaration = 318 - Psl_Expression = 319 - Psl_Boolean = 320 - PSL_Clock = 321 - PSL_NFA = 322 - PSL_Nbr_States = 323 - PSL_Clock_Sensitivity = 324 - PSL_EOS_Flag = 325 + Literal_Length = 35 + Literal_Origin = 36 + Range_Origin = 37 + Literal_Subtype = 38 + Allocator_Subtype = 39 + Entity_Class = 40 + Entity_Name_List = 41 + Attribute_Designator = 42 + Attribute_Specification_Chain = 43 + Attribute_Specification = 44 + Signal_List = 45 + Designated_Entity = 46 + Formal = 47 + Actual = 48 + Actual_Conversion = 49 + Formal_Conversion = 50 + Whole_Association_Flag = 51 + Collapse_Signal_Flag = 52 + Artificial_Flag = 53 + Open_Flag = 54 + After_Drivers_Flag = 55 + We_Value = 56 + Time = 57 + Choice_Order = 58 + Associated_Expr = 59 + Associated_Block = 60 + Associated_Chain = 61 + Choice_Name = 62 + Choice_Expression = 63 + Choice_Range = 64 + Same_Alternative_Flag = 65 + Element_Type_Flag = 66 + Architecture = 67 + Block_Specification = 68 + Prev_Block_Configuration = 69 + Configuration_Item_Chain = 70 + Attribute_Value_Chain = 71 + Spec_Chain = 72 + Value_Chain = 73 + Attribute_Value_Spec_Chain = 74 + Entity_Name = 75 + Package = 76 + Package_Body = 77 + Instance_Package_Body = 78 + Need_Body = 79 + Macro_Expanded_Flag = 80 + Need_Instance_Bodies = 81 + Block_Configuration = 82 + Concurrent_Statement_Chain = 83 + Chain = 84 + Port_Chain = 85 + Generic_Chain = 86 + Type = 87 + Subtype_Indication = 88 + Discrete_Range = 89 + Type_Definition = 90 + Subtype_Definition = 91 + Incomplete_Type_Declaration = 92 + Interface_Type_Subprograms = 93 + Nature = 94 + Mode = 95 + Guarded_Signal_Flag = 96 + Signal_Kind = 97 + Base_Name = 98 + Interface_Declaration_Chain = 99 + Subprogram_Specification = 100 + Sequential_Statement_Chain = 101 + Subprogram_Body = 102 + Overload_Number = 103 + Subprogram_Depth = 104 + Subprogram_Hash = 105 + Impure_Depth = 106 + Return_Type = 107 + Implicit_Definition = 108 + Default_Value = 109 + Deferred_Declaration = 110 + Deferred_Declaration_Flag = 111 + Shared_Flag = 112 + Design_Unit = 113 + Block_Statement = 114 + Signal_Driver = 115 + Declaration_Chain = 116 + File_Logical_Name = 117 + File_Open_Kind = 118 + Element_Position = 119 + Use_Clause_Chain = 120 + Context_Reference_Chain = 121 + Selected_Name = 122 + Type_Declarator = 123 + Complete_Type_Definition = 124 + Incomplete_Type_Ref_Chain = 125 + Associated_Type = 126 + Enumeration_Literal_List = 127 + Entity_Class_Entry_Chain = 128 + Group_Constituent_List = 129 + Unit_Chain = 130 + Primary_Unit = 131 + Identifier = 132 + Label = 133 + Visible_Flag = 134 + Range_Constraint = 135 + Direction = 136 + Left_Limit = 137 + Right_Limit = 138 + Left_Limit_Expr = 139 + Right_Limit_Expr = 140 + Base_Type = 141 + Resolution_Indication = 142 + Record_Element_Resolution_Chain = 143 + Tolerance = 144 + Plus_Terminal = 145 + Minus_Terminal = 146 + Simultaneous_Left = 147 + Simultaneous_Right = 148 + Text_File_Flag = 149 + Only_Characters_Flag = 150 + Is_Character_Type = 151 + Type_Staticness = 152 + Constraint_State = 153 + Index_Subtype_List = 154 + Index_Subtype_Definition_List = 155 + Element_Subtype_Indication = 156 + Element_Subtype = 157 + Index_Constraint_List = 158 + Array_Element_Constraint = 159 + Elements_Declaration_List = 160 + Owned_Elements_Chain = 161 + Designated_Type = 162 + Designated_Subtype_Indication = 163 + Index_List = 164 + Reference = 165 + Nature_Declarator = 166 + Across_Type = 167 + Through_Type = 168 + Target = 169 + Waveform_Chain = 170 + Guard = 171 + Delay_Mechanism = 172 + Reject_Time_Expression = 173 + Sensitivity_List = 174 + Process_Origin = 175 + Package_Origin = 176 + Condition_Clause = 177 + Timeout_Clause = 178 + Postponed_Flag = 179 + Callees_List = 180 + Passive_Flag = 181 + Resolution_Function_Flag = 182 + Wait_State = 183 + All_Sensitized_State = 184 + Seen_Flag = 185 + Pure_Flag = 186 + Foreign_Flag = 187 + Resolved_Flag = 188 + Signal_Type_Flag = 189 + Has_Signal_Flag = 190 + Purity_State = 191 + Elab_Flag = 192 + Configuration_Mark_Flag = 193 + Configuration_Done_Flag = 194 + Index_Constraint_Flag = 195 + Hide_Implicit_Flag = 196 + Assertion_Condition = 197 + Report_Expression = 198 + Severity_Expression = 199 + Instantiated_Unit = 200 + Generic_Map_Aspect_Chain = 201 + Port_Map_Aspect_Chain = 202 + Configuration_Name = 203 + Component_Configuration = 204 + Configuration_Specification = 205 + Default_Binding_Indication = 206 + Default_Configuration_Declaration = 207 + Expression = 208 + Conditional_Expression = 209 + Allocator_Designated_Type = 210 + Selected_Waveform_Chain = 211 + Conditional_Waveform_Chain = 212 + Guard_Expression = 213 + Guard_Decl = 214 + Guard_Sensitivity_List = 215 + Signal_Attribute_Chain = 216 + Block_Block_Configuration = 217 + Package_Header = 218 + Block_Header = 219 + Uninstantiated_Package_Name = 220 + Uninstantiated_Package_Decl = 221 + Instance_Source_File = 222 + Generate_Block_Configuration = 223 + Generate_Statement_Body = 224 + Alternative_Label = 225 + Generate_Else_Clause = 226 + Condition = 227 + Else_Clause = 228 + Parameter_Specification = 229 + Parent = 230 + Loop_Label = 231 + Component_Name = 232 + Instantiation_List = 233 + Entity_Aspect = 234 + Default_Entity_Aspect = 235 + Binding_Indication = 236 + Named_Entity = 237 + Alias_Declaration = 238 + Referenced_Name = 239 + Expr_Staticness = 240 + Error_Origin = 241 + Operand = 242 + Left = 243 + Right = 244 + Unit_Name = 245 + Name = 246 + Group_Template_Name = 247 + Name_Staticness = 248 + Prefix = 249 + Signature_Prefix = 250 + External_Pathname = 251 + Pathname_Suffix = 252 + Pathname_Expression = 253 + In_Formal_Flag = 254 + Slice_Subtype = 255 + Suffix = 256 + Index_Subtype = 257 + Parameter = 258 + Attr_Chain = 259 + Signal_Attribute_Declaration = 260 + Actual_Type = 261 + Actual_Type_Definition = 262 + Association_Chain = 263 + Individual_Association_Chain = 264 + Subprogram_Association_Chain = 265 + Aggregate_Info = 266 + Sub_Aggregate_Info = 267 + Aggr_Dynamic_Flag = 268 + Aggr_Min_Length = 269 + Aggr_Low_Limit = 270 + Aggr_High_Limit = 271 + Aggr_Others_Flag = 272 + Aggr_Named_Flag = 273 + Aggregate_Expand_Flag = 274 + Association_Choices_Chain = 275 + Case_Statement_Alternative_Chain = 276 + Choice_Staticness = 277 + Procedure_Call = 278 + Implementation = 279 + Parameter_Association_Chain = 280 + Method_Object = 281 + Subtype_Type_Mark = 282 + Type_Conversion_Subtype = 283 + Type_Mark = 284 + File_Type_Mark = 285 + Return_Type_Mark = 286 + Has_Disconnect_Flag = 287 + Has_Active_Flag = 288 + Is_Within_Flag = 289 + Type_Marks_List = 290 + Implicit_Alias_Flag = 291 + Alias_Signature = 292 + Attribute_Signature = 293 + Overload_List = 294 + Simple_Name_Identifier = 295 + Simple_Name_Subtype = 296 + Protected_Type_Body = 297 + Protected_Type_Declaration = 298 + Use_Flag = 299 + End_Has_Reserved_Id = 300 + End_Has_Identifier = 301 + End_Has_Postponed = 302 + Has_Label = 303 + Has_Begin = 304 + Has_End = 305 + Has_Is = 306 + Has_Pure = 307 + Has_Body = 308 + Has_Parameter = 309 + Has_Component = 310 + Has_Identifier_List = 311 + Has_Mode = 312 + Has_Class = 313 + Suspend_Flag = 314 + Is_Ref = 315 + Is_Forward_Ref = 316 + Psl_Property = 317 + Psl_Sequence = 318 + Psl_Declaration = 319 + Psl_Expression = 320 + Psl_Boolean = 321 + PSL_Clock = 322 + PSL_NFA = 323 + PSL_Nbr_States = 324 + PSL_Clock_Sensitivity = 325 + PSL_EOS_Flag = 326 Get_Boolean = libghdl.vhdl__nodes_meta__get_boolean @@ -557,6 +558,9 @@ Has_Has_Sign =\ Has_Has_Length =\ libghdl.vhdl__nodes_meta__has_has_length +Has_Literal_Length =\ + libghdl.vhdl__nodes_meta__has_literal_length + Has_Literal_Origin =\ libghdl.vhdl__nodes_meta__has_literal_origin diff --git a/src/vhdl/vhdl-disp_vhdl.adb b/src/vhdl/vhdl-disp_vhdl.adb index cdcce46a3..b1b9e698c 100644 --- a/src/vhdl/vhdl-disp_vhdl.adb +++ b/src/vhdl/vhdl-disp_vhdl.adb @@ -26,6 +26,7 @@ with Flags; use Flags; with Name_Table; with Str_Table; with Std_Names; use Std_Names; +with Files_Map; with Vhdl.Errors; use Vhdl.Errors; with Vhdl.Utils; use Vhdl.Utils; with Vhdl.Std_Package; @@ -138,11 +139,53 @@ package body Vhdl.Disp_Vhdl is return R; end Or_Else; - procedure Disp_Identifier (Ctxt : in out Ctxt_Class; Node : Iir) is - begin - Disp_Ident (Ctxt, Get_Identifier (Node)); + -- Disp a literal from the sources (so using exactely the same characters). + procedure Disp_From_Source + (Ctxt : in out Ctxt_Class; + Loc : Location_Type; Len : Int32; Tok : Token_Type) + is + use Files_Map; + pragma Assert (Len > 0); + File : Source_File_Entry; + Pos : Source_Ptr; + Buf : File_Buffer_Acc; + begin + Location_To_File_Pos (Loc, File, Pos); + Buf := Get_File_Source (File); + Start_Lit (Ctxt, Tok); + for I in 1 .. Len loop + Disp_Char (Ctxt, Buf (Pos)); + Pos := Pos + 1; + end loop; + Close_Lit (Ctxt); + end Disp_From_Source; + + procedure Disp_Identifier (Ctxt : in out Ctxt_Class; Node : Iir) + is + use Name_Table; + Id : constant Name_Id := Get_Identifier (Node); + Loc : constant Location_Type := Get_Location (Node); + begin + -- Try to display the one from the sources. + if Id /= Null_Identifier + and then not Is_Character (Id) + and then Loc /= No_Location + and then Loc /= Std_Package.Std_Location + then + Disp_From_Source + (Ctxt, Loc, Int32 (Get_Name_Length (Id)), Tok_Identifier); + else + Disp_Ident (Ctxt, Id); + end if; end Disp_Identifier; + procedure Disp_Literal_From_Source + (Ctxt : in out Ctxt_Class; Lit : Iir; Tok : Token_Type) is + begin + Disp_From_Source + (Ctxt, Get_Location (Lit), Get_Literal_Length (Lit), Tok); + end Disp_Literal_From_Source; + procedure Disp_Function_Name (Ctxt : in out Ctxt_Class; Func: Iir) is use Name_Table; @@ -654,13 +697,22 @@ package body Vhdl.Disp_Vhdl is procedure Disp_Physical_Literal (Ctxt : in out Ctxt_Class; Lit: Iir) is + Len : constant Int32 := Get_Literal_Length (Lit); Unit : Iir; begin case Iir_Kinds_Physical_Literal (Get_Kind (Lit)) is when Iir_Kind_Physical_Int_Literal => - Disp_Int64 (Ctxt, Get_Value (Lit)); + if Len /= 0 then + Disp_Literal_From_Source (Ctxt, Lit, Tok_Integer); + else + Disp_Int64 (Ctxt, Get_Value (Lit)); + end if; when Iir_Kind_Physical_Fp_Literal => - Disp_Fp64 (Ctxt, Get_Fp_Value (Lit)); + if Len /= 0 then + Disp_Literal_From_Source (Ctxt, Lit, Tok_Real); + else + Disp_Fp64 (Ctxt, Get_Fp_Value (Lit)); + end if; end case; Unit := Get_Unit_Name (Lit); @@ -1921,7 +1973,7 @@ package body Vhdl.Disp_Vhdl is Label: constant Name_Id := Get_Label (Stmt); begin if Label /= Null_Identifier then - Disp_Ident (Ctxt, Label); + Disp_Identifier (Ctxt, Stmt); Disp_Token (Ctxt, Tok_Colon); end if; end Disp_Label; @@ -2866,7 +2918,7 @@ package body Vhdl.Disp_Vhdl is Disp_Token (Ctxt, Tok_Right_Paren); end Disp_Parametered_Type_Attribute; - procedure Disp_String_Literal + procedure Disp_String_Literal_Raw (Ctxt : in out Ctxt_Class; Str : Iir; El_Type : Iir) is Str_Id : constant String8_Id := Get_String8_Id (Str); @@ -2912,6 +2964,16 @@ package body Vhdl.Disp_Vhdl is Disp_Char (Ctxt, '"'); Close_Lit (Ctxt); + end Disp_String_Literal_Raw; + + procedure Disp_String_Literal + (Ctxt : in out Ctxt_Class; Str : Iir; El_Type : Iir) is + begin + if Get_Literal_Length (Str) /= 0 then + Disp_Literal_From_Source (Ctxt, Str, Tok_String); + else + Disp_String_Literal_Raw (Ctxt, Str, El_Type); + end if; end Disp_String_Literal; procedure Print (Ctxt : in out Ctxt_Class; Expr: Iir) @@ -2924,14 +2986,22 @@ package body Vhdl.Disp_Vhdl is if Dump_Origin_Flag and then Orig /= Null_Iir then Print (Ctxt, Orig); else - Disp_Int64 (Ctxt, Get_Value (Expr)); + if Get_Literal_Length (Expr) /= 0 then + Disp_Literal_From_Source (Ctxt, Expr, Tok_Integer); + else + Disp_Int64 (Ctxt, Get_Value (Expr)); + end if; end if; when Iir_Kind_Floating_Point_Literal => Orig := Get_Literal_Origin (Expr); if Dump_Origin_Flag and then Orig /= Null_Iir then Print (Ctxt, Orig); else - Disp_Fp64 (Ctxt, Get_Fp_Value (Expr)); + if Get_Literal_Length (Expr) /= 0 then + Disp_Literal_From_Source (Ctxt, Expr, Tok_Real); + else + Disp_Fp64 (Ctxt, Get_Fp_Value (Expr)); + end if; end if; when Iir_Kind_String_Literal8 => Orig := Get_Literal_Origin (Expr); diff --git a/src/vhdl/vhdl-nodes.adb b/src/vhdl/vhdl-nodes.adb index 40048a84f..85755105e 100644 --- a/src/vhdl/vhdl-nodes.adb +++ b/src/vhdl/vhdl-nodes.adb @@ -1875,6 +1875,22 @@ package body Vhdl.Nodes is Set_Flag3 (Lit, Flag); end Set_Has_Length; + function Get_Literal_Length (Lit : Iir) return Int32 is + begin + pragma Assert (Lit /= Null_Iir); + pragma Assert (Has_Literal_Length (Get_Kind (Lit)), + "no field Literal_Length"); + return Iir_To_Int32 (Get_Field0 (Lit)); + end Get_Literal_Length; + + procedure Set_Literal_Length (Lit : Iir; Len : Int32) is + begin + pragma Assert (Lit /= Null_Iir); + pragma Assert (Has_Literal_Length (Get_Kind (Lit)), + "no field Literal_Length"); + Set_Field0 (Lit, Int32_To_Iir (Len)); + end Set_Literal_Length; + function Get_Literal_Origin (Lit : Iir) return Iir is begin pragma Assert (Lit /= Null_Iir); diff --git a/src/vhdl/vhdl-nodes.ads b/src/vhdl/vhdl-nodes.ads index 8e20bf830..97e7d706f 100644 --- a/src/vhdl/vhdl-nodes.ads +++ b/src/vhdl/vhdl-nodes.ads @@ -300,6 +300,15 @@ package Vhdl.Nodes is -- Iir_Kind_String_Literal8 (Short) -- + -- Number of literals in the expanded string. + -- Get/Set_String_Length (Field4) + -- + -- Before analysis, this is the ASCII code of each character in the string. + -- After analysis, this is the position of each literal. + -- Get/Set_String8_Id (Field5) + -- + -- Get/Set_Literal_Length (Field0) + -- -- Used for computed literals. Literal_Origin contains the expression -- whose value was computed during analysis and replaces the expression. -- Get/Set_Literal_Origin (Field2) @@ -309,13 +318,6 @@ package Vhdl.Nodes is -- -- Get/Set_Type (Field1) -- - -- Number of literals in the expanded string. - -- Get/Set_String_Length (Field4) - -- - -- Before analysis, this is the ASCII code of each character in the string. - -- After analysis, this is the position of each literal. - -- Get/Set_String8_Id (Field5) - -- -- Base of the bit_string (corresponds to letters 'b', 'o', 'd' or 'x' in -- the base specifier). -- Get/Set_Bit_String_Base (Flag12,Flag13,Flag14) @@ -337,6 +339,8 @@ package Vhdl.Nodes is -- Get/Set the value of the integer. -- Get/Set_Value (Field4,Field5) -- + -- Get/Set_Literal_Length (Field0) + -- -- Get/Set_Literal_Origin (Field2) -- -- Get/Set_Type (Field1) @@ -348,6 +352,8 @@ package Vhdl.Nodes is -- The value of the literal. -- Get/Set_Fp_Value (Field4,Field5) -- + -- Get/Set_Literal_Length (Field0) + -- -- Get/Set_Literal_Origin (Field2) -- -- Get/Set_Type (Field1) @@ -364,23 +370,25 @@ package Vhdl.Nodes is -- Iir_Kind_Physical_Int_Literal (Short) -- Iir_Kind_Physical_Fp_Literal (Short) -- - -- Get/Set_Literal_Origin (Field2) + -- Only for Iir_Kind_Physical_Int_Literal: + -- The multiplicand. + -- Get/Set_Value (Field4,Field5) + -- + -- Only for Iir_Kind_Physical_Fp_Literal: + -- The multiplicand. + -- Get/Set_Fp_Value (Field4,Field5) -- -- The name of the physical unit. -- Get/Set_Unit_Name (Field3) -- + -- Get/Set_Literal_Length (Field0) + -- + -- Get/Set_Literal_Origin (Field2) + -- -- Get/Set_Type (Field1) -- -- Must be set to locally except for time literal, which is globally. -- Get/Set_Expr_Staticness (State1) - -- - -- Only for Iir_Kind_Physical_Int_Literal: - -- The multiplicand. - -- Get/Set_Value (Field4,Field5) - -- - -- Only for Iir_Kind_Physical_Fp_Literal: - -- The multiplicand. - -- Get/Set_Fp_Value (Field4,Field5) -- Iir_Kind_Simple_Aggregate (Short) -- This node can only be generated by evaluation: it is an unidimentional @@ -6077,6 +6085,12 @@ package Vhdl.Nodes is function Get_Has_Length (Lit : Iir) return Boolean; procedure Set_Has_Length (Lit : Iir; Flag : Boolean); + -- Length of the literal in characters. Used for pretty print. Set to 0 + -- when doesn't come from the sources. + -- Field: Field0 (uc) + function Get_Literal_Length (Lit : Iir) return Int32; + procedure Set_Literal_Length (Lit : Iir; Len : Int32); + -- The origin of a literal can be null_iir for a literal generated by the -- parser, or a node which was statically evaluated to this literal. -- Such nodes are created by eval_expr. diff --git a/src/vhdl/vhdl-nodes_meta.adb b/src/vhdl/vhdl-nodes_meta.adb index be9ab31d8..5c55f608a 100644 --- a/src/vhdl/vhdl-nodes_meta.adb +++ b/src/vhdl/vhdl-nodes_meta.adb @@ -54,6 +54,7 @@ package body Vhdl.Nodes_Meta is Field_Has_Signed => Type_Boolean, Field_Has_Sign => Type_Boolean, Field_Has_Length => Type_Boolean, + Field_Literal_Length => Type_Int32, Field_Literal_Origin => Type_Iir, Field_Range_Origin => Type_Iir, Field_Literal_Subtype => Type_Iir, @@ -425,6 +426,8 @@ package body Vhdl.Nodes_Meta is return "has_sign"; when Field_Has_Length => return "has_length"; + when Field_Literal_Length => + return "literal_length"; when Field_Literal_Origin => return "literal_origin"; when Field_Range_Origin => @@ -1627,6 +1630,8 @@ package body Vhdl.Nodes_Meta is return Attr_None; when Field_Has_Length => return Attr_None; + when Field_Literal_Length => + return Attr_None; when Field_Literal_Origin => return Attr_None; when Field_Range_Origin => @@ -2270,11 +2275,13 @@ package body Vhdl.Nodes_Meta is Field_Chain, Field_Context_Reference_Chain, -- Iir_Kind_Integer_Literal + Field_Literal_Length, Field_Value, Field_Expr_Staticness, Field_Literal_Origin, Field_Type, -- Iir_Kind_Floating_Point_Literal + Field_Literal_Length, Field_Fp_Value, Field_Expr_Staticness, Field_Literal_Origin, @@ -2283,6 +2290,7 @@ package body Vhdl.Nodes_Meta is Field_Expr_Staticness, Field_Type, -- Iir_Kind_String_Literal8 + Field_Literal_Length, Field_String_Length, Field_String8_Id, Field_Has_Signed, @@ -2294,16 +2302,18 @@ package body Vhdl.Nodes_Meta is Field_Literal_Subtype, Field_Type, -- Iir_Kind_Physical_Int_Literal + Field_Literal_Length, Field_Value, Field_Expr_Staticness, - Field_Literal_Origin, Field_Unit_Name, + Field_Literal_Origin, Field_Type, -- Iir_Kind_Physical_Fp_Literal + Field_Literal_Length, Field_Fp_Value, Field_Expr_Staticness, - Field_Literal_Origin, Field_Unit_Name, + Field_Literal_Origin, Field_Type, -- Iir_Kind_Simple_Aggregate Field_Expr_Staticness, @@ -4425,268 +4435,268 @@ package body Vhdl.Nodes_Meta is Iir_Kind_Library_Clause => 39, Iir_Kind_Use_Clause => 43, Iir_Kind_Context_Reference => 47, - Iir_Kind_Integer_Literal => 51, - Iir_Kind_Floating_Point_Literal => 55, - Iir_Kind_Null_Literal => 57, - Iir_Kind_String_Literal8 => 67, - Iir_Kind_Physical_Int_Literal => 72, - Iir_Kind_Physical_Fp_Literal => 77, - Iir_Kind_Simple_Aggregate => 82, - Iir_Kind_Overflow_Literal => 85, - Iir_Kind_Unaffected_Waveform => 86, - Iir_Kind_Waveform_Element => 89, - Iir_Kind_Conditional_Waveform => 93, - Iir_Kind_Conditional_Expression => 97, - Iir_Kind_Association_Element_By_Expression => 105, - Iir_Kind_Association_Element_By_Individual => 114, - Iir_Kind_Association_Element_Open => 120, - Iir_Kind_Association_Element_Package => 126, - Iir_Kind_Association_Element_Type => 134, - Iir_Kind_Association_Element_Subprogram => 140, - Iir_Kind_Choice_By_Range => 149, - Iir_Kind_Choice_By_Expression => 158, - Iir_Kind_Choice_By_Others => 165, - Iir_Kind_Choice_By_None => 172, - Iir_Kind_Choice_By_Name => 180, - Iir_Kind_Entity_Aspect_Entity => 182, - Iir_Kind_Entity_Aspect_Configuration => 183, - Iir_Kind_Entity_Aspect_Open => 183, - Iir_Kind_Block_Configuration => 189, - Iir_Kind_Block_Header => 193, - Iir_Kind_Component_Configuration => 200, - Iir_Kind_Binding_Indication => 204, - Iir_Kind_Entity_Class => 206, - Iir_Kind_Attribute_Value => 214, - Iir_Kind_Signature => 217, - Iir_Kind_Aggregate_Info => 224, - Iir_Kind_Procedure_Call => 228, - Iir_Kind_Record_Element_Constraint => 234, - Iir_Kind_Array_Element_Resolution => 236, - Iir_Kind_Record_Resolution => 237, - Iir_Kind_Record_Element_Resolution => 240, - Iir_Kind_Attribute_Specification => 248, - Iir_Kind_Disconnection_Specification => 254, - Iir_Kind_Configuration_Specification => 260, - Iir_Kind_Access_Type_Definition => 268, - Iir_Kind_Incomplete_Type_Definition => 276, - Iir_Kind_Interface_Type_Definition => 283, - Iir_Kind_File_Type_Definition => 290, - Iir_Kind_Protected_Type_Declaration => 299, - Iir_Kind_Record_Type_Definition => 310, - Iir_Kind_Array_Type_Definition => 322, - Iir_Kind_Array_Subtype_Definition => 337, - Iir_Kind_Record_Subtype_Definition => 350, - Iir_Kind_Access_Subtype_Definition => 358, - Iir_Kind_Physical_Subtype_Definition => 368, - Iir_Kind_Floating_Subtype_Definition => 379, - Iir_Kind_Integer_Subtype_Definition => 389, - Iir_Kind_Enumeration_Subtype_Definition => 399, - Iir_Kind_Enumeration_Type_Definition => 410, - Iir_Kind_Integer_Type_Definition => 418, - Iir_Kind_Floating_Type_Definition => 426, - Iir_Kind_Physical_Type_Definition => 437, - Iir_Kind_Range_Expression => 445, - Iir_Kind_Protected_Type_Body => 452, - Iir_Kind_Wildcard_Type_Definition => 457, - Iir_Kind_Subtype_Definition => 464, - Iir_Kind_Scalar_Nature_Definition => 468, - Iir_Kind_Overload_List => 469, - Iir_Kind_Type_Declaration => 476, - Iir_Kind_Anonymous_Type_Declaration => 482, - Iir_Kind_Subtype_Declaration => 489, - Iir_Kind_Nature_Declaration => 495, - Iir_Kind_Subnature_Declaration => 501, - Iir_Kind_Entity_Declaration => 513, - Iir_Kind_Configuration_Declaration => 522, - Iir_Kind_Context_Declaration => 528, - Iir_Kind_Package_Declaration => 543, - Iir_Kind_Package_Instantiation_Declaration => 557, - Iir_Kind_Package_Body => 565, - Iir_Kind_Architecture_Body => 577, - Iir_Kind_Package_Header => 579, - Iir_Kind_Unit_Declaration => 588, - Iir_Kind_Library_Declaration => 595, - Iir_Kind_Component_Declaration => 605, - Iir_Kind_Attribute_Declaration => 612, - Iir_Kind_Group_Template_Declaration => 618, - Iir_Kind_Group_Declaration => 625, - Iir_Kind_Element_Declaration => 632, - Iir_Kind_Non_Object_Alias_Declaration => 640, - Iir_Kind_Psl_Declaration => 648, - Iir_Kind_Psl_Endpoint_Declaration => 662, - Iir_Kind_Terminal_Declaration => 669, - Iir_Kind_Free_Quantity_Declaration => 680, - Iir_Kind_Across_Quantity_Declaration => 692, - Iir_Kind_Through_Quantity_Declaration => 704, - Iir_Kind_Enumeration_Literal => 715, - Iir_Kind_Function_Declaration => 740, - Iir_Kind_Procedure_Declaration => 764, - Iir_Kind_Function_Body => 774, - Iir_Kind_Procedure_Body => 785, - Iir_Kind_Object_Alias_Declaration => 796, - Iir_Kind_File_Declaration => 810, - Iir_Kind_Guard_Signal_Declaration => 823, - Iir_Kind_Signal_Declaration => 840, - Iir_Kind_Variable_Declaration => 853, - Iir_Kind_Constant_Declaration => 867, - Iir_Kind_Iterator_Declaration => 878, - Iir_Kind_Interface_Constant_Declaration => 894, - Iir_Kind_Interface_Variable_Declaration => 910, - Iir_Kind_Interface_Signal_Declaration => 931, - Iir_Kind_Interface_File_Declaration => 947, - Iir_Kind_Interface_Type_Declaration => 957, - Iir_Kind_Interface_Package_Declaration => 969, - Iir_Kind_Interface_Function_Declaration => 986, - Iir_Kind_Interface_Procedure_Declaration => 999, - Iir_Kind_Signal_Attribute_Declaration => 1002, - Iir_Kind_Identity_Operator => 1006, - Iir_Kind_Negation_Operator => 1010, - Iir_Kind_Absolute_Operator => 1014, - Iir_Kind_Not_Operator => 1018, - Iir_Kind_Implicit_Condition_Operator => 1022, - Iir_Kind_Condition_Operator => 1026, - Iir_Kind_Reduction_And_Operator => 1030, - Iir_Kind_Reduction_Or_Operator => 1034, - Iir_Kind_Reduction_Nand_Operator => 1038, - Iir_Kind_Reduction_Nor_Operator => 1042, - Iir_Kind_Reduction_Xor_Operator => 1046, - Iir_Kind_Reduction_Xnor_Operator => 1050, - Iir_Kind_And_Operator => 1055, - Iir_Kind_Or_Operator => 1060, - Iir_Kind_Nand_Operator => 1065, - Iir_Kind_Nor_Operator => 1070, - Iir_Kind_Xor_Operator => 1075, - Iir_Kind_Xnor_Operator => 1080, - Iir_Kind_Equality_Operator => 1085, - Iir_Kind_Inequality_Operator => 1090, - Iir_Kind_Less_Than_Operator => 1095, - Iir_Kind_Less_Than_Or_Equal_Operator => 1100, - Iir_Kind_Greater_Than_Operator => 1105, - Iir_Kind_Greater_Than_Or_Equal_Operator => 1110, - Iir_Kind_Match_Equality_Operator => 1115, - Iir_Kind_Match_Inequality_Operator => 1120, - Iir_Kind_Match_Less_Than_Operator => 1125, - Iir_Kind_Match_Less_Than_Or_Equal_Operator => 1130, - Iir_Kind_Match_Greater_Than_Operator => 1135, - Iir_Kind_Match_Greater_Than_Or_Equal_Operator => 1140, - Iir_Kind_Sll_Operator => 1145, - Iir_Kind_Sla_Operator => 1150, - Iir_Kind_Srl_Operator => 1155, - Iir_Kind_Sra_Operator => 1160, - Iir_Kind_Rol_Operator => 1165, - Iir_Kind_Ror_Operator => 1170, - Iir_Kind_Addition_Operator => 1175, - Iir_Kind_Substraction_Operator => 1180, - Iir_Kind_Concatenation_Operator => 1185, - Iir_Kind_Multiplication_Operator => 1190, - Iir_Kind_Division_Operator => 1195, - Iir_Kind_Modulus_Operator => 1200, - Iir_Kind_Remainder_Operator => 1205, - Iir_Kind_Exponentiation_Operator => 1210, - Iir_Kind_Function_Call => 1218, - Iir_Kind_Aggregate => 1225, - Iir_Kind_Parenthesis_Expression => 1228, - Iir_Kind_Qualified_Expression => 1232, - Iir_Kind_Type_Conversion => 1237, - Iir_Kind_Allocator_By_Expression => 1241, - Iir_Kind_Allocator_By_Subtype => 1246, - Iir_Kind_Selected_Element => 1254, - Iir_Kind_Dereference => 1259, - Iir_Kind_Implicit_Dereference => 1264, - Iir_Kind_Slice_Name => 1271, - Iir_Kind_Indexed_Name => 1277, - Iir_Kind_Psl_Expression => 1279, - Iir_Kind_Sensitized_Process_Statement => 1300, - Iir_Kind_Process_Statement => 1320, - Iir_Kind_Concurrent_Simple_Signal_Assignment => 1332, - Iir_Kind_Concurrent_Conditional_Signal_Assignment => 1344, - Iir_Kind_Concurrent_Selected_Signal_Assignment => 1357, - Iir_Kind_Concurrent_Assertion_Statement => 1365, - Iir_Kind_Concurrent_Procedure_Call_Statement => 1372, - Iir_Kind_Psl_Assert_Statement => 1385, - Iir_Kind_Psl_Cover_Statement => 1398, - Iir_Kind_Block_Statement => 1412, - Iir_Kind_If_Generate_Statement => 1423, - Iir_Kind_Case_Generate_Statement => 1432, - Iir_Kind_For_Generate_Statement => 1441, - Iir_Kind_Component_Instantiation_Statement => 1452, - Iir_Kind_Psl_Default_Clock => 1456, - Iir_Kind_Simple_Simultaneous_Statement => 1463, - Iir_Kind_Generate_Statement_Body => 1474, - Iir_Kind_If_Generate_Else_Clause => 1480, - Iir_Kind_Simple_Signal_Assignment_Statement => 1490, - Iir_Kind_Conditional_Signal_Assignment_Statement => 1500, - Iir_Kind_Selected_Waveform_Assignment_Statement => 1511, - Iir_Kind_Null_Statement => 1515, - Iir_Kind_Assertion_Statement => 1522, - Iir_Kind_Report_Statement => 1528, - Iir_Kind_Wait_Statement => 1536, - Iir_Kind_Variable_Assignment_Statement => 1543, - Iir_Kind_Conditional_Variable_Assignment_Statement => 1550, - Iir_Kind_Return_Statement => 1556, - Iir_Kind_For_Loop_Statement => 1565, - Iir_Kind_While_Loop_Statement => 1574, - Iir_Kind_Next_Statement => 1581, - Iir_Kind_Exit_Statement => 1588, - Iir_Kind_Case_Statement => 1596, - Iir_Kind_Procedure_Call_Statement => 1602, - Iir_Kind_If_Statement => 1612, - Iir_Kind_Elsif => 1618, - Iir_Kind_Character_Literal => 1626, - Iir_Kind_Simple_Name => 1634, - Iir_Kind_Selected_Name => 1643, - Iir_Kind_Operator_Symbol => 1649, - Iir_Kind_Reference_Name => 1652, - Iir_Kind_External_Constant_Name => 1660, - Iir_Kind_External_Signal_Name => 1668, - Iir_Kind_External_Variable_Name => 1677, - Iir_Kind_Selected_By_All_Name => 1683, - Iir_Kind_Parenthesis_Name => 1688, - Iir_Kind_Package_Pathname => 1692, - Iir_Kind_Absolute_Pathname => 1693, - Iir_Kind_Relative_Pathname => 1694, - Iir_Kind_Pathname_Element => 1699, - Iir_Kind_Base_Attribute => 1701, - Iir_Kind_Subtype_Attribute => 1706, - Iir_Kind_Element_Attribute => 1711, - Iir_Kind_Left_Type_Attribute => 1716, - Iir_Kind_Right_Type_Attribute => 1721, - Iir_Kind_High_Type_Attribute => 1726, - Iir_Kind_Low_Type_Attribute => 1731, - Iir_Kind_Ascending_Type_Attribute => 1736, - Iir_Kind_Image_Attribute => 1742, - Iir_Kind_Value_Attribute => 1748, - Iir_Kind_Pos_Attribute => 1754, - Iir_Kind_Val_Attribute => 1760, - Iir_Kind_Succ_Attribute => 1766, - Iir_Kind_Pred_Attribute => 1772, - Iir_Kind_Leftof_Attribute => 1778, - Iir_Kind_Rightof_Attribute => 1784, - Iir_Kind_Delayed_Attribute => 1793, - Iir_Kind_Stable_Attribute => 1802, - Iir_Kind_Quiet_Attribute => 1811, - Iir_Kind_Transaction_Attribute => 1820, - Iir_Kind_Event_Attribute => 1824, - Iir_Kind_Active_Attribute => 1828, - Iir_Kind_Last_Event_Attribute => 1832, - Iir_Kind_Last_Active_Attribute => 1836, - Iir_Kind_Last_Value_Attribute => 1840, - Iir_Kind_Driving_Attribute => 1844, - Iir_Kind_Driving_Value_Attribute => 1848, - Iir_Kind_Behavior_Attribute => 1848, - Iir_Kind_Structure_Attribute => 1848, - Iir_Kind_Simple_Name_Attribute => 1855, - Iir_Kind_Instance_Name_Attribute => 1860, - Iir_Kind_Path_Name_Attribute => 1865, - Iir_Kind_Left_Array_Attribute => 1872, - Iir_Kind_Right_Array_Attribute => 1879, - Iir_Kind_High_Array_Attribute => 1886, - Iir_Kind_Low_Array_Attribute => 1893, - Iir_Kind_Length_Array_Attribute => 1900, - Iir_Kind_Ascending_Array_Attribute => 1907, - Iir_Kind_Range_Array_Attribute => 1914, - Iir_Kind_Reverse_Range_Array_Attribute => 1921, - Iir_Kind_Attribute_Name => 1930 + Iir_Kind_Integer_Literal => 52, + Iir_Kind_Floating_Point_Literal => 57, + Iir_Kind_Null_Literal => 59, + Iir_Kind_String_Literal8 => 70, + Iir_Kind_Physical_Int_Literal => 76, + Iir_Kind_Physical_Fp_Literal => 82, + Iir_Kind_Simple_Aggregate => 87, + Iir_Kind_Overflow_Literal => 90, + Iir_Kind_Unaffected_Waveform => 91, + Iir_Kind_Waveform_Element => 94, + Iir_Kind_Conditional_Waveform => 98, + Iir_Kind_Conditional_Expression => 102, + Iir_Kind_Association_Element_By_Expression => 110, + Iir_Kind_Association_Element_By_Individual => 119, + Iir_Kind_Association_Element_Open => 125, + Iir_Kind_Association_Element_Package => 131, + Iir_Kind_Association_Element_Type => 139, + Iir_Kind_Association_Element_Subprogram => 145, + Iir_Kind_Choice_By_Range => 154, + Iir_Kind_Choice_By_Expression => 163, + Iir_Kind_Choice_By_Others => 170, + Iir_Kind_Choice_By_None => 177, + Iir_Kind_Choice_By_Name => 185, + Iir_Kind_Entity_Aspect_Entity => 187, + Iir_Kind_Entity_Aspect_Configuration => 188, + Iir_Kind_Entity_Aspect_Open => 188, + Iir_Kind_Block_Configuration => 194, + Iir_Kind_Block_Header => 198, + Iir_Kind_Component_Configuration => 205, + Iir_Kind_Binding_Indication => 209, + Iir_Kind_Entity_Class => 211, + Iir_Kind_Attribute_Value => 219, + Iir_Kind_Signature => 222, + Iir_Kind_Aggregate_Info => 229, + Iir_Kind_Procedure_Call => 233, + Iir_Kind_Record_Element_Constraint => 239, + Iir_Kind_Array_Element_Resolution => 241, + Iir_Kind_Record_Resolution => 242, + Iir_Kind_Record_Element_Resolution => 245, + Iir_Kind_Attribute_Specification => 253, + Iir_Kind_Disconnection_Specification => 259, + Iir_Kind_Configuration_Specification => 265, + Iir_Kind_Access_Type_Definition => 273, + Iir_Kind_Incomplete_Type_Definition => 281, + Iir_Kind_Interface_Type_Definition => 288, + Iir_Kind_File_Type_Definition => 295, + Iir_Kind_Protected_Type_Declaration => 304, + Iir_Kind_Record_Type_Definition => 315, + Iir_Kind_Array_Type_Definition => 327, + Iir_Kind_Array_Subtype_Definition => 342, + Iir_Kind_Record_Subtype_Definition => 355, + Iir_Kind_Access_Subtype_Definition => 363, + Iir_Kind_Physical_Subtype_Definition => 373, + Iir_Kind_Floating_Subtype_Definition => 384, + Iir_Kind_Integer_Subtype_Definition => 394, + Iir_Kind_Enumeration_Subtype_Definition => 404, + Iir_Kind_Enumeration_Type_Definition => 415, + Iir_Kind_Integer_Type_Definition => 423, + Iir_Kind_Floating_Type_Definition => 431, + Iir_Kind_Physical_Type_Definition => 442, + Iir_Kind_Range_Expression => 450, + Iir_Kind_Protected_Type_Body => 457, + Iir_Kind_Wildcard_Type_Definition => 462, + Iir_Kind_Subtype_Definition => 469, + Iir_Kind_Scalar_Nature_Definition => 473, + Iir_Kind_Overload_List => 474, + Iir_Kind_Type_Declaration => 481, + Iir_Kind_Anonymous_Type_Declaration => 487, + Iir_Kind_Subtype_Declaration => 494, + Iir_Kind_Nature_Declaration => 500, + Iir_Kind_Subnature_Declaration => 506, + Iir_Kind_Entity_Declaration => 518, + Iir_Kind_Configuration_Declaration => 527, + Iir_Kind_Context_Declaration => 533, + Iir_Kind_Package_Declaration => 548, + Iir_Kind_Package_Instantiation_Declaration => 562, + Iir_Kind_Package_Body => 570, + Iir_Kind_Architecture_Body => 582, + Iir_Kind_Package_Header => 584, + Iir_Kind_Unit_Declaration => 593, + Iir_Kind_Library_Declaration => 600, + Iir_Kind_Component_Declaration => 610, + Iir_Kind_Attribute_Declaration => 617, + Iir_Kind_Group_Template_Declaration => 623, + Iir_Kind_Group_Declaration => 630, + Iir_Kind_Element_Declaration => 637, + Iir_Kind_Non_Object_Alias_Declaration => 645, + Iir_Kind_Psl_Declaration => 653, + Iir_Kind_Psl_Endpoint_Declaration => 667, + Iir_Kind_Terminal_Declaration => 674, + Iir_Kind_Free_Quantity_Declaration => 685, + Iir_Kind_Across_Quantity_Declaration => 697, + Iir_Kind_Through_Quantity_Declaration => 709, + Iir_Kind_Enumeration_Literal => 720, + Iir_Kind_Function_Declaration => 745, + Iir_Kind_Procedure_Declaration => 769, + Iir_Kind_Function_Body => 779, + Iir_Kind_Procedure_Body => 790, + Iir_Kind_Object_Alias_Declaration => 801, + Iir_Kind_File_Declaration => 815, + Iir_Kind_Guard_Signal_Declaration => 828, + Iir_Kind_Signal_Declaration => 845, + Iir_Kind_Variable_Declaration => 858, + Iir_Kind_Constant_Declaration => 872, + Iir_Kind_Iterator_Declaration => 883, + Iir_Kind_Interface_Constant_Declaration => 899, + Iir_Kind_Interface_Variable_Declaration => 915, + Iir_Kind_Interface_Signal_Declaration => 936, + Iir_Kind_Interface_File_Declaration => 952, + Iir_Kind_Interface_Type_Declaration => 962, + Iir_Kind_Interface_Package_Declaration => 974, + Iir_Kind_Interface_Function_Declaration => 991, + Iir_Kind_Interface_Procedure_Declaration => 1004, + Iir_Kind_Signal_Attribute_Declaration => 1007, + Iir_Kind_Identity_Operator => 1011, + Iir_Kind_Negation_Operator => 1015, + Iir_Kind_Absolute_Operator => 1019, + Iir_Kind_Not_Operator => 1023, + Iir_Kind_Implicit_Condition_Operator => 1027, + Iir_Kind_Condition_Operator => 1031, + Iir_Kind_Reduction_And_Operator => 1035, + Iir_Kind_Reduction_Or_Operator => 1039, + Iir_Kind_Reduction_Nand_Operator => 1043, + Iir_Kind_Reduction_Nor_Operator => 1047, + Iir_Kind_Reduction_Xor_Operator => 1051, + Iir_Kind_Reduction_Xnor_Operator => 1055, + Iir_Kind_And_Operator => 1060, + Iir_Kind_Or_Operator => 1065, + Iir_Kind_Nand_Operator => 1070, + Iir_Kind_Nor_Operator => 1075, + Iir_Kind_Xor_Operator => 1080, + Iir_Kind_Xnor_Operator => 1085, + Iir_Kind_Equality_Operator => 1090, + Iir_Kind_Inequality_Operator => 1095, + Iir_Kind_Less_Than_Operator => 1100, + Iir_Kind_Less_Than_Or_Equal_Operator => 1105, + Iir_Kind_Greater_Than_Operator => 1110, + Iir_Kind_Greater_Than_Or_Equal_Operator => 1115, + Iir_Kind_Match_Equality_Operator => 1120, + Iir_Kind_Match_Inequality_Operator => 1125, + Iir_Kind_Match_Less_Than_Operator => 1130, + Iir_Kind_Match_Less_Than_Or_Equal_Operator => 1135, + Iir_Kind_Match_Greater_Than_Operator => 1140, + Iir_Kind_Match_Greater_Than_Or_Equal_Operator => 1145, + Iir_Kind_Sll_Operator => 1150, + Iir_Kind_Sla_Operator => 1155, + Iir_Kind_Srl_Operator => 1160, + Iir_Kind_Sra_Operator => 1165, + Iir_Kind_Rol_Operator => 1170, + Iir_Kind_Ror_Operator => 1175, + Iir_Kind_Addition_Operator => 1180, + Iir_Kind_Substraction_Operator => 1185, + Iir_Kind_Concatenation_Operator => 1190, + Iir_Kind_Multiplication_Operator => 1195, + Iir_Kind_Division_Operator => 1200, + Iir_Kind_Modulus_Operator => 1205, + Iir_Kind_Remainder_Operator => 1210, + Iir_Kind_Exponentiation_Operator => 1215, + Iir_Kind_Function_Call => 1223, + Iir_Kind_Aggregate => 1230, + Iir_Kind_Parenthesis_Expression => 1233, + Iir_Kind_Qualified_Expression => 1237, + Iir_Kind_Type_Conversion => 1242, + Iir_Kind_Allocator_By_Expression => 1246, + Iir_Kind_Allocator_By_Subtype => 1251, + Iir_Kind_Selected_Element => 1259, + Iir_Kind_Dereference => 1264, + Iir_Kind_Implicit_Dereference => 1269, + Iir_Kind_Slice_Name => 1276, + Iir_Kind_Indexed_Name => 1282, + Iir_Kind_Psl_Expression => 1284, + Iir_Kind_Sensitized_Process_Statement => 1305, + Iir_Kind_Process_Statement => 1325, + Iir_Kind_Concurrent_Simple_Signal_Assignment => 1337, + Iir_Kind_Concurrent_Conditional_Signal_Assignment => 1349, + Iir_Kind_Concurrent_Selected_Signal_Assignment => 1362, + Iir_Kind_Concurrent_Assertion_Statement => 1370, + Iir_Kind_Concurrent_Procedure_Call_Statement => 1377, + Iir_Kind_Psl_Assert_Statement => 1390, + Iir_Kind_Psl_Cover_Statement => 1403, + Iir_Kind_Block_Statement => 1417, + Iir_Kind_If_Generate_Statement => 1428, + Iir_Kind_Case_Generate_Statement => 1437, + Iir_Kind_For_Generate_Statement => 1446, + Iir_Kind_Component_Instantiation_Statement => 1457, + Iir_Kind_Psl_Default_Clock => 1461, + Iir_Kind_Simple_Simultaneous_Statement => 1468, + Iir_Kind_Generate_Statement_Body => 1479, + Iir_Kind_If_Generate_Else_Clause => 1485, + Iir_Kind_Simple_Signal_Assignment_Statement => 1495, + Iir_Kind_Conditional_Signal_Assignment_Statement => 1505, + Iir_Kind_Selected_Waveform_Assignment_Statement => 1516, + Iir_Kind_Null_Statement => 1520, + Iir_Kind_Assertion_Statement => 1527, + Iir_Kind_Report_Statement => 1533, + Iir_Kind_Wait_Statement => 1541, + Iir_Kind_Variable_Assignment_Statement => 1548, + Iir_Kind_Conditional_Variable_Assignment_Statement => 1555, + Iir_Kind_Return_Statement => 1561, + Iir_Kind_For_Loop_Statement => 1570, + Iir_Kind_While_Loop_Statement => 1579, + Iir_Kind_Next_Statement => 1586, + Iir_Kind_Exit_Statement => 1593, + Iir_Kind_Case_Statement => 1601, + Iir_Kind_Procedure_Call_Statement => 1607, + Iir_Kind_If_Statement => 1617, + Iir_Kind_Elsif => 1623, + Iir_Kind_Character_Literal => 1631, + Iir_Kind_Simple_Name => 1639, + Iir_Kind_Selected_Name => 1648, + Iir_Kind_Operator_Symbol => 1654, + Iir_Kind_Reference_Name => 1657, + Iir_Kind_External_Constant_Name => 1665, + Iir_Kind_External_Signal_Name => 1673, + Iir_Kind_External_Variable_Name => 1682, + Iir_Kind_Selected_By_All_Name => 1688, + Iir_Kind_Parenthesis_Name => 1693, + Iir_Kind_Package_Pathname => 1697, + Iir_Kind_Absolute_Pathname => 1698, + Iir_Kind_Relative_Pathname => 1699, + Iir_Kind_Pathname_Element => 1704, + Iir_Kind_Base_Attribute => 1706, + Iir_Kind_Subtype_Attribute => 1711, + Iir_Kind_Element_Attribute => 1716, + Iir_Kind_Left_Type_Attribute => 1721, + Iir_Kind_Right_Type_Attribute => 1726, + Iir_Kind_High_Type_Attribute => 1731, + Iir_Kind_Low_Type_Attribute => 1736, + Iir_Kind_Ascending_Type_Attribute => 1741, + Iir_Kind_Image_Attribute => 1747, + Iir_Kind_Value_Attribute => 1753, + Iir_Kind_Pos_Attribute => 1759, + Iir_Kind_Val_Attribute => 1765, + Iir_Kind_Succ_Attribute => 1771, + Iir_Kind_Pred_Attribute => 1777, + Iir_Kind_Leftof_Attribute => 1783, + Iir_Kind_Rightof_Attribute => 1789, + Iir_Kind_Delayed_Attribute => 1798, + Iir_Kind_Stable_Attribute => 1807, + Iir_Kind_Quiet_Attribute => 1816, + Iir_Kind_Transaction_Attribute => 1825, + Iir_Kind_Event_Attribute => 1829, + Iir_Kind_Active_Attribute => 1833, + Iir_Kind_Last_Event_Attribute => 1837, + Iir_Kind_Last_Active_Attribute => 1841, + Iir_Kind_Last_Value_Attribute => 1845, + Iir_Kind_Driving_Attribute => 1849, + Iir_Kind_Driving_Value_Attribute => 1853, + Iir_Kind_Behavior_Attribute => 1853, + Iir_Kind_Structure_Attribute => 1853, + Iir_Kind_Simple_Name_Attribute => 1860, + Iir_Kind_Instance_Name_Attribute => 1865, + Iir_Kind_Path_Name_Attribute => 1870, + Iir_Kind_Left_Array_Attribute => 1877, + Iir_Kind_Right_Array_Attribute => 1884, + Iir_Kind_High_Array_Attribute => 1891, + Iir_Kind_Low_Array_Attribute => 1898, + Iir_Kind_Length_Array_Attribute => 1905, + Iir_Kind_Ascending_Array_Attribute => 1912, + Iir_Kind_Range_Array_Attribute => 1919, + Iir_Kind_Reverse_Range_Array_Attribute => 1926, + Iir_Kind_Attribute_Name => 1935 ); function Get_Fields_First (K : Iir_Kind) return Fields_Index is @@ -6295,6 +6305,8 @@ package body Vhdl.Nodes_Meta is return Get_Design_Unit_Source_Col (N); when Field_String_Length => return Get_String_Length (N); + when Field_Literal_Length => + return Get_Literal_Length (N); when Field_Choice_Order => return Get_Choice_Order (N); when Field_PSL_Nbr_States => @@ -6315,6 +6327,8 @@ package body Vhdl.Nodes_Meta is Set_Design_Unit_Source_Col (N, V); when Field_String_Length => Set_String_Length (N, V); + when Field_Literal_Length => + Set_Literal_Length (N, V); when Field_Choice_Order => Set_Choice_Order (N, V); when Field_PSL_Nbr_States => @@ -6849,6 +6863,20 @@ package body Vhdl.Nodes_Meta is return K = Iir_Kind_String_Literal8; end Has_Has_Length; + function Has_Literal_Length (K : Iir_Kind) return Boolean is + begin + case K is + when Iir_Kind_Integer_Literal + | Iir_Kind_Floating_Point_Literal + | Iir_Kind_String_Literal8 + | Iir_Kind_Physical_Int_Literal + | Iir_Kind_Physical_Fp_Literal => + return True; + when others => + return False; + end case; + end Has_Literal_Length; + function Has_Literal_Origin (K : Iir_Kind) return Boolean is begin case K is diff --git a/src/vhdl/vhdl-nodes_meta.ads b/src/vhdl/vhdl-nodes_meta.ads index 55804ab15..c9cfe3a99 100644 --- a/src/vhdl/vhdl-nodes_meta.ads +++ b/src/vhdl/vhdl-nodes_meta.ads @@ -96,6 +96,7 @@ package Vhdl.Nodes_Meta is Field_Has_Signed, Field_Has_Sign, Field_Has_Length, + Field_Literal_Length, Field_Literal_Origin, Field_Range_Origin, Field_Literal_Subtype, @@ -623,6 +624,7 @@ package Vhdl.Nodes_Meta is function Has_Has_Signed (K : Iir_Kind) return Boolean; function Has_Has_Sign (K : Iir_Kind) return Boolean; function Has_Has_Length (K : Iir_Kind) return Boolean; + function Has_Literal_Length (K : Iir_Kind) return Boolean; function Has_Literal_Origin (K : Iir_Kind) return Boolean; function Has_Range_Origin (K : Iir_Kind) return Boolean; function Has_Literal_Subtype (K : Iir_Kind) return Boolean; diff --git a/src/vhdl/vhdl-parse.adb b/src/vhdl/vhdl-parse.adb index e10be4998..d227d9b9f 100644 --- a/src/vhdl/vhdl-parse.adb +++ b/src/vhdl/vhdl-parse.adb @@ -1378,6 +1378,7 @@ package body Vhdl.Parse is Res := Create_Iir (Iir_Kind_String_Literal8); Set_String8_Id (Res, Current_String_Id); Set_String_Length (Res, Current_String_Length); + Set_Literal_Length (Res, Get_Token_Length); Set_Location (Res); -- Skip string @@ -5356,7 +5357,7 @@ package body Vhdl.Parse is -- postcond: tok_bit_string -- -- Simply create the node for a bit string. - function Parse_Bit_String return Iir + function Parse_Bit_String (Len : Int32) return Iir is Res : Iir; B : Number_Base_Type; @@ -5365,6 +5366,7 @@ package body Vhdl.Parse is Set_Location (Res); Set_String8_Id (Res, Current_String_Id); Set_String_Length (Res, Current_String_Length); + Set_Literal_Length (Res, Len + Get_Token_Length); case Get_Bit_String_Sign is when 's' => Set_Has_Sign (Res, True); @@ -5500,7 +5502,7 @@ package body Vhdl.Parse is -- postcond: likewise -- -- Return an integer_literal or a physical_literal. - function Parse_Integer_Literal (Val : Int64) return Iir + function Parse_Integer_Literal (Val : Int64; Len : Int32) return Iir is Res : Iir; begin @@ -5513,6 +5515,7 @@ package body Vhdl.Parse is Res := Create_Iir (Iir_Kind_Integer_Literal); end if; Set_Value (Res, Val); + Set_Literal_Length (Res, Len); return Res; end Parse_Integer_Literal; @@ -5551,22 +5554,25 @@ package body Vhdl.Parse is Int: Int64; Fp: Fp64; Loc: Location_Type; + Len : Int32; begin case Current_Token is when Tok_Integer => Int := Current_Iir_Int64; Loc := Get_Token_Location; + Len := Get_Token_Length; -- Skip integer Scan; - Res := Parse_Integer_Literal (Int); + Res := Parse_Integer_Literal (Int, Len); Set_Location (Res, Loc); return Res; when Tok_Real => Fp := Current_Iir_Fp64; Loc := Get_Token_Location; + Len := Get_Token_Length; -- Skip real Scan; @@ -5581,6 +5587,7 @@ package body Vhdl.Parse is end if; Set_Location (Res, Loc); Set_Fp_Value (Res, Fp); + Set_Literal_Length (Res, Len); return Res; when Tok_Identifier @@ -5631,12 +5638,13 @@ package body Vhdl.Parse is when Tok_Integer_Letter => Int := Current_Iir_Int64; Loc := Get_Token_Location; + Len := Get_Token_Length; -- Skip integer Scan; if Current_Token = Tok_Bit_String then - Res := Parse_Bit_String; + Res := Parse_Bit_String (Len); Set_Has_Length (Res, True); -- Skip bit string @@ -5648,13 +5656,13 @@ package body Vhdl.Parse is Error_Msg_Parse (Get_Token_Location, "space is required between number and unit name"); - Res := Parse_Integer_Literal (Int); + Res := Parse_Integer_Literal (Int, Len); end if; Set_Location (Res, Loc); return Res; when Tok_Bit_String => - Res := Parse_Bit_String; + Res := Parse_Bit_String (0); -- Skip bit string Scan; diff --git a/src/vhdl/vhdl-scanner.adb b/src/vhdl/vhdl-scanner.adb index c17f3553e..1b3243761 100644 --- a/src/vhdl/vhdl-scanner.adb +++ b/src/vhdl/vhdl-scanner.adb @@ -311,6 +311,11 @@ package body Vhdl.Scanner is return Current_Context.Token_Pos; end Get_Token_Position; + function Get_Token_Length return Int32 is + begin + return Int32 (Current_Context.Pos - Current_Context.Token_Pos); + end Get_Token_Length; + function Get_Position return Source_Ptr is begin return Current_Context.Pos; diff --git a/src/vhdl/vhdl-scanner.ads b/src/vhdl/vhdl-scanner.ads index 63d359e97..f0afb1e0c 100644 --- a/src/vhdl/vhdl-scanner.ads +++ b/src/vhdl/vhdl-scanner.ads @@ -122,6 +122,7 @@ package Vhdl.Scanner is function Get_Token_Location return Location_Type; function Get_Token_Offset return Natural; function Get_Token_Position return Source_Ptr; + function Get_Token_Length return Int32; function Get_Current_Coord return Source_Coord_Type; function Get_Token_Coord return Source_Coord_Type; |