mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-03 19:52:30 +00:00
Add -vet-tabs
This commit is contained in:
@@ -282,6 +282,7 @@ enum VetFlags : u64 {
|
||||
VetFlag_UnusedImports = 1u<<6,
|
||||
VetFlag_Deprecated = 1u<<7,
|
||||
VetFlag_Cast = 1u<<8,
|
||||
VetFlag_Tabs = 1u<<9,
|
||||
|
||||
VetFlag_Unused = VetFlag_UnusedVariables|VetFlag_UnusedImports,
|
||||
|
||||
@@ -311,6 +312,8 @@ u64 get_vet_flag_from_name(String const &name) {
|
||||
return VetFlag_Deprecated;
|
||||
} else if (name == "cast") {
|
||||
return VetFlag_Cast;
|
||||
} else if (name == "tabs") {
|
||||
return VetFlag_Tabs;
|
||||
}
|
||||
return VetFlag_NONE;
|
||||
}
|
||||
|
||||
@@ -301,6 +301,7 @@ enum BuildFlagKind {
|
||||
BuildFlag_VetStyle,
|
||||
BuildFlag_VetSemicolon,
|
||||
BuildFlag_VetCast,
|
||||
BuildFlag_VetTabs,
|
||||
|
||||
BuildFlag_CustomAttribute,
|
||||
BuildFlag_IgnoreUnknownAttributes,
|
||||
@@ -502,6 +503,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
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_VetCast, str_lit("vet-cast"), BuildFlagParam_None, Command__does_check);
|
||||
add_flag(&build_flags, BuildFlag_VetTabs, str_lit("vet-tabs"), 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_IgnoreUnknownAttributes, str_lit("ignore-unknown-attributes"), BuildFlagParam_None, Command__does_check);
|
||||
@@ -1157,6 +1159,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
case BuildFlag_VetStyle: build_context.vet_flags |= VetFlag_Style; break;
|
||||
case BuildFlag_VetSemicolon: build_context.vet_flags |= VetFlag_Semicolon; break;
|
||||
case BuildFlag_VetCast: build_context.vet_flags |= VetFlag_Cast; break;
|
||||
case BuildFlag_VetTabs: build_context.vet_flags |= VetFlag_Tabs; break;
|
||||
|
||||
case BuildFlag_CustomAttribute:
|
||||
{
|
||||
@@ -2256,6 +2259,10 @@ gb_internal void print_show_help(String const arg0, String const &command) {
|
||||
print_usage_line(1, "-vet-cast");
|
||||
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(1, "-vet-tabs");
|
||||
print_usage_line(2, "Errs when the use of tabs has not been used for indentation.");
|
||||
print_usage_line(0, "");
|
||||
}
|
||||
|
||||
if (check) {
|
||||
|
||||
@@ -5286,12 +5286,53 @@ gb_internal Ast *parse_stmt(AstFile *f) {
|
||||
return ast_bad_stmt(f, token, f->curr_token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
gb_internal u64 check_vet_flags(AstFile *file) {
|
||||
if (file && file->vet_flags_set) {
|
||||
return file->vet_flags;
|
||||
}
|
||||
return build_context.vet_flags;
|
||||
}
|
||||
|
||||
|
||||
gb_internal void parse_enforce_tabs(AstFile *f) {
|
||||
Token prev = f->prev_token;
|
||||
Token curr = f->curr_token;
|
||||
if (prev.pos.line < curr.pos.line) {
|
||||
u8 *start = f->tokenizer.start+prev.pos.offset;
|
||||
u8 *end = f->tokenizer.start+curr.pos.offset;
|
||||
u8 *it = end;
|
||||
while (it > start) {
|
||||
if (*it == '\n') {
|
||||
it++;
|
||||
break;
|
||||
}
|
||||
it--;
|
||||
}
|
||||
|
||||
isize len = end-it;
|
||||
for (isize i = 0; i < len; i++) {
|
||||
if (it[i] == ' ') {
|
||||
syntax_error(curr, "With '-vet-tabs', tabs must be used for indentation");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gb_internal Array<Ast *> parse_stmt_list(AstFile *f) {
|
||||
auto list = array_make<Ast *>(ast_allocator(f));
|
||||
|
||||
while (f->curr_token.kind != Token_case &&
|
||||
f->curr_token.kind != Token_CloseBrace &&
|
||||
f->curr_token.kind != Token_EOF) {
|
||||
|
||||
// Checks to see if tabs have been used for indentation
|
||||
if (check_vet_flags(f) & VetFlag_Tabs) {
|
||||
parse_enforce_tabs(f);
|
||||
}
|
||||
|
||||
Ast *stmt = parse_stmt(f);
|
||||
if (stmt && stmt->kind != Ast_EmptyStmt) {
|
||||
array_add(&list, stmt);
|
||||
|
||||
Reference in New Issue
Block a user