Browse Source

Add the enumeration item expression as a string to the AST.

pull/13/merge
triton 12 years ago
parent
commit
6a31a00760
  1. 10
      src/Parser/Parser.cpp
  2. 2
      src/Parser/Parser.h

10
src/Parser/Parser.cpp

@ -1222,6 +1222,10 @@ CppSharp::AST::Enumeration^ Parser::WalkEnum(clang::EnumDecl* ED) @@ -1222,6 +1222,10 @@ CppSharp::AST::Enumeration^ Parser::WalkEnum(clang::EnumDecl* ED)
EnumItem->Comment = marshalString<E_UTF8>(BriefText);
//EnumItem->ExplicitValue = ECD->getExplicitValue();
std::string Text;
if (GetDeclText(ECD->getSourceRange(), Text))
EnumItem->Expression = marshalString<E_UTF8>(Text);
E->AddItem(EnumItem);
}
@ -1539,13 +1543,13 @@ void Parser::HandleComments(clang::Decl* D, CppSharp::AST::Declaration^ Decl) @@ -1539,13 +1543,13 @@ void Parser::HandleComments(clang::Decl* D, CppSharp::AST::Declaration^ Decl)
//-----------------------------------//
bool Parser::GetPreprocessedEntityText(clang::PreprocessedEntity* PE, std::string& Text)
bool Parser::GetDeclText(clang::SourceRange SR, std::string& Text)
{
using namespace clang;
SourceManager& SM = C->getSourceManager();
const LangOptions &LangOpts = C->getLangOpts();
auto Range = CharSourceRange::getTokenRange(PE->getSourceRange());
auto Range = CharSourceRange::getTokenRange(SR);
bool Invalid;
Text = Lexer::getSourceText(Range, SM, LangOpts, &Invalid);
@ -1575,7 +1579,7 @@ void Parser::HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl, @@ -1575,7 +1579,7 @@ void Parser::HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl,
Entity = gcnew CppSharp::AST::MacroExpansion();
std::string Text;
if (!GetPreprocessedEntityText(PPEntity, Text))
if (!GetDeclText(PPEntity->getSourceRange(), Text))
continue;
static_cast<CppSharp::AST::MacroExpansion^>(Entity)->Text =

2
src/Parser/Parser.h

@ -158,7 +158,7 @@ protected: @@ -158,7 +158,7 @@ protected:
bool IsDependent = false);
void HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl, clang::SourceRange sourceRange,
CppSharp::AST::MacroLocation macroLocation = CppSharp::AST::MacroLocation::Unknown);
bool GetPreprocessedEntityText(clang::PreprocessedEntity*, std::string& Text);
bool GetDeclText(clang::SourceRange, std::string& Text);
CppSharp::AST::TranslationUnit^ GetTranslationUnit(clang::SourceLocation Loc,
SourceLocationKind *Kind = 0);

Loading…
Cancel
Save