Skip to content

Commit a5f400e

Browse files
authored
parser, ast, fmt: convert "hello".str => c"hello" (fix #24635) (#24652)
1 parent 0de2f74 commit a5f400e

File tree

11 files changed

+41
-29
lines changed

11 files changed

+41
-29
lines changed

examples/vanilla_http_server/src/server.c.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn create_server_socket(port int) int {
112112
server_fd := C.socket(C.AF_INET, C.SOCK_STREAM, 0)
113113
if server_fd < 0 {
114114
eprintln(@LOCATION)
115-
C.perror('Socket creation failed'.str)
115+
C.perror(c'Socket creation failed')
116116
return -1
117117
}
118118

@@ -122,7 +122,7 @@ fn create_server_socket(port int) int {
122122
opt := 1
123123
if C.setsockopt(server_fd, C.SOL_SOCKET, C.SO_REUSEPORT, &opt, sizeof(opt)) < 0 {
124124
eprintln(@LOCATION)
125-
C.perror('setsockopt SO_REUSEPORT failed'.str)
125+
C.perror(c'setsockopt SO_REUSEPORT failed')
126126
close_socket(server_fd)
127127
return -1
128128
}
@@ -136,13 +136,13 @@ fn create_server_socket(port int) int {
136136

137137
if C.bind(server_fd, voidptr(&server_addr), sizeof(server_addr)) < 0 {
138138
eprintln(@LOCATION)
139-
C.perror('Bind failed'.str)
139+
C.perror(c'Bind failed')
140140
close_socket(server_fd)
141141
return -1
142142
}
143143
if C.listen(server_fd, max_connection_size) < 0 {
144144
eprintln(@LOCATION)
145-
C.perror('Listen failed'.str)
145+
C.perror(c'Listen failed')
146146
close_socket(server_fd)
147147
return -1
148148
}
@@ -157,7 +157,7 @@ fn add_fd_to_epoll(epoll_fd int, fd int, events u32) int {
157157
ev.data.fd = fd
158158
if C.epoll_ctl(epoll_fd, C.EPOLL_CTL_ADD, fd, &ev) == -1 {
159159
eprintln(@LOCATION)
160-
C.perror('epoll_ctl'.str)
160+
C.perror(c'epoll_ctl')
161161
return -1
162162
}
163163
return 0
@@ -178,7 +178,7 @@ fn handle_accept_loop(mut server Server) {
178178
}
179179

180180
eprintln(@LOCATION)
181-
C.perror('Accept failed'.str)
181+
C.perror(c'Accept failed')
182182
return
183183
}
184184

@@ -263,7 +263,7 @@ fn (mut server Server) run() {
263263
for i := 0; i < max_thread_pool_size; i++ {
264264
server.epoll_fds[i] = C.epoll_create1(0)
265265
if server.epoll_fds[i] < 0 {
266-
C.perror('epoll_create1 failed'.str)
266+
C.perror(c'epoll_create1 failed')
267267
close_socket(server.socket_fd)
268268
return
269269
}

vlib/builtin/prealloc.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn prealloc_vcleanup() {
141141
path := $d('memdumpfile', 'memdump.bin')
142142
C.fprintf(C.stderr, c'prealloc_vcleanup dumping process memory to path: %s\n',
143143
path.str)
144-
stream := C.fopen(path.str, 'wb'.str)
144+
stream := C.fopen(path.str, c'wb')
145145
mut mb := start
146146
for {
147147
used := u64(mb.current) - u64(mb.start)

vlib/builtin/string_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ fn test_bytes_to_string() {
10191019
}
10201020

10211021
fn test_charptr() {
1022-
foo := &char('VLANG'.str)
1022+
foo := &char(c'VLANG')
10231023
assert typeof(foo).name == '&char'
10241024
assert unsafe { foo.vstring() } == 'VLANG'
10251025
assert unsafe { foo.vstring_with_len(3) } == 'VLA'

vlib/log/log.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ fn (mut l Log) log_file(s string, level Level) {
125125

126126
unsafe {
127127
l.ofile.write_ptr(timestamp.str, timestamp.len)
128-
l.ofile.write_ptr(' '.str, 1)
128+
l.ofile.write_ptr(c' ', 1)
129129

130-
l.ofile.write_ptr('['.str, 1)
130+
l.ofile.write_ptr(c'[', 1)
131131
l.ofile.write_ptr(e.str, e.len)
132-
l.ofile.write_ptr(']'.str, 1)
132+
l.ofile.write_ptr(c']', 1)
133133

134-
l.ofile.write_ptr(' '.str, 1)
134+
l.ofile.write_ptr(c' ', 1)
135135
l.ofile.write_ptr(s.str, s.len)
136136

137-
l.ofile.write_ptr('\n'.str, 1)
137+
l.ofile.write_ptr(c'\n', 1)
138138
}
139139
if l.always_flush {
140140
l.flush()

vlib/os/bare/bare_example_linux.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
sys_write(1, 'hello\n'.str, 6)
2+
sys_write(1, c'hello\n', 6)
33
s := 'test string\n'
44
sys_write(1, s.str, u64(s.len))
55
a := s[0]

vlib/time/parse.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub fn parse_rfc3339(s string) !Time {
230230
}
231231

232232
// Check if it is UTC time
233-
if unsafe { vmemcmp(s.str + s.len - 5, '00:00'.str, 5) == 0 } {
233+
if unsafe { vmemcmp(s.str + s.len - 5, c'00:00', 5) == 0 } {
234234
return new(Time{
235235
year: year
236236
month: month

vlib/v/ast/ast.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ pub:
996996
is_test bool // true for _test.v files
997997
is_generated bool // true for `@[generated] module xyz` files; turn off notices
998998
is_translated bool // true for `@[translated] module xyz` files; turn off some checks
999+
language Language
9991000
pub mut:
10001001
idx int // index in an external container; can be used to refer to the file in a more efficient way, just by its integer index
10011002
path string // absolute path of the source file - '/projects/v/file.v'

vlib/v/fmt/fmt.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// that can be found in the LICENSE file.
44
module fmt
55

6+
import os
67
import strings
78
import v.ast
89
import v.util
@@ -3039,6 +3040,15 @@ pub fn (mut f Fmt) select_expr(node ast.SelectExpr) {
30393040
}
30403041

30413042
pub fn (mut f Fmt) selector_expr(node ast.SelectorExpr) {
3043+
// TODO(StunxFS): Even though we ignored the JS backend, the `v/gen/js/tests/js.v`
3044+
// file was still formatted/transformed, so it is specifically ignored here. Fix this.
3045+
if f.file.language != .js && node.expr is ast.StringLiteral && node.field_name == 'str'
3046+
&& !f.pref.backend.is_js()
3047+
&& !f.file.path.ends_with(os.join_path('v', 'gen', 'js', 'tests', 'js.v')) {
3048+
f.write('c')
3049+
f.expr(node.expr)
3050+
return
3051+
}
30423052
f.expr(node.expr)
30433053
f.write('.')
30443054
f.write(node.field_name)

vlib/v/gen/native/readdll.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn (mut g Gen) lookup_system_dll(dll string) !SystemDll {
3434
$if windows {
3535
unsafe {
3636
buffer := malloc(1024)
37-
len := C.SearchPathA(nil, dll.str, '.dll'.str, 1024, buffer, nil)
37+
len := C.SearchPathA(nil, dll.str, c'.dll', 1024, buffer, nil)
3838
if len == 0 {
3939
err_code := C.GetLastError()
4040
err_msg := cstring_to_vstring(C.strerror(err_code))

vlib/v/parser/parser.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ pub fn (mut p Parser) parse() &ast.File {
342342
is_test: p.inside_test_file
343343
is_generated: p.is_generated
344344
is_translated: p.is_translated
345+
language: p.file_backend_mode
345346
nr_lines: p.scanner.line_nr
346347
nr_bytes: p.scanner.text.len
347348
nr_tokens: p.scanner.all_tokens.len

0 commit comments

Comments
 (0)