vfmt2: fix literal integer number formatting

pull/4050/head
Delyan Angelov 2020-03-17 03:49:15 +02:00 committed by GitHub
parent cff6f4abd6
commit f73b38a0d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 9 deletions

View File

@ -40,7 +40,7 @@ pub:
pub struct IntegerLiteral {
pub:
val int
val string
}
pub struct FloatLiteral {

View File

@ -69,9 +69,9 @@ pub fn (x Expr) str() string {
*/
IntegerLiteral {
return it.val.str()
return it.val
}
IntegerLiteral {
StringLiteral {
return '"$it.val"'
}
else {

View File

@ -492,12 +492,12 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type {
mut fixed_size := 1
match array_init.exprs[0] {
ast.IntegerLiteral {
fixed_size = it.val
fixed_size = it.val.int()
}
else {
c.error('expecting `int` for fixed size', array_init.pos)
}
}
}
idx := c.table.find_or_register_array_fixed(array_init.elem_type, fixed_size, 1)
array_type := table.new_type(idx)
array_init.typ = array_type

View File

@ -433,7 +433,7 @@ fn (f mut Fmt) expr(node ast.Expr) {
f.write(']')
}
ast.IntegerLiteral {
f.write(it.val.str())
f.write(it.val)
}
ast.MapInit {
f.writeln('{')

View File

@ -0,0 +1,4 @@
fn main() {
x := 0xdeadbeef
u := 9978654321
}

View File

@ -747,7 +747,7 @@ fn (g mut Gen) expr(node ast.Expr) {
g.infix_expr(it)
}
ast.IntegerLiteral {
g.write(it.val.str())
g.write(it.val.int().str())
}
ast.MatchExpr {
g.match_expr(it)

View File

@ -108,7 +108,7 @@ fn (g mut JsGen) expr(node ast.Expr) {
// println('cgen expr()')
match node {
ast.IntegerLiteral {
g.write(it.val.str())
g.write(it.val)
}
ast.FloatLiteral {
g.write(it.val)

View File

@ -1310,7 +1310,7 @@ fn (p mut Parser) parse_number_literal() ast.Expr {
}
else {
node = ast.IntegerLiteral{
val: lit.int()
val: lit
}
}
p.next()