Skip to content

Conversation

@Gnimuc
Copy link
Contributor

@Gnimuc Gnimuc commented Oct 27, 2024

Since there is a substantial overlap with libclang’s API, I am only exposing the API I currently use in this PR.

This PR introduces two types, CXScope and CXQualType, which wrap TCppScope_t and TCppType_t, respectively. The structure of these two types is the same as libclang's CXCursor/CXType, with the only difference being that they store a handle to the interpreter instead of a CXTranslationUnit. This paves the way for upstreaming changes to libclang.

@codecov
Copy link

codecov bot commented Oct 27, 2024

Codecov Report

Attention: Patch coverage is 22.09632% with 275 lines in your changes missing coverage. Please review.

Project coverage is 70.56%. Comparing base (05d65c8) to head (bc07bb0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/Interpreter/CXCppInterOp.cpp 22.09% 275 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #337      +/-   ##
==========================================
- Coverage   76.15%   70.56%   -5.59%     
==========================================
  Files           8        9       +1     
  Lines        3137     3496     +359     
==========================================
+ Hits         2389     2467      +78     
- Misses        748     1029     +281     
Files with missing lines Coverage Δ
lib/Interpreter/CXCppInterOp.cpp 22.09% <22.09%> (ø)

... and 2 files with indirect coverage changes

Files with missing lines Coverage Δ
lib/Interpreter/CXCppInterOp.cpp 22.09% <22.09%> (ø)

... and 2 files with indirect coverage changes

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 41. Check the log or trigger a new build to see more.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 24. Check the log or trigger a new build to see more.

static inline bool isNull(const CXScope& S) { return !S.data[0]; }

static inline clang::Decl* getDecl(const CXScope& S) {
return const_cast<clang::Decl*>(static_cast<const clang::Decl*>(S.data[0]));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]

  return const_cast<clang::Decl*>(static_cast<const clang::Decl*>(S.data[0]));
         ^

auto* I = getInterpreter(scope);
if (const Cpp::JitCall JC = Cpp::MakeFunctionCallableImpl(I, getDecl(Ctor))) {
if (arena) {
JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

      JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
                            ^

auto* I = getInterpreter(scope);
if (const Cpp::JitCall JC = Cpp::MakeFunctionCallableImpl(I, getDecl(Ctor))) {
if (arena) {
JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]

      JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
                            ^

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Looks like we are quite close. Can we silence the codecov somehow without duplicating tests? Can we move the refactorings in CppInterOp.cpp as a separate PR?

*
* \param prepend Whether to prepend the directory to the search path.
*/
void clang_interpreter_addSearchPath(CXInterpreter I, const char* dir,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to shorten these interfaces. Maybe Cpp_AddSearchPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we only expose opaque pointers in the C API, I believe libclang uses this naming style to warn users about the type of the input argument. However, for historical reasons, libclang appears to lack strict rules on capitalization.

The naming convention is like clang_ + ClassName + methodName or clang_ + functionName.

Here are some examples:

typedef void *CXIndexAction;
CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);

CINDEX_LINKAGE CXIdxClientContainer
clang_index_getClientContainer(const CXIdxContainerInfo *);

CINDEX_LINKAGE unsigned clang_CXXMethod_isDeleted(CXCursor C);

CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);

CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);

CINDEX_LINKAGE unsigned
clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy, enum CXPrintingPolicyProperty Property);

CINDEX_LINKAGE void
clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy,
                                 enum CXPrintingPolicyProperty Property,
                                 unsigned Value);

CINDEX_LINKAGE CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor);

CINDEX_LINKAGE void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy);

CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CXPrintingPolicy Policy);

/// This is similar to GetName() function, but besides
/// the name, it also gets the template arguments.
CPPINTEROP_API std::string GetCompleteName(TCppType_t klass);
CPPINTEROP_API std::string GetCompleteName(TCppScope_t klass);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! We should probably adopt the CX enum style so that the compiler could help us with finding these wrong cases. Related to compiler-research/CPyCppyy#8.

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Oct 27, 2024

Looks like we are quite close. Can we silence the codecov somehow without duplicating tests? Can we move the refactorings in CppInterOp.cpp as a separate PR?

Yes. I'll make another PR for the changes in CppInterOp.cpp.

@Gnimuc Gnimuc force-pushed the add-c-api2 branch 3 times, most recently from 66ccc69 to 1bb9ead Compare October 27, 2024 14:56
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 12. Check the log or trigger a new build to see more.

EXPECT_FALSE(Cpp::GetNamed("cppUnknown"));

// C API
const char* args[] = {"-std=c++14"};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

  const char* args[] = {"-std=c++14"};
        ^


// C API
const char* args[] = {"-std=c++14"};
auto CXI = clang_createInterpreter(args, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'auto CXI' can be declared as 'auto *CXI' [llvm-qualified-auto]

Suggested change
auto CXI = clang_createInterpreter(args, 1);
auto *CXI = clang_createInterpreter(args, 1);


// C API
const char* args[] = {"-std=c++14"};
auto CXI = clang_createInterpreter(args, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

  auto CXI = clang_createInterpreter(args, 1);
                                     ^

clang_Interpreter_dispose(CXI);

CXI = clang_createInterpreterFromRawPtr(I);
auto CLI = clang_Interpreter_getClangInterpreter(CXI);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'auto CLI' can be declared as 'auto *CLI' [llvm-qualified-auto]

Suggested change
auto CLI = clang_Interpreter_getClangInterpreter(CXI);
auto *CLI = clang_Interpreter_getClangInterpreter(CXI);

CXI = clang_createInterpreterFromRawPtr(I);
auto CLI = clang_Interpreter_getClangInterpreter(CXI);
EXPECT_TRUE(CLI);
auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'auto I2' can be declared as 'auto *I2' [llvm-qualified-auto]

Suggested change
auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);
auto *I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);


void dispose_string(CXString string) {
if (string.private_flags == 1 && string.data)
free(const_cast<void*>(string.data));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: calling legacy resource function without passing a 'gsl::owner<>' [cppcoreguidelines-owning-memory]

    free(const_cast<void*>(string.data));
    ^


void dispose_string(CXString string) {
if (string.private_flags == 1 && string.data)
free(const_cast<void*>(string.data));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not manage memory manually; use RAII [cppcoreguidelines-no-malloc]

    free(const_cast<void*>(string.data));
    ^


void dispose_string(CXString string) {
if (string.private_flags == 1 && string.data)
free(const_cast<void*>(string.data));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]

    free(const_cast<void*>(string.data));
         ^

free(const_cast<void*>(string.data));
}

CXScope make_scope(const clang::Decl* D, const CXInterpreter I) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'I' declared with a const-qualified typedef; results in the type being 'CXInterpreterImpl *const' instead of 'const CXInterpreterImpl *' [misc-misplaced-const]

CXScope make_scope(const clang::Decl* D, const CXInterpreter I) {
                                                             ^
Additional context

include/clang-c/CXCppInterOp.h:25: typedef declared here

typedef struct CXInterpreterImpl* CXInterpreter;
                                  ^

#include <vector>
#include "llvm/Support/Valgrind.h"
#include "clang-c/CXCppInterOp.h"
#include "clang-c/CXString.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: #includes are not sorted properly [llvm-include-order]

Suggested change
#include "clang-c/CXString.h"
#include "clang-c/CXCppInterOp.h"
#include "clang-c/CXString.h"
#include "llvm/Support/Valgrind.h"
#include <memory>
#include <vector>

Comment on lines +482 to +491
if (!clang_hasDefaultConstructor(S))
return clang::cxscope::MakeCXScope(nullptr, getNewTU(S));

auto* CXXRD = llvm::dyn_cast_or_null<clang::CXXRecordDecl>(getDecl(S));
if (!CXXRD)
return clang::cxscope::MakeCXScope(nullptr, getNewTU(S));

const auto* Res =
getInterpreter(S)->getSema().LookupDefaultConstructor(CXXRD);
return clang::cxscope::MakeCXScope(Res, getNewTU(S));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we forward to Cpp::GetDefaultConstructor? I see this trend in several interfaces. Is there some limitation on the C++ side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no particular reasons. I forwarded this one to the C++ API. As for other interpreter-related APIs, the C++ implementation is also a thin wrapper, so I copied the implementation on the C API side.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions


void dispose_string(CXString string);

CXScope make_scope(const clang::Decl* D, const CXInterpreter I);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'I' declared with a const-qualified typedef; results in the type being 'CXInterpreterImpl *const' instead of 'const CXInterpreterImpl *' [misc-misplaced-const]

CXScope make_scope(const clang::Decl* D, const CXInterpreter I);
                                                             ^
Additional context

include/clang-c/CXCppInterOp.h:25: typedef declared here

typedef struct CXInterpreterImpl* CXInterpreter;
                                  ^


void dispose_string(CXString string);

CXScope make_scope(const clang::Decl* D, const CXInterpreter I);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: parameter 'I' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
CXScope make_scope(const clang::Decl* D, const CXInterpreter I);
CXScope make_scope(const clang::Decl* D, CXInterpreter I);

@vgvassilev
Copy link
Contributor

Do we know why some builds are failing?

if (!D)
return CXCursor_UnexposedDecl;

switch (D->getKind()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the preprocessor to expand it but I think we could steal the implementation from clang::ASTNodeKind or just forward to it...

#define BTCASE(K) \
case BuiltinType::K: \
return CXType_##K
switch (BT->getKind()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use something like:

define BUILTIN_TYPE(Id, SingletonId) \
  case BuiltinType::Id: return ...
#include "clang/AST/BuiltinTypes.def"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are copied from libclang's source code. Since we will make the merge in the upstream in the future, it would be better to submit PRs to the upstream directly.

case Type::K: \
return CXType_##K
switch (TP->getTypeClass()) {
case Type::Builtin:
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

@mcbarton mcbarton force-pushed the add-c-api2 branch 2 times, most recently from b13674d to de15348 Compare December 2, 2024 20:44
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 116. Check the log or trigger a new build to see more.

#include "clang-c/ExternC.h"
#include "clang-c/Index.h"
#include "clang-c/Platform.h"

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header Platform.h is not used directly [misc-include-cleaner]

Suggested change

#include "clang-c/Index.h"
#include "clang-c/Platform.h"

#include <stdbool.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: including 'stdbool.h' has no effect in C++; consider removing it [modernize-deprecated-headers]

Suggested change
#include <stdbool.h>

#include "clang-c/Platform.h"

#include <stdbool.h>
#include <stddef.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead [modernize-deprecated-headers]

Suggested change
#include <stddef.h>
#include <cstddef>


#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: inclusion of deprecated C++ header 'stdint.h'; consider using 'cstdint' instead [modernize-deprecated-headers]

Suggested change
#include <stdint.h>
#include <cstdint>

/**
* An opaque pointer representing an interpreter context.
*/
typedef struct CXInterpreterImpl* CXInterpreter;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
typedef struct CXInterpreterImpl* CXInterpreter;
using CXInterpreter = struct CXInterpreterImpl *;

*/
CXInterpreter clang_createInterpreter(const char* const* argv, int argc);

typedef void* TInterp_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
typedef void* TInterp_t;
using TInterp_t = void *;

* Describes the return result of the different routines that do the incremental
* compilation.
*/
typedef enum {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: enum 'CXInterpreter_CompilationResult' uses a larger base type ('unsigned int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

typedef enum {
        ^

* More more input is expected.
*/
CXInterpreter_MoreInputExpected = 2,
} CXInterpreter_CompilationResult;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
} CXInterpreter_CompilationResult;
using CXInterpreter_CompilationResult = enum {
/**
* The compilation was successful.
*/
CXInterpreter_Success = 0,
/**
* The compilation failed.
*/
CXInterpreter_Failure = 1,
/**
* More more input is expected.
*/
CXInterpreter_MoreInputExpected = 2,
};

* An opaque pointer representing a lightweight struct that is used for carrying
* execution results.
*/
typedef void* CXValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
typedef void* CXValue;
using CXValue = void *;

enum CXCursorKind kind;
int xdata;
const void* data[3];
} CXScope;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
} CXScope;
using CXScope = struct {
enum CXCursorKind kind;
int xdata;
const void* data[3];
};

@vgvassilev
Copy link
Contributor

@Gnimuc, any chance to make progress on this pr?

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Dec 3, 2024

@Gnimuc, any chance to make progress on this pr?

Sorry for the late response. I'll give it a look this weekend.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 106. Check the log or trigger a new build to see more.

typedef struct {
void* Type;
const char* IntegralValue;
} CXTemplateArgInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
} CXTemplateArgInfo;
using CXTemplateArgInfo = struct {
void* Type;
const char* IntegralValue;
};

typedef struct {
enum CXTypeKind kind;
void* data[2];
} CXQualType;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
} CXQualType;
using CXQualType = struct {
enum CXTypeKind kind;
void* data[2];
};

/**
* An opaque pointer representing the object of a given type (\c CXScope).
*/
typedef void* CXObject;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use 'using' instead of 'typedef' [modernize-use-using]

Suggested change
typedef void* CXObject;
using CXObject = void *;

@@ -0,0 +1,627 @@
#include "clang-c/CXCppInterOp.h"
#include "Compatibility.h"
#include "clang/AST/CXXInheritance.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: #includes are not sorted properly [llvm-include-order]

#include "clang/AST/CXXInheritance.h"
^

this fix will not be applied because it overlaps with another fix

#include "clang/Frontend/CompilerInstance.h"
#include "clang/Interpreter/CppInterOp.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Sema.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header Lookup.h is not used directly [misc-include-cleaner]

Suggested change
#include "clang/Sema/Sema.h"
#include "clang/Sema/Sema.h"

#include "clang/Sema/Sema.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/Support/Casting.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header LLJIT.h is not used directly [misc-include-cleaner]

Suggested change
#include "llvm/Support/Casting.h"
#include "llvm/Support/Casting.h"

#include "llvm/Support/Casting.h"
#include <cstring>
#include <iterator>
#include "clang-c/CXString.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header iterator is not used directly [misc-include-cleaner]

Suggested change
#include "clang-c/CXString.h"
#include "clang-c/CXString.h"

// copied and tweaked from libclang
namespace clang {

CXCursorKind cxcursor_getCursorKindForDecl(const Decl* D) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursorKind" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang-c/Index.h>
+ #include <cstring>


CXCursorKind cxcursor_getCursorKindForDecl(const Decl* D) {
if (!D)
return CXCursor_UnexposedDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_UnexposedDecl" is directly included [misc-include-cleaner]

    return CXCursor_UnexposedDecl;
           ^


switch (D->getKind()) {
case Decl::Enum:
return CXCursor_EnumDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_EnumDecl" is directly included [misc-include-cleaner]

    return CXCursor_EnumDecl;
           ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 92. Check the log or trigger a new build to see more.

case Decl::Enum:
return CXCursor_EnumDecl;
case Decl::EnumConstant:
return CXCursor_EnumConstantDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_EnumConstantDecl" is directly included [misc-include-cleaner]

    return CXCursor_EnumConstantDecl;
           ^

case Decl::EnumConstant:
return CXCursor_EnumConstantDecl;
case Decl::Field:
return CXCursor_FieldDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_FieldDecl" is directly included [misc-include-cleaner]

    return CXCursor_FieldDecl;
           ^

case Decl::Field:
return CXCursor_FieldDecl;
case Decl::Function:
return CXCursor_FunctionDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_FunctionDecl" is directly included [misc-include-cleaner]

    return CXCursor_FunctionDecl;
           ^

case Decl::Function:
return CXCursor_FunctionDecl;
case Decl::CXXMethod:
return CXCursor_CXXMethod;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_CXXMethod" is directly included [misc-include-cleaner]

    return CXCursor_CXXMethod;
           ^

case Decl::CXXMethod:
return CXCursor_CXXMethod;
case Decl::CXXConstructor:
return CXCursor_Constructor;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_Constructor" is directly included [misc-include-cleaner]

    return CXCursor_Constructor;
           ^

case Decl::CXXConstructor:
return CXCursor_Constructor;
case Decl::CXXDestructor:
return CXCursor_Destructor;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_Destructor" is directly included [misc-include-cleaner]

    return CXCursor_Destructor;
           ^

case Decl::CXXDestructor:
return CXCursor_Destructor;
case Decl::CXXConversion:
return CXCursor_ConversionFunction;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_ConversionFunction" is directly included [misc-include-cleaner]

    return CXCursor_ConversionFunction;
           ^

case Decl::CXXConversion:
return CXCursor_ConversionFunction;
case Decl::ParmVar:
return CXCursor_ParmDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_ParmDecl" is directly included [misc-include-cleaner]

    return CXCursor_ParmDecl;
           ^

case Decl::ParmVar:
return CXCursor_ParmDecl;
case Decl::Typedef:
return CXCursor_TypedefDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_TypedefDecl" is directly included [misc-include-cleaner]

    return CXCursor_TypedefDecl;
           ^

case Decl::Typedef:
return CXCursor_TypedefDecl;
case Decl::TypeAlias:
return CXCursor_TypeAliasDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_TypeAliasDecl" is directly included [misc-include-cleaner]

    return CXCursor_TypeAliasDecl;
           ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 82. Check the log or trigger a new build to see more.

case Decl::TypeAlias:
return CXCursor_TypeAliasDecl;
case Decl::TypeAliasTemplate:
return CXCursor_TypeAliasTemplateDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_TypeAliasTemplateDecl" is directly included [misc-include-cleaner]

    return CXCursor_TypeAliasTemplateDecl;
           ^

case Decl::TypeAliasTemplate:
return CXCursor_TypeAliasTemplateDecl;
case Decl::Var:
return CXCursor_VarDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_VarDecl" is directly included [misc-include-cleaner]

    return CXCursor_VarDecl;
           ^

case Decl::Var:
return CXCursor_VarDecl;
case Decl::Namespace:
return CXCursor_Namespace;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_Namespace" is directly included [misc-include-cleaner]

    return CXCursor_Namespace;
           ^

case Decl::Namespace:
return CXCursor_Namespace;
case Decl::NamespaceAlias:
return CXCursor_NamespaceAlias;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_NamespaceAlias" is directly included [misc-include-cleaner]

    return CXCursor_NamespaceAlias;
           ^

case Decl::NamespaceAlias:
return CXCursor_NamespaceAlias;
case Decl::TemplateTypeParm:
return CXCursor_TemplateTypeParameter;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_TemplateTypeParameter" is directly included [misc-include-cleaner]

    return CXCursor_TemplateTypeParameter;
           ^

case Decl::TemplateTypeParm:
return CXCursor_TemplateTypeParameter;
case Decl::NonTypeTemplateParm:
return CXCursor_NonTypeTemplateParameter;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_NonTypeTemplateParameter" is directly included [misc-include-cleaner]

    return CXCursor_NonTypeTemplateParameter;
           ^

case Decl::NonTypeTemplateParm:
return CXCursor_NonTypeTemplateParameter;
case Decl::TemplateTemplateParm:
return CXCursor_TemplateTemplateParameter;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_TemplateTemplateParameter" is directly included [misc-include-cleaner]

    return CXCursor_TemplateTemplateParameter;
           ^

case Decl::TemplateTemplateParm:
return CXCursor_TemplateTemplateParameter;
case Decl::FunctionTemplate:
return CXCursor_FunctionTemplate;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_FunctionTemplate" is directly included [misc-include-cleaner]

    return CXCursor_FunctionTemplate;
           ^

case Decl::FunctionTemplate:
return CXCursor_FunctionTemplate;
case Decl::ClassTemplate:
return CXCursor_ClassTemplate;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_ClassTemplate" is directly included [misc-include-cleaner]

    return CXCursor_ClassTemplate;
           ^

case Decl::ClassTemplate:
return CXCursor_ClassTemplate;
case Decl::AccessSpec:
return CXCursor_CXXAccessSpecifier;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_CXXAccessSpecifier" is directly included [misc-include-cleaner]

    return CXCursor_CXXAccessSpecifier;
           ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 68. Check the log or trigger a new build to see more.

case Decl::AccessSpec:
return CXCursor_CXXAccessSpecifier;
case Decl::ClassTemplatePartialSpecialization:
return CXCursor_ClassTemplatePartialSpecialization;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_ClassTemplatePartialSpecialization" is directly included [misc-include-cleaner]

    return CXCursor_ClassTemplatePartialSpecialization;
           ^

case Decl::ClassTemplatePartialSpecialization:
return CXCursor_ClassTemplatePartialSpecialization;
case Decl::UsingDirective:
return CXCursor_UsingDirective;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_UsingDirective" is directly included [misc-include-cleaner]

    return CXCursor_UsingDirective;
           ^

case Decl::UsingDirective:
return CXCursor_UsingDirective;
case Decl::StaticAssert:
return CXCursor_StaticAssert;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_StaticAssert" is directly included [misc-include-cleaner]

    return CXCursor_StaticAssert;
           ^

case Decl::StaticAssert:
return CXCursor_StaticAssert;
case Decl::Friend:
return CXCursor_FriendDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_FriendDecl" is directly included [misc-include-cleaner]

    return CXCursor_FriendDecl;
           ^

case Decl::Friend:
return CXCursor_FriendDecl;
case Decl::TranslationUnit:
return CXCursor_TranslationUnit;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_TranslationUnit" is directly included [misc-include-cleaner]

    return CXCursor_TranslationUnit;
           ^

case Decl::Using:
case Decl::UnresolvedUsingValue:
case Decl::UnresolvedUsingTypename:
return CXCursor_UsingDeclaration;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_UsingDeclaration" is directly included [misc-include-cleaner]

    return CXCursor_UsingDeclaration;
           ^

return CXCursor_EnumDecl;

default:
if (const auto* TD = dyn_cast<TagDecl>(D)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "clang::dyn_cast" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang/Basic/LLVM.h>
+ #include <cstring>

default:
if (const auto* TD = dyn_cast<TagDecl>(D)) {
switch (TD->getTagKind()) {
#if CLANG_VERSION_MAJOR >= 18
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CLANG_VERSION_MAJOR" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang/Basic/Version.h>
+ #include <cstring>

#else
case TagTypeKind::TTK_Interface: // fall through
case TagTypeKind::TTK_Struct:
return CXCursor_StructDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_StructDecl" is directly included [misc-include-cleaner]

        return CXCursor_StructDecl;
               ^

case TagTypeKind::TTK_Struct:
return CXCursor_StructDecl;
case TagTypeKind::TTK_Class:
return CXCursor_ClassDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_ClassDecl" is directly included [misc-include-cleaner]

        return CXCursor_ClassDecl;
               ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 60. Check the log or trigger a new build to see more.

case TagTypeKind::TTK_Class:
return CXCursor_ClassDecl;
case TagTypeKind::TTK_Union:
return CXCursor_UnionDecl;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_UnionDecl" is directly included [misc-include-cleaner]

        return CXCursor_UnionDecl;
               ^

return CXCursor_UnexposedDecl;
}

CXTypeKind cxtype_GetBuiltinTypeKind(const BuiltinType* BT) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXTypeKind" is directly included [misc-include-cleaner]

CXTypeKind cxtype_GetBuiltinTypeKind(const BuiltinType* BT) {
^

}

CXTypeKind cxtype_GetBuiltinTypeKind(const BuiltinType* BT) {
#define BTCASE(K) \
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function-like macro 'BTCASE' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]

#define BTCASE(K)                                                              \
        ^

BTCASE(UInt128);
BTCASE(Char_S);
BTCASE(SChar);
case BuiltinType::WChar_S:
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: switch has 2 consecutive identical branches [bugprone-branch-clone]

  case BuiltinType::WChar_S:
  ^
Additional context

lib/Interpreter/CXCppInterOp.cpp:140: last of these clones ends here

    return CXType_WChar;
                       ^

BTCASE(Char_S);
BTCASE(SChar);
case BuiltinType::WChar_S:
return CXType_WChar;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXType_WChar" is directly included [misc-include-cleaner]

    return CXType_WChar;
           ^

BTCASE(Float128);
BTCASE(NullPtr);
default:
return CXType_Unexposed;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXType_Unexposed" is directly included [misc-include-cleaner]

    return CXType_Unexposed;
           ^

CXTypeKind cxtype_GetTypeKind(QualType T) {
const Type* TP = T.getTypePtrOrNull();
if (!TP)
return CXType_Invalid;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXType_Invalid" is directly included [misc-include-cleaner]

    return CXType_Invalid;
           ^

if (!TP)
return CXType_Invalid;

#define TKCASE(K) \
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function-like macro 'TKCASE' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]

#define TKCASE(K)                                                              \
        ^

return CXType_##K
switch (TP->getTypeClass()) {
case Type::Builtin:
return cxtype_GetBuiltinTypeKind(cast<BuiltinType>(TP));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "clang::cast" is directly included [misc-include-cleaner]

    return cxtype_GetBuiltinTypeKind(cast<BuiltinType>(TP));
                                     ^

namespace cxscope {

CXScope MakeCXScope(const clang::Decl* D, const CXInterpreterImpl* I,
SourceRange RegionOfInterest = SourceRange(),
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "clang::SourceRange" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang/Basic/SourceLocation.h>
+ #include <cstring>

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Dec 8, 2024

Do we know why some builds are failing?

I added clang_createInterpreter to create a Clang interpreter from scratch without any default settings. (I need this feature to make it work with the environment of Julia's package system.) The current CI test environment is for Cpp::CreateInterpreter so there could be issues when calling clang_createInterpreter without appropriate arguments.

The CI only fails on cling now. This is expected because the C API is for working with clang::Interpreter and does not support cling.

@vgvassilev
Copy link
Contributor

Do we know why some builds are failing?

I added clang_createInterpreter to create a Clang interpreter from scratch without any default settings. (I need this feature to make it work with the environment of Julia's package system.) The current CI test environment is for Cpp::CreateInterpreter so there could be issues when calling clang_createInterpreter without appropriate arguments.

The CI only fails on cling now. This is expected because the C API is for working with clang::Interpreter and does not support cling.

IIUC, @aaronj0, has a patch in that area where we have extern "C" CppInterOp_CreateInterpreter. Would that help here?

EXPECT_FALSE(Cpp::GetNamed("cppUnknown"));

// C API
auto CXI = clang_createInterpreterFromRawPtr(I);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this fails with cling we can wrap it with #ifndef USE_CLING

@Gnimuc
Copy link
Contributor Author

Gnimuc commented Dec 9, 2024

Do we know why some builds are failing?

I added clang_createInterpreter to create a Clang interpreter from scratch without any default settings. (I need this feature to make it work with the environment of Julia's package system.) The current CI test environment is for Cpp::CreateInterpreter so there could be issues when calling clang_createInterpreter without appropriate arguments.
The CI only fails on cling now. This is expected because the C API is for working with clang::Interpreter and does not support cling.

IIUC, @aaronj0, has a patch in that area where we have extern "C" CppInterOp_CreateInterpreter. Would that help here?

Did you mean Cpp::UseExternalInterpreter? It can address the problem if a Cling/Clang interpreter instance is already available. On the other hand, clang_createInterpreter is the C API used to create such an interpreter.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 50. Check the log or trigger a new build to see more.

CXScope MakeCXScope(const clang::Decl* D, const CXInterpreterImpl* I,
SourceRange RegionOfInterest = SourceRange(),
bool FirstInDeclGroup = true) {
assert(D && I && "Invalid arguments!");
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "assert" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <cassert>
+ #include <cstring>


CXCursorKind K = cxcursor_getCursorKindForDecl(D);

CXScope S = {K, 0, {D, (void*)(intptr_t)(FirstInDeclGroup ? 1 : 0), I}};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

  CXScope S = {K, 0, {D, (void*)(intptr_t)(FirstInDeclGroup ? 1 : 0), I}};
                         ^


CXCursorKind K = cxcursor_getCursorKindForDecl(D);

CXScope S = {K, 0, {D, (void*)(intptr_t)(FirstInDeclGroup ? 1 : 0), I}};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]

  CXScope S = {K, 0, {D, (void*)(intptr_t)(FirstInDeclGroup ? 1 : 0), I}};
                         ^


CXCursorKind K = cxcursor_getCursorKindForDecl(D);

CXScope S = {K, 0, {D, (void*)(intptr_t)(FirstInDeclGroup ? 1 : 0), I}};
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "intptr_t" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <cstdint>
+ #include <cstring>


} // namespace clang

CXString makeCXString(const std::string& S) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::string" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <string>
+ #include "clang-c/CXString.h"

Str.data = "";
Str.private_flags = 0; // CXS_Unmanaged
} else {
Str.data = strdup(S.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "strdup" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <string.h>
+ #include "clang-c/CXString.h"

return Str;
}

CXStringSet* makeCXStringSet(const std::vector<std::string>& Strs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <vector>
+ #include "clang-c/CXString.h"

}

struct CXInterpreterImpl {
std::unique_ptr<compat::Interpreter> Interp;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::unique_ptr" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <memory>
+ #include "clang-c/CXString.h"


CXInterpreter clang_createInterpreter(const char* const* argv, int argc) {
auto* I = new CXInterpreterImpl(); // NOLINT(*-owning-memory)
I->Interp = std::make_unique<compat::Interpreter>(argc, argv);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::make_unique" is directly included [misc-include-cleaner]

  I->Interp = std::make_unique<compat::Interpreter>(argc, argv);
                   ^

return nullptr;
#else
auto* interp = getInterpreter(I);
auto* clInterp = &static_cast<clang::Interpreter&>(*interp);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "clang::Interpreter" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang/Interpreter/Interpreter.h>
+ #include <cstring>

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

LGTM!

- Add `CXScope` and `CXQualType` as a bridge between libclang types and CppInterOp's types
- Add C API for interpreter and scope manipulations
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 40. Check the log or trigger a new build to see more.

return static_cast<CXInterpreterImpl*>(I)->Interp.release();
}

enum CXErrorCode clang_Interpreter_undo(CXInterpreter I, unsigned int N) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXErrorCode" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang-c/CXErrorCode.h>
+ #include <cstring>

#ifdef USE_CLING
return CXError_Failure;
#else
return getInterpreter(I)->Undo(N) ? CXError_Failure : CXError_Success;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXError_Failure" is directly included [misc-include-cleaner]

  return getInterpreter(I)->Undo(N) ? CXError_Failure : CXError_Success;
                                      ^

#ifdef USE_CLING
return CXError_Failure;
#else
return getInterpreter(I)->Undo(N) ? CXError_Failure : CXError_Success;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXError_Success" is directly included [misc-include-cleaner]

  return getInterpreter(I)->Undo(N) ? CXError_Failure : CXError_Success;
                                                        ^

#ifdef USE_CLING
auto val = std::make_unique<cling::Value>();
#else
auto val = std::make_unique<clang::Value>();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "clang::Value" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:15:

- #include <cstring>
+ #include <clang/Interpreter/Value.h>
+ #include <cstring>

namespace Cpp {
bool InsertOrReplaceJitSymbol(compat::Interpreter& I,
const char* linker_mangled_name,
uint64_t address);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "uint64_t" is directly included [misc-include-cleaner]

                              uint64_t address);
                              ^

static inline bool isNull(const CXScope& S) { return !S.data[0]; }

static inline clang::Decl* getDecl(const CXScope& S) {
return const_cast<clang::Decl*>(static_cast<const clang::Decl*>(S.data[0]));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]

  return const_cast<clang::Decl*>(static_cast<const clang::Decl*>(S.data[0]));
         ^

auto* D = getDecl(func);
if (const auto* FD = llvm::dyn_cast<clang::FunctionDecl>(D)) {
std::string Signature;
llvm::raw_string_ostream SS(Signature);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "llvm::raw_string_ostream" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <llvm/Support/raw_ostream.h>
+ #include "clang-c/CXString.h"

}

bool clang_existsFunctionTemplate(const char* name, CXScope parent) {
if (kind(parent) == CXCursor_FirstInvalid || !name)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "CXCursor_FirstInvalid" is directly included [misc-include-cleaner]

  if (kind(parent) == CXCursor_FirstInvalid || !name)
                      ^

const auto* Within = llvm::dyn_cast<clang::DeclContext>(getDecl(parent));

auto& S = getInterpreter(parent)->getSema();
auto* ND = Cpp::Cpp_utils::Lookup::Named(&S, name, Within);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "Cpp::utils::Lookup::Named" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:2:

- #include "clang/AST/CXXInheritance.h"
+ #include "CppInterOpInterpreter.h"
+ #include "clang/AST/CXXInheritance.h"

size_t template_args_size) {
auto* I = getInterpreter(tmpl);

llvm::SmallVector<Cpp::TemplateArgInfo> Info;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "llvm::SmallVector" is directly included [misc-include-cleaner]

lib/Interpreter/CXCppInterOp.cpp:17:

- #include "clang-c/CXString.h"
+ #include <llvm/ADT/SmallVector.h>
+ #include "clang-c/CXString.h"

@vgvassilev vgvassilev merged commit e9610ba into compiler-research:main Dec 10, 2024
42 of 44 checks passed
@Gnimuc Gnimuc deleted the add-c-api2 branch December 10, 2024 10:46
@Gnimuc
Copy link
Contributor Author

Gnimuc commented Dec 10, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants