Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/beta/include/tree_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TreeBuilder {
void BuildClassTemplateDecl(clang::ClassTemplateDecl* Decl);
void BuildClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl* Decl);
void BuildClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl* Decl);
void BuildTypeAliasDecl(clang::TypeAliasDecl* Decl);
bool BuildTypeAliasDecl(clang::TypeAliasDecl* Decl);
void BuildUsingDecl(clang::UsingDecl* Decl);
void BuildUsingDirectiveDecl(clang::UsingDirectiveDecl* Decl);
void BuildNamespaceAliasDecl(clang::NamespaceAliasDecl* Decl);
Expand Down
3 changes: 1 addition & 2 deletions src/beta/src/astnormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ bool beta::ASTNormalize::VisitFunctionDecl(clang::FunctionDecl *Decl) {
}

bool beta::ASTNormalize::VisitTypeAliasDecl(clang::TypeAliasDecl *Decl) {
treeBuilder.BuildTypeAliasDecl(Decl);
return true;
return treeBuilder.BuildTypeAliasDecl(Decl);
}

bool beta::ASTNormalize::VisitTypedefDecl(clang::TypedefDecl *Decl) {
Expand Down
42 changes: 39 additions & 3 deletions src/beta/src/tree_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,13 +1018,49 @@ void beta::TreeBuilder::BuildClassTemplatePartialSpecializationDecl(clang::Class
processUnhandledDecl(Decl);
}

void beta::TreeBuilder::BuildTypeAliasDecl(clang::TypeAliasDecl* Decl) {
if (!IsDeclFromMainFileAndNotLocal(Decl) || isWrittenInTemplatedClass(Decl)) return;
bool beta::TreeBuilder::BuildTypeAliasDecl(clang::TypeAliasDecl* Decl) {

if(!IsDeclFromMainFileAndNotLocal(Decl) || isInTemplatedClass(Decl) || Decl->isTemplated()){
if(IsDeclFromMainFileAndNotLocal(Decl) && !isWrittenInTemplatedClass(Decl)){
armor::debug() << "Excluding TypeAliasDecl\n";
TEST_LOG << "TypeAliasDecl\n";
processUnhandledDecl(Decl);
}
return false;
}

processUnhandledDecl(Decl);
const std::string USR = ::generateUSRForDecl(Decl);
if( context->usrNodeMap.find(USR) != context->usrNodeMap.end() ) return true;
llvm::SmallString<128> nameBuf;
llvm::raw_svector_ostream OS(nameBuf);
const clang::QualType underlyingType = Decl->getUnderlyingType();
auto typeDefNode = std::make_shared<armor::APINode>();
Decl->printName(OS);
PushName(nameBuf);
typeDefNode->qualifiedName = GetCurrentQualifiedName();
typeDefNode->kind = NodeKind::Typedef;
auto [dataType, canonicalType] = getTypesWithAndWithoutTypeResolution(underlyingType, Decl->getASTContext());
typeDefNode->dataType = dataType;
typeDefNode->caonicalType = canonicalType;
typeDefNode->USR = USR;
typeDefNode->NSR = ::generateNSRForDecl(Decl);
typeDefNode->access = getAccessSpecifier(Decl->getAccess());
context->usrNodeMap.insert_or_assign(std::move(USR), typeDefNode);
armor::debug() << "VisitTypeAliasDecl V2: " << typeDefNode->qualifiedName << "\n";
if (!llvm::isa<clang::TypedefType>(underlyingType)) {
if (const clang::TypeSourceInfo *TSI = Decl->getTypeSourceInfo()) {
auto [typeModifiers,unwrappedTL] = unwrapTypeLoc(TSI->getTypeLoc());
if (const clang::FunctionProtoTypeLoc FTL = unwrappedTL.getAs<clang::FunctionProtoTypeLoc>()) {
typeDefNode->dataType = std::string{};
PushNode(typeDefNode);
normalizeFunctionPointerType(typeModifiers, FTL, Decl);
PopNode();
}
}
}
PopName();
AddNode(typeDefNode);
return true;
}

void beta::TreeBuilder::BuildUsingDecl(clang::UsingDecl* Decl) {
Expand Down
10 changes: 10 additions & 0 deletions src/common/src/custom_usr_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class USRGenerator : public ConstDeclVisitor<USRGenerator> {
void VisitClassTemplateDecl(const ClassTemplateDecl *D);
void VisitTagDecl(const TagDecl *D);
void VisitTypedefDecl(const TypedefDecl *D);
void VisitTypeAliasDecl(const TypeAliasDecl *D);
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
void VisitVarDecl(const VarDecl *D);
void VisitFriendDecl(const FriendDecl *D);
Expand Down Expand Up @@ -531,6 +532,15 @@ void USRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
Out << "@T@";
Out << D->getName();
}
void USRGenerator::VisitTypeAliasDecl(const TypeAliasDecl *D) {
if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
const DeclContext *DC = D->getDeclContext();
if (const NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Visit(DCN);
Out << "@T@";
Out << D->getName();
}

void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
GenLoc(D, /*IncludeOffset=*/true);
Expand Down
10 changes: 10 additions & 0 deletions src/common/src/nsr_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class NSRGenerator : public ConstDeclVisitor<NSRGenerator> {
void VisitClassTemplateDecl(const ClassTemplateDecl *D);
void VisitTagDecl(const TagDecl *D);
void VisitTypedefDecl(const TypedefDecl *D);
void VisitTypeAliasDecl(const TypeAliasDecl *D);
// void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
void VisitVarDecl(const VarDecl *D);
void VisitFriendDecl(const FriendDecl *D);
Expand Down Expand Up @@ -528,6 +529,15 @@ void NSRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
Out << "@T@";
Out << D->getName();
}
void NSRGenerator::VisitTypeAliasDecl(const TypeAliasDecl *D) {
if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
const DeclContext *DC = D->getDeclContext();
if (const NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Visit(DCN);
Out << "@T@";
Out << D->getName();
}

// void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
// GenLoc(D, /*IncludeOffset=*/true);
Expand Down
9 changes: 9 additions & 0 deletions src/common/src/qualified_name_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class USRGenerator : public ConstDeclVisitor<USRGenerator> {
void VisitClassTemplateDecl(const ClassTemplateDecl *D);
void VisitTagDecl(const TagDecl *D);
void VisitTypedefDecl(const TypedefDecl *D);
void VisitTypeAliasDecl(const TypeAliasDecl *D);
void VisitVarDecl(const VarDecl *D);
void VisitBindingDecl(const BindingDecl *D);
void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
Expand Down Expand Up @@ -323,6 +324,14 @@ void USRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
Out << D->getName();
}

void USRGenerator::VisitTypeAliasDecl(const TypeAliasDecl *D) {
const unsigned startSize = Buf.size();
const DeclContext *DC = D->getDeclContext();
if (const NamedDecl *DCN = dyn_cast<NamedDecl>(DC)) Visit(DCN);
const unsigned endSize = Buf.size();
startSize == endSize ? Out : Out << "::";
Out << D->getName();
}
void USRGenerator::GenExtSymbolContainer(const NamedDecl *D) {
StringRef Container = GetExternalSourceContainer(D);
if (!Container.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@
2354681959671418142
// End of mylib.h - Compact version with preprocessing, templates, classes, structs, unions
----------------------------------------
TypeAliasDecl
4778056794275737411
using byte_t = uint8_t
----------------------------------------
TypeAliasDecl
12067307721732456158
using size_type = std::size_t
----------------------------------------
EnumConst
ErrorCode:SUCCESS
Get the actual end location (after the last token) startOffset == endOffset
Expand Down Expand Up @@ -712,14 +704,6 @@ processData
2354681959671418142
// End of mylib.h - Compact version with preprocessing, templates, classes, structs, unions
----------------------------------------
TypeAliasDecl
4778056794275737411
using byte_t = uint8_t
----------------------------------------
TypeAliasDecl
12067307721732456158
using size_type = std::size_t
----------------------------------------
EnumConst
ErrorCode:SUCCESS
Get the actual end location (after the last token) startOffset == endOffset
Expand Down Expand Up @@ -1182,7 +1166,6 @@ comments1
1748340414771073951 : 1
----------------------------------------
unhandledDecls1
11044959451838826049 : 1
5527843489271040135 : 1
1567017602521651188 : 1
5323582179407016097 : 1
Expand All @@ -1197,7 +1180,6 @@ unhandledDecls1
10705571255276855191 : 4
10585965716865580119 : 1
7497696533842709105 : 1
12067307721732456158 : 1
1402593494274183058 : 1
13074568307166890559 : 1
14191502057406420813 : 1
Expand All @@ -1212,12 +1194,12 @@ unhandledDecls1
4504840211387841570 : 1
15464300162902583911 : 1
8068769666068225577 : 1
4778056794275737411 : 1
13117341127079206593 : 1
12700262454154676125 : 1
8733956534700832650 : 1
15173472626001195300 : 1
15219203312359965853 : 1
13117341127079206593 : 1
11044959451838826049 : 1
9884558697256544607 : 1
15521860531219160998 : 3
8717144482643656166 : 1
Expand Down Expand Up @@ -1278,7 +1260,6 @@ comments2
1748340414771073951 : 1
----------------------------------------
unhandledDecls2
11044959451838826049 : 1
5527843489271040135 : 1
1567017602521651188 : 1
5323582179407016097 : 1
Expand All @@ -1292,7 +1273,6 @@ unhandledDecls2
11687501982600197290 : 1
10705571255276855191 : 4
10585965716865580119 : 1
12067307721732456158 : 1
1402593494274183058 : 1
13074568307166890559 : 1
14191502057406420813 : 1
Expand All @@ -1307,12 +1287,12 @@ unhandledDecls2
4504840211387841570 : 1
15464300162902583911 : 1
8068769666068225577 : 1
4778056794275737411 : 1
13117341127079206593 : 1
12700262454154676125 : 1
8733956534700832650 : 1
15173472626001195300 : 1
15219203312359965853 : 1
13117341127079206593 : 1
11044959451838826049 : 1
618311601172597535 : 1
9884558697256544607 : 1
15521860531219160998 : 3
Expand Down
84 changes: 84 additions & 0 deletions src/tests/beta/functional/complex_chains/expected_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[
{
"children": [
{
"dataType": "unsigned int",
"nodeType": "Enumerator",
"qualifiedName": "StatusCode::STATUS_OK"
},
{
"dataType": "unsigned int",
"nodeType": "Enumerator",
"qualifiedName": "StatusCode::STATUS_FAIL"
},
{
"dataType": "unsigned int",
"nodeType": "Enumerator",
"qualifiedName": "StatusCode::STATUS_PENDING"
}
],
"nodeType": "Enum",
"qualifiedName": "StatusCode",
"tag": "removed"
},
{
"children": [
{
"dataType": "StatusCode",
"nodeType": "Typedef",
"qualifiedName": "StatusCode",
"tag": "removed"
},
{
"dataType": "enum StatusCodeEnum",
"nodeType": "Typedef",
"qualifiedName": "StatusCode",
"tag": "added"
}
],
"nodeType": "Typedef",
"qualifiedName": "StatusCode",
"tag": "modified"
},
{
"children": [
{
"dataType": "short",
"nodeType": "Typedef",
"qualifiedName": "size_base_t",
"tag": "removed"
},
{
"dataType": "int",
"nodeType": "Typedef",
"qualifiedName": "size_base_t",
"tag": "added"
}
],
"nodeType": "Typedef",
"qualifiedName": "size_base_t",
"tag": "modified"
},
{
"children": [
{
"dataType": "unsigned int",
"nodeType": "Enumerator",
"qualifiedName": "StatusCodeEnum::STATUS_OK"
},
{
"dataType": "unsigned int",
"nodeType": "Enumerator",
"qualifiedName": "StatusCodeEnum::STATUS_FAIL"
},
{
"dataType": "unsigned int",
"nodeType": "Enumerator",
"qualifiedName": "StatusCodeEnum::STATUS_PENDING"
}
],
"nodeType": "Enum",
"qualifiedName": "StatusCodeEnum",
"tag": "added"
}
]
29 changes: 29 additions & 0 deletions src/tests/beta/functional/complex_chains/test_complex_chains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
import os
import json
import subprocess
from deepdiff import DeepDiff


def test_ast_diff(binary_path, binary_args, request):

test_dir = os.path.dirname(request.fspath)

subprocess.run(
[binary_path] + binary_args,
check=True,
cwd=os.path.dirname(request.fspath)
)

print(test_dir)

with open(f'{test_dir}/expected_output.json', 'r') as f:
expected_json = json.load(f)

with open(f'{test_dir}/debug_output/ast_diffs/ast_diff_output_mylib.h.json', 'r') as f:
actual_json = json.load(f)

diff = DeepDiff(expected_json, actual_json['astDiff'], ignore_order=True)

assert diff == {}
Loading
Loading