diff options
author | Tristan Gingold <tgingold@free.fr> | 2018-12-23 13:41:39 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2018-12-23 13:41:39 +0100 |
commit | feb198c93bd936b20d5b3d878080ec4cdf7e480b (patch) | |
tree | b27b263b31de29e77acc6bf271a3776661446637 /src | |
parent | 73bb7fd335965c9c6079415ce50fb2059c3e6265 (diff) | |
download | ghdl-feb198c93bd936b20d5b3d878080ec4cdf7e480b.tar.gz ghdl-feb198c93bd936b20d5b3d878080ec4cdf7e480b.tar.bz2 ghdl-feb198c93bd936b20d5b3d878080ec4cdf7e480b.zip |
parse/sem: be more tolerante to parse errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/parse.adb | 36 | ||||
-rw-r--r-- | src/vhdl/sem.adb | 2 | ||||
-rw-r--r-- | src/vhdl/sem_names.adb | 12 | ||||
-rw-r--r-- | src/vhdl/sem_specs.adb | 4 |
4 files changed, 30 insertions, 24 deletions
diff --git a/src/vhdl/parse.adb b/src/vhdl/parse.adb index a0138913e..5178bfe75 100644 --- a/src/vhdl/parse.adb +++ b/src/vhdl/parse.adb @@ -457,6 +457,17 @@ package body Parse is end if; end Scan_Semi_Colon_Unit; + function Create_Error_Node (Orig : Iir := Null_Iir) return Iir + is + Res : Iir; + begin + Res := Create_Error (Orig); + if Orig = Null_Iir then + Set_Location (Res); + end if; + return Res; + end Create_Error_Node; + -- precond : next token -- postcond: next token. -- @@ -587,7 +598,7 @@ package body Parse is end if; Error_Msg_Parse ("'to' or 'downto' expected"); end if; - return Create_Error (Left); + return Create_Error_Node (Left); end case; end Parse_Range; @@ -1017,7 +1028,7 @@ package body Parse is then Expect (Tok_Identifier, "attribute identifier expected after '"); - return Null_Iir; + return Res; end if; Res := Create_Iir (Iir_Kind_Attribute_Name); Set_Identifier (Res, Current_Identifier); @@ -1359,7 +1370,7 @@ package body Parse is Error_Msg_Parse ("name expected here, found %t", +Current_Token); end if; - return Null_Iir; + return Create_Error_Node; end case; return Parse_Name_Suffix (Res, Allow_Indexes, Allow_Signature); @@ -1403,9 +1414,6 @@ package body Parse is pragma Unreferenced (Old); begin Res := Parse_Name (Allow_Indexes => False); - if Res = Null_Iir then - return Null_Iir; - end if; Check_Type_Mark (Res); if Check_Paren and then Current_Token = Tok_Left_Paren then @@ -1838,6 +1846,7 @@ package body Parse is else if Is_Func then Error_Msg_Parse ("'return' expected"); + Set_Return_Type_Mark (Subprg, Create_Error_Node); end if; end if; end Parse_Subprogram_Parameters_And_Return; @@ -2258,7 +2267,7 @@ package body Parse is -- unbounded_array_definition ::= -- ARRAY ( index_subtype_definition { , index_subtype_definition } ) -- OF element_subtype_indication - function Parse_Array_Definition return Iir + function Parse_Array_Type_Definition return Iir is Index_Constrained : Boolean; Array_Constrained : Boolean; @@ -2360,7 +2369,7 @@ package body Parse is Set_Location (Res_Type, Loc); return Res_Type; - end Parse_Array_Definition; + end Parse_Array_Type_Definition; -- precond : UNITS -- postcond: next token @@ -2754,7 +2763,7 @@ package body Parse is end if; when Tok_Array => - Def := Parse_Array_Definition; + Def := Parse_Array_Type_Definition; Decl := Null_Iir; when Tok_Record => @@ -5246,10 +5255,9 @@ package body Parse is end if; Set_Associated_Expr (Assoc, Expr); Append_Subchain (Last, Res, Assoc); - exit when Current_Token = Tok_Right_Paren; + exit when Current_Token /= Tok_Comma; Loc := Get_Token_Location; - Expect (Tok_Comma); -- Eat ',' Scan; @@ -5258,7 +5266,7 @@ package body Parse is end loop; -- Eat ')'. - Scan; + Expect_Scan (Tok_Right_Paren); return Res; end Parse_Aggregate; @@ -5617,11 +5625,11 @@ package body Parse is | Tok_End => -- Token not to be skipped Error_Msg_Parse ("primary expression expected"); - return Create_Error (Null_Iir); + return Create_Error_Node; when others => Unexpected ("primary"); - return Null_Iir; + return Create_Error_Node; end case; end Parse_Primary; diff --git a/src/vhdl/sem.adb b/src/vhdl/sem.adb index 8729a97e0..190623e9c 100644 --- a/src/vhdl/sem.adb +++ b/src/vhdl/sem.adb @@ -100,7 +100,7 @@ package body Sem is -- Resolve the name. Name := Get_Entity_Name (Library_Unit); - if Name = Null_Iir then + if Is_Error (Name) then pragma Assert (Flags.Flag_Force_Analysis); return Null_Iir; end if; diff --git a/src/vhdl/sem_names.adb b/src/vhdl/sem_names.adb index da8637f82..03c1f1e40 100644 --- a/src/vhdl/sem_names.adb +++ b/src/vhdl/sem_names.adb @@ -889,16 +889,14 @@ package body Sem_Names is Atype : Iir; Res : Iir; begin - if Name = Null_Iir then - pragma Assert (Flags.Flag_Force_Analysis); - Res := Create_Error_Type (Null_Iir); - Set_Type (Res, Res); - return Res; - end if; - -- The name must not have been analyzed. pragma Assert (Get_Type (Name) = Null_Iir); + if Is_Error (Name) then + Set_Type (Name, Name); + return Name; + end if; + -- Analyze the name (if not already done). Res := Get_Named_Entity (Name); if Res = Null_Iir then diff --git a/src/vhdl/sem_specs.adb b/src/vhdl/sem_specs.adb index 91a4ac169..d4713b264 100644 --- a/src/vhdl/sem_specs.adb +++ b/src/vhdl/sem_specs.adb @@ -1360,7 +1360,7 @@ package body Sem_Specs is begin Primary_Entity_Aspect := Null_Iir; Comp_Name := Get_Component_Name (Spec); - if Comp_Name = Null_Iir then + if Is_Error (Comp_Name) then pragma Assert (Flags.Flag_Force_Analysis); return; end if; @@ -1467,7 +1467,7 @@ package body Sem_Specs is begin Sem_Component_Specification (Parent_Stmts, Conf, Primary_Entity_Aspect); Component := Get_Component_Name (Conf); - if Component = Null_Iir then + if Is_Error (Component) then pragma Assert (Flags.Flag_Force_Analysis); return; end if; |