[cfe-commits] r138813 - /cfe/trunk/tools/libclang/CIndex.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Aug 30 12:43:19 PDT 2011
Author: akirtzidis
Date: Tue Aug 30 14:43:19 2011
New Revision: 138813
URL: http://llvm.org/viewvc/llvm-project?rev=138813&view=rev
Log:
[libclang] Rename some functions and make sure we don't iterate past the tokens array.
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=138813&r1=138812&r2=138813&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Aug 30 14:43:19 2011
@@ -4538,16 +4538,16 @@
SourceLocation GetTokenLoc(unsigned tokI) {
return SourceLocation::getFromRawEncoding(Tokens[tokI].int_data[1]);
}
- bool isMacroArgToken(unsigned tokI) const {
+ bool isFunctionMacroToken(unsigned tokI) const {
return Tokens[tokI].int_data[3] != 0;
}
- SourceLocation getMacroArgLoc(unsigned tokI) const {
+ SourceLocation getFunctionMacroTokenLoc(unsigned tokI) const {
return SourceLocation::getFromRawEncoding(Tokens[tokI].int_data[3]);
}
void annotateAndAdvanceTokens(CXCursor, RangeComparisonResult, SourceRange);
- void annotateAndAdvanceMacroArgTokens(CXCursor, RangeComparisonResult,
- SourceRange);
+ void annotateAndAdvanceFunctionMacroTokens(CXCursor, RangeComparisonResult,
+ SourceRange);
public:
AnnotateTokensWorker(AnnotateTokensData &annotated,
@@ -4611,8 +4611,8 @@
SourceRange range) {
while (MoreTokens()) {
const unsigned I = NextToken();
- if (isMacroArgToken(I))
- return annotateAndAdvanceMacroArgTokens(updateC, compResult, range);
+ if (isFunctionMacroToken(I))
+ return annotateAndAdvanceFunctionMacroTokens(updateC, compResult, range);
SourceLocation TokLoc = GetTokenLoc(I);
if (LocationCompare(SrcMgr, TokLoc, range) == compResult) {
@@ -4625,10 +4625,12 @@
}
/// \brief Special annotation handling for macro argument tokens.
-void AnnotateTokensWorker::annotateAndAdvanceMacroArgTokens(CXCursor updateC,
+void AnnotateTokensWorker::annotateAndAdvanceFunctionMacroTokens(
+ CXCursor updateC,
RangeComparisonResult compResult,
SourceRange range) {
- assert(isMacroArgToken(NextToken()) &&
+ assert(MoreTokens());
+ assert(isFunctionMacroToken(NextToken()) &&
"Should be called only for macro arg tokens");
// This works differently than annotateAndAdvanceTokens; because expanded
@@ -4642,8 +4644,8 @@
bool atLeastOneCompFail = false;
unsigned I = NextToken();
- for (; isMacroArgToken(I); ++I) {
- SourceLocation TokLoc = getMacroArgLoc(I);
+ for (; I < NumTokens && isFunctionMacroToken(I); ++I) {
+ SourceLocation TokLoc = getFunctionMacroTokenLoc(I);
if (TokLoc.isFileID())
continue; // not macro arg token, it's parens or comma.
if (LocationCompare(SrcMgr, TokLoc, range) == compResult) {
@@ -4893,7 +4895,7 @@
if (!SM.isBeforeInTranslationUnit(tokLoc, macroRange.getEnd()))
break;
- setMacroArgExpandedLoc(CurIdx, SM.getMacroArgExpandedLocation(tokLoc));
+ setFunctionMacroTokenLoc(CurIdx, SM.getMacroArgExpandedLocation(tokLoc));
}
if (CurIdx == NumTokens)
@@ -4907,7 +4909,7 @@
return SourceLocation::getFromRawEncoding(Tokens[tokI].int_data[1]);
}
- void setMacroArgExpandedLoc(unsigned tokI, SourceLocation loc) {
+ void setFunctionMacroTokenLoc(unsigned tokI, SourceLocation loc) {
// The third field is reserved and currently not used. Use it here
// to mark macro arg expanded tokens with their expanded locations.
Tokens[tokI].int_data[3] = loc.getRawEncoding();
More information about the cfe-commits
mailing list