Browse Source

Make default calling convention code more correct to read

gingerBill 4 years ago
parent
commit
f19bb0f4d4
5 changed files with 31 additions and 16 deletions
  1. 3 3
      src/check_decl.cpp
  2. 8 2
      src/docs_writer.cpp
  3. 1 1
      src/parser.cpp
  4. 13 9
      src/parser.hpp
  5. 6 1
      src/types.cpp

+ 3 - 3
src/check_decl.cpp

@@ -648,7 +648,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
 	if (d->gen_proc_type != nullptr) {
 	if (d->gen_proc_type != nullptr) {
 		proc_type = d->gen_proc_type;
 		proc_type = d->gen_proc_type;
 	} else {
 	} else {
-		proc_type = alloc_type_proc(e->scope, nullptr, 0, nullptr, 0, false, ProcCC_Odin);
+		proc_type = alloc_type_proc(e->scope, nullptr, 0, nullptr, 0, false, default_calling_convention());
 	}
 	}
 	e->type = proc_type;
 	e->type = proc_type;
 	ast_node(pl, ProcLit, d->proc_lit);
 	ast_node(pl, ProcLit, d->proc_lit);
@@ -746,10 +746,10 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
 			error(e->token, "Procedure type of 'main' was expected to be 'proc()', got %s", str);
 			error(e->token, "Procedure type of 'main' was expected to be 'proc()', got %s", str);
 			gb_string_free(str);
 			gb_string_free(str);
 		}
 		}
-		if (pt->calling_convention != ProcCC_Odin) {
+		if (pt->calling_convention != default_calling_convention()) {
 			error(e->token, "Procedure 'main' cannot have a custom calling convention");
 			error(e->token, "Procedure 'main' cannot have a custom calling convention");
 		}
 		}
-		pt->calling_convention = ProcCC_Odin;
+		pt->calling_convention = default_calling_convention();
 		if (e->pkg->kind == Package_Init) {
 		if (e->pkg->kind == Package_Init) {
 			if (ctx->info->entry_point != nullptr) {
 			if (ctx->info->entry_point != nullptr) {
 				error(e->token, "Redeclaration of the entry pointer procedure 'main'");
 				error(e->token, "Redeclaration of the entry pointer procedure 'main'");

+ 8 - 2
src/docs_writer.cpp

@@ -676,11 +676,17 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
 			String calling_convention = {};
 			String calling_convention = {};
 			switch (type->Proc.calling_convention) {
 			switch (type->Proc.calling_convention) {
 			case ProcCC_Invalid:
 			case ProcCC_Invalid:
-			case ProcCC_Odin:
 				// no need
 				// no need
 				break;
 				break;
+			case ProcCC_Odin:
+				if (default_calling_convention() != ProcCC_Odin) {
+					calling_convention = str_lit("odin");
+				}
+				break;
 			case ProcCC_Contextless:
 			case ProcCC_Contextless:
-				calling_convention = str_lit("contextless");
+				if (default_calling_convention() != ProcCC_Contextless) {
+					calling_convention = str_lit("contextless");
+				}
 				break;
 				break;
 			case ProcCC_CDecl:
 			case ProcCC_CDecl:
 				calling_convention = str_lit("cdecl");
 				calling_convention = str_lit("cdecl");

+ 1 - 1
src/parser.cpp

@@ -3232,7 +3232,7 @@ Ast *parse_proc_type(AstFile *f, Token proc_token) {
 		if (f->in_foreign_block) {
 		if (f->in_foreign_block) {
 			cc = ProcCC_ForeignBlockDefault;
 			cc = ProcCC_ForeignBlockDefault;
 		} else {
 		} else {
-			cc = ProcCC_Odin;
+			cc = default_calling_convention();
 		}
 		}
 	}
 	}
 
 

+ 13 - 9
src/parser.hpp

@@ -208,18 +208,18 @@ enum ProcTag {
 	ProcTag_optional_second = 1<<6,
 	ProcTag_optional_second = 1<<6,
 };
 };
 
 
-enum ProcCallingConvention {
-	ProcCC_Invalid = 0,
-	ProcCC_Odin = 1,
+enum ProcCallingConvention : i32 {
+	ProcCC_Invalid     = 0,
+	ProcCC_Odin        = 1,
 	ProcCC_Contextless = 2,
 	ProcCC_Contextless = 2,
-	ProcCC_CDecl = 3,
-	ProcCC_StdCall = 4,
-	ProcCC_FastCall = 5,
+	ProcCC_CDecl       = 3,
+	ProcCC_StdCall     = 4,
+	ProcCC_FastCall    = 5,
 
 
-	ProcCC_None = 6,
-	ProcCC_Naked = 7,
+	ProcCC_None        = 6,
+	ProcCC_Naked       = 7,
 
 
-	ProcCC_InlineAsm = 8,
+	ProcCC_InlineAsm   = 8,
 
 
 	ProcCC_MAX,
 	ProcCC_MAX,
 
 
@@ -227,6 +227,10 @@ enum ProcCallingConvention {
 	ProcCC_ForeignBlockDefault = -1,
 	ProcCC_ForeignBlockDefault = -1,
 };
 };
 
 
+ProcCallingConvention default_calling_convention(void) {
+	return ProcCC_Odin;
+}
+
 enum StateFlag : u16 {
 enum StateFlag : u16 {
 	StateFlag_bounds_check    = 1<<0,
 	StateFlag_bounds_check    = 1<<0,
 	StateFlag_no_bounds_check = 1<<1,
 	StateFlag_no_bounds_check = 1<<1,

+ 6 - 1
src/types.cpp

@@ -3618,9 +3618,14 @@ gbString write_type_to_string(gbString str, Type *type) {
 
 
 		switch (type->Proc.calling_convention) {
 		switch (type->Proc.calling_convention) {
 		case ProcCC_Odin:
 		case ProcCC_Odin:
+			if (default_calling_convention() != ProcCC_Odin) {
+				str = gb_string_appendc(str, " \"odin\" ");
+			}
 			break;
 			break;
 		case ProcCC_Contextless:
 		case ProcCC_Contextless:
-			str = gb_string_appendc(str, " \"contextless\" ");
+			if (default_calling_convention() != ProcCC_Contextless) {
+				str = gb_string_appendc(str, " \"contextless\" ");
+			}
 			break;
 			break;
 		case ProcCC_CDecl:
 		case ProcCC_CDecl:
 			str = gb_string_appendc(str, " \"cdecl\" ");
 			str = gb_string_appendc(str, " \"cdecl\" ");