1414#include "defs.h"
1515
1616/* Forward declaration for string interning */
17- char * intern_string (char * str );
17+ char * intern_string (const char * str );
1818
1919/* Lexer */
2020char token_str [MAX_TOKEN_LEN ];
@@ -285,7 +285,7 @@ void *arena_realloc(arena_t *arena, char *oldptr, int oldsz, int newsz)
285285 *
286286 * Return: Pointer to the duplicated string stored in the arena.
287287 */
288- char * arena_strdup (arena_t * arena , char * str )
288+ char * arena_strdup (arena_t * arena , const char * str )
289289{
290290 int n = strlen (str );
291291 char * dup = arena_alloc (arena , n + 1 );
@@ -303,7 +303,7 @@ char *arena_strdup(arena_t *arena, char *str)
303303 *
304304 * Return: The pointer to the duplicated memory stored in the arena.
305305 */
306- void * arena_memdup (arena_t * arena , void * data , int size )
306+ void * arena_memdup (arena_t * arena , const void * data , int size )
307307{
308308 return memcpy (arena_alloc (arena , size ), data , size );
309309}
@@ -371,7 +371,7 @@ void arena_free(arena_t *arena)
371371 *
372372 * Return: The usable hashmap index.
373373 */
374- int hashmap_hash_index (int size , char * key )
374+ int hashmap_hash_index (int size , const char * key )
375375{
376376 int hash = 0x811c9dc5 , mask ;
377377
@@ -431,7 +431,7 @@ hashmap_t *hashmap_create(int cap)
431431 *
432432 * Return: The pointer of created node.
433433 */
434- hashmap_node_t * hashmap_node_new (char * key , void * val )
434+ hashmap_node_t * hashmap_node_new (const char * key , void * val )
435435{
436436 if (!key )
437437 return NULL ;
@@ -506,7 +506,7 @@ void hashmap_rehash(hashmap_t *map)
506506 * @val: The value pointer. May be NULL. This value's lifetime is held by
507507 * hashmap.
508508 */
509- void hashmap_put (hashmap_t * map , char * key , void * val )
509+ void hashmap_put (hashmap_t * map , const char * key , void * val )
510510{
511511 if (!map )
512512 return ;
@@ -536,7 +536,7 @@ void hashmap_put(hashmap_t *map, char *key, void *val)
536536 * Return: The look up result, if the key-value pair entry exists, then returns
537537 * address of itself, NULL otherwise.
538538 */
539- hashmap_node_t * hashmap_get_node (hashmap_t * map , char * key )
539+ hashmap_node_t * hashmap_get_node (hashmap_t * map , const char * key )
540540{
541541 if (!map )
542542 return NULL ;
@@ -557,7 +557,7 @@ hashmap_node_t *hashmap_get_node(hashmap_t *map, char *key)
557557 * Return: The look up result, if the key-value pair entry exists, then returns
558558 * its value's address, NULL otherwise.
559559 */
560- void * hashmap_get (hashmap_t * map , char * key )
560+ void * hashmap_get (hashmap_t * map , const char * key )
561561{
562562 hashmap_node_t * node = hashmap_get_node (map , key );
563563 return node ? node -> val : NULL ;
@@ -570,7 +570,7 @@ void *hashmap_get(hashmap_t *map, char *key)
570570 * Return: The look up result, if the key-value pair entry exists, then returns
571571 * true, false otherwise.
572572 */
573- bool hashmap_contains (hashmap_t * map , char * key )
573+ bool hashmap_contains (hashmap_t * map , const char * key )
574574{
575575 return hashmap_get_node (map , key );
576576}
@@ -601,7 +601,7 @@ bool hard_mul_div = false;
601601 *
602602 * Return: The pointer to the type, or NULL if not found.
603603 */
604- type_t * find_type (char * type_name , int flag )
604+ type_t * find_type (const char * type_name , int flag )
605605{
606606 for (int i = 0 ; i < types_idx ; i ++ ) {
607607 if (TYPES [i ].base_type == TYPE_struct ||
@@ -672,7 +672,7 @@ block_t *add_block(block_t *parent, func_t *func, macro_t *macro)
672672 return blk ;
673673}
674674
675- void add_alias (char * alias , char * value )
675+ void add_alias (const char * alias , const char * value )
676676{
677677 alias_t * al = hashmap_get (ALIASES_MAP , alias );
678678 if (!al ) {
@@ -689,15 +689,15 @@ void add_alias(char *alias, char *value)
689689 al -> disabled = false;
690690}
691691
692- char * find_alias (char alias [])
692+ char * find_alias (const char alias [])
693693{
694694 alias_t * al = hashmap_get (ALIASES_MAP , alias );
695695 if (al && !al -> disabled )
696696 return al -> value ;
697697 return NULL ;
698698}
699699
700- bool remove_alias (char * alias )
700+ bool remove_alias (const char * alias )
701701{
702702 alias_t * al = hashmap_get (ALIASES_MAP , alias );
703703 if (al && !al -> disabled ) {
@@ -724,15 +724,15 @@ macro_t *add_macro(char *name)
724724 return ma ;
725725}
726726
727- macro_t * find_macro (char * name )
727+ macro_t * find_macro (const char * name )
728728{
729729 macro_t * ma = hashmap_get (MACROS_MAP , name );
730730 if (ma && !ma -> disabled )
731731 return ma ;
732732 return NULL ;
733733}
734734
735- bool remove_macro (char * name )
735+ bool remove_macro (const char * name )
736736{
737737 macro_t * ma = hashmap_get (MACROS_MAP , name );
738738 if (ma ) {
@@ -749,7 +749,7 @@ string_pool_t *string_pool;
749749string_literal_pool_t * string_literal_pool ;
750750
751751/* Safe string interning that works with self-hosting */
752- char * intern_string (char * str )
752+ char * intern_string (const char * str )
753753{
754754 char * existing ;
755755 char * interned ;
@@ -761,7 +761,7 @@ char *intern_string(char *str)
761761
762762 /* Safety: can't intern before initialization */
763763 if (!GENERAL_ARENA || !string_pool )
764- return str ;
764+ return ( char * ) str ;
765765
766766 /* Check if already interned */
767767 existing = hashmap_get (string_pool -> strings , str );
@@ -778,7 +778,7 @@ char *intern_string(char *str)
778778 return interned ;
779779}
780780
781- int find_macro_param_src_idx (char * name , block_t * parent )
781+ int find_macro_param_src_idx (const char * name , block_t * parent )
782782{
783783 macro_t * macro = parent -> macro ;
784784
@@ -811,7 +811,7 @@ type_t *add_named_type(char *name)
811811 return type ;
812812}
813813
814- void add_constant (char alias [], int value )
814+ void add_constant (const char alias [], int value )
815815{
816816 constant_t * constant = arena_alloc_constant ();
817817 if (!constant ) {
@@ -825,12 +825,12 @@ void add_constant(char alias[], int value)
825825 hashmap_put (CONSTANTS_MAP , alias , constant );
826826}
827827
828- constant_t * find_constant (char alias [])
828+ constant_t * find_constant (const char alias [])
829829{
830830 return hashmap_get (CONSTANTS_MAP , alias );
831831}
832832
833- var_t * find_member (char token [], type_t * type )
833+ var_t * find_member (const char token [], type_t * type )
834834{
835835 /* If it is a forwardly declared alias of a structure, switch to the base
836836 * structure type.
@@ -845,7 +845,7 @@ var_t *find_member(char token[], type_t *type)
845845 return NULL ;
846846}
847847
848- var_t * find_local_var (char * token , block_t * block )
848+ var_t * find_local_var (const char * token , block_t * block )
849849{
850850 func_t * func = block -> func ;
851851
@@ -866,7 +866,7 @@ var_t *find_local_var(char *token, block_t *block)
866866 return NULL ;
867867}
868868
869- var_t * find_global_var (char * token )
869+ var_t * find_global_var (const char * token )
870870{
871871 var_list_t * var_list = & GLOBAL_BLOCK -> locals ;
872872
@@ -877,7 +877,7 @@ var_t *find_global_var(char *token)
877877 return NULL ;
878878}
879879
880- var_t * find_var (char * token , block_t * parent )
880+ var_t * find_var (const char * token , block_t * parent )
881881{
882882 var_t * var = find_local_var (token , parent );
883883 if (!var )
@@ -915,7 +915,7 @@ int size_var(var_t *var)
915915 *
916916 * Return: A pointer to the function.
917917 */
918- func_t * add_func (char * func_name , bool synthesize )
918+ func_t * add_func (const char * func_name , bool synthesize )
919919{
920920 func_t * func = hashmap_get (FUNC_MAP , func_name );
921921
@@ -947,7 +947,7 @@ func_t *add_func(char *func_name, bool synthesize)
947947 *
948948 * Return: A pointer to the function if exists, NULL otherwise.
949949 */
950- func_t * find_func (char * func_name )
950+ func_t * find_func (const char * func_name )
951951{
952952 return hashmap_get (FUNC_MAP , func_name );
953953}
@@ -1164,7 +1164,7 @@ bool strbuf_putc(strbuf_t *src, char value)
11641164 return true;
11651165}
11661166
1167- bool strbuf_puts (strbuf_t * src , char * value )
1167+ bool strbuf_puts (strbuf_t * src , const char * value )
11681168{
11691169 int len = strlen (value );
11701170
0 commit comments