Browse Source

Initial commit supporting Clang 19

pull/1942/head
Christopher Franzwa 3 months ago
parent
commit
6a7258fbac
  1. 2
      build/llvm/LLVM-commit
  2. 9
      build/llvm/LLVM.lua
  3. 8
      src/CppParser/ASTNameMangler.cpp
  4. 287
      src/CppParser/Comments.cpp
  5. 4
      src/CppParser/Link.cpp
  6. 2
      src/CppParser/ParseExpr.cpp
  7. 137
      src/CppParser/Parser.cpp
  8. 4
      src/CppParser/Parser.h

2
build/llvm/LLVM-commit

@ -1 +1 @@ @@ -1 +1 @@
6eb36aed86ea276695697093eb8136554c29286b
cd708029e0b2869e80abe31ddb175f7c35361f90

9
build/llvm/LLVM.lua

@ -260,6 +260,8 @@ function cmake(gen, conf, builddir, options) @@ -260,6 +260,8 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_INCLUDE_TESTS=false'
.. ' -DLLVM_ENABLE_LIBEDIT=false'
.. ' -DLLVM_ENABLE_LIBXML2=false'
.. ' -DLLVM_ENABLE_HIP=false'
.. ' -DLLVM_ENABLE_MLGO=false'
.. ' -DLLVM_ENABLE_TERMINFO=false'
.. ' -DLLVM_ENABLE_ZLIB=false'
.. ' -DLLVM_ENABLE_ZSTD=false'
@ -323,7 +325,7 @@ function cmake(gen, conf, builddir, options) @@ -323,7 +325,7 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_MODEXTRACT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_NM_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=true'
.. ' -DLLVM_TOOL_LLVM_OBJDUMP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=false'
@ -363,7 +365,8 @@ function cmake(gen, conf, builddir, options) @@ -363,7 +365,8 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_VERIFY_USELISTORDER_BUILD=false'
.. ' -DLLVM_TOOL_VFABI_DEMANGLE_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_XCODE_TOOLCHAIN_BUILD=false'
.. ' -DLLVM_TOOL_YAML2OBJ_BUILD=false'
.. ' -DLLVM_TOOL_YAML2OBJ_BUILD=true'
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=true'
.. ' -DLLVM_HAVE_LIBXAR=false'
.. ' -DCLANG_BUILD_EXAMPLES=false '
.. ' -DCLANG_BUILD_TOOLS=false'
@ -373,6 +376,8 @@ function cmake(gen, conf, builddir, options) @@ -373,6 +376,8 @@ function cmake(gen, conf, builddir, options)
.. ' -DCLANG_INCLUDE_TESTS=false'
.. ' -DCLANG_TOOL_AMDGPU_ARCH_BUILD=false'
.. ' -DCLANG_TOOL_APINOTES_TEST_BUILD=false'
.. ' -DCLANG_ENABLE_HIP=false'
.. ' -DCLANG_ENABLE_API_NOTES=false'
.. ' -DCLANG_TOOL_ARCMT_TEST_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_CHECK_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_DIFF_BUILD=false'

8
src/CppParser/ASTNameMangler.cpp

@ -99,14 +99,18 @@ std::string ASTNameMangler::GetMangledStructor(const NamedDecl* ND, unsigned Str @@ -99,14 +99,18 @@ std::string ASTNameMangler::GetMangledStructor(const NamedDecl* ND, unsigned Str
return FrontendBuf;
}
std::string ASTNameMangler::GetMangledThunk(const CXXMethodDecl* MD, const ThunkInfo& T, bool /*ElideOverrideInfo*/) const
std::string ASTNameMangler::GetMangledThunk(const CXXMethodDecl* MD, const ThunkInfo& T, bool ElideOverrideInfo) const
{
std::string FrontendBuf;
llvm::raw_string_ostream FOS(FrontendBuf);
// TODO: Enable `ElideOverrideInfo` param if clang is updated to 19
MC->mangleThunk(MD, T, /*ElideOverrideInfo,*/ FOS);
#if LLVM_VERSION_MAJOR >= 19
MC->mangleThunk(MD, T, ElideOverrideInfo, FOS);
#else
MC->mangleThunk(MD, T, FOS);
#endif
return FrontendBuf;
}

287
src/CppParser/Comments.cpp

@ -49,41 +49,22 @@ RawComment* Parser::WalkRawComment(const clang::RawComment* RC) @@ -49,41 +49,22 @@ RawComment* Parser::WalkRawComment(const clang::RawComment* RC)
}
static InlineCommandComment::RenderKind
ConvertRenderKind(clang::comments::InlineCommandComment::RenderKind Kind)
ConvertRenderKind(std::string Kind)
{
using namespace clang::comments;
switch (Kind)
{
case clang::comments::InlineCommandComment::RenderNormal:
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderNormal;
case clang::comments::InlineCommandComment::RenderBold:
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderBold;
case clang::comments::InlineCommandComment::RenderMonospaced:
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderMonospaced;
case clang::comments::InlineCommandComment::RenderEmphasized:
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderEmphasized;
case clang::comments::InlineCommandComment::RenderAnchor:
return CppSharp::CppParser::AST::InlineCommandComment::RenderKind::RenderAnchor;
}
if (Kind == "b")
return AST::InlineCommandComment::RenderKind::RenderBold;
else if (Kind == "c")
return AST::InlineCommandComment::RenderKind::RenderMonospaced;
else if (Kind == "a")
return AST::InlineCommandComment::RenderKind::RenderAnchor;
else if (Kind == "e")
return AST::InlineCommandComment::RenderKind::RenderEmphasized;
else
return AST::InlineCommandComment::RenderKind::RenderNormal;
llvm_unreachable("Unknown render kind");
}
static ParamCommandComment::PassDirection
ConvertParamPassDirection(clang::comments::ParamCommandComment::PassDirection Dir)
{
using namespace clang::comments;
switch (Dir)
{
case clang::comments::ParamCommandComment::In:
return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::In;
case clang::comments::ParamCommandComment::Out:
return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::Out;
case clang::comments::ParamCommandComment::InOut:
return CppSharp::CppParser::AST::ParamCommandComment::PassDirection::InOut;
}
llvm_unreachable("Unknown parameter pass direction");
}
static void HandleInlineContent(const clang::comments::InlineContentComment* CK,
InlineContentComment* IC)
{
@ -102,158 +83,120 @@ static void HandleBlockCommand(const clang::comments::BlockCommandComment* CK, @@ -102,158 +83,120 @@ static void HandleBlockCommand(const clang::comments::BlockCommandComment* CK,
}
}
static Comment* ConvertCommentBlock(clang::comments::Comment* C)
static Comment* ConvertCommentBlock(clang::comments::Comment* C, clang::CompilerInstance* CI)
{
using namespace clang;
using clang::comments::Comment;
// This needs to have an underscore else we get an ICE under VS2012.
CppSharp::CppParser::AST::Comment* _Comment = 0;
switch (C->getCommentKind())
CppSharp::CppParser::AST::Comment* _Comment = nullptr;
auto kind = C->getCommentKind();
if (auto CK = dyn_cast<const comments::FullComment>(C))
{
case Comment::FullCommentKind:
{
auto CK = cast<clang::comments::FullComment>(C);
auto FC = new FullComment();
_Comment = FC;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
{
auto Content = ConvertCommentBlock(*I);
FC->Blocks.push_back(static_cast<BlockContentComment*>(Content));
}
break;
}
case Comment::BlockCommandCommentKind:
{
auto CK = cast<const clang::comments::BlockCommandComment>(C);
auto BC = new BlockCommandComment();
_Comment = BC;
HandleBlockCommand(CK, BC);
BC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph()));
break;
}
case Comment::ParamCommandCommentKind:
{
auto CK = cast<clang::comments::ParamCommandComment>(C);
auto PC = new ParamCommandComment();
_Comment = PC;
HandleBlockCommand(CK, PC);
PC->direction = ConvertParamPassDirection(CK->getDirection());
if (CK->isParamIndexValid() && !CK->isVarArgParam())
PC->paramIndex = CK->getParamIndex();
PC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph()));
break;
}
case Comment::TParamCommandCommentKind:
{
auto CK = cast<clang::comments::TParamCommandComment>(C);
_Comment = new TParamCommandComment();
auto TC = new TParamCommandComment();
_Comment = TC;
HandleBlockCommand(CK, TC);
if (CK->isPositionValid())
for (unsigned I = 0, E = CK->getDepth(); I != E; ++I)
TC->Position.push_back(CK->getIndex(I));
TC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph()));
break;
}
case Comment::VerbatimBlockCommentKind:
{
auto CK = cast<clang::comments::VerbatimBlockComment>(C);
auto VB = new VerbatimBlockComment();
_Comment = VB;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
{
auto Line = ConvertCommentBlock(*I);
VB->Lines.push_back(static_cast<VerbatimBlockLineComment*>(Line));
}
break;
}
case Comment::VerbatimLineCommentKind:
{
auto CK = cast<clang::comments::VerbatimLineComment>(C);
auto VL = new VerbatimLineComment();
_Comment = VL;
VL->text = CK->getText().str();
break;
}
case Comment::ParagraphCommentKind:
{
auto CK = cast<clang::comments::ParagraphComment>(C);
auto PC = new ParagraphComment();
_Comment = PC;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
{
auto Content = ConvertCommentBlock(*I);
PC->Content.push_back(static_cast<InlineContentComment*>(Content));
}
PC->isWhitespace = CK->isWhitespace();
break;
}
case Comment::HTMLStartTagCommentKind:
{
auto CK = cast<clang::comments::HTMLStartTagComment>(C);
auto TC = new HTMLStartTagComment();
_Comment = TC;
HandleInlineContent(CK, TC);
TC->tagName = CK->getTagName().str();
for (unsigned I = 0, E = CK->getNumAttrs(); I != E; ++I)
{
auto A = CK->getAttr(I);
auto Attr = HTMLStartTagComment::Attribute();
Attr.name = A.Name.str();
Attr.value = A.Value.str();
TC->Attributes.push_back(Attr);
}
break;
}
case Comment::HTMLEndTagCommentKind:
{
auto CK = cast<clang::comments::HTMLEndTagComment>(C);
auto TC = new HTMLEndTagComment();
_Comment = TC;
HandleInlineContent(CK, TC);
TC->tagName = CK->getTagName().str();
break;
}
case Comment::TextCommentKind:
{
auto CK = cast<clang::comments::TextComment>(C);
auto TC = new TextComment();
_Comment = TC;
HandleInlineContent(CK, TC);
TC->text = CK->getText().str();
break;
}
case Comment::InlineCommandCommentKind:
auto FC = new FullComment();
_Comment = FC;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
FC->Blocks.push_back(static_cast<BlockContentComment*>(ConvertCommentBlock(*I, CI)));
}
else if (auto CK = dyn_cast<const comments::BlockCommandComment>(C))
{
auto BC = new BlockCommandComment();
_Comment = BC;
HandleBlockCommand(CK, BC);
BC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph(), CI));
}
else if (auto CK = dyn_cast<const comments::ParamCommandComment>(C))
{
auto PC = new ParamCommandComment();
_Comment = PC;
HandleBlockCommand(CK, PC);
if (CK->isParamIndexValid() && !CK->isVarArgParam())
PC->paramIndex = CK->getParamIndex();
PC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph(), CI));
}
else if (auto CK = dyn_cast<const comments::TParamCommandComment>(C))
{
auto TC = new TParamCommandComment();
_Comment = TC;
HandleBlockCommand(CK, TC);
if (CK->isPositionValid())
for (unsigned I = 0, E = CK->getDepth(); I != E; ++I)
TC->Position.push_back(CK->getIndex(I));
TC->paragraphComment = static_cast<ParagraphComment*>(ConvertCommentBlock(CK->getParagraph(), CI));
}
else if (auto CK = dyn_cast<const comments::VerbatimBlockComment>(C))
{
auto VB = new VerbatimBlockComment();
_Comment = VB;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
VB->Lines.push_back(static_cast<VerbatimBlockLineComment*>(ConvertCommentBlock(*I, CI)));
}
else if (auto CK = dyn_cast<const comments::VerbatimLineComment>(C))
{
auto VL = new VerbatimLineComment();
_Comment = VL;
VL->text = CK->getText().str();
}
else if (auto CK = dyn_cast<const comments::ParagraphComment>(C))
{
auto PC = new ParagraphComment();
_Comment = PC;
for (auto I = CK->child_begin(), E = CK->child_end(); I != E; ++I)
PC->Content.push_back(static_cast<InlineContentComment*>(ConvertCommentBlock(*I, CI)));
PC->isWhitespace = CK->isWhitespace();
}
else if (auto CK = dyn_cast<const comments::HTMLStartTagComment>(C))
{
auto TC = new HTMLStartTagComment();
_Comment = TC;
HandleInlineContent(CK, TC);
TC->tagName = CK->getTagName().str();
for (unsigned I = 0, E = CK->getNumAttrs(); I != E; ++I)
{
auto CK = cast<clang::comments::InlineCommandComment>(C);
auto IC = new InlineCommandComment();
_Comment = IC;
HandleInlineContent(CK, IC);
IC->commandId = CK->getCommandID();
IC->commentRenderKind = ConvertRenderKind(CK->getRenderKind());
for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I)
{
auto Arg = InlineCommandComment::Argument();
Arg.text = CK->getArgText(I).str();
IC->Arguments.push_back(Arg);
}
break;
auto A = CK->getAttr(I);
auto Attr = HTMLStartTagComment::Attribute();
Attr.name = A.Name.str();
Attr.value = A.Value.str();
TC->Attributes.push_back(Attr);
}
case Comment::VerbatimBlockLineCommentKind:
}
else if (auto CK = dyn_cast<const comments::HTMLEndTagComment>(C))
{
auto TC = new HTMLEndTagComment();
_Comment = TC;
HandleInlineContent(CK, TC);
TC->tagName = CK->getTagName().str();
}
else if (auto CK = dyn_cast<const comments::TextComment>(C))
{
auto TC = new TextComment();
_Comment = TC;
HandleInlineContent(CK, TC);
TC->text = CK->getText().str();
}
else if (auto CK = dyn_cast<const comments::InlineCommandComment>(C))
{
auto IC = new InlineCommandComment();
_Comment = IC;
HandleInlineContent(CK, IC);
IC->commandId = CK->getCommandID();
IC->commentRenderKind = ConvertRenderKind(CK->getCommandName(CI->getASTContext().getCommentCommandTraits()).str());
for (unsigned I = 0, E = CK->getNumArgs(); I != E; ++I)
{
auto CK = cast<clang::comments::VerbatimBlockLineComment>(C);
auto VL = new VerbatimBlockLineComment();
_Comment = VL;
VL->text = CK->getText().str();
break;
auto Arg = InlineCommandComment::Argument();
Arg.text = CK->getArgText(I).str();
IC->Arguments.push_back(Arg);
}
case Comment::NoCommentKind: return nullptr;
default:
llvm_unreachable("Unknown comment kind");
}
else if (auto CK = dyn_cast<const comments::VerbatimBlockLineComment>(C))
{
auto VL = new VerbatimBlockLineComment();
_Comment = VL;
VL->text = CK->getText().str();
}
else
llvm_unreachable("Unknown comment kind");
assert(_Comment && "Invalid comment instance");
return _Comment;
@ -272,7 +215,7 @@ void Parser::HandleComments(const clang::Decl* D, Declaration* Decl) @@ -272,7 +215,7 @@ void Parser::HandleComments(const clang::Decl* D, Declaration* Decl)
if (clang::comments::FullComment* FC = RC->parse(c->getASTContext(), &c->getPreprocessor(), D))
{
auto CB = static_cast<FullComment*>(ConvertCommentBlock(FC));
auto CB = static_cast<FullComment*>(ConvertCommentBlock(FC, c.get()));
RawComment->fullCommentBlock = CB;
}
}

4
src/CppParser/Link.cpp

@ -70,9 +70,9 @@ bool Parser::LinkWindows(const CppLinkerOptions* LinkerOptions, @@ -70,9 +70,9 @@ bool Parser::LinkWindows(const CppLinkerOptions* LinkerOptions,
}
const Triple& Triple = c->getTarget().getTriple();
driver::Driver D("", Triple.str(), c->getDiagnostics());
clang::driver::Driver D("", Triple.str(), c->getDiagnostics());
opt::InputArgList Args(0, 0);
driver::toolchains::MSVCToolChain TC(D, Triple, Args);
clang::driver::toolchains::MSVCToolChain TC(D, Triple, Args);
std::vector<std::string> LibraryPaths;
LibraryPaths.push_back("-libpath:" + TC.getSubDirectoryPath(

2
src/CppParser/ParseExpr.cpp

@ -2322,7 +2322,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr) @@ -2322,7 +2322,7 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
_S->hasExplicitTemplateArgs = S->hasExplicitTemplateArgs();
_S->numTemplateArgs = S->getNumTemplateArgs();
_S->requiresADL = S->requiresADL();
_S->isOverloaded = S->isOverloaded();
_S->isOverloaded = S->getNumDecls() > 1;
_Expr = _S;
break;
}

137
src/CppParser/Parser.cpp

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
#include <stdlib.h>
#include <llvm/TargetParser/Host.h>
#include <llvm/Support/ManagedStatic.h>
#include <llvm/Support/Path.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/TargetSelect.h>
@ -36,6 +37,7 @@ @@ -36,6 +37,7 @@
#include <clang/AST/Comment.h>
#include <clang/AST/DeclFriend.h>
#include <clang/AST/ExprCXX.h>
#include "clang/AST/TemplateBase.h"
#include <clang/CodeGen/CodeGenAction.h>
#include <clang/Lex/DirectoryLookup.h>
#include <clang/Lex/HeaderSearch.h>
@ -1097,15 +1099,15 @@ static TagKind ConvertToTagKind(clang::TagTypeKind AS) @@ -1097,15 +1099,15 @@ static TagKind ConvertToTagKind(clang::TagTypeKind AS)
{
switch (AS)
{
case clang::TagTypeKind::TTK_Struct:
case clang::TagTypeKind::Struct:
return TagKind::Struct;
case clang::TagTypeKind::TTK_Interface:
case clang::TagTypeKind::Interface:
return TagKind::Interface;
case clang::TagTypeKind::TTK_Union:
case clang::TagTypeKind::Union:
return TagKind::Union;
case clang::TagTypeKind::TTK_Class:
case clang::TagTypeKind::Class:
return TagKind::Class;
case clang::TagTypeKind::TTK_Enum:
case clang::TagTypeKind::Enum:
return TagKind::Enum;
}
@ -1394,17 +1396,9 @@ Parser::WalkClassTemplateSpecialization(const clang::ClassTemplateSpecialization @@ -1394,17 +1396,9 @@ Parser::WalkClassTemplateSpecialization(const clang::ClassTemplateSpecialization
CT->Specializations.push_back(TS);
auto& TAL = CTS->getTemplateArgs();
auto TSI = CTS->getTypeAsWritten();
if (TSI)
{
auto TL = TSI->getTypeLoc();
auto TSL = TL.getAs<TemplateSpecializationTypeLoc>();
TS->Arguments = WalkTemplateArgumentList(&TAL, &TSL);
}
else
{
TS->Arguments = WalkTemplateArgumentList(&TAL, (TemplateSpecializationTypeLoc*)0);
}
TemplateSpecializationTypeLoc TSL;
TS->Arguments = WalkTemplateArgumentList(&TAL, nullptr);
if (CTS->isCompleteDefinition())
{
@ -1448,13 +1442,8 @@ Parser::WalkClassTemplatePartialSpecialization(const clang::ClassTemplatePartial @@ -1448,13 +1442,8 @@ Parser::WalkClassTemplatePartialSpecialization(const clang::ClassTemplatePartial
TS->specializationKind = WalkTemplateSpecializationKind(CTS->getSpecializationKind());
CT->Specializations.push_back(TS);
auto& TAL = CTS->getTemplateArgs();
if (auto TSI = CTS->getTypeAsWritten())
{
auto TL = TSI->getTypeLoc();
auto TSL = TL.getAs<TemplateSpecializationTypeLoc>();
TS->Arguments = WalkTemplateArgumentList(&TAL, &TSL);
}
const TemplateArgumentList& TAL = CTS->getTemplateArgs();
WalkTemplateArgumentList(&TAL, nullptr);
if (CTS->isCompleteDefinition())
{
@ -1567,7 +1556,11 @@ TypeTemplateParameter* Parser::WalkTypeTemplateParameter(const clang::TemplateTy @@ -1567,7 +1556,11 @@ TypeTemplateParameter* Parser::WalkTypeTemplateParameter(const clang::TemplateTy
HandleDeclaration(TTPD, TP);
if (TTPD->hasDefaultArgument())
TP->defaultArgument = GetQualifiedType(TTPD->getDefaultArgument());
{
auto TSI = TTPD->getDefaultArgument().getTypeSourceInfo();
if (TSI)
TP->defaultArgument = GetQualifiedType(TSI->getType());
}
TP->depth = TTPD->getDepth();
TP->index = TTPD->getIndex();
TP->isParameterPack = TTPD->isParameterPack();
@ -1591,7 +1584,7 @@ NonTypeTemplateParameter* Parser::WalkNonTypeTemplateParameter(const clang::NonT @@ -1591,7 +1584,7 @@ NonTypeTemplateParameter* Parser::WalkNonTypeTemplateParameter(const clang::NonT
HandleDeclaration(NTTPD, NTP);
if (NTTPD->hasDefaultArgument())
NTP->defaultArgument = WalkExpressionObsolete(NTTPD->getDefaultArgument());
NTP->defaultArgument = WalkExpressionObsolete(NTTPD->getDefaultArgument().getSourceExpression());
NTP->type = GetQualifiedType(NTTPD->getType());
NTP->depth = NTTPD->getDepth();
NTP->index = NTTPD->getIndex();
@ -1641,6 +1634,39 @@ std::vector<TemplateArgument> Parser::WalkTemplateArgumentList(const clang::Temp @@ -1641,6 +1634,39 @@ std::vector<TemplateArgument> Parser::WalkTemplateArgumentList(const clang::Temp
//-----------------------------------//
template <typename TypeLoc>
std::vector<TemplateArgument> Parser::WalkTemplateArgumentList(
llvm::ArrayRef<clang::TemplateArgument> TAL, TypeLoc* TSTL)
{
using namespace clang;
const bool LocValid = TSTL && !TSTL->isNull() && TSTL->getTypePtr();
std::vector<AST::TemplateArgument> params;
const size_t typeLocNumArgs = LocValid ? TSTL->getNumArgs() : 0;
for (size_t i = 0, e = TAL.size(); i < e; ++i)
{
const clang::TemplateArgument& TA = TAL[i];
TemplateArgumentLoc TArgLoc;
TemplateArgumentLoc* ArgLoc = nullptr;
if (i < typeLocNumArgs && e == typeLocNumArgs)
{
TArgLoc = TSTL->getArgLoc(i);
ArgLoc = &TArgLoc;
}
auto Arg = WalkTemplateArgument(TA, ArgLoc);
params.push_back(Arg);
}
return params;
}
//-----------------------------------//
std::vector<TemplateArgument>
Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL,
const clang::ASTTemplateArgumentListInfo* TALI)
@ -1893,7 +1919,7 @@ Parser::WalkVarTemplateSpecialization(const clang::VarTemplateSpecializationDecl @@ -1893,7 +1919,7 @@ Parser::WalkVarTemplateSpecialization(const clang::VarTemplateSpecializationDecl
VT->Specializations.push_back(TS);
auto& TAL = VTS->getTemplateArgs();
auto TSI = VTS->getTypeAsWritten();
auto TSI = VTS->getTypeSourceInfo();
if (TSI)
{
auto TL = TSI->getTypeLoc();
@ -1933,7 +1959,7 @@ Parser::WalkVarTemplatePartialSpecialization(const clang::VarTemplatePartialSpec @@ -1933,7 +1959,7 @@ Parser::WalkVarTemplatePartialSpecialization(const clang::VarTemplatePartialSpec
VT->Specializations.push_back(TS);
auto& TAL = VTS->getTemplateArgs();
if (auto TSI = VTS->getTypeAsWritten())
if (auto TSI = VTS->getTypeSourceInfo())
{
auto TL = TSI->getTypeLoc();
auto TSL = TL.getAs<TemplateSpecializationTypeLoc>();
@ -2812,11 +2838,9 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool @@ -2812,11 +2838,9 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool
if (TS->isSugared())
TST->desugared = GetQualifiedType(TS->getCanonicalTypeInternal(), TL);
TemplateArgumentList TArgs(TemplateArgumentList::OnStack, TS->template_arguments());
if (!LocValid)
{
TST->Arguments = WalkTemplateArgumentList(&TArgs, (TemplateSpecializationTypeLoc*)nullptr);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), (TemplateSpecializationTypeLoc*)nullptr);
Ty = TST;
break;
}
@ -2840,21 +2864,21 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool @@ -2840,21 +2864,21 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool
case TypeLoc::DependentTemplateSpecialization:
{
DependentTemplateSpecializationTypeLoc TSpecTL = TL->getAs<DependentTemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), &TSpecTL);
Ty = TST;
break;
}
case TypeLoc::TemplateSpecialization:
{
TemplateSpecializationTypeLoc TSpecTL = TL->getAs<TemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), &TSpecTL);
Ty = TST;
break;
}
case TypeLoc::TemplateTypeParm:
{
TemplateTypeParmTypeLoc TTPTL = TL->getAs<TemplateTypeParmTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, (TemplateSpecializationTypeLoc*)nullptr);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), (TemplateSpecializationTypeLoc*)nullptr);
break;
}
default:
@ -2873,11 +2897,9 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool @@ -2873,11 +2897,9 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool
if (TS->isSugared())
TST->desugared = GetQualifiedType(TS->getCanonicalTypeInternal(), TL);
TemplateArgumentList TArgs(TemplateArgumentList::OnStack, TS->template_arguments());
if (!LocValid)
{
TST->Arguments = WalkTemplateArgumentList(&TArgs, (DependentTemplateSpecializationTypeLoc*)nullptr);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), (DependentTemplateSpecializationTypeLoc*)nullptr);
Ty = TST;
break;
}
@ -2901,18 +2923,18 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool @@ -2901,18 +2923,18 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool
case TypeLoc::DependentTemplateSpecialization:
{
DependentTemplateSpecializationTypeLoc TSpecTL = TL->getAs<DependentTemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), &TSpecTL);
break;
}
case TypeLoc::TemplateSpecialization:
{
TemplateSpecializationTypeLoc TSpecTL = TL->getAs<TemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), &TSpecTL);
break;
}
case TypeLoc::TemplateTypeParm:
{
TST->Arguments = WalkTemplateArgumentList(&TArgs, (DependentTemplateSpecializationTypeLoc*)nullptr);
TST->Arguments = WalkTemplateArgumentList(TS->template_arguments(), (DependentTemplateSpecializationTypeLoc*)nullptr);
break;
}
default:
@ -3510,7 +3532,7 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F) @@ -3510,7 +3532,7 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F)
F->isConstExpr = FD->isConstexpr();
F->isVariadic = FD->isVariadic();
F->isDependent = FD->isDependentContext();
F->isPure = FD->isPure();
F->isPure = FD->isPureVirtual();
F->isDeleted = FD->isDeleted();
F->isDefaulted = FD->isDefaulted();
SetBody(FD, F);
@ -4476,7 +4498,6 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D) @@ -4476,7 +4498,6 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D)
break;
}
case Decl::BuiltinTemplate:
case Decl::ClassScopeFunctionSpecialization:
case Decl::PragmaComment:
case Decl::PragmaDetectMismatch:
case Decl::Empty:
@ -4614,31 +4635,31 @@ void Parser::SetupLLVMCodegen() @@ -4614,31 +4635,31 @@ void Parser::SetupLLVMCodegen()
}
bool Parser::SetupSourceFiles(const std::vector<std::string>& SourceFiles,
std::vector<const clang::FileEntry*>& FileEntries)
std::vector<clang::OptionalFileEntryRef>& FileEntries)
{
// Check that the file is reachable.
clang::ConstSearchDirIterator* Dir = 0;
llvm::ArrayRef<std::pair<const clang::FileEntry*, clang::DirectoryEntryRef>> Includers;
clang::ConstSearchDirIterator* Dir = nullptr;
llvm::ArrayRef<std::pair<clang::OptionalFileEntryRef, clang::DirectoryEntryRef>> EmptyIncluders;
for (const auto& SourceFile : SourceFiles)
{
auto FileEntry = c->getPreprocessor().getHeaderSearchInfo().LookupFile(SourceFile,
clang::SourceLocation(), /*isAngled*/ true,
nullptr, Dir, Includers, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
auto FileEntry = c->getPreprocessor().getHeaderSearchInfo().LookupFile(
SourceFile,
clang::SourceLocation(),
/*isAngled*/ true,
nullptr, Dir,
EmptyIncluders,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (!FileEntry)
return false;
FileEntries.push_back(&FileEntry.getPointer()->getFileEntry());
FileEntries.push_back(FileEntry);
}
// Create a virtual file that includes the header. This gets rid of some
// Clang warnings about parsing an header file as the main file.
std::string source;
for (const auto& SourceFile : SourceFiles)
{
source += "#include \"" + SourceFile + "\"" + "\n";
source += "#include \"" + SourceFile + "\"\n";
}
source += "\0";
@ -4652,7 +4673,7 @@ bool Parser::SetupSourceFiles(const std::vector<std::string>& SourceFiles, @@ -4652,7 +4673,7 @@ bool Parser::SetupSourceFiles(const std::vector<std::string>& SourceFiles,
class SemaConsumer : public clang::SemaConsumer
{
public:
SemaConsumer(Parser& parser, std::vector<const clang::FileEntry*>& entries)
SemaConsumer(Parser& parser, std::vector<clang::OptionalFileEntryRef>& entries)
: Parser(parser)
, FileEntries(entries)
{
@ -4662,7 +4683,7 @@ public: @@ -4662,7 +4683,7 @@ public:
private:
Parser& Parser;
std::vector<const clang::FileEntry*>& FileEntries;
std::vector<clang::OptionalFileEntryRef>& FileEntries;
};
void SemaConsumer::HandleTranslationUnit(clang::ASTContext& Ctx)
@ -4675,7 +4696,7 @@ void SemaConsumer::HandleTranslationUnit(clang::ASTContext& Ctx) @@ -4675,7 +4696,7 @@ void SemaConsumer::HandleTranslationUnit(clang::ASTContext& Ctx)
Parser.HandleDeclaration(TU, Unit);
if (Unit->originalPtr == nullptr)
Unit->originalPtr = (void*)FileEntry;
Unit->originalPtr = (void*)&FileEntry->getFileEntry();
Parser.WalkAST(TU);
}
@ -4695,7 +4716,7 @@ ParserResult* Parser::Parse(const std::vector<std::string>& SourceFiles) @@ -4695,7 +4716,7 @@ ParserResult* Parser::Parse(const std::vector<std::string>& SourceFiles)
Setup();
SetupLLVMCodegen();
std::vector<const clang::FileEntry*> FileEntries;
std::vector<clang::OptionalFileEntryRef> FileEntries;
if (!SetupSourceFiles(SourceFiles, FileEntries))
{
res->kind = ParserResultKind::FileNotFound;
@ -4829,7 +4850,7 @@ ParserResultKind Parser::ParseSharedLib(const std::string& File, @@ -4829,7 +4850,7 @@ ParserResultKind Parser::ParseSharedLib(const std::string& File,
for (const auto& ImportedSymbol : COFFObjectFile->import_directories())
{
llvm::StringRef Name;
if (!ImportedSymbol.getName(Name) && (Name.endswith(".dll") || Name.endswith(".DLL")))
if (!ImportedSymbol.getName(Name) && (Name.ends_with(".dll") || Name.ends_with(".DLL")))
NativeLib->Dependencies.push_back(Name.str());
}

4
src/CppParser/Parser.h

@ -70,7 +70,7 @@ namespace CppSharp { namespace CppParser { @@ -70,7 +70,7 @@ namespace CppSharp { namespace CppParser {
void SetupLLVMCodegen();
bool SetupSourceFiles(const std::vector<std::string>& SourceFiles,
std::vector<const clang::FileEntry*>& FileEntries);
std::vector<clang::OptionalFileEntryRef>& FileEntries);
bool IsSupported(const clang::NamedDecl* ND);
bool IsSupported(const clang::CXXMethodDecl* MD);
@ -114,6 +114,8 @@ namespace CppSharp { namespace CppParser { @@ -114,6 +114,8 @@ namespace CppSharp { namespace CppParser {
WalkVarTemplatePartialSpecialization(const clang::VarTemplatePartialSpecializationDecl* VTS);
template <typename TypeLoc>
std::vector<AST::TemplateArgument> WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, TypeLoc* TSTL);
template <typename TypeLoc>
std::vector<AST::TemplateArgument> WalkTemplateArgumentList(llvm::ArrayRef<clang::TemplateArgument> TAL,TypeLoc* TSTL);
std::vector<AST::TemplateArgument> WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, const clang::ASTTemplateArgumentListInfo* TSTL);
void WalkVTable(const clang::CXXRecordDecl* RD, AST::Class* C);
AST::QualifiedType GetQualifiedType(clang::QualType qual, const clang::TypeLoc* TL = 0);

Loading…
Cancel
Save