2017-11-15 23:57:21 +00:00
|
|
|
/*
|
|
|
|
4coder_metadata_generator.cpp - A preprocessor program for generating a list of commands and their descriptions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
#define COMMAND_METADATA_OUT "4coder_generated/command_metadata.h"
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
#include "4coder_base_types.h"
|
|
|
|
|
|
|
|
#include "4coder_base_types.cpp"
|
|
|
|
#include "4coder_stringf.cpp"
|
|
|
|
#include "4coder_malloc_allocator.cpp"
|
|
|
|
|
2018-03-03 07:46:44 +00:00
|
|
|
#include "4coder_file.h"
|
2017-11-22 18:45:44 +00:00
|
|
|
|
2017-11-21 00:35:35 +00:00
|
|
|
#include "4coder_lib/4cpp_lexer.h"
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-03-03 07:46:44 +00:00
|
|
|
#include <stdlib.h>
|
2017-11-15 23:57:21 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
#define str_to_l_c(s) ((i32)(s).size), ((s).str)
|
|
|
|
#define str_to_c_l(s) ((s).str), ((i32)(s).size)
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
///////////////////////////////
|
|
|
|
|
|
|
|
struct Line_Column_Coordinates{
|
|
|
|
int32_t line;
|
|
|
|
int32_t column;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Line_Column_Coordinates
|
2019-06-01 23:58:28 +00:00
|
|
|
line_column_coordinates(String_Const_char text, int32_t pos){
|
2017-11-15 23:57:21 +00:00
|
|
|
if (pos < 0){
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
if (pos > text.size){
|
2019-06-01 23:58:28 +00:00
|
|
|
pos = (i32)text.size;
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Line_Column_Coordinates coords = {};
|
2017-11-18 22:40:10 +00:00
|
|
|
coords.line = 1;
|
|
|
|
coords.column = 1;
|
2017-11-15 23:57:21 +00:00
|
|
|
char *end = text.str + pos;
|
|
|
|
for (char *p = text.str; p < end; ++p){
|
|
|
|
if (*p == '\n'){
|
2017-11-18 22:40:10 +00:00
|
|
|
++coords.line;
|
|
|
|
coords.column = 1;
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-11-18 22:40:10 +00:00
|
|
|
++coords.column;
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
return(coords);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
2019-06-01 23:58:28 +00:00
|
|
|
line_number(String_Const_char text, int32_t pos){
|
2017-11-18 22:40:10 +00:00
|
|
|
Line_Column_Coordinates coords = line_column_coordinates(text, pos);
|
|
|
|
return(coords.line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
error(char *source_name, String_Const_char text, int32_t pos, char *msg){
|
2017-11-18 22:40:10 +00:00
|
|
|
Line_Column_Coordinates coords = line_column_coordinates(text, pos);
|
|
|
|
fprintf(stdout, "%s:%d:%d: %s\n", source_name, coords.line, coords.column, msg);
|
2017-11-15 23:57:21 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
///////////////////////////////
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
struct Reader{
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena *error_arena;
|
2017-11-15 23:57:21 +00:00
|
|
|
char *source_name;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char text;
|
2019-09-04 05:31:35 +00:00
|
|
|
Token_Array tokens;
|
|
|
|
Token *ptr;
|
2017-11-15 23:57:21 +00:00
|
|
|
};
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
struct Temp_Read{
|
|
|
|
Reader *reader;
|
2019-09-04 05:31:35 +00:00
|
|
|
Token *pos;
|
2017-11-18 22:40:10 +00:00
|
|
|
};
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
static Reader
|
2019-06-01 23:58:28 +00:00
|
|
|
make_reader(Cpp_Token_Array array, char *source_name, String_Const_char text){
|
2018-11-20 08:18:54 +00:00
|
|
|
Reader reader = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
reader.tokens = array;
|
|
|
|
reader.ptr = array.tokens;
|
|
|
|
reader.source_name = source_name;
|
|
|
|
reader.text = text;
|
|
|
|
return(reader);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
static Token
|
2017-11-15 23:57:21 +00:00
|
|
|
prev_token(Reader *reader){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token result = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
for (;;){
|
|
|
|
if (reader->ptr > reader->tokens.tokens + reader->tokens.count){
|
|
|
|
reader->ptr = reader->tokens.tokens + reader->tokens.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reader->ptr > reader->tokens.tokens){
|
|
|
|
--reader->ptr;
|
|
|
|
result = *reader->ptr;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reader->ptr = reader->tokens.tokens;
|
|
|
|
memset(&result, 0, sizeof(result));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.type != CPP_TOKEN_COMMENT && result.type != CPP_TOKEN_JUNK){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
static Token
|
2017-11-15 23:57:21 +00:00
|
|
|
get_token(Reader *reader){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token result = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
for (;;){
|
|
|
|
if (reader->ptr < reader->tokens.tokens){
|
|
|
|
reader->ptr = reader->tokens.tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reader->ptr < reader->tokens.tokens + reader->tokens.count){
|
|
|
|
result = *reader->ptr;
|
|
|
|
++reader->ptr;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
reader->ptr = reader->tokens.tokens + reader->tokens.count;
|
|
|
|
memset(&result, 0, sizeof(result));
|
2019-06-01 23:58:28 +00:00
|
|
|
result.start = (i32)reader->text.size;
|
2017-11-15 23:57:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.type != CPP_TOKEN_COMMENT && result.type != CPP_TOKEN_JUNK){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
static Token
|
2017-11-15 23:57:21 +00:00
|
|
|
peek_token(Reader *reader){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token result = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
if (reader->ptr < reader->tokens.tokens){
|
|
|
|
reader->ptr = reader->tokens.tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reader->ptr >= reader->tokens.tokens + reader->tokens.count){
|
2019-06-01 23:58:28 +00:00
|
|
|
result.start = (i32)reader->text.size;
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
result = *reader->ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
|
|
|
peek_pos(Reader *reader){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = peek_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
return(token.start);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
static int32_t
|
|
|
|
line_number(Reader *reader, int32_t pos){
|
|
|
|
int32_t result = line_number(reader->text, pos);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
static void
|
|
|
|
error(Reader *reader, int32_t pos, char *msg){
|
|
|
|
error(reader->source_name, reader->text, pos, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Temp_Read
|
|
|
|
begin_temp_read(Reader *reader){
|
2018-11-20 08:18:54 +00:00
|
|
|
Temp_Read temp = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
temp.reader = reader;
|
|
|
|
temp.pos = reader->ptr;
|
|
|
|
return(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
end_temp_read(Temp_Read temp){
|
|
|
|
temp.reader->ptr = temp.pos;
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
///////////////////////////////
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static String_Const_char
|
2019-09-04 05:31:35 +00:00
|
|
|
token_str(String_Const_char text, Token token){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char str = string_prefix(string_skip(text, token.start), token.size);
|
2017-11-15 23:57:21 +00:00
|
|
|
return(str);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
///////////////////////////////
|
|
|
|
|
|
|
|
typedef uint32_t Meta_Command_Entry_Type;
|
|
|
|
enum{
|
|
|
|
MetaCommandEntry_DocString,
|
|
|
|
MetaCommandEntry_Alias,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Meta_Command_Entry{
|
|
|
|
Meta_Command_Entry *next;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char name;
|
2017-11-18 22:40:10 +00:00
|
|
|
char *source_name;
|
|
|
|
int32_t line_number;
|
|
|
|
union{
|
|
|
|
struct{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char doc;
|
2017-11-18 22:40:10 +00:00
|
|
|
} docstring;
|
|
|
|
struct{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char potential;
|
2017-11-18 22:40:10 +00:00
|
|
|
} alias;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Meta_Command_Entry_Arrays{
|
|
|
|
Meta_Command_Entry *first_doc_string;
|
|
|
|
Meta_Command_Entry *last_doc_string;
|
|
|
|
int32_t doc_string_count;
|
|
|
|
|
|
|
|
Meta_Command_Entry *first_alias;
|
|
|
|
Meta_Command_Entry *last_alias;
|
|
|
|
int32_t alias_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
|
2017-11-27 20:13:42 +00:00
|
|
|
static int32_t
|
|
|
|
quick_sort_part(Meta_Command_Entry **entries, int32_t first, int32_t one_past_last){
|
|
|
|
int32_t pivot = one_past_last - 1;
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char pivot_key = entries[pivot]->name;
|
2017-11-27 20:13:42 +00:00
|
|
|
int32_t j = first;
|
|
|
|
for (int32_t i = first; i < pivot; ++i){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_compare(entries[i]->name, pivot_key) < 0){
|
2017-11-27 20:13:42 +00:00
|
|
|
Swap(Meta_Command_Entry*, entries[i], entries[j]);
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Swap(Meta_Command_Entry*, entries[j], entries[pivot]);
|
|
|
|
return(j);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
quick_sort(Meta_Command_Entry **entries, int32_t first, int32_t one_past_last){
|
|
|
|
if (first + 1 < one_past_last){
|
|
|
|
int32_t pivot = quick_sort_part(entries, first, one_past_last);
|
|
|
|
quick_sort(entries, first, pivot);
|
|
|
|
quick_sort(entries, pivot + 1, one_past_last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Meta_Command_Entry**
|
2019-06-01 23:58:28 +00:00
|
|
|
get_sorted_meta_commands(Arena *arena, Meta_Command_Entry *first, int32_t count){
|
|
|
|
Meta_Command_Entry **entries = push_array(arena, Meta_Command_Entry*, count);
|
2017-11-27 20:13:42 +00:00
|
|
|
|
|
|
|
int32_t i = 0;
|
|
|
|
for (Meta_Command_Entry *entry = first;
|
|
|
|
entry != 0;
|
|
|
|
entry = entry->next, ++i){
|
|
|
|
entries[i] = entry;
|
|
|
|
}
|
|
|
|
Assert(i == count);
|
|
|
|
|
|
|
|
quick_sort(entries, 0, count);
|
|
|
|
|
|
|
|
return(entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
|
|
|
has_duplicate_entry(Meta_Command_Entry *first, String_Const_char name){
|
|
|
|
b32 has_duplicate = false;
|
2017-11-18 22:40:10 +00:00
|
|
|
for (Meta_Command_Entry *entry = first;
|
|
|
|
entry != 0;
|
|
|
|
entry = entry->next){
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(name, entry->name)){
|
2017-11-18 22:40:10 +00:00
|
|
|
has_duplicate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(has_duplicate);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
2017-11-18 22:40:10 +00:00
|
|
|
require_key_identifier(Reader *reader, char *str, int32_t *opt_pos_out = 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 success = false;
|
|
|
|
|
|
|
|
String_Const_char string = SCchar(str);
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_IDENTIFIER){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char lexeme = token_str(reader->text, token);
|
|
|
|
if (string_match(lexeme, string)){
|
2017-11-15 23:57:21 +00:00
|
|
|
success = true;
|
2017-11-18 22:40:10 +00:00
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(reader->error_arena);
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_char error_string = push_stringf(reader->error_arena, "expected to find '%s'", str);
|
2019-06-01 23:58:28 +00:00
|
|
|
error(reader, token.start, error_string.str);
|
|
|
|
end_temp(temp);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
2017-11-18 22:40:10 +00:00
|
|
|
require_open_parenthese(Reader *reader, int32_t *opt_pos_out = 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 success = false;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_PARENTHESE_OPEN){
|
|
|
|
success = true;
|
2017-11-18 22:40:10 +00:00
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find '('");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
2017-11-18 22:40:10 +00:00
|
|
|
require_close_parenthese(Reader *reader, int32_t *opt_pos_out = 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 success = false;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_PARENTHESE_CLOSE){
|
|
|
|
success = true;
|
2017-11-18 22:40:10 +00:00
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find ')'");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
2018-06-22 20:59:21 +00:00
|
|
|
require_comma(Reader *reader, int32_t *opt_pos_out = 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 success = false;
|
2018-06-22 20:59:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2018-06-22 20:59:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_COMMA){
|
|
|
|
success = true;
|
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find ','");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
2017-11-18 22:40:10 +00:00
|
|
|
require_define(Reader *reader, int32_t *opt_pos_out = 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 success = false;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (token.type == CPP_PP_DEFINE){
|
|
|
|
success = true;
|
2017-11-18 22:40:10 +00:00
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find '#define'");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
|
|
|
extract_identifier(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){
|
|
|
|
b32 success = false;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_IDENTIFIER){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char lexeme = token_str(reader->text, token);
|
2017-11-15 23:57:21 +00:00
|
|
|
*str_out = lexeme;
|
|
|
|
success = true;
|
2017-11-18 22:40:10 +00:00
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find an identifier");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
|
|
|
extract_integer(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){
|
|
|
|
b32 success = false;
|
2018-06-22 20:59:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2018-06-22 20:59:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_INTEGER_CONSTANT){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char lexeme = token_str(reader->text, token);
|
2018-06-22 20:59:21 +00:00
|
|
|
*str_out = lexeme;
|
|
|
|
success = true;
|
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find an integer");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
|
|
|
extract_string(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){
|
|
|
|
b32 success = false;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (token.type == CPP_TOKEN_STRING_CONSTANT){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char lexeme = token_str(reader->text, token);
|
2017-11-15 23:57:21 +00:00
|
|
|
*str_out = lexeme;
|
|
|
|
success = true;
|
2017-11-18 22:40:10 +00:00
|
|
|
if (opt_pos_out != 0){
|
|
|
|
*opt_pos_out = token.start;
|
|
|
|
}
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!success){
|
|
|
|
error(reader, token.start, "expected to find a string literal");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
|
|
|
parse_documented_command(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){
|
|
|
|
String_Const_char name = {};
|
|
|
|
String_Const_char file_name = {};
|
|
|
|
String_Const_char line_number = {};
|
|
|
|
String_Const_char doc = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
// Getting the command's name
|
2017-11-18 22:40:10 +00:00
|
|
|
int32_t start_pos = 0;
|
|
|
|
if (!require_key_identifier(reader, "CUSTOM_COMMAND_SIG", &start_pos)){
|
2017-11-15 23:57:21 +00:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!require_open_parenthese(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extract_identifier(reader, &name)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:59:21 +00:00
|
|
|
if (!require_comma(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extract_string(reader, &file_name)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!require_comma(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extract_integer(reader, &line_number)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
if (!require_close_parenthese(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getting the command's doc string
|
|
|
|
if (!require_key_identifier(reader, "CUSTOM_DOC")){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!require_open_parenthese(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
int32_t doc_pos = 0;
|
|
|
|
if (!extract_string(reader, &doc, &doc_pos)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doc.size < 1 || doc.str[0] != '"'){
|
|
|
|
error(reader, doc_pos, "warning: doc strings with string literal prefixes not allowed");
|
2017-11-15 23:57:21 +00:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!require_close_parenthese(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
if (has_duplicate_entry(arrays->first_doc_string, name)){
|
|
|
|
error(reader, start_pos, "warning: multiple commands with the same name and separate doc strings, skipping this one");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
doc = string_chop(string_skip(doc, 1), 1);
|
2017-11-18 22:40:10 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char file_name_unquoted = string_chop(string_skip(file_name, 1), 1);
|
|
|
|
String_Const_char source_name = string_interpret_escapes(arena, file_name_unquoted);
|
2018-06-22 20:59:21 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Meta_Command_Entry *new_entry = push_array(arena, Meta_Command_Entry, 1);
|
2017-11-18 22:40:10 +00:00
|
|
|
new_entry->name = name;
|
2019-06-01 23:58:28 +00:00
|
|
|
new_entry->source_name = source_name.str;
|
|
|
|
new_entry->line_number = (i32)string_to_integer(line_number, 10);
|
2017-11-18 22:40:10 +00:00
|
|
|
new_entry->docstring.doc = doc;
|
2019-06-01 23:58:28 +00:00
|
|
|
sll_queue_push(arrays->first_doc_string, arrays->last_doc_string, new_entry);
|
2017-11-18 22:40:10 +00:00
|
|
|
++arrays->doc_string_count;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
static b32
|
|
|
|
parse_alias(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){
|
|
|
|
String_Const_char name = {};
|
|
|
|
String_Const_char potential = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
// Getting the alias's name
|
2017-11-18 22:40:10 +00:00
|
|
|
int32_t start_pos = 0;
|
|
|
|
if (!require_define(reader, &start_pos)){
|
2017-11-15 23:57:21 +00:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extract_identifier(reader, &name)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getting the alias's target
|
|
|
|
if (!require_key_identifier(reader, "CUSTOM_ALIAS")){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!require_open_parenthese(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extract_identifier(reader, &potential)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!require_close_parenthese(reader)){
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Meta_Command_Entry *new_entry = push_array(arena, Meta_Command_Entry, 1);
|
2017-11-18 22:40:10 +00:00
|
|
|
new_entry->name = name;
|
|
|
|
new_entry->source_name = reader->source_name;
|
|
|
|
new_entry->line_number = line_number(reader, start_pos);
|
|
|
|
new_entry->alias.potential = potential;
|
2019-06-01 23:58:28 +00:00
|
|
|
sll_queue_push(arrays->first_alias, arrays->last_alias, new_entry);
|
2017-11-18 22:40:10 +00:00
|
|
|
++arrays->alias_count;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
///////////////////////////////
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, char *source_name, String_Const_char text){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token_Array array = cpp_make_token_array(1024);
|
2019-06-01 23:58:28 +00:00
|
|
|
cpp_lex_file(text.str, (i32)text.size, &array);
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
Reader reader_ = make_reader(array, source_name, text);
|
|
|
|
Reader *reader = &reader_;
|
|
|
|
|
|
|
|
for (;;){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token token = get_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
if (token.type == CPP_TOKEN_IDENTIFIER){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char lexeme = token_str(text, token);
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 in_preproc_body = ((token.flags & CPP_TFLAG_PP_BODY) != 0);
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
if (!in_preproc_body && string_match(lexeme, string_litexpr("CUSTOM_DOC"))){
|
2017-11-15 23:57:21 +00:00
|
|
|
Temp_Read temp_read = begin_temp_read(reader);
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 found_start_pos = false;
|
2018-06-22 20:59:21 +00:00
|
|
|
for (int32_t R = 0; R < 10; ++R){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token p_token = prev_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (p_token.type == CPP_TOKEN_IDENTIFIER){
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char p_lexeme = token_str(text, p_token);
|
|
|
|
if (string_match(p_lexeme, string_litexpr("CUSTOM_COMMAND_SIG"))){
|
2017-11-15 23:57:21 +00:00
|
|
|
found_start_pos = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_token.type == 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_start_pos){
|
|
|
|
end_temp_read(temp_read);
|
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
if (!parse_documented_command(arena, entry_arrays, reader)){
|
2017-11-15 23:57:21 +00:00
|
|
|
end_temp_read(temp_read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
else if (string_match(lexeme, string_litexpr("CUSTOM_ALIAS"))){
|
2017-11-15 23:57:21 +00:00
|
|
|
Temp_Read temp_read = begin_temp_read(reader);
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 found_start_pos = false;
|
2017-11-15 23:57:21 +00:00
|
|
|
for (int32_t R = 0; R < 3; ++R){
|
2019-09-04 05:31:35 +00:00
|
|
|
Token p_token = prev_token(reader);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (p_token.type == CPP_PP_DEFINE){
|
|
|
|
if (R == 2){
|
|
|
|
found_start_pos = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p_token.type == 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_start_pos){
|
|
|
|
end_temp_read(temp_read);
|
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
if (!parse_alias(arena, entry_arrays, reader)){
|
2017-11-15 23:57:21 +00:00
|
|
|
end_temp_read(temp_read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token.type == 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cpp_free_token_array(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_file(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *name_, int32_t len){
|
|
|
|
char *name = unencode(arena, name_, len);
|
2017-11-15 23:57:21 +00:00
|
|
|
if (name == 0){
|
|
|
|
if (sizeof(*name_) == 2){
|
2017-11-22 19:04:14 +00:00
|
|
|
fprintf(stdout, "warning: could not unencode file name %ls - file skipped\n", (wchar_t*)name_);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-11-22 19:04:14 +00:00
|
|
|
fprintf(stdout, "warning: could not unencode file name %s - file skipped\n", (char*)name_);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char text = file_dump(arena, name);
|
|
|
|
parse_text(arena, entry_arrays, name, text);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_files_by_pattern(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *pattern, b32 recursive){
|
|
|
|
Cross_Platform_File_List list = get_file_list(arena, pattern, filter_all);
|
2017-11-15 23:57:21 +00:00
|
|
|
for (int32_t i = 0; i < list.count; ++i){
|
2018-03-03 07:46:44 +00:00
|
|
|
Cross_Platform_File_Info *info = &list.info[i];
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_Any info_name = SCany(info->name, info->len);
|
|
|
|
Temp_Memory temp = begin_temp(arena);
|
|
|
|
String_Const_char info_name_ascii = string_char_from_any(arena, info_name);
|
|
|
|
b32 is_generated = string_match(info_name_ascii, string_litexpr("4coder_generated"));
|
|
|
|
end_temp(temp);
|
|
|
|
|
|
|
|
if (info->is_folder && is_generated){
|
2017-11-18 22:40:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-09 23:19:32 +00:00
|
|
|
if (!recursive && info->is_folder){
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-18 22:40:10 +00:00
|
|
|
|
2018-03-09 23:19:32 +00:00
|
|
|
int32_t full_name_len = list.path_length + 1 + info->len;
|
|
|
|
if (info->is_folder){
|
|
|
|
full_name_len += 2;
|
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
Filename_Character *full_name = push_array(arena, Filename_Character, full_name_len + 1);
|
2017-11-15 23:57:21 +00:00
|
|
|
|
|
|
|
if (full_name == 0){
|
|
|
|
fprintf(stdout, "fatal error: not enough memory to recurse to sub directory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-03-09 23:19:32 +00:00
|
|
|
memmove(full_name, list.path_name, list.path_length*sizeof(*full_name));
|
|
|
|
full_name[list.path_length] = SLASH;
|
|
|
|
memmove(full_name + list.path_length + 1, info->name, info->len*sizeof(*full_name));
|
2017-11-15 23:57:21 +00:00
|
|
|
full_name[full_name_len] = 0;
|
|
|
|
|
|
|
|
if (!info->is_folder){
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_file(arena, entry_arrays, full_name, full_name_len);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
else{
|
2018-03-09 23:19:32 +00:00
|
|
|
full_name[full_name_len - 2] = SLASH;
|
|
|
|
full_name[full_name_len - 1] = '*';
|
2019-06-01 23:58:28 +00:00
|
|
|
parse_files_by_pattern(arena, entry_arrays, full_name, true);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_usage(int argc, char **argv){
|
|
|
|
char *name = "metadata_generator";
|
|
|
|
if (argc >= 1){
|
|
|
|
name = argv[0];
|
|
|
|
}
|
2018-03-09 23:19:32 +00:00
|
|
|
fprintf(stdout, "usage:\n%s [-R] <4coder-root-directory> <input-file-pattern> [<input-file-pattern> ...]\n", name);
|
2017-11-15 23:57:21 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv){
|
2017-11-22 20:05:58 +00:00
|
|
|
if (argc < 3){
|
2017-11-15 23:57:21 +00:00
|
|
|
show_usage(argc, argv);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
b32 recursive = string_match(SCchar(argv[1]), string_litexpr("-R"));
|
2017-11-22 20:05:58 +00:00
|
|
|
if (recursive && argc < 4){
|
2017-11-15 23:57:21 +00:00
|
|
|
show_usage(argc, argv);
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena arena_ = make_arena_malloc(MB(1), 8);
|
|
|
|
Arena *arena = &arena_;
|
2017-11-15 23:57:21 +00:00
|
|
|
|
2017-11-22 20:05:58 +00:00
|
|
|
char *out_directory = argv[2];
|
|
|
|
|
|
|
|
int32_t start_i = 2;
|
2017-11-15 23:57:21 +00:00
|
|
|
if (recursive){
|
2017-11-22 20:05:58 +00:00
|
|
|
start_i = 3;
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Meta_Command_Entry_Arrays entry_arrays = {};
|
2017-11-15 23:57:21 +00:00
|
|
|
for (int32_t i = start_i; i < argc; ++i){
|
2019-06-01 23:58:28 +00:00
|
|
|
Filename_Character *pattern_name = encode(arena, argv[i]);
|
|
|
|
parse_files_by_pattern(arena, &entry_arrays, pattern_name, recursive);
|
2017-11-18 22:40:10 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
umem out_dir_len = cstring_length(out_directory);
|
2017-11-22 20:05:58 +00:00
|
|
|
if (out_directory[0] == '"'){
|
|
|
|
out_directory += 1;
|
|
|
|
out_dir_len -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_char str = SCchar(out_directory, out_dir_len);
|
|
|
|
str = string_skip_chop_whitespace(str);
|
2017-11-22 20:05:58 +00:00
|
|
|
out_directory = str.str;
|
|
|
|
out_dir_len = str.size;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
umem len = out_dir_len + 1 + sizeof(COMMAND_METADATA_OUT) - 1;
|
2017-11-22 20:05:58 +00:00
|
|
|
char *out_file_name = (char*)malloc(len + 1);
|
|
|
|
memcpy(out_file_name, out_directory, out_dir_len);
|
|
|
|
memcpy(out_file_name + out_dir_len, "/", 1);
|
|
|
|
memcpy(out_file_name + out_dir_len + 1, COMMAND_METADATA_OUT, sizeof(COMMAND_METADATA_OUT));
|
|
|
|
|
|
|
|
FILE *out = fopen(out_file_name, "wb");
|
2017-11-18 22:40:10 +00:00
|
|
|
|
|
|
|
if (out != 0){
|
2017-11-27 20:13:42 +00:00
|
|
|
int32_t entry_count = entry_arrays.doc_string_count;
|
2019-06-01 23:58:28 +00:00
|
|
|
Meta_Command_Entry **entries = get_sorted_meta_commands(arena, entry_arrays.first_doc_string, entry_count);
|
2017-11-27 20:13:42 +00:00
|
|
|
|
2018-06-22 20:59:21 +00:00
|
|
|
fprintf(out, "#if !defined(META_PASS)\n");
|
2017-11-18 22:40:10 +00:00
|
|
|
fprintf(out, "#define command_id(c) (fcoder_metacmd_ID_##c)\n");
|
|
|
|
fprintf(out, "#define command_metadata(c) (&fcoder_metacmd_table[command_id(c)])\n");
|
|
|
|
fprintf(out, "#define command_metadata_by_id(id) (&fcoder_metacmd_table[id])\n");
|
|
|
|
fprintf(out, "#define command_one_past_last_id %d\n", entry_arrays.doc_string_count);
|
|
|
|
fprintf(out, "#if defined(CUSTOM_COMMAND_SIG)\n");
|
|
|
|
fprintf(out, "#define PROC_LINKS(x,y) x\n");
|
|
|
|
fprintf(out, "#else\n");
|
|
|
|
fprintf(out, "#define PROC_LINKS(x,y) y\n");
|
|
|
|
fprintf(out, "#endif\n");
|
|
|
|
|
|
|
|
fprintf(out, "#if defined(CUSTOM_COMMAND_SIG)\n");
|
2017-11-27 20:13:42 +00:00
|
|
|
for (int32_t i = 0; i < entry_count; ++i){
|
|
|
|
Meta_Command_Entry *entry = entries[i];
|
2017-11-18 22:40:10 +00:00
|
|
|
fprintf(out, "CUSTOM_COMMAND_SIG(%.*s);\n", str_to_l_c(entry->name));
|
|
|
|
}
|
|
|
|
fprintf(out, "#endif\n");
|
|
|
|
|
|
|
|
fprintf(out,
|
|
|
|
"struct Command_Metadata{\n"
|
|
|
|
"PROC_LINKS(Custom_Command_Function, void) *proc;\n"
|
|
|
|
"char *name;\n"
|
|
|
|
"int32_t name_len;\n"
|
|
|
|
"char *description;\n"
|
|
|
|
"int32_t description_len;\n"
|
|
|
|
"char *source_name;\n"
|
|
|
|
"int32_t source_name_len;\n"
|
|
|
|
"int32_t line_number;\n"
|
|
|
|
"};\n");
|
|
|
|
|
|
|
|
fprintf(out,
|
|
|
|
"static Command_Metadata fcoder_metacmd_table[%d] = {\n",
|
|
|
|
entry_arrays.doc_string_count);
|
2017-11-27 20:13:42 +00:00
|
|
|
for (int32_t i = 0; i < entry_count; ++i){
|
|
|
|
Meta_Command_Entry *entry = entries[i];
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Temp_Memory temp = begin_temp(arena);
|
2017-11-18 22:40:10 +00:00
|
|
|
|
|
|
|
// HACK(allen): We could just get these at the HEAD END of the process,
|
|
|
|
// then we only have to do it once per file, and pass the lengths through.
|
2019-06-01 23:58:28 +00:00
|
|
|
//umem source_name_len = cstring_length(entry->source_name);
|
|
|
|
String_Const_char source_name = SCchar(entry->source_name);
|
|
|
|
String_Const_char printable = string_replace(arena, source_name,
|
|
|
|
SCchar("\\"), SCchar("\\\\"),
|
|
|
|
StringFill_NullTerminate);
|
2017-11-18 22:40:10 +00:00
|
|
|
|
|
|
|
fprintf(out,
|
|
|
|
"{ PROC_LINKS(%.*s, 0), \"%.*s\", %d, \"%.*s\", %d, \"%s\", %d, %d },\n",
|
|
|
|
str_to_l_c(entry->name),
|
2019-06-01 23:58:28 +00:00
|
|
|
str_to_l_c(entry->name), (i32)entry->name.size,
|
|
|
|
str_to_l_c(entry->docstring.doc), (i32)entry->docstring.doc.size,
|
|
|
|
printable.str, (i32)source_name.size, entry->line_number);
|
|
|
|
end_temp(temp);
|
2017-11-18 22:40:10 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "};\n");
|
|
|
|
|
|
|
|
int32_t id = 0;
|
2017-11-27 20:13:42 +00:00
|
|
|
for (int32_t i = 0; i < entry_count; ++i){
|
|
|
|
Meta_Command_Entry *entry = entries[i];
|
|
|
|
|
2017-11-18 22:40:10 +00:00
|
|
|
fprintf(out, "static int32_t fcoder_metacmd_ID_%.*s = %d;\n",
|
|
|
|
str_to_l_c(entry->name), id);
|
|
|
|
++id;
|
|
|
|
}
|
2018-06-15 20:10:49 +00:00
|
|
|
|
|
|
|
fprintf(out, "#endif\n");
|
|
|
|
|
|
|
|
fclose(out);
|
2017-11-18 22:40:10 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-11-22 20:05:58 +00:00
|
|
|
fprintf(stdout, "fatal error: could not open output file %s%s\n", out_directory, COMMAND_METADATA_OUT);
|
2017-11-15 23:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|