Skip to content

Commit ce7c7dd

Browse files
committed
fixes
1 parent 02c7d8d commit ce7c7dd

File tree

9 files changed

+62
-52
lines changed

9 files changed

+62
-52
lines changed

server/src/FeaturesFilter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ 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.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-
// }
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)) {

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/printers/KleePrinter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fs::path KleePrinter::writeTmpKleeFile(
5252
LOG_S(DEBUG) << "Writing tmpKleeFile for " << testedMethod << " inside " << tests.sourceFilePath;
5353

5454
bool hasMethod = false;
55-
for (const auto &[methodName,testMethod ]: tests.methods) {
55+
for (const auto &[methodName, testMethod]: tests.methods) {
5656
if (methodFilter(testMethod)) {
5757
hasMethod = true;
5858
}
@@ -80,8 +80,11 @@ fs::path KleePrinter::writeTmpKleeFile(
8080
strInclude("stdlib.h", true);
8181
ss << NL;
8282
writeStubsForStructureFields(tests);
83-
84-
writeAccessPrivateMacros(typesHandler, tests, false);
83+
writeAccessPrivateMacros(typesHandler, tests, false, [methodFilter, onlyForOneClass, onlyForOneFunction, testedMethod, testedClass] (
84+
tests::Tests::MethodDescription const &testMethod) {
85+
return methodFilter(testMethod) && !((onlyForOneFunction && testMethod.name != testedMethod) ||
86+
(onlyForOneClass && testMethod.isClassMethod() && testMethod.classObj->type.typeName() != testedClass));
87+
});
8588

8689
for (const auto &[methodName, testMethod] : tests.methods) {
8790
if (!methodFilter(testMethod)) {

server/src/printers/Printer.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,22 @@ namespace printer {
583583
stubName, "stub", makeStatic);
584584
}
585585

586-
void Printer::writeAccessPrivateMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable) {
586+
void Printer::writeAccessPrivateMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable,
587+
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter) {
587588
if (srcLanguage == utbot::Language::CXX) {
588589
ss << NL;
589590
strInclude("access_private.hpp");
590591
ss << NL;
591592
std::unordered_set<uint64_t> checkedOnPrivate;
592-
for (const auto &[methodName, testMethod] : tests.methods) {
593+
for (const auto &[methodName, testMethod]: tests.methods) {
594+
if (!methodFilter(testMethod)) {
595+
continue;
596+
}
593597
addAccessor(typesHandler, testMethod.returnType, checkedOnPrivate);
594598
if (testMethod.isClassMethod()) {
595599
addAccessor(typesHandler, testMethod.classObj->type, checkedOnPrivate);
596600
}
597-
for (const auto& param : testMethod.params) {
601+
for (const auto &param: testMethod.params) {
598602
if (!onlyChangeable || param.isChangeable()) {
599603
addAccessor(typesHandler, param.type, checkedOnPrivate);
600604
}
@@ -604,6 +608,12 @@ namespace printer {
604608
}
605609
}
606610

611+
void Printer::writeAccessPrivateMacros(types::TypesHandler const *typesHandler,
612+
const Tests &tests, bool onlyChangeable) {
613+
writeAccessPrivateMacros(typesHandler, tests, onlyChangeable,
614+
[](tests::Tests::MethodDescription const &val) { return true; });
615+
}
616+
607617
void Printer::addAccessor(const types::TypesHandler *typesHandler, const types::Type &type,
608618
std::unordered_set<uint64_t> &checkedOnPrivate) {
609619
if (!checkedOnPrivate.count(type.getId()) && typesHandler->isStruct(type)) {

server/src/printers/Printer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ namespace printer {
220220
const string& name,
221221
const string& stubName, bool needToTypedef, bool makeStatic);
222222

223+
void writeAccessPrivateMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable,
224+
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter);
225+
223226
void writeAccessPrivateMacros(types::TypesHandler const *typesHandler, const Tests &tests, bool onlyChangeable);
224227

225228
void genStubForStructFunctionPointer(const string& structName,

server/src/printers/TestsPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void TestsPrinter::genHeaders(Tests &tests, const fs::path& generatedHeaderPath)
218218
}
219219
}
220220

221+
//TODO filter tests
221222
writeAccessPrivateMacros(typesHandler, tests, true);
222223
}
223224

@@ -347,6 +348,9 @@ void printer::TestsPrinter::printClassObject(const Tests::MethodDescription &met
347348
if (methodDescription.isClassMethod()) {
348349
const auto &param = methodDescription.classObj.value();
349350
const auto &value = testCase.classPreValues.value();
351+
if (!typesHandler->getStructInfo(param.type).isCLike) {
352+
strComment("struct/class maybe can't be construct");
353+
}
350354
verboseParameter(methodDescription, param, value, true);
351355
}
352356
}

server/src/types/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ namespace types {
290290

291291
FPointerMap functionFields{};
292292
bool hasUnnamedFields;
293-
// Temporary solution, while we need constructor from initializer list and default constructor
293+
//TODO while we need constructor from initializer list and default constructor
294294
bool canBeConstruct;
295+
bool isCLike;
295296
};
296297

297298
struct UnionInfo: TypeInfo {

server/src/types/TypesResolver.cpp

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static bool canBeReplaced(const string &nameInMap, const string &name) {
2424
return nameInMap.empty() && !name.empty();
2525
}
2626

27-
template <class Info>
27+
template<class Info>
2828
bool isCandidateToReplace(uint64_t id,
2929
std::unordered_map<uint64_t, Info> &someMap,
3030
std::string const &name) {
@@ -44,9 +44,9 @@ static size_t getDeclAlignment(const clang::TagDecl *T) {
4444
return T->getASTContext().getTypeAlign(T->getTypeForDecl()) / 8;
4545
}
4646

47-
template <class Info>
47+
template<class Info>
4848
static void addInfo(uint64_t id, std::unordered_map<uint64_t, Info> &someMap, Info info) {
49-
auto [iterator, inserted] = someMap.emplace(id, info);
49+
auto[iterator, inserted] = someMap.emplace(id, info);
5050
LOG_IF_S(MAX, !inserted) << "Type with id=" << id << " already existed";
5151
if (!inserted) {
5252
std::string nameInMap = iterator->second.name;
@@ -78,6 +78,7 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
7878
structInfo.name = name;
7979
structInfo.hasUnnamedFields = false;
8080
structInfo.canBeConstruct = false;
81+
structInfo.isCLike = true;
8182

8283
if (Paths::isGtest(structInfo.filePath)) {
8384
return;
@@ -88,9 +89,10 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
8889
ss << "Struct: " << structInfo.name << "\n"
8990
<< "\tFile path: " << structInfo.filePath.string() << "";
9091
std::vector<types::Field> fields;
91-
fs::path sourceFilePath = sourceManager.getFileEntryForID(sourceManager.getMainFileID())->tryGetRealPathName().str();
92+
fs::path sourceFilePath = sourceManager.getFileEntryForID(
93+
sourceManager.getMainFileID())->tryGetRealPathName().str();
9294

93-
for (const clang::FieldDecl *F : D->fields()) {
95+
for (const clang::FieldDecl *F: D->fields()) {
9496
if (F->isUnnamedBitfield()) {
9597
continue;
9698
}
@@ -132,32 +134,18 @@ void TypesResolver::resolveStruct(const clang::RecordDecl *D, const std::string
132134
structInfo.fields = fields;
133135
structInfo.size = getRecordSize(D);
134136
structInfo.alignment = getDeclAlignment(D);
135-
//probably replace by D->isCXXClassMember()
136-
if (auto CXXD = dynamic_cast<const clang::CXXRecordDecl*>(D); CXXD != nullptr ) {
137-
if (CXXD->hasDefaultConstructor()) {
138-
for (const auto &it: CXXD->ctors()) {
139-
bool flag = true;
140-
auto it_field = structInfo.fields.begin();
141-
for (const auto p : it->parameters()) {
142-
if(it_field == structInfo.fields.end()) {
143-
flag = false;
144-
break;
145-
}
146-
if (it_field->type.getId() != p->getID()) {
147-
flag = false;
148-
break;
149-
}
150-
it_field++;
151-
}
152-
if (it_field != structInfo.fields.end() && structInfo.fields.begin() != structInfo.fields.end()) {
153-
flag = false;
154-
}
155-
if (flag) {
156-
structInfo.canBeConstruct = true;
157-
break;
158-
}
137+
if (auto CXXD = dynamic_cast<const clang::CXXRecordDecl *>(D)) {
138+
LOG_S(MAX) << "Struct/Class " << structInfo.name << " CXX class";
139+
if (!CXXD->isCLike()) {
140+
structInfo.isCLike = false;
141+
}
142+
for (const auto &it: CXXD->ctors()) {
143+
if (it->isDefaultConstructor() && !it->isDeleted() && getAS(it) == types::AccessSpecifier::AS_pubic) {
144+
structInfo.canBeConstruct = true;
145+
break;
159146
}
160147
}
148+
LOG_IF_S(MAX, !structInfo.canBeConstruct) << "Struct/Class " << structInfo.name << " hasn't default public constructor";
161149
}
162150

163151
addInfo(id, parent->projectTypes->structs, structInfo);
@@ -200,7 +188,7 @@ void TypesResolver::resolveEnum(const clang::EnumDecl *EN, const string &name) {
200188
types::EnumInfo enumInfo;
201189
enumInfo.name = name;
202190
enumInfo.filePath = Paths::getCCJsonFileFullPath(
203-
sourceManager.getFilename(EN->getLocation()).str(), parent->buildRootPath.string());
191+
sourceManager.getFilename(EN->getLocation()).str(), parent->buildRootPath.string());
204192
clang::QualType promotionType = EN->getPromotionType();
205193
enumInfo.size = context.getTypeSize(promotionType) / 8;
206194

@@ -227,6 +215,7 @@ void TypesResolver::resolveEnum(const clang::EnumDecl *EN, const string &name) {
227215
<< "\tFile path: " << enumInfo.filePath.string();
228216
LOG_S(DEBUG) << ss.str();
229217
}
218+
230219
void TypesResolver::updateMaximumAlignment(uint64_t alignment) const {
231220
uint64_t &maximumAlignment = *(this->parent->maximumAlignment);
232221
maximumAlignment = std::max(maximumAlignment, alignment);
@@ -243,7 +232,7 @@ void TypesResolver::resolveUnion(const clang::RecordDecl *D, const std::string &
243232
}
244233
types::UnionInfo unionInfo;
245234
unionInfo.filePath = Paths::getCCJsonFileFullPath(
246-
sourceManager.getFilename(D->getLocation()).str(), parent->buildRootPath.string());
235+
sourceManager.getFilename(D->getLocation()).str(), parent->buildRootPath.string());
247236
unionInfo.name = name;
248237

249238
if (Paths::isGtest(unionInfo.filePath)) {
@@ -256,7 +245,7 @@ void TypesResolver::resolveUnion(const clang::RecordDecl *D, const std::string &
256245
<< "\tFile path: " << unionInfo.filePath.string() << "";
257246
std::vector<types::Field> fields;
258247
unionInfo.hasUnnamedFields = false;
259-
for (const clang::FieldDecl *F : D->fields()) {
248+
for (const clang::FieldDecl *F: D->fields()) {
260249
if (F->isUnnamedBitfield()) {
261250
continue;
262251
}

0 commit comments

Comments
 (0)