Skip to content

Commit

Permalink
Improve type safety -- Take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Jun 11, 2024
1 parent a2f4f76 commit a2e3769
Show file tree
Hide file tree
Showing 4 changed files with 651 additions and 67 deletions.
162 changes: 139 additions & 23 deletions include/clang-c/CXCppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ CXString clang_interpreter_searchLibrariesForSymbol(CXInterpreter I,
const char* mangled_name,
bool search_system);

typedef void* CXFuncAddr;

/**
* Get the function address from the given mangled name.
*
* \param I The interpreter.
*
* \param mangled_name The mangled name of the function.
*
* \returns the address of the function given its potentially mangled name.
*/
CXFuncAddr
clang_interpreter_getFunctionAddressFromMangledName(CXInterpreter I,
const char* mangled_name);

/**
* @}
*/
Expand All @@ -212,6 +227,8 @@ CXString clang_interpreter_searchLibrariesForSymbol(CXInterpreter I,
*/
typedef void* CXObject;

typedef void* CXFunction;

/**
* \defgroup CPPINTEROP_TYPE_MANIP Type manipulations
*
Expand All @@ -223,6 +240,7 @@ typedef void* CXObject;
*/
enum CXQualTypeKind {
CXQualType_Unexposed = 0,
CXQualType_Invalid = 1,
// reserved for future use
};

Expand Down Expand Up @@ -256,6 +274,11 @@ CXQualType clang_qualtype_getIntegerTypeFromEnumType(CXQualType type);
*/
size_t clang_qualtype_getSizeOfType(CXQualType type);

/**
* Checks if a C++ type derives from another.
*/
bool clang_qualtype_isTypeDerivedFrom(CXQualType derived, CXQualType base);

/**
* @}
*/
Expand All @@ -270,12 +293,14 @@ size_t clang_qualtype_getSizeOfType(CXQualType type);
* Describes the kind of entity that a scope refers to.
*/
enum CXScopeKind {
/** Generic declarations. */
CXScope_Unexposed = 0,
/** Function, methods, etc. */
CXScope_Function = 1,
CXScope_Invalid = 1,
/** Function, methods, constructor etc. */
CXScope_Function = 2,
/** Variables. */
CXScope_Variable = 2,
CXScope_Variable = 3,
/** Fields. */
CXScope_Field = 4,
// reserved for future use
};

Expand All @@ -288,6 +313,9 @@ typedef struct {
const void* meta;
} CXScope;

// for debugging purposes
void clang_scope_dump(CXScope S);

/**
* This will convert a class into its type, so for example, you can use it to
* declare variables in it.
Expand Down Expand Up @@ -423,6 +451,13 @@ CXString clang_scope_getQualifiedCompleteName(CXScope S);
*/
size_t clang_scope_getNumBases(CXScope S);

/**
* Gets a specific Base Class using its index. Typically GetNumBases()
* is used to get the number of Base Classes, and then that number can be used
* to iterate through the index value to get each specific base class.
*/
CXScope clang_scope_getBaseClass(CXScope S, size_t ibase);

/**
* Checks if the supplied Derived Class is a sub-class of the provided Base
* Class.
Expand All @@ -440,8 +475,6 @@ int64_t clang_scope_getBaseClassOffset(CXScope derived, CXScope base);
*/
bool clang_scope_hasDefaultConstructor(CXScope S);

typedef void* CXFunction;

/**
* Returns the default constructor of a class, if any.
*/
Expand All @@ -462,12 +495,110 @@ CXScope clang_scope_getDestructor(CXScope S);
/**
* Gets the return type of the provided function.
*/
CXQualType clang_scope_getFunctionReturnType(CXScope S);
CXQualType clang_scope_getFunctionReturnType(CXScope func);

/**
* Gets the number of Arguments for the provided function.
*/
size_t clang_scope_getFunctionNumArgs(CXScope S);
size_t clang_scope_getFunctionNumArgs(CXScope func);

/**
* Gets the number of Required Arguments for the provided function.
*/
size_t clang_scope_getFunctionRequiredArgs(CXScope func);

/**
* For each Argument of a function, you can get the Argument Type by providing
* the Argument Index, based on the number of arguments from the
* GetFunctionNumArgs() function.
*/
CXQualType clang_scope_getFunctionArgType(CXScope func, size_t iarg);

/**
* Returns a stringified version of a given function signature in the form:
* void N::f(int i, double d, long l = 0, char ch = 'a').
*/
CXString clang_scope_getFunctionSignature(CXScope func);

/**
* Checks if a function was marked as \c =delete.
*/
bool clang_scope_isFunctionDeleted(CXScope func);

/**
* Checks if a function is a templated function.
*/
bool clang_scope_isTemplatedFunction(CXScope func);

/**
* This function performs a lookup to check if there is a templated function of
* that type.
*/
bool clang_scope_existsFunctionTemplate(const CXInterpreter I, const char* name,
CXScope parent);

/**
* Checks if the provided parameter is a method.
*/
bool clang_scope_isMethod(CXScope method);

/**
* Checks if the provided parameter is a 'Public' method.
*/
bool clang_scope_isPublicMethod(CXScope method);

/**
* Checks if the provided parameter is a 'Protected' method.
*/
bool clang_scope_isProtectedMethod(CXScope method);

/**
* Checks if the provided parameter is a 'Private' method.
*/
bool clang_scope_isPrivateMethod(CXScope method);

/**
* Checks if the provided parameter is a 'Private' method.
*/
bool clang_scope_isPrivateMethod(CXScope method);

/**
* Checks if the provided parameter is a Constructor.
*/
bool clang_scope_isConstructor(CXScope method);

/**
* Checks if the provided parameter is a Destructor.
*/
bool clang_scope_isDestructor(CXScope method);

/**
* Checks if the provided parameter is a 'Static' method.
*/
bool clang_scope_isStaticMethod(CXScope method);

/**
* Returns the address of the function given its function declaration.
*/
CXFuncAddr clang_scope_getFunctionAddress(CXScope method);

/**
* Checks if the provided parameter is a 'Virtual' method.
*/
bool clang_scope_isVirtualMethod(CXScope method);

/**
* Gets all the Fields/Data Members of a Class. For now, it only gets non-static
* data members but in a future update, it may support getting static data
* members as well.
*/
// std::vector<CXScope> clang_scope_getDatamembers(CXScope method);

/**
* This is a Lookup function to be used specifically for data members.
*/
CXScope clang_scope_lookupDatamember(const CXInterpreter I, const char* name,
CXScope parent);

/**
* @}
Expand Down Expand Up @@ -534,21 +665,6 @@ void clang_interpreter_construct(CXInterpreter I, CXScope type, void* arena);
void clang_interpreter_destruct(CXInterpreter I, CXObject This, CXScope type,
bool withFree);

typedef void* CXFuncAddr;

/**
* Get the function address from the given mangled name.
*
* \param I The interpreter.
*
* \param mangled_name The mangled name of the function.
*
* \returns the address of the function given its potentially mangled name.
*/
CXFuncAddr
clang_interpreter_getFunctionAddressFromMangledName(CXInterpreter I,
const char* mangled_name);

/**
* An opaque pointer representing CppInterOp's JitCall, a class modeling
* function calls for functions produced by the interpreter in compiled code.
Expand Down
2 changes: 1 addition & 1 deletion include/clang/Interpreter/CppInterOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ namespace Cpp {
/// is used to get the number of Base Classes, and then that number
/// can be used to iterate through the index value to get each specific
/// base class.
CPPINTEROP_API TCppScope_t GetBaseClass(TCppType_t klass, TCppIndex_t ibase);
CPPINTEROP_API TCppScope_t GetBaseClass(TCppScope_t klass, TCppIndex_t ibase);

/// Checks if the supplied Derived Class is a sub-class of the
/// provided Base Class.
Expand Down
Loading

0 comments on commit a2e3769

Please sign in to comment.