Skip to content

Commit

Permalink
Fix write "extern" for stubs (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
ladisgin authored Oct 25, 2023
1 parent d1c9e2f commit ca9ea6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
28 changes: 21 additions & 7 deletions server/src/printers/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ namespace printer {
types::PointerUsage usage,
std::optional<std::string_view> value,
std::optional<uint64_t> alignment,
bool complete) {
bool complete,
ExternType externType) {
auto baseType = type.baseType();
std::string arrayName{ name.data(), name.length() };

Expand All @@ -135,6 +136,18 @@ namespace printer {
}

ss << LINE_INDENT();
switch (externType) {
case ExternType::C :
if (getLanguage() == utbot::Language::CXX) {
ss << "extern \"C\" ";
break;
}
case ExternType::SAME_LANGUAGE :
ss << "extern ";
break;
case ExternType::NONE :
break;
}
printAlignmentIfExists(alignment);
ss << baseType << " " << arrayName;
std::vector<size_t> sizes = type.arraysSizes(usage);
Expand Down Expand Up @@ -539,15 +552,16 @@ namespace printer {
}
}

void printer::Printer::writeExternForSymbolicStubs(const Tests::MethodDescription& testMethod) {
std::unordered_map<std::string, std::string> symbolicNamesToTypesMap;
for (const auto& testCase: testMethod.testCases) {
void printer::Printer::writeExternForSymbolicStubs(const Tests::MethodDescription &testMethod) {
std::unordered_map<std::string, types::Type> symbolicNamesToTypesMap;
for (const auto &testCase: testMethod.testCases) {
for (size_t i = 0; i < testCase.stubValues.size(); i++) {
symbolicNamesToTypesMap[testCase.stubValues[i].name] = testCase.stubValuesTypes[i].type.usedType();
symbolicNamesToTypesMap[testCase.stubValues[i].name] = testCase.stubValuesTypes[i].type;
}
}
for (const auto& [name, type]: symbolicNamesToTypesMap) {
strDeclareVar("extern \"C\" " + type, name);
for (const auto &[name, type]: symbolicNamesToTypesMap) {
strDeclareArrayVar(type, name, types::PointerUsage::PARAMETER, std::nullopt, std::nullopt, true,
ExternType::C);
}
}

Expand Down
9 changes: 8 additions & 1 deletion server/src/printers/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,19 @@ namespace printer {

Stream strDeclareAbsError(SRef name);

enum ExternType {
NONE,
SAME_LANGUAGE,
C
};

Stream strDeclareArrayVar(const types::Type& type,
std::string_view name,
types::PointerUsage usage,
std::optional<std::string_view> value = std::nullopt,
std::optional<uint64_t> alignment = std::nullopt,
bool complete = true);
bool complete = true,
ExternType externType = ExternType::NONE);

Stream strDeclareSetOfVars(const std::set<Tests::TypeAndVarName> &vars);

Expand Down

0 comments on commit ca9ea6a

Please sign in to comment.