mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-13 06:43:35 +00:00
Merge pull request #6048 from odin-lang/bill/feature-using-stmt
Make `using` as a statement opt-in with `#+feature using-stmt`
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#+vet !using-param
|
||||
#+feature using-stmt
|
||||
package compress_zlib
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#+vet !using-stmt
|
||||
package netpbm
|
||||
|
||||
import "core:bytes"
|
||||
@@ -73,8 +72,7 @@ save_to_buffer :: proc(img: ^Image, custom_info: Info = {}, allocator := context
|
||||
}
|
||||
}
|
||||
|
||||
// using info so we can just talk about the header
|
||||
using info
|
||||
header := &info.header
|
||||
|
||||
// validation
|
||||
if header.format in (PBM + PGM + Formats{.Pf}) && img.channels != 1 \
|
||||
@@ -664,14 +662,14 @@ autoselect_pbm_format_from_image :: proc(img: ^Image, prefer_binary := true, for
|
||||
|
||||
ASCII :: Formats{.P1, .P2, .P3}
|
||||
*/
|
||||
using res.header
|
||||
h := &res.header
|
||||
|
||||
width = img.width
|
||||
height = img.height
|
||||
channels = img.channels
|
||||
depth = img.depth
|
||||
maxval = 255 if img.depth == 8 else 65535
|
||||
little_endian = true if ODIN_ENDIAN == .Little else false
|
||||
h.width = img.width
|
||||
h.height = img.height
|
||||
h.channels = img.channels
|
||||
h.depth = img.depth
|
||||
h.maxval = 255 if img.depth == 8 else 65535
|
||||
h.little_endian = ODIN_ENDIAN == .Little
|
||||
|
||||
// Assume we'll find a suitable format
|
||||
ok = true
|
||||
@@ -680,37 +678,37 @@ autoselect_pbm_format_from_image :: proc(img: ^Image, prefer_binary := true, for
|
||||
case 1:
|
||||
// Must be Portable Float Map
|
||||
if img.depth == 32 {
|
||||
format = .Pf
|
||||
h.format = .Pf
|
||||
return
|
||||
}
|
||||
|
||||
if force_black_and_white {
|
||||
// Portable Bit Map
|
||||
format = .P4 if prefer_binary else .P1
|
||||
maxval = 1
|
||||
h.format = .P4 if prefer_binary else .P1
|
||||
h.maxval = 1
|
||||
return
|
||||
} else {
|
||||
// Portable Gray Map
|
||||
format = .P5 if prefer_binary else .P2
|
||||
h.format = .P5 if prefer_binary else .P2
|
||||
return
|
||||
}
|
||||
|
||||
case 3:
|
||||
// Must be Portable Float Map
|
||||
if img.depth == 32 {
|
||||
format = .PF
|
||||
h.format = .PF
|
||||
return
|
||||
}
|
||||
|
||||
// Portable Pixel Map
|
||||
format = .P6 if prefer_binary else .P3
|
||||
h.format = .P6 if prefer_binary else .P3
|
||||
return
|
||||
|
||||
case:
|
||||
// Portable Arbitrary Map
|
||||
if img.depth == 8 || img.depth == 16 {
|
||||
format = .P7
|
||||
scale = pfm_scale
|
||||
h.format = .P7
|
||||
h.scale = pfm_scale
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#+vet !using-stmt
|
||||
#+feature using-stmt
|
||||
package png
|
||||
|
||||
/*
|
||||
|
||||
@@ -37,7 +37,7 @@ _destroy :: proc(thread: ^Thread) {
|
||||
unimplemented("core:thread procedure not supported on target")
|
||||
}
|
||||
|
||||
_terminate :: proc(using thread : ^Thread, exit_code: int) {
|
||||
_terminate :: proc(thread : ^Thread, exit_code: int) {
|
||||
unimplemented("core:thread procedure not supported on target")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#+vet !using-stmt !using-param
|
||||
#+feature dynamic-literals
|
||||
#+feature using-stmt
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
|
||||
@@ -366,9 +366,7 @@ enum OptInFeatureFlags : u64 {
|
||||
OptInFeatureFlag_IntegerDivisionByZero_AllBits,
|
||||
|
||||
OptInFeatureFlag_ForceTypeAssert = 1u<<6,
|
||||
|
||||
|
||||
|
||||
OptInFeatureFlag_UsingStmt = 1u<<7,
|
||||
};
|
||||
|
||||
u64 get_feature_flag_from_name(String const &name) {
|
||||
@@ -387,6 +385,9 @@ u64 get_feature_flag_from_name(String const &name) {
|
||||
if (name == "integer-division-by-zero:all-bits") {
|
||||
return OptInFeatureFlag_IntegerDivisionByZero_AllBits;
|
||||
}
|
||||
if (name == "using-stmt") {
|
||||
return OptInFeatureFlag_UsingStmt;
|
||||
}
|
||||
if (name == "force-type-assert") {
|
||||
return OptInFeatureFlag_ForceTypeAssert;
|
||||
}
|
||||
|
||||
@@ -2945,10 +2945,12 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
error(us->token, "Empty 'using' list");
|
||||
return;
|
||||
}
|
||||
if (check_vet_flags(node) & VetFlag_UsingStmt) {
|
||||
|
||||
u64 feature_flags = check_feature_flags(ctx, node);
|
||||
if ((feature_flags & OptInFeatureFlag_UsingStmt) == 0) {
|
||||
ERROR_BLOCK();
|
||||
error(node, "'using' as a statement is not allowed when '-vet' or '-vet-using' is applied");
|
||||
error_line("\t'using' is considered bad practice to use as a statement outside of immediate refactoring\n");
|
||||
error(node, "'using' has been disallowed as it is considered bad practice to use as a statement outside of immediate refactoring");
|
||||
error_line("\tIt you do require it for refactoring purposes or legacy code, it can be enabled on a per-file basis with '#+feature using-stmt'\n");
|
||||
}
|
||||
|
||||
for (Ast *expr : us->list) {
|
||||
|
||||
@@ -1845,11 +1845,14 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
|
||||
Type *specialization = nullptr;
|
||||
|
||||
bool is_using = (p->flags&FieldFlag_using) != 0;
|
||||
if ((check_vet_flags(param) & VetFlag_UsingParam) && is_using) {
|
||||
ERROR_BLOCK();
|
||||
error(param, "'using' on a procedure parameter is not allowed when '-vet' or '-vet-using-param' is applied");
|
||||
error_line("\t'using' is considered bad practice to use as a statement/procedure parameter outside of immediate refactoring\n");
|
||||
|
||||
|
||||
u64 feature_flags = check_feature_flags(ctx, param);
|
||||
|
||||
if (is_using && (feature_flags & OptInFeatureFlag_UsingStmt) == 0) {
|
||||
ERROR_BLOCK();
|
||||
error(param, "'using' has been disallowed as it is considered bad practice to use as a statement/procedure parameter outside of immediate refactoring");
|
||||
error_line("\tIt you do require it for refactoring purposes or legacy code, it can be enabled on a per-file basis with '#+feature using-stmt'\n");
|
||||
}
|
||||
|
||||
if (type_expr == nullptr) {
|
||||
|
||||
@@ -6504,6 +6504,8 @@ gb_internal u64 parse_feature_tag(Token token_for_pos, String s) {
|
||||
syntax_error(token_for_pos, "Invalid feature flag name: %.*s", LIT(p));
|
||||
error_line("\tExpected one of the following\n");
|
||||
error_line("\tdynamic-literals\n");
|
||||
error_line("\tglobal-context\n");
|
||||
error_line("\tusing-stmt\n");
|
||||
error_line("\tinteger-division-by-zero:trap\n");
|
||||
error_line("\tinteger-division-by-zero:zero\n");
|
||||
error_line("\tinteger-division-by-zero:self\n");
|
||||
|
||||
2
vendor/fontstash/fontstash.odin
vendored
2
vendor/fontstash/fontstash.odin
vendored
@@ -1,5 +1,5 @@
|
||||
// An Odin-native source port of [[ Fontstash ; https://github.com/memononen/fontstash ]].
|
||||
#+vet !using-param
|
||||
#+feature using-stmt
|
||||
package fontstash
|
||||
|
||||
import "base:runtime"
|
||||
|
||||
Reference in New Issue
Block a user