On 12/9/19 7:29 PM, Martin Sebor wrote:
Just a few nits:
+/* A mapping between a TYPE_DECL for a class and the class_decl_loc_t
+ description above. */
+typedef hash_map<tree_decl_hash, class_decl_loc_t> class_to_loc_map_t;
+static class_to_loc_map_t class2loc;
I think we can make these members of class_decl_loc_t, now that we
aren't marking them with GTY.
+ class_decl_loc_t *rdl = class2loc.get (type_decl);
+ if (!rdl)
+ {
+ tree type = TREE_TYPE (type_decl);
+ if (def_p || !COMPLETE_TYPE_P (type))
+ {
+ /* TYPE_DECL is the first declaration or definition of the type
+ (outside precompiled headers -- see below). Just create
+ a new entry for it. */
+ class2loc.put (type_decl, class_decl_loc_t (class_key, false, def_p));
+ return;
+ }
+
+ /* TYPE was previously defined in some unknown precompiled hdeader.
+ Simply add a record of its definition at an unknown location and
+ proceed below to add a reference to it at the current location.
+ (Declarations in precompiled headers that are not definitions
+ are ignored.) */
+ tag_types def_key
+ = CLASSTYPE_DECLARED_CLASS (type) ? class_type : record_type;
+ location_t def_loc = DECL_SOURCE_LOCATION (type_decl);
+ rdl = &class2loc.get_or_insert (type_decl);
+ *rdl = class_decl_loc_t (def_key, false, true, def_loc);
+ }
It seems that you could use get_or_insert at the top, since you always
end up creating an element if there wasn't one already.
+ /* A prior declaration of TYPE_DECL has been seen. */
+
+ if (rdl->idxdef != UINT_MAX && rdl->def_class_key == class_key)
+ /* Do nothing if the class-key in this declaration matches
+ the definition. */
+ return;
...
I still think that the rest of this function could be a non-static
member function to avoid so many "rdl->".
Jason