Skip to content

Commit ca9ea6a

Browse files
authored
Fix write "extern" for stubs (#651)
1 parent d1c9e2f commit ca9ea6a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

server/src/printers/Printer.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ namespace printer {
125125
types::PointerUsage usage,
126126
std::optional<std::string_view> value,
127127
std::optional<uint64_t> alignment,
128-
bool complete) {
128+
bool complete,
129+
ExternType externType) {
129130
auto baseType = type.baseType();
130131
std::string arrayName{ name.data(), name.length() };
131132

@@ -135,6 +136,18 @@ namespace printer {
135136
}
136137

137138
ss << LINE_INDENT();
139+
switch (externType) {
140+
case ExternType::C :
141+
if (getLanguage() == utbot::Language::CXX) {
142+
ss << "extern \"C\" ";
143+
break;
144+
}
145+
case ExternType::SAME_LANGUAGE :
146+
ss << "extern ";
147+
break;
148+
case ExternType::NONE :
149+
break;
150+
}
138151
printAlignmentIfExists(alignment);
139152
ss << baseType << " " << arrayName;
140153
std::vector<size_t> sizes = type.arraysSizes(usage);
@@ -539,15 +552,16 @@ namespace printer {
539552
}
540553
}
541554

542-
void printer::Printer::writeExternForSymbolicStubs(const Tests::MethodDescription& testMethod) {
543-
std::unordered_map<std::string, std::string> symbolicNamesToTypesMap;
544-
for (const auto& testCase: testMethod.testCases) {
555+
void printer::Printer::writeExternForSymbolicStubs(const Tests::MethodDescription &testMethod) {
556+
std::unordered_map<std::string, types::Type> symbolicNamesToTypesMap;
557+
for (const auto &testCase: testMethod.testCases) {
545558
for (size_t i = 0; i < testCase.stubValues.size(); i++) {
546-
symbolicNamesToTypesMap[testCase.stubValues[i].name] = testCase.stubValuesTypes[i].type.usedType();
559+
symbolicNamesToTypesMap[testCase.stubValues[i].name] = testCase.stubValuesTypes[i].type;
547560
}
548561
}
549-
for (const auto& [name, type]: symbolicNamesToTypesMap) {
550-
strDeclareVar("extern \"C\" " + type, name);
562+
for (const auto &[name, type]: symbolicNamesToTypesMap) {
563+
strDeclareArrayVar(type, name, types::PointerUsage::PARAMETER, std::nullopt, std::nullopt, true,
564+
ExternType::C);
551565
}
552566
}
553567

server/src/printers/Printer.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ namespace printer {
8181

8282
Stream strDeclareAbsError(SRef name);
8383

84+
enum ExternType {
85+
NONE,
86+
SAME_LANGUAGE,
87+
C
88+
};
89+
8490
Stream strDeclareArrayVar(const types::Type& type,
8591
std::string_view name,
8692
types::PointerUsage usage,
8793
std::optional<std::string_view> value = std::nullopt,
8894
std::optional<uint64_t> alignment = std::nullopt,
89-
bool complete = true);
95+
bool complete = true,
96+
ExternType externType = ExternType::NONE);
9097

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

0 commit comments

Comments
 (0)