struct objfile *
block::objfile () const
{
- const struct global_block *global_block;
-
if (function () != nullptr)
return function ()->objfile ();
- global_block = (struct global_block *) this->global_block ();
- return global_block->compunit_symtab->objfile ();
+ return this->global_block ()->compunit ()->objfile ();
}
/* See block. */
/* See block.h. */
-const struct block *
+const struct global_block *
block::global_block () const
{
const block *block = this;
while (block->superblock () != NULL)
block = block->superblock ();
- return block;
+ return block->as_global_block ();
}
/* See block.h. */
-const struct block *
-block::function_block () const
+struct global_block *
+block::as_global_block ()
{
- const block *block = this;
+ gdb_assert (this->is_global_block ());
- while (block != nullptr && block->function () == nullptr)
- block = block->superblock ();
+ return static_cast<struct global_block *>(this);
+}
- return block;
+/* See block.h. */
+
+const struct global_block *
+block::as_global_block () const
+{
+ gdb_assert (this->is_global_block ());
+
+ return static_cast<const struct global_block *>(this);
}
/* See block.h. */
-void
-block::set_compunit_symtab (struct compunit_symtab *cu)
+const struct block *
+block::function_block () const
{
- struct global_block *gb;
+ const block *block = this;
- gdb_assert (superblock () == NULL);
- gb = (struct global_block *) this;
- gdb_assert (gb->compunit_symtab == NULL);
- gb->compunit_symtab = cu;
+ while (block != nullptr && block->function () == nullptr)
+ block = block->superblock ();
+
+ return block;
}
/* See block.h. */
return (struct dynamic_prop *) objfile_lookup_static_link (objfile, this);
}
-/* Return the compunit of the global block. */
-
-static struct compunit_symtab *
-get_block_compunit_symtab (const struct block *block)
-{
- struct global_block *gb;
-
- gdb_assert (block->superblock () == NULL);
- gb = (struct global_block *) block;
- gdb_assert (gb->compunit_symtab != NULL);
- return gb->compunit_symtab;
-}
-
-\f
-
/* Initialize a block iterator, either to iterate over a single block,
or, for static and global blocks, all the included symtabs as
well. */
const lookup_name_info *name)
{
enum block_enum which;
- struct compunit_symtab *cu;
iter->idx = -1;
iter->name = name;
- if (block->superblock () == NULL)
- {
- which = GLOBAL_BLOCK;
- cu = get_block_compunit_symtab (block);
- }
- else if (block->superblock ()->superblock () == NULL)
- {
- which = STATIC_BLOCK;
- cu = get_block_compunit_symtab (block->superblock ());
- }
+ if (block->is_global_block ())
+ which = GLOBAL_BLOCK;
+ else if (block->is_static_block ())
+ which = STATIC_BLOCK;
else
{
iter->d.block = block;
+
/* A signal value meaning that we're iterating over a single
block. */
iter->which = FIRST_LOCAL_BLOCK;
return;
}
+ compunit_symtab *cu = block->global_block ()->compunit ();
+
/* If this is an included symtab, find the canonical includer and
use it instead. */
while (cu->user != NULL)
return sup->is_global_block ();
}
- /* Return the static block associated with block. */
+ /* Return the global block associated with block. */
- const struct block *global_block () const;
+ const struct global_block *global_block () const;
/* Return true if this block is a global block. */
bool is_global_block () const
{ return superblock () == nullptr; }
+ /* Return this block as a global_block. This block must be a global
+ block. */
+ struct global_block *as_global_block ();
+ const struct global_block *as_global_block () const;
+
/* Return the function block for this block. Returns nullptr if
there is no enclosing function, i.e., if this block is a static
or global block. */
const struct block *function_block () const;
- /* Set the compunit of this block, which must be a global block. */
-
- void set_compunit_symtab (struct compunit_symtab *);
-
/* Return a property to evaluate the static link associated to this
block.
};
/* The global block is singled out so that we can provide a back-link
- to the compunit symtab. */
+ to the compunit. */
struct global_block : public block
{
- /* This holds a pointer to the compunit symtab holding this block. */
+ /* Set the compunit of this global block.
+
+ The compunit must not have been set previously. */
+ void set_compunit (compunit_symtab *cu)
+ {
+ gdb_assert (m_compunit == nullptr);
+ m_compunit = cu;
+ }
+
+ /* Return the compunit of this global block.
- struct compunit_symtab *compunit_symtab = nullptr;
+ The compunit must have been set previously. */
+ compunit_symtab *compunit () const
+ {
+ gdb_assert (m_compunit != nullptr);
+ return m_compunit;
+ }
+
+private:
+ /* This holds a pointer to the compunit holding this block. */
+ compunit_symtab *m_compunit = nullptr;
};
struct blockvector
{ return m_num_blocks; }
/* Return the global block of this blockvector. */
- struct block *global_block ()
- { return this->block (GLOBAL_BLOCK); }
+ struct global_block *global_block ()
+ { return static_cast<struct global_block *> (this->block (GLOBAL_BLOCK)); }
/* Const version of the above. */
- const struct block *global_block () const
- { return this->block (GLOBAL_BLOCK); }
+ const struct global_block *global_block () const
+ {
+ return static_cast<const struct global_block *>
+ (this->block (GLOBAL_BLOCK));
+ }
/* Return the static block of this blockvector. */
struct block *static_block ()
cu->set_producer (m_producer);
cu->set_blockvector (blockvector);
- {
- struct block *b = blockvector->global_block ();
-
- b->set_compunit_symtab (cu);
- }
+ blockvector->global_block ()->set_compunit (cu);
cu->set_macro_table (release_macros ());
new_block = new (&objfile->objfile_obstack) global_block;
else
new_block = new (&objfile->objfile_obstack) block;
+
new_block->set_multidict
(mdict_create_linear (&objfile->objfile_obstack, NULL));
new_block->set_superblock (block_iter);
bv->set_block (i, new_block);
if (i == GLOBAL_BLOCK)
- new_block->set_compunit_symtab (cust);
+ new_block->as_global_block ()->set_compunit (cust);
}
/* Fill up the superblock fields for the real blocks, using the