aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-12-22 08:03:52 +0100
committerTristan Gingold <tgingold@free.fr>2018-12-22 08:03:52 +0100
commit9f8627a01e41eb50e7e547f1d0da2ecc662da292 (patch)
treea27d5161cdc05d49968196f271d1c28d0c9c545c /src/vhdl
parentd42d7795a70586f7479565b89e8870b25ceb06ba (diff)
downloadghdl-9f8627a01e41eb50e7e547f1d0da2ecc662da292.tar.gz
ghdl-9f8627a01e41eb50e7e547f1d0da2ecc662da292.tar.bz2
ghdl-9f8627a01e41eb50e7e547f1d0da2ecc662da292.zip
analysis: tolerate more parse errors (empty enumeration type).
Diffstat (limited to 'src/vhdl')
-rw-r--r--src/vhdl/iirs_utils.adb13
-rw-r--r--src/vhdl/parse.adb67
-rw-r--r--src/vhdl/sem_types.adb2
3 files changed, 40 insertions, 42 deletions
diff --git a/src/vhdl/iirs_utils.adb b/src/vhdl/iirs_utils.adb
index bc4b7b7e7..6a888911d 100644
--- a/src/vhdl/iirs_utils.adb
+++ b/src/vhdl/iirs_utils.adb
@@ -774,18 +774,19 @@ package body Iirs_Utils is
is
Range_Expr : Iir_Range_Expression;
Literal_List : constant Iir_Flist := Get_Enumeration_Literal_List (Def);
+ List_Len : constant Natural := Get_Nbr_Elements (Literal_List);
begin
-- Create a constraint.
Range_Expr := Create_Iir (Iir_Kind_Range_Expression);
Location_Copy (Range_Expr, Def);
Set_Type (Range_Expr, Def);
Set_Direction (Range_Expr, Iir_To);
- Set_Left_Limit
- (Range_Expr,
- Get_Nth_Element (Literal_List, 0));
- Set_Right_Limit
- (Range_Expr,
- Get_Nth_Element (Literal_List, Get_Nbr_Elements (Literal_List) - 1));
+ if List_Len >= 1 then
+ Set_Left_Limit
+ (Range_Expr, Get_Nth_Element (Literal_List, 0));
+ Set_Right_Limit
+ (Range_Expr, Get_Nth_Element (Literal_List, List_Len - 1));
+ end if;
Set_Expr_Staticness (Range_Expr, Locally);
Set_Range_Constraint (Def, Range_Expr);
end Create_Range_Constraint_For_Enumeration_Type;
diff --git a/src/vhdl/parse.adb b/src/vhdl/parse.adb
index cb53eb7ca..a0138913e 100644
--- a/src/vhdl/parse.adb
+++ b/src/vhdl/parse.adb
@@ -587,7 +587,7 @@ package body Parse is
end if;
Error_Msg_Parse ("'to' or 'downto' expected");
end if;
- return Null_Iir;
+ return Create_Error (Left);
end case;
end Parse_Range;
@@ -2187,46 +2187,41 @@ package body Parse is
if Current_Token = Tok_Right_Paren then
Error_Msg_Parse ("at least one literal must be declared");
- Scan;
- return Enum_Type;
- end if;
- loop
- if Current_Token /= Tok_Identifier
- and then Current_Token /= Tok_Character
- then
- if Current_Token = Tok_Eof then
- Error_Msg_Parse ("unexpected end of file");
- return Enum_Type;
- end if;
- Error_Msg_Parse ("identifier or character expected");
- end if;
-
- Enum_Lit := Create_Iir (Iir_Kind_Enumeration_Literal);
- Set_Identifier (Enum_Lit, Current_Identifier);
- Set_Parent (Enum_Lit, Parent);
- Set_Location (Enum_Lit);
- Set_Enum_Pos (Enum_Lit, Pos);
+ else
+ loop
+ if Current_Token = Tok_Identifier
+ or Current_Token = Tok_Character
+ then
+ Enum_Lit := Create_Iir (Iir_Kind_Enumeration_Literal);
+ Set_Identifier (Enum_Lit, Current_Identifier);
+ Set_Parent (Enum_Lit, Parent);
+ Set_Location (Enum_Lit);
+ Set_Enum_Pos (Enum_Lit, Pos);
- -- LRM93 3.1.1
- -- the position number for each additional enumeration literal is
- -- one more than that if its predecessor in the list.
- Pos := Pos + 1;
+ -- LRM93 3.1.1
+ -- the position number for each additional enumeration literal
+ -- is one more than that if its predecessor in the list.
+ Pos := Pos + 1;
- Append_Element (Enum_List, Enum_Lit);
+ Append_Element (Enum_List, Enum_Lit);
- -- Skip identifier or character.
- Scan;
+ -- Skip identifier or character.
+ Scan;
+ else
+ Error_Msg_Parse ("identifier or character expected");
+ end if;
- exit when Current_Token /= Tok_Comma;
+ exit when Current_Token /= Tok_Comma;
- -- Skip ','.
- Scan;
+ -- Skip ','.
+ Scan;
- if Current_Token = Tok_Right_Paren then
- Error_Msg_Parse ("extra ',' ignored");
- exit;
- end if;
- end loop;
+ if Current_Token = Tok_Right_Paren then
+ Error_Msg_Parse ("extra ',' ignored");
+ exit;
+ end if;
+ end loop;
+ end if;
-- Skip ')'.
Expect_Scan (Tok_Right_Paren, "')' expected at end of enumeration type");
@@ -5622,7 +5617,7 @@ package body Parse is
| Tok_End =>
-- Token not to be skipped
Error_Msg_Parse ("primary expression expected");
- return Null_Iir;
+ return Create_Error (Null_Iir);
when others =>
Unexpected ("primary");
diff --git a/src/vhdl/sem_types.adb b/src/vhdl/sem_types.adb
index 600f29257..8de136ac9 100644
--- a/src/vhdl/sem_types.adb
+++ b/src/vhdl/sem_types.adb
@@ -357,6 +357,8 @@ package body Sem_Types is
when Iir_Kind_Attribute_Name =>
Sem_Name (Range_Expr);
Range_Expr1 := Name_To_Range (Range_Expr);
+ when Iir_Kind_Error =>
+ Range_Expr1 := Null_Iir;
when others =>
Error_Kind ("sem_physical_type_definition", Range_Expr);
end case;