Skip to content
  • David Johnson's avatar
    Reimpl REDUCETYPES_FULL_EQUIV; add KEEPDECLS; support C++ using-directives. · 21343756
    David Johnson authored
    The core of this commit is an implementation of reactive reference handling
    in the DWARF parser.  Since DWARF DIES may reference each other in a
    forward or backward manner, we had implemented multiple post-passes to
    handle reference resolution.  This obviously complicates the picture because
    in general the prior pass must memoize enough information to conduct the
    next pass.  We now have a model that supports symbols registering that they
    reference other symbols; and handlers for when referenced symbols are
    changed.  This provides a nice way for us to substitute symbols for each
    other (i.e., replace decls with their definitions).
    
    This new core forms the basis for REDUCETYPES_FULL_EQUIV (it is now trivial),
    and handles our datatype and abstract origin symbol reference resolution.
    
    The secondmost important feature is handling DWARF TAG_imported_modules.
    Initially, I had thought that I could avoid imported_modules, but I can't,
    because g++ emits DWARF namespace-relevant stuff that relies on it (it
    expresses C++ using-directives with it, for instance).  The main affect
    on us is to change the "current" namespace back and forth at will -- so we
    have to respond to ensure that symbols are added to the appropriate scope.
    
    The third primary feature (related to the improved symbol reference handling)
    is a new flag called KEEPDECLS.  By default, now, declaration symbols are
    *removed* when corresponding definition symbols are located that match them;
    the definition symbols are emplaced into the declaration's scope, and a ref
    is held on them -- but they are *not* part of the declaration's scope's
    scope hierarchy.  This is good because it cuts down on the number of symbols
    for things like the kernel that are particularly heavily on declared structs
    and often do not include full definitions in compilation units.  This is bad
    from an AST-like perspective.  Thus, there is a flag.  If you use it, what
    will happen is that key parts of the definition symbol (i.e. symbol size,
    datatype, extra stuff like members) will be *copied* into the declaration
    symbol.  This is necessary so that if a declaration symbol is actually used,
    it will have the necessary information for use :).  We do it this way instead
    of linking the declaration symbols to definitions because it makes accessors
    simpler; I may well revisit this later.
    
    I added debugfile_ops::symbol_root_priv_free to free backend-specific root
    symbol data; this allows DWARF reftabs, etc, to hang around until the CU is
    fully loaded.  Allowing per-CU reftab/refuselist state to persist until all
    CUs have been loaded is critical to global symbol reference rewriting (i.e.,
    for REDUCETYPES_FULL_EQUIV).
    
    I improved symbol_type_equiv as well; it now caches previous results; and
    we use the caching per-CU (which is the same as per-reftab).
    
    This commit also fixes several bugs, especially in scope.c, and in general,
    handling scope/symbol pointer refs to each other on the delete path.
    21343756