authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-01 13:39:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-01 13:39:16-04:00
log60bdbe540538867315038305c6f41020b44036c2
tree42366615c196b22741435f771a23c1965696ba3d
parent46e9d9df51ee0c0d094c4b428bbb8d2c820b99fd

parseh: emit_warning takes SourceLocation


1 files changed, 42 insertions(+), 44 deletions(-)

src/parseh.cpp+42-44
......@@ -67,7 +67,7 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl);
6767
6868
6969__attribute__ ((format (printf, 3, 4)))
70static void emit_warning(Context *c, const Decl *decl, const char *format, ...) {
70static void emit_warning(Context *c, const SourceLocation &sl, const char *format, ...) {
7171 if (!c->warnings_on) {
7272 return;
7373 }
......@@ -77,8 +77,6 @@ static void emit_warning(Context *c, const Decl *decl, const char *format, ...)
7777 Buf *msg = buf_vprintf(format, ap);
7878 va_end(ap);
7979
80 SourceLocation sl = decl->getLocation();
81
8280 StringRef filename = c->source_manager->getFilename(sl);
8381 const char *filename_bytes = (const char *)filename.bytes_begin();
8482 Buf *path;
......@@ -185,14 +183,14 @@ static ConstExprValue *create_const_int_ap(Context *c, TypeTableEntry *type, con
185183{
186184 if (aps_int.isSigned()) {
187185 if (aps_int > INT64_MAX || aps_int < INT64_MIN) {
188 emit_warning(c, source_decl, "integer overflow\n");
186 emit_warning(c, source_decl->getLocation(), "integer overflow\n");
189187 return nullptr;
190188 } else {
191189 return create_const_signed(type, aps_int.getExtValue());
192190 }
193191 } else {
194192 if (aps_int > INT64_MAX) {
195 emit_warning(c, source_decl, "integer overflow\n");
193 emit_warning(c, source_decl->getLocation(), "integer overflow\n");
196194 return nullptr;
197195 } else {
198196 return create_const_unsigned_negative(type, aps_int.getExtValue(), false);
......@@ -347,7 +345,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
347345 case BuiltinType::OCLClkEvent:
348346 case BuiltinType::OCLQueue:
349347 case BuiltinType::OCLReserveID:
350 emit_warning(c, decl, "missed a builtin type");
348 emit_warning(c, decl->getLocation(), "missed a builtin type");
351349 return c->codegen->builtin_types.entry_invalid;
352350 }
353351 break;
......@@ -358,7 +356,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
358356 QualType child_qt = pointer_ty->getPointeeType();
359357 TypeTableEntry *child_type = resolve_qual_type(c, child_qt, decl);
360358 if (type_is_invalid(child_type)) {
361 emit_warning(c, decl, "pointer to unresolved type");
359 emit_warning(c, decl->getLocation(), "pointer to unresolved type");
362360 return c->codegen->builtin_types.entry_invalid;
363361 }
364362
......@@ -423,7 +421,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
423421 case ETK_Class:
424422 case ETK_Typename:
425423 case ETK_None:
426 emit_warning(c, decl, "unsupported elaborated type");
424 emit_warning(c, decl->getLocation(), "unsupported elaborated type");
427425 return c->codegen->builtin_types.entry_invalid;
428426 }
429427 }
......@@ -435,52 +433,52 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
435433 case CC_C: // __attribute__((cdecl))
436434 break;
437435 case CC_X86StdCall: // __attribute__((stdcall))
438 emit_warning(c, decl, "function type has x86 stdcall calling convention");
436 emit_warning(c, decl->getLocation(), "function type has x86 stdcall calling convention");
439437 return c->codegen->builtin_types.entry_invalid;
440438 case CC_X86FastCall: // __attribute__((fastcall))
441 emit_warning(c, decl, "function type has x86 fastcall calling convention");
439 emit_warning(c, decl->getLocation(), "function type has x86 fastcall calling convention");
442440 return c->codegen->builtin_types.entry_invalid;
443441 case CC_X86ThisCall: // __attribute__((thiscall))
444 emit_warning(c, decl, "function type has x86 thiscall calling convention");
442 emit_warning(c, decl->getLocation(), "function type has x86 thiscall calling convention");
445443 return c->codegen->builtin_types.entry_invalid;
446444 case CC_X86VectorCall: // __attribute__((vectorcall))
447 emit_warning(c, decl, "function type has x86 vectorcall calling convention");
445 emit_warning(c, decl->getLocation(), "function type has x86 vectorcall calling convention");
448446 return c->codegen->builtin_types.entry_invalid;
449447 case CC_X86Pascal: // __attribute__((pascal))
450 emit_warning(c, decl, "function type has x86 pascal calling convention");
448 emit_warning(c, decl->getLocation(), "function type has x86 pascal calling convention");
451449 return c->codegen->builtin_types.entry_invalid;
452450 case CC_Win64: // __attribute__((ms_abi))
453 emit_warning(c, decl, "function type has win64 calling convention");
451 emit_warning(c, decl->getLocation(), "function type has win64 calling convention");
454452 return c->codegen->builtin_types.entry_invalid;
455453 case CC_X86_64SysV: // __attribute__((sysv_abi))
456 emit_warning(c, decl, "function type has x86 64sysv calling convention");
454 emit_warning(c, decl->getLocation(), "function type has x86 64sysv calling convention");
457455 return c->codegen->builtin_types.entry_invalid;
458456 case CC_X86RegCall:
459 emit_warning(c, decl, "function type has x86 reg calling convention");
457 emit_warning(c, decl->getLocation(), "function type has x86 reg calling convention");
460458 return c->codegen->builtin_types.entry_invalid;
461459 case CC_AAPCS: // __attribute__((pcs("aapcs")))
462 emit_warning(c, decl, "function type has aapcs calling convention");
460 emit_warning(c, decl->getLocation(), "function type has aapcs calling convention");
463461 return c->codegen->builtin_types.entry_invalid;
464462 case CC_AAPCS_VFP: // __attribute__((pcs("aapcs-vfp")))
465 emit_warning(c, decl, "function type has aapcs-vfp calling convention");
463 emit_warning(c, decl->getLocation(), "function type has aapcs-vfp calling convention");
466464 return c->codegen->builtin_types.entry_invalid;
467465 case CC_IntelOclBicc: // __attribute__((intel_ocl_bicc))
468 emit_warning(c, decl, "function type has intel_ocl_bicc calling convention");
466 emit_warning(c, decl->getLocation(), "function type has intel_ocl_bicc calling convention");
469467 return c->codegen->builtin_types.entry_invalid;
470468 case CC_SpirFunction: // default for OpenCL functions on SPIR target
471 emit_warning(c, decl, "function type has SPIR function calling convention");
469 emit_warning(c, decl->getLocation(), "function type has SPIR function calling convention");
472470 return c->codegen->builtin_types.entry_invalid;
473471 case CC_OpenCLKernel:
474 emit_warning(c, decl, "function type has OpenCLKernel calling convention");
472 emit_warning(c, decl->getLocation(), "function type has OpenCLKernel calling convention");
475473 return c->codegen->builtin_types.entry_invalid;
476474 case CC_Swift:
477 emit_warning(c, decl, "function type has Swift calling convention");
475 emit_warning(c, decl->getLocation(), "function type has Swift calling convention");
478476 return c->codegen->builtin_types.entry_invalid;
479477 case CC_PreserveMost:
480 emit_warning(c, decl, "function type has PreserveMost calling convention");
478 emit_warning(c, decl->getLocation(), "function type has PreserveMost calling convention");
481479 return c->codegen->builtin_types.entry_invalid;
482480 case CC_PreserveAll:
483 emit_warning(c, decl, "function type has PreserveAll calling convention");
481 emit_warning(c, decl->getLocation(), "function type has PreserveAll calling convention");
484482 return c->codegen->builtin_types.entry_invalid;
485483 }
486484
......@@ -495,7 +493,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
495493 } else {
496494 fn_type_id.return_type = resolve_qual_type(c, fn_proto_ty->getReturnType(), decl);
497495 if (type_is_invalid(fn_type_id.return_type)) {
498 emit_warning(c, decl, "unresolved function proto return type");
496 emit_warning(c, decl->getLocation(), "unresolved function proto return type");
499497 return c->codegen->builtin_types.entry_invalid;
500498 }
501499 // convert c_void to actual void (only for return type)
......@@ -510,7 +508,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
510508 TypeTableEntry *param_type = resolve_qual_type(c, qt, decl);
511509
512510 if (type_is_invalid(param_type)) {
513 emit_warning(c, decl, "unresolved function proto parameter type");
511 emit_warning(c, decl->getLocation(), "unresolved function proto parameter type");
514512 return c->codegen->builtin_types.entry_invalid;
515513 }
516514
......@@ -536,7 +534,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
536534 const ConstantArrayType *const_arr_ty = static_cast<const ConstantArrayType *>(ty);
537535 TypeTableEntry *child_type = resolve_qual_type(c, const_arr_ty->getElementType(), decl);
538536 if (child_type->id == TypeTableEntryIdInvalid) {
539 emit_warning(c, decl, "unresolved array element type");
537 emit_warning(c, decl->getLocation(), "unresolved array element type");
540538 return child_type;
541539 }
542540 uint64_t size = const_arr_ty->getSize().getLimitedValue();
......@@ -591,7 +589,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
591589 case Type::Pipe:
592590 case Type::ObjCTypeParam:
593591 case Type::DeducedTemplateSpecialization:
594 emit_warning(c, decl, "missed a '%s' type", ty->getTypeClassName());
592 emit_warning(c, decl->getLocation(), "missed a '%s' type", ty->getTypeClassName());
595593 return c->codegen->builtin_types.entry_invalid;
596594 }
597595 zig_unreachable();
......@@ -823,6 +821,8 @@ static AstNode * trans_implicit_cast_expr(Context *c, ImplicitCastExpr *stmt) {
823821 switch (stmt->getCastKind()) {
824822 case CK_LValueToRValue:
825823 return trans_expr(c, stmt->getSubExpr());
824 case CK_IntegralCast:
825 zig_panic("TODO handle C translation cast CK_IntegralCast");
826826 case CK_Dependent:
827827 zig_panic("TODO handle C translation cast CK_Dependent");
828828 case CK_BitCast:
......@@ -871,8 +871,6 @@ static AstNode * trans_implicit_cast_expr(Context *c, ImplicitCastExpr *stmt) {
871871 zig_panic("TODO handle C translation cast CK_ToVoid");
872872 case CK_VectorSplat:
873873 zig_panic("TODO handle C translation cast CK_VectorSplat");
874 case CK_IntegralCast:
875 zig_panic("TODO handle C translation cast CK_IntegralCast");
876874 case CK_IntegralToBoolean:
877875 zig_panic("TODO handle C translation cast CK_IntegralToBoolean");
878876 case CK_IntegralToFloating:
......@@ -1424,7 +1422,7 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
14241422 TypeTableEntry *fn_type = resolve_qual_type(c, fn_decl->getType(), fn_decl);
14251423
14261424 if (fn_type->id == TypeTableEntryIdInvalid) {
1427 emit_warning(c, fn_decl, "ignoring function '%s' - unable to resolve type", buf_ptr(fn_name));
1425 emit_warning(c, fn_decl->getLocation(), "ignoring function '%s' - unable to resolve type", buf_ptr(fn_name));
14281426 return;
14291427 }
14301428 assert(fn_type->id == TypeTableEntryIdFn);
......@@ -1482,7 +1480,7 @@ static void visit_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl)
14821480
14831481 TypeTableEntry *child_type = resolve_qual_type(c, child_qt, typedef_decl);
14841482 if (child_type->id == TypeTableEntryIdInvalid) {
1485 emit_warning(c, typedef_decl, "typedef %s - unresolved child type", buf_ptr(type_name));
1483 emit_warning(c, typedef_decl->getLocation(), "typedef %s - unresolved child type", buf_ptr(type_name));
14861484 return;
14871485 }
14881486 add_const_type(c, type_name, child_type);
......@@ -1663,7 +1661,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
16631661 const char *raw_name = decl_name(record_decl);
16641662
16651663 if (!record_decl->isStruct()) {
1666 emit_warning(c, record_decl, "skipping record %s, not a struct", raw_name);
1664 emit_warning(c, record_decl->getLocation(), "skipping record %s, not a struct", raw_name);
16671665 return c->codegen->builtin_types.entry_invalid;
16681666 }
16691667
......@@ -1702,7 +1700,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
17021700 const FieldDecl *field_decl = *it;
17031701
17041702 if (field_decl->isBitField()) {
1705 emit_warning(c, field_decl, "struct %s demoted to opaque type - has bitfield\n", buf_ptr(bare_name));
1703 emit_warning(c, field_decl->getLocation(), "struct %s demoted to opaque type - has bitfield\n", buf_ptr(bare_name));
17061704 replace_with_fwd_decl(c, struct_type, full_type_name);
17071705 return struct_type;
17081706 }
......@@ -1729,7 +1727,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
17291727 type_struct_field->type_entry = field_type;
17301728
17311729 if (type_is_invalid(field_type) || !type_is_complete(field_type)) {
1732 emit_warning(c, field_decl, "struct %s demoted to opaque type - unresolved type\n", buf_ptr(bare_name));
1730 emit_warning(c, field_decl->getLocation(), "struct %s demoted to opaque type - unresolved type\n", buf_ptr(bare_name));
17331731 replace_with_fwd_decl(c, struct_type, full_type_name);
17341732 return struct_type;
17351733 }
......@@ -1810,17 +1808,17 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
18101808 case VarDecl::TLS_None:
18111809 break;
18121810 case VarDecl::TLS_Static:
1813 emit_warning(c, var_decl, "ignoring variable '%s' - static thread local storage\n", buf_ptr(name));
1811 emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - static thread local storage\n", buf_ptr(name));
18141812 return;
18151813 case VarDecl::TLS_Dynamic:
1816 emit_warning(c, var_decl, "ignoring variable '%s' - dynamic thread local storage\n", buf_ptr(name));
1814 emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - dynamic thread local storage\n", buf_ptr(name));
18171815 return;
18181816 }
18191817
18201818 QualType qt = var_decl->getType();
18211819 TypeTableEntry *var_type = resolve_qual_type(c, qt, var_decl);
18221820 if (var_type->id == TypeTableEntryIdInvalid) {
1823 emit_warning(c, var_decl, "ignoring variable '%s' - unresolved type\n", buf_ptr(name));
1821 emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - unresolved type\n", buf_ptr(name));
18241822 return;
18251823 }
18261824
......@@ -1830,12 +1828,12 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
18301828
18311829 if (is_static && !is_extern) {
18321830 if (!var_decl->hasInit()) {
1833 emit_warning(c, var_decl, "ignoring variable '%s' - no initializer\n", buf_ptr(name));
1831 emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - no initializer\n", buf_ptr(name));
18341832 return;
18351833 }
18361834 APValue *ap_value = var_decl->evaluateValue();
18371835 if (!ap_value) {
1838 emit_warning(c, var_decl, "ignoring variable '%s' - unable to evaluate initializer\n", buf_ptr(name));
1836 emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - unable to evaluate initializer\n", buf_ptr(name));
18391837 return;
18401838 }
18411839 ConstExprValue *init_value = nullptr;
......@@ -1843,7 +1841,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
18431841 case APValue::Int:
18441842 {
18451843 if (var_type->id != TypeTableEntryIdInt) {
1846 emit_warning(c, var_decl,
1844 emit_warning(c, var_decl->getLocation(),
18471845 "ignoring variable '%s' - int initializer for non int type\n", buf_ptr(name));
18481846 return;
18491847 }
......@@ -1864,7 +1862,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
18641862 case APValue::Union:
18651863 case APValue::MemberPointer:
18661864 case APValue::AddrLabelDiff:
1867 emit_warning(c, var_decl,
1865 emit_warning(c, var_decl->getLocation(),
18681866 "ignoring variable '%s' - unrecognized initializer value kind\n", buf_ptr(name));
18691867 return;
18701868 }
......@@ -1881,7 +1879,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
18811879 return;
18821880 }
18831881
1884 emit_warning(c, var_decl, "ignoring variable '%s' - non-extern, non-static variable\n", buf_ptr(name));
1882 emit_warning(c, var_decl->getLocation(), "ignoring variable '%s' - non-extern, non-static variable\n", buf_ptr(name));
18851883 return;
18861884}
18871885
......@@ -1905,7 +1903,7 @@ static bool decl_visitor(void *context, const Decl *decl) {
19051903 visit_var_decl(c, static_cast<const VarDecl *>(decl));
19061904 break;
19071905 default:
1908 emit_warning(c, decl, "ignoring %s decl\n", decl->getDeclKindName());
1906 emit_warning(c, decl->getLocation(), "ignoring %s decl\n", decl->getDeclKindName());
19091907 }
19101908
19111909 return true;