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()...@@ -104,9 +104,11 @@ else()
104104
105 set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})105 set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
106106
107 if(LLVM_LIBRARY)107 if(LLVM_LIBRARY AND NOT LLVM_LIBRARIES)
108 set(LLVM_LIBRARIES ${LLVM_LIBRARY})108 set(LLVM_LIBRARIES ${LLVM_LIBRARY})
109 endif()109 endif()
110
111 link_directories("${CMAKE_PREFIX_PATH}/lib")
110endif()112endif()
111113
112114
src/ir.cpp+13-2
...@@ -11432,6 +11432,17 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -11432,6 +11432,17 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
11432 if (type_is_invalid(child_type)) {11432 if (type_is_invalid(child_type)) {
11433 return ira->codegen->builtin_types.entry_invalid;11433 return ira->codegen->builtin_types.entry_invalid;
11434 } else if (is_container(child_type)) {11434 } 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 }
11435 if (child_type->id == TypeTableEntryIdEnum) {11446 if (child_type->id == TypeTableEntryIdEnum) {
11436 ensure_complete_type(ira->codegen, child_type);11447 ensure_complete_type(ira->codegen, child_type);
11437 if (child_type->data.enumeration.is_invalid)11448 if (child_type->data.enumeration.is_invalid)
...@@ -11522,7 +11533,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -11522,7 +11533,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
11522 return ira->codegen->builtin_types.entry_invalid;11533 return ira->codegen->builtin_types.entry_invalid;
11523 }11534 }
11524 } else if (child_type->id == TypeTableEntryIdPointer) {11535 } else if (child_type->id == TypeTableEntryIdPointer) {
11525 if (buf_eql_str(field_name, "child")) {11536 if (buf_eql_str(field_name, "Child")) {
11526 bool ptr_is_const = true;11537 bool ptr_is_const = true;
11527 bool ptr_is_volatile = false;11538 bool ptr_is_volatile = false;
11528 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,11539 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
...@@ -11544,7 +11555,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -11544,7 +11555,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
11544 return ira->codegen->builtin_types.entry_invalid;11555 return ira->codegen->builtin_types.entry_invalid;
11545 }11556 }
11546 } else if (child_type->id == TypeTableEntryIdArray) {11557 } else if (child_type->id == TypeTableEntryIdArray) {
11547 if (buf_eql_str(field_name, "child")) {11558 if (buf_eql_str(field_name, "Child")) {
11548 bool ptr_is_const = true;11559 bool ptr_is_const = true;
11549 bool ptr_is_volatile = false;11560 bool ptr_is_volatile = false;
11550 return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,11561 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...@@ -208,7 +208,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
208 return output(context, @errorName(value));208 return output(context, @errorName(value));
209 },209 },
210 builtin.TypeId.Pointer => {210 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) {
212 return output(context, (*value)[0..]);212 return output(context, (*value)[0..]);
213 } else {213 } else {
214 @compileError("Unable to format type '" ++ @typeName(T) ++ "'");214 @compileError("Unable to format type '" ++ @typeName(T) ++ "'");
test/cases/array.zig+1-1
...@@ -89,7 +89,7 @@ test "array literal with specified size" {...@@ -89,7 +89,7 @@ test "array literal with specified size" {
8989
90test "array child property" {90test "array child property" {
91 var x: [5]i32 = undefined;91 var x: [5]i32 = undefined;
92 assert(@typeOf(x).child == i32);92 assert(@typeOf(x).Child == i32);
93}93}
9494
95test "array len property" {95test "array len property" {
test/cases/misc.zig+1-1
...@@ -536,7 +536,7 @@ export fn writeToVRam() {...@@ -536,7 +536,7 @@ export fn writeToVRam() {
536}536}
537537
538test "pointer child field" {538test "pointer child field" {
539 assert((&u32).child == u32);539 assert((&u32).Child == u32);
540}540}
541541
542const OpaqueA = @OpaqueType();542const OpaqueA = @OpaqueType();
test/cases/slice.zig+6
...@@ -9,3 +9,9 @@ test "compile time slice of pointer to hard coded address" {...@@ -9,3 +9,9 @@ test "compile time slice of pointer to hard coded address" {
9 assert(@ptrToInt(y.ptr) == 0x1100);9 assert(@ptrToInt(y.ptr) == 0x1100);
10 assert(y.len == 0x400);10 assert(y.len == 0x400);
11}11}
12
13test "slice child property" {
14 var array: [5]i32 = undefined;
15 var slice = array[0..];
16 assert(@typeOf(slice).Child == i32);
17}