nextsub = subfile->next;
xfree (subfile->name);
xfree (subfile->line_vector);
- xfree (subfile);
+ delete subfile;
}
struct pending *next, *next1;
buildsym_compunit::start_subfile (const char *name)
{
const char *subfile_dirname;
- struct subfile *subfile;
subfile_dirname = m_comp_dir.get ();
/* See if this subfile is already registered. */
- for (subfile = m_subfiles; subfile; subfile = subfile->next)
+ for (subfile *subfile = m_subfiles; subfile; subfile = subfile->next)
{
char *subfile_name;
/* This subfile is not known. Add an entry for it. */
- subfile = XNEW (struct subfile);
- memset (subfile, 0, sizeof (struct subfile));
-
- subfile->next = m_subfiles;
- m_subfiles = subfile;
+ subfile_up subfile (new struct subfile);
- m_current_subfile = subfile;
+ m_current_subfile = subfile.get ();
subfile->name = xstrdup (name);
source file. */
subfile->language = deduce_language_from_filename (subfile->name);
- if (subfile->language == language_unknown
- && subfile->next != NULL)
- {
- subfile->language = subfile->next->language;
- }
+ if (subfile->language == language_unknown && m_subfiles != nullptr)
+ subfile->language = m_subfiles->language;
/* If the filename of this subfile ends in .C, then change the
language of any pending subfiles from C to C++. We also accept
/* And patch up this file if necessary. */
if (subfile->language == language_c
- && subfile->next != NULL
- && (subfile->next->language == language_cplus
- || subfile->next->language == language_fortran))
- {
- subfile->language = subfile->next->language;
- }
+ && m_subfiles != nullptr
+ && (m_subfiles->language == language_cplus
+ || m_subfiles->language == language_fortran))
+ subfile->language = m_subfiles->language;
+
+ /* Link this subfile at the front of the subfile list. */
+ subfile->next = m_subfiles;
+ m_subfiles = subfile.release ();
}
/* For stabs readers, the first N_SO symbol is assumed to be the
else
prev_mainsub_alias->next = mainsub_alias->next;
xfree (mainsub_alias->name);
- xfree (mainsub_alias);
+
+ delete mainsub_alias;
}
}
}
struct subfile
{
- struct subfile *next;
+ subfile () = default;
+
+ /* There's nothing wrong with copying a subfile, but we don't need to, so use
+ this to avoid copying one by mistake. */
+ DISABLE_COPY_AND_ASSIGN (subfile);
+
+ struct subfile *next = nullptr;
+
/* Space for this is malloc'd. */
- char *name;
+ char *name = nullptr;
+
/* Space for this is malloc'd. */
- struct linetable *line_vector;
- int line_vector_length;
- enum language language;
- struct symtab *symtab;
+ struct linetable *line_vector = nullptr;
+ int line_vector_length = 0;
+ enum language language = language_unknown;
+ struct symtab *symtab = nullptr;
};
+using subfile_up = std::unique_ptr<subfile>;
+
/* Record the symbols defined for each context in a list. We don't
create a struct block for the context until we know how long to
make it. */
if (offset == 0)
goto return_after_cleanup;
- memset (&main_subfile, '\0', sizeof (main_subfile));
-
if (inclIndx == 0)
/* All source lines were in the main source file. None in include
files. */
for (ii = 0; ii < inclIndx; ++ii)
{
- struct subfile *tmpSubfile;
-
/* If there is main file source before include file, enter it. */
if (offset < inclTable[ii].begin)
{
else
{
/* Have a new subfile for the include file. */
+ inclTable[ii].subfile = new subfile;
- tmpSubfile = inclTable[ii].subfile = XNEW (struct subfile);
-
- memset (tmpSubfile, '\0', sizeof (struct subfile));
firstLine = &(inclTable[ii].funStartLine);
/* Enter include file's lines now. */
- enter_line_range (tmpSubfile, inclTable[ii].begin,
+ enter_line_range (inclTable[ii].subfile, inclTable[ii].begin,
inclTable[ii].end, start, 0, firstLine);
}