/* Set up the identifier hash table. Use TABLE if non-null, otherwise create our own. */ void _cpp_init_hashtable (cpp_reader *pfile, cpp_hash_table *table) { struct spec_nodes *s; if (table == NULL) { pfile->our_hashtable = 1; table = ht_create (13); /* 8K (=2^13) entries. */ table->alloc_node = alloc_node; obstack_specify_allocation (&pfile->hash_ob, 0, 0, xmalloc, free); } table->pfile = pfile; pfile->hash_table = table; /* Now we can initialize things that use the hash table. */ _cpp_init_directives (pfile); _cpp_init_internal_pragmas (pfile); s = &pfile->spec_nodes; s->n_defined = cpp_lookup (pfile, DSC("defined")); s->n_true = cpp_lookup (pfile, DSC("true")); s->n_false = cpp_lookup (pfile, DSC("false")); s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__")); s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC; s->n__has_include__ = cpp_lookup (pfile, DSC("__has_include__")); s->n__has_include_next__ = cpp_lookup (pfile, DSC("__has_include_next__")); }
/* Allocate a tbitset element. The bits are not cleared. */ static inline tbitset_elt * tbitset_elt_alloc (void) { tbitset_elt *elt; if (tbitset_free_list != 0) { elt = tbitset_free_list; tbitset_free_list = EBITSET_NEXT (elt); } else { if (!tbitset_obstack_init) { tbitset_obstack_init = true; /* Let particular systems override the size of a chunk. */ #ifndef OBSTACK_CHUNK_SIZE #define OBSTACK_CHUNK_SIZE 0 #endif /* Let them override the alloc and free routines too. */ #ifndef OBSTACK_CHUNK_ALLOC #define OBSTACK_CHUNK_ALLOC xmalloc #endif #ifndef OBSTACK_CHUNK_FREE #define OBSTACK_CHUNK_FREE free #endif #if ! defined __GNUC__ || __GNUC__ < 2 #define __alignof__(type) 0 #endif obstack_specify_allocation (&tbitset_obstack, OBSTACK_CHUNK_SIZE, __alignof__ (tbitset_elt), OBSTACK_CHUNK_ALLOC, OBSTACK_CHUNK_FREE); } /* Perhaps we should add a number of new elements to the free list. */ elt = (tbitset_elt *) obstack_alloc (&tbitset_obstack, sizeof (tbitset_elt)); } return elt; }
cpp_hash_table * ht_create (unsigned int order) { unsigned int nslots = 1 << order; cpp_hash_table *table; table = XCNEW (cpp_hash_table); /* Strings need no alignment. */ obstack_specify_allocation (&table->stack, 0, 0, xmalloc, free); obstack_alignment_mask (&table->stack) = 0; table->entries = XCNEWVEC (hashnode, nslots); table->entries_owned = true; table->nslots = nslots; return table; }
void bitmap_obstack_initialize (bitmap_obstack *bit_obstack) { if (!bit_obstack) { if (bitmap_default_obstack_depth++) return; bit_obstack = &bitmap_default_obstack; } #if !defined(__GNUC__) || (__GNUC__ < 2) #define __alignof__(type) 0 #endif bit_obstack->elements = NULL; bit_obstack->heads = NULL; obstack_specify_allocation (&bit_obstack->obstack, OBSTACK_CHUNK_SIZE, __alignof__ (bitmap_element), obstack_chunk_alloc, obstack_chunk_free); }
/* Initialize a cpp_reader structure. */ cpp_reader * cpp_create_reader (enum c_lang lang, cpp_hash_table *table, struct line_maps *line_table) { cpp_reader *pfile; /* Initialize this instance of the library if it hasn't been already. */ init_library (); pfile = XCNEW (cpp_reader); memset (&pfile->base_context, 0, sizeof (pfile->base_context)); cpp_set_lang (pfile, lang); CPP_OPTION (pfile, warn_multichar) = 1; CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1; CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, operator_names) = 1; CPP_OPTION (pfile, warn_trigraphs) = 2; CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1; CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0; CPP_OPTION (pfile, cpp_warn_deprecated) = 1; CPP_OPTION (pfile, cpp_warn_long_long) = 0; CPP_OPTION (pfile, dollars_in_ident) = 1; CPP_OPTION (pfile, warn_dollars) = 1; CPP_OPTION (pfile, warn_variadic_macros) = 1; CPP_OPTION (pfile, warn_builtin_macro_redefined) = 1; /* By default, track locations of tokens resulting from macro expansion. The '2' means, track the locations with the highest accuracy. Read the comments for struct cpp_options::track_macro_expansion to learn about the other values. */ CPP_OPTION (pfile, track_macro_expansion) = 2; CPP_OPTION (pfile, warn_normalize) = normalized_C; CPP_OPTION (pfile, warn_literal_suffix) = 1; CPP_OPTION (pfile, canonical_system_headers) = ENABLE_CANONICAL_SYSTEM_HEADERS; CPP_OPTION (pfile, ext_numeric_literals) = 1; CPP_OPTION (pfile, warn_date_time) = 0; /* Default CPP arithmetic to something sensible for the host for the benefit of dumb users like fix-header. */ CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long); CPP_OPTION (pfile, char_precision) = CHAR_BIT; CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int); CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int); CPP_OPTION (pfile, unsigned_char) = 0; CPP_OPTION (pfile, unsigned_wchar) = 1; CPP_OPTION (pfile, bytes_big_endian) = 1; /* does not matter */ /* Default to no charset conversion. */ CPP_OPTION (pfile, narrow_charset) = _cpp_default_encoding (); CPP_OPTION (pfile, wide_charset) = 0; /* Default the input character set to UTF-8. */ CPP_OPTION (pfile, input_charset) = _cpp_default_encoding (); /* A fake empty "directory" used as the starting point for files looked up without a search path. Name cannot be '/' because we don't want to prepend anything at all to filenames using it. All other entries are correct zero-initialized. */ pfile->no_search_path.name = (char *) ""; /* Initialize the line map. */ pfile->line_table = line_table; /* Initialize lexer state. */ pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); /* Set up static tokens. */ pfile->avoid_paste.type = CPP_PADDING; pfile->avoid_paste.val.source = NULL; pfile->eof.type = CPP_EOF; pfile->eof.flags = 0; /* Create a token buffer for the lexer. */ _cpp_init_tokenrun (&pfile->base_run, 250); pfile->cur_run = &pfile->base_run; pfile->cur_token = pfile->base_run.base; /* Initialize the base context. */ pfile->context = &pfile->base_context; pfile->base_context.c.macro = 0; pfile->base_context.prev = pfile->base_context.next = 0; /* Aligned and unaligned storage. */ pfile->a_buff = _cpp_get_buff (pfile, 0); pfile->u_buff = _cpp_get_buff (pfile, 0); /* Initialize table for push_macro/pop_macro. */ pfile->pushed_macros = 0; /* Do not force token locations by default. */ pfile->forced_token_location_p = NULL; /* Initialize source_date_epoch to -2 (not yet set). */ pfile->source_date_epoch = (time_t) -2; /* The expression parser stack. */ _cpp_expand_op_stack (pfile); /* Initialize the buffer obstack. */ obstack_specify_allocation (&pfile->buffer_ob, 0, 0, xmalloc, free); _cpp_init_files (pfile); _cpp_init_hashtable (pfile, table); return pfile; }