Skip to content

Commit

Permalink
Added vcpkg baseline; Updates for clang 18; Worked around stack overl…
Browse files Browse the repository at this point in the history
…ow in keyvault admin on debug builds (#8749)

* Added vcpkg baseline; Updates for clang 18; Worked around stack overflow in keyvault admin on debug builds

* Removed debug code

* Added a comment explaining why the stack needs to be bigger

* Added error on using namespace in header because it can easily lead to duplicate errors
  • Loading branch information
LarryOsterman authored Sep 10, 2024
1 parent 10528ec commit 58d1f21
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 85 deletions.
111 changes: 89 additions & 22 deletions tools/apiview/parsers/cpp-api-parser/ApiViewProcessor/AstNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@
#include "AstNode.hpp"
#include "CommentExtractor.hpp"
#include "ProcessorImpl.hpp"
#include "clang/AST/ASTConsumer.h"
#include <clang/AST/Comment.h>
#include <clang/AST/CommentVisitor.h>
#include <clang/AST/Expr.h>
#include <clang/AST/ExprCXX.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/AST/Type.h>
#include <clang/AST/TypeVisitor.h>
#include <iostream>
#include <iterator>
#include <list>
#include <vector>

Expand Down Expand Up @@ -1041,7 +1033,7 @@ class AstAttribute : public AstNode {
}
switch (m_syntax)
{
case Attr::Syntax::AS_C2x:
case Attr::Syntax::AS_C23:
case Attr::Syntax::AS_CXX11:
dumper->InsertPunctuation('[');
dumper->InsertPunctuation('[');
Expand Down Expand Up @@ -1072,7 +1064,7 @@ class AstAttribute : public AstNode {
}
switch (m_syntax)
{
case Attr::Syntax::AS_C2x:
case Attr::Syntax::AS_C23:
case Attr::Syntax::AS_CXX11:
dumper->InsertPunctuation('[');
dumper->InsertPunctuation('[');
Expand Down Expand Up @@ -1318,10 +1310,62 @@ static std::string GetNavigationId(clang::FunctionDecl const* func)
return navigationId;
}

static std::string GetNavigationId(clang::CXXRecordDecl const* record)
{
return record->getQualifiedNameAsString();
}

/**
* Get the navigation ID for a qualified type declaration.
*
* The navigation ID uniquely
* identifies a declaration in the ApiView. For qualified type
* declarations, we want to include
* the full type name, including the namespace.
*
* @param type The type to get the navigation ID
* for.
* @return The navigation ID for the type.
*
*/
static std::string GetNavigationId(clang::QualType const& type)
{
std::string navigationId;
clang::PrintingPolicy pp{LangOptions{}};
pp.adjustForCPlusPlus();
pp.FullyQualifiedName = true;
pp.TerseOutput = true;
llvm::raw_string_ostream os(navigationId);

type.print(os, pp);
return navigationId;
}

/**
* Get the navigation ID for a friend declaration.
*
* The navigation ID uniquely identifies a
* declaration in the ApiView. For friend declarations, we
* want to include the navigation ID of
* the parent node, followed by "_friend_", followed by the
* navigation ID of the friend
* declaration.
*
* @param friendDecl The friend declaration to get the navigation ID for.
* @param
* parentNodeNavigationId The navigation ID of the parent node.
* @return The navigation ID for the
* friend declaration.
*
*/
static std::string GetNavigationId(
clang::FriendDecl const* friendDecl,
std::string const& parentNodeNavigationId)
{
if (parentNodeNavigationId.empty())
{
llvm::errs() << "Parent node navigation ID is empty\n";
}
std::string navigationId = parentNodeNavigationId + "_friend_";
auto dc = friendDecl->getFriendDecl();
if (dc)
Expand All @@ -1334,10 +1378,11 @@ static std::string GetNavigationId(
else if (isa<CXXRecordDecl>(dc))
{
auto rd = cast<CXXRecordDecl>(dc);
navigationId += rd->getQualifiedNameAsString();
navigationId += GetNavigationId(rd);
}
else
{
llvm::errs() << "Unknown friend declaration type.\n";
dc->dump(llvm::outs());
}
}
Expand All @@ -1346,11 +1391,13 @@ static std::string GetNavigationId(
auto friendType = friendDecl->getFriendType();
if (friendType)
{
navigationId += GetNavigationId(friendType->getType());
navigationId
+= QualType::getAsString(friendDecl->getFriendType()->getType().split(), LangOptions{});
}
else
{
llvm::errs() << "Unknown friend declaration.\n";
friendDecl->dump(llvm::outs());
}
}
Expand Down Expand Up @@ -2040,7 +2087,7 @@ class AstMethod : public AstFunction {
AzureClassesDatabase* const database,
std::shared_ptr<TypeHierarchy::TypeHierarchyNode> parentNode)
: AstFunction(method, database, parentNode), m_isVirtual(method->isVirtual()),
m_isPure(method->isPure()), m_isConst(method->isConst())
m_isPure(method->isPureVirtual()), m_isConst(method->isConst())
{
// We assume that this is an implicit override if there are overriden methods. If we later
// find an override attribute, we know it's not an implicit override.
Expand Down Expand Up @@ -2377,23 +2424,23 @@ class AstClassLike : public AstNamedNode {
switch (m_tagUsed)
{
/// The "struct" keyword.
case TTK_Struct:
case TagDecl::TagKind::Struct:
dumper->InsertKeyword("struct");
break;
/// The "__interface" keyword.
case TTK_Interface:
case TagDecl::TagKind::Interface:
dumper->InsertKeyword("__interface");
break;
/// The "union" keyword.
case TTK_Union:
case TagDecl::TagKind::Union:
dumper->InsertKeyword("union");
break;
/// The "class" keyword.
case TTK_Class:
case TagDecl::TagKind::Class:
dumper->InsertKeyword("class");
break;
/// The "enum" keyword.
case TTK_Enum:
case TagDecl::TagKind::Enum:
dumper->InsertKeyword("enum");
break;
default:
Expand Down Expand Up @@ -2828,6 +2875,26 @@ class AstUsingDirective : public AstNode {
: AstNode(), m_namedNamespace{
usingDirective->getNominatedNamespaceAsWritten()->getQualifiedNameAsString()}
{

// Determine the location for the error message.
auto location = usingDirective->getLocation();
auto const& sourceManager = usingDirective->getASTContext().getSourceManager();
auto const& presumedLocation = sourceManager.getPresumedLoc(location);
std::string typeLocation{presumedLocation.getFilename()};

// Remove the root directory from the location if the location is within the root directory.
if (typeLocation.find(azureClassesDatabase->GetProcessor()->RootDirectory()) == 0)
{
typeLocation.erase(0, azureClassesDatabase->GetProcessor()->RootDirectory().size() + 1);
}

typeLocation += ":" + std::to_string(presumedLocation.getLine());
typeLocation += ":" + std::to_string(presumedLocation.getColumn());

llvm::errs() << raw_ostream::Colors::RED
<< "Found `using namespace` directive in public headers for `m_namedNamespace`, "
"at location " << typeLocation << raw_ostream::Colors::RESET << "\n";

azureClassesDatabase->CreateApiViewMessage(
ApiViewMessages::UsingDirectiveFound, m_namedNamespace);
}
Expand Down Expand Up @@ -2978,19 +3045,19 @@ AstClassLike::AstClassLike(
TypeHierarchy::TypeHierarchyClass classType;
switch (m_tagUsed)
{
case TagDecl::TagKind::TTK_Class:
case TagDecl::TagKind::Class:
classType = TypeHierarchy::TypeHierarchyClass::Class;
break;
case TagDecl::TagKind::TTK_Enum:
case TagDecl::TagKind::Enum:
classType = TypeHierarchy::TypeHierarchyClass::Enum;
break;
case TagDecl::TagKind::TTK_Interface:
case TagDecl::TagKind::Interface:
classType = TypeHierarchy::TypeHierarchyClass::Interface;
break;
case TagDecl::TagKind::TTK_Struct:
case TagDecl::TagKind::Struct:
classType = TypeHierarchy::TypeHierarchyClass::Struct;
break;
case TagDecl::TagKind::TTK_Union:
case TagDecl::TagKind::Union:
classType = TypeHierarchy::TypeHierarchyClass::Unknown;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ clangSerialization
clangTooling
clangEdit
clangAnalysis
clangApiNotes
clangASTMatchers
)

Expand All @@ -61,6 +62,7 @@ endforeach()
#message(STATUS "llvm_libs: ${llvm_libs}")
#message(STATUS "clang_libs: ${clang_libs}")


target_link_libraries(ApiViewProcessor
PUBLIC
${llvm_libs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,17 @@ struct AstInlineCommand : AstDocumentation
std::string commandRenderMarkdownEnd;
switch (comment->getRenderKind())
{
case clang::comments::InlineCommandComment::RenderKind::RenderNormal:
case clang::comments::InlineCommandRenderKind::Normal:
break;
case clang::comments::InlineCommandComment::RenderKind::RenderBold:
case clang::comments::InlineCommandRenderKind::Bold:
commandRenderMarkdownEnd = "**";
commandRenderMarkdownStart = "**";
break;
case clang::comments::InlineCommandComment::RenderKind::RenderEmphasized:
case clang::comments::InlineCommandRenderKind::Emphasized:
commandRenderMarkdownEnd = "*";
commandRenderMarkdownStart = "*";
break;
case clang::comments::InlineCommandComment::RenderKind::RenderMonospaced:
case clang::comments::InlineCommandRenderKind::Monospaced:
commandRenderMarkdownEnd = "`";
commandRenderMarkdownStart = "`";
break;
Expand Down Expand Up @@ -617,37 +617,37 @@ std::unique_ptr<AstDocumentation> AstDocumentation::Create(const comments::Comme
{
switch (comment->getCommentKind())
{
case comments::Comment::CommentKind::FullCommentKind:
case comments::CommentKind::FullComment:
return std::make_unique<AstComment>(cast<const comments::FullComment>(comment));
case comments::Comment::CommentKind::BlockCommandCommentKind:
case comments::CommentKind::BlockCommandComment:
return std::make_unique<AstBlockCommandComment>(
cast<const comments::BlockCommandComment>(comment));
case comments::Comment::CommentKind::ParamCommandCommentKind:
case comments::CommentKind::ParamCommandComment:
return std::make_unique<AstParamComment>(cast<const comments::ParamCommandComment>(comment));
case comments::Comment::CommentKind::TParamCommandCommentKind:
case comments::CommentKind::TParamCommandComment:
return std::make_unique<AstTParamComment>(
cast<const comments::TParamCommandComment>(comment));
case comments::Comment::CommentKind::VerbatimBlockCommentKind:
case comments::CommentKind::VerbatimBlockComment:
return std::make_unique<AstVerbatimBlockComment>(
cast<const comments::VerbatimBlockComment>(comment));
case comments::Comment::CommentKind::InlineCommandCommentKind:
case comments::CommentKind::InlineCommandComment:
return std::make_unique<AstInlineCommand>(
cast<const comments::InlineCommandComment>(comment));
case comments::Comment::ParagraphCommentKind:
case comments::CommentKind::ParagraphComment:
return std::make_unique<AstParagraphComment>(cast<const comments::ParagraphComment>(comment));
case comments::Comment::TextCommentKind:
case comments::CommentKind::TextComment:
return std::make_unique<AstTextComment>(cast<const comments::TextComment>(comment));
case comments::Comment::VerbatimBlockLineCommentKind:
case comments::CommentKind::VerbatimBlockLineComment:
return std::make_unique<AstVerbatimBlockLineComment>(
cast<const comments::VerbatimBlockLineComment>(comment));
case comments::Comment::VerbatimLineCommentKind:
case comments::CommentKind::VerbatimLineComment:
return std::make_unique<AstVerbatimLineComment>(
cast<const comments::VerbatimLineComment>(comment));

case comments::Comment::HTMLStartTagCommentKind:
case comments::CommentKind::HTMLStartTagComment:
return std::make_unique<AstHtmlStartTagComment>(
cast<const comments::HTMLStartTagComment>(comment));
case comments::Comment::HTMLEndTagCommentKind:
case comments::CommentKind::HTMLEndTagComment:
return std::make_unique<AstHtmlEndTagComment>(
cast<const comments::HTMLEndTagComment>(comment));

Expand Down
Loading

0 comments on commit 58d1f21

Please sign in to comment.