Cleanup iterators, remove logging, add message queue
This commit is contained in:
161
core_parsing.cpp
161
core_parsing.cpp
@@ -1,103 +1,100 @@
|
||||
CORE_Static Ast_Decl *parse_decl(B32 is_global);
|
||||
|
||||
enum Log_Kind{Log_Kind_Normal_No_NewLine, Log_Kind_Normal, Log_Kind_Error, Log_Kind_Trace};
|
||||
typedef void Log_Proc(Log_Kind kind, String string, char *file, int line);
|
||||
|
||||
#define log_info(...) handle_log_message(Log_Kind_Normal, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_info_no_nl(...) handle_log_message(Log_Kind_Normal_No_NewLine, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_trace(...) handle_log_message(Log_Kind_Trace, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
#define log_error(...) handle_log_message(Log_Kind_Error, __LINE__, __FILE__,##__VA_ARGS__)
|
||||
CORE_Static void
|
||||
handle_log_message(Log_Kind kind, int line, const char *file, const char *str, ...){
|
||||
if(kind == Log_Kind_Trace) return;
|
||||
|
||||
Scratch_Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope _scope(scratch);
|
||||
STRING_FMT(scratch, str, message);
|
||||
printf("%s", message.str);
|
||||
if(kind != Log_Kind_Normal_No_NewLine){
|
||||
printf("\n");
|
||||
}
|
||||
static void core_add_message(Core_Message_Kind kind, String string, Token *pos1, Token *pos2 = 0, int line = -1, const char *file = 0) {
|
||||
if (kind == CORE_ERROR) pctx->errors_occured += 1;
|
||||
if (kind == CORE_WARNING) pctx->warnings_occured += 1;
|
||||
Core_Message *message = allocate_struct(pctx->perm, Core_Message);
|
||||
message->kind = kind;
|
||||
message->string = string;
|
||||
message->pos1 = pos1;
|
||||
message->pos2 = pos2;
|
||||
message->trace_line = line;
|
||||
message->trace_file = (char *)file;
|
||||
SLL_QUEUE_ADD(pctx->first_message, pctx->last_message, message);
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
print_token_line(Token *token){
|
||||
if(!token) return;
|
||||
#define log_trace(...) core_log_trace(__LINE__, __FILE__,##__VA_ARGS__)
|
||||
static void core_log_trace(int line, const char *file, const char *str, ...){
|
||||
STRING_FMT(pctx->perm, str, string);
|
||||
core_add_message(CORE_TRACE, string, 0, 0, line, file);
|
||||
}
|
||||
|
||||
#define PRINTF_GREEN "\033[32m"
|
||||
#define PRINTF_RED "\033[31m"
|
||||
#define PRINTF_RESET "\033[0m"
|
||||
//
|
||||
//CORE_Static void
|
||||
//print_token_line(Token *token){
|
||||
// if(!token) return;
|
||||
//
|
||||
// // Print from line begin to token
|
||||
// int i1 = token->str - token->line_begin;
|
||||
// log_info_no_nl("%.*s", i1, token->line_begin);
|
||||
//
|
||||
// // Print token part
|
||||
// if(pctx->color_codes_enabled){
|
||||
// log_info_no_nl( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
// } else {
|
||||
// log_info_no_nl("%.*s", (int)token->len, token->str);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // Print to end of line from token
|
||||
// int iend = 0;
|
||||
// U8 *pointer = token->str + token->len;
|
||||
// while(pointer[iend]!='\n' && pointer[iend]!=0) iend++;
|
||||
// log_info_no_nl("%.*s", iend, pointer);
|
||||
// log_info_no_nl("\n");
|
||||
//}
|
||||
//
|
||||
//CORE_Static void
|
||||
//print_token_context(Token *token){
|
||||
// if(!token) return;
|
||||
// log_info_no_nl("\n");
|
||||
// print_token_line(token);
|
||||
//}
|
||||
|
||||
// Print from line begin to token
|
||||
int i1 = token->str - token->line_begin;
|
||||
log_info_no_nl("%.*s", i1, token->line_begin);
|
||||
|
||||
// Print token part
|
||||
if(pctx->color_codes_enabled){
|
||||
log_info_no_nl( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
} else {
|
||||
log_info_no_nl("%.*s", (int)token->len, token->str);
|
||||
}
|
||||
|
||||
|
||||
// Print to end of line from token
|
||||
int iend = 0;
|
||||
U8 *pointer = token->str + token->len;
|
||||
while(pointer[iend]!='\n' && pointer[iend]!=0) iend++;
|
||||
log_info_no_nl("%.*s", iend, pointer);
|
||||
log_info_no_nl("\n");
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
print_token_context(Token *token){
|
||||
if(!token) return;
|
||||
log_info_no_nl("\n");
|
||||
print_token_line(token);
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
compiler_error(Token *token1, Token *token2, const char *str, ...){
|
||||
static void compiler_error(Token *token1, Token *token2, const char *str, ...) {
|
||||
STRING_FMT(pctx->perm, str, string);
|
||||
|
||||
log_info_no_nl("\n%s", string.str);
|
||||
if(token1){
|
||||
if(token1->kind == TK_Error){
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token1->error_val.len, token1->error_val.str);
|
||||
}
|
||||
print_token_context(token1);
|
||||
}
|
||||
|
||||
if(token2){
|
||||
if(token2->kind == TK_Error){
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token2->error_val.len, token2->error_val.str);
|
||||
}
|
||||
print_token_context(token2);
|
||||
}
|
||||
|
||||
if(token1) log_info_no_nl("\n%s:%d", token1->file.str, (S32)token1->line + 1);
|
||||
if(token2) log_info_no_nl("\n%s:%d", token2->file.str, (S32)token2->line + 1);
|
||||
|
||||
fflush(stdout);
|
||||
core_add_message(CORE_ERROR, string, token1, token2);
|
||||
// log_info_no_nl("\n%s", string.str);
|
||||
// if(token1){
|
||||
// if(token1->kind == TK_Error){
|
||||
// log_info_no_nl("\nToken Error: %.*s", (int)token1->error_val.len, token1->error_val.str);
|
||||
// }
|
||||
// print_token_context(token1);
|
||||
// }
|
||||
//
|
||||
// if(token2){
|
||||
// if(token2->kind == TK_Error){
|
||||
// log_info_no_nl("\nToken Error: %.*s", (int)token2->error_val.len, token2->error_val.str);
|
||||
// }
|
||||
// print_token_context(token2);
|
||||
// }
|
||||
//
|
||||
// if(token1) log_info_no_nl("\n%s:%d", token1->file.str, (S32)token1->line + 1);
|
||||
// if(token2) log_info_no_nl("\n%s:%d", token2->file.str, (S32)token2->line + 1);
|
||||
//
|
||||
// fflush(stdout);
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
compiler_error(Token *token, const char *str, ...){
|
||||
STRING_FMT(pctx->perm, str, string);
|
||||
core_add_message(CORE_ERROR, string, token);
|
||||
|
||||
if(token) log_info_no_nl("\n%s:%d %Q", token->file.str, (S32)token->line + 1, string);
|
||||
else log_info_no_nl("\n%s", string.str);
|
||||
if(token){
|
||||
if(token->kind == TK_Error){
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||
}
|
||||
// if(token) log_info_no_nl("\n%s:%d %Q", token->file.str, (S32)token->line + 1, string);
|
||||
// else log_info_no_nl("\n%s", string.str);
|
||||
// if(token){
|
||||
// if(token->kind == TK_Error){
|
||||
// log_info_no_nl("\nToken Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||
// }
|
||||
//
|
||||
// print_token_context(token);
|
||||
// }
|
||||
//fflush(stdout);
|
||||
|
||||
print_token_context(token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fflush(stdout);
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user