@@ -62,6 +62,25 @@ static void addInfo(uint64_t id, std::unordered_map<uint64_t, Info> &someMap, In
6262 }
6363}
6464
65+ std::string TypesResolver::getFullname (const clang::TagDecl *TD, const clang::QualType &canonicalType,
66+ uint64_t id, const fs::path &sourceFilePath) {
67+ auto pp = clang::PrintingPolicy (clang::LangOptions ());
68+ pp.SuppressTagKeyword = true ;
69+ std::string currentStructName = canonicalType.getNonReferenceType ().getUnqualifiedType ().getAsString (pp);
70+ fullname.insert (std::make_pair (id, currentStructName));
71+
72+ if (Paths::getSourceLanguage (sourceFilePath) == utbot::Language::C) {
73+ if (const clang::RecordDecl *parentNode = llvm::dyn_cast<const clang::RecordDecl>(TD->getLexicalParent ())) {
74+ clang::QualType parentCanonicalType = parentNode->getASTContext ().getTypeDeclType (parentNode).getCanonicalType ();
75+ uint64_t parentID = types::Type::getIdFromCanonicalType (parentCanonicalType);
76+ if (!fullname[parentID].empty ()) {
77+ fullname[id] = fullname[parentID] + " ::" + fullname[id];
78+ }
79+ }
80+ }
81+ return fullname[id];
82+ }
83+
6584void TypesResolver::resolveStruct (const clang::RecordDecl *D, const std::string &name) {
6685 clang::ASTContext const &context = D->getASTContext ();
6786 clang::SourceManager const &sourceManager = context.getSourceManager ();
@@ -71,14 +90,15 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
7190 if (!isCandidateToReplace (id, parent->projectTypes ->structs , name)) {
7291 return ;
7392 }
93+
7494 types::StructInfo structInfo;
7595 fs::path filename =
7696 sourceManager.getFilename (sourceManager.getSpellingLoc (D->getLocation ())).str ();
97+ fs::path sourceFilePath = sourceManager.getFileEntryForID (sourceManager.getMainFileID ())->tryGetRealPathName ().str ();
7798 structInfo.filePath = Paths::getCCJsonFileFullPath (filename, parent->buildRootPath );
78- structInfo.name = name ;
99+ structInfo.name = getFullname (D, canonicalType, id, sourceFilePath) ;
79100 structInfo.hasUnnamedFields = false ;
80101
81-
82102 if (Paths::isGtest (structInfo.filePath )) {
83103 return ;
84104 }
@@ -88,7 +108,6 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
88108 ss << " Struct: " << structInfo.name << " \n "
89109 << " \t File path: " << structInfo.filePath .string () << " " ;
90110 std::vector<types::Field> fields;
91- fs::path sourceFilePath = sourceManager.getFileEntryForID (sourceManager.getMainFileID ())->tryGetRealPathName ().str ();
92111 for (const clang::FieldDecl *F : D->fields ()) {
93112 if (F->isUnnamedBitfield ()) {
94113 continue ;
@@ -182,8 +201,10 @@ void TypesResolver::resolveEnum(const clang::EnumDecl *EN, const string &name) {
182201 if (!isCandidateToReplace (id, parent->projectTypes ->enums , name)) {
183202 return ;
184203 }
204+
185205 types::EnumInfo enumInfo;
186- enumInfo.name = name;
206+ fs::path sourceFilePath = sourceManager.getFileEntryForID (sourceManager.getMainFileID ())->tryGetRealPathName ().str ();
207+ enumInfo.name = getFullname (EN, canonicalType, id, sourceFilePath);
187208 enumInfo.filePath = Paths::getCCJsonFileFullPath (
188209 sourceManager.getFilename (EN->getLocation ()).str (), parent->buildRootPath .string ());
189210 clang::QualType promotionType = EN->getPromotionType ();
@@ -226,10 +247,12 @@ void TypesResolver::resolveUnion(const clang::RecordDecl *D, const std::string &
226247 if (!isCandidateToReplace (id, parent->projectTypes ->unions , name)) {
227248 return ;
228249 }
250+
229251 types::UnionInfo unionInfo;
252+ fs::path sourceFilePath = sourceManager.getFileEntryForID (sourceManager.getMainFileID ())->tryGetRealPathName ().str ();
230253 unionInfo.filePath = Paths::getCCJsonFileFullPath (
231254 sourceManager.getFilename (D->getLocation ()).str (), parent->buildRootPath .string ());
232- unionInfo.name = name ;
255+ unionInfo.name = getFullname (D, canonicalType, id, sourceFilePath) ;
233256
234257 if (Paths::isGtest (unionInfo.filePath )) {
235258 return ;
0 commit comments