From a805fd5fa850a6e3ccd50c6ee29e3530edb8c90e Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 5 Jun 2018 17:40:55 -0400 Subject: [PATCH] lib/core: remove ascii method on Int and 'b' prefix Since no distinction is to be done between both Int and Byte when dealing with strings, there is no need to have both an 'ascii' and a 'code_point' service on both Int and Char. Therefore, we remove the ascii method, as our Chars are first and foremost Unicode-compliant. Signed-off-by: Lucas Bajolet --- lib/core/fixed_ints.nit | 15 --------------- lib/core/kernel.nit | 13 ------------- lib/crypto/bytes.nit | 2 +- src/compiler/abstract_compiler.nit | 5 +++-- src/interpreter/naive_interpreter.nit | 5 +++-- src/literal.nit | 5 ----- src/modelize/modelize_property.nit | 4 +--- src/semantize/typing.nit | 4 +--- tests/sav/nitce/fixme/base_gen_reassign_alt4.res | 2 +- tests/sav/nitce/fixme/base_gen_reassign_alt5.res | 2 +- tests/sav/nitce/fixme/base_gen_reassign_alt6.res | 2 +- tests/sav/nituml_args3.res | 6 +++--- tests/sav/nituml_args4.res | 6 +++--- 13 files changed, 18 insertions(+), 53 deletions(-) diff --git a/lib/core/fixed_ints.nit b/lib/core/fixed_ints.nit index ce79f53..521c02b 100644 --- a/lib/core/fixed_ints.nit +++ b/lib/core/fixed_ints.nit @@ -158,9 +158,6 @@ universal Int8 redef fun to_i32 is intern redef fun to_u32 is intern - # Returns `self` as a Char according to its ASCII value. - fun ascii: Char `{ return (uint32_t)self; `} - redef fun distance(i) do return (self - i).to_i redef fun <=>(other) @@ -252,9 +249,6 @@ universal Int16 redef fun *(i) is intern redef fun /(i) is intern - # Returns `self` as a Char according to its ASCII value. - fun ascii: Char `{ return (uint32_t)self; `} - # Modulo of `self` with `i`. # # Returns the remainder of division of `self` by `i`. @@ -387,9 +381,6 @@ universal UInt16 redef fun zero do return 0.to_u16 redef fun value_of(val) do return val.to_u16 - # Returns `self` as a Char according to its ASCII value. - fun ascii: Char `{ return (uint32_t)self; `} - # `i` bits shift to the left # # assert 5u16 << 1 == 10u16 @@ -500,9 +491,6 @@ universal Int32 redef fun *(i) is intern redef fun /(i) is intern - # Returns `self` as a Char according to its ASCII value. - fun ascii: Char `{ return (uint32_t)self; `} - # Modulo of `self` with `i`. # # Returns the remainder of division of `self` by `i`. @@ -624,9 +612,6 @@ universal UInt32 redef fun *(i) is intern redef fun /(i) is intern - # Returns `self` as a Char according to its ASCII value. - fun ascii: Char `{ return (uint32_t)self; `} - # Modulo of `self` with `i`. # # Returns the remainder of division of `self` by `i`. diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index 1160e72..45c3ccd 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -807,11 +807,6 @@ universal Int # assert 0x220B.code_point == '∋' fun code_point: Char is intern `{ return (uint32_t)self; `} - # Returns the character equivalent of `self` - # - # REQUIRE: `self <= 127` - fun ascii: Char do return code_point - # Number of digits of an integer in base `b` (plus one if negative) # # assert 123.digit_count(10) == 3 @@ -964,14 +959,6 @@ universal Char end end - # The ascii value of `self` - # - # assert 'a'.ascii == 97 - # assert '\n'.ascii == 10 - # - # REQUIRE: `is_ascii` - fun ascii: Int do return code_point - # The unicode code point value of `self` # # assert 'A'.code_point == 65 diff --git a/lib/crypto/bytes.nit b/lib/crypto/bytes.nit index 59f8f55..287d782 100644 --- a/lib/crypto/bytes.nit +++ b/lib/crypto/bytes.nit @@ -26,7 +26,7 @@ redef class Bytes var mod = length % blocksize if mod == 0 then return self var pad = blocksize - mod - var byte = pad.to_b + var byte = pad for i in [0..pad[ do add byte return self end diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 3fa312d..c7594bd 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -3809,8 +3809,9 @@ end redef class ACharExpr redef fun expr(v) do - if is_ascii then return v.int_instance(value.as(not null).ascii) - if is_code_point then return v.int_instance(value.as(not null).code_point) + if is_code_point then + return v.int_instance(value.as(not null).code_point) + end return v.char_instance(self.value.as(not null)) end end diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 9c7ec34..799c413 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -1991,8 +1991,9 @@ end redef class ACharExpr redef fun expr(v) do - if is_ascii then return v.int_instance(self.value.as(not null).ascii) - if is_code_point then return v.int_instance(self.value.as(not null).code_point) + if is_code_point then + return v.int_instance(self.value.as(not null).code_point) + end return v.char_instance(self.value.as(not null)) end end diff --git a/src/literal.nit b/src/literal.nit index 344bd4d..5146a91 100644 --- a/src/literal.nit +++ b/src/literal.nit @@ -129,9 +129,6 @@ redef class ACharExpr redef fun delimiter_end do return '\'' - # Is the expression returning an ASCII byte value ? - fun is_ascii: Bool do return prefix == "b" - # Is the expression returning a Code Point ? fun is_code_point: Bool do return prefix == "u" @@ -139,7 +136,6 @@ redef class ACharExpr redef fun is_valid_augmentation do if suffix != "" then return false - if is_ascii then return true if is_code_point then return true if prefix != "" then return false return true @@ -157,7 +153,6 @@ redef class ACharExpr return end self.value = txt.chars[1] - if is_ascii and txt.chars[1].code_point > 127 then v.toolcontext.error(self.hot_location, "Syntax Error: usage of byte prefix on multibyte character.") end end diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index 2ae2b59..c8a7f3b 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -1463,9 +1463,7 @@ redef class AAttrPropdef if cla != null then mtype = cla.mclass_type else if nexpr isa ACharExpr then var cla: nullable MClass - if nexpr.is_ascii then - cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Byte") - else if nexpr.is_code_point then + if nexpr.is_code_point then cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Int") else cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Char") diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 3297d12..3463b07 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -1577,9 +1577,7 @@ end redef class ACharExpr redef fun accept_typing(v) do var mclass: nullable MClass = null - if is_ascii then - mclass = v.get_mclass(self, "Byte") - else if is_code_point then + if is_code_point then mclass = v.get_mclass(self, "Int") else mclass = v.get_mclass(self, "Char") diff --git a/tests/sav/nitce/fixme/base_gen_reassign_alt4.res b/tests/sav/nitce/fixme/base_gen_reassign_alt4.res index e131b2e..5bdd4bf 100644 --- a/tests/sav/nitce/fixme/base_gen_reassign_alt4.res +++ b/tests/sav/nitce/fixme/base_gen_reassign_alt4.res @@ -1,4 +1,4 @@ -Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728) +Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723) 11 21 31 diff --git a/tests/sav/nitce/fixme/base_gen_reassign_alt5.res b/tests/sav/nitce/fixme/base_gen_reassign_alt5.res index e131b2e..5bdd4bf 100644 --- a/tests/sav/nitce/fixme/base_gen_reassign_alt5.res +++ b/tests/sav/nitce/fixme/base_gen_reassign_alt5.res @@ -1,4 +1,4 @@ -Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728) +Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723) 11 21 31 diff --git a/tests/sav/nitce/fixme/base_gen_reassign_alt6.res b/tests/sav/nitce/fixme/base_gen_reassign_alt6.res index e131b2e..5bdd4bf 100644 --- a/tests/sav/nitce/fixme/base_gen_reassign_alt6.res +++ b/tests/sav/nitce/fixme/base_gen_reassign_alt6.res @@ -1,4 +1,4 @@ -Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:728) +Runtime error: Cast failed. Expected `OTHER`, got `Float` (../lib/core/kernel.nit:723) 11 21 31 diff --git a/tests/sav/nituml_args3.res b/tests/sav/nituml_args3.res index de28bd9..a5a027f 100644 --- a/tests/sav/nituml_args3.res +++ b/tests/sav/nituml_args3.res @@ -51,19 +51,19 @@ Float [ Numeric -> Float [dir=back arrowtail=open style=dashed]; Byte [ - label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ ascii(): Char\l+ is_whitespace(): Bool\l}" + label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ is_whitespace(): Bool\l}" ] Discrete -> Byte [dir=back arrowtail=open style=dashed]; Numeric -> Byte [dir=back arrowtail=open style=dashed]; Int [ - label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l}" + label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l+ is_whitespace(): Bool\l}" ] Discrete -> Int [dir=back arrowtail=open style=dashed]; Numeric -> Int [dir=back arrowtail=open style=dashed]; Char [ - label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ ascii(): Byte\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}" + label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}" ] Discrete -> Char [dir=back arrowtail=open style=dashed]; diff --git a/tests/sav/nituml_args4.res b/tests/sav/nituml_args4.res index 53d63de..f03123a 100644 --- a/tests/sav/nituml_args4.res +++ b/tests/sav/nituml_args4.res @@ -51,19 +51,19 @@ Float [ Numeric -> Float [dir=back arrowtail=open style=dashed]; Byte [ - label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ ascii(): Char\l+ is_whitespace(): Bool\l}" + label = "{Byte||+ %(i: Byte): Byte\l+ \<\<(i: Int): Byte\l+ \>\>(i: Int): Byte\l+ is_whitespace(): Bool\l}" ] Discrete -> Byte [dir=back arrowtail=open style=dashed]; Numeric -> Byte [dir=back arrowtail=open style=dashed]; Int [ - label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l}" + label = "{Int||+ %(i: Int): Int\l+ \<\<(i: Int): Int\l+ \>\>(i: Int): Int\l+ code_point(): Char\l+ digit_count(b: Int): Int\l+ digit_count_base_10(): Int\l+ to_c(): Char\l+ abs(): Int\l+ is_whitespace(): Bool\l}" ] Discrete -> Int [dir=back arrowtail=open style=dashed]; Numeric -> Int [dir=back arrowtail=open style=dashed]; Char [ - label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ ascii(): Byte\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}" + label = "{Char||+ +(i: Int): Char\l+ -(i: Int): Char\l+ to_i(): Int\l+ code_point(): Int\l+ is_ascii(): Bool\l+ to_lower(): Char\l+ to_upper(): Char\l+ is_digit(): Bool\l+ is_lower(): Bool\l+ is_upper(): Bool\l+ is_letter(): Bool\l+ is_whitespace(): Bool\l}" ] Discrete -> Char [dir=back arrowtail=open style=dashed]; -- 1.7.9.5