-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][SourceManager] Reuse code when computing Column and Line numbers #166593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clang Author: SKill (SergejSalnikov) ChangesFull diff: https://github.com/llvm/llvm-project/pull/166593.diff 2 Files Affected:
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 6d9d074d78026..a6984f7b06cbc 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1409,6 +1409,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// before calling this method.
unsigned getColumnNumber(FileID FID, unsigned FilePos,
bool *Invalid = nullptr) const;
+ unsigned getColumnNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
unsigned getSpellingColumnNumber(SourceLocation Loc,
bool *Invalid = nullptr) const;
unsigned getExpansionColumnNumber(SourceLocation Loc,
@@ -1423,6 +1424,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// MemoryBuffer, so this is not cheap: use only when about to emit a
/// diagnostic.
unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = nullptr) const;
+ unsigned getLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 7dc81c50f87a2..01faeb67597a2 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1159,18 +1159,22 @@ static bool isInvalid(LocType Loc, bool *Invalid) {
return MyInvalid;
}
-unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc,
- bool *Invalid) const {
+unsigned SourceManager::getColumnNumber(SourceLocation Loc,
+ bool *Invalid) const {
+ assert(Loc.isFileID());
if (isInvalid(Loc, Invalid)) return 0;
- FileIDAndOffset LocInfo = getDecomposedSpellingLoc(Loc);
+ FileIDAndOffset LocInfo = getDecomposedLoc(Loc);
return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
}
+unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc,
+ bool *Invalid) const {
+ return getColumnNumber(getSpellingLoc(Loc), Invalid);
+}
+
unsigned SourceManager::getExpansionColumnNumber(SourceLocation Loc,
bool *Invalid) const {
- if (isInvalid(Loc, Invalid)) return 0;
- FileIDAndOffset LocInfo = getDecomposedExpansionLoc(Loc);
- return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
+ return getColumnNumber(getExpansionLoc(Loc), Invalid);
}
unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc,
@@ -1367,17 +1371,19 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,
return LineNo;
}
-unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,
- bool *Invalid) const {
+unsigned SourceManager::getLineNumber(SourceLocation Loc, bool *Invalid) const {
+ assert(Loc.isFileID());
if (isInvalid(Loc, Invalid)) return 0;
- FileIDAndOffset LocInfo = getDecomposedSpellingLoc(Loc);
+ FileIDAndOffset LocInfo = getDecomposedLoc(Loc);
return getLineNumber(LocInfo.first, LocInfo.second);
}
+unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,
+ bool *Invalid) const {
+ return getLineNumber(getSpellingLoc(Loc), Invalid);
+}
unsigned SourceManager::getExpansionLineNumber(SourceLocation Loc,
bool *Invalid) const {
- if (isInvalid(Loc, Invalid)) return 0;
- FileIDAndOffset LocInfo = getDecomposedExpansionLoc(Loc);
- return getLineNumber(LocInfo.first, LocInfo.second);
+ return getLineNumber(getExpansionLoc(Loc), Invalid);
}
unsigned SourceManager::getPresumedLineNumber(SourceLocation Loc,
bool *Invalid) const {
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
cor3ntin
approved these changes
Nov 5, 2025
Contributor
Author
|
Could you please also merge the PR? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.