[cfe-dev] [cfe-commits] Patch for LineTableInfo to use FileID instead of int for file references
dgregor at apple.com
Fri Jun 8 09:43:41 PDT 2012
On May 25, 2012, at 9:17 AM, Tom Honermann wrote:
> I recently needed to write code to iterate over preprocessing line control directives, identify the originating source file for the directive, and then lookup details for the originating source file.
> LineTableInfo has begin() and end() methods to iterate over the set of source file IDs and retrieve the vector of line control directives in each. The returned iterator (iter) is 'std::map<int, std::vector<LineEntry> >::iterator' where the int (iter->first) corresponds to FileID::ID.
> The FileID class restricts creating instances with arbitrary IDs to a few friend classes (SourceManager, ASTWriter, ASTReader), so a user iterating over the map held by LineTableInfo is unable to create a FileID instance with an ID field corresponding to the 'int' key value from the map. This prevents calling methods like SourceManager::getSLocEntry(). To work around this, I had to implement code to mimic the getSLocEntryByID() and getLoadedSLocEntryByID() private methods of SourceManager in order to retrieve the corresponding SLocEntry.
> The attached patch modifies LineTableInfo to use FileID instead of an int corresponding to a FileID::ID as the key value for its map, modifies other methods similarly, and updates all users to pass FileID instances instead of int. In all cases, users already had a FileID instance and were passing FileID.ID anyway.
> The patch was produced with 'diff -rupN <orig> <modified>' where orig corresponds to the Clang 3.1 final release. Apply the patch in the Clang root directory with 'patch -p1 ...'
Committed as r158211, thanks!
More information about the cfe-dev