diff --git a/vlib/v/ast/comptime_const_values.v b/vlib/v/ast/comptime_const_values.v index 1e0c679e86ae52..acbe8e6568c9af 100644 --- a/vlib/v/ast/comptime_const_values.v +++ b/vlib/v/ast/comptime_const_values.v @@ -18,10 +18,12 @@ pub type ComptTimeConstValue = EmptyExpr //| int +// empty_comptime_const_expr return an EmptyExpr. pub fn empty_comptime_const_expr() ComptTimeConstValue { return EmptyExpr(0) } +// i8 tries to return a `ComptTimeConstValue` as `i8` type. pub fn (val ComptTimeConstValue) i8() ?i8 { x := val.i64()? if x > -129 && x < 128 { @@ -30,6 +32,7 @@ pub fn (val ComptTimeConstValue) i8() ?i8 { return none } +// i16 tries to return a `ComptTimeConstValue` as `i16` type. pub fn (val ComptTimeConstValue) i16() ?i16 { x := val.i64()? if x > -32769 && x < 32768 { @@ -38,6 +41,7 @@ pub fn (val ComptTimeConstValue) i16() ?i16 { return none } +// int tries to return a `ComptTimeConstValue` as `int` type. pub fn (val ComptTimeConstValue) int() ?int { x := val.i64()? if x > -2147483649 && x < 2147483648 { @@ -46,6 +50,7 @@ pub fn (val ComptTimeConstValue) int() ?int { return none } +// i32 tries to return a `ComptTimeConstValue` as `i32` type. pub fn (val ComptTimeConstValue) i32() ?i32 { x := val.i64()? if x > -2147483649 && x < 2147483648 { @@ -54,6 +59,7 @@ pub fn (val ComptTimeConstValue) i32() ?i32 { return none } +// voidptr tries to return a `ComptTimeConstValue` as `voidptr` type. pub fn (val ComptTimeConstValue) voidptr() ?voidptr { match val { i8, i16, i32, i64, int { return voidptr(i64(val)) } @@ -65,6 +71,7 @@ pub fn (val ComptTimeConstValue) voidptr() ?voidptr { return none } +// i64 tries to return a `ComptTimeConstValue` as i64 type. pub fn (val ComptTimeConstValue) i64() ?i64 { match val { i8 { @@ -119,6 +126,7 @@ pub fn (val ComptTimeConstValue) i64() ?i64 { return none } +// u8 tries to return a `ComptTimeConstValue` as `u8` type. pub fn (val ComptTimeConstValue) u8() ?u8 { x := val.u64()? if x < 256 { @@ -127,6 +135,7 @@ pub fn (val ComptTimeConstValue) u8() ?u8 { return none } +// u16 tries to return a `ComptTimeConstValue` as `u16` type. pub fn (val ComptTimeConstValue) u16() ?u16 { x := val.u64()? if x < 65536 { @@ -135,6 +144,7 @@ pub fn (val ComptTimeConstValue) u16() ?u16 { return none } +// u32 tries to return a `ComptTimeConstValue` as `u32` type. pub fn (val ComptTimeConstValue) u32() ?u32 { x := val.u64()? if x < 4294967296 { @@ -143,6 +153,7 @@ pub fn (val ComptTimeConstValue) u32() ?u32 { return none } +// u64 tries to return a `ComptTimeConstValue` as `u64` type. pub fn (val ComptTimeConstValue) u64() ?u64 { match val { i8 { @@ -204,11 +215,13 @@ pub fn (val ComptTimeConstValue) u64() ?u64 { return none } +// f32 tries to return a `ComptTimeConstValue` as `f32` type. pub fn (val ComptTimeConstValue) f32() ?f32 { x := val.f64()? return f32(x) } +// f64 tries to return a `ComptTimeConstValue` as `f64` type. pub fn (val ComptTimeConstValue) f64() ?f64 { match val { i8 { @@ -254,6 +267,7 @@ pub fn (val ComptTimeConstValue) f64() ?f64 { return none } +// string tries to return a `ComptTimeConstValue` as `string` type. pub fn (val ComptTimeConstValue) string() ?string { match val { i8 { diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index aa09c5b67ee8b5..1cc6616590d0fb 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -433,6 +433,7 @@ fn (ts TypeSymbol) dbg_common(mut res []string) { res << 'language: ${ts.language}' } +// str returns a string representation of the type. pub fn (t Type) str() string { return 'ast.Type(0x${t.hex()} = ${u32(t)})' } @@ -717,7 +718,7 @@ pub fn mktyp(typ Type) Type { } } -// returns TypeSymbol kind only if there are no type modifiers +// type_kind returns the kind of the given type symbol. pub fn (t &Table) type_kind(typ Type) Kind { if typ.nr_muls() > 0 || typ.has_option_or_result() { return Kind.placeholder