diff options
author | Tristan Gingold <tgingold@free.fr> | 2016-02-10 04:58:22 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2016-02-10 07:52:53 +0100 |
commit | 1db60a0e91a18ddcc7c4d0c08e5c07adc8c59831 (patch) | |
tree | 9295bbffd9b9ecbdea71204c8cadae9d3a15c308 /src/vhdl | |
parent | 16d76f62ee60847721c6c5fead792b5c342ec740 (diff) | |
download | ghdl-1db60a0e91a18ddcc7c4d0c08e5c07adc8c59831.tar.gz ghdl-1db60a0e91a18ddcc7c4d0c08e5c07adc8c59831.tar.bz2 ghdl-1db60a0e91a18ddcc7c4d0c08e5c07adc8c59831.zip |
evaluation: handle whitespace for 'value.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/evaluation.adb | 38 | ||||
-rw-r--r-- | src/vhdl/scanner.adb | 13 | ||||
-rw-r--r-- | src/vhdl/scanner.ads | 4 |
3 files changed, 54 insertions, 1 deletions
diff --git a/src/vhdl/evaluation.adb b/src/vhdl/evaluation.adb index 08610882a..8f93d379d 100644 --- a/src/vhdl/evaluation.adb +++ b/src/vhdl/evaluation.adb @@ -16,6 +16,7 @@ -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. with Ada.Unchecked_Deallocation; +with Scanner; with Errorout; use Errorout; with Name_Table; use Name_Table; with Str_Table; @@ -1980,6 +1981,43 @@ package body Evaluation is return Build_Physical (Get_Physical_Value (Val), Expr); end Eval_Physical_Literal; + function Eval_Value_Attribute + (Value : String; Atype : Iir; Orig : Iir) return Iir + is + Base_Type : constant Iir := Get_Base_Type (Atype); + First, Last : Positive; + begin + -- LRM93 14.1 Predefined attributes. + -- Leading and trailing whitespace are ignored. + First := Value'First; + Last := Value'Last; + while First <= Last loop + exit when not Scanner.Is_Whitespace (Value (First)); + First := First + 1; + end loop; + while Last >= First loop + exit when not Scanner.Is_Whitespace (Value (Last)); + Last := Last - 1; + end loop; + + declare + Value1 : String renames Value (First .. Last); + begin + case Get_Kind (Base_Type) is + when Iir_Kind_Integer_Type_Definition => + return Build_Discrete (Iir_Int64'Value (Value1), Orig); + when Iir_Kind_Enumeration_Type_Definition => + return Build_Enumeration_Value (Value1, Base_Type, Orig); + when Iir_Kind_Floating_Type_Definition => + return Build_Floating (Iir_Fp64'value (Value1), Orig); + when Iir_Kind_Physical_Type_Definition => + return Build_Physical_Value (Value1, Base_Type, Orig); + when others => + Error_Kind ("eval_value_attribute", Base_Type); + end case; + end; + end Eval_Value_Attribute; + function Eval_Static_Expr (Expr: Iir) return Iir is Res : Iir; diff --git a/src/vhdl/scanner.adb b/src/vhdl/scanner.adb index 84d334d89..b56c04e9a 100644 --- a/src/vhdl/scanner.adb +++ b/src/vhdl/scanner.adb @@ -84,7 +84,7 @@ package body Scanner is | '_' | '|' | '*' => Special_Character, -- 4. the space characters - ' ' | No_Break_Space => Space_Character, + ' ' | NBSP => Space_Character, -- 5. lower case letters 'a' .. 'z' | LC_German_Sharp_S .. LC_O_Diaeresis | @@ -1901,4 +1901,15 @@ package body Scanner is return File_Pos_To_Location (Current_Context.Source_File, Current_Context.Token_Pos); end Get_Token_Location; + + function Is_Whitespace (C : Character) return Boolean is + begin + if C = ' ' then + return True; + elsif Vhdl_Std > Vhdl_87 and C = NBSP then + return True; + else + return False; + end if; + end Is_Whitespace; end Scanner; diff --git a/src/vhdl/scanner.ads b/src/vhdl/scanner.ads index 297debcb6..05f45f663 100644 --- a/src/vhdl/scanner.ads +++ b/src/vhdl/scanner.ads @@ -121,4 +121,8 @@ package Scanner is -- Also, Vhdl_Std should be set. procedure Convert_Identifier; + -- Return TRUE iff C is a whitespace. + -- LRM93 13.2 Lexical elements, separators, and delimiters + -- A space character (SPACE or NBSP) ... + function Is_Whitespace (C : Character) return Boolean; end Scanner; |