From 7d239414f7ed5abad8cdd8b1262590d8f50dd56a Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Tue, 1 May 2018 13:42:20 +0300 Subject: Fixed type info test, added documentation. --- doc/langref.html.in | 391 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 387 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/langref.html.in b/doc/langref.html.in index 16fafdaad9..db41ca6a1f 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -4809,6 +4809,182 @@ pub const TypeId = enum { BoundFn, ArgTuple, Opaque, +}; + {#code_end#} + {#header_close#} + {#header_open|@typeInfo#} +
@typeInfo(comptime T: type) -> @import("builtin").TypeInfo
+

+ Returns information on the type. Returns a value of the following union: +

+ {#code_begin|syntax#} +pub const TypeInfo = union(TypeId) { + Type: void, + Void: void, + Bool: void, + NoReturn: void, + Int: Int, + Float: Float, + Pointer: Pointer, + Array: Array, + Struct: Struct, + FloatLiteral: void, + IntLiteral: void, + UndefinedLiteral: void, + NullLiteral: void, + Nullable: Nullable, + ErrorUnion: ErrorUnion, + ErrorSet: ErrorSet, + Enum: Enum, + Union: Union, + Fn: Fn, + Namespace: void, + Block: void, + BoundFn: Fn, + ArgTuple: void, + Opaque: void, + Promise: Promise, + + + pub const Int = struct { + is_signed: bool, + bits: u8, + }; + + pub const Float = struct { + bits: u8, + }; + + pub const Pointer = struct { + is_const: bool, + is_volatile: bool, + alignment: u32, + child: type, + }; + + pub const Array = struct { + len: usize, + child: type, + }; + + pub const ContainerLayout = enum { + Auto, + Extern, + Packed, + }; + + pub const StructField = struct { + name: []const u8, + offset: ?usize, + field_type: type, + }; + + pub const Struct = struct { + layout: ContainerLayout, + fields: []StructField, + defs: []Definition, + }; + + pub const Nullable = struct { + child: type, + }; + + pub const ErrorUnion = struct { + error_set: type, + payload: type, + }; + + pub const Error = struct { + name: []const u8, + value: usize, + }; + + pub const ErrorSet = struct { + errors: []Error, + }; + + pub const EnumField = struct { + name: []const u8, + value: usize, + }; + + pub const Enum = struct { + layout: ContainerLayout, + tag_type: type, + fields: []EnumField, + defs: []Definition, + }; + + pub const UnionField = struct { + name: []const u8, + enum_field: ?EnumField, + field_type: type, + }; + + pub const Union = struct { + layout: ContainerLayout, + tag_type: type, + fields: []UnionField, + defs: []Definition, + }; + + pub const CallingConvention = enum { + Unspecified, + C, + Cold, + Naked, + Stdcall, + Async, + }; + + pub const FnArg = struct { + is_generic: bool, + is_noalias: bool, + arg_type: type, + }; + + pub const Fn = struct { + calling_convention: CallingConvention, + is_generic: bool, + is_var_args: bool, + return_type: type, + async_allocator_type: type, + args: []FnArg, + }; + + pub const Promise = struct { + child: type, + }; + + pub const Definition = struct { + name: []const u8, + is_pub: bool, + data: Data, + + pub const Data = union(enum) { + Type: type, + Var: type, + Fn: FnDef, + + pub const FnDef = struct { + fn_type: type, + inline_type: Inline, + calling_convention: CallingConvention, + is_var_args: bool, + is_extern: bool, + is_export: bool, + lib_name: ?[]const u8, + return_type: type, + arg_names: [][] const u8, + + pub const Inline = enum { + Auto, + Always, + Never, + }; + }; + }; + }; }; {#code_end#} {#header_close#} @@ -5226,7 +5402,6 @@ pub const Os = enum { rtems, nacl, cnk, - bitrig, aix, cuda, nvcl, @@ -5237,10 +5412,12 @@ pub const Os = enum { watchos, mesa3d, contiki, + amdpal, zen, }; pub const Arch = enum { + armv8_3a, armv8_2a, armv8_1a, armv8, @@ -5260,9 +5437,29 @@ pub const Arch = enum { armv5, armv5te, armv4t, - armeb, + armebv8_3a, + armebv8_2a, + armebv8_1a, + armebv8, + armebv8r, + armebv8m_baseline, + armebv8m_mainline, + armebv7, + armebv7em, + armebv7m, + armebv7s, + armebv7k, + armebv7ve, + armebv6, + armebv6m, + armebv6k, + armebv6t2, + armebv5, + armebv5te, + armebv4t, aarch64, aarch64_be, + arc, avr, bpfel, bpfeb, @@ -5315,6 +5512,7 @@ pub const Arch = enum { pub const Environ = enum { unknown, gnu, + gnuabin32, gnuabi64, gnueabi, gnueabihf, @@ -5332,6 +5530,7 @@ pub const Environ = enum { amdopencl, coreclr, opencl, + simulator, }; pub const ObjectFormat = enum { @@ -5358,10 +5557,23 @@ pub const AtomicOrder = enum { SeqCst, }; +pub const AtomicRmwOp = enum { + Xchg, + Add, + Sub, + And, + Nand, + Or, + Xor, + Max, + Min, +}; + pub const Mode = enum { Debug, ReleaseSafe, ReleaseFast, + ReleaseSmall, }; pub const TypeId = enum { @@ -5380,7 +5592,7 @@ pub const TypeId = enum { NullLiteral, Nullable, ErrorUnion, - Error, + ErrorSet, Enum, Union, Fn, @@ -5389,6 +5601,176 @@ pub const TypeId = enum { BoundFn, ArgTuple, Opaque, + Promise, +}; + +pub const TypeInfo = union(TypeId) { + Type: void, + Void: void, + Bool: void, + NoReturn: void, + Int: Int, + Float: Float, + Pointer: Pointer, + Array: Array, + Struct: Struct, + FloatLiteral: void, + IntLiteral: void, + UndefinedLiteral: void, + NullLiteral: void, + Nullable: Nullable, + ErrorUnion: ErrorUnion, + ErrorSet: ErrorSet, + Enum: Enum, + Union: Union, + Fn: Fn, + Namespace: void, + Block: void, + BoundFn: Fn, + ArgTuple: void, + Opaque: void, + Promise: Promise, + + + pub const Int = struct { + is_signed: bool, + bits: u8, + }; + + pub const Float = struct { + bits: u8, + }; + + pub const Pointer = struct { + is_const: bool, + is_volatile: bool, + alignment: u32, + child: type, + }; + + pub const Array = struct { + len: usize, + child: type, + }; + + pub const ContainerLayout = enum { + Auto, + Extern, + Packed, + }; + + pub const StructField = struct { + name: []const u8, + offset: ?usize, + field_type: type, + }; + + pub const Struct = struct { + layout: ContainerLayout, + fields: []StructField, + defs: []Definition, + }; + + pub const Nullable = struct { + child: type, + }; + + pub const ErrorUnion = struct { + error_set: type, + payload: type, + }; + + pub const Error = struct { + name: []const u8, + value: usize, + }; + + pub const ErrorSet = struct { + errors: []Error, + }; + + pub const EnumField = struct { + name: []const u8, + value: usize, + }; + + pub const Enum = struct { + layout: ContainerLayout, + tag_type: type, + fields: []EnumField, + defs: []Definition, + }; + + pub const UnionField = struct { + name: []const u8, + enum_field: ?EnumField, + field_type: type, + }; + + pub const Union = struct { + layout: ContainerLayout, + tag_type: type, + fields: []UnionField, + defs: []Definition, + }; + + pub const CallingConvention = enum { + Unspecified, + C, + Cold, + Naked, + Stdcall, + Async, + }; + + pub const FnArg = struct { + is_generic: bool, + is_noalias: bool, + arg_type: type, + }; + + pub const Fn = struct { + calling_convention: CallingConvention, + is_generic: bool, + is_var_args: bool, + return_type: type, + async_allocator_type: type, + args: []FnArg, + }; + + pub const Promise = struct { + child: type, + }; + + pub const Definition = struct { + name: []const u8, + is_pub: bool, + data: Data, + + pub const Data = union(enum) { + Type: type, + Var: type, + Fn: FnDef, + + pub const FnDef = struct { + fn_type: type, + inline_type: Inline, + calling_convention: CallingConvention, + is_var_args: bool, + is_extern: bool, + is_export: bool, + lib_name: ?[]const u8, + return_type: type, + arg_names: [][] const u8, + + pub const Inline = enum { + Auto, + Always, + Never, + }; + }; + }; + }; }; pub const FloatMode = enum { @@ -5402,7 +5784,7 @@ pub const Endian = enum { }; pub const endian = Endian.Little; -pub const is_test = false; +pub const is_test = true; pub const os = Os.linux; pub const arch = Arch.x86_64; pub const environ = Environ.gnu; @@ -5410,6 +5792,7 @@ pub const object_format = ObjectFormat.elf; pub const mode = Mode.Debug; pub const link_libc = false; pub const have_error_return_tracing = true; +pub const __zig_test_fn_slice = {}; // overwritten later {#code_end#} {#see_also|Build Mode#} {#header_close#} -- cgit v1.2.3 From 57940837e7a178577c22b89c5173082e4fb8e618 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Tue, 1 May 2018 13:44:19 +0300 Subject: Added typeInfo to langref built_ins --- doc/langref.html.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/langref.html.in b/doc/langref.html.in index db41ca6a1f..b867ff0b35 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -6451,7 +6451,7 @@ hljs.registerLanguage("zig", function(t) { a = t.IR + "\\s*\\(", c = { keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong", - built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field", + built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo", literal: "true false null undefined" }, n = [e, t.CLCM, t.CBCM, s, r]; -- cgit v1.2.3