aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-10-21 13:56:50 +0200
committerTristan Gingold <tgingold@free.fr>2018-10-21 13:56:50 +0200
commit372be650b099083860a1c161cea01d021f3d0a38 (patch)
treebaec9fb96ea74eeb5fa09010488bb4bd0da8a49c
parentf53ea530de143fdf402bc1d3bdc755f77fb75c09 (diff)
downloadghdl-372be650b099083860a1c161cea01d021f3d0a38.tar.gz
ghdl-372be650b099083860a1c161cea01d021f3d0a38.tar.bz2
ghdl-372be650b099083860a1c161cea01d021f3d0a38.zip
oread: handle min int in typed expression.
-rw-r--r--src/ortho/oread/ortho_front.adb41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/ortho/oread/ortho_front.adb b/src/ortho/oread/ortho_front.adb
index b3d9d3a08..559ace797 100644
--- a/src/ortho/oread/ortho_front.adb
+++ b/src/ortho/oread/ortho_front.adb
@@ -1457,6 +1457,21 @@ package body Ortho_Front is
return Res;
end Parse_Alignof;
+ function Parse_Minus_Num (Atype : Node_Acc) return O_Cnode
+ is
+ Res : O_Cnode;
+ V : Integer_64;
+ begin
+ if Token_Number = Unsigned_64 (Integer_64'Last) + 1 then
+ V := Integer_64'First;
+ else
+ V := -Integer_64 (Token_Number);
+ end if;
+ Res := New_Signed_Literal (Atype.Type_Onode, V);
+ Next_Token;
+ return Res;
+ end Parse_Minus_Num;
+
-- Parse a literal whose type is ATYPE.
function Parse_Typed_Literal (Atype : Node_Acc) return O_Cnode
is
@@ -1478,16 +1493,7 @@ package body Ortho_Front is
Next_Token;
case Tok is
when Tok_Num =>
- declare
- V : Integer_64;
- begin
- if Token_Number = Unsigned_64 (Integer_64'Last) + 1 then
- V := Integer_64'First;
- else
- V := -Integer_64 (Token_Number);
- end if;
- Res := New_Signed_Literal (Atype.Type_Onode, V);
- end;
+ return Parse_Minus_Num (Atype);
when Tok_Float_Num =>
Res := New_Float_Literal (Atype.Type_Onode, -Token_Float);
when others =>
@@ -1737,14 +1743,21 @@ package body Ortho_Front is
-- Parse '-' EXPR, 'not' EXPR, 'abs' EXPR or EXPR.
procedure Parse_Unary_Expression (Atype : Node_Acc;
Res : out O_Enode;
- Res_Type : out Node_Acc)
- is
+ Res_Type : out Node_Acc) is
begin
case Tok is
when Tok_Minus =>
Next_Token;
- Parse_Primary_Expression (Atype, Res, Res_Type);
- Res := New_Monadic_Op (ON_Neg_Ov, Res);
+ if Tok = Tok_Num then
+ if Atype = null then
+ Parse_Error ("numeric literal without type context");
+ end if;
+ Res := New_Lit (Parse_Minus_Num (Atype));
+ Res_Type := Atype;
+ else
+ Parse_Primary_Expression (Atype, Res, Res_Type);
+ Res := New_Monadic_Op (ON_Neg_Ov, Res);
+ end if;
when Tok_Not =>
Next_Token;
Parse_Unary_Expression (Atype, Res, Res_Type);