Browse Source

Refactored and fixed parsing of original source text for declarations.

pull/86/head
triton 12 years ago
parent
commit
6a3998002f
  1. 13
      src/Parser/Comments.cpp
  2. 58
      src/Parser/Parser.cpp
  3. 4
      src/Parser/Parser.h

13
src/Parser/Comments.cpp

@ -265,17 +265,4 @@ void Parser::HandleComments(clang::Decl* D, CppSharp::AST::Declaration^ Decl)
auto CB = safe_cast<CppSharp::AST::FullComment^>(ConvertCommentBlock(FC)); auto CB = safe_cast<CppSharp::AST::FullComment^>(ConvertCommentBlock(FC));
RawComment->FullComment = CB; RawComment->FullComment = CB;
} }
// Debug Text
SourceManager& SM = C->getSourceManager();
const LangOptions& LangOpts = C->getLangOpts();
auto Range = CharSourceRange::getTokenRange(D->getSourceRange());
bool Invalid;
StringRef DeclText = Lexer::getSourceText(Range, SM, LangOpts, &Invalid);
//assert(!Invalid && "Should have a valid location");
if (!Invalid)
Decl->DebugText = marshalString<E_UTF8>(DeclText);
} }

58
src/Parser/Parser.cpp

@ -613,9 +613,9 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
{ {
auto MD = cast<CXXMethodDecl>(D); auto MD = cast<CXXMethodDecl>(D);
auto Method = WalkMethodCXX(MD); auto Method = WalkMethodCXX(MD);
HandleDeclaration(MD, Method);
Method->AccessDecl = AccessDecl; Method->AccessDecl = AccessDecl;
RC->Methods->Add(Method); RC->Methods->Add(Method);
HandleComments(MD, Method);
break; break;
} }
case Decl::Field: case Decl::Field:
@ -626,8 +626,8 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
if (Layout) if (Layout)
Field->Offset = Layout->getFieldOffset(FD->getFieldIndex()); Field->Offset = Layout->getFieldOffset(FD->getFieldIndex());
HandleDeclaration(FD, Field);
RC->Fields->Add(Field); RC->Fields->Add(Field);
HandleComments(FD, Field);
break; break;
} }
case Decl::AccessSpec: case Decl::AccessSpec:
@ -642,7 +642,7 @@ CppSharp::AST::Class^ Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
auto range = SourceRange(startLoc, AS->getColonLoc()); auto range = SourceRange(startLoc, AS->getColonLoc());
HandlePreprocessedEntities(AccessDecl, range, HandlePreprocessedEntities(AccessDecl, range,
CppSharp::AST::MacroLocation::Unknown); CppSharp::AST::MacroLocation::Unknown);
HandleDeclaration(AS, AccessDecl);
RC->Specifiers->Add(AccessDecl); RC->Specifiers->Add(AccessDecl);
break; break;
} }
@ -1558,6 +1558,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F,
F->Mangled = marshalString<E_UTF8>(Mangled); F->Mangled = marshalString<E_UTF8>(Mangled);
SourceLocation ParamStartLoc = FD->getLocStart(); SourceLocation ParamStartLoc = FD->getLocStart();
SourceLocation ResultLoc;
auto FTSI = FD->getTypeSourceInfo(); auto FTSI = FD->getTypeSourceInfo();
if (FTSI) if (FTSI)
@ -1591,6 +1592,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F,
P->QualifiedType = GetQualifiedType(VD->getType(), WalkType(VD->getType(), &PTL)); P->QualifiedType = GetQualifiedType(VD->getType(), WalkType(VD->getType(), &PTL));
P->HasDefaultValue = VD->hasDefaultArg(); P->HasDefaultValue = VD->hasDefaultArg();
P->Namespace = NS; P->Namespace = NS;
HandleDeclaration(VD, P);
F->Parameters->Add(P); F->Parameters->Add(P);
@ -1864,6 +1866,40 @@ void Parser::HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl,
} }
} }
void Parser::HandleOriginalText(clang::Decl* D, CppSharp::AST::Declaration^ Decl)
{
auto &SM = C->getSourceManager();
auto &LangOpts = C->getLangOpts();
auto Range = clang::CharSourceRange::getTokenRange(D->getSourceRange());
bool Invalid;
auto DeclText = clang::Lexer::getSourceText(Range, SM, LangOpts, &Invalid);
if (!Invalid)
Decl->DebugText = clix::marshalString<clix::E_UTF8>(DeclText);
}
void Parser::HandleDeclaration(clang::Decl* D, CppSharp::AST::Declaration^ Decl)
{
if (Decl->PreprocessedEntities->Count == 0)
{
auto startLoc = GetDeclStartLocation(C.get(), D);
auto endLoc = D->getLocEnd();
auto range = clang::SourceRange(startLoc, endLoc);
HandlePreprocessedEntities(Decl, range);
}
HandleOriginalText(D, Decl);
HandleComments(D, Decl);
if (const clang::ValueDecl *VD = clang::dyn_cast_or_null<clang::ValueDecl>(D))
Decl->IsDependent = VD->getType()->isDependentType();
Decl->Access = ConvertToAccess(D->getAccess());
}
//-----------------------------------// //-----------------------------------//
CppSharp::AST::Declaration^ Parser::WalkDeclarationDef(clang::Decl* D) CppSharp::AST::Declaration^ Parser::WalkDeclarationDef(clang::Decl* D)
@ -2065,21 +2101,7 @@ CppSharp::AST::Declaration^ Parser::WalkDeclaration(clang::Decl* D,
} }; } };
if (Decl) if (Decl)
{ HandleDeclaration(D, Decl);
if (Decl->PreprocessedEntities->Count == 0)
{
auto startLoc = GetDeclStartLocation(C.get(), D);
auto endLoc = D->getLocEnd();
auto range = clang::SourceRange(startLoc, endLoc);
HandlePreprocessedEntities(Decl, range);
}
HandleComments(D, Decl);
if (const ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D))
Decl->IsDependent = VD->getType()->isDependentType();
Decl->Access = ConvertToAccess(D->getAccess());
}
return Decl; return Decl;
} }

4
src/Parser/Parser.h

@ -81,7 +81,6 @@ protected:
std::string GetDeclMangledName(clang::Decl*, clang::TargetCXXABI, std::string GetDeclMangledName(clang::Decl*, clang::TargetCXXABI,
bool IsDependent = false); bool IsDependent = false);
std::string GetTypeName(const clang::Type*); std::string GetTypeName(const clang::Type*);
void HandleComments(clang::Decl* D, CppSharp::AST::Declaration^);
void WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, void WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F,
bool IsDependent = false); bool IsDependent = false);
void HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl, clang::SourceRange sourceRange, void HandlePreprocessedEntities(CppSharp::AST::Declaration^ Decl, clang::SourceRange sourceRange,
@ -95,6 +94,9 @@ protected:
CppSharp::AST::DeclarationContext^ GetNamespace(clang::Decl*, clang::DeclContext*); CppSharp::AST::DeclarationContext^ GetNamespace(clang::Decl*, clang::DeclContext*);
CppSharp::AST::DeclarationContext^ GetNamespace(clang::Decl*); CppSharp::AST::DeclarationContext^ GetNamespace(clang::Decl*);
void HandleDeclaration(clang::Decl* D, CppSharp::AST::Declaration^);
void HandleOriginalText(clang::Decl* D, CppSharp::AST::Declaration^);
void HandleComments(clang::Decl* D, CppSharp::AST::Declaration^);
void HandleDiagnostics(ParserResult^ res); void HandleDiagnostics(ParserResult^ res);
int Index; int Index;

Loading…
Cancel
Save