Skip to content

Commit 6b65250

Browse files
committed
fixes
1 parent d4c727c commit 6b65250

File tree

10 files changed

+44
-57
lines changed

10 files changed

+44
-57
lines changed

server/src/BordersFinder.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,7 @@ void BordersFinder::run(const MatchFinder::MatchResult &Result) {
8383
} else {
8484
lineInfo.scopeName = path.stem().string();
8585
}
86-
87-
std::string QualName = "";
88-
89-
llvm::raw_string_ostream OS(QualName);
90-
auto qua = FS->getQualifier();
91-
if (qua) {
92-
qua->print(OS, FS->getASTContext().getPrintingPolicy());
93-
}
94-
95-
lineInfo.methodName = QualName + FS->getNameAsString();
86+
lineInfo.methodName = FS->getQualifiedNameAsString();
9687
clang::QualType realReturnType = ClangUtils::getReturnType(FS, Result);
9788
lineInfo.functionReturnType = ParamsHandler::getType(realReturnType, realReturnType, sourceManager);
9889
lineInfo.initialized = true;

server/src/Tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ namespace tests {
491491
struct MethodDescription {
492492
std::optional<MethodParam> classObj;
493493
std::string name;
494+
std::string callName;
494495
typedef std::unordered_map<std::string, std::string> SuiteNameToCodeTextMap;
495496
std::string stubsText;
496497
SuiteNameToCodeTextMap codeText;

server/src/clang-utils/ClangUtils.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ClangUtils {
2929
}
3030

3131
const clang::FunctionDecl *getFunctionOrConstructor(const clang::ast_matchers::MatchFinder::MatchResult &Result) {
32-
const auto *FS = Result.Nodes.getNodeAs<clang::FunctionDecl>(Matchers::FUNCTION_DEF);
32+
const clang::FunctionDecl *FS = Result.Nodes.getNodeAs<clang::FunctionDecl>(Matchers::FUNCTION_DEF);
3333
if (!FS) {
3434
FS = getConstructor(Result);
3535
}
@@ -45,18 +45,20 @@ namespace ClangUtils {
4545
return realReturnType;
4646
}
4747

48-
std::string getQualName(const clang::FunctionDecl *FS) {
49-
std::string QualName = "";
50-
llvm::raw_string_ostream OS(QualName);
51-
auto qualifier = FS->getQualifier();
52-
if (qualifier) {
53-
switch (FS->getCanonicalDecl()) {
54-
48+
std::string getCallName(const clang::FunctionDecl *FS) {
49+
std::string qualName = "";
50+
if (auto qualifier = FS->getQualifier()) {
51+
llvm::raw_string_ostream OS(qualName);
52+
if (dyn_cast<clang::CXXConstructorDecl>(FS)) {
53+
qualifier = qualifier->getPrefix();
54+
if (qualifier) {
55+
qualifier->print(OS, FS->getASTContext().getPrintingPolicy());
56+
}
57+
} else if (!dyn_cast<clang::CXXMethodDecl>(FS)) {
58+
qualifier->print(OS, FS->getASTContext().getPrintingPolicy());
5559
}
56-
qualifier->print(OS, FS->getASTContext().getPrintingPolicy());
5760
OS.flush();
58-
59-
LOG_S(ERROR) << "qualname: '" << QualName << "' '" << FS->getQualifiedNameAsString() << "'";
6061
}
62+
return qualName + FS->getNameAsString();
6163
}
6264
}

server/src/clang-utils/ClangUtils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66

77
namespace ClangUtils {
88
bool isIncomplete(clang::QualType type);
9+
910
const clang::CXXConstructorDecl *getConstructor(const clang::ast_matchers::MatchFinder::MatchResult &Result);
11+
1012
const clang::FunctionDecl *getFunctionOrConstructor(const clang::ast_matchers::MatchFinder::MatchResult &Result);
11-
clang::QualType getReturnType(const clang::FunctionDecl *FS, const clang::ast_matchers::MatchFinder::MatchResult &Result);
13+
14+
clang::QualType
15+
getReturnType(const clang::FunctionDecl *FS, const clang::ast_matchers::MatchFinder::MatchResult &Result);
16+
17+
std::string getCallName(const clang::FunctionDecl *FS);
1218
};
1319

1420

server/src/fetchers/FunctionDeclsMatchCallback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "clang-utils/AlignmentFetcher.h"
77
#include "clang-utils/ClangUtils.h"
88
#include "utils/LogUtils.h"
9-
#include "clang-utils/ClangUtils.h"
109

1110
#include "loguru.h"
1211

@@ -35,8 +34,9 @@ void FunctionDeclsMatchCallback::run(const MatchFinder::MatchResult &Result) {
3534
: Tests::ConstructorInfo::CONSTRUCTOR;
3635
}
3736

38-
std::string methodName = QualName + FS->getNameAsString();
37+
std::string methodName = FS->getQualifiedNameAsString();
3938
methodDescription.name = methodName;
39+
methodDescription.callName = ClangUtils::getCallName(FS);
4040
methodDescription.sourceFilePath = sourceFilePath;
4141
if (onlyNames) {
4242
addMethod(sourceFilePath, methodDescription);

server/src/printers/KleePrinter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,14 @@ fs::path KleePrinter::writeTmpKleeFile(
155155
strDeclareSetOfVars(tests.externVariables);
156156
ss << NL;
157157

158-
for (const auto &[methodName, testMethod] : tests.methods) {
158+
for (const auto &[methodName, testMethod]: tests.methods) {
159159
if (!methodFilter(testMethod)) {
160160
continue;
161161
}
162-
if ((onlyForOneFunction && methodName != testedMethod) ||
163-
(onlyForOneClass && testMethod.isClassMethod() && testMethod.classObj->type.typeName() != testedClass)) {
162+
if (onlyForOneFunction && methodName != testedMethod) {
163+
continue;
164+
}
165+
if (onlyForOneClass && testMethod.isClassMethod() && testMethod.classObj->type.typeName() != testedClass) {
164166
continue;
165167
}
166168
try {

server/src/printers/KleePrinter.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ namespace printer {
3030
utbot::Language getLanguage() const override;
3131

3232
fs::path writeTmpKleeFile(
33-
const Tests &tests,
34-
const std::string &buildDir,
35-
const PathSubstitution &pathSubstitution,
36-
const std::optional<LineInfo::PredicateInfo> &predicateInfo = std::nullopt,
37-
const std::string &testedMethod = "",
38-
const std::optional<std::string> &testedClass = "",
39-
bool onlyForOneFunction = false,
40-
bool onlyForOneClass = false,
41-
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter = [](tests::Tests::MethodDescription const &) { return true; });
33+
const Tests &tests,
34+
const std::string &buildDir,
35+
const PathSubstitution &pathSubstitution,
36+
const std::optional<LineInfo::PredicateInfo> &predicateInfo = std::nullopt,
37+
const std::string &testedMethod = "",
38+
const std::optional<std::string> &testedClass = "",
39+
bool onlyForOneFunction = false,
40+
bool onlyForOneClass = false,
41+
const std::function<bool(tests::Tests::MethodDescription const &)> &methodFilter = [](
42+
tests::Tests::MethodDescription const &) { return true; });
4243

4344
std::string addTestLineFlag(const std::shared_ptr<LineInfo> &lineInfo,
4445
bool needAssertion,
@@ -87,6 +88,7 @@ namespace printer {
8788
/*
8889
* Functions for constraints generation.
8990
*/
91+
//TODO check does it really nead methodName
9092
void genConstraints(const Tests::MethodParam &param, const std::string& methodName = "", const std::vector<std::string>& names = {});
9193

9294
void genTwoDimPointers(const Tests::MethodParam &param, bool needDeclare);

server/src/printers/Printer.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,25 +227,11 @@ namespace printer {
227227
Printer::Stream &Printer::strFunctionDecl(const tests::Tests::MethodDescription &method,
228228
const std::string &end,
229229
const std::vector<std::string> &modifiers) {
230-
return strFunctionDecl(method.returnType.usedType(), method.name, method.getParamTypes(),
230+
return strFunctionDecl(method.returnType.usedType(), method.callName, method.getParamTypes(),
231231
method.getParamNames(), end, modifiers, method.functionPointers,
232232
method.isVariadic);
233233
}
234234

235-
236-
Printer::Stream &
237-
Printer::strFunctionDeclWithParamString(const tests::Tests::MethodDescription &method,
238-
const std::string &end,
239-
const std::vector<std::string> &modifiers) {
240-
ss << LINE_INDENT();
241-
for (const auto &modifier : modifiers) {
242-
ss << modifier << " ";
243-
}
244-
ss << method.returnType.usedType() << " " << method.name << "(" << method.paramsString
245-
<< ")" << end;
246-
return ss;
247-
}
248-
249235
Printer::Stream &Printer::strFunctionCall(std::string_view functionName,
250236
const std::vector<std::string> &args,
251237
const std::string &end,
@@ -285,7 +271,7 @@ namespace printer {
285271
parameters.push_back(param.getFunctionParamDecl());
286272
}
287273
auto classObjName = method.getClassName();
288-
return strFunctionCall(method.name, parameters, end, classObjName, needTabs,
274+
return strFunctionCall(method.callName, parameters, end, classObjName, needTabs,
289275
returnPointers);
290276
}
291277

server/src/printers/Printer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ namespace printer {
201201
const std::string &end = "",
202202
bool needTabs = true);
203203

204-
std::stringstream &strFunctionDeclWithParamString(const Tests::MethodDescription &method,
205-
const std::string &end ,
206-
const std::vector<std::string> &modifiers = {});
207-
208204
void writeStubsForFunctionParams(const types::TypesHandler* typesHandler,
209205
const Tests::MethodDescription& testMethod,
210206
bool forKlee);

server/src/printers/TestsPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ void TestsPrinter::genCode(Tests::MethodDescription &methodDescription,
194194

195195
static std::string getTestName(const Tests::MethodDescription &methodDescription, int testNum) {
196196
std::string renamedMethodDescription = KleeUtils::getRenamedOperator(methodDescription.name);
197+
StringUtils::replaceAll(renamedMethodDescription, ':', '_');
197198
std::string testBaseName = methodDescription.isClassMethod()
198199
? StringUtils::stringFormat("%s_%s",
199200
methodDescription.classObj->type.typeName(),
@@ -782,7 +783,7 @@ std::string TestsPrinter::constrVisitorFunctionCall(const Tests::MethodDescripti
782783
if (testCase.returnValue.view && testCase.returnValue.view->getEntryValue(nullptr) != PrinterUtils::C_NULL) {
783784
returnPointersCount = methodDescription.returnType.countReturnPointers(true);
784785
}
785-
std::string functionCall = constrFunctionCall(methodDescription.name, methodArgs, "", classObjName,
786+
std::string functionCall = constrFunctionCall(methodDescription.callName, methodArgs, "", classObjName,
786787
false, returnPointersCount, castType);
787788
if (methodDescription.isMoveConstructor()) {
788789
functionCall = "std::move(" + functionCall + ")";

0 commit comments

Comments
 (0)