|
|
@ -1915,58 +1915,80 @@ bool Parser::GetDeclText(clang::SourceRange SR, std::string& Text) |
|
|
|
return !Invalid && !Text.empty(); |
|
|
|
return !Invalid && !Text.empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Parser::HandlePreprocessedEntities(Declaration* Decl, |
|
|
|
PreprocessedEntity* Parser::WalkPreprocessedEntity( |
|
|
|
clang::SourceRange sourceRange, |
|
|
|
Declaration* Decl, clang::PreprocessedEntity* PPEntity) |
|
|
|
MacroLocation macroLocation) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (sourceRange.isInvalid()) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& SourceMgr = C->getSourceManager(); |
|
|
|
|
|
|
|
auto isBefore = SourceMgr.isBeforeInTranslationUnit(sourceRange.getEnd(), |
|
|
|
|
|
|
|
sourceRange.getBegin()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isBefore) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(!SourceMgr.isBeforeInTranslationUnit(sourceRange.getEnd(), |
|
|
|
|
|
|
|
sourceRange.getBegin())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace clang; |
|
|
|
using namespace clang; |
|
|
|
auto PPRecord = C->getPreprocessor().getPreprocessingRecord(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto Range = PPRecord->getPreprocessedEntitiesInRange(sourceRange); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto it = Range.first; it != Range.second; ++it) |
|
|
|
for (unsigned I = 0, E = Decl->PreprocessedEntities.size(); |
|
|
|
|
|
|
|
I != E; ++I) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto PPEntity = (*it); |
|
|
|
auto Entity = Decl->PreprocessedEntities[I]; |
|
|
|
|
|
|
|
if (Entity->OriginalPtr == PPEntity) |
|
|
|
|
|
|
|
return Entity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PreprocessedEntity* Entity; |
|
|
|
PreprocessedEntity* Entity; |
|
|
|
|
|
|
|
|
|
|
|
switch(PPEntity->getKind()) |
|
|
|
switch(PPEntity->getKind()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case clang::PreprocessedEntity::MacroExpansionKind: |
|
|
|
case clang::PreprocessedEntity::MacroExpansionKind: |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto MD = cast<clang::MacroExpansion>(PPEntity); |
|
|
|
const MacroExpansion* MD = cast<MacroExpansion>(PPEntity); |
|
|
|
Entity = new MacroExpansion(); |
|
|
|
Entity = new MacroExpansion(); |
|
|
|
|
|
|
|
|
|
|
|
std::string Text; |
|
|
|
std::string Text; |
|
|
|
if (!GetDeclText(PPEntity->getSourceRange(), Text)) |
|
|
|
if (!GetDeclText(PPEntity->getSourceRange(), Text)) |
|
|
|
continue; |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
|
|
|
|
static_cast<MacroExpansion*>(Entity)->Text = Text; |
|
|
|
static_cast<MacroExpansion*>(Entity)->Text = Text; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case clang::PreprocessedEntity::MacroDefinitionKind: |
|
|
|
case clang::PreprocessedEntity::MacroDefinitionKind: |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto MD = cast<clang::MacroDefinition>(PPEntity); |
|
|
|
const MacroDefinition* MD = cast<MacroDefinition>(PPEntity); |
|
|
|
Entity = new MacroDefinition(); |
|
|
|
Entity = new MacroDefinition(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
continue; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Entity->Location = macroLocation; |
|
|
|
Entity->OriginalPtr = PPEntity; |
|
|
|
|
|
|
|
|
|
|
|
Decl->PreprocessedEntities.push_back(Entity); |
|
|
|
Decl->PreprocessedEntities.push_back(Entity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Entity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Parser::HandlePreprocessedEntities(Declaration* Decl, |
|
|
|
|
|
|
|
clang::SourceRange sourceRange, |
|
|
|
|
|
|
|
MacroLocation macroLocation) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (sourceRange.isInvalid()) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& SourceMgr = C->getSourceManager(); |
|
|
|
|
|
|
|
auto isBefore = SourceMgr.isBeforeInTranslationUnit(sourceRange.getEnd(), |
|
|
|
|
|
|
|
sourceRange.getBegin()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isBefore) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(!SourceMgr.isBeforeInTranslationUnit(sourceRange.getEnd(), |
|
|
|
|
|
|
|
sourceRange.getBegin())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace clang; |
|
|
|
|
|
|
|
auto PPRecord = C->getPreprocessor().getPreprocessingRecord(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto Range = PPRecord->getPreprocessedEntitiesInRange(sourceRange); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto it = Range.first; it != Range.second; ++it) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto PPEntity = (*it); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto Entity = WalkPreprocessedEntity(Decl, PPEntity); |
|
|
|
|
|
|
|
if (!Entity) continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Entity->Location == MacroLocation::Unknown) |
|
|
|
|
|
|
|
Entity->Location = macroLocation; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|