lib/core: remove ascii method on Int and 'b' prefix
authorLucas Bajolet <lucas.bajolet@gmail.com>
Tue, 5 Jun 2018 21:40:55 +0000 (17:40 -0400)
committerLucas Bajolet <lucas.bajolet@gmail.com>
Fri, 8 Jun 2018 15:48:48 +0000 (11:48 -0400)
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 <lucas.bajolet@gmail.com>

13 files changed:
lib/core/fixed_ints.nit
lib/core/kernel.nit
lib/crypto/bytes.nit
src/compiler/abstract_compiler.nit
src/interpreter/naive_interpreter.nit
src/literal.nit
src/modelize/modelize_property.nit
src/semantize/typing.nit
tests/sav/nitce/fixme/base_gen_reassign_alt4.res
tests/sav/nitce/fixme/base_gen_reassign_alt5.res
tests/sav/nitce/fixme/base_gen_reassign_alt6.res
tests/sav/nituml_args3.res
tests/sav/nituml_args4.res

index ce79f53..521c02b 100644 (file)
@@ -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`.
index 1160e72..45c3ccd 100644 (file)
@@ -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
index 59f8f55..287d782 100644 (file)
@@ -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
index 3fa312d..c7594bd 100644 (file)
@@ -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
index 9c7ec34..799c413 100644 (file)
@@ -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
index 344bd4d..5146a91 100644 (file)
@@ -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
 
index 2ae2b59..c8a7f3b 100644 (file)
@@ -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")
index 3297d12..3463b07 100644 (file)
@@ -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")
index e131b2e..5bdd4bf 100644 (file)
@@ -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
index e131b2e..5bdd4bf 100644 (file)
@@ -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
index e131b2e..5bdd4bf 100644 (file)
@@ -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
index de28bd9..a5a027f 100644 (file)
@@ -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];
 
index 53d63de..f03123a 100644 (file)
@@ -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];