Skip to content

Changes for using UTBotCPP on scalapack project. #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-utbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:

build-portable-container:
needs: build-utbot-and-generate-test
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
DOCKER_IMAGE_TAG: docker-image
PORTABLE_CONTAINER_NAME: Portable
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-utbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:

auto_installation_check:
needs: publish
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions server/src/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace Paths {
return m.first == base.end();
}

bool skipFile(const fs::path &file) {
return file.string().substr(file.string().size() - 4) == ".f.o";
}

fs::path longestCommonPrefixPath(const fs::path &a, const fs::path &b) {
if (a == b) {
return a;
Expand Down
2 changes: 2 additions & 0 deletions server/src/Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace Paths {

bool isSubPathOf(const fs::path &base, const fs::path &sub);

bool skipFile(const fs::path &file);

fs::path longestCommonPrefixPath(const fs::path &a, const fs::path &b);

static inline fs::path replaceExtension(const fs::path &path, const std::string &newExt) {
Expand Down
3 changes: 3 additions & 0 deletions server/src/building/BuildDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ bool BuildDatabase::ObjectFileInfo::is32bits() const {
}

fs::path BuildDatabase::TargetInfo::getOutput() const {
if (commands.empty()){
throw CompilationDatabaseException("There are no targets");
}
return commands[0].getOutput();
}

Expand Down
10 changes: 10 additions & 0 deletions server/src/building/ProjectBuildDatabse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "loguru.h"
#include "utils/StringUtils.h"
#include "utils/CompilationUtils.h"
#include "Paths.h"

static std::string tryConvertToFullPath(const std::string &possibleFilePath, const fs::path &dirPath) {
fs::path fullFilePath = Paths::getCCJsonFileFullPath(possibleFilePath, dirPath);
Expand Down Expand Up @@ -68,6 +69,10 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
fs::path jsonFile = compileCommand.at("file").get<std::string>();
fs::path sourceFile = Paths::getCCJsonFileFullPath(jsonFile, directory);

if (!Paths::isSourceFile(sourceFile)){
continue;
}

std::vector<std::string> jsonArguments;
if (compileCommand.contains("command")) {
std::string command = compileCommand.at("command");
Expand Down Expand Up @@ -125,7 +130,9 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
objectFileInfos[outputFile] = objectInfo;
}
const fs::path &sourcePath = objectInfo->getSourcePath();

sourceFileInfos[sourcePath].emplace_back(objectInfo);

}
for (auto &[sourceFile, objectInfos]: sourceFileInfos) {
std::sort(objectInfos.begin(), objectInfos.end(), BuildDatabase::ObjectFileInfo::conflictPriorityMore);
Expand Down Expand Up @@ -164,6 +171,9 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson) {
for (nlohmann::json const &jsonFile: linkCommand.at("files")) {
auto filename = jsonFile.get<std::string>();
fs::path currentFile = Paths::getCCJsonFileFullPath(filename, command.getDirectory());
if (Paths::skipFile(currentFile)){
continue;
}
targetInfo->addFile(currentFile);
if (Paths::isObjectFile(currentFile)) {
if (!CollectionUtils::containsKey(objectFileInfos, currentFile)) {
Expand Down
45 changes: 45 additions & 0 deletions server/src/clang-utils/SourceToHeaderMatchCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ void SourceToHeaderMatchCallback::generateInternal(const FunctionDecl *decl) con

std::string curDecl = getRenamedDeclarationAsString(decl, policy, decoratedName);
std::string wrapperDecl = getRenamedDeclarationAsString(decl, policy, wrapperName);

if (IsOldStyleDefinition(curDecl)){
curDecl = getOldStyleDeclarationAsString(decl, decoratedName);
wrapperDecl = getOldStyleDeclarationAsString(decl, wrapperName);
}

*internalStream << "extern \"C\" " << wrapperDecl << ";\n";
*internalStream << "static " << curDecl << " {\n";
printReturn(decl, wrapperName, internalStream);
Expand Down Expand Up @@ -253,6 +259,9 @@ void SourceToHeaderMatchCallback::generateWrapper(const FunctionDecl *decl) cons
std::string name = decl->getNameAsString();
std::string wrapperName = PrinterUtils::wrapperName(name, projectContext, sourceFilePath);
std::string wrapperDecl = getRenamedDeclarationAsString(decl, policy, wrapperName);
if (IsOldStyleDefinition(wrapperDecl)){
wrapperDecl = getOldStyleDeclarationAsString(decl, wrapperName);
}

*wrapperStream << wrapperDecl << " {\n";
printReturn(decl, name, wrapperStream);
Expand Down Expand Up @@ -362,3 +371,39 @@ void SourceToHeaderMatchCallback::renameDecl(const NamedDecl *decl, const std::s
DeclarationName wrapperDeclarationName{ &info };
const_cast<NamedDecl *>(decl)->setDeclName(wrapperDeclarationName);
}

std::string SourceToHeaderMatchCallback::getOldStyleDeclarationAsString(const FunctionDecl *decl, std::string const &name) const{
std::string result;
llvm::raw_string_ostream resultStream{ result };
std::string funcReturnType = decl->getFunctionType()->getReturnType().getAsString();
std::vector<std::string> parameters = CollectionUtils::transformTo<std::vector<std::string>>(
decl->parameters(), [](ParmVarDecl *param) { return param->getNameAsString(); });

std::vector<std::string> param_types = CollectionUtils::transformTo<std::vector<std::string>>(
decl->parameters(), [](ParmVarDecl *param) { return param->getType().getAsString(); });
resultStream << funcReturnType << ' ' << name << '(';

for (int i = 0; i < parameters.size(); i++){
if (i != 0){
resultStream << ", ";
}
resultStream << param_types[i] << ' ' << parameters[i];
}
resultStream << ")";
resultStream.flush();
return result;
}

/*Example of old style definition
int sum(a, b)
int a;
int b;
{
return a + b;
}
*/
bool SourceToHeaderMatchCallback::IsOldStyleDefinition(std::string const &definition) const{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment with example

std::regex normStyle ("\\([a-zA-Z0-9*&_()\\[\\]]+ [a-zA-Z0-9*&_()\\[\\]]+[,) ]");
bool res = std::regex_search(definition, normStyle);
return !res;
}
4 changes: 4 additions & 0 deletions server/src/clang-utils/SourceToHeaderMatchCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class SourceToHeaderMatchCallback : public clang::ast_matchers::MatchFinder::Mat
void renameDecl(const clang::NamedDecl *decl, const std::string &name) const;

std::string decorate(std::string_view name) const;

std::string getOldStyleDeclarationAsString(const clang::FunctionDecl *decl, std::string const &name) const;

bool IsOldStyleDefinition(std::string const &definition) const;
};


Expand Down
10 changes: 4 additions & 6 deletions server/src/fetchers/FunctionDeclsMatchCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ void FunctionDeclsMatchCallback::run(const MatchFinder::MatchResult &Result) {
}

const auto paramsFromDefinition = FS->parameters();
const auto paramsFromDeclaration = FSFromHeader->parameters();
for (size_t i = 0; i < paramsFromDeclaration.size(); ++i) {
const auto &declParam = paramsFromDeclaration[i];
for (size_t i = 0; i < paramsFromDefinition.size(); ++i) {
const auto &defParam = paramsFromDefinition[i];
std::string name = NameDecorator::decorate(defParam->getNameAsString());
std::string mangledName = PrinterUtils::getParamMangledName(name, methodName);
Expand All @@ -102,9 +100,9 @@ void FunctionDeclsMatchCallback::run(const MatchFinder::MatchResult &Result) {
if (name == methodDescription.name) {
name = mangledName;
}
auto paramType = ParamsHandler::getType(defParam->getType(), declParam->getType(), sourceManager);
addFunctionPointer(methodDescription.functionPointers, declParam->getFunctionType(),
declParam->getType(), name, sourceManager, paramType);
auto paramType = ParamsHandler::getType(defParam->getType(), defParam->getType(), sourceManager);
addFunctionPointer(methodDescription.functionPointers, defParam->getFunctionType(),
defParam->getType(), name, sourceManager, paramType);
auto alignment = AlignmentFetcher::fetch(defParam);
bool hasIncompleteType = ClangUtils::isIncomplete(defParam->getType());
methodDescription.params.emplace_back(paramType, name, alignment, hasIncompleteType);
Expand Down