summaryrefslogtreecommitdiff
path: root/symbol_analyzer
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-07-13 21:58:18 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-07-13 21:58:18 +0530
commitf8c0dc54e36cc201c657aa12e5a22029b092e1bc (patch)
treea0dd1a42c9681be98a7508c128db0dacacefc2e7 /symbol_analyzer
parent2e8b78ab0ef01eaacd8094ff839ac93b4451e9c3 (diff)
restructed all the files + uci done now
also broke the symbol analyser in the process, i didn't help much, i had to pull out the pen & paper, but it made a cool graph never the less multithreading was a pain! but it got it in the end fixed the structs naming convention, if it's used outside by other files, it's typedeffed, otherwise it's not fixed the recursive imports issued i had in go_args*, where i was casting it to void* in uci to make it work now response.c doesn't deal with ipc, really happy with that change now every single thing has its own responsibility
Diffstat (limited to 'symbol_analyzer')
-rw-r--r--symbol_analyzer/analysis.js1
-rw-r--r--symbol_analyzer/index.html137
-rw-r--r--symbol_analyzer/main.py110
-rw-r--r--symbol_analyzer/parser.py29
4 files changed, 252 insertions, 25 deletions
diff --git a/symbol_analyzer/analysis.js b/symbol_analyzer/analysis.js
new file mode 100644
index 0000000..3181318
--- /dev/null
+++ b/symbol_analyzer/analysis.js
@@ -0,0 +1 @@
+data = [{"name": "stdbool.h", "imports": [], "symbols": ["bool"], "unused": ["bool"], "used": []}, {"name": "uci.h", "imports": ["stdint.h", "mman.h", "stdatomic.h", "state.h", "bitboard.h", "ipc.h", "stdbool.h", "stdlib.h", "inttypes.h", "fen.h", "ints.h"], "symbols": ["uci", "int", "char"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "OPTION_COMBO", "WHITE_QUEEN", "engine_message", "engine_messages", "option_setting_button", "OPTION_STRING", "int", "should_continue", "go_args", "uci_state", "WHITE_BISHOP", "option_setting_spin", "option_setting_t", "option_combo_setting_t", "comm_moves", "comms", "BLACK_ROOK", "option_setting_string", "OPTION_SPIN", "WHITE_ROOK", "OPTION_CHECK", "MESSAGE_READ", "option_spin_setting_t", "PIECE_TYPE_COUNT", "assert_valid_position", "combo_t", "position_starting", "occupied_by", "WHITE_KING", "comm_moves_init", "str_t", "option_setting_check", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "uci_move", "OPTION_BUTTON", "BLACK_BISHOP", "BLACK_TURN", "char", "position_t", "WHITE_KNIGHT", "add_comm_move", "MESSAGE_FILLED", "MESSAGE_PROCESSED", "spin_t", "bool", "fen_load", "WHITE_PAWN", "option_setting_combo", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN"], "used": ["uci"]}, {"name": "ints.h", "imports": ["stdint.h", "inttypes.h"], "symbols": ["int", "char"], "unused": ["int", "char"], "used": []}, {"name": "bitboard.h", "imports": ["stdint.h", "stdbool.h", "inttypes.h", "ints.h"], "symbols": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "WHITE_QUEEN", "int", "WHITE_BISHOP", "BLACK_ROOK", "WHITE_ROOK", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "WHITE_KING", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "position_t", "char", "WHITE_KNIGHT", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN"], "unused": ["WHITE_SHORT_CASTLE", "BLACK_TURN", "BLACK_LONG_CASTLE", "PIECE_TYPE_COUNT", "WHITE_LONG_CASTLE", "char", "BLACK_SHORT_CASTLE", "WHITE_TURN", "int"], "used": ["blacks", "WHITE_QUEEN", "WHITE_BISHOP", "BLACK_ROOK", "WHITE_ROOK", "assert_valid_position", "position_starting", "occupied_by", "WHITE_KING", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "BLACK_BISHOP", "position_t", "WHITE_KNIGHT", "bool", "WHITE_PAWN", "BLACK_KING", "BLACK_PAWN", "BLACK_QUEEN"]}, {"name": "ipc.h", "imports": ["stdint.h", "mman.h", "stdatomic.h", "state.h", "bitboard.h", "stdbool.h", "stdlib.h", "inttypes.h", "fen.h", "ints.h"], "symbols": ["MESSAGE_READ", "go_args", "add_comm_move", "should_continue", "char", "MESSAGE_FILLED", "MESSAGE_PROCESSED", "engine_message", "engine_messages", "comm_moves_init", "comm_moves", "comms", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "OPTION_COMBO", "engine_message", "WHITE_QUEEN", "engine_messages", "option_setting_button", "int", "go_args", "uci_state", "WHITE_BISHOP", "option_setting_spin", "option_setting_t", "option_combo_setting_t", "comms", "BLACK_ROOK", "option_setting_string", "OPTION_SPIN", "MESSAGE_READ", "OPTION_CHECK", "WHITE_ROOK", "option_spin_setting_t", "PIECE_TYPE_COUNT", "assert_valid_position", "combo_t", "position_starting", "occupied_by", "WHITE_KING", "str_t", "option_setting_check", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "uci_move", "OPTION_BUTTON", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "char", "MESSAGE_FILLED", "MESSAGE_PROCESSED", "BLACK_TURN", "position_t", "WHITE_KNIGHT", "spin_t", "fen_load", "WHITE_PAWN", "option_setting_combo", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "OPTION_STRING", "BLACK_QUEEN"], "used": ["should_continue", "add_comm_move", "bool", "comm_moves_init", "comm_moves"]}, {"name": "fen.h", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "inttypes.h", "ints.h"], "symbols": ["fen_load", "int", "char"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_ROOK", "PIECE_TYPE_COUNT", "assert_valid_position", "WHITE_LONG_CASTLE", "blacks", "WHITE_QUEEN", "position_starting", "occupied_by", "WHITE_KING", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "int", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "WHITE_BISHOP", "BLACK_BISHOP", "BLACK_TURN", "char", "position_t", "WHITE_KNIGHT", "fen_load", "bool", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_ROOK", "BLACK_QUEEN"], "used": []}, {"name": "state.h", "imports": ["stdint.h", "stdatomic.h", "bitboard.h", "stdbool.h", "inttypes.h", "fen.h", "ints.h"], "symbols": ["OPTION_COMBO", "option_setting_button", "int", "uci_state", "option_setting_spin", "option_setting_t", "option_combo_setting_t", "option_setting_string", "OPTION_SPIN", "OPTION_CHECK", "option_spin_setting_t", "combo_t", "str_t", "option_setting_check", "uci_move", "OPTION_BUTTON", "char", "spin_t", "option_setting_combo", "OPTION_STRING"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "OPTION_COMBO", "WHITE_QUEEN", "int", "uci_state", "WHITE_BISHOP", "option_combo_setting_t", "BLACK_ROOK", "OPTION_SPIN", "WHITE_ROOK", "OPTION_CHECK", "option_spin_setting_t", "PIECE_TYPE_COUNT", "assert_valid_position", "combo_t", "position_starting", "occupied_by", "WHITE_KING", "str_t", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "uci_move", "OPTION_BUTTON", "BLACK_BISHOP", "BLACK_TURN", "char", "position_t", "WHITE_KNIGHT", "fen_load", "spin_t", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "OPTION_STRING", "BLACK_QUEEN"], "used": ["option_setting_spin", "bool", "option_setting_t", "option_setting_combo", "option_setting_check", "option_setting_button", "option_setting_string"]}, {"name": "response.h", "imports": ["stdint.h", "mman.h", "stdatomic.h", "state.h", "bitboard.h", "ipc.h", "stdbool.h", "stdlib.h", "inttypes.h", "fen.h", "command.h", "ints.h"], "symbols": ["handle_idle", "handle_halt", "char", "handle_initial", "handle_ping", "handle_sync", "handle_active", "handle_uci", "int"], "unused": ["WHITE_LONG_CASTLE", "WHITE_QUEEN", "option_setting_button", "should_continue", "ucicmd_set_root", "uci_state", "option_combo_setting_t", "comm_moves", "ucicmd", "comms", "OPTION_SPIN", "MESSAGE_READ", "option_spin_setting_t", "combo_t", "occupied_by", "WHITE_KING", "option_setting_check", "print_bitboard", "check_valid_position", "whites", "BLACK_TURN", "add_comm_move", "WHITE_KNIGHT", "MESSAGE_FILLED", "bool", "fen_load", "option_setting_combo", "BLACK_KING", "BLACK_PAWN", "BLACK_QUEEN", "WHITE_SHORT_CASTLE", "blacks", "OPTION_COMBO", "engine_message", "ucicmd_append_arg", "engine_messages", "ucicmd_add", "int", "go_args", "WHITE_BISHOP", "option_setting_spin", "option_setting_t", "BLACK_ROOK", "option_setting_string", "OPTION_CHECK", "WHITE_ROOK", "PIECE_TYPE_COUNT", "assert_valid_position", "ucicmd_get_arg", "position_starting", "comm_moves_init", "str_t", "WHITE_TURN", "ucicmd_deinit", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "uci_move", "OPTION_BUTTON", "BLACK_BISHOP", "char", "position_t", "MESSAGE_PROCESSED", "spin_t", "WHITE_PAWN", "BLACK_SHORT_CASTLE", "OPTION_STRING", "ucicmd_init"], "used": ["handle_idle", "handle_halt", "handle_initial", "handle_ping", "handle_sync", "handle_uci", "handle_active"]}, {"name": "command.h", "imports": [], "symbols": ["ucicmd_deinit", "ucicmd_set_root", "ucicmd_get_arg", "char", "ucicmd_append_arg", "ucicmd", "ucicmd_add", "ucicmd_init", "int"], "unused": ["int"], "used": ["ucicmd_deinit", "ucicmd_set_root", "ucicmd_get_arg", "char", "ucicmd_append_arg", "ucicmd", "ucicmd_add", "ucicmd_init"]}, {"name": "moves.h", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "inttypes.h", "ints.h"], "symbols": ["MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "get_queen_moves", "get_rook_moves", "MOVE_PROMOTE_B", "moves_t", "int", "__forloop_rook_moves_gen", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "MOVE_LONG_CASTLE", "position_make_move", "MOVE_CAPTURE", "add_move_params", "MOVE_CHECK", "MOVE_PROMOTE_N", "get_knight_moves", "move_t", "get_pawn_moves", "char", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "get_moves", "moves_empty", "_add_move", "moves_init_wcapacity", "add_move"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "MOVE_PROMOTE_B", "int", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "BLACK_ROOK", "MOVE_LONG_CASTLE", "MOVE_CAPTURE", "WHITE_ROOK", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "MOVE_PROMOTE_N", "check_valid_position", "whites", "BLACK_KNIGHT", "move_t", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "char", "position_t", "WHITE_KNIGHT", "bool", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN"], "used": ["add_move", "get_pawn_moves", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "get_queen_moves", "get_moves", "get_rook_moves", "get_king_moves", "position_make_move", "moves_empty", "_add_move", "moves_init_wcapacity", "moves_t", "get_knight_moves", "__forloop_rook_moves_gen"]}, {"name": "fen.c", "imports": ["stdint.h", "assert.h", "bitboard.h", "stdbool.h", "inttypes.h", "fen.h", "ints.h"], "symbols": ["get_castling", "get_piece_enum_item", "letters", "char", "fen_load", "get_turn", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "WHITE_QUEEN", "WHITE_BISHOP", "BLACK_ROOK", "WHITE_ROOK", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "WHITE_KING", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "char", "position_t", "WHITE_KNIGHT", "fen_load", "bool", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN"], "used": ["get_castling", "get_piece_enum_item", "letters", "get_turn", "int"]}, {"name": "bitboard.c", "imports": ["stdint.h", "assert.h", "stdio.h", "bitboard.h", "stdbool.h", "inttypes.h", "ints.h"], "symbols": ["assert_valid_position", "char", "position_starting", "print_bitboard", "check_valid_position", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "WHITE_QUEEN", "int", "WHITE_BISHOP", "BLACK_ROOK", "WHITE_ROOK", "PIECE_TYPE_COUNT", "occupied_by", "WHITE_KING", "WHITE_TURN", "whites", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "char", "WHITE_KNIGHT", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN"], "used": ["assert_valid_position", "bool", "position_t", "position_starting", "print_bitboard", "check_valid_position"]}, {"name": "ipc.c", "imports": ["stdint.h", "mman.h", "assert.h", "stdatomic.h", "state.h", "bitboard.c", "stdio.h", "bitboard.h", "ipc.h", "stdbool.h", "stdlib.h", "inttypes.h", "fen.h", "fen.c", "ints.h"], "symbols": ["should_continue", "add_comm_move", "return", "char", "if", "comm_moves_init", "realloc", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "OPTION_COMBO", "WHITE_QUEEN", "engine_message", "engine_messages", "option_setting_button", "go_args", "uci_state", "WHITE_BISHOP", "option_setting_spin", "option_setting_t", "option_combo_setting_t", "comms", "BLACK_ROOK", "option_setting_string", "OPTION_SPIN", "WHITE_ROOK", "OPTION_CHECK", "MESSAGE_READ", "option_spin_setting_t", "assert_valid_position", "PIECE_TYPE_COUNT", "get_piece_enum_item", "letters", "combo_t", "position_starting", "occupied_by", "WHITE_KING", "str_t", "option_setting_check", "print_bitboard", "WHITE_TURN", "check_valid_position", "get_turn", "whites", "get_castling", "BLACK_KNIGHT", "uci_move", "OPTION_BUTTON", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "char", "BLACK_TURN", "position_t", "WHITE_KNIGHT", "MESSAGE_FILLED", "MESSAGE_PROCESSED", "spin_t", "fen_load", "WHITE_PAWN", "option_setting_combo", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "OPTION_STRING", "BLACK_QUEEN"], "used": ["should_continue", "add_comm_move", "return", "bool", "if", "comm_moves_init", "comm_moves", "realloc", "int"]}, {"name": "uci.c", "imports": ["unistd.h", "assert.h", "stdio.h", "ipc.h", "command.c", "stdbool.h", "fcntl.h", "inttypes.h", "mman.h", "response.h", "stdatomic.h", "uci.h", "stdlib.h", "string.h", "command.h", "stdint.h", "state.c", "state.h", "bitboard.h", "response.c", "fen.h", "ints.h"], "symbols": ["uci", "load_from_message", "int", "char"], "unused": ["WHITE_LONG_CASTLE", "atoi", "WHITE_QUEEN", "STATE_IDLE", "option_setting_button", "should_continue", "ucicmd_set_root", "uci_state", "print_setting", "is_valid_cmd", "STATE_INITIAL", "option_combo_setting_t", "STATE_SYNC", "handle_sync", "comm_moves", "printf", "ucicmd", "comms", "free", "handle_active", "OPTION_SPIN", "MESSAGE_READ", "option_spin_setting_t", "handle_halt", "sizeof", "combo_t", "occupied_by", "test_ucicmd", "WHITE_KING", "option_setting_check", "print_bitboard", "check_valid_position", "while", "whites", "BLACK_TURN", "add_comm_move", "bool", "MESSAGE_FILLED", "WHITE_KNIGHT", "fen_load", "option_setting_combo", "BLACK_KING", "BLACK_PAWN", "BLACK_QUEEN", "WHITE_SHORT_CASTLE", "blacks", "OPTION_COMBO", "engine_message", "ucicmd_append_arg", "engine_messages", "handle_ping", "realloc", "assert", "ucicmd_add", "int", "go_args", "WHITE_BISHOP", "strcmp", "option_setting_spin", "apply_option", "stpncpy", "option_setting_t", "BLACK_ROOK", "atomic_store", "option_setting_string", "STATE_PING", "handle_idle", "WHITE_ROOK", "OPTION_CHECK", "malloc", "PIECE_TYPE_COUNT", "assert_valid_position", "ucicmd_get_arg", "if", "handle_initial", "position_starting", "comm_moves_init", "str_t", "WHITE_TURN", "ucicmd_deinit", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "OPTION_BUTTON", "uci_move", "STATE_ACTIVE", "char", "MESSAGE_PROCESSED", "STATE_HALT", "for", "position_t", "spin_t", "test_invalid_cmd_ucicmd", "WHITE_PAWN", "BLACK_SHORT_CASTLE", "OPTION_STRING", "ucicmd_init", "handle_uci"], "used": ["uci", "load_from_message"]}, {"name": "engine.c", "imports": ["unistd.h", "assert.h", "stdio.h", "knight.c", "ipc.h", "stdbool.h", "fcntl.h", "pthread.h", "inttypes.h", "moves.c", "mman.h", "stdatomic.h", "uci.h", "stdlib.h", "moves.h", "string.h", "stdint.h", "state.h", "bitboard.h", "fen.h", "vec.c", "ints.h", "rook.c", "pawn.c", "bishop.c", "king.c", "queen.c"], "symbols": ["thread_args", "decrease_threads", "engine_message", "realloc", "main", "int", "send_stop_signal", "printf", "pthread_cancel", "free", "atomic_store", "malloc", "engine_thread", "if", "threads", "comm_moves_init", "all_stopped", "while", "add_comm_move", "pthread_create", "set_threads", "for", "char", "increase_threads"], "unused": ["MOVE_PROMOTE_R", "get_queen_moves", "moves_t", "option_setting_button", "min", "comm_moves", "test_black_king_corners", "combo_t", "occupied_by", "WHITE_KING", "MOVE_CHECK", "option_setting_check", "MOVE_PROMOTE_N", "BLACK_TURN", "move_t", "MESSAGE_FILLED", "__forloop_bishop_moves_gen", "option_setting_combo", "BLACK_PAWN", "moves_init_wcapacity", "WHITE_SHORT_CASTLE", "OPTION_COMBO", "assert", "go_args", "option_setting_t", "get_king_moves", "find_piece_on_square", "BLACK_ROOK", "add_promote_moves", "MOVE_CAPTURE", "WHITE_ROOK", "position_starting", "threads", "get_knight_moves", "BLACK_KNIGHT", "test_white_king_corners", "BLACK_BISHOP", "OPTION_BUTTON", "char", "MESSAGE_PROCESSED", "get_bishop_moves", "spin_t", "moves_empty", "add_move_params", "add_move", "WHITE_LONG_CASTLE", "WHITE_QUEEN", "get_rook_moves", "should_continue", "uci_state", "MOVE_PROMOTE_Q", "option_combo_setting_t", "position_make_move", "MESSAGE_READ", "OPTION_SPIN", "option_spin_setting_t", "print_bitboard", "check_valid_position", "whites", "WHITE_KNIGHT", "fen_load", "get_moves", "_add_move", "BLACK_KING", "uci", "BLACK_QUEEN", "thread_args", "blacks", "MOVE_SHORT_CASTLE", "engine_message", "engine_messages", "MOVE_PROMOTE_B", "__forloop_rook_moves_gen", "WHITE_BISHOP", "get_black_pawn_forwardmoves", "option_setting_spin", "MOVE_EN_PASSANT", "get_white_pawn_forwardmoves", "MOVE_LONG_CASTLE", "option_setting_string", "OPTION_CHECK", "PIECE_TYPE_COUNT", "assert_valid_position", "str_t", "WHITE_TURN", "BLACK_LONG_CASTLE", "uci_move", "get_pawn_moves", "moves_init", "position_t", "WHITE_PAWN", "BLACK_SHORT_CASTLE", "OPTION_STRING"], "used": ["decrease_threads", "realloc", "main", "int", "send_stop_signal", "printf", "pthread_cancel", "comms", "free", "atomic_store", "malloc", "engine_thread", "if", "comm_moves_init", "all_stopped", "while", "add_comm_move", "pthread_create", "set_threads", "for", "bool", "increase_threads"]}, {"name": "command.c", "imports": ["assert.h", "stdbool.h", "stdlib.h", "string.h", "command.h"], "symbols": ["ucicmd_deinit", "ucicmd_set_root", "ucicmd_get_arg", "char", "is_valid_cmd", "test_ucicmd", "ucicmd_append_arg", "test_invalid_cmd_ucicmd", "ucicmd_add", "ucicmd_init", "int"], "unused": ["int"], "used": ["ucicmd_deinit", "ucicmd_set_root", "ucicmd_get_arg", "char", "is_valid_cmd", "bool", "test_ucicmd", "ucicmd_append_arg", "test_invalid_cmd_ucicmd", "ucicmd", "ucicmd_add", "ucicmd_init"]}, {"name": "response.c", "imports": ["stdint.h", "mman.h", "assert.h", "response.h", "stdatomic.h", "state.h", "bitboard.h", "ipc.h", "stdbool.h", "stdlib.h", "inttypes.h", "fen.h", "string.h", "command.h", "ints.h"], "symbols": ["atoi", "engine_message", "STATE_IDLE", "handle_ping", "realloc", "assert", "int", "go_args", "strcmp", "print_setting", "apply_option", "STATE_INITIAL", "stpncpy", "STATE_SYNC", "handle_sync", "printf", "free", "atomic_store", "handle_active", "STATE_PING", "handle_idle", "malloc", "handle_halt", "sizeof", "ucicmd_get_arg", "if", "handle_initial", "comm_moves_init", "while", "STATE_ACTIVE", "uci_move", "add_comm_move", "STATE_HALT", "for", "char", "fen_load", "handle_uci"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "OPTION_COMBO", "WHITE_QUEEN", "engine_message", "ucicmd_append_arg", "engine_messages", "ucicmd_add", "option_setting_button", "should_continue", "go_args", "ucicmd_set_root", "uci_state", "WHITE_BISHOP", "option_setting_spin", "option_combo_setting_t", "comm_moves", "ucicmd", "comms", "BLACK_ROOK", "option_setting_string", "OPTION_SPIN", "WHITE_ROOK", "MESSAGE_READ", "OPTION_CHECK", "option_spin_setting_t", "PIECE_TYPE_COUNT", "assert_valid_position", "combo_t", "occupied_by", "position_starting", "WHITE_KING", "str_t", "option_setting_check", "print_bitboard", "WHITE_TURN", "check_valid_position", "whites", "ucicmd_deinit", "BLACK_TURN", "BLACK_KNIGHT", "BLACK_BISHOP", "OPTION_BUTTON", "uci_move", "BLACK_LONG_CASTLE", "MESSAGE_PROCESSED", "MESSAGE_FILLED", "WHITE_KNIGHT", "fen_load", "position_t", "ucicmd_init", "spin_t", "WHITE_PAWN", "option_setting_combo", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "OPTION_STRING", "BLACK_QUEEN"], "used": ["atoi", "STATE_IDLE", "handle_ping", "realloc", "assert", "int", "strcmp", "print_setting", "apply_option", "STATE_INITIAL", "stpncpy", "option_setting_t", "STATE_SYNC", "handle_sync", "printf", "free", "atomic_store", "handle_active", "STATE_PING", "handle_idle", "malloc", "handle_halt", "ucicmd_get_arg", "sizeof", "if", "handle_initial", "comm_moves_init", "while", "add_comm_move", "STATE_ACTIVE", "STATE_HALT", "for", "bool", "char", "handle_uci"]}, {"name": "state.c", "imports": ["stdint.h", "stdatomic.h", "state.h", "bitboard.h", "stdbool.h", "inttypes.h", "fen.h", "string.h", "ints.h"], "symbols": ["option_setting_spin", "char", "option_setting_combo", "option_setting_check", "option_setting_button", "option_setting_string", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "OPTION_COMBO", "WHITE_QUEEN", "int", "uci_state", "WHITE_BISHOP", "option_combo_setting_t", "BLACK_ROOK", "OPTION_SPIN", "WHITE_ROOK", "OPTION_CHECK", "option_spin_setting_t", "PIECE_TYPE_COUNT", "assert_valid_position", "combo_t", "position_starting", "occupied_by", "WHITE_KING", "str_t", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "uci_move", "OPTION_BUTTON", "BLACK_BISHOP", "BLACK_TURN", "char", "position_t", "WHITE_KNIGHT", "bool", "fen_load", "spin_t", "WHITE_PAWN", "BLACK_KING", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "OPTION_STRING", "BLACK_QUEEN"], "used": ["option_setting_spin", "option_setting_t", "option_setting_combo", "option_setting_check", "option_setting_button", "option_setting_string"]}, {"name": "moves.c", "imports": ["stdint.h", "rook.c", "assert.h", "moves.h", "stdio.h", "bitboard.h", "pawn.c", "knight.c", "stdbool.h", "stdlib.h", "bishop.c", "king.c", "inttypes.h", "queen.c", "vec.c", "ints.h"], "symbols": ["char", "get_moves", "find_piece_on_square", "int", "position_make_move"], "unused": ["WHITE_LONG_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "get_queen_moves", "get_rook_moves", "moves_t", "min", "MOVE_PROMOTE_Q", "test_black_king_corners", "occupied_by", "WHITE_KING", "MOVE_CHECK", "print_bitboard", "MOVE_PROMOTE_N", "check_valid_position", "whites", "BLACK_TURN", "move_t", "WHITE_KNIGHT", "bool", "__forloop_bishop_moves_gen", "_add_move", "BLACK_KING", "moves_init_wcapacity", "BLACK_PAWN", "BLACK_QUEEN", "WHITE_SHORT_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "realloc", "MOVE_PROMOTE_B", "assert", "__forloop_rook_moves_gen", "WHITE_BISHOP", "get_black_pawn_forwardmoves", "MOVE_EN_PASSANT", "get_white_pawn_forwardmoves", "get_king_moves", "MOVE_LONG_CASTLE", "BLACK_ROOK", "add_promote_moves", "MOVE_CAPTURE", "WHITE_ROOK", "PIECE_TYPE_COUNT", "assert_valid_position", "if", "position_starting", "WHITE_TURN", "get_knight_moves", "BLACK_KNIGHT", "test_white_king_corners", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "get_pawn_moves", "char", "moves_init", "position_t", "get_bishop_moves", "WHITE_PAWN", "moves_empty", "BLACK_SHORT_CASTLE", "add_move_params", "add_move"], "used": ["find_piece_on_square", "get_moves", "int", "position_make_move"]}, {"name": "king.c", "imports": ["stdint.h", "assert.h", "stdio.h", "bitboard.h", "stdbool.h", "stdlib.h", "moves.h", "inttypes.h", "vec.c", "ints.h"], "symbols": ["test_white_king_corners", "char", "test_black_king_corners", "get_king_moves", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "moves_init_wcapacity", "get_queen_moves", "get_rook_moves", "realloc", "MOVE_PROMOTE_B", "assert", "moves_t", "int", "__forloop_rook_moves_gen", "min", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "if", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "MOVE_PROMOTE_N", "whites", "get_knight_moves", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "char", "position_t", "WHITE_KNIGHT", "get_pawn_moves", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "WHITE_PAWN", "get_moves", "BLACK_KING", "moves_empty", "_add_move", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN", "add_move"], "used": ["test_white_king_corners", "get_king_moves", "test_black_king_corners", "bool"]}, {"name": "knight.c", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "moves.h", "inttypes.h", "ints.h"], "symbols": ["get_knight_moves", "int", "char"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "moves_init_wcapacity", "get_queen_moves", "get_rook_moves", "MOVE_PROMOTE_B", "moves_t", "int", "__forloop_rook_moves_gen", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "whites", "MOVE_PROMOTE_N", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "get_pawn_moves", "char", "position_t", "WHITE_KNIGHT", "bool", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "WHITE_PAWN", "get_moves", "BLACK_KING", "moves_empty", "_add_move", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN", "add_move"], "used": ["get_knight_moves"]}, {"name": "bishop.c", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "moves.h", "inttypes.h", "ints.h"], "symbols": ["__forloop_bishop_moves_gen", "get_bishop_moves", "int", "char"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "moves_init_wcapacity", "get_queen_moves", "get_rook_moves", "MOVE_PROMOTE_B", "moves_t", "int", "__forloop_rook_moves_gen", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "MOVE_PROMOTE_N", "whites", "get_knight_moves", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "get_pawn_moves", "char", "position_t", "WHITE_KNIGHT", "bool", "moves_init", "WHITE_PAWN", "get_moves", "BLACK_KING", "moves_empty", "_add_move", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN", "add_move"], "used": ["__forloop_bishop_moves_gen", "get_bishop_moves"]}, {"name": "pawn.c", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "moves.h", "inttypes.h", "ints.h"], "symbols": ["get_pawn_moves", "get_black_pawn_forwardmoves", "char", "get_white_pawn_forwardmoves", "add_promote_moves", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "moves_init_wcapacity", "get_queen_moves", "get_rook_moves", "MOVE_PROMOTE_B", "moves_t", "int", "__forloop_rook_moves_gen", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "MOVE_PROMOTE_N", "whites", "get_knight_moves", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "char", "position_t", "WHITE_KNIGHT", "bool", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "WHITE_PAWN", "get_moves", "BLACK_KING", "moves_empty", "_add_move", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN", "add_move"], "used": ["get_white_pawn_forwardmoves", "get_pawn_moves", "get_black_pawn_forwardmoves", "add_promote_moves"]}, {"name": "vec.c", "imports": ["stdint.h", "assert.h", "bitboard.h", "stdbool.h", "stdlib.h", "moves.h", "inttypes.h", "ints.h"], "symbols": ["min", "moves_init", "char", "if", "moves_empty", "_add_move", "realloc", "assert", "moves_init_wcapacity", "int"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "get_queen_moves", "get_rook_moves", "MOVE_PROMOTE_B", "__forloop_rook_moves_gen", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "MOVE_PROMOTE_N", "whites", "get_knight_moves", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "get_pawn_moves", "char", "position_t", "WHITE_KNIGHT", "bool", "__forloop_bishop_moves_gen", "BLACK_PAWN", "get_bishop_moves", "WHITE_PAWN", "get_moves", "BLACK_KING", "BLACK_SHORT_CASTLE", "add_move_params", "BLACK_QUEEN", "add_move"], "used": ["min", "moves_init", "if", "moves_empty", "_add_move", "realloc", "assert", "moves_init_wcapacity", "moves_t", "int"]}, {"name": "rook.c", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "moves.h", "inttypes.h", "ints.h"], "symbols": ["__forloop_rook_moves_gen", "get_rook_moves", "int", "char"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "moves_init_wcapacity", "get_queen_moves", "MOVE_PROMOTE_B", "moves_t", "int", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "MOVE_PROMOTE_N", "whites", "get_knight_moves", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "get_pawn_moves", "char", "position_t", "WHITE_KNIGHT", "bool", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "WHITE_PAWN", "get_moves", "BLACK_KING", "moves_empty", "_add_move", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN", "add_move"], "used": ["get_rook_moves", "__forloop_rook_moves_gen"]}, {"name": "queen.c", "imports": ["stdint.h", "bitboard.h", "stdbool.h", "moves.h", "inttypes.h", "ints.h"], "symbols": ["get_queen_moves", "int", "char"], "unused": ["WHITE_SHORT_CASTLE", "WHITE_LONG_CASTLE", "blacks", "MOVE_SHORT_CASTLE", "MOVE_PROMOTE_R", "WHITE_QUEEN", "moves_init_wcapacity", "get_rook_moves", "MOVE_PROMOTE_B", "moves_t", "int", "__forloop_rook_moves_gen", "WHITE_BISHOP", "MOVE_PROMOTE_Q", "MOVE_EN_PASSANT", "get_king_moves", "BLACK_ROOK", "MOVE_LONG_CASTLE", "position_make_move", "WHITE_ROOK", "MOVE_CAPTURE", "PIECE_TYPE_COUNT", "assert_valid_position", "position_starting", "occupied_by", "add_move_params", "WHITE_KING", "MOVE_CHECK", "WHITE_TURN", "print_bitboard", "check_valid_position", "MOVE_PROMOTE_N", "whites", "get_knight_moves", "BLACK_KNIGHT", "BLACK_LONG_CASTLE", "BLACK_BISHOP", "BLACK_TURN", "move_t", "get_pawn_moves", "char", "position_t", "WHITE_KNIGHT", "bool", "moves_init", "__forloop_bishop_moves_gen", "get_bishop_moves", "WHITE_PAWN", "get_moves", "BLACK_KING", "moves_empty", "_add_move", "BLACK_SHORT_CASTLE", "BLACK_PAWN", "BLACK_QUEEN", "add_move"], "used": ["get_queen_moves"]}] \ No newline at end of file
diff --git a/symbol_analyzer/index.html b/symbol_analyzer/index.html
new file mode 100644
index 0000000..3f0257b
--- /dev/null
+++ b/symbol_analyzer/index.html
@@ -0,0 +1,137 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="./analysis.js"></script>
+ <style>
+body {
+ background-color: #141514;4;4;4;
+}
+ </style>
+ </head>
+ <body>
+ <canvas id="main" width="1000" height="1000" style="border:1px solid #fff;">
+ </canvas>
+ <script>
+const RADIUS = 20;
+const WIDTH = 1000;
+const HEIGHT = 1000;
+const RING_RADIUS = Math.min(WIDTH, HEIGHT) / 2 - 2 * RADIUS;
+const ignore_files = [
+ "stdbool.h",
+ "queen.c",
+ "rook.c",
+ "king.c",
+ "pawn.c",
+ "bishop.c",
+ "knight.c"
+];
+
+data = data.filter(x => !ignore_files.includes(x.name));
+
+const c = document.getElementById("main");
+const ctx = c.getContext("2d");
+ctx.textAlign = "center";
+ctx.font = "bold 10pt Courier";
+
+function canvas_arrow(fromx, fromy, tox, toy) {
+ var headlen = 10; // length of head in pixels
+ var dx = tox - fromx;
+ var dy = toy - fromy;
+ var angle = Math.atan2(dy, dx);
+ ctx.moveTo(
+ fromx + Math.cos(angle) * RADIUS,
+ fromy + Math.sin(angle) * RADIUS
+ );
+ ctx.lineTo(
+ tox + Math.cos(Math.PI + angle) * RADIUS,
+ toy + Math.sin(Math.PI + angle) * RADIUS
+ );
+ ctx.lineTo(
+ tox - headlen * Math.cos(angle - Math.PI / 6) + Math.cos(Math.PI + angle) * RADIUS,
+ toy - headlen * Math.sin(angle - Math.PI / 6) + Math.sin(Math.PI + angle) * RADIUS
+ );
+ ctx.moveTo(
+ tox + Math.cos(Math.PI + angle) * RADIUS,
+ toy + Math.sin(Math.PI + angle) * RADIUS
+ );
+ ctx.lineTo(
+ tox - headlen * Math.cos(angle + Math.PI / 6) + Math.cos(Math.PI + angle) * RADIUS,
+ toy - headlen * Math.sin(angle + Math.PI / 6) + Math.sin(Math.PI + angle) * RADIUS
+ );
+}
+
+let mapping = {}
+
+for (let i = 0; i < data.length; i++) {
+ mapping[data[i].name] = i;
+ const angle = i * 2 * Math.PI / data.length;
+ const [x, y] = [
+ RING_RADIUS * Math.cos(angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(angle) + HEIGHT / 2
+ ];
+ ctx.fillStyle = `hsl(${i * 255 / data.length}, 50%, 50%)`;
+ ctx.beginPath();
+ ctx.arc(x, y, RADIUS, 0, 2 * Math.PI);
+ ctx.fill();
+ ctx.fillStyle = "white";
+ ctx.fillText(data[i].name, x, y);
+}
+
+for (let i = 0; i < data.length; i++) {
+ for (let j = 0; j < data[i].imports.length; j++) {
+ if (!(data[i].imports[j] in mapping)) continue;
+ const to_idx = mapping[data[i].name];
+ const from_idx = mapping[data[i].imports[j]];
+ const from_angle = from_idx * 2 * Math.PI / data.length;
+ const [from_x, from_y] = [
+ RING_RADIUS * Math.cos(from_angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(from_angle) + HEIGHT / 2
+ ];
+ const to_angle = to_idx * 2 * Math.PI / data.length;
+ const [to_x, to_y] = [
+ RING_RADIUS * Math.cos(to_angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(to_angle) + HEIGHT / 2
+ ];
+ ctx.beginPath();
+ ctx.strokeStyle = `hsl(${from_idx * 255 / data.length}, 50%, 40%)`;
+ canvas_arrow(from_x, from_y, to_x, to_y);
+ ctx.stroke();
+ }
+}
+
+function getCursorPosition(canvas, event) {
+ const rect = canvas.getBoundingClientRect()
+ const x = event.clientX - rect.left
+ const y = event.clientY - rect.top
+ return [x, y]
+}
+
+const canvas = document.querySelector('canvas')
+canvas.addEventListener('mousedown', function(e) {
+ const [x, y] = getCursorPosition(canvas, e)
+ for (let i = 0; i < data.length; i++) {
+ const angle = i * 2 * Math.PI / data.length;
+ const [point_x, point_y] = [
+ RING_RADIUS * Math.cos(angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(angle) + HEIGHT / 2
+ ];
+
+
+ if (Math.pow(point_x - x, 2) + Math.pow(point_y - y, 2) > Math.pow(RADIUS, 2)) {
+ continue;
+ }
+
+ console.clear()
+ console.log(data[i].symbols)
+ console.log(data[i].unused)
+ console.log(data[i].used)
+ // for (let j = 0; j < data[i].unused.length; j++) {
+ // console.log(data[i].unused[j]);
+ // }
+ // console.log(data[i].unused.length);
+ }
+})
+
+ </script>
+ </body>
+</html>
diff --git a/symbol_analyzer/main.py b/symbol_analyzer/main.py
index 1fa5457..f137cfb 100644
--- a/symbol_analyzer/main.py
+++ b/symbol_analyzer/main.py
@@ -1,26 +1,104 @@
+# this code was written to work, not to be maintained
+# don't touch my trash
+
import os
+import json
from extractor import parse_file
from parser import parse_definition_tokens
from symbols import symbols_from_struct_tokens, symbols_from_enum_tokens
-symbols = set()
+stdlibs = [
+ "stdlib.h", "assert.h", "stdio.h", "stdint.h",
+ "inttypes.h", "mman.h", "stdatomic.h", "string.h", "unistd.h",
+ "fcntl.h", "pthread.h"
+]
-for root, subdirs, files in os.walk("include"):
- for file in files:
- file_symbols = ["int", "bool", "char"]
- definitions, usage = parse_file(root + "/" + file)
- structs, enums, functions, typedefs = parse_definition_tokens(
+files_content = {
+ "stdbool.h": {
+ "symbols": ["bool"],
+ "usage": [],
+ "imports": []
+ }
+}
+
+def handle(file):
+ files_content[file] = {}
+ file_symbols = ["int", "char"]
+ definitions, _ = parse_file(root + "/" + file)
+ structs, enums, functions, typedefs, imports, usage = \
+ parse_definition_tokens(
definitions,
file_symbols
)
- file_symbols.extend(symbols_from_struct_tokens(structs))
- file_symbols.extend(symbols_from_enum_tokens(enums))
- file_symbols.extend(functions)
- file_symbols.extend(typedefs)
- for item in file_symbols:
- if item.isnumeric():
- continue
- symbols.add(item)
-
-print(symbols)
+ file_symbols.extend(symbols_from_struct_tokens(structs))
+ file_symbols.extend(symbols_from_struct_tokens(structs))
+ file_symbols.extend(symbols_from_enum_tokens(enums))
+ file_symbols.extend(functions)
+ file_symbols.extend(typedefs)
+ files_content[file]["symbols"] = set()
+ files_content[file]["imports"] = list(map(lambda x: x[1:-1] ,imports))
+ files_content[file]["usage"] = usage
+ for item in file_symbols:
+ if item.isnumeric():
+ continue
+ if "".join(item.split("_")).isalnum():
+ files_content[file]["symbols"].add(item)
+
+for root, subdirs, files in os.walk("include"):
+ for file in files:
+ handle(file)
+for root, subdirs, files in os.walk("src"):
+ for file in files:
+ handle(file)
+
+for file in files_content.keys():
+ final_imports = set()
+ to_resolve = []
+ for imported_file in files_content[file]["imports"]:
+ x = imported_file.split("/")[-1]
+ to_resolve.append(x)
+ final_imports.add(x)
+
+ while len(to_resolve) > 0:
+ f = to_resolve.pop()
+ if f not in files_content:
+ if f not in stdlibs:
+ print(f)
+ assert f in stdlibs
+ continue
+ new_items = files_content[f]["imports"]
+ for new_item in new_items:
+ x = new_item.split("/")[-1]
+ to_resolve.append(x)
+ final_imports.add(x)
+
+ files_content[file]["imports"] = final_imports
+
+
+for file, file_content in files_content.items():
+ symbols = list(file_content["symbols"])
+ for imported_file in file_content["imports"]:
+ imported_file = imported_file.split("/")[-1]
+ if imported_file not in files_content:
+ assert imported_file in stdlibs
+ continue
+ symbols.extend(files_content[imported_file]["symbols"])
+ symbols = set(symbols)
+ usage_set = set(file_content["usage"])
+ files_content[file]["unused"] = symbols - usage_set
+ files_content[file]["used"] = symbols.intersection(usage_set)
+
+output = []
+for file in files_content.keys():
+ output.append({
+ "name": file,
+ "imports": list(files_content[file]["imports"]),
+ "symbols": list(files_content[file]["symbols"]),
+ "unused": list(files_content[file]["unused"]),
+ "used": list(files_content[file]["used"])
+ })
+
+with open("symbol_analyzer/analysis.js", "w") as f:
+ f.write("data = ")
+ json.dump(output, f)
diff --git a/symbol_analyzer/parser.py b/symbol_analyzer/parser.py
index 551857e..977a634 100644
--- a/symbol_analyzer/parser.py
+++ b/symbol_analyzer/parser.py
@@ -4,24 +4,29 @@ def parse_definition_tokens(tokens, symbols):
structs = []
enums = []
functions = []
+ imports = []
+ usage = []
i = 0
while i < len(tokens):
# skip comments
if tokens[i] == "//":
- while tokens[i] != "\n":
+ while tokens[i] != "\n" and i < len(tokens):
i += 1
i += 1
continue
- if tokens[i] == "typedef":
+ elif tokens[i] == "#include":
+ imports.append(tokens[i + 1])
+ i += 2
+ elif tokens[i] == "typedef":
if tokens[i + 1] in symbols:
simple_typedefs.append(tokens[i + 2])
i += 2
- if tokens[i] == "struct":
+ elif tokens[i] == "struct":
i += 1
defs = []
depth = 0
- while True:
+ while i < len(tokens):
if tokens[i] == "//":
while tokens[i] != "\n":
i += 1
@@ -37,7 +42,7 @@ def parse_definition_tokens(tokens, symbols):
defs.append(tokens[i])
i += 1
structs.append(defs)
- if tokens[i] == "enum":
+ elif tokens[i] == "enum":
i += 1
defs = []
depth = 0
@@ -57,9 +62,15 @@ def parse_definition_tokens(tokens, symbols):
defs.append(tokens[i])
i += 1
enums.append(defs)
- i += 1
-
- if tokens[i] == "(":
+ elif tokens[i] == "(":
functions.append(tokens[i - 1])
+ while tokens[i] != ")":
+ i += 1
+ i += 1
+ else:
+ usage.append(tokens[i])
+
+ i += 1
- return structs, enums, functions, simple_typedefs
+ print(structs, enums, functions, simple_typedefs, imports)
+ return structs, enums, functions, simple_typedefs, imports, usage