Skip to content

Commit 02c7d8d

Browse files
committed
skip class with private methods
1 parent a22b054 commit 02c7d8d

File tree

9 files changed

+58
-42
lines changed

9 files changed

+58
-42
lines changed

server/src/FeaturesFilter.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,21 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
8585
return true;
8686
}
8787

88-
if (method.isClassMethod() && !typesHandler.getStructInfo(method.classObj->type).canBeConstruct) {
89-
std::stringstream message;
90-
message
91-
<< "Method '" << method.name
92-
<< "' was skipped, as class '" << method.getClassName().value()
93-
<< "' can't be construct in current version";
94-
LOG_S(DEBUG) << message.str();
95-
tests.commentBlocks.push_back(message.str());
96-
return true;
97-
}
88+
// if (method.isClassMethod() && !typesHandler.getStructInfo(method.classObj->type).canBeConstruct) {
89+
// std::stringstream message;
90+
// message
91+
// << "Method '" << method.name
92+
// << "' was skipped, as class '" << method.getClassTypeName().value()
93+
// << "' can't be construct in current version";
94+
// LOG_S(DEBUG) << message.str();
95+
// tests.commentBlocks.push_back(message.str());
96+
// return true;
97+
// }
9898

9999
for (const auto &param: method.params) {
100100
if (typesHandler.isStruct(param.type)) {
101101
for (const auto &field: typesHandler.getStructInfo(param.type).fields) {
102-
if (field.type.isArray() && field.accessSpecifier != types::Field::AS_pubic) {
102+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
103103
std::stringstream message;
104104
message
105105
<< "Method '" << method.name
@@ -115,7 +115,7 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
115115

116116
if (typesHandler.isStruct(method.returnType)) {
117117
for (const auto &field: typesHandler.getStructInfo(method.returnType).fields) {
118-
if (field.type.isArray() && field.accessSpecifier != types::Field::AS_pubic) {
118+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
119119
std::stringstream message;
120120
message
121121
<< "Method '" << method.name
@@ -130,11 +130,11 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
130130

131131
if (method.isClassMethod()) {
132132
for (const auto &field : typesHandler.getStructInfo(method.classObj->type).fields) {
133-
if (field.type.isArray() && field.accessSpecifier != types::Field::AS_pubic) {
133+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
134134
std::stringstream message;
135135
message
136136
<< "Method '" << method.name
137-
<< "' was skipped, as class '" << method.getClassName().value()
137+
<< "' was skipped, as class '" << method.getClassTypeName().value()
138138
<< "' has private array member '" << field.name << "'";
139139
LOG_S(DEBUG) << message.str();
140140
tests.commentBlocks.push_back(message.str());
@@ -143,6 +143,17 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
143143
}
144144
}
145145

146+
if (method.accessSpecifier != types::AS_pubic) {
147+
std::stringstream message;
148+
message
149+
<< "Method '" << method.name
150+
<< "' from class '" << method.getClassTypeName().value_or("")
151+
<< "' was skipped, as private";
152+
LOG_S(DEBUG) << message.str();
153+
tests.commentBlocks.push_back(message.str());
154+
return true;
155+
}
156+
146157
unsupportedStatistics["passed features filter"]++;
147158

148159
return false;

server/src/Tests.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ namespace tests {
413413
vector<MethodTestCase> testCases;
414414
typedef std::unordered_map<string, vector<MethodTestCase>> SuiteNameToTestCasesMap;
415415
SuiteNameToTestCasesMap suiteTestCases;
416+
types::AccessSpecifier accessSpecifier;
416417

417418
bool operator==(const MethodDescription &other) const;
418419

@@ -452,7 +453,7 @@ namespace tests {
452453
}
453454

454455
bool hasChangeable() const {
455-
for(const auto& i : params) {
456+
for (const auto& i : params) {
456457
if (i.isChangeable()) {
457458
return true;
458459
}

server/src/fetchers/Fetcher.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,17 @@ bool Fetcher::Options::has(Fetcher::Options::Value other) const {
133133

134134
std::shared_ptr<Fetcher::FileToStringSet> Fetcher::getStructsToDeclare() const {
135135
return structsToDeclare;
136-
}
136+
}
137+
138+
types::AccessSpecifier getAS(const clang::Decl *D) {
139+
switch (D->getAccess()) {
140+
case clang::AS_private :
141+
return types::AS_private;
142+
case clang::AS_protected :
143+
return types::AS_protected;
144+
case clang::AS_public :
145+
return types::AS_pubic;
146+
case clang::AS_none :
147+
return types::AS_none;
148+
}
149+
}

server/src/fetchers/Fetcher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,7 @@ inline Fetcher::Options operator&(Fetcher::Options a, Fetcher::Options b) {
131131
return Fetcher::Options{ a.value & b.value };
132132
}
133133

134+
// TODO Move to another file
135+
types::AccessSpecifier getAS(const clang::Decl *D);
134136

135137
#endif // UNITTESTBOT_FETCHER_H

server/src/fetchers/FunctionDeclsMatchCallback.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void FunctionDeclsMatchCallback::run(const MatchFinder::MatchResult &Result) {
4242
}
4343
const clang::QualType realReturnType = FS->getReturnType().getCanonicalType();
4444
methodDescription.returnType = ParamsHandler::getType(realReturnType, realReturnType, sourceManager);
45+
methodDescription.accessSpecifier = types::AS_pubic;
4546
if (onlyReturnTypes) {
4647
addMethod(sourceFilePath, methodDescription);
4748
return;
@@ -67,6 +68,7 @@ void FunctionDeclsMatchCallback::run(const MatchFinder::MatchResult &Result) {
6768
methodDescription.classObj = { classType,
6869
classType.typeName() + "_obj",
6970
std::nullopt };
71+
methodDescription.accessSpecifier = getAS(FS);
7072
}
7173
methodDescription.returnType = ParamsHandler::getType(realReturnType, realReturnType, sourceManager);
7274
methodDescription.hasIncompleteReturnType = ClangUtils::isIncomplete(realReturnType);

server/src/printers/Printer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ namespace printer {
609609
if (!checkedOnPrivate.count(type.getId()) && typesHandler->isStruct(type)) {
610610
checkedOnPrivate.insert(type.getId());
611611
for (const auto& field : typesHandler->getStructInfo(type).fields) {
612-
if (field.accessSpecifier != types::Field::AS_pubic && !field.type.isArray()) {
612+
if (field.accessSpecifier != types::AccessSpecifier::AS_pubic && !field.type.isArray()) {
613613
ss << StringUtils::stringFormat("ACCESS_PRIVATE_FIELD(%s, %s, %s)",
614614
type.typeName(),
615615
field.type.typeName(),

server/src/types/Types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ namespace types {
2929
enum class PointerUsage;
3030
enum class ReferenceType;
3131

32+
enum AccessSpecifier {
33+
AS_pubic,
34+
AS_protected,
35+
AS_private,
36+
AS_none
37+
};
38+
3239
class Type {
3340
public:
3441
Type() = default;
@@ -265,12 +272,6 @@ namespace types {
265272
unsigned int size;
266273
// reassigned in structFields
267274
unsigned int offset = 0;
268-
enum AccessSpecifier {
269-
AS_pubic,
270-
AS_protected,
271-
AS_private,
272-
AS_none
273-
};
274275
AccessSpecifier accessSpecifier = AS_pubic;
275276
};
276277

@@ -666,7 +667,6 @@ namespace types {
666667
};
667668
std::vector<FunctionParamInfo> params;
668669
};
669-
670670
}
671671

672672
#endif //UNITTESTBOT_TYPES_H

server/src/types/TypesResolver.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,16 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
123123
}
124124
structInfo.hasUnnamedFields |= F->isAnonymousStructOrUnion();
125125
if (Paths::getSourceLanguage(sourceFilePath) == utbot::Language::CXX) {
126-
switch (F->getAccess()) {
127-
case clang::AccessSpecifier::AS_private :
128-
field.accessSpecifier = types::Field::AS_private;
129-
break;
130-
case clang::AccessSpecifier::AS_protected :
131-
field.accessSpecifier = types::Field::AS_protected;
132-
break;
133-
case clang::AccessSpecifier::AS_public :
134-
field.accessSpecifier = types::Field::AS_pubic;
135-
break;
136-
case clang::AccessSpecifier::AS_none :
137-
field.accessSpecifier = types::Field::AS_none;
138-
break;
139-
}
126+
field.accessSpecifier = getAS(F);
140127
} else {
141-
field.accessSpecifier = types::Field::AS_pubic;
128+
field.accessSpecifier = types::AccessSpecifier::AS_pubic;
142129
}
143130
fields.push_back(field);
144131
}
145132
structInfo.fields = fields;
146133
structInfo.size = getRecordSize(D);
147134
structInfo.alignment = getDeclAlignment(D);
148-
135+
//probably replace by D->isCXXClassMember()
149136
if (auto CXXD = dynamic_cast<const clang::CXXRecordDecl*>(D); CXXD != nullptr ) {
150137
if (CXXD->hasDefaultConstructor()) {
151138
for (const auto &it: CXXD->ctors()) {
@@ -162,7 +149,7 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
162149
}
163150
it_field++;
164151
}
165-
if (it_field != structInfo.fields.end()) {
152+
if (it_field != structInfo.fields.end() && structInfo.fields.begin() != structInfo.fields.end()) {
166153
flag = false;
167154
}
168155
if (flag) {

server/src/utils/PrinterUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace PrinterUtils {
6363
if (field.name.empty()) {
6464
return objectName;
6565
}
66-
if (field.accessSpecifier == types::Field::AS_pubic) {
66+
if (field.accessSpecifier == types::AccessSpecifier::AS_pubic) {
6767
return getFieldAccess(objectName, field.name);
6868
}
6969
return StringUtils::stringFormat("access_private::%s(%s)", field.name, objectName);

0 commit comments

Comments
 (0)