Skip to content

Commit

Permalink
Merge pull request #27 from Superbelko/develop
Browse files Browse the repository at this point in the history
Add support for clang-14
  • Loading branch information
Superbelko committed Aug 12, 2023
2 parents cc75d91 + 079efb6 commit f1686bc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ jobs:
- uses: actions/checkout@v2
- uses: dlang-community/setup-dlang@4c99aa991ce7d19dd3064de0a4f2f6b2f152e2d7
with:
compiler: ldc-latest
compiler: ldc-1.32.2

- name: 'Get clang packages'
run: |
sudo apt-get install -y libclang-11-dev llvm-11-dev lld-11
sudo apt-get install -y libclang-14-dev llvm-14-dev lld-14
# symlink needed otherwise link will fail
sudo ln -s /usr/lib/llvm-11/lib/libclang-cpp.so.11 /usr/lib/llvm-11/lib/libclang-cpp.so
sudo ln -s /usr/lib/llvm-14/lib/libclang-cpp.so.14 /usr/lib/llvm-14/lib/libclang-cpp.so
- name: 'Use lld linker'
run: sudo update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/lld-11" 50
run: sudo update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/lld-14" 50

- name: 'Build library'
run: |
Expand All @@ -37,7 +37,7 @@ jobs:
mkdir build
cd build
# Use specific version
export LLVM_DIR=/usr/lib/llvm-11/lib/cmake/llvm
export LLVM_DIR=/usr/lib/llvm-14/lib/cmake/llvm
cmake .. -DGENTOOL_LIB=ON
cmake --build . --config Release
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3) # 3.10 for VS /std:c++17 switch
cmake_minimum_required(VERSION 3.10) # 3.10 for VS /std:c++17 switch
project(gentool)

option(GENTOOL_LIB "Build gentool as library")
Expand Down
4 changes: 4 additions & 0 deletions scripts/makeenv.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ string makeEnv(string[] libs, string llvmDir = null, string buildType = null)

// folder that contains llvm cmake config (e.g. ~/llvm-build/lib/cmake/llvm)
// we are interested in static libraries files location
// note: ubuntu 23 and LLVM 14 has cmake config in two locations
// 1) /usr/lib/llvm-14/lib/cmake/llvm/
// 2) /usr/lib/llvm-14/cmake/
// no idea which is what... but option 2 will result in wrong lib path
if (llvmDir)
{
llvmDir = buildNormalizedPath(llvmDir, "..", "..");
Expand Down
11 changes: 10 additions & 1 deletion source/dlang_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ void printQualifier(NestedNameSpecifier* qualifier, llvm::raw_ostream& os)
const Type *T = qualifier->getAsType();
if (const TemplateSpecializationType *SpecType = dyn_cast<TemplateSpecializationType>(T))
{
SpecType->getTemplateName().print(os, *DlangBindGenerator::g_printPolicy, true);
#if (LLVM_VERSION_MAJOR > 12)
#define SUPPRESS_NNM TemplateName::Qualified::None
#else
#define SUPPRESS_NNM true
#endif
SpecType->getTemplateName().print(os, *DlangBindGenerator::g_printPolicy, SUPPRESS_NNM);
#undef SUPPRESS_NNM
printDTemplateArgumentList(os, SpecType->template_arguments(), *DlangBindGenerator::g_printPolicy);
} else if (const TemplateTypeParmType* SpecType = dyn_cast<TemplateTypeParmType>(T)) {
if (auto id = SpecType->getIdentifier()) {
Expand Down Expand Up @@ -2977,3 +2983,6 @@ void IncludeMap::add(const std::string& header, const std::string& mappedModule)

_mappings.insert(std::make_pair(header, mappedModule));
}

void dumpDecl(const clang::Decl* decl) { decl->dump(); }
void dumpStmt(const clang::Stmt* stmt) { stmt->dump(); }
4 changes: 4 additions & 0 deletions source/dlang_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
// Gathers 'actions' to take after translation
class FeedbackContext;

// just a helper that redirects to decl->dump(), useful e.g. when no debug symbols for clang is available
void dumpDecl(const clang::Decl* decl);
void dumpStmt(const clang::Stmt* stmt);

// Similar to default printPretty for expressions, except prints D from C++ AST
void printPrettyD(const clang::Stmt *stmt, llvm::raw_ostream &OS, clang::PrinterHelper *Helper,
const clang::PrintingPolicy &Policy, unsigned Indentation = 0,
Expand Down
6 changes: 5 additions & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,12 @@ std::vector<std::string> makeCompilerCommandLineArgs(gentool::InputOptions& inpu
return cmd;
}


// oof, messy
#if (LLVM_VERSION_MAJOR > 12)
void llvmOnError(void *user_data, const char* reason, bool gen_crash_diag)
#else
void llvmOnError(void *user_data, const std::string& reason, bool gen_crash_diag)
#endif
{
std::cout << reason << std::endl;
}
Expand Down
12 changes: 12 additions & 0 deletions source/printprettyd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,18 @@ class CppDASTPrinterVisitor : public RecursiveASTVisitor<CppDASTPrinterVisitor>
if (isBaseCtor || E->isElidable())
prependType = false;

// appers when explicitly returns constructed copy
// e.g. "return s" doesn't have it, but "return Mat22(s)" does
// but note that without xvalue test it chomps variable assignment construction too
if (E->getArgs() && isa<ImplicitCastExpr>(E->getArg(0)))
{
if (auto impcast = llvm::cast_or_null<ImplicitCastExpr>(E->getArg(0)))
{
if (impcast->getCastKind() == clang::CastKind::CK_NoOp && impcast->isXValue())
prependType = false;
}
}

// if doesn't have braces might mean it is implicit ctor match
if (prependType)// && !isCtorInitializer)
{
Expand Down

0 comments on commit f1686bc

Please sign in to comment.