Browse Source

Fixed regression in parsing of preprocessed entities.

Specifically we now store the pointer of the original declaration and check for duplicates.
pull/137/merge
triton 12 years ago
parent
commit
677ca81154
  1. 78
      src/CppParser/Parser.cpp
  2. 2
      src/CppParser/Parser.h
  3. 78
      src/Parser/Parser.cpp
  4. 2
      src/Parser/Parser.h

78
src/CppParser/Parser.cpp

@ -1915,6 +1915,51 @@ bool Parser::GetDeclText(clang::SourceRange SR, std::string& Text) @@ -1915,6 +1915,51 @@ bool Parser::GetDeclText(clang::SourceRange SR, std::string& Text)
return !Invalid && !Text.empty();
}
PreprocessedEntity* Parser::WalkPreprocessedEntity(
Declaration* Decl, clang::PreprocessedEntity* PPEntity)
{
using namespace clang;
for (unsigned I = 0, E = Decl->PreprocessedEntities.size();
I != E; ++I)
{
auto Entity = Decl->PreprocessedEntities[I];
if (Entity->OriginalPtr == PPEntity)
return Entity;
}
PreprocessedEntity* Entity;
switch(PPEntity->getKind())
{
case clang::PreprocessedEntity::MacroExpansionKind:
{
const MacroExpansion* MD = cast<MacroExpansion>(PPEntity);
Entity = new MacroExpansion();
std::string Text;
if (!GetDeclText(PPEntity->getSourceRange(), Text))
return nullptr;
static_cast<MacroExpansion*>(Entity)->Text = Text;
break;
}
case clang::PreprocessedEntity::MacroDefinitionKind:
{
const MacroDefinition* MD = cast<MacroDefinition>(PPEntity);
Entity = new MacroDefinition();
break;
}
default:
return nullptr;
}
Entity->OriginalPtr = PPEntity;
Decl->PreprocessedEntities.push_back(Entity);
return Entity;
}
void Parser::HandlePreprocessedEntities(Declaration* Decl,
clang::SourceRange sourceRange,
MacroLocation macroLocation)
@ -1938,35 +1983,12 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl, @@ -1938,35 +1983,12 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl,
for (auto it = Range.first; it != Range.second; ++it)
{
auto PPEntity = (*it);
PreprocessedEntity* Entity;
switch(PPEntity->getKind())
{
case clang::PreprocessedEntity::MacroExpansionKind:
{
auto MD = cast<clang::MacroExpansion>(PPEntity);
Entity = new MacroExpansion();
std::string Text;
if (!GetDeclText(PPEntity->getSourceRange(), Text))
continue;
static_cast<MacroExpansion*>(Entity)->Text = Text;
break;
}
case clang::PreprocessedEntity::MacroDefinitionKind:
{
auto MD = cast<clang::MacroDefinition>(PPEntity);
Entity = new MacroDefinition();
break;
}
default:
continue;
}
Entity->Location = macroLocation;
Decl->PreprocessedEntities.push_back(Entity);
auto Entity = WalkPreprocessedEntity(Decl, PPEntity);
if (!Entity) continue;
if (Entity->Location == MacroLocation::Unknown)
Entity->Location = macroLocation;
}
}

2
src/CppParser/Parser.h

@ -79,6 +79,8 @@ protected: @@ -79,6 +79,8 @@ protected:
void WalkVTable(clang::CXXRecordDecl* RD, Class* C);
VTableLayout WalkVTableLayout(const clang::VTableLayout& VTLayout);
VTableComponent WalkVTableComponent(const clang::VTableComponent& Component);
PreprocessedEntity* WalkPreprocessedEntity(Declaration* Decl,
clang::PreprocessedEntity* PPEntity);
// Clang helpers
SourceLocationKind GetLocationKind(const clang::SourceLocation& Loc);

78
src/Parser/Parser.cpp

@ -2033,6 +2033,52 @@ bool Parser::GetDeclText(clang::SourceRange SR, std::string& Text) @@ -2033,6 +2033,52 @@ bool Parser::GetDeclText(clang::SourceRange SR, std::string& Text)
return !Invalid && !Text.empty();
}
CppSharp::AST::PreprocessedEntity^ Parser::WalkPreprocessedEntity(
CppSharp::AST::Declaration^ Decl, clang::PreprocessedEntity* PPEntity)
{
using namespace clang;
for (unsigned I = 0, E = Decl->PreprocessedEntities->Count;
I != E; ++I)
{
auto Entity = Decl->PreprocessedEntities[I];
if (Entity->OriginalPtr == System::IntPtr(PPEntity))
return Entity;
}
CppSharp::AST::PreprocessedEntity^ Entity;
switch(PPEntity->getKind())
{
case PreprocessedEntity::MacroExpansionKind:
{
const MacroExpansion* MD = cast<MacroExpansion>(PPEntity);
Entity = gcnew CppSharp::AST::MacroExpansion();
std::string Text;
if (!GetDeclText(PPEntity->getSourceRange(), Text))
return nullptr;
static_cast<CppSharp::AST::MacroExpansion^>(Entity)->Text =
clix::marshalString<clix::E_UTF8>(Text);
break;
}
case PreprocessedEntity::MacroDefinitionKind:
{
const MacroDefinition* MD = cast<MacroDefinition>(PPEntity);
Entity = gcnew CppSharp::AST::MacroDefinition();
break;
}
default:
return nullptr;
}
Entity->OriginalPtr = System::IntPtr(PPEntity);
Decl->PreprocessedEntities->Add(Entity);
return Entity;
}
void Parser::HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl,
clang::SourceRange sourceRange,
CppSharp::AST::MacroLocation macroLocation)
@ -2056,36 +2102,12 @@ void Parser::HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl, @@ -2056,36 +2102,12 @@ void Parser::HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl,
for (auto it = Range.first; it != Range.second; ++it)
{
PreprocessedEntity* PPEntity = (*it);
CppSharp::AST::PreprocessedEntity^ Entity;
switch(PPEntity->getKind())
{
case PreprocessedEntity::MacroExpansionKind:
{
const MacroExpansion* MD = cast<MacroExpansion>(PPEntity);
Entity = gcnew CppSharp::AST::MacroExpansion();
std::string Text;
if (!GetDeclText(PPEntity->getSourceRange(), Text))
continue;
static_cast<CppSharp::AST::MacroExpansion^>(Entity)->Text =
clix::marshalString<clix::E_UTF8>(Text);
break;
}
case PreprocessedEntity::MacroDefinitionKind:
{
const MacroDefinition* MD = cast<MacroDefinition>(PPEntity);
Entity = gcnew CppSharp::AST::MacroDefinition();
break;
}
default:
continue;
}
Entity->Location = macroLocation;
auto Entity = WalkPreprocessedEntity(Decl, PPEntity);
if (!Entity) continue;
Decl->PreprocessedEntities->Add(Entity);
if (Entity->Location == CppSharp::AST::MacroLocation::Unknown)
Entity->Location = macroLocation;
}
}

2
src/Parser/Parser.h

@ -85,6 +85,8 @@ protected: @@ -85,6 +85,8 @@ protected:
void WalkVTable(clang::CXXRecordDecl* RD, CppSharp::AST::Class^ C);
CppSharp::AST::VTableLayout^ WalkVTableLayout(const clang::VTableLayout& VTLayout);
CppSharp::AST::VTableComponent WalkVTableComponent(const clang::VTableComponent& Component);
CppSharp::AST::PreprocessedEntity^ WalkPreprocessedEntity(CppSharp::AST::Declaration^ Decl,
clang::PreprocessedEntity* PPEntity);
// Clang helpers
SourceLocationKind GetLocationKind(const clang::SourceLocation& Loc);

Loading…
Cancel
Save