Browse Source

Updated CppParser to the latest Parser changes.

pull/86/head
triton 12 years ago
parent
commit
1ecd2e138d
  1. 1
      src/CppParser/AST.h
  2. 70
      src/CppParser/Parser.cpp
  3. 4
      src/CppParser/Parser.h

1
src/CppParser/AST.h

@ -435,6 +435,7 @@ struct CS_API Function : public Declaration @@ -435,6 +435,7 @@ struct CS_API Function : public Declaration
bool IsDeleted;
CXXOperatorKind OperatorKind;
std::string Mangled;
std::string Signature;
CallingConvention CallingConvention;
std::vector<Parameter*> Parameters;
};

70
src/CppParser/Parser.cpp

@ -317,6 +317,9 @@ static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C, @@ -317,6 +317,9 @@ static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C,
auto lineBeginOffset = SM.getFileOffset(lineBeginLoc);
assert(lineBeginOffset <= startOffset);
if (D->getLexicalDeclContext()->decls_empty())
return lineBeginLoc;
auto prevDecl = GetPreviousDeclInContext(D);
if(!prevDecl)
return lineBeginLoc;
@ -613,9 +616,9 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -613,9 +616,9 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
{
auto MD = cast<CXXMethodDecl>(D);
auto Method = WalkMethodCXX(MD);
HandleDeclaration(MD, Method);
Method->AccessDecl = AccessDecl;
RC->Methods.push_back(Method);
HandleComments(MD, Method);
break;
}
case Decl::Field:
@ -626,8 +629,8 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -626,8 +629,8 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
if (Layout)
Field->Offset = Layout->getFieldOffset(FD->getFieldIndex());
HandleDeclaration(FD, Field);
RC->Fields.push_back(Field);
HandleComments(FD, Field);
break;
}
case Decl::AccessSpec:
@ -642,7 +645,7 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record) @@ -642,7 +645,7 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
auto range = SourceRange(startLoc, AS->getColonLoc());
HandlePreprocessedEntities(AccessDecl, range,
MacroLocation::Unknown);
HandleDeclaration(AS, AccessDecl);
RC->Specifiers.push_back(AccessDecl);
break;
}
@ -1558,6 +1561,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, @@ -1558,6 +1561,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
F->Mangled = Mangled;
SourceLocation ParamStartLoc = FD->getLocStart();
SourceLocation ResultLoc;
auto FTSI = FD->getTypeSourceInfo();
if (FTSI)
@ -1570,8 +1574,17 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, @@ -1570,8 +1574,17 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
assert (!FTInfo.isNull());
ParamStartLoc = FTInfo.getRParenLoc();
ResultLoc = FTInfo.getResultLoc().getLocStart();
}
clang::SourceRange Range(FD->getLocStart(), ParamStartLoc);
if (ResultLoc.isValid())
Range.setBegin(ResultLoc);
std::string Sig;
if (GetDeclText(Range, Sig))
F->Signature = Sig;
for(auto it = FD->param_begin(); it != FD->param_end(); ++it)
{
ParmVarDecl* VD = (*it);
@ -1591,6 +1604,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, @@ -1591,6 +1604,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
P->QualifiedType = GetQualifiedType(VD->getType(), WalkType(VD->getType(), &PTL));
P->HasDefaultValue = VD->hasDefaultArg();
P->_Namespace = NS;
HandleDeclaration(VD, P);
F->Parameters.push_back(P);
@ -1860,6 +1874,40 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl, @@ -1860,6 +1874,40 @@ void Parser::HandlePreprocessedEntities(Declaration* Decl,
}
}
void Parser::HandleOriginalText(clang::Decl* D, 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 = DeclText;
}
void Parser::HandleDeclaration(clang::Decl* D, Declaration* Decl)
{
if (Decl->PreprocessedEntities.empty())
{
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());
}
//-----------------------------------//
Declaration* Parser::WalkDeclarationDef(clang::Decl* D)
@ -2061,21 +2109,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D, @@ -2061,21 +2109,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
} };
if (Decl)
{
if (Decl->PreprocessedEntities.size() == 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());
}
HandleDeclaration(D, Decl);
return Decl;
}

4
src/CppParser/Parser.h

@ -86,7 +86,6 @@ protected: @@ -86,7 +86,6 @@ protected:
std::string GetDeclMangledName(clang::Decl*, clang::TargetCXXABI,
bool IsDependent = false);
std::string GetTypeName(const clang::Type*);
void HandleComments(clang::Decl* D, Declaration*);
void WalkFunction(clang::FunctionDecl* FD, Function* F,
bool IsDependent = false);
void HandlePreprocessedEntities(Declaration* Decl, clang::SourceRange sourceRange,
@ -103,6 +102,9 @@ protected: @@ -103,6 +102,9 @@ protected:
clang::CallingConv GetAbiCallConv(clang::CallingConv CC,
bool IsInstMethod, bool IsVariadic);
void HandleDeclaration(clang::Decl* D, Declaration*);
void HandleOriginalText(clang::Decl* D, Declaration*);
void HandleComments(clang::Decl* D, Declaration*);
void HandleDiagnostics(ParserResult* res);
int Index;

Loading…
Cancel
Save