parser: remove ++/-- exception for some modules (#9895)

pull/9897/head
Enzo 2021-04-27 00:41:42 +02:00 committed by GitHub
parent 3877522ee3
commit 4eb8072882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 116 additions and 58 deletions

View File

@ -529,11 +529,13 @@ pub fn (b []byte) hex() string {
for i in b { for i in b {
n0 := i >> 4 n0 := i >> 4
unsafe { unsafe {
hex[dst_i++] = if n0 < 10 { n0 + `0` } else { n0 + byte(87) } hex[dst_i] = if n0 < 10 { n0 + `0` } else { n0 + byte(87) }
dst_i++
} }
n1 := i & 0xF n1 := i & 0xF
unsafe { unsafe {
hex[dst_i++] = if n1 < 10 { n1 + `0` } else { n1 + byte(87) } hex[dst_i] = if n1 < 10 { n1 + `0` } else { n1 + byte(87) }
dst_i++
} }
} }
unsafe { unsafe {

View File

@ -79,15 +79,19 @@ fn (nn int) str_l(max int) string {
} }
mut index := max mut index := max
unsafe { unsafe {
buf[index--] = 0 buf[index] = 0
index--
} }
for n > 0 { for n > 0 {
n1 := int(n / 100) n1 := int(n / 100)
d = ((int(n) - (n1 * 100)) << 1) d = ((int(n) - (n1 * 100)) << 1)
n = n1 n = n1
unsafe { unsafe {
buf[index--] = digit_pairs.str[d++] buf[index] = digit_pairs.str[d]
buf[index--] = digit_pairs.str[d] index--
d++
buf[index] = digit_pairs.str[d]
index--
} }
} }
index++ index++
@ -145,15 +149,19 @@ pub fn (nn u32) str() string {
mut buf := unsafe { malloc(max + 1) } mut buf := unsafe { malloc(max + 1) }
mut index := max mut index := max
unsafe { unsafe {
buf[index--] = 0 buf[index] = 0
index--
} }
for n > 0 { for n > 0 {
n1 := n / u32(100) n1 := n / u32(100)
d = ((n - (n1 * u32(100))) << u32(1)) d = ((n - (n1 * u32(100))) << u32(1))
n = n1 n = n1
unsafe { unsafe {
buf[index--] = digit_pairs[d++] buf[index] = digit_pairs[d]
buf[index--] = digit_pairs[d] index--
d++
buf[index] = digit_pairs[d]
index--
} }
} }
index++ index++
@ -191,15 +199,19 @@ pub fn (nn i64) str() string {
} }
mut index := max mut index := max
unsafe { unsafe {
buf[index--] = 0 buf[index] = 0
index--
} }
for n > 0 { for n > 0 {
n1 := n / i64(100) n1 := n / i64(100)
d = ((n - (n1 * i64(100))) << i64(1)) d = ((n - (n1 * i64(100))) << i64(1))
n = n1 n = n1
unsafe { unsafe {
buf[index--] = digit_pairs[d++] buf[index] = digit_pairs[d]
buf[index--] = digit_pairs[d] index--
d++
buf[index] = digit_pairs[d]
index--
} }
} }
index++ index++
@ -233,15 +245,19 @@ pub fn (nn u64) str() string {
mut buf := vcalloc(max + 1) mut buf := vcalloc(max + 1)
mut index := max mut index := max
unsafe { unsafe {
buf[index--] = 0 buf[index] = 0
index--
} }
for n > 0 { for n > 0 {
n1 := n / 100 n1 := n / 100
d = ((n - (n1 * 100)) << 1) d = ((n - (n1 * 100)) << 1)
n = n1 n = n1
unsafe { unsafe {
buf[index--] = digit_pairs[d++] buf[index] = digit_pairs[d]
buf[index--] = digit_pairs[d] index--
d++
buf[index] = digit_pairs[d]
index--
} }
} }
index++ index++

View File

@ -483,8 +483,10 @@ fn (re RE) get_char_class(pc int) string {
if re.cc[cc_i].cc_type == cc_bsls { if re.cc[cc_i].cc_type == cc_bsls {
unsafe { unsafe {
buf_ptr[i++] = `\\` buf_ptr[i] = `\\`
buf_ptr[i++] = byte(re.cc[cc_i].ch0) i++
buf_ptr[i] = byte(re.cc[cc_i].ch0)
i++
} }
} }
else if re.cc[cc_i].ch0 == re.cc[cc_i].ch1 { else if re.cc[cc_i].ch0 == re.cc[cc_i].ch1 {
@ -493,7 +495,8 @@ fn (re RE) get_char_class(pc int) string {
x := byte((re.cc[cc_i].ch0 >> (tmp*8)) & 0xFF) x := byte((re.cc[cc_i].ch0 >> (tmp*8)) & 0xFF)
if x != 0 { if x != 0 {
unsafe { unsafe {
buf_ptr[i++] = x buf_ptr[i] = x
i++
} }
} }
tmp-- tmp--
@ -505,20 +508,23 @@ fn (re RE) get_char_class(pc int) string {
x := byte((re.cc[cc_i].ch0 >> (tmp*8)) & 0xFF) x := byte((re.cc[cc_i].ch0 >> (tmp*8)) & 0xFF)
if x != 0 { if x != 0 {
unsafe { unsafe {
buf_ptr[i++] = x buf_ptr[i] = x
i++
} }
} }
tmp-- tmp--
} }
unsafe { unsafe {
buf_ptr[i++] = `-` buf_ptr[i] = `-`
i++
} }
tmp = 3 tmp = 3
for tmp >= 0 { for tmp >= 0 {
x := byte((re.cc[cc_i].ch1 >> (tmp*8)) & 0xFF) x := byte((re.cc[cc_i].ch1 >> (tmp*8)) & 0xFF)
if x != 0 { if x != 0 {
unsafe { unsafe {
buf_ptr[i++] = x buf_ptr[i] = x
i++
} }
} }
tmp-- tmp--

View File

@ -205,10 +205,12 @@ fn parser(s string) (int,PrepNumber) {
// skip the inital zeros // skip the inital zeros
fsm_c { fsm_c {
if c == c_zero { if c == c_zero {
c = s[i++] c = s[i]
i++
} }
else if c == c_dpoint { else if c == c_dpoint {
c = s[i++] c = s[i]
i++
state = fsm_d state = fsm_d
} }
else { else {
@ -218,7 +220,8 @@ fn parser(s string) (int,PrepNumber) {
// reading leading zeros in the fractional part of mantissa // reading leading zeros in the fractional part of mantissa
fsm_d { fsm_d {
if c == c_zero { if c == c_zero {
c = s[i++] c = s[i]
i++
if pn.exponent > -2147483647 { if pn.exponent > -2147483647 {
pn.exponent-- pn.exponent--
} }
@ -238,10 +241,12 @@ fn parser(s string) (int,PrepNumber) {
else if pn.exponent < 2147483647 { else if pn.exponent < 2147483647 {
pn.exponent++ pn.exponent++
} }
c = s[i++] c = s[i]
i++
} }
else if c == c_dpoint { else if c == c_dpoint {
c = s[i++] c = s[i]
i++
state = fsm_f state = fsm_f
} }
else { else {
@ -257,10 +262,12 @@ fn parser(s string) (int,PrepNumber) {
pn.exponent-- pn.exponent--
digx++ digx++
} }
c = s[i++] c = s[i]
i++
} }
else if is_exp(c) { else if is_exp(c) {
c = s[i++] c = s[i]
i++
state = fsm_g state = fsm_g
} }
else { else {
@ -270,18 +277,21 @@ fn parser(s string) (int,PrepNumber) {
// reading sign of exponent // reading sign of exponent
fsm_g { fsm_g {
if c == c_plus { if c == c_plus {
c = s[i++] c = s[i]
i++
} }
else if c == c_minus { else if c == c_minus {
expneg = true expneg = true
c = s[i++] c = s[i]
i++
} }
state = fsm_h state = fsm_h
} }
// skipping leading zeros of exponent // skipping leading zeros of exponent
fsm_h { fsm_h {
if c == c_zero { if c == c_zero {
c = s[i++] c = s[i]
i++
} }
else { else {
state = fsm_i state = fsm_i
@ -294,7 +304,8 @@ fn parser(s string) (int,PrepNumber) {
expexp *= 10 expexp *= 10
expexp += int(c - c_zero) expexp += int(c - c_zero)
} }
c = s[i++] c = s[i]
i++
} }
else { else {
state = fsm_stop state = fsm_stop

View File

@ -114,7 +114,8 @@ pub fn (d Dec32) get_string_32(neg bool, i_n_digit int, i_pad_digit int) string
} }
for fw_zeros > 0 { for fw_zeros > 0 {
buf[i++] = `0` buf[i] = `0`
i++
fw_zeros-- fw_zeros--
} }

View File

@ -130,7 +130,8 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string {
} }
for fw_zeros > 0 { for fw_zeros > 0 {
buf[i++] = `0` buf[i] = `0`
i++
fw_zeros-- fw_zeros--
} }

View File

@ -97,7 +97,8 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
i++ i++
} }
else if c >= `0` && c <= `9` { else if c >= `0` && c <= `9` {
b[i1++] = c b[i1] = c
i1++
i++ i++
} else if c == `.` { } else if c == `.` {
if sgn > 0 { if sgn > 0 {
@ -136,43 +137,51 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
if sgn == 1 { if sgn == 1 {
if m_sgn_flag { if m_sgn_flag {
res[r_i++] = `+` res[r_i] = `+`
r_i++
} }
} else { } else {
res[r_i++] = `-` res[r_i] = `-`
r_i++
} }
i = 0 i = 0
if exp_sgn >= 0 { if exp_sgn >= 0 {
for b[i] != 0 { for b[i] != 0 {
res[r_i++] = b[i] res[r_i] = b[i]
r_i++
i++ i++
if i >= d_pos && exp >= 0 { if i >= d_pos && exp >= 0 {
if exp == 0 { if exp == 0 {
dot_res_sp = r_i dot_res_sp = r_i
res[r_i++] = `.` res[r_i] = `.`
r_i++
} }
exp-- exp--
} }
} }
for exp >= 0 { for exp >= 0 {
res[r_i++] = `0` res[r_i] = `0`
r_i++
exp-- exp--
} }
//println("exp: $exp $r_i $dot_res_sp") //println("exp: $exp $r_i $dot_res_sp")
} else { } else {
mut dot_p := true mut dot_p := true
for exp > 0 { for exp > 0 {
res[r_i++] = `0` res[r_i] = `0`
r_i++
exp-- exp--
if dot_p { if dot_p {
dot_res_sp = r_i dot_res_sp = r_i
res[r_i++] = `.` res[r_i] = `.`
r_i++
dot_p = false dot_p = false
} }
} }
for b[i] != 0 { for b[i] != 0 {
res[r_i++] = b[i] res[r_i] = b[i]
r_i++
i++ i++
} }
} }
@ -193,9 +202,11 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
} else { } else {
if dec_digit > 0 { if dec_digit > 0 {
mut c := 0 mut c := 0
res[r_i++] = `.` res[r_i] = `.`
r_i++
for c < dec_digit { for c < dec_digit {
res[r_i++] = `0` res[r_i] = `0`
r_i++
c++ c++
} }
res[r_i] = 0 res[r_i] = 0

View File

@ -260,7 +260,8 @@ pub fn f64_to_str_l(f f64) string {
i++ i++
} }
else if c >= `0` && c <= `9` { else if c >= `0` && c <= `9` {
b[i1++] = c b[i1] = c
i1++
i++ i++
} else if c == `.` { } else if c == `.` {
if sgn > 0 { if sgn > 0 {
@ -298,40 +299,48 @@ pub fn f64_to_str_l(f f64) string {
if sgn == 1 { if sgn == 1 {
if m_sgn_flag { if m_sgn_flag {
res[r_i++] = `+` res[r_i] = `+`
r_i++
} }
} else { } else {
res[r_i++] = `-` res[r_i] = `-`
r_i++
} }
i = 0 i = 0
if exp_sgn >= 0 { if exp_sgn >= 0 {
for b[i] != 0 { for b[i] != 0 {
res[r_i++] = b[i] res[r_i] = b[i]
r_i++
i++ i++
if i >= d_pos && exp >= 0 { if i >= d_pos && exp >= 0 {
if exp == 0 { if exp == 0 {
res[r_i++] = `.` res[r_i] = `.`
r_i++
} }
exp-- exp--
} }
} }
for exp >= 0 { for exp >= 0 {
res[r_i++] = `0` res[r_i] = `0`
r_i++
exp-- exp--
} }
} else { } else {
mut dot_p := true mut dot_p := true
for exp > 0 { for exp > 0 {
res[r_i++] = `0` res[r_i] = `0`
r_i++
exp-- exp--
if dot_p { if dot_p {
res[r_i++] = `.` res[r_i] = `.`
r_i++
dot_p = false dot_p = false
} }
} }
for b[i] != 0 { for b[i] != 0 {
res[r_i++] = b[i] res[r_i] = b[i]
r_i++
i++ i++
} }
} }

View File

@ -772,7 +772,8 @@ fn (mut g JsGen) gen_enum_decl(it ast.EnumDecl) {
e := field.expr as ast.IntegerLiteral e := field.expr as ast.IntegerLiteral
i = e.val.int() i = e.val.int()
} }
g.writeln('${i++},') g.writeln('$i,')
i++
} }
g.dec_indent() g.dec_indent()
g.writeln('};') g.writeln('};')

View File

@ -419,7 +419,7 @@ pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_iden
} else if p.tok.kind in [.inc, .dec] || (p.tok.kind == .question && p.inside_ct_if_expr) { } else if p.tok.kind in [.inc, .dec] || (p.tok.kind == .question && p.inside_ct_if_expr) {
// Postfix // Postfix
// detect `f(x++)`, `a[x++]` // detect `f(x++)`, `a[x++]`
if p.peek_tok.kind in [.rpar, .rsbr] && p.mod !in ['builtin', 'regex', 'strconv'] { // temp if p.peek_tok.kind in [.rpar, .rsbr] {
p.warn_with_pos('`$p.tok.kind` operator can only be used as a statement', p.warn_with_pos('`$p.tok.kind` operator can only be used as a statement',
p.peek_tok.position()) p.peek_tok.position())
} }