v: remove the automatic passing of structs with more than 8 fields by reference (related #17159) (#22547)

This commit is contained in:
yuyi 2024-10-17 16:04:23 +08:00 committed by GitHub
parent 5f413f48f8
commit e97036a25b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 146 additions and 175 deletions

View file

@ -863,7 +863,6 @@ fn (t Tree) arg(node ast.Param) &Node {
obj.add_terse('is_mut', t.bool_node(node.is_mut))
obj.add_terse('is_shared', t.bool_node(node.is_shared))
obj.add_terse('is_atomic', t.bool_node(node.is_atomic))
obj.add_terse('is_auto_rec', t.bool_node(node.is_auto_rec))
obj.add_terse('on_newline', t.bool_node(node.on_newline))
obj.add('pos', t.pos(node.pos))
obj.add('type_pos', t.pos(node.type_pos))

View file

@ -56,7 +56,7 @@ struct SearchResult {
link string
}
fn (vd VDoc) render_search_index(out Output) {
fn (vd &VDoc) render_search_index(out Output) {
mut js_search_index := strings.new_builder(200)
mut js_search_data := strings.new_builder(200)
js_search_index.write_string('var searchModuleIndex = [\n')
@ -96,7 +96,7 @@ fn (mut vd VDoc) render_static_html(out Output) {
}
}
fn (vd VDoc) get_resource(name string, out Output) string {
fn (vd &VDoc) get_resource(name string, out Output) string {
cfg := vd.cfg
path := os.join_path(cfg.theme_dir, name)
mut res := os.read_file(path) or { panic('vdoc: could not read ${path}') }
@ -169,7 +169,7 @@ fn (mut vd VDoc) create_search_results(mod string, dn doc.DocNode, out Output) {
}
}
fn (vd VDoc) write_content(cn &doc.DocNode, d &doc.Doc, mut hw strings.Builder) {
fn (vd &VDoc) write_content(cn &doc.DocNode, d &doc.Doc, mut hw strings.Builder) {
cfg := vd.cfg
base_dir := os.dir(os.real_path(cfg.input_path))
file_path_name := if cfg.is_multi {
@ -192,7 +192,7 @@ fn (vd VDoc) write_content(cn &doc.DocNode, d &doc.Doc, mut hw strings.Builder)
}
}
fn (vd VDoc) gen_html(d doc.Doc) string {
fn (vd &VDoc) gen_html(d doc.Doc) string {
cfg := vd.cfg
mut symbols_toc := strings.new_builder(200)
mut modules_toc := strings.new_builder(200)

View file

@ -3,7 +3,7 @@ module main
import strings
import v.doc
fn (vd VDoc) gen_markdown(d doc.Doc, with_toc bool) string {
fn (vd &VDoc) gen_markdown(d doc.Doc, with_toc bool) string {
cfg := vd.cfg
mut hw := strings.new_builder(200)
mut cw := strings.new_builder(200)
@ -26,7 +26,7 @@ fn (vd VDoc) gen_markdown(d doc.Doc, with_toc bool) string {
return hw.str() + '\n' + cw.str()
}
fn (vd VDoc) write_markdown_content(contents []doc.DocNode, mut cw strings.Builder, mut hw strings.Builder,
fn (vd &VDoc) write_markdown_content(contents []doc.DocNode, mut cw strings.Builder, mut hw strings.Builder,
indent int, with_toc bool) {
cfg := vd.cfg
for cn in contents {

View file

@ -57,7 +57,7 @@ pub mut:
type Defaults = CommandFlag | bool
// str returns the `string` representation of the `Command`.
pub fn (cmd Command) str() string {
pub fn (cmd &Command) str() string {
mut res := []string{}
res << 'Command{'
res << ' name: "${cmd.name}"'
@ -88,20 +88,20 @@ pub fn (cmd Command) str() string {
}
// is_root returns `true` if this `Command` has no parents.
pub fn (cmd Command) is_root() bool {
pub fn (cmd &Command) is_root() bool {
return isnil(cmd.parent)
}
// root returns the root `Command` of the command chain.
pub fn (cmd Command) root() Command {
pub fn (cmd &Command) root() Command {
if cmd.is_root() {
return cmd
return *cmd
}
return cmd.parent.root()
}
// full_name returns the full `string` representation of all commands int the chain.
pub fn (cmd Command) full_name() string {
pub fn (cmd &Command) full_name() string {
if cmd.is_root() {
return cmd.name
}
@ -317,7 +317,7 @@ fn (mut cmd Command) handle_cb(cb FnCommandCallback, label string) {
}
}
fn (cmd Command) check_help_flag() {
fn (cmd &Command) check_help_flag() {
if cmd.defaults.parsed.help.flag && cmd.flags.contains('help') {
help_flag := cmd.flags.get_bool('help') or { return } // ignore error and handle command normally
if help_flag {
@ -327,7 +327,7 @@ fn (cmd Command) check_help_flag() {
}
}
fn (cmd Command) check_man_flag() {
fn (cmd &Command) check_man_flag() {
if cmd.defaults.parsed.man.flag && cmd.flags.contains('man') {
man_flag := cmd.flags.get_bool('man') or { return } // ignore error and handle command normally
if man_flag {
@ -337,7 +337,7 @@ fn (cmd Command) check_man_flag() {
}
}
fn (cmd Command) check_version_flag() {
fn (cmd &Command) check_version_flag() {
if cmd.defaults.parsed.version.flag && cmd.version != '' && cmd.flags.contains('version') {
version_flag := cmd.flags.get_bool('version') or { return } // ignore error and handle command normally
if version_flag {
@ -347,7 +347,7 @@ fn (cmd Command) check_version_flag() {
}
}
fn (cmd Command) check_required_flags() {
fn (cmd &Command) check_required_flags() {
for flag in cmd.flags {
if flag.required && flag.value.len == 0 {
full_name := cmd.full_name()
@ -358,7 +358,7 @@ fn (cmd Command) check_required_flags() {
// execute_help executes the callback registered
// for the `-h`/`--help` flag option.
pub fn (cmd Command) execute_help() {
pub fn (cmd &Command) execute_help() {
if cmd.commands.contains('help') {
help_cmd := cmd.commands.get('help') or { return } // ignore error and handle command normally
if !isnil(help_cmd.execute) {
@ -371,7 +371,7 @@ pub fn (cmd Command) execute_help() {
// execute_help executes the callback registered
// for the `-man` flag option.
pub fn (cmd Command) execute_man() {
pub fn (cmd &Command) execute_man() {
if cmd.commands.contains('man') {
man_cmd := cmd.commands.get('man') or { return }
man_cmd.execute(man_cmd) or { panic(err) }

View file

@ -43,7 +43,7 @@ pub fn (flags []Flag) get_all_found() []Flag {
// get_bool returns `true` if the flag is set.
// get_bool returns an error if the `FlagType` is not boolean.
pub fn (flag Flag) get_bool() !bool {
pub fn (flag &Flag) get_bool() !bool {
if flag.flag != .bool {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `bool`')
}
@ -62,7 +62,7 @@ pub fn (flags []Flag) get_bool(name string) !bool {
// get_int returns the `int` value argument of the flag.
// get_int returns an error if the `FlagType` is not integer.
pub fn (flag Flag) get_int() !int {
pub fn (flag &Flag) get_int() !int {
if flag.flag != .int {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `int`')
}
@ -78,7 +78,7 @@ pub fn (flag Flag) get_int() !int {
// get_ints returns the array of `int` value argument of the flag specified in `name`.
// get_ints returns an error if the `FlagType` is not integer.
pub fn (flag Flag) get_ints() ![]int {
pub fn (flag &Flag) get_ints() ![]int {
if flag.flag != .int_array {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `int_array`')
}
@ -114,7 +114,7 @@ pub fn (flags []Flag) get_ints(name string) ![]int {
// get_float returns the `f64` value argument of the flag.
// get_float returns an error if the `FlagType` is not floating point.
pub fn (flag Flag) get_float() !f64 {
pub fn (flag &Flag) get_float() !f64 {
if flag.flag != .float {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `float`')
}
@ -130,7 +130,7 @@ pub fn (flag Flag) get_float() !f64 {
// get_floats returns the `f64` value argument of the flag.
// get_floats returns an error if the `FlagType` is not floating point.
pub fn (flag Flag) get_floats() ![]f64 {
pub fn (flag &Flag) get_floats() ![]f64 {
if flag.flag != .float_array {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `float_array`')
}
@ -166,7 +166,7 @@ pub fn (flags []Flag) get_floats(name string) ![]f64 {
// get_string returns the `string` value argument of the flag.
// get_string returns an error if the `FlagType` is not string.
pub fn (flag Flag) get_string() !string {
pub fn (flag &Flag) get_string() !string {
if flag.flag != .string {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `string`')
}
@ -182,7 +182,7 @@ pub fn (flag Flag) get_string() !string {
// get_strings returns the array of `string` value argument of the flag.
// get_strings returns an error if the `FlagType` is not string.
pub fn (flag Flag) get_strings() ![]string {
pub fn (flag &Flag) get_strings() ![]string {
if flag.flag != .string_array {
return error('${flag.name}: Invalid flag type `${flag.flag}`, expected `string_array`')
}
@ -285,7 +285,7 @@ fn (flags []Flag) contains(name string) bool {
}
// Check if value is set by command line option. If not, return default value.
fn (flag Flag) get_value_or_default_value() []string {
fn (flag &Flag) get_value_or_default_value() []string {
if flag.value.len == 0 && flag.default_value.len > 0 {
// If default value is set and no value provide, use default value.
return flag.default_value

View file

@ -43,7 +43,7 @@ pub fn print_help_for_command(cmd Command) ! {
}
// help_message returns a generated help message as a `string` for the `Command`.
pub fn (cmd Command) help_message() string {
pub fn (cmd &Command) help_message() string {
mut help := ''
help += 'Usage: ${cmd.full_name()}'
if cmd.flags.len > 0 {

View file

@ -38,7 +38,7 @@ pub fn print_manpage_for_command(cmd Command) ! {
// manpage returns a `string` containing the mdoc(7) manpage for
// this `Command`
pub fn (cmd Command) manpage() string {
pub fn (cmd &Command) manpage() string {
mut mdoc := '.Dd ${time.now().strftime('%B %d, %Y')}\n'
mdoc += '.Dt ${cmd.full_name().replace(' ', '-').to_upper()} 1\n'
mdoc += '.Os\n.Sh NAME\n.Nm ${cmd.full_name().replace(' ', '-')}\n.Nd ${cmd.description}\n'

View file

@ -36,6 +36,6 @@ fn print_version_for_command(cmd Command) ! {
}
// version returns a generated version `string` for the `Command`.
pub fn (cmd Command) version() string {
pub fn (cmd &Command) version() string {
return '${cmd.name} version ${cmd.version}'
}

View file

@ -562,7 +562,7 @@ fn (mut dl Dlmalloc) unlink_large_chunk(chunk_ &TreeChunk) {
fn (mut dl Dlmalloc) unlink_first_small_chunk(head_ &Chunk, next_ &Chunk, idx u32) {
mut next := unsafe { next_ }
mut head := unsafe { head_ }
println('Unlink first small')
// println('Unlink first small')
mut ptr := next.prev
if voidptr(head) == voidptr(ptr) {
unsafe { dl.clear_smallmap(idx) }
@ -675,7 +675,7 @@ pub fn (mut dl Dlmalloc) free_(mem voidptr) {
}
}
fn (dl Dlmalloc) should_trim(size usize) bool {
fn (dl &Dlmalloc) should_trim(size usize) bool {
return size > dl.trim_check
}

View file

@ -545,7 +545,7 @@ pub fn (mut fs FlagParser) arguments_description(description string) {
// usage returns a nicely formatted usage screen, containing all the
// possible options, as well as the description for the program.
// That screen is usually shown when the `--help` option is given to the program.
pub fn (fs FlagParser) usage() string {
pub fn (fs &FlagParser) usage() string {
positive_min_arg := (fs.min_free_args > 0)
positive_max_arg := (fs.max_free_args > 0 && fs.max_free_args != max_args_number)
no_arguments := (fs.min_free_args == 0 && fs.max_free_args == 0)

View file

@ -20,7 +20,7 @@ pub:
// to_css_string returns a CSS compatible string of the TextCfg `cfg`.
// For example: `'mono 14px serif'`.
pub fn (cfg TextCfg) to_css_string() string {
pub fn (cfg &TextCfg) to_css_string() string {
mut font_style := ''
if cfg.bold {
font_style += 'bold '

View file

@ -170,18 +170,18 @@ fn (mut dom DocumentObjectModel) construct(tag_list []&Tag) {
}
// get_root returns the root of the document.
pub fn (dom DocumentObjectModel) get_root() &Tag {
pub fn (dom &DocumentObjectModel) get_root() &Tag {
return dom.root
}
// get_tag retrieves all tags in the document that have the given tag name.
@[deprecated: 'use get_tags instead']
pub fn (dom DocumentObjectModel) get_tag(name string) []&Tag {
pub fn (dom &DocumentObjectModel) get_tag(name string) []&Tag {
return dom.get_tags(name: name)
}
// get_tags returns all tags stored in the document.
pub fn (dom DocumentObjectModel) get_tags(options GetTagsOptions) []&Tag {
pub fn (dom &DocumentObjectModel) get_tags(options GetTagsOptions) []&Tag {
if options.name != '' {
return if options.name in dom.tag_type {
unsafe { dom.tag_type[options.name] }
@ -193,18 +193,18 @@ pub fn (dom DocumentObjectModel) get_tags(options GetTagsOptions) []&Tag {
}
// get_tags_by_class_name retrieves all tags recursively in the document root that have the given class name(s).
pub fn (dom DocumentObjectModel) get_tags_by_class_name(names ...string) []&Tag {
pub fn (dom &DocumentObjectModel) get_tags_by_class_name(names ...string) []&Tag {
return dom.root.get_tags_by_class_name(...names)
}
// get_tag_by_attribute retrieves all tags in the document that have the given attribute name.
@[deprecated: 'use get_tags_by_attribute instead']
pub fn (dom DocumentObjectModel) get_tag_by_attribute(name string) []&Tag {
pub fn (dom &DocumentObjectModel) get_tag_by_attribute(name string) []&Tag {
return dom.get_tags_by_attribute(name)
}
// get_tags_by_attribute retrieves all tags in the document that have the given attribute name.
pub fn (dom DocumentObjectModel) get_tags_by_attribute(name string) []&Tag {
pub fn (dom &DocumentObjectModel) get_tags_by_attribute(name string) []&Tag {
return if name in dom.all_attributes { unsafe { dom.all_attributes[name] } } else { []&Tag{} }
}

View file

@ -35,7 +35,7 @@ fn (mut tag Tag) add_child(t &Tag) int {
}
// text returns the text contents of the tag.
pub fn (tag Tag) text() string {
pub fn (tag &Tag) text() string {
if tag.name.len >= 2 && tag.name[..2] == 'br' {
return '\n'
}

View file

@ -180,7 +180,7 @@ pub fn (mut ws Client) read_next_message() !Message {
}
// payload_from_fragments returns the whole paylaod from fragmented message
fn (ws Client) payload_from_fragments(fin_payload []u8) ![]u8 {
fn (ws &Client) payload_from_fragments(fin_payload []u8) ![]u8 {
mut total_size := 0
for f in ws.fragments {
if f.data.len > 0 {
@ -202,7 +202,7 @@ fn (ws Client) payload_from_fragments(fin_payload []u8) ![]u8 {
}
// opcode_from_fragments returns the opcode for message from the first fragment sent
fn (ws Client) opcode_from_fragments() OPCode {
fn (ws &Client) opcode_from_fragments() OPCode {
return OPCode(ws.fragments[0].opcode)
}
@ -287,7 +287,7 @@ pub fn (mut ws Client) parse_frame_header() !Frame {
}
// unmask_sequence unmask any given sequence
fn (f Frame) unmask_sequence(mut buffer []u8) {
fn (f &Frame) unmask_sequence(mut buffer []u8) {
for i in 0 .. buffer.len {
buffer[i] ^= f.masking_key[i % 4] & 0xff
}

View file

@ -456,14 +456,14 @@ pub fn (mut ws Client) set_state(state State) {
}
// get_state return the current state of the websocket connection
pub fn (ws Client) get_state() State {
pub fn (ws &Client) get_state() State {
return rlock ws.client_state {
ws.client_state.state
}
}
// assert_not_connected returns error if the connection is not connected
fn (ws Client) assert_not_connected() ! {
fn (ws &Client) assert_not_connected() ! {
match ws.get_state() {
.connecting { return error('connect: websocket is connecting') }
.open { return error('connect: websocket already open') }

View file

@ -239,7 +239,7 @@ pub fn (mut s Server) set_state(state State) {
}
// get_state return current state in a thread safe way
pub fn (s Server) get_state() State {
pub fn (s &Server) get_state() State {
return rlock s.server_state {
s.server_state.state
}

View file

@ -25,11 +25,11 @@ pub:
// check checks the `ast.Value` and all it's children
// for common errors.
pub fn (c Checker) check(n &ast.Value) ! {
pub fn (c &Checker) check(n &ast.Value) ! {
walker.walk(c, n)!
}
fn (c Checker) visit(value &ast.Value) ! {
fn (c &Checker) visit(value &ast.Value) ! {
match value {
ast.Bool {
c.check_boolean(value)!
@ -54,7 +54,7 @@ fn (c Checker) visit(value &ast.Value) ! {
}
// excerpt returns a string of the token's surroundings
fn (c Checker) excerpt(tp token.Pos) string {
fn (c &Checker) excerpt(tp token.Pos) string {
return c.scanner.excerpt(tp.pos, 10)
}
@ -82,7 +82,7 @@ fn has_repeating(str string, repeats []rune) bool {
}
// check_number returns an error if `num` is not a valid TOML number.
fn (c Checker) check_number(num ast.Number) ! {
fn (c &Checker) check_number(num ast.Number) ! {
lit := num.text
lit_lower_case := lit.to_lower()
if lit in ['0', '0.0', '+0', '-0', '+0.0', '-0.0', '0e0', '+0e0', '-0e0', '0e00'] {
@ -229,7 +229,7 @@ fn (c Checker) check_number(num ast.Number) ! {
}
// is_valid_binary_literal returns true if `num` is valid TOML binary literal.
fn (c Checker) is_valid_binary_literal(num string) bool {
fn (c &Checker) is_valid_binary_literal(num string) bool {
for ch in num {
if ch == `_` {
continue
@ -242,7 +242,7 @@ fn (c Checker) is_valid_binary_literal(num string) bool {
}
// is_valid_octal_literal returns true if `num` is valid TOML octal literal.
fn (c Checker) is_valid_octal_literal(num string) bool {
fn (c &Checker) is_valid_octal_literal(num string) bool {
for ch in num {
if ch == `_` {
continue
@ -255,7 +255,7 @@ fn (c Checker) is_valid_octal_literal(num string) bool {
}
// is_valid_hex_literal returns true if `num` is valid TOML hexadecimal literal.
fn (c Checker) is_valid_hex_literal(num string) bool {
fn (c &Checker) is_valid_hex_literal(num string) bool {
for ch in num {
if ch == `_` {
continue
@ -268,7 +268,7 @@ fn (c Checker) is_valid_hex_literal(num string) bool {
}
// check_boolean returns an error if `b` is not a valid TOML boolean.
fn (c Checker) check_boolean(b ast.Bool) ! {
fn (c &Checker) check_boolean(b ast.Bool) ! {
lit := b.text
if lit in ['true', 'false'] {
return
@ -280,7 +280,7 @@ fn (c Checker) check_boolean(b ast.Bool) ! {
// check_date_time returns an error if `dt` is not a valid TOML date-time string (RFC 3339).
// See also https://ijmacd.github.io/rfc3339-iso8601 for a more
// visual representation of the RFC 3339 format.
fn (c Checker) check_date_time(dt ast.DateTime) ! {
fn (c &Checker) check_date_time(dt ast.DateTime) ! {
lit := dt.text
mut split := []string{}
// RFC 3339 Date-Times can be split via 4 separators (` `, `_`, `T` and `t`).
@ -330,7 +330,7 @@ fn (c Checker) check_date_time(dt ast.DateTime) ! {
}
// check_time returns an error if `date` is not a valid TOML date string (RFC 3339).
fn (c Checker) check_date(date ast.Date) ! {
fn (c &Checker) check_date(date ast.Date) ! {
lit := date.text
parts := lit.split('-')
if parts.len != 3 {
@ -360,7 +360,7 @@ fn (c Checker) check_date(date ast.Date) ! {
}
// check_time returns an error if `t` is not a valid TOML time string (RFC 3339).
fn (c Checker) check_time(t ast.Time) ! {
fn (c &Checker) check_time(t ast.Time) ! {
lit := t.text
// Split any offsets from the time
mut offset_splitter := if lit.contains('+') { '+' } else { '-' }
@ -388,7 +388,7 @@ fn (c Checker) check_time(t ast.Time) ! {
}
// check_quoted returns an error if `q` is not a valid quoted TOML string.
pub fn (c Checker) check_quoted(q ast.Quoted) ! {
pub fn (c &Checker) check_quoted(q ast.Quoted) ! {
lit := q.text
quote := q.quote.ascii_str()
triple_quote := quote + quote + quote
@ -414,7 +414,7 @@ pub fn (c Checker) check_quoted(q ast.Quoted) ! {
// \\ - backslash (U+005C)
// \uXXXX - Unicode (U+XXXX)
// \UXXXXXXXX - Unicode (U+XXXXXXXX)
fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
fn (c &Checker) check_quoted_escapes(q ast.Quoted) ! {
// Setup a scanner in stack memory for easier navigation.
mut s := scanner.new_simple_text(q.text)!
@ -494,7 +494,7 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ! {
}
// check_utf8_string returns an error if `str` is not valid UTF-8.
fn (c Checker) check_utf8_validity(q ast.Quoted) ! {
fn (c &Checker) check_utf8_validity(q ast.Quoted) ! {
lit := q.text
if !utf8.validate_str(lit) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
@ -524,7 +524,7 @@ fn validate_utf8_codepoint_string(str string) ! {
// check_unicode_escape returns an error if `esc_unicode` is not
// a valid Unicode escape sequence. `esc_unicode` is expected to be
// prefixed with either `u` or `U`.
fn (c Checker) check_unicode_escape(esc_unicode string) ! {
fn (c &Checker) check_unicode_escape(esc_unicode string) ! {
if esc_unicode.len < 5 || !esc_unicode.to_lower().starts_with('u') {
// Makes sure the input to this function is actually valid.
return error('`${esc_unicode}` is not a valid escaped Unicode sequence.')
@ -550,7 +550,7 @@ fn (c Checker) check_unicode_escape(esc_unicode string) ! {
// check_comment returns an error if the contents of `comment` isn't
// a valid TOML comment.
pub fn (c Checker) check_comment(comment ast.Comment) ! {
pub fn (c &Checker) check_comment(comment ast.Comment) ! {
lit := comment.text
// Setup a scanner in stack memory for easier navigation.
mut s := scanner.new_simple_text(lit)!

View file

@ -260,7 +260,7 @@ fn (mut p Parser) expect(expected_token token.Kind) ! {
}
// build_abs_dotted_key returns the absolute dotted key path.
fn (p Parser) build_abs_dotted_key(key DottedKey) DottedKey {
fn (p &Parser) build_abs_dotted_key(key DottedKey) DottedKey {
if p.root_map_key.len > 0 {
mut abs_dotted_key := DottedKey([]string{})
abs_dotted_key << p.root_map_key
@ -277,7 +277,7 @@ fn todo_msvc_astring2dkey(s []string) DottedKey {
}
// check_explicitly_declared returns an error if `key` has been explicitly declared.
fn (p Parser) check_explicitly_declared(key DottedKey) ! {
fn (p &Parser) check_explicitly_declared(key DottedKey) ! {
if p.explicit_declared.len > 0 && p.explicit_declared.has(key) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' key `${key.str()}` is already explicitly declared. Unexpected redeclaration at "${p.tok.kind}" "${p.tok.lit}" in this (excerpt): "...${p.excerpt()}..."')
@ -286,7 +286,7 @@ fn (p Parser) check_explicitly_declared(key DottedKey) ! {
// check_explicitly_declared_array_of_tables returns an error if `key` has been
// explicitly declared as an array of tables.
fn (p Parser) check_explicitly_declared_array_of_tables(key DottedKey) ! {
fn (p &Parser) check_explicitly_declared_array_of_tables(key DottedKey) ! {
if p.explicit_declared_array_of_tables.len > 0 && p.explicit_declared_array_of_tables.has(key) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' key `${key.str()}` is already an explicitly declared array of tables. Unexpected redeclaration at "${p.tok.kind}" "${p.tok.lit}" in this (excerpt): "...${p.excerpt()}..."')
@ -294,7 +294,7 @@ fn (p Parser) check_explicitly_declared_array_of_tables(key DottedKey) ! {
}
// check_implicitly_declared returns an error if `key` has been implicitly declared.
fn (p Parser) check_implicitly_declared(key DottedKey) ! {
fn (p &Parser) check_implicitly_declared(key DottedKey) ! {
if p.implicit_declared.len > 0 && p.implicit_declared.has(key) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' key `${key.str()}` is already implicitly declared. Unexpected redeclaration at "${p.tok.kind}" "${p.tok.lit}" in this (excerpt): "...${p.excerpt()}..."')
@ -665,7 +665,7 @@ pub fn (mut p Parser) root_table() ! {
}
// excerpt returns a string of the characters surrounding `Parser.tok.pos`
fn (p Parser) excerpt() string {
fn (p &Parser) excerpt() string {
return p.scanner.excerpt(p.tok.pos, 10)
}

View file

@ -305,7 +305,7 @@ pub fn (s &Scanner) at() u32 {
// at_crlf returns `true` if the scanner is at a `\r` character
// and the next character is a `\n`.
fn (s Scanner) at_crlf() bool {
fn (s &Scanner) at_crlf() bool {
return s.at() == `\r` && s.peek(1) == `\n`
}
@ -654,14 +654,14 @@ fn (mut s Scanner) extract_nan_or_inf_number() !string {
// excerpt returns a string excerpt of the input text centered
// at `pos`. The `margin` argument defines how many chacters
// on each side of `pos` is returned
pub fn (s Scanner) excerpt(pos int, margin int) string {
pub fn (s &Scanner) excerpt(pos int, margin int) string {
start := if pos > 0 && pos >= margin { pos - margin } else { 0 }
end := if pos + margin < s.text.len { pos + margin } else { s.text.len }
return s.text[start..end].replace('\n', r'\n')
}
// state returns a read-only view of the scanner's internal state.
pub fn (s Scanner) state() State {
pub fn (s &Scanner) state() State {
return State{
col: s.col
line_nr: s.line_nr

View file

@ -707,15 +707,14 @@ fn (f &Fn) method_equals(o &Fn) bool {
@[minify]
pub struct Param {
pub:
pos token.Pos
name string
is_mut bool
is_shared bool
is_atomic bool
is_auto_rec bool
type_pos token.Pos
is_hidden bool // interface first arg
on_newline bool // whether the argument starts on a new line
pos token.Pos
name string
is_mut bool
is_shared bool
is_atomic bool
type_pos token.Pos
is_hidden bool // interface first arg
on_newline bool // whether the argument starts on a new line
pub mut:
typ Type
}

View file

@ -30,12 +30,12 @@ pub mut:
ct_skip bool // is the comptime expr *false*, filled by checker
}
pub fn (a Attr) debug() string {
pub fn (a &Attr) debug() string {
return 'Attr{ name: "${a.name}", has_arg: ${a.has_arg}, arg: "${a.arg}", kind: ${a.kind}, ct_expr: ${a.ct_expr}, ct_opt: ${a.ct_opt}, ct_skip: ${a.ct_skip}}'
}
// str returns the string representation without square brackets
pub fn (a Attr) str() string {
pub fn (a &Attr) str() string {
mut s := ''
mut arg := if a.has_arg {
s += '${a.name}: '

View file

@ -113,9 +113,6 @@ pub fn (t &Table) stringify_fn_decl(node &FnDecl, cur_mod string, m2a map[string
}
f.write_string(node.receiver.name + ' ')
styp = util.no_cur_mod(styp, cur_mod)
if node.params[0].is_auto_rec {
styp = styp.trim('&')
}
f.write_string(styp + ') ')
} else if node.is_static_type_method {
mut styp := util.no_cur_mod(t.type_to_code(node.receiver.typ.clear_flag(.shared_f)),

View file

@ -1506,7 +1506,7 @@ pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
}
}
pub fn (t Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
pub fn (t &Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
if typ.idx() == inter_typ.idx() {
// same type -> already casted to the interface
return true

View file

@ -416,7 +416,7 @@ pub fn (t Type) has_option_or_result() bool {
}
@[inline]
pub fn (ts TypeSymbol) scoped_name() string {
pub fn (ts &TypeSymbol) scoped_name() string {
return if ts.info is Struct && ts.info.scoped_name != '' {
ts.info.scoped_name
} else {
@ -425,7 +425,7 @@ pub fn (ts TypeSymbol) scoped_name() string {
}
@[inline]
pub fn (ts TypeSymbol) scoped_cname() string {
pub fn (ts &TypeSymbol) scoped_cname() string {
return if ts.info is Struct && ts.info.scoped_name != '' {
ts.info.scoped_name.replace('.', '__')
} else {
@ -434,7 +434,7 @@ pub fn (ts TypeSymbol) scoped_cname() string {
}
// debug returns a verbose representation of the information in ts, useful for tracing/debugging
pub fn (ts TypeSymbol) debug() []string {
pub fn (ts &TypeSymbol) debug() []string {
mut res := []string{}
ts.dbg_common(mut res)
res << 'info: ${ts.info}'
@ -443,13 +443,13 @@ pub fn (ts TypeSymbol) debug() []string {
}
// same as .debug(), but without the verbose .info and .methods fields
pub fn (ts TypeSymbol) dbg() []string {
pub fn (ts &TypeSymbol) dbg() []string {
mut res := []string{}
ts.dbg_common(mut res)
return res
}
fn (ts TypeSymbol) dbg_common(mut res []string) {
fn (ts &TypeSymbol) dbg_common(mut res []string) {
res << 'idx: 0x${ts.idx.hex()}'
res << 'parent_idx: 0x${ts.parent_idx.hex()}'
res << 'mod: ${ts.mod}'
@ -460,7 +460,7 @@ fn (ts TypeSymbol) dbg_common(mut res []string) {
res << 'language: ${ts.language}'
}
pub fn (ts TypeSymbol) nr_dims() int {
pub fn (ts &TypeSymbol) nr_dims() int {
match ts.info {
Alias {
parent_sym := global_table.sym(ts.info.parent_type)
@ -831,7 +831,7 @@ pub enum Kind {
}
// str returns the internal & source name of the type
pub fn (t TypeSymbol) str() string {
pub fn (t &TypeSymbol) str() string {
return t.name
}
@ -1550,7 +1550,7 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
return res
}
fn (t Table) shorten_user_defined_typenames(original_name string, import_aliases map[string]string) string {
fn (t &Table) shorten_user_defined_typenames(original_name string, import_aliases map[string]string) string {
if alias := import_aliases[original_name] {
return alias
}

View file

@ -338,7 +338,7 @@ pub fn (b &Builder) import_graph() &depgraph.DepGraph {
return graph
}
pub fn (b Builder) v_files_from_dir(dir string) []string {
pub fn (b &Builder) v_files_from_dir(dir string) []string {
if !os.exists(dir) {
if dir == 'compiler' && os.is_dir('vlib') {
println('looks like you are trying to build V with an old command')
@ -367,13 +367,13 @@ pub fn (b Builder) v_files_from_dir(dir string) []string {
return res
}
pub fn (b Builder) log(s string) {
pub fn (b &Builder) log(s string) {
if b.pref.is_verbose {
println(s)
}
}
pub fn (b Builder) info(s string) {
pub fn (b &Builder) info(s string) {
if b.pref.is_verbose {
println(s)
}

View file

@ -192,7 +192,7 @@ fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return true
}
fn (c Checker) check_multiple_ptr_match(got ast.Type, expected ast.Type, param ast.Param, arg ast.CallArg) bool {
fn (c &Checker) check_multiple_ptr_match(got ast.Type, expected ast.Type, param ast.Param, arg ast.CallArg) bool {
param_nr_muls := if param.is_mut && !expected.is_ptr() { 1 } else { expected.nr_muls() }
if got.is_ptr() && got.nr_muls() > 1 && got.nr_muls() != param_nr_muls {
if arg.expr is ast.PrefixExpr && arg.expr.op == .amp {
@ -361,7 +361,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan
}
}
fn (c Checker) get_string_names_of(got ast.Type, expected ast.Type) (string, string) {
fn (c &Checker) get_string_names_of(got ast.Type, expected ast.Type) (string, string) {
got_typ_str := c.table.type_to_str(got.clear_flag(.variadic))
expected_typ_str := c.table.type_to_str(expected.clear_flag(.variadic))
return got_typ_str, expected_typ_str
@ -370,7 +370,7 @@ fn (c Checker) get_string_names_of(got ast.Type, expected ast.Type) (string, str
// helper method to check if the type is of the same module.
// FIXME(vincenzopalazzo) This is a work around to the issue
// explained in the https://github.com/vlang/v/pull/13718#issuecomment-1074517800
fn (c Checker) check_same_module(got ast.Type, expected ast.Type) bool {
fn (c &Checker) check_same_module(got ast.Type, expected ast.Type) bool {
clean_got_typ := c.table.clean_generics_type_str(got.clear_flag(.variadic)).all_before('<')
clean_expected_typ := c.table.clean_generics_type_str(expected.clear_flag(.variadic)).all_before('<')
if clean_got_typ == clean_expected_typ {

View file

@ -568,7 +568,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
// check_same_type_ignoring_pointers util function to check if the Types are the same, including all
// corner cases.
// FIXME: if the optimization is done after the checker, we can safely remove this util function
fn (c Checker) check_same_type_ignoring_pointers(type_a ast.Type, type_b ast.Type) bool {
fn (c &Checker) check_same_type_ignoring_pointers(type_a ast.Type, type_b ast.Type) bool {
// FIXME: if possible pass the ast.Node and check the property `is_auto_rec`
if type_a != type_b {
// before failing we must be sure that the parser didn't optimize the function

View file

@ -28,17 +28,15 @@ pub fn (mut c Checker) lambda_expr(mut node ast.LambdaExpr, exp_typ ast.Type) as
for idx, mut x in node.params {
eparam := exp_sym.info.func.params[idx]
eparam_type := eparam.typ
eparam_auto_deref := eparam.typ.is_ptr()
c.lambda_expr_fix_type_of_param(mut node, mut x, eparam_type)
if eparam_type.has_flag(.generic) {
generic_types[eparam_type] = true
}
params << ast.Param{
pos: x.pos
name: x.name
typ: eparam_type
type_pos: x.pos
is_auto_rec: eparam_auto_deref
pos: x.pos
name: x.name
typ: eparam_type
type_pos: x.pos
}
}
@ -139,18 +137,15 @@ pub fn (mut c Checker) lambda_expr_fix_type_of_param(mut node ast.LambdaExpr, mu
}
pub fn (mut c Checker) support_lambda_expr_in_sort(param_type ast.Type, return_type ast.Type, mut expr ast.LambdaExpr) {
is_auto_rec := param_type.is_ptr()
mut expected_fn := ast.Fn{
params: [
ast.Param{
name: 'zza'
typ: param_type
is_auto_rec: is_auto_rec
name: 'zza'
typ: param_type
},
ast.Param{
name: 'zzb'
typ: param_type
is_auto_rec: is_auto_rec
name: 'zzb'
typ: param_type
},
]
return_type: return_type
@ -164,9 +159,8 @@ pub fn (mut c Checker) support_lambda_expr_one_param(param_type ast.Type, return
mut expected_fn := ast.Fn{
params: [
ast.Param{
name: 'xx'
typ: param_type
is_auto_rec: param_type.is_ptr()
name: 'xx'
typ: param_type
},
]
return_type: return_type

View file

@ -276,20 +276,20 @@ pub fn (mut e Eval) register_symbol(stmt ast.Stmt, mod string, file string) {
}
}
fn (e Eval) error(msg string) {
fn (e &Eval) error(msg string) {
eprintln('> V interpreter backtrace:')
e.print_backtrace()
util.verror('interpreter', msg)
}
fn (e Eval) panic(s string) {
fn (e &Eval) panic(s string) {
eprintln('V panic: ${s}')
eprintln('V hash: ${@VCURRENTHASH}')
e.print_backtrace()
exit(1)
}
fn (e Eval) print_backtrace() {
fn (e &Eval) print_backtrace() {
for i := e.back_trace.len - 1; i >= 0; i-- {
t := e.back_trace[i]
file_path := if path := e.trace_file_paths[t.file_idx] {

View file

@ -584,7 +584,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
return empty
}
fn (e Eval) type_to_size(typ ast.Type) u64 {
fn (e &Eval) type_to_size(typ ast.Type) u64 {
match typ {
ast.voidptr_type_idx, ast.nil_type_idx, ast.byteptr_type_idx, ast.charptr_type_idx {
return u64(if e.pref.m64 {
@ -612,7 +612,7 @@ fn (e Eval) type_to_size(typ ast.Type) u64 {
}
}
fn (e Eval) get_escape(r rune) rune {
fn (e &Eval) get_escape(r rune) rune {
res := match r {
`\\` {
`\\`

View file

@ -8,7 +8,7 @@ const header = '[generated]
module eval
import v.token
import v.ast
fn(e Eval)infix_expr(left Object,right Object,op token.Kind,expecting ast.Type)Object{match op{'
fn(e &Eval)infix_expr(left Object,right Object,op token.Kind,expecting ast.Type)Object{match op{'
const footer = "else{e.error('unknown infix expression: \$op')}}return empty // should e.error before this anyway
}

View file

@ -4,7 +4,7 @@ module eval
import v.token
import v.ast
fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.Type) Object {
fn (e &Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.Type) Object {
match op {
.gt {
match left {

View file

@ -1213,7 +1213,7 @@ fn (mut g Gen) result_type_name(t ast.Type) (string, string) {
return styp, base
}
fn (g Gen) option_type_text(styp string, base string) string {
fn (g &Gen) option_type_text(styp string, base string) string {
// replace void with something else
size := if base == 'void' {
'u8'
@ -1234,7 +1234,7 @@ fn (g Gen) option_type_text(styp string, base string) string {
return ret
}
fn (g Gen) result_type_text(styp string, base string) string {
fn (g &Gen) result_type_text(styp string, base string) string {
// replace void with something else
size := if base == 'void' {
'u8'
@ -7515,7 +7515,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
}
}
fn (g Gen) get_all_test_function_names() []string {
fn (g &Gen) get_all_test_function_names() []string {
mut tfuncs := []string{}
mut tsuite_begin := ''
mut tsuite_end := ''
@ -7704,7 +7704,7 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
}
}
fn (g Gen) as_cast_name_table() string {
fn (g &Gen) as_cast_name_table() string {
if g.as_cast_type_names.len == 0 {
return 'new_array_from_c_array(1, 1, sizeof(VCastTypeIndexName), _MOV((VCastTypeIndexName[1]){(VCastTypeIndexName){.tindex = 0,.tname = _SLIT("unknown")}}));\n'
}
@ -7719,7 +7719,7 @@ fn (g Gen) as_cast_name_table() string {
return name_ast.str()
}
fn (g Gen) has_been_referenced(fn_name string) bool {
fn (g &Gen) has_been_referenced(fn_name string) bool {
mut referenced := false
lock g.referenced_fns {
referenced = g.referenced_fns[fn_name]

View file

@ -1342,7 +1342,7 @@ fn (mut g Gen) resolve_fn_return_type(node ast.CallExpr) ast.Type {
return ast.void_type
}
fn (g Gen) get_generic_array_element_type(array ast.Array) ast.Type {
fn (g &Gen) get_generic_array_element_type(array ast.Array) ast.Type {
mut cparam_elem_info := array as ast.Array
mut cparam_elem_sym := g.table.sym(cparam_elem_info.elem_type)
mut typ := ast.void_type

View file

@ -25,13 +25,13 @@ fn (mut g Gen) gen_reflection_strings() {
// gen_empty_array generates code for empty array
@[inline]
fn (g Gen) gen_empty_array(type_name string) string {
fn (g &Gen) gen_empty_array(type_name string) string {
return '__new_array_with_default(0, 0, sizeof(${type_name}), 0)'
}
// gen_functionarg_array generates the code for functionarg argument
@[inline]
fn (g Gen) gen_functionarg_array(type_name string, node ast.Fn) string {
fn (g &Gen) gen_functionarg_array(type_name string, node ast.Fn) string {
if node.params.len == 0 {
return g.gen_empty_array(type_name)
}
@ -88,7 +88,7 @@ fn (mut g Gen) gen_reflection_sym(tsym ast.TypeSymbol) string {
// gen_attrs_array generates C code for []Attr
@[inline]
fn (g Gen) gen_attrs_array(attrs []ast.Attr) string {
fn (g &Gen) gen_attrs_array(attrs []ast.Attr) string {
if attrs.len == 0 {
return g.gen_empty_array('string')
}
@ -101,7 +101,7 @@ fn (g Gen) gen_attrs_array(attrs []ast.Attr) string {
// gen_fields_array generates C code for []StructField
@[inline]
fn (g Gen) gen_fields_array(fields []ast.StructField) string {
fn (g &Gen) gen_fields_array(fields []ast.StructField) string {
if fields.len == 0 {
return g.gen_empty_array('${cprefix}StructField')
}
@ -114,7 +114,7 @@ fn (g Gen) gen_fields_array(fields []ast.StructField) string {
// gen_type_array generates C code for []Type
@[inline]
fn (g Gen) gen_type_array(types []ast.Type) string {
fn (g &Gen) gen_type_array(types []ast.Type) string {
if types.len == 0 {
return g.gen_empty_array(ast.int_type_name)
}
@ -123,7 +123,7 @@ fn (g Gen) gen_type_array(types []ast.Type) string {
// gen_string_array generates C code for []string
@[inline]
fn (g Gen) gen_string_array(strs []string) string {
fn (g &Gen) gen_string_array(strs []string) string {
if strs.len == 0 {
return g.gen_empty_array('string')
}

View file

@ -32,6 +32,6 @@ const whitelist = {
'main.main': false
}
fn (g Gen) is_blacklisted(name string, is_builtin bool) bool {
fn (g &Gen) is_blacklisted(name string, is_builtin bool) bool {
return whitelist[name] or { is_builtin }
}

View file

@ -102,7 +102,7 @@ pub fn (mut g Gen) w_error(s string) {
util.verror('wasm error', s)
}
pub fn (g Gen) unpack_type(typ ast.Type) []ast.Type {
pub fn (g &Gen) unpack_type(typ ast.Type) []ast.Type {
ts := g.table.sym(typ)
return match ts.info {
ast.MultiReturn {
@ -114,7 +114,7 @@ pub fn (g Gen) unpack_type(typ ast.Type) []ast.Type {
}
}
pub fn (g Gen) is_param_type(typ ast.Type) bool {
pub fn (g &Gen) is_param_type(typ ast.Type) bool {
return !typ.is_ptr() && !g.is_pure_type(typ)
}

View file

@ -276,7 +276,7 @@ pub fn (mut g Gen) new_global(name string, typ_ ast.Type, init ast.Expr, is_glob
// is_pure_type(voidptr) == true
// is_pure_type(&Struct) == false
pub fn (g Gen) is_pure_type(typ ast.Type) bool {
pub fn (g &Gen) is_pure_type(typ ast.Type) bool {
if typ.is_pure_int() || typ.is_pure_float() || typ == ast.char_type_idx
|| typ.is_any_kind_of_pointer() || typ.is_bool() {
return true

View file

@ -453,7 +453,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
name: param.name
typ: param.typ
is_mut: param.is_mut
is_auto_deref: param.is_mut || param.is_auto_rec
is_auto_deref: param.is_mut
is_stack_obj: is_stack_obj
pos: param.pos
is_used: true
@ -771,16 +771,6 @@ fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInf
if is_atomic {
rec.typ = rec.typ.set_flag(.atomic_f)
}
// optimize method `automatic use fn (a &big_foo) instead of fn (a big_foo)`
type_sym := p.table.sym(rec.typ)
mut is_auto_rec := false
if type_sym.kind == .struct {
info := type_sym.info as ast.Struct
if !rec.is_mut && !rec.typ.is_ptr() && info.fields.len > 8 {
rec.typ = rec.typ.ref()
is_auto_rec = true
}
}
if rec.language != .v {
p.check_for_impure_v(rec.language, rec.type_pos)
@ -788,22 +778,14 @@ fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInf
p.check(.rpar)
if is_auto_rec && p.tok.kind != .name {
// Disable the auto-reference conversion for methodlike operators like ==, <=, > etc,
// since their parameters and receivers, *must* always be of the same type.
is_auto_rec = false
rec.typ = rec.typ.deref()
}
params << ast.Param{
pos: rec_start_pos
name: rec.name
is_mut: rec.is_mut
is_atomic: is_atomic
is_shared: is_shared
is_auto_rec: is_auto_rec
typ: rec.typ
type_pos: rec.type_pos
pos: rec_start_pos
name: rec.name
is_mut: rec.is_mut
is_atomic: is_atomic
is_shared: is_shared
typ: rec.typ
type_pos: rec.type_pos
}
}
@ -846,7 +828,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
name: param.name
typ: param.typ
is_mut: param.is_mut
is_auto_deref: param.is_mut || param.is_auto_rec
is_auto_deref: param.is_mut
pos: param.pos
is_used: true
is_arg: true

View file

@ -3497,7 +3497,7 @@ fn (mut p Parser) parse_concrete_types() []ast.Type {
}
// is_generic_name returns true if the current token is a generic name.
fn (p Parser) is_generic_name() bool {
fn (p &Parser) is_generic_name() bool {
return p.tok.kind == .name && util.is_generic_type_name(p.tok.lit)
}

View file

@ -258,7 +258,7 @@ fn (mut s Scanner) ident_name() string {
return name
}
fn (s Scanner) num_lit(start int, end int) string {
fn (s &Scanner) num_lit(start int, end int) string {
if s.is_fmt {
return s.text[start..end]
}

View file

@ -11,7 +11,7 @@ struct Gen {
s shared St
}
fn (g Gen) set_val() bool {
fn (g &Gen) set_val() bool {
lock g.s {
g.s.x = 6.25
if g.s.x == 6.25 {

View file

@ -107,7 +107,7 @@ fn (mut s Scanner) create_ident() string {
return text
}
fn (s Scanner) peek_char(c u8) bool {
fn (s &Scanner) peek_char(c u8) bool {
return s.pos - 1 < s.text.len && s.text[s.pos - 1] == c
}

View file

@ -203,7 +203,7 @@ struct Route {
// Defining this method is optional.
// This method called at server start.
// You can use it for initializing globals.
pub fn (ctx Context) init_server() {
pub fn (ctx &Context) init_server() {
eprintln('init_server() has been deprecated, please init your web app in `fn main()`')
}
@ -220,7 +220,7 @@ pub fn (ctx &Context) before_accept_loop() {
// It will be called in one of multiple threads in a pool, serving requests,
// the same one, in which the matching route method will be executed right after it.
// Defining this method is optional.
pub fn (ctx Context) before_request() {}
pub fn (ctx &Context) before_request() {}
// TODO: test
// vweb intern function

View file

@ -101,12 +101,12 @@ fn (mut s Scanner) move_pos(include_space bool, include_newlines bool) {
}
// error returns an error token.
fn (s Scanner) error(description string) Token {
fn (s &Scanner) error(description string) Token {
return s.tokenize(description.bytes(), .error)
}
// tokenize returns a token based on the given lit and kind.
fn (s Scanner) tokenize(lit []u8, kind TokenKind) Token {
fn (s &Scanner) tokenize(lit []u8, kind TokenKind) Token {
return Token{
lit: lit
kind: kind
@ -242,7 +242,7 @@ fn (mut s Scanner) num_scan() Token {
}
// invalid_token returns an error token with the invalid token message.
fn (s Scanner) invalid_token() Token {
fn (s &Scanner) invalid_token() Token {
if s.text[s.pos] >= 32 && s.text[s.pos] <= 126 {
x := s.text[s.pos].ascii_str()
return s.error('invalid token `${x}`')