collapsed everything into Item_Node; made the item parsing functions more similar

master
Allen Webster 2016-09-02 17:41:56 -04:00
parent 8b00c86db1
commit 56b04115b3
3 changed files with 91 additions and 85 deletions

View File

@ -41,8 +41,14 @@ begin_file_out(Out_Context *out_context, char *filename, String *out){
} }
static void static void
end_file_out(Out_Context out_context){ dump_file_out(Out_Context out_context){
fwrite(out_context.str->str, 1, out_context.str->size, out_context.file); fwrite(out_context.str->str, 1, out_context.str->size, out_context.file);
out_context.str->size = 0;
}
static void
end_file_out(Out_Context out_context){
dump_file_out(out_context);
fclose(out_context.file); fclose(out_context.file);
} }
@ -342,14 +348,14 @@ typedef struct Documentation{
String *see_also; String *see_also;
} Documentation; } Documentation;
enum{ typedef enum Item_Type{
Item_Null, Item_Null,
Item_Function, Item_Function,
Item_Macro, Item_Macro,
Item_Typedef, Item_Typedef,
Item_Struct, Item_Struct,
Item_Union, Item_Union,
}; } Item_Type;
typedef struct Item_Node{ typedef struct Item_Node{
int32_t t; int32_t t;
@ -377,18 +383,14 @@ typedef struct Function_Set{
Item_Node *funcs; Item_Node *funcs;
} Function_Set; } Function_Set;
typedef struct Typedef_Set{ typedef struct Item_Set{
Item_Node *items; Item_Node *items;
} Typedef_Set; } Item_Set;
typedef struct Struct_Set{ typedef struct Struct_Set{
Item_Node *structs; Item_Node *structs;
} Struct_Set; } Struct_Set;
typedef struct Enum_Set{
Item_Node *items;
} Enum_Set;
static Item_Node null_item_node = {0}; static Item_Node null_item_node = {0};
static String static String
@ -1097,17 +1099,75 @@ print_see_also(FILE *file, Documentation *doc){
} }
} }
static int32_t
parse_typedef(char *data, Cpp_Token *tokens, int32_t count,
Cpp_Token **token_ptr, Item_Set item_set, int32_t item_index){
int32_t result = false;
Cpp_Token *token = *token_ptr;
int32_t i = (int32_t)(token - tokens);
String doc_string = {0};
get_type_doc_string(data, tokens, i, &doc_string);
int32_t start_i = i;
Cpp_Token *start_token = token;
for (; i < count; ++i, ++token){
if (token->type == CPP_TOKEN_SEMICOLON){
break;
}
}
if (i < count){
Cpp_Token *token_j = token;
for (int32_t j = i; j > start_i; --j, --token_j){
if (token_j->type == CPP_TOKEN_IDENTIFIER){
break;
}
}
String name = make_string(data + token_j->start, token_j->size);
name = skip_chop_whitespace(name);
int32_t type_start = start_token->start + start_token->size;
int32_t type_end = token_j->start;
String type = make_string(data + type_start, type_end - type_start);
type = skip_chop_whitespace(type);
result = true;
item_set.items[item_index].type = type;
item_set.items[item_index].name = name;
item_set.items[item_index].doc_string = doc_string;
}
*token_ptr = token;
return(result);
}
static int32_t static int32_t
parse_enum(Partition *part, char *data, parse_enum(Partition *part, char *data,
Cpp_Token *tokens, int32_t count, Cpp_Token *tokens, int32_t count,
Cpp_Token **token_ptr, int32_t start_i, Cpp_Token **token_ptr,
Enum_Set flag_set, int32_t flag_index){ Item_Set item_set, int32_t item_index){
int32_t result = false; int32_t result = false;
Cpp_Token *token = *token_ptr; Cpp_Token *token = *token_ptr;
int32_t i = (int32_t)(token - tokens); int32_t i = (int32_t)(token - tokens);
String doc_string = {0};
get_type_doc_string(data, tokens, i, &doc_string);
int32_t start_i = i;
for (; i < count; ++i, ++token){
if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){
break;
}
}
if (i < count){ if (i < count){
Cpp_Token *token_j = token; Cpp_Token *token_j = token;
@ -1197,8 +1257,9 @@ parse_enum(Partition *part, char *data,
++token; ++token;
result = true; result = true;
flag_set.items[flag_index].name = name; item_set.items[item_index].name = name;
flag_set.items[flag_index].first_child = first_member; item_set.items[item_index].doc_string = doc_string;
item_set.items[item_index].first_child = first_member;
} }
} }
} }
@ -2022,10 +2083,10 @@ generate_custom_headers(){
// NOTE(allen): Documentation // NOTE(allen): Documentation
{ {
Typedef_Set typedef_set = {0}; Item_Set typedef_set = {0};
Struct_Set struct_set = {0}; Struct_Set struct_set = {0};
Enum_Set flag_set = {0}; Item_Set flag_set = {0};
Enum_Set enum_set = {0}; Item_Set enum_set = {0};
String type_code[1]; String type_code[1];
type_code[0] = file_dump("4coder_os_types.h"); type_code[0] = file_dump("4coder_os_types.h");
@ -2127,40 +2188,11 @@ generate_custom_headers(){
switch (match_index){ switch (match_index){
case 0: //typedef case 0: //typedef
{ {
String doc_string = {0}; if (parse_typedef(data, tokens, count, &token,
get_type_doc_string(data, tokens, i, &doc_string); typedef_set, typedef_index)){
int32_t start_i = i;
Cpp_Token *start_token = token;
for (; i < count; ++i, ++token){
if (token->type == CPP_TOKEN_SEMICOLON){
break;
}
}
if (i < count){
Cpp_Token *token_j = token;
for (int32_t j = i; j > start_i; --j, --token_j){
if (token_j->type == CPP_TOKEN_IDENTIFIER){
break;
}
}
String name = make_string(data + token_j->start, token_j->size);
name = skip_chop_whitespace(name);
int32_t type_start = start_token->start + start_token->size;
int32_t type_end = token_j->start;
String type = make_string(data + type_start, type_end - type_start);
type = skip_chop_whitespace(type);
typedef_set.items[typedef_index].type = type;
typedef_set.items[typedef_index].name = name;
typedef_set.items[typedef_index].doc_string = doc_string;
++typedef_index; ++typedef_index;
} }
i = (int32_t)(token - tokens);
}break; }break;
case 1: case 2: //struct/union case 1: case 2: //struct/union
@ -2175,22 +2207,9 @@ generate_custom_headers(){
case 3: //ENUM case 3: //ENUM
{ {
String doc_string = {0};
get_type_doc_string(data, tokens, i, &doc_string);
int32_t start_i = i;
for (; i < count; ++i, ++token){
if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){
break;
}
}
if (parse_enum(part, data, if (parse_enum(part, data,
tokens, count, tokens, count, &token,
&token, start_i,
enum_set, enum_index)){ enum_set, enum_index)){
enum_set.items[enum_index].doc_string = doc_string;
++enum_index; ++enum_index;
} }
i = (int32_t)(token - tokens); i = (int32_t)(token - tokens);
@ -2198,22 +2217,9 @@ generate_custom_headers(){
case 4: //FLAGENUM case 4: //FLAGENUM
{ {
String doc_string = {0};
get_type_doc_string(data, tokens, i, &doc_string);
int32_t start_i = i;
for (; i < count; ++i, ++token){
if (token->type == CPP_TOKEN_PARENTHESE_CLOSE){
break;
}
}
if (parse_enum(part, data, if (parse_enum(part, data,
tokens, count, tokens, count, &token,
&token, start_i,
flag_set, flag_index)){ flag_set, flag_index)){
flag_set.items[flag_index].doc_string = doc_string;
++flag_index; ++flag_index;
} }
i = (int32_t)(token - tokens); i = (int32_t)(token - tokens);

View File

@ -1,4 +1,4 @@
Distribution Date: 1.9.2016 (dd.mm.yyyy) Distribution Date: 2.9.2016 (dd.mm.yyyy)
Thank you for contributing to the 4coder project! Thank you for contributing to the 4coder project!

View File

@ -83,14 +83,6 @@
; BEFORE I SHIP ; BEFORE I SHIP
; ;
; [X] flag in create buffer to prevent making new files
; [X] locking to a view for next position jumping
; [X] break down the build system and get away from the preproc hack
; [X] exit command
; [X] full screen option
; [X] add to APIs
; [X] try to make win32 version better
;
; [] tokens in the custom API ; [] tokens in the custom API
; [] auto indent on the custom side ; [] auto indent on the custom side
; [] expose dirty flags ; [] expose dirty flags
@ -103,6 +95,7 @@
; [] mouse down/up distinction ; [] mouse down/up distinction
; [] hook on exit ; [] hook on exit
; [] read only files ; [] read only files
; [] occasionally missing the (!) mark on files on windows
; ;
; TODOS ; TODOS
@ -133,6 +126,13 @@
; [X] error parsing and jump to error ; [X] error parsing and jump to error
; [X] manipulate scroll target API ; [X] manipulate scroll target API
; [X] generate documentation for custom API ; [X] generate documentation for custom API
; [X] flag in create buffer to prevent making new files
; [X] locking to a view for next position jumping
; [X] break down the build system and get away from the preproc hack
; [X] exit command
; [X] full screen option
; [X] add to APIs
; [X] try to make win32 version better
; ;
; [] support full length unicode file names ; [] support full length unicode file names
; [] switch based word complete ; [] switch based word complete