Skip to content

Commit 936b499

Browse files
committed
Fixes for CPP projects
1 parent 9934f15 commit 936b499

21 files changed

+205
-48
lines changed

server/src/FeaturesFilter.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,37 @@ static void updateIfNotCompleteType(types::TypeSupport &typeSupport,
1818
}
1919
}
2020

21+
bool has_private_array(const types::Type &type, const types::TypesHandler &typesHandler) {
22+
switch (typesHandler.getTypeKind(type)) {
23+
case types::TypeKind::STRUCT:
24+
for (const auto &field: typesHandler.getStructInfo(type).fields) {
25+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
26+
return true;
27+
}
28+
return has_private_array(field.type, typesHandler);
29+
}
30+
break;
31+
case types::TypeKind::UNION:
32+
for (const auto &field: typesHandler.getUnionInfo(type).fields) {
33+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
34+
return true;
35+
}
36+
return has_private_array(field.type, typesHandler);
37+
}
38+
break;
39+
case types::TypeKind::OBJECT_POINTER:
40+
return has_private_array(type.baseTypeObj(), typesHandler);
41+
case types::TypeKind::ARRAY:
42+
return has_private_array(type.baseTypeObj(), typesHandler);
43+
case types::TypeKind::PRIMITIVE:
44+
case types::TypeKind::ENUM:
45+
case types::TypeKind::UNKNOWN:
46+
default:
47+
return false;
48+
}
49+
return false;
50+
}
51+
2152
void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
2253
const types::TypesHandler &typesHandler,
2354
tests::TestsMap &testsMap,
@@ -84,6 +115,76 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
84115
tests.commentBlocks.push_back(message.str());
85116
return true;
86117
}
118+
119+
if (method.isClassMethod() && !typesHandler.getStructInfo(method.classObj->type).canBeConstruct) {
120+
std::stringstream message;
121+
message
122+
<< "Method '" << method.name
123+
<< "' was skipped, as class '" << method.getClassTypeName().value()
124+
<< "' can't be construct in current version";
125+
LOG_S(DEBUG) << message.str();
126+
tests.commentBlocks.push_back(message.str());
127+
return true;
128+
}
129+
130+
for (const auto &param: method.params) {
131+
if (typesHandler.isStruct(param.type)) {
132+
for (const auto &field: typesHandler.getStructInfo(param.type).fields) {
133+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
134+
std::stringstream message;
135+
message
136+
<< "Method '" << method.name
137+
<< "' was skipped, as class '" << param.type.typeName()
138+
<< "' has private array member '" << field.name << "'";
139+
LOG_S(DEBUG) << message.str();
140+
tests.commentBlocks.push_back(message.str());
141+
return true;
142+
}
143+
}
144+
}
145+
}
146+
147+
if (typesHandler.isStruct(method.returnType)) {
148+
for (const auto &field: typesHandler.getStructInfo(method.returnType).fields) {
149+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
150+
std::stringstream message;
151+
message
152+
<< "Method '" << method.name
153+
<< "' was skipped, as class '" << method.returnType.typeName()
154+
<< "' has private array member '" << field.name << "'";
155+
LOG_S(DEBUG) << message.str();
156+
tests.commentBlocks.push_back(message.str());
157+
return true;
158+
}
159+
}
160+
}
161+
162+
if (method.isClassMethod()) {
163+
for (const auto &field : typesHandler.getStructInfo(method.classObj->type).fields) {
164+
if (field.type.isArray() && field.accessSpecifier != types::AccessSpecifier::AS_pubic) {
165+
std::stringstream message;
166+
message
167+
<< "Method '" << method.name
168+
<< "' was skipped, as class '" << method.getClassTypeName().value()
169+
<< "' has private array member '" << field.name << "'";
170+
LOG_S(DEBUG) << message.str();
171+
tests.commentBlocks.push_back(message.str());
172+
return true;
173+
}
174+
}
175+
}
176+
177+
if (method.accessSpecifier != types::AS_pubic) {
178+
std::stringstream message;
179+
message
180+
<< "Method '" << method.name
181+
<< "' from class '" << method.getClassTypeName().value_or("")
182+
<< "' was skipped, as private";
183+
LOG_S(DEBUG) << message.str();
184+
tests.commentBlocks.push_back(message.str());
185+
return true;
186+
}
187+
87188
unsupportedStatistics["passed features filter"]++;
88189

89190
return false;

server/src/Paths.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace Paths {
108108
fs::path getCCJsonFileFullPath(const string &filename, const fs::path &directory) {
109109
fs::path path1 = fs::path(filename);
110110
fs::path path2 = fs::weakly_canonical(directory / path1);
111-
return fs::exists(path2) ? path2 : path1;
111+
return fs::exists(path2.parent_path()) ? path2 : path1;
112112
}
113113

114114
bool isPath(const string &possibleFilePath) noexcept {

server/src/Server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,7 @@ Status Server::TestsGenServiceImpl::ProcessProjectStubsRequest(BaseTestGen *test
559559
}
560560

561561
Status Server::TestsGenServiceImpl::failedToLoadCDbStatus(const CompilationDatabaseException &e) {
562-
return Status(StatusCode::INVALID_ARGUMENT,
563-
"Failed to find compile_commands.json:\n" + string(e.what()));
562+
return {StatusCode::INVALID_ARGUMENT, "Failed to find compile_commands.json:\n" + string(e.what())};
564563
}
565564

566565
Status Server::TestsGenServiceImpl::PrintModulesContent(ServerContext *context,
@@ -655,6 +654,7 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context,
655654
ProjectTargetsWriter targetsWriter{ response };
656655
targetsWriter.writeResponse(projectContext, targets);
657656
} catch (CompilationDatabaseException const &e) {
657+
LOG_S(ERROR) << "Compilation database error: " << e.what();
658658
return failedToLoadCDbStatus(e);
659659
}
660660
return Status::OK;

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/building/IRParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ bool IRParser::parseModule(const fs::path &rootBitcode, tests::TestsMap &tests)
2828
for (auto it = tests.begin(); it != tests.end(); it++) {
2929
fs::path const &sourceFile = it.key();
3030
tests::Tests &test = it.value();
31-
test.isFilePresentedInArtifact = true;
31+
test.isFilePresentedInArtifact = false;
3232
for (const auto &[methodName, methodDescription] : test.methods) {
3333
std::string entryPointFunction = KleeUtils::entryPointFunction(test, methodName, true);
3434
string methodDebugInfo =
3535
StringUtils::stringFormat("Method: '%s', file: '%s'", methodName, sourceFile);
3636
if (llvm::Function *pFunction = module->getFunction(entryPointFunction)) {
37+
test.isFilePresentedInArtifact = true;
3738
continue;
3839
} else {
3940
LOG_S(DEBUG) << "llvm::Function is null: " << methodDebugInfo;
40-
test.isFilePresentedInArtifact = false;
4141
}
4242
}
4343
}

server/src/building/UserProjectConfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ UserProjectConfiguration::RunProjectConfigurationCommands(const fs::path &buildD
4747
cmakeOptions.emplace_back("..");
4848
ShellExecTask::ExecutionParameters cmakeParams(Paths::getCMake(), cmakeOptions);
4949
ShellExecTask::ExecutionParameters bearMakeParams(Paths::getBear(),
50-
{Paths::getMake(), MakefileUtils::threadFlag()});
50+
{Paths::getMake(), MakefileUtils::threadFlag(), "--always-make"});
5151

5252

5353
fs::path cmakeListsPath = getCmakeListsPath(buildDirPath);

server/src/fetchers/Fetcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@ bool Fetcher::Options::has(Fetcher::Options::Value other) const {
132132

133133
std::shared_ptr<Fetcher::FileToStringSet> Fetcher::getStructsToDeclare() const {
134134
return structsToDeclare;
135-
}
135+
}

server/src/fetchers/FetcherUtils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,16 @@ void ClangToolRunner::setResourceDirOption(clang::tooling::ClangTool *clangTool)
115115
clangTool->appendArgumentsAdjuster(resourceDirAdjuster);
116116
}
117117
}
118+
119+
types::AccessSpecifier getAS(const clang::Decl *D) {
120+
switch (D->getAccess()) {
121+
case clang::AS_private :
122+
return types::AS_private;
123+
case clang::AS_protected :
124+
return types::AS_protected;
125+
case clang::AS_public :
126+
return types::AS_pubic;
127+
case clang::AS_none :
128+
return types::AS_none;
129+
}
130+
}

server/src/fetchers/FetcherUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ template <typename StatementType> bool canBeMissed(StatementType const& statemen
6464
llvm::isa<clang::ParenExpr>(statement) || llvm::isa<clang::CStyleCastExpr>(statement);
6565
}
6666

67+
types::AccessSpecifier getAS(const clang::Decl *D);
68+
6769
#endif //UNITTESTBOT_FETCHERUTILS_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);

0 commit comments

Comments
 (0)