Skip to content

Commit eb9fc45

Browse files
committed
[Temp] fix stubs 2
1 parent a474688 commit eb9fc45

File tree

8 files changed

+29
-19
lines changed

8 files changed

+29
-19
lines changed

server/src/Tests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,8 @@ void KTestObjectParser::processStubParamValue(
11651165
const std::unordered_map<std::string, types::Type> &methodNameToReturnTypeMap,
11661166
std::vector<RawKleeParam> &rawKleeParams) {
11671167
for (const auto &kleeParam : rawKleeParams) {
1168-
if (StringUtils::endsWith(kleeParam.paramName, PrinterUtils::KLEE_SYMBOLIC_SUFFIX)) {
1169-
std::string methodName = kleeParam.paramName.substr(
1170-
0, kleeParam.paramName.size() - PrinterUtils::KLEE_SYMBOLIC_SUFFIX.size());
1168+
std::string methodName = StubsUtils::tryGetMethodNameFromStubSymbolic(kleeParam.paramName);
1169+
if (!methodName.empty()) {
11711170
if (!CollectionUtils::containsKey(methodNameToReturnTypeMap, methodName)) {
11721171
LOG_S(WARNING) << "Method name \"" << methodName << "\" was not fetched, skipping";
11731172
continue;

server/src/printers/Printer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,12 @@ namespace printer {
388388
const types::TypesHandler &typesHandler,
389389
const std::string &prefix,
390390
const std::string &suffix,
391-
const std::string &methodName,
391+
const std::string &parentMethodName,
392392
bool makeStatic) {
393393
auto methodCopy = method;
394394
methodCopy.name = method.name;
395395

396-
// TODO: may have same method.name for different classes in c++
397-
std::string stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(method.name);
396+
std::string stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(methodCopy.name, parentMethodName);
398397
if (!types::TypesHandler::omitMakeSymbolic(method.returnType)) {
399398
strDeclareArrayVar(types::Type::createArray(method.returnType), stubSymbolicVarName,
400399
types::PointerUsage::PARAMETER);

server/src/printers/Printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace printer {
178178
const types::TypesHandler &typesHandler,
179179
const std::string &prefix,
180180
const std::string &suffix,
181-
const std::string &methodName,
181+
const std::string &parentMethodName,
182182
bool makeStatic);
183183

184184
Stream strKleeMakeSymbolic(SRef varName, bool needAmpersand, SRef pseudoName);

server/src/printers/TestsPrinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ void TestsPrinter::printLazyReferences(const Tests::MethodDescription &methodDes
358358
}
359359
}
360360

361-
void TestsPrinter::printStubVariables(const Tests::MethodDescription &methodDescription,
362-
const Tests::MethodTestCase &testCase) {
361+
void TestsPrinter::printStubVariablesForParam(const Tests::MethodDescription &methodDescription,
362+
const Tests::MethodTestCase &testCase) {
363363
for (int i = 0; i < testCase.stubParamValues.size(); i++) {
364364
auto stub = testCase.stubParamValues[i];
365365
types::Type stubType = testCase.stubParamTypes[i].type;
@@ -378,8 +378,8 @@ void TestsPrinter::genParametrizedTestCase(const Tests::MethodDescription &metho
378378
openFiles(methodDescription, testCase);
379379
parametrizedInitializeGlobalVariables(methodDescription, testCase);
380380
parametrizedInitializeSymbolicStubs(methodDescription, testCase);
381+
printStubVariablesForParam(methodDescription, testCase);
381382
printClassObject(methodDescription, testCase);
382-
printStubVariables(methodDescription, testCase);
383383
printFunctionParameters(methodDescription, testCase, false);
384384
printLazyVariables(methodDescription, testCase, false);
385385
printLazyReferences(methodDescription, testCase, false);
@@ -457,8 +457,8 @@ void TestsPrinter::verboseParameters(const Tests::MethodDescription &methodDescr
457457
ss << NL;
458458
}
459459

460-
std::vector<std::vector<tests::Tests::MethodParam>> types = {testCase.stubValuesTypes, testCase.stubParamTypes };
461-
std::vector<std::vector<tests::Tests::TestCaseParamValue>> values = { testCase.stubParamValues, testCase.stubParamValues };
460+
std::vector<std::vector<tests::Tests::MethodParam>> types = {testCase.stubValuesTypes, testCase.stubParamTypes};
461+
std::vector<std::vector<tests::Tests::TestCaseParamValue>> values = {testCase.stubValues, testCase.stubParamValues};
462462

463463
for (int j = 0; j < types.size(); j++) {
464464
if (!types[j].empty()) {

server/src/printers/TestsPrinter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ namespace printer {
148148
const Tests::MethodTestCase &testCase,
149149
bool verbose);
150150

151-
void printStubVariables(const Tests::MethodDescription &methodDescription,
152-
const Tests::MethodTestCase &testCase);
151+
void printStubVariablesForParam(const Tests::MethodDescription &methodDescription,
152+
const Tests::MethodTestCase &testCase);
153153

154154
void printPointerParameter(const tests::Tests::MethodDescription &methodDescription,
155155
const Tests::MethodTestCase &testCase,

server/src/stubs/StubsStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
void StubsStorage::registerFunctionPointerStub(const std::string &methodName,
77
std::shared_ptr<types::FunctionInfo> functionInfo) {
8-
_functionPointers[StubsUtils::getStubSymbolicVarName(methodName + "_" + functionInfo->name)] = std::move(
8+
_functionPointers[StubsUtils::getStubSymbolicVarName(functionInfo->name, methodName)] = std::move(
99
functionInfo);
1010
}
1111

server/src/utils/StubsUtils.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ namespace StubsUtils {
1515
return stubName;
1616
}
1717

18-
std::string getStubSymbolicVarName(const std::string &methodName) {
19-
std::string stubName = methodName + PrinterUtils::KLEE_SYMBOLIC_SUFFIX;
20-
StringUtils::replaceColon(stubName); //TODO has problem
18+
std::string getStubSymbolicVarName(const std::string &methodName, const std::string &parentMethodName) {
19+
std::string stubName;
20+
if (!parentMethodName.empty()) {
21+
stubName = parentMethodName + "_";
22+
}
23+
stubName += methodName + PrinterUtils::KLEE_SYMBOLIC_SUFFIX;
24+
StringUtils::replaceColon(stubName); //TODO has problem for stubs
2125
return stubName;
2226
}
2327

28+
std::string tryGetMethodNameFromStubSymbolic(const std::string &symbolicName) {
29+
std::string methodName = symbolicName.substr(
30+
0, symbolicName.size() - PrinterUtils::KLEE_SYMBOLIC_SUFFIX.size());
31+
return methodName;
32+
}
33+
2434
std::string getFunctionPointerAsStructFieldStubName(const std::string &structName,
2535
const std::string &fieldName,
2636
bool omitSuffix) {

server/src/utils/StubsUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ namespace StubsUtils {
1010
const std::string &paramName,
1111
bool omitSuffix = false);
1212

13-
std::string getStubSymbolicVarName(const std::string &methodName);
13+
std::string getStubSymbolicVarName(const std::string &methodName, const std::string &parentMethodName);
14+
15+
std::string tryGetMethodNameFromStubSymbolic(const std::string &symbolicName);
1416

1517
std::string getFunctionPointerAsStructFieldStubName(const std::string &structName,
1618
const std::string &fieldName,

0 commit comments

Comments
 (0)