authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-13 14:30:57-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-13 14:30:57-04:00
logd9eabde319bc035f710b106808022e9b5872f728
tree798876d64f37829bdc3eb637ef35e648493afe8f
parent5931a6b1a5b8f4941fc9b78f8960745f81594f17

add Child property of slice type

also rename child field to Child for pointer and array

6 files changed, 25 insertions(+), 6 deletions(-)

cmake/Findllvm.cmake+3-1
......@@ -104,9 +104,11 @@ else()
104104
105105 set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
106106
107 if(LLVM_LIBRARY)
107 if(LLVM_LIBRARY AND NOT LLVM_LIBRARIES)
108108 set(LLVM_LIBRARIES ${LLVM_LIBRARY})
109109 endif()
110
111 link_directories("${CMAKE_PREFIX_PATH}/lib")
110112endif()
111113
112114
src/ir.cpp+13-2
......@@ -11432,6 +11432,17 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1143211432 if (type_is_invalid(child_type)) {
1143311433 return ira->codegen->builtin_types.entry_invalid;
1143411434 } else if (is_container(child_type)) {
11435 if (is_slice(child_type) && buf_eql_str(field_name, "Child")) {
11436 bool ptr_is_const = true;
11437 bool ptr_is_volatile = false;
11438 TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];
11439 assert(ptr_field->type_entry->id == TypeTableEntryIdPointer);
11440 TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type;
11441 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
11442 create_const_type(ira->codegen, child_type),
11443 ira->codegen->builtin_types.entry_type,
11444 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
11445 }
1143511446 if (child_type->id == TypeTableEntryIdEnum) {
1143611447 ensure_complete_type(ira->codegen, child_type);
1143711448 if (child_type->data.enumeration.is_invalid)
......@@ -11522,7 +11533,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1152211533 return ira->codegen->builtin_types.entry_invalid;
1152311534 }
1152411535 } else if (child_type->id == TypeTableEntryIdPointer) {
11525 if (buf_eql_str(field_name, "child")) {
11536 if (buf_eql_str(field_name, "Child")) {
1152611537 bool ptr_is_const = true;
1152711538 bool ptr_is_volatile = false;
1152811539 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
......@@ -11544,7 +11555,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1154411555 return ira->codegen->builtin_types.entry_invalid;
1154511556 }
1154611557 } else if (child_type->id == TypeTableEntryIdArray) {
11547 if (buf_eql_str(field_name, "child")) {
11558 if (buf_eql_str(field_name, "Child")) {
1154811559 bool ptr_is_const = true;
1154911560 bool ptr_is_volatile = false;
1155011561 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
std/fmt/index.zig+1-1
......@@ -208,7 +208,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
208208 return output(context, @errorName(value));
209209 },
210210 builtin.TypeId.Pointer => {
211 if (@typeId(T.child) == builtin.TypeId.Array and T.child.child == u8) {
211 if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) {
212212 return output(context, (*value)[0..]);
213213 } else {
214214 @compileError("Unable to format type '" ++ @typeName(T) ++ "'");
test/cases/array.zig+1-1
......@@ -89,7 +89,7 @@ test "array literal with specified size" {
8989
9090test "array child property" {
9191 var x: [5]i32 = undefined;
92 assert(@typeOf(x).child == i32);
92 assert(@typeOf(x).Child == i32);
9393}
9494
9595test "array len property" {
test/cases/misc.zig+1-1
......@@ -536,7 +536,7 @@ export fn writeToVRam() {
536536}
537537
538538test "pointer child field" {
539 assert((&u32).child == u32);
539 assert((&u32).Child == u32);
540540}
541541
542542const OpaqueA = @OpaqueType();
test/cases/slice.zig+6
......@@ -9,3 +9,9 @@ test "compile time slice of pointer to hard coded address" {
99 assert(@ptrToInt(y.ptr) == 0x1100);
1010 assert(y.len == 0x400);
1111}
12
13test "slice child property" {
14 var array: [5]i32 = undefined;
15 var slice = array[0..];
16 assert(@typeOf(slice).Child == i32);
17}