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
bool IsDeleted; bool IsDeleted;
CXXOperatorKind OperatorKind; CXXOperatorKind OperatorKind;
std::string Mangled; std::string Mangled;
std::string Signature;
CallingConvention CallingConvention; CallingConvention CallingConvention;
std::vector<Parameter*> Parameters; std::vector<Parameter*> Parameters;
}; };

70
src/CppParser/Parser.cpp

@ -317,6 +317,9 @@ static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C,
auto lineBeginOffset = SM.getFileOffset(lineBeginLoc); auto lineBeginOffset = SM.getFileOffset(lineBeginLoc);
assert(lineBeginOffset <= startOffset); assert(lineBeginOffset <= startOffset);
if (D->getLexicalDeclContext()->decls_empty())
return lineBeginLoc;
auto prevDecl = GetPreviousDeclInContext(D); auto prevDecl = GetPreviousDeclInContext(D);
if(!prevDecl) if(!prevDecl)
return lineBeginLoc; return lineBeginLoc;
@ -613,9 +616,9 @@ 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.push_back(Method); RC->Methods.push_back(Method);
HandleComments(MD, Method);
break; break;
} }
case Decl::Field: case Decl::Field:
@ -626,8 +629,8 @@ 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.push_back(Field); RC->Fields.push_back(Field);
HandleComments(FD, Field);
break; break;
} }
case Decl::AccessSpec: case Decl::AccessSpec:
@ -642,7 +645,7 @@ Class* Parser::WalkRecordCXX(clang::CXXRecordDecl* Record)
auto range = SourceRange(startLoc, AS->getColonLoc()); auto range = SourceRange(startLoc, AS->getColonLoc());
HandlePreprocessedEntities(AccessDecl, range, HandlePreprocessedEntities(AccessDecl, range,
MacroLocation::Unknown); MacroLocation::Unknown);
HandleDeclaration(AS, AccessDecl);
RC->Specifiers.push_back(AccessDecl); RC->Specifiers.push_back(AccessDecl);
break; break;
} }
@ -1558,6 +1561,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
F->Mangled = Mangled; F->Mangled = Mangled;
SourceLocation ParamStartLoc = FD->getLocStart(); SourceLocation ParamStartLoc = FD->getLocStart();
SourceLocation ResultLoc;
auto FTSI = FD->getTypeSourceInfo(); auto FTSI = FD->getTypeSourceInfo();
if (FTSI) if (FTSI)
@ -1570,8 +1574,17 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
assert (!FTInfo.isNull()); assert (!FTInfo.isNull());
ParamStartLoc = FTInfo.getRParenLoc(); 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) for(auto it = FD->param_begin(); it != FD->param_end(); ++it)
{ {
ParmVarDecl* VD = (*it); ParmVarDecl* VD = (*it);
@ -1591,6 +1604,7 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, 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.push_back(P); F->Parameters.push_back(P);
@ -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) Declaration* Parser::WalkDeclarationDef(clang::Decl* D)
@ -2061,21 +2109,7 @@ Declaration* Parser::WalkDeclaration(clang::Decl* D,
} }; } };
if (Decl) if (Decl)
{ HandleDeclaration(D, 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());
}
return Decl; return Decl;
} }

4
src/CppParser/Parser.h

@ -86,7 +86,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, Declaration*);
void WalkFunction(clang::FunctionDecl* FD, Function* F, void WalkFunction(clang::FunctionDecl* FD, Function* F,
bool IsDependent = false); bool IsDependent = false);
void HandlePreprocessedEntities(Declaration* Decl, clang::SourceRange sourceRange, void HandlePreprocessedEntities(Declaration* Decl, clang::SourceRange sourceRange,
@ -103,6 +102,9 @@ protected:
clang::CallingConv GetAbiCallConv(clang::CallingConv CC, clang::CallingConv GetAbiCallConv(clang::CallingConv CC,
bool IsInstMethod, bool IsVariadic); 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); void HandleDiagnostics(ParserResult* res);
int Index; int Index;

Loading…
Cancel
Save