mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Rename -vet-identical-cast to -vet-cast; with minor code clean up
This commit is contained in:
@@ -742,11 +742,11 @@ enum VetFlags : u64 {
|
|||||||
VetFlag_UnusedVariables = 1u<<5,
|
VetFlag_UnusedVariables = 1u<<5,
|
||||||
VetFlag_UnusedImports = 1u<<6,
|
VetFlag_UnusedImports = 1u<<6,
|
||||||
VetFlag_Deprecated = 1u<<7,
|
VetFlag_Deprecated = 1u<<7,
|
||||||
VetFlag_IdenticalCast = 1u<<8,
|
VetFlag_Cast = 1u<<8,
|
||||||
|
|
||||||
VetFlag_Unused = VetFlag_UnusedVariables|VetFlag_UnusedImports,
|
VetFlag_Unused = VetFlag_UnusedVariables|VetFlag_UnusedImports,
|
||||||
|
|
||||||
VetFlag_All = VetFlag_Unused|VetFlag_Shadowing|VetFlag_UsingStmt|VetFlag_Deprecated|VetFlag_IdenticalCast,
|
VetFlag_All = VetFlag_Unused|VetFlag_Shadowing|VetFlag_UsingStmt|VetFlag_Deprecated|VetFlag_Cast,
|
||||||
|
|
||||||
VetFlag_Using = VetFlag_UsingStmt|VetFlag_UsingParam,
|
VetFlag_Using = VetFlag_UsingStmt|VetFlag_UsingParam,
|
||||||
};
|
};
|
||||||
@@ -770,8 +770,8 @@ u64 get_vet_flag_from_name(String const &name) {
|
|||||||
return VetFlag_Semicolon;
|
return VetFlag_Semicolon;
|
||||||
} else if (name == "deprecated") {
|
} else if (name == "deprecated") {
|
||||||
return VetFlag_Deprecated;
|
return VetFlag_Deprecated;
|
||||||
} else if (name == "identical-cast") {
|
} else if (name == "cast") {
|
||||||
return VetFlag_IdenticalCast;
|
return VetFlag_Cast;
|
||||||
}
|
}
|
||||||
return VetFlag_NONE;
|
return VetFlag_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -3382,18 +3382,18 @@ gb_internal void check_cast(CheckerContext *c, Operand *x, Type *type, bool forb
|
|||||||
add_package_dependency(c, "runtime", "gnu_f2h_ieee", REQUIRE);
|
add_package_dependency(c, "runtime", "gnu_f2h_ieee", REQUIRE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (forbid_identical && check_vet_flags(c) & VetFlag_IdenticalCast) {
|
// If we check polymorphic procedures, we risk erring on
|
||||||
|
// identical casts that cannot be foreseen or otherwise
|
||||||
|
// forbidden, so just skip them.
|
||||||
|
if (forbid_identical && check_vet_flags(c) & VetFlag_Cast &&
|
||||||
|
(c->curr_proc_sig == nullptr || !is_type_polymorphic(c->curr_proc_sig))) {
|
||||||
Type *src_exact = x->type;
|
Type *src_exact = x->type;
|
||||||
Type *dst_exact = type;
|
Type *dst_exact = type;
|
||||||
|
|
||||||
if (src_exact != nullptr &&
|
if (src_exact != nullptr &&
|
||||||
dst_exact != nullptr &&
|
dst_exact != nullptr &&
|
||||||
// If we check polymorphic procedures, we risk erring on
|
are_types_identical(src_exact, dst_exact)
|
||||||
// identical casts that cannot be foreseen or otherwise
|
) {
|
||||||
// forbidden, so just skip them.
|
|
||||||
(c->curr_proc_sig == nullptr || !is_type_polymorphic(c->curr_proc_sig)) &&
|
|
||||||
src_exact == dst_exact)
|
|
||||||
{
|
|
||||||
gbString oper_str = expr_to_string(x->expr);
|
gbString oper_str = expr_to_string(x->expr);
|
||||||
gbString to_type = type_to_string(dst_exact);
|
gbString to_type = type_to_string(dst_exact);
|
||||||
error(x->expr, "Unneeded cast of `%s` to identical type `%s`", oper_str, to_type);
|
error(x->expr, "Unneeded cast of `%s` to identical type `%s`", oper_str, to_type);
|
||||||
|
|||||||
+5
-5
@@ -300,7 +300,7 @@ enum BuildFlagKind {
|
|||||||
BuildFlag_VetUsingParam,
|
BuildFlag_VetUsingParam,
|
||||||
BuildFlag_VetStyle,
|
BuildFlag_VetStyle,
|
||||||
BuildFlag_VetSemicolon,
|
BuildFlag_VetSemicolon,
|
||||||
BuildFlag_VetIdenticalCast,
|
BuildFlag_VetCast,
|
||||||
|
|
||||||
BuildFlag_CustomAttribute,
|
BuildFlag_CustomAttribute,
|
||||||
BuildFlag_IgnoreUnknownAttributes,
|
BuildFlag_IgnoreUnknownAttributes,
|
||||||
@@ -500,7 +500,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
|||||||
add_flag(&build_flags, BuildFlag_VetUsingParam, str_lit("vet-using-param"), BuildFlagParam_None, Command__does_check);
|
add_flag(&build_flags, BuildFlag_VetUsingParam, str_lit("vet-using-param"), BuildFlagParam_None, Command__does_check);
|
||||||
add_flag(&build_flags, BuildFlag_VetStyle, str_lit("vet-style"), BuildFlagParam_None, Command__does_check);
|
add_flag(&build_flags, BuildFlag_VetStyle, str_lit("vet-style"), BuildFlagParam_None, Command__does_check);
|
||||||
add_flag(&build_flags, BuildFlag_VetSemicolon, str_lit("vet-semicolon"), BuildFlagParam_None, Command__does_check);
|
add_flag(&build_flags, BuildFlag_VetSemicolon, str_lit("vet-semicolon"), BuildFlagParam_None, Command__does_check);
|
||||||
add_flag(&build_flags, BuildFlag_VetIdenticalCast, str_lit("vet-identical-cast"), BuildFlagParam_None, Command__does_check);
|
add_flag(&build_flags, BuildFlag_VetCast, str_lit("vet-cast"), BuildFlagParam_None, Command__does_check);
|
||||||
|
|
||||||
add_flag(&build_flags, BuildFlag_CustomAttribute, str_lit("custom-attribute"), BuildFlagParam_String, Command__does_check, true);
|
add_flag(&build_flags, BuildFlag_CustomAttribute, str_lit("custom-attribute"), BuildFlagParam_String, Command__does_check, true);
|
||||||
add_flag(&build_flags, BuildFlag_IgnoreUnknownAttributes, str_lit("ignore-unknown-attributes"), BuildFlagParam_None, Command__does_check);
|
add_flag(&build_flags, BuildFlag_IgnoreUnknownAttributes, str_lit("ignore-unknown-attributes"), BuildFlagParam_None, Command__does_check);
|
||||||
@@ -1154,7 +1154,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
|||||||
case BuildFlag_VetUsingParam: build_context.vet_flags |= VetFlag_UsingParam; break;
|
case BuildFlag_VetUsingParam: build_context.vet_flags |= VetFlag_UsingParam; break;
|
||||||
case BuildFlag_VetStyle: build_context.vet_flags |= VetFlag_Style; break;
|
case BuildFlag_VetStyle: build_context.vet_flags |= VetFlag_Style; break;
|
||||||
case BuildFlag_VetSemicolon: build_context.vet_flags |= VetFlag_Semicolon; break;
|
case BuildFlag_VetSemicolon: build_context.vet_flags |= VetFlag_Semicolon; break;
|
||||||
case BuildFlag_VetIdenticalCast: build_context.vet_flags |= VetFlag_IdenticalCast; break;
|
case BuildFlag_VetCast: build_context.vet_flags |= VetFlag_Cast; break;
|
||||||
|
|
||||||
case BuildFlag_CustomAttribute:
|
case BuildFlag_CustomAttribute:
|
||||||
{
|
{
|
||||||
@@ -2247,8 +2247,8 @@ gb_internal void print_show_help(String const arg0, String const &command) {
|
|||||||
print_usage_line(2, "Errs on unneeded semicolons.");
|
print_usage_line(2, "Errs on unneeded semicolons.");
|
||||||
print_usage_line(0, "");
|
print_usage_line(0, "");
|
||||||
|
|
||||||
print_usage_line(1, "-vet-identical-cast");
|
print_usage_line(1, "-vet-cast");
|
||||||
print_usage_line(2, "Errs on casting a value to its own type.");
|
print_usage_line(2, "Errs on casting a value to its own type or using `transmute` rather than `cast`.");
|
||||||
print_usage_line(0, "");
|
print_usage_line(0, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user