From: Jean Privat Date: Mon, 24 Feb 2014 20:53:12 +0000 (-0500) Subject: Merge commit 'b7e675f' X-Git-Tag: v0.6.4~17 X-Git-Url: http://nitlanguage.org?hp=b7e675fd8f257b1be7d37b0cccc81c4f4d49a9d5 Merge commit 'b7e675f' Partially fixes issue #276 and add the test to exhibit the remaining bad behavior of the issue --- diff --git a/examples/draw_operation.nit b/examples/draw_operation.nit index 8ad92fc..cada831 100644 --- a/examples/draw_operation.nit +++ b/examples/draw_operation.nit @@ -124,7 +124,7 @@ redef class String end var ci = 0 - for c in self do + for c in self.chars do var local_dispc if c.override_dispc then local_dispc = c @@ -193,10 +193,10 @@ else b = gets.to_i printn "Operator (+, -, *, /, %): " - op_char = gets[0] + op_char = gets.chars[0] printn "Char to display: " - disp_char = gets[0] + disp_char = gets.chars[0] printn "Size of text: " disp_size = gets.to_i diff --git a/lib/base64.nit b/lib/base64.nit index 861cb9a..9c57166 100644 --- a/lib/base64.nit +++ b/lib/base64.nit @@ -28,7 +28,7 @@ redef class String do var inv_base64_chars = new HashMap[Char,Int] for k in [0..base64_chars.length[ do - inv_base64_chars[ base64_chars[k] ] = k + inv_base64_chars[ base64_chars.chars[k] ] = k end return inv_base64_chars end @@ -52,23 +52,23 @@ redef class String for s in [0..steps[ do var e = 0 for ss in [0..3[ do - e += self[s*3+ss].ascii.lshift((2-ss)*8) + e += self.chars[s*3+ss].ascii.lshift((2-ss)*8) end for ss in [0..4[ do - result[s*4+3-ss] = base64_chars[ e.rshift(ss*6).bin_and( mask_6bit ) ] + result[s*4+3-ss] = base64_chars.chars[ e.rshift(ss*6).bin_and( mask_6bit ) ] end end if chars_in_last_step == 1 then - var e = self[length-1].ascii.lshift(16) + var e = self.chars[length-1].ascii.lshift(16) for ss in [0..2[ do - result[steps*4+1-ss] = base64_chars[ e.rshift((ss+2)*6).bin_and( mask_6bit ) ] + result[steps*4+1-ss] = base64_chars.chars[ e.rshift((ss+2)*6).bin_and( mask_6bit ) ] end else if chars_in_last_step == 2 then - var e = self[length-2].ascii.lshift(16) + - self[length-1].ascii.lshift(8) + var e = self.chars[length-2].ascii.lshift(16) + + self.chars[length-1].ascii.lshift(8) for ss in [0..3[ do - result[steps*4+2-ss] = base64_chars[ e.rshift((ss+1)*6).bin_and( mask_6bit ) ] + result[steps*4+2-ss] = base64_chars.chars[ e.rshift((ss+1)*6).bin_and( mask_6bit ) ] end end @@ -104,7 +104,7 @@ redef class String for s in [0..steps[ do var e = 0 for ss in [0..4[ do - e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6) + e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6) end for ss in [0..3[ do @@ -116,7 +116,7 @@ redef class String if padding_count == 1 then var e = 0 for ss in [0..3[ do - e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6) + e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6) end for ss in [0..2[ do @@ -125,7 +125,7 @@ redef class String else if padding_count == 2 then var e = 0 for ss in [0..2[ do - e += inverted_base64_chars[self[s*4+ss]].lshift((3-ss)*6) + e += inverted_base64_chars[self.chars[s*4+ss]].lshift((3-ss)*6) end result[s*3] = e.rshift(2*8).bin_and( mask_8bit ).ascii diff --git a/lib/bcm2835.nit b/lib/bcm2835.nit index 3557073..aac7352 100644 --- a/lib/bcm2835.nit +++ b/lib/bcm2835.nit @@ -440,7 +440,7 @@ class HD44780 clear return_home var count = 0 - for c in v do + for c in v.chars do if c == '\n' then # FIXME, this should work #write(true, "C0".to_hex) diff --git a/lib/mnit_linux/sdl.nit b/lib/mnit_linux/sdl.nit index eb584b5..256b070 100644 --- a/lib/mnit_linux/sdl.nit +++ b/lib/mnit_linux/sdl.nit @@ -330,7 +330,7 @@ class SDLKeyEvent redef fun to_c: nullable Char do - if key_name.length == 1 then return key_name.first + if key_name.length == 1 then return key_name.chars.first return null end diff --git a/lib/opts.nit b/lib/opts.nit index 1ac2326..ec3c006 100644 --- a/lib/opts.nit +++ b/lib/opts.nit @@ -138,7 +138,7 @@ abstract class OptionParameter redef fun read_param(it) do super - if it.is_ok and it.item.first != '-' then + if it.is_ok and it.item.chars.first != '-' then value = convert(it.item) it.next else @@ -273,7 +273,7 @@ class OptionContext if str.last_index_of('-') == 0 and str.length > 2 then var next_called = false for i in [1..str.length] do - var short_opt = "-" + str[i].to_s + var short_opt = "-" + str.chars[i].to_s if _optmap.has_key(short_opt) then var option = _optmap[short_opt] if option isa OptionParameter then diff --git a/lib/standard/file.nit b/lib/standard/file.nit index 1e4b345..cbb8ac6 100644 --- a/lib/standard/file.nit +++ b/lib/standard/file.nit @@ -248,7 +248,7 @@ redef class String fun dirname: String do var l = _length - 1 # Index of the last char - if l > 0 and self[l] == '/' then l -= 1 # remove trailing `/` + if l > 0 and self.chars[l] == '/' then l -= 1 # remove trailing `/` var pos = last_index_of_from('/', l) if pos > 0 then return substring(0, pos) @@ -317,7 +317,7 @@ redef class String do if path.is_empty then return self if self.is_empty then return path - if path[0] == '/' then return path + if path.chars[0] == '/' then return path return "{self}/{path}" end diff --git a/lib/standard/standard.nit b/lib/standard/standard.nit index 4cfac4e..d11fa21 100644 --- a/lib/standard/standard.nit +++ b/lib/standard/standard.nit @@ -16,7 +16,6 @@ module standard import posix -import ropes import environ import time import string_search diff --git a/lib/standard/stream.nit b/lib/standard/stream.nit index 5dbe9d8..745064a 100644 --- a/lib/standard/stream.nit +++ b/lib/standard/stream.nit @@ -77,7 +77,7 @@ interface IStream if eof then return else var c = x.ascii - s.push(c) + s.chars.push(c) if c == '\n' then return end end @@ -110,7 +110,7 @@ abstract class BufferedIStream if _buffer_pos >= _buffer.length then return -1 end - var c = _buffer[_buffer_pos] + var c = _buffer.chars[_buffer_pos] _buffer_pos += 1 return c.ascii end @@ -128,7 +128,7 @@ abstract class BufferedIStream k = _buffer.length end while j < k and i > 0 do - s.add(_buffer[j]) + s.add(_buffer.chars[j]) j += 1 i -= 1 end @@ -144,7 +144,7 @@ abstract class BufferedIStream var j = _buffer_pos var k = _buffer.length while j < k do - s.add(_buffer[j]) + s.add(_buffer.chars[j]) j += 1 end _buffer_pos = j @@ -158,7 +158,7 @@ abstract class BufferedIStream loop # First phase: look for a '\n' var i = _buffer_pos - while i < _buffer.length and _buffer[i] != '\n' do i += 1 + while i < _buffer.length and _buffer.chars[i] != '\n' do i += 1 # if there is something to append if i > _buffer_pos then @@ -168,7 +168,7 @@ abstract class BufferedIStream # Copy from the buffer to the string var j = _buffer_pos while j < i do - s.add(_buffer[j]) + s.add(_buffer.chars[j]) j += 1 end end diff --git a/lib/standard/string.nit b/lib/standard/string.nit index 5066f9b..b9ee718 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -30,6 +30,8 @@ abstract class AbstractString readable private var _items: NativeString + fun chars: StringCharView is abstract + # Access a character at `index` in the string. # # assert "abcd"[2] == 'c' @@ -54,7 +56,7 @@ abstract class AbstractString if from < count then var r = new Buffer.with_capacity(count - from) while from < count do - r.push(_items[from]) + r.chars.push(_items[from]) from += 1 end return r.to_s @@ -142,7 +144,7 @@ abstract class AbstractString var i = 0 var neg = false - for c in self + for c in self.chars do var v = c.to_i if v > base then @@ -173,7 +175,7 @@ abstract class AbstractString fun is_numeric: Bool do var has_point_or_comma = false - for i in self + for i in self.chars do if not i.is_numeric then @@ -194,7 +196,7 @@ abstract class AbstractString fun to_upper: String do var s = new Buffer.with_capacity(length) - for i in self do s.add(i.to_upper) + for i in self.chars do s.add(i.to_upper) return s.to_s end @@ -204,7 +206,7 @@ abstract class AbstractString fun to_lower : String do var s = new Buffer.with_capacity(length) - for i in self do s.add(i.to_lower) + for i in self.chars do s.add(i.to_lower) return s.to_s end @@ -215,18 +217,18 @@ abstract class AbstractString # assert "\na\nb\tc\t".trim == "a\nb\tc" fun trim: String do - if self._length == 0 then return self.to_s + if self.length == 0 then return self.to_s # find position of the first non white space char (ascii < 32) from the start of the string var start_pos = 0 - while self[start_pos].ascii <= 32 do + while self.chars[start_pos].ascii <= 32 do start_pos += 1 - if start_pos == _length then return "" + if start_pos == length then return "" end # find position of the first non white space char from the end of the string var end_pos = length - 1 - while self[end_pos].ascii <= 32 do + while self.chars[end_pos].ascii <= 32 do end_pos -= 1 - if end_pos == start_pos then return self[start_pos].to_s + if end_pos == start_pos then return self.chars[start_pos].to_s end return self.substring(start_pos, end_pos - start_pos + 1) end @@ -245,7 +247,7 @@ abstract class AbstractString do var res = new Buffer var underscore = false - for c in self do + for c in self.chars do if (c >= 'a' and c <= 'z') or (c >='A' and c <= 'Z') then res.add(c) underscore = false @@ -278,7 +280,7 @@ abstract class AbstractString fun escape_to_c: String do var b = new Buffer - for c in self do + for c in self.chars do if c == '\n' then b.append("\\n") else if c == '\0' then @@ -357,6 +359,44 @@ abstract class AbstractString end end +# Abstract class for the SequenceRead compatible +# views on String and Buffer objects +abstract class StringCharView + super SequenceRead[Char] + + type SELFTYPE: AbstractString + + private var target: SELFTYPE + + private init(tgt: SELFTYPE) + do + target = tgt + end + + redef fun is_empty do return target.is_empty + + redef fun length do return target.length + + redef fun has(c: Char): Bool + do + for i in self do + if i == c then return true + end + return false + end + +end + +# View on Buffer objects, extends Sequence +# for mutation operations +abstract class BufferCharView + super StringCharView + super Sequence[Char] + + redef type SELFTYPE: Buffer + +end + # Immutable strings of characters. class String super Comparable @@ -371,6 +411,8 @@ class String # Indes in _items of the last item of the string readable var _index_to: Int + redef var chars: StringCharView = new FlatStringCharView(self) + ################################################ # AbstractString specific methods # ################################################ @@ -395,11 +437,13 @@ class String var realFrom = _index_from + from - if (realFrom + count) > _index_to then return new String.from_substring(realFrom, _index_to, _items) + if (realFrom + count) > _index_to then return new String.with_infos(_items, _index_to - realFrom + 1, realFrom, _index_to) if count == 0 then return "" - return new String.from_substring(realFrom, realFrom + count - 1, _items) + var to = realFrom + count - 1 + + return new String.with_infos(_items, to - realFrom + 1, realFrom, to) end redef fun substring_from(from: Int): String @@ -507,20 +551,6 @@ class String # String Specific Methods # ################################################## - # Creates a String object as a substring of another String - # - # From : index to start at - # - # To : Index to stop at (from + count -1) - # - private init from_substring(from: Int, to: Int, internalString: NativeString) - do - _items = internalString - _index_from = from - _index_to = to - _length = to - from + 1 - end - private init with_infos(items: NativeString, len: Int, from: Int, to: Int) do self._items = items @@ -676,6 +706,50 @@ class String end end +private class FlatStringIterator + super IndexedIterator[Char] + + var target: String + + var target_items: NativeString + + var curr_pos: Int + + init with_pos(tgt: String, pos: Int) + do + target = tgt + target_items = tgt.items + curr_pos = pos + target.index_from + end + + redef fun is_ok do return curr_pos <= target.index_to + + redef fun item do return target_items[curr_pos] + + redef fun next do curr_pos += 1 + + redef fun index do return curr_pos - target.index_from + +end + +private class FlatStringCharView + super StringCharView + + redef type SELFTYPE: String + + redef fun [](index) + do + # Check that the index (+ index_from) is not larger than indexTo + # In other terms, if the index is valid + assert index >= 0 + assert (index + target._index_from) <= target._index_to + return target._items[index + target._index_from] + end + + redef fun iterator: IndexedIterator[Char] do return new FlatStringIterator.with_pos(target, 0) + +end + # Mutable strings of characters. class Buffer super AbstractString @@ -685,6 +759,8 @@ class Buffer redef type OTHER: String + redef var chars: BufferCharView = new FlatBufferCharView(self) + redef fun []=(index, item) do if index == length then @@ -743,8 +819,8 @@ class Buffer var l1 = length var l2 = s.length while i < l1 and i < l2 do - var c1 = self[i].ascii - var c2 = s[i].ascii + var c1 = self.chars[i].ascii + var c2 = s.chars[i].ascii if c1 < c2 then return true else if c2 < c1 then @@ -801,6 +877,81 @@ class Buffer readable private var _capacity: Int end +private class FlatBufferCharView + super BufferCharView + super StringCapable + + redef type SELFTYPE: Buffer + + init(tgt: Buffer) + do + self.target = tgt + end + + redef fun [](index) do return target._items[index] + + redef fun []=(index, item) + do + assert index >= 0 and index <= length + if index == length then + add(item) + return + end + target._items[index] = item + end + + redef fun push(c) + do + target.add(c) + end + + redef fun add(c) + do + target.add(c) + end + + fun enlarge(cap: Int) + do + target.enlarge(cap) + end + + redef fun append(s) + do + var my_items = target.items + var s_length = s.length + if target.capacity < s.length then enlarge(s_length + target.length) + end + + redef fun iterator: IndexedIterator[Char] do return new FlatBufferIterator.with_pos(target, 0) + +end + +private class FlatBufferIterator + super IndexedIterator[Char] + + var target: Buffer + + var target_items: NativeString + + var curr_pos: Int + + init with_pos(tgt: Buffer, pos: Int) + do + target = tgt + target_items = tgt.items + curr_pos = pos + end + + redef fun index do return curr_pos + + redef fun is_ok do return curr_pos < target.length + + redef fun item do return target_items[curr_pos] + + redef fun next do curr_pos += 1 + +end + ############################################################################### # Refinement # ############################################################################### @@ -859,9 +1010,9 @@ redef class Int # Sign if self < 0 then n = - self - s[0] = '-' + s.chars[0] = '-' else if self == 0 then - s[0] = '0' + s.chars[0] = '0' return else n = self @@ -869,7 +1020,7 @@ redef class Int # Fill digits var pos = digit_count(base) - 1 while pos >= 0 and n > 0 do - s[pos] = (n % base).to_c + s.chars[pos] = (n % base).to_c n = n / base # / pos -= 1 end @@ -907,7 +1058,7 @@ redef class Float var len = str.length for i in [0..len-1] do var j = len-1-i - var c = str[j] + var c = str.chars[j] if c == '0' then continue else if c == '.' then @@ -960,7 +1111,7 @@ redef class Char redef fun to_s do var s = new Buffer.with_capacity(1) - s[0] = self + s.chars[0] = self return s.to_s end diff --git a/lib/standard/string_search.nit b/lib/standard/string_search.nit index 46bda9b..22d0bc9 100644 --- a/lib/standard/string_search.nit +++ b/lib/standard/string_search.nit @@ -76,12 +76,12 @@ class BM_Pattern var j = from while j < n - m + 1 do var i = m - 1 # Cursor in the pattern - while i >= 0 and _motif[i] == s[i + j] do i -= 1 + while i >= 0 and _motif.chars[i] == s.chars[i + j] do i -= 1 if i < 0 then return j else var gs = _gs[i] # Good shift - var bc = bc(s[i+j]) - m + 1 + i # Bad char + var bc = bc(s.chars[i+j]) - m + 1 + i # Bad char # Both are true, do move to the best if gs > bc then j += gs @@ -142,7 +142,7 @@ class BM_Pattern var m = _length var i = 0 while i < m - 1 do - _bc_table[x[i]] = m - i - 1 + _bc_table[x.chars[i]] = m - i - 1 i += 1 end end @@ -162,7 +162,7 @@ class BM_Pattern else if i < g then g = i f = i - while g >= 0 and x[g] == x[g + m - 1 - f] do g -= 1 + while g >= 0 and x.chars[g] == x.chars[g + m - 1 - f] do g -= 1 suff[i] = f - g end i -= 1 @@ -239,7 +239,7 @@ redef class Char do var stop = s.length while from < stop do - if s[from] == self then return from + if s.chars[from] == self then return from from += 1 end return -1 @@ -265,7 +265,7 @@ redef class String var stop = s.length - length + 1 while from < stop do var i = length - 1 - while i >= 0 and self[i] == s[i + from] do i -= 1 + while i >= 0 and self.chars[i] == s.chars[i + from] do i -= 1 # Test if we found if i < 0 then return from # Not found so try next one @@ -330,10 +330,10 @@ redef class String fun html_escape: String do var ret = self - if ret.has('&') then ret = ret.replace('&', "&") - if ret.has('<') then ret = ret.replace('<', "<") - if ret.has('>') then ret = ret.replace('>', ">") - if ret.has('"') then ret = ret.replace('"', """) + if ret.chars.has('&') then ret = ret.replace('&', "&") + if ret.chars.has('<') then ret = ret.replace('<', "<") + if ret.chars.has('>') then ret = ret.replace('>', ">") + if ret.chars.has('"') then ret = ret.replace('"', """) return ret end end diff --git a/src/abstract_compiler.nit b/src/abstract_compiler.nit index b02369f..76aaa19 100644 --- a/src/abstract_compiler.nit +++ b/src/abstract_compiler.nit @@ -2402,13 +2402,13 @@ redef class ASuperExpr args = v.frame.arguments end - var mproperty = self.mproperty - if mproperty != null then - if mproperty.intro.msignature.arity == 0 then + var callsite = self.callsite + if callsite != null then + if callsite.mproperty.intro.msignature.arity == 0 then args = [recv] end # Super init call - var res = v.send(mproperty, args) + var res = v.compile_callsite(callsite, args) return res end diff --git a/src/auto_super_init.nit b/src/auto_super_init.nit index 316320a..89362a2 100644 --- a/src/auto_super_init.nit +++ b/src/auto_super_init.nit @@ -124,7 +124,7 @@ end redef class ASendExpr redef fun accept_auto_super_init(v) do - var mproperty = self.mproperty + var mproperty = self.callsite.mproperty if mproperty == null then return if mproperty.is_init then v.has_explicit_super_init = true diff --git a/src/collect_super_sends.nit b/src/collect_super_sends.nit index 9e6f9b0..70822ce 100644 --- a/src/collect_super_sends.nit +++ b/src/collect_super_sends.nit @@ -41,7 +41,7 @@ private class CollectSuperSends return end n.visit_all(self) - if n isa ASuperExpr and n.mproperty == null then + if n isa ASuperExpr and n.callsite == null then var mprop = mpropdef assert mprop != null res.add(mprop) diff --git a/src/debugger.nit b/src/debugger.nit index be9c26b..12d8b37 100644 --- a/src/debugger.nit +++ b/src/debugger.nit @@ -596,7 +596,7 @@ class Debugger print "\nEnd of current instruction \n" else if parts_of_command[1] == "stack" then print self.stack_trace - else if parts_of_command[1].has('[') and parts_of_command[1].has(']') then + else if parts_of_command[1].chars.has('[') and parts_of_command[1].chars.has(']') then process_array_command(parts_of_command) else var instance = seek_variable(get_real_variable_name(parts_of_command[1]), frame) @@ -832,7 +832,7 @@ class Debugger var trigger_string_escape = false var trigger_concat_in_string = false - for i in instruction do + for i in instruction.chars do if trigger_char_escape then if i == '\'' then trigger_char_escape = false else if trigger_string_escape then @@ -844,7 +844,7 @@ class Debugger if i.is_alphanumeric or i == '_' then instruction_buffer.add(i) else if i == '.' then - if instruction_buffer.is_numeric or (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then + if instruction_buffer.is_numeric or (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then instruction_buffer.clear else result_array.push(instruction_buffer.to_s) @@ -858,13 +858,13 @@ class Debugger trigger_concat_in_string = false trigger_string_escape = true else - if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then result_array.push(instruction_buffer.to_s) + if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s) instruction_buffer.clear end end end - if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer[0] >= 'A' and instruction_buffer[0] <= 'Z') then result_array.push(instruction_buffer.to_s) + if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s) return result_array end @@ -876,7 +876,7 @@ class Debugger var buf = new Buffer var trigger_copy = false - for i in function do + for i in function.chars do if i == ')' then break if trigger_copy then buf.add(i) if i == '(' then trigger_copy = true @@ -1166,7 +1166,7 @@ class Debugger var last_was_opening_bracket = false - for i in braces do + for i in braces.chars do if i == '[' then if last_was_opening_bracket then return null @@ -1344,7 +1344,7 @@ class Debugger fun get_char(value: String): nullable Instance do if value.length >= 1 then - return char_instance(value[0]) + return char_instance(value.chars[0]) else return null end diff --git a/src/literal.nit b/src/literal.nit index 668f72a..9daefcb 100644 --- a/src/literal.nit +++ b/src/literal.nit @@ -90,7 +90,7 @@ redef class ACharExpr v.toolcontext.error(self.hot_location, "Invalid character literal {txt}") return end - self.value = txt[1] + self.value = txt.chars[1] end end @@ -101,7 +101,7 @@ redef class AStringFormExpr do var txt = self.n_string.text var skip = 1 - if txt[0] == txt[1] and txt.length >= 6 then skip = 3 + if txt.chars[0] == txt.chars[1] and txt.length >= 6 then skip = 3 self.value = txt.substring(skip, txt.length-(2*skip)).unescape_nit end end diff --git a/src/location.nit b/src/location.nit index b3e8458..753acea 100644 --- a/src/location.nit +++ b/src/location.nit @@ -174,7 +174,7 @@ class Location var line_start = l.file.line_starts[i-1] var line_end = line_start var string = l.file.string - while line_end+1 < string.length and string[line_end+1] != '\n' and string[line_end+1] != '\r' do + while line_end+1 < string.length and string.chars[line_end+1] != '\n' and string.chars[line_end+1] != '\r' do line_end += 1 end var lstart = string.substring(line_start, l.column_start - 1) @@ -195,7 +195,7 @@ class Location end var indent = new Buffer for j in [line_start..line_start+l.column_start-1[ do - if string[j] == '\t' then + if string.chars[j] == '\t' then indent.add '\t' else indent.add ' ' diff --git a/src/markdown.nit b/src/markdown.nit index 2d2b6e4..d4b7a81 100644 --- a/src/markdown.nit +++ b/src/markdown.nit @@ -51,7 +51,7 @@ private class Doc2Mdwn # Count the number of spaces lastindent = indent indent = 0 - while text.length > indent and text[indent] == ' ' do indent += 1 + while text.length > indent and text.chars[indent] == ' ' do indent += 1 # Is codeblock? Then just collect them if indent > 4 then diff --git a/src/naive_interpreter.nit b/src/naive_interpreter.nit index ef2a5f3..b5139f1 100644 --- a/src/naive_interpreter.nit +++ b/src/naive_interpreter.nit @@ -751,13 +751,13 @@ redef class AInternMethPropdef if arg1 >= recvval.length or arg1 < 0 then debug("Illegal access on {recvval} for element {arg1}/{recvval.length}") end - return v.char_instance(recvval[arg1]) + return v.char_instance(recvval.chars[arg1]) else if pname == "[]=" then var arg1 = args[1].to_i if arg1 >= recvval.length or arg1 < 0 then debug("Illegal access on {recvval} for element {arg1}/{recvval.length}") end - recvval[arg1] = args[2].val.as(Char) + recvval.chars[arg1] = args[2].val.as(Char) return null else if pname == "copy_to" then # sig= copy_to(dest: NativeString, length: Int, from: Int, to: Int) @@ -1103,7 +1103,7 @@ redef class AVarReassignExpr var vari = v.frame.map[self.variable.as(not null)] var value = v.expr(self.n_value) if value == null then return - var res = v.send(reassign_property.mproperty, [vari, value]) + var res = v.send(reassign_callsite.mproperty, [vari, value]) assert res != null v.frame.map[self.variable.as(not null)] = res end @@ -1517,9 +1517,8 @@ redef class ASendExpr if i == null then return null args.add(i) end - var mproperty = self.mproperty.as(not null) - var res = v.send(mproperty, args) + var res = v.send(callsite.mproperty, args) return res end end @@ -1538,16 +1537,15 @@ redef class ASendReassignFormExpr var value = v.expr(self.n_value) if value == null then return - var mproperty = self.mproperty.as(not null) - var read = v.send(mproperty, args) + var read = v.send(callsite.mproperty, args) assert read != null - var write = v.send(self.reassign_property.mproperty, [read, value]) + var write = v.send(reassign_callsite.mproperty, [read, value]) assert write != null args.add(write) - v.send(self.write_mproperty.as(not null), args) + v.send(write_callsite.mproperty, args) end end @@ -1565,13 +1563,13 @@ redef class ASuperExpr args = v.frame.arguments end - var mproperty = self.mproperty - if mproperty != null then - if mproperty.intro.msignature.arity == 0 then + var callsite = self.callsite + if callsite != null then + if callsite.mproperty.intro.msignature.arity == 0 then args = [recv] end # Super init call - var res = v.send(mproperty, args) + var res = v.send(callsite.mproperty, args) return res end @@ -1596,8 +1594,7 @@ redef class ANewExpr if i == null then return null args.add(i) end - var mproperty = self.mproperty.as(not null) - var res2 = v.send(mproperty, args) + var res2 = v.send(callsite.mproperty, args) if res2 != null then #self.debug("got {res2} from {mproperty}. drop {recv}") return res2 @@ -1641,7 +1638,7 @@ redef class AAttrReassignExpr if value == null then return var mproperty = self.mproperty.as(not null) var attr = v.read_attribute(mproperty, recv) - var res = v.send(reassign_property.mproperty, [attr, value]) + var res = v.send(reassign_callsite.mproperty, [attr, value]) assert res != null assert recv isa MutableInstance recv.attributes[mproperty] = res diff --git a/src/network_debugger.nit b/src/network_debugger.nit index fc6dc36..cac7dd5 100755 --- a/src/network_debugger.nit +++ b/src/network_debugger.nit @@ -167,7 +167,7 @@ redef class Stdin do var loc_buf = new Buffer if connection.ready_to_read(0) then buf.append(connection.read) - for i in [buf_pos .. buf.length-1] do loc_buf.add(buf[i]) + for i in [buf_pos .. buf.length-1] do loc_buf.add(buf.chars[i]) buf.clear buf_pos = 0 return loc_buf.to_s @@ -185,7 +185,7 @@ redef class Stdin buf.append(connection.read) end buf_pos += 1 - return buf[buf_pos-1].ascii + return buf.chars[buf_pos-1].ascii end # Reads a line on the network if available @@ -204,8 +204,8 @@ redef class Stdin buf.append(connection.read) end buf_pos += 1 - if buf[buf_pos-1] == '\n' then break - line_buf.add(buf[buf_pos-1]) + if buf.chars[buf_pos-1] == '\n' then break + line_buf.add(buf.chars[buf_pos-1]) end return line_buf.to_s end diff --git a/src/nitx.nit b/src/nitx.nit index 84c0815..c073793 100644 --- a/src/nitx.nit +++ b/src/nitx.nit @@ -159,7 +159,7 @@ class NitIndex else var category = parts[0] var keyword = parts[1] - if keyword.first == ' ' then keyword = keyword.substring_from(1) + if keyword.chars.first == ' ' then keyword = keyword.substring_from(1) return new IndexQueryPair(str, keyword, category) end end @@ -863,7 +863,7 @@ redef class String private fun escape: String do var b = new Buffer - for c in self do + for c in self.chars do if c == '\n' then b.append("\\n") else if c == '\0' then diff --git a/src/parser/lexer.nit b/src/parser/lexer.nit index 5e230dc..614a11e 100644 --- a/src/parser/lexer.nit +++ b/src/parser/lexer.nit @@ -1297,7 +1297,7 @@ class Lexer if sp >= string_len then dfa_state = -1 else - var c = string[sp].ascii + var c = string.chars[sp].ascii sp += 1 var cr = _cr diff --git a/src/parser/xss/lexer.xss b/src/parser/xss/lexer.xss index 6a4d1d0..7784714 100644 --- a/src/parser/xss/lexer.xss +++ b/src/parser/xss/lexer.xss @@ -107,7 +107,7 @@ $ end foreach if sp >= string_len then dfa_state = -1 else - var c = string[sp].ascii + var c = string.chars[sp].ascii sp += 1 var cr = _cr diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index e2422aa..db88025 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -391,6 +391,8 @@ class RapidTypeVisitor fun add_send(mtype: MType, mproperty: MMethod) do analysis.add_send(mtype, mproperty) fun add_cast_type(mtype: MType) do analysis.add_cast(mtype) + + fun add_callsite(callsite: nullable CallSite) do if callsite != null then analysis.add_send(callsite.recv, callsite.mproperty) end ### @@ -509,9 +511,7 @@ end redef class ASendExpr redef fun accept_rapid_type_visitor(v) do - var mproperty = self.mproperty.as(not null) - var recvtype = self.n_expr.mtype.as(not null) - v.add_send(recvtype, mproperty) + v.add_callsite(callsite) end end @@ -519,40 +519,32 @@ end redef class ASendReassignFormExpr redef fun accept_rapid_type_visitor(v) do - v.add_send(self.read_type.as(not null), self.reassign_property.mproperty) - var mproperty = self.mproperty.as(not null) - var write_mproperty = self.write_mproperty.as(not null) - if n_expr isa ASelfExpr then - v.add_monomorphic_send(v.receiver, mproperty) - v.add_monomorphic_send(v.receiver, write_mproperty) - else - var recvtype = self.n_expr.mtype.as(not null) - v.add_send(recvtype, mproperty) - v.add_send(recvtype, write_mproperty) - end + v.add_callsite(callsite) + v.add_callsite(reassign_callsite) + v.add_callsite(write_callsite) end end redef class AVarReassignExpr redef fun accept_rapid_type_visitor(v) do - v.add_send(self.read_type.as(not null), self.reassign_property.mproperty) + v.add_callsite(reassign_callsite) end end redef class AAttrReassignExpr redef fun accept_rapid_type_visitor(v) do - v.add_send(self.read_type.as(not null), self.reassign_property.mproperty) + v.add_callsite(reassign_callsite) end end redef class ASuperExpr redef fun accept_rapid_type_visitor(v) do - var mproperty = self.mproperty - if mproperty != null then - v.add_monomorphic_send(v.receiver, mproperty) + var callsite = self.callsite + if callsite != null then + v.add_callsite(callsite) return end @@ -587,7 +579,6 @@ redef class ANewExpr do var mtype = self.mtype.as(MClassType) v.add_type(mtype) - var mproperty = self.mproperty.as(not null) - v.add_monomorphic_send(mtype, mproperty) + v.add_callsite(callsite) end end diff --git a/src/test_parser.nit b/src/test_parser.nit index 91851ba..674753c 100644 --- a/src/test_parser.nit +++ b/src/test_parser.nit @@ -45,7 +45,7 @@ var only_lexer = false var need_help = false var no_file = false -while not args.is_empty and args.first.first == '-' do +while not args.is_empty and args.first.chars.first == '-' do if args.first == "-n" then no_print = true else if args.first == "-l" then diff --git a/src/typing.nit b/src/typing.nit index 2a1fa54..719fae2 100644 --- a/src/typing.nit +++ b/src/typing.nit @@ -640,9 +640,6 @@ redef class AVarAssignExpr end redef class AReassignFormExpr - # @depreciated use `reassign_callsite` - fun reassign_property: nullable MMethodDef do return self.reassign_callsite.mpropdef - # The method designed by the reassign operator. var reassign_callsite: nullable CallSite @@ -1190,9 +1187,6 @@ end ## MESSAGE SENDING AND PROPERTY redef class ASendExpr - # @depreciated: use `callsite` - fun mproperty: nullable MMethod do return callsite.mproperty - # The property invoked by the send. var callsite: nullable CallSite @@ -1353,9 +1347,6 @@ redef class ABraAssignExpr end redef class ASendReassignFormExpr - # @depreciated use `write_callsite` - fun write_mproperty: nullable MMethod do return write_callsite.mproperty - # The property invoked for the writing var write_callsite: nullable CallSite @@ -1426,7 +1417,7 @@ end redef class ASuperExpr # The method to call if the super is in fact a 'super init call' # Note: if the super is a normal call-next-method, then this attribute is null - var mproperty: nullable MMethod + var callsite: nullable CallSite redef fun accept_typing(v) do @@ -1490,12 +1481,14 @@ redef class ASuperExpr v.error(self, "Error: No super method to call for {mproperty}.") return end - self.mproperty = superprop.mproperty - var args = self.n_args.to_a var msignature = v.resolve_signature_for(superprop, recvtype, true) + var callsite = new CallSite(self, recvtype, true, superprop.mproperty, superprop, msignature, false) + self.callsite = callsite + + var args = self.n_args.to_a if args.length > 0 then - v.check_signature(self, args, mproperty.name, msignature) + callsite.check_signature(v, args) else # TODO: Check signature end @@ -1507,9 +1500,6 @@ end #### redef class ANewExpr - # @depreciated use `callsite` - fun mproperty: nullable MMethod do return self.callsite.mproperty - # The constructor invoked by the new. var callsite: nullable CallSite diff --git a/tests/base_string.nit b/tests/base_string.nit index 4ff4c8e..8251428 100644 --- a/tests/base_string.nit +++ b/tests/base_string.nit @@ -17,7 +17,7 @@ import string redef class String redef fun output do - for c in self do c.output + for c in self.chars do c.output end end diff --git a/tests/bench_string_append.nit b/tests/bench_string_append.nit index 9f5944f..6a2d643 100644 --- a/tests/bench_string_append.nit +++ b/tests/bench_string_append.nit @@ -48,7 +48,7 @@ print(i) i = 0 for k in [0..s.length[ do - var c = s[k] + var c = s.chars[k] if c >= 'a' and c <= 'z' then i = i + 1 end diff --git a/tests/example_procedural_string.nit b/tests/example_procedural_string.nit index 069ed21..a78d01f 100644 --- a/tests/example_procedural_string.nit +++ b/tests/example_procedural_string.nit @@ -20,8 +20,8 @@ fun first_word(s: String): String do var result = new Buffer var i = 0 - while i < s.length and s[i] != ' ' do - result.add(s[i]) + while i < s.length and s.chars[i] != ' ' do + result.add(s.chars[i]) i = i + 1 end return result.to_s diff --git a/tests/sav/nitmetrics_args1.res b/tests/sav/nitmetrics_args1.res index ebc4cab..adcfffd 100644 --- a/tests/sav/nitmetrics_args1.res +++ b/tests/sav/nitmetrics_args1.res @@ -321,7 +321,7 @@ Number of live runtime classes: 6 Sys Bool Int A B C Number of live runtime types (instantied resolved type): 6 Sys Bool Int A B C -Number of live methods: 11 +Number of live methods: 14 Number of live method definitions: 14 Number of live runtime cast types (ie used in as and isa): 0 diff --git a/tests/sav/test_parser_args1.res b/tests/sav/test_parser_args1.res index ea32fbf..f2d3216 100644 --- a/tests/sav/test_parser_args1.res +++ b/tests/sav/test_parser_args1.res @@ -196,7 +196,7 @@ Start ../src/test_parser.nit:17,1--110,1 TKwfalse "false" ../src/test_parser.nit:46,15--19 AWhileExpr ../src/test_parser.nit:48,1--64,3 TKwwhile "while" ../src/test_parser.nit:48,1--5 - AAndExpr ../src/test_parser.nit:48,7--51 + AAndExpr ../src/test_parser.nit:48,7--57 ANotExpr ../src/test_parser.nit:48,7--23 TKwnot "not" ../src/test_parser.nit:48,7--9 ACallExpr ../src/test_parser.nit:48,11--23 @@ -206,20 +206,23 @@ Start ../src/test_parser.nit:17,1--110,1 AListExprs ../src/test_parser.nit:48,14 TId "is_empty" ../src/test_parser.nit:48,16--23 AListExprs ../src/test_parser.nit:48,23 - AEqExpr ../src/test_parser.nit:48,29--51 - ACallExpr ../src/test_parser.nit:48,29--44 - ACallExpr ../src/test_parser.nit:48,29--38 - ACallExpr ../src/test_parser.nit:48,29--32 - AImplicitSelfExpr ../src/test_parser.nit:48,29 - TId "args" ../src/test_parser.nit:48,29--32 - AListExprs ../src/test_parser.nit:48,32 - TId "first" ../src/test_parser.nit:48,34--38 - AListExprs ../src/test_parser.nit:48,38 - TId "first" ../src/test_parser.nit:48,40--44 - AListExprs ../src/test_parser.nit:48,44 - ACharExpr ../src/test_parser.nit:48,49--51 - TChar "\'-\'" ../src/test_parser.nit:48,49--51 - TKwdo "do" ../src/test_parser.nit:48,53--54 + AEqExpr ../src/test_parser.nit:48,29--57 + ACallExpr ../src/test_parser.nit:48,29--50 + ACallExpr ../src/test_parser.nit:48,29--44 + ACallExpr ../src/test_parser.nit:48,29--38 + ACallExpr ../src/test_parser.nit:48,29--32 + AImplicitSelfExpr ../src/test_parser.nit:48,29 + TId "args" ../src/test_parser.nit:48,29--32 + AListExprs ../src/test_parser.nit:48,32 + TId "first" ../src/test_parser.nit:48,34--38 + AListExprs ../src/test_parser.nit:48,38 + TId "chars" ../src/test_parser.nit:48,40--44 + AListExprs ../src/test_parser.nit:48,44 + TId "first" ../src/test_parser.nit:48,46--50 + AListExprs ../src/test_parser.nit:48,50 + ACharExpr ../src/test_parser.nit:48,55--57 + TChar "\'-\'" ../src/test_parser.nit:48,55--57 + TKwdo "do" ../src/test_parser.nit:48,59--60 ABlockExpr ../src/test_parser.nit:49,2--64,3 AIfExpr ../src/test_parser.nit:49,2--62,4 TKwif "if" ../src/test_parser.nit:49,2--3 diff --git a/tests/sav/test_parser_args2.res b/tests/sav/test_parser_args2.res index af40e9f..f647540 100644 --- a/tests/sav/test_parser_args2.res +++ b/tests/sav/test_parser_args2.res @@ -212,11 +212,13 @@ Read token at ../src/test_parser.nit:48,29--32 text='args' Read token at ../src/test_parser.nit:48,33 text='.' Read token at ../src/test_parser.nit:48,34--38 text='first' Read token at ../src/test_parser.nit:48,39 text='.' -Read token at ../src/test_parser.nit:48,40--44 text='first' -Read token at ../src/test_parser.nit:48,46--47 text='==' -Read token at ../src/test_parser.nit:48,49--51 text=''-'' -Read token at ../src/test_parser.nit:48,53--54 text='do' -Read token at ../src/test_parser.nit:48,55--49,0 text=' +Read token at ../src/test_parser.nit:48,40--44 text='chars' +Read token at ../src/test_parser.nit:48,45 text='.' +Read token at ../src/test_parser.nit:48,46--50 text='first' +Read token at ../src/test_parser.nit:48,52--53 text='==' +Read token at ../src/test_parser.nit:48,55--57 text=''-'' +Read token at ../src/test_parser.nit:48,59--60 text='do' +Read token at ../src/test_parser.nit:48,61--49,0 text=' ' Read token at ../src/test_parser.nit:49,2--3 text='if' Read token at ../src/test_parser.nit:49,5--8 text='args' diff --git a/tests/sav/test_ropes.res b/tests/sav/test_ropes.res deleted file mode 100644 index ce6b816..0000000 --- a/tests/sav/test_ropes.res +++ /dev/null @@ -1,7 +0,0 @@ -Je suis ici. -Je suis ici.Je suis ici.Je suis ici. -Je suis ici.Je suis ici.Je suis ici.Je suis ici.Je suis ici. -Je suis ici.Je suis ici. -Je su -je suis ici.hi !je suis ici.hi ! -JE SUIS ICI.HI !JE SUIS ICI.HI ! diff --git a/tests/shootout_nsieve.nit b/tests/shootout_nsieve.nit index b84da54..b0ecf41 100644 --- a/tests/shootout_nsieve.nit +++ b/tests/shootout_nsieve.nit @@ -19,13 +19,13 @@ do var count = 0 var array = new Buffer.with_capacity(n) for i in [0..n[ do - array[i] = 'o' + array.chars[i] = 'o' end for i in [2..n[ do - if array[i] == 'o' then + if array.chars[i] == 'o' then var j = i * 2 while j < n do - array[j] = 'x' + array.chars[j] = 'x' j = j + i end count = count + 1 diff --git a/tests/test_ropes.nit b/tests/test_ropes.nit deleted file mode 100644 index 86a0cd7..0000000 --- a/tests/test_ropes.nit +++ /dev/null @@ -1,108 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# This file is free software, which comes along with NIT. This software is -# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. You can modify it if you want, provided this header -# is kept unaltered, and a notification of the changes is added. -# You are allowed to redistribute it and sell it, alone or as a part of -# another product. - -module test_ropes - -var str_part_1 = "Je" - -var str_part_2 = "suis" - -var str_part_3 = "ici" - -var str_part_4 = "." - -var space = " " - -var test = "Je suis ici." - -var rope_uniq_test = new ImmutableRope.with_string("zzzzzzzzzzzzzzzzzzzzzzzzzzzz") - -var not_rope_uniq_test = new ImmutableRope.with_string("zzzzzzzzzzzzzezzzzzzzzzzzzzz") - -################################ -# Rope methods tests # -################################ - -var buf = new Buffer - -buf.append(str_part_1) -buf.append(space) -buf.append(str_part_2) -buf.append(space) -buf.append(str_part_3) -buf.append(str_part_4) - -print buf - -var buf_rope = new BufferRope - -buf_rope.append_multi(str_part_1,space,str_part_2,space,str_part_3,str_part_4) - -var buf_rope_with_str = new BufferRope.with_string(test) - -print buf_rope*3 - -print buf_rope_with_str*5 - -print buf_rope + buf_rope_with_str - -assert buf_rope.length == buf_rope_with_str.length - -assert buf_rope == buf_rope_with_str - -assert buf_rope.multi_concat(buf_rope, buf_rope) == buf_rope * 3 - -print buf_rope.subrope(0, 5) - -assert buf_rope.subrope(0, 5) == "Je su" - -buf_rope.append("Hi !") - -assert buf_rope > buf_rope_with_str - -assert buf_rope == buf_rope.chars.to_s - -assert buf_rope.chars.to_s == buf_rope - -assert buf == buf_rope_with_str - -###################################### -# BufferRope methods tests # -###################################### - -assert buf_rope + buf_rope == buf_rope.concat(buf_rope) - -assert buf_rope == buf_rope.freeze - -###################################### -# Rope.chars methods tests # -###################################### - -assert buf_rope.chars[3] == 's' - -assert buf_rope.chars.index_of('k') == -1 - -assert buf_rope.chars.index_of('s') == 3 - -assert buf_rope.chars.count('s') == 4 - -assert buf_rope.chars.last == '!' - -assert rope_uniq_test.chars.has_only('z') - -assert not not_rope_uniq_test.chars.has_only('z') - -assert (new BufferRope).chars.has_only('l') - -print buf_rope.to_lower - -print buf_rope.to_upper - - diff --git a/tests/test_string2.nit b/tests/test_string2.nit index 1401821..82e2527 100644 --- a/tests/test_string2.nit +++ b/tests/test_string2.nit @@ -15,9 +15,9 @@ fun test(s: String) do print s.length - print s.first - print s.last - print s[2] + print s.chars.first + print s.chars.last + print s.chars[2] print s.substring(1, 2) print s.substring(-1, 2) print s.substring(1, 0) diff --git a/tests/test_string_long.nit b/tests/test_string_long.nit index 94324a3..1b59ba8 100644 --- a/tests/test_string_long.nit +++ b/tests/test_string_long.nit @@ -23,8 +23,8 @@ var i = 0 while i < 5000 do var j = 0 while j < s.length do - r.add(s[j]) - r2.add(s[j]) + r.add(s.chars[j]) + r2.add(s.chars[j]) j = j + 1 end i = i + 1 diff --git a/tests/test_string_unicode.nit b/tests/test_string_unicode.nit index 9a576c7..9dee4a7 100644 --- a/tests/test_string_unicode.nit +++ b/tests/test_string_unicode.nit @@ -17,5 +17,5 @@ var a = "éè" print(a.length) for i in [0..a.length[ do - print("{i} is {a[i]} ({a[i].ascii})") + print("{i} is {a.chars[i]} ({a.chars[i].ascii})") end diff --git a/tests/test_substring.nit b/tests/test_substring.nit index 28eb4f3..c2393aa 100644 --- a/tests/test_substring.nit +++ b/tests/test_substring.nit @@ -34,10 +34,10 @@ print("has_suffix: {s.has_suffix(p)}") var test = "test" -print("test[0] == 't' => {test[0] == 't'}") -print("test[1] == 'e' => {test[1] == 'e'}") -print("test[2] == 's' => {test[2] == 's'}") -print("test[3] == 't' => {test[3] == 't'}") +print("test[0] == 't' => {test.chars[0] == 't'}") +print("test[1] == 'e' => {test.chars[1] == 'e'}") +print("test[2] == 's' => {test.chars[2] == 's'}") +print("test[3] == 't' => {test.chars[3] == 't'}") print("test.substring(0,1) == \"t\" => {test.substring(0,1) == "t"}") print("test.substring(0,2) == \"te\" => {test.substring(0,2) == "te"}")