Skip to content

Commit

Permalink
Fix extern
Browse files Browse the repository at this point in the history
  • Loading branch information
ladisgin committed Jun 7, 2024
1 parent e262a31 commit fcf5573
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion server/src/Synchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Synchronizer {

[[nodiscard]] bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;

[[nodiscard]] bool removeStubIfSourceAbsent(const StubOperator &stub) const;
bool removeStubIfSourceAbsent(const StubOperator &stub) const;

void synchronizeStubs(std::unordered_set<StubOperator, HashUtils::StubHash> &outdatedStubs,
const types::TypesHandler &typesHandler);
Expand Down
3 changes: 1 addition & 2 deletions server/src/coverage/LlvmCoverageTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ LlvmCoverageTool::getCoverageCommands(const std::vector<UnitTest> &testsToLaunch
for (const std::string &objectFile : objectFiles) {
if (firstBIN) {
firstBIN = false;
}
else {
} else {
exportArguments.emplace_back("-object");
}
exportArguments.emplace_back(objectFile);
Expand Down
2 changes: 1 addition & 1 deletion server/src/fetchers/GlobalVariableUsageMatchCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
const std::string usedParamTypeString = varDecl->getType().getAsString();
types::Type paramType = types::Type(realParamType, usedParamTypeString, sourceManager);
method.globalParams.emplace_back(paramType, usage.variableName, AlignmentFetcher::fetch(varDecl));
if (varDecl->isExternC() && !varDecl->isKnownToBeDefined()) {
if (varDecl->isExternC() && !varDecl->hasDefinition()) {
tests.externVariables.insert({paramType, usage.variableName});
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/printers/KleePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fs::path KleePrinter::writeTmpKleeFile(
return filter && forThisFunction && forThisClass;
});

strDeclareSetOfVars(tests.externVariables);
strDeclareSetOfExternVars(tests.externVariables);
ss << printer::NL;

for (const auto &[methodName, testMethod]: tests.methods) {
Expand Down
25 changes: 21 additions & 4 deletions server/src/printers/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,23 @@ namespace printer {
std::optional<std::string_view> initValue,
std::optional<uint64_t> alignment,
bool complete,
size_t additionalPointersCount) {
size_t additionalPointersCount,
ExternType externType) {
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);
auto additionalPointers = StringUtils::repeat("*", additionalPointersCount);
if (needDecorate()) {
Expand Down Expand Up @@ -685,12 +700,14 @@ namespace printer {
ss << Copyright::GENERATED_C_CPP_FILE_HEADER << printer::NL;
}

Printer::Stream Printer::strDeclareSetOfVars(const std::set<Tests::TypeAndVarName> &vars) {
Printer::Stream Printer::strDeclareSetOfExternVars(const std::set<Tests::TypeAndVarName> &vars) {
for (const auto &var: vars) {
if (var.type.isArray()) {
strDeclareArrayVar(var.type, var.varName, types::PointerUsage::KNOWN_SIZE);
strDeclareArrayVar(var.type, var.varName, types::PointerUsage::KNOWN_SIZE, std::nullopt,
std::nullopt, true, ExternType::C);
} else {
strDeclareVar(var.type.mTypeName(), var.varName);
strDeclareVar(var.type.mTypeName(), var.varName, std::nullopt,
std::nullopt, true, 0, ExternType::C);
}
}
return ss;
Expand Down
17 changes: 9 additions & 8 deletions server/src/printers/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,22 @@ namespace printer {

Stream strIfBound(SRef condition);

enum ExternType {
NONE,
SAME_LANGUAGE,
C
};

Stream strDeclareVar(std::string_view type,
std::string_view name,
std::optional<std::string_view> initValue = std::nullopt,
std::optional<uint64_t> alignment = std::nullopt,
bool complete = true,
size_t additionalPointersCount = 0);
size_t additionalPointersCount = 0,
ExternType externType = ExternType::NONE);

Stream strDeclareAbsError(SRef name);

enum ExternType {
NONE,
SAME_LANGUAGE,
C
};

Stream strDeclareArrayVar(const types::Type &type,
std::string_view name,
types::PointerUsage usage,
Expand All @@ -96,7 +97,7 @@ namespace printer {
bool complete = true,
ExternType externType = ExternType::NONE);

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

Stream strAssignVar(std::string_view name, std::string_view value);

Expand Down
2 changes: 1 addition & 1 deletion server/src/printers/TestsPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void TestsPrinter::joinToFinalCode(Tests &tests, const fs::path& generatedHeader
genHeaders(tests, generatedHeaderPath);
ss << printer::NL;

strDeclareSetOfVars(tests.externVariables);
strDeclareSetOfExternVars(tests.externVariables);

ss << "namespace " << PrinterUtils::TEST_NAMESPACE << " {\n";

Expand Down

0 comments on commit fcf5573

Please sign in to comment.