Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:49

0001 //--------------------------------------------------------------------*- C++ -*-
0002 // CLING - the C++ LLVM-based InterpreterG :)
0003 // author:  Vassil Vassilev <vvasilev@cern.ch>
0004 //
0005 // This file is dual-licensed: you can choose to license it under the University
0006 // of Illinois Open Source License or the GNU Lesser General Public License. See
0007 // LICENSE.TXT for details.
0008 //------------------------------------------------------------------------------
0009 
0010 #ifndef CPPINTEROP_CPPINTEROP_H
0011 #define CPPINTEROP_CPPINTEROP_H
0012 
0013 #include <cassert>
0014 #include <cstdint>
0015 #include <set>
0016 #include <string>
0017 #include <vector>
0018 
0019 // The cross-platform CPPINTEROP_API macro definition
0020 #if defined _WIN32 || defined __CYGWIN__
0021 #define CPPINTEROP_API __declspec(dllexport)
0022 #else
0023 #ifdef __GNUC__
0024 #define CPPINTEROP_API __attribute__((__visibility__("default")))
0025 #else
0026 #define CPPINTEROP_API
0027 #endif
0028 #endif
0029 
0030 namespace Cpp {
0031   using TCppIndex_t = size_t;
0032   using TCppScope_t = void*;
0033   using TCppType_t = void*;
0034   using TCppFunction_t = void*;
0035   using TCppConstFunction_t = const void*;
0036   using TCppFuncAddr_t = void*;
0037   using TInterp_t = void*;
0038   using TCppObject_t = void*;
0039 
0040   enum Operator {
0041     OP_None,
0042     OP_New,
0043     OP_Delete,
0044     OP_Array_New,
0045     OP_Array_Delete,
0046     OP_Plus,
0047     OP_Minus,
0048     OP_Star,
0049     OP_Slash,
0050     OP_Percent,
0051     OP_Caret,
0052     OP_Amp,
0053     OP_Pipe,
0054     OP_Tilde,
0055     OP_Exclaim,
0056     OP_Equal,
0057     OP_Less,
0058     OP_Greater,
0059     OP_PlusEqual,
0060     OP_MinusEqual,
0061     OP_StarEqual,
0062     OP_SlashEqual,
0063     OP_PercentEqual,
0064     OP_CaretEqual,
0065     OP_AmpEqual,
0066     OP_PipeEqual,
0067     OP_LessLess,
0068     OP_GreaterGreater,
0069     OP_LessLessEqual,
0070     OP_GreaterGreaterEqual,
0071     OP_EqualEqual,
0072     OP_ExclaimEqual,
0073     OP_LessEqual,
0074     OP_GreaterEqual,
0075     OP_Spaceship,
0076     OP_AmpAmp,
0077     OP_PipePipe,
0078     OP_PlusPlus,
0079     OP_MinusMinus,
0080     OP_Comma,
0081     OP_ArrowStar,
0082     OP_Arrow,
0083     OP_Call,
0084     OP_Subscript,
0085     OP_Conditional,
0086     OP_Coawait,
0087   };
0088 
0089   enum OperatorArity { kUnary = 1, kBinary, kBoth };
0090 
0091   /// A class modeling function calls for functions produced by the interpreter
0092   /// in compiled code. It provides an information if we are calling a standard
0093   /// function, constructor or destructor.
0094   class JitCall {
0095   public:
0096     friend CPPINTEROP_API JitCall
0097     MakeFunctionCallable(TInterp_t I, TCppConstFunction_t func);
0098     enum Kind : char {
0099       kUnknown = 0,
0100       kGenericCall,
0101       kDestructorCall,
0102     };
0103     struct ArgList {
0104       void** m_Args = nullptr;
0105       size_t m_ArgSize = 0;
0106       // Clang struggles with =default...
0107       ArgList() : m_Args(nullptr), m_ArgSize(0) {}
0108       ArgList(void** Args, size_t ArgSize)
0109         : m_Args(Args), m_ArgSize(ArgSize) {}
0110     };
0111     // FIXME: Figure out how to unify the wrapper signatures.
0112     // FIXME: Hide these implementation details by moving wrapper generation in
0113     // this class.
0114     using GenericCall = void (*)(void*, int, void**, void*);
0115     using DestructorCall = void (*)(void*, unsigned long, int);
0116   private:
0117     union {
0118       GenericCall m_GenericCall;
0119       DestructorCall m_DestructorCall;
0120     };
0121     const Kind m_Kind;
0122     TCppConstFunction_t m_FD;
0123     JitCall() : m_Kind(kUnknown), m_GenericCall(nullptr), m_FD(nullptr) {}
0124     JitCall(Kind K, GenericCall C, TCppConstFunction_t FD)
0125       : m_Kind(K), m_GenericCall(C), m_FD(FD) {}
0126     JitCall(Kind K, DestructorCall C, TCppConstFunction_t Dtor)
0127       : m_Kind(K), m_DestructorCall(C), m_FD(Dtor) {}
0128 
0129     /// Checks if the passed arguments are valid for the given function.
0130     CPPINTEROP_API bool AreArgumentsValid(void* result, ArgList args,
0131                                           void* self) const;
0132 
0133     /// This function is used for debugging, it reports when the function was
0134     /// called.
0135     CPPINTEROP_API void ReportInvokeStart(void* result, ArgList args,
0136                                           void* self) const;
0137     CPPINTEROP_API void ReportInvokeStart(void* object, unsigned long nary,
0138                                           int withFree) const;
0139     void ReportInvokeEnd() const;
0140   public:
0141     Kind getKind() const { return m_Kind; }
0142     bool isValid() const { return getKind() != kUnknown; }
0143     bool isInvalid() const { return !isValid(); }
0144     explicit operator bool() const { return isValid(); }
0145 
0146     // Specialized for calling void functions.
0147     void Invoke(ArgList args = {}, void* self = nullptr) const {
0148       Invoke(/*result=*/nullptr, args, self);
0149     }
0150 
0151     /// Makes a call to a generic function or method.
0152     ///\param[in] result - the location where the return result will be placed.
0153     ///\param[in] args - a pointer to a argument list and argument size.
0154     ///\param[in] self - the 'this pointer' of the object.
0155     // FIXME: Adjust the arguments and their types: args_size can be unsigned;
0156     // self can go in the end and be nullptr by default; result can be a nullptr
0157     // by default. These changes should be synchronized with the wrapper if we
0158     // decide to directly.
0159     void Invoke(void* result, ArgList args = {}, void* self = nullptr) const {
0160       // Forward if we intended to call a dtor with only 1 parameter.
0161       if (m_Kind == kDestructorCall && result && !args.m_Args)
0162         return InvokeDestructor(result, /*nary=*/0UL, /*withFree=*/true);
0163 
0164 #ifndef NDEBUG
0165       assert(AreArgumentsValid(result, args, self) && "Invalid args!");
0166       ReportInvokeStart(result, args, self);
0167 #endif // NDEBUG
0168       m_GenericCall(self, args.m_ArgSize, args.m_Args, result);
0169     }
0170     /// Makes a call to a destructor.
0171     ///\param[in] object - the pointer of the object whose destructor we call.
0172     ///\param[in] nary - the count of the objects we destruct if we deal with an
0173     ///           array of objects.
0174     ///\param[in] withFree - true if we should call operator delete or false if
0175     ///           we should call only the destructor.
0176     //FIXME: Change the type of withFree from int to bool in the wrapper code.
0177     void InvokeDestructor(void* object, unsigned long nary = 0,
0178                           int withFree = true) const {
0179       assert(m_Kind == kDestructorCall && "Wrong overload!");
0180 #ifndef NDEBUG
0181       ReportInvokeStart(object, nary, withFree);
0182 #endif // NDEBUG
0183       m_DestructorCall(object, nary, withFree);
0184     }
0185   };
0186 
0187   ///\returns the version string information of the library.
0188   CPPINTEROP_API std::string GetVersion();
0189 
0190   ///\returns the demangled representation of the given mangled_name
0191   CPPINTEROP_API std::string Demangle(const std::string& mangled_name);
0192 
0193   /// Enables or disables the debugging printouts on stderr.
0194   /// Debugging output can be enabled also by the environment variable
0195   /// CPPINTEROP_EXTRA_INTERPRETER_ARGS. For example,
0196   /// CPPINTEROP_EXTRA_INTERPRETER_ARGS="-mllvm -debug-only=jitcall" to produce
0197   /// only debug output for jitcall events.
0198   CPPINTEROP_API void EnableDebugOutput(bool value = true);
0199 
0200   ///\returns true if the debugging printouts on stderr are enabled.
0201   CPPINTEROP_API bool IsDebugOutputEnabled();
0202 
0203   /// Checks if the given class represents an aggregate type).
0204   ///\returns true if \c scope is an array or a C++ tag (as per C++
0205   ///[dcl.init.aggr]) \returns true if the scope supports aggregate
0206   /// initialization.
0207   CPPINTEROP_API bool IsAggregate(TCppScope_t scope);
0208 
0209   /// Checks if the scope is a namespace or not.
0210   CPPINTEROP_API bool IsNamespace(TCppScope_t scope);
0211 
0212   /// Checks if the scope is a class or not.
0213   CPPINTEROP_API bool IsClass(TCppScope_t scope);
0214 
0215   /// Checks if the scope is a function.
0216   CPPINTEROP_API bool IsFunction(TCppScope_t scope);
0217 
0218   /// Checks if the type is a function pointer.
0219   CPPINTEROP_API bool IsFunctionPointerType(TCppType_t type);
0220 
0221   /// Checks if the klass polymorphic.
0222   /// which means that the class contains or inherits a virtual function
0223   CPPINTEROP_API bool IsClassPolymorphic(TCppScope_t klass);
0224 
0225   // See TClingClassInfo::IsLoaded
0226   /// Checks if the class definition is present, or not. Performs a
0227   /// template instantiation if necessary.
0228   CPPINTEROP_API bool IsComplete(TCppScope_t scope);
0229 
0230   CPPINTEROP_API size_t SizeOf(TCppScope_t scope);
0231 
0232   /// Checks if it is a "built-in" or a "complex" type.
0233   CPPINTEROP_API bool IsBuiltin(TCppType_t type);
0234 
0235   /// Checks if it is a templated class.
0236   CPPINTEROP_API bool IsTemplate(TCppScope_t handle);
0237 
0238   /// Checks if it is a class template specialization class.
0239   CPPINTEROP_API bool IsTemplateSpecialization(TCppScope_t handle);
0240 
0241   /// Checks if \c handle introduces a typedef name via \c typedef or \c using.
0242   CPPINTEROP_API bool IsTypedefed(TCppScope_t handle);
0243 
0244   CPPINTEROP_API bool IsAbstract(TCppType_t klass);
0245 
0246   /// Checks if it is an enum name (EnumDecl represents an enum name).
0247   CPPINTEROP_API bool IsEnumScope(TCppScope_t handle);
0248 
0249   /// Checks if it is an enum's value (EnumConstantDecl represents
0250   /// each enum constant that is defined).
0251   CPPINTEROP_API bool IsEnumConstant(TCppScope_t handle);
0252 
0253   /// Checks if the passed value is an enum type or not.
0254   CPPINTEROP_API bool IsEnumType(TCppType_t type);
0255 
0256   /// Extracts enum declarations from a specified scope and stores them in
0257   /// vector
0258   CPPINTEROP_API void GetEnums(TCppScope_t scope,
0259                                std::vector<std::string>& Result);
0260 
0261   /// We assume that smart pointer types define both operator* and
0262   /// operator->.
0263   CPPINTEROP_API bool IsSmartPtrType(TCppType_t type);
0264 
0265   /// For the given "class", get the integer type that the enum
0266   /// represents, so that you can store it properly in your specific
0267   /// language.
0268   CPPINTEROP_API TCppType_t GetIntegerTypeFromEnumScope(TCppScope_t handle);
0269 
0270   /// For the given "type", this function gets the integer type that the enum
0271   /// represents, so that you can store it properly in your specific
0272   /// language.
0273   CPPINTEROP_API TCppType_t GetIntegerTypeFromEnumType(TCppType_t handle);
0274 
0275   /// Gets a list of all the enum constants for an enum.
0276   CPPINTEROP_API std::vector<TCppScope_t> GetEnumConstants(TCppScope_t scope);
0277 
0278   /// Gets the enum name when an enum constant is passed.
0279   CPPINTEROP_API TCppType_t GetEnumConstantType(TCppScope_t scope);
0280 
0281   /// Gets the index value (0,1,2, etcetera) of the enum constant
0282   /// that was passed into this function.
0283   CPPINTEROP_API TCppIndex_t GetEnumConstantValue(TCppScope_t scope);
0284 
0285   /// Gets the size of the "type" that is passed in to this function.
0286   CPPINTEROP_API size_t GetSizeOfType(TCppType_t type);
0287 
0288   /// Checks if the passed value is a variable.
0289   CPPINTEROP_API bool IsVariable(TCppScope_t scope);
0290 
0291   /// Gets the name of any named decl (a class,
0292   /// namespace, variable, or a function).
0293   CPPINTEROP_API std::string GetName(TCppScope_t klass);
0294 
0295   /// This is similar to GetName() function, but besides
0296   /// the name, it also gets the template arguments.
0297   CPPINTEROP_API std::string GetCompleteName(TCppScope_t klass);
0298 
0299   /// Gets the "qualified" name (including the namespace) of any
0300   /// named decl (a class, namespace, variable, or a function).
0301   CPPINTEROP_API std::string GetQualifiedName(TCppScope_t klass);
0302 
0303   /// This is similar to GetQualifiedName() function, but besides
0304   /// the "qualified" name (including the namespace), it also
0305   /// gets the template arguments.
0306   CPPINTEROP_API std::string GetQualifiedCompleteName(TCppScope_t klass);
0307 
0308   /// Gets the list of namespaces utilized in the supplied scope.
0309   CPPINTEROP_API std::vector<TCppScope_t> GetUsingNamespaces(TCppScope_t scope);
0310 
0311   /// Gets the global scope of the whole C++  instance.
0312   CPPINTEROP_API TCppScope_t GetGlobalScope();
0313 
0314   /// Strips the typedef and returns the underlying class, and if the
0315   /// underlying decl is not a class it returns the input unchanged.
0316   CPPINTEROP_API TCppScope_t GetUnderlyingScope(TCppScope_t scope);
0317 
0318   /// Gets the namespace or class (by stripping typedefs) for the name
0319   /// passed as a parameter, and if the parent is not passed,
0320   /// then global scope will be assumed.
0321   CPPINTEROP_API TCppScope_t GetScope(const std::string& name,
0322                                       TCppScope_t parent = nullptr);
0323 
0324   /// When the namespace is known, then the parent doesn't need
0325   /// to be specified. This will probably be phased-out in
0326   /// future versions of the interop library.
0327   CPPINTEROP_API TCppScope_t GetScopeFromCompleteName(const std::string& name);
0328 
0329   /// This function performs a lookup within the specified parent,
0330   /// a specific named entity (functions, enums, etcetera).
0331   CPPINTEROP_API TCppScope_t GetNamed(const std::string& name,
0332                                       TCppScope_t parent = nullptr);
0333 
0334   /// Gets the parent of the scope that is passed as a parameter.
0335   CPPINTEROP_API TCppScope_t GetParentScope(TCppScope_t scope);
0336 
0337   /// Gets the scope of the type that is passed as a parameter.
0338   CPPINTEROP_API TCppScope_t GetScopeFromType(TCppType_t type);
0339 
0340   /// Gets the number of Base Classes for the Derived Class that
0341   /// is passed as a parameter.
0342   CPPINTEROP_API TCppIndex_t GetNumBases(TCppScope_t klass);
0343 
0344   /// Gets a specific Base Class using its index. Typically GetNumBases()
0345   /// is used to get the number of Base Classes, and then that number
0346   /// can be used to iterate through the index value to get each specific
0347   /// base class.
0348   CPPINTEROP_API TCppScope_t GetBaseClass(TCppScope_t klass, TCppIndex_t ibase);
0349 
0350   /// Checks if the supplied Derived Class is a sub-class of the
0351   /// provided Base Class.
0352   CPPINTEROP_API bool IsSubclass(TCppScope_t derived, TCppScope_t base);
0353 
0354   /// Each base has its own offset in a Derived Class. This offset can be
0355   /// used to get to the Base Class fields.
0356   CPPINTEROP_API int64_t GetBaseClassOffset(TCppScope_t derived,
0357                                             TCppScope_t base);
0358 
0359   /// Sets a list of all the Methods that are in the Class that is
0360   /// supplied as a parameter.
0361   ///\param[in] klass - Pointer to the scope/class under which the methods have
0362   ///           to be retrieved
0363   ///\param[out] methods - Vector of methods in the class
0364   CPPINTEROP_API void GetClassMethods(TCppScope_t klass,
0365                                       std::vector<TCppFunction_t>& methods);
0366 
0367   /// Template function pointer list to add proxies for un-instantiated/
0368   /// non-overloaded templated methods
0369   ///\param[in] klass - Pointer to the scope/class under which the methods have
0370   ///           to be retrieved
0371   ///\param[out] methods - Vector of methods in the class
0372   CPPINTEROP_API void
0373   GetFunctionTemplatedDecls(TCppScope_t klass,
0374                             std::vector<TCppFunction_t>& methods);
0375 
0376   ///\returns if a class has a default constructor.
0377   CPPINTEROP_API bool HasDefaultConstructor(TCppScope_t scope);
0378 
0379   ///\returns the default constructor of a class, if any.
0380   CPPINTEROP_API TCppFunction_t GetDefaultConstructor(TCppScope_t scope);
0381 
0382   ///\returns the class destructor, if any.
0383   CPPINTEROP_API TCppFunction_t GetDestructor(TCppScope_t scope);
0384 
0385   /// Looks up all the functions that have the name that is
0386   /// passed as a parameter in this function.
0387   CPPINTEROP_API std::vector<TCppFunction_t>
0388   GetFunctionsUsingName(TCppScope_t scope, const std::string& name);
0389 
0390   /// Gets the return type of the provided function.
0391   CPPINTEROP_API TCppType_t GetFunctionReturnType(TCppFunction_t func);
0392 
0393   /// Gets the number of Arguments for the provided function.
0394   CPPINTEROP_API TCppIndex_t GetFunctionNumArgs(TCppFunction_t func);
0395 
0396   /// Gets the number of Required Arguments for the provided function.
0397   CPPINTEROP_API TCppIndex_t GetFunctionRequiredArgs(TCppConstFunction_t func);
0398 
0399   /// For each Argument of a function, you can get the Argument Type
0400   /// by providing the Argument Index, based on the number of arguments
0401   /// from the GetFunctionNumArgs() function.
0402   CPPINTEROP_API TCppType_t GetFunctionArgType(TCppFunction_t func,
0403                                                TCppIndex_t iarg);
0404 
0405   ///\returns a stringified version of a given function signature in the form:
0406   /// void N::f(int i, double d, long l = 0, char ch = 'a').
0407   CPPINTEROP_API std::string GetFunctionSignature(TCppFunction_t func);
0408 
0409   ///\returns if a function was marked as \c =delete.
0410   CPPINTEROP_API bool IsFunctionDeleted(TCppConstFunction_t function);
0411 
0412   CPPINTEROP_API bool IsTemplatedFunction(TCppFunction_t func);
0413 
0414   /// This function performs a lookup to check if there is a
0415   /// templated function of that type.
0416   CPPINTEROP_API bool ExistsFunctionTemplate(const std::string& name,
0417                                              TCppScope_t parent = nullptr);
0418 
0419   /// Sets a list of all the constructor for a scope/class that is
0420   /// supplied as a parameter.
0421   ///\param[in] name - This string is used as a constraint, that clients can use
0422   ///           to ensure the constructors match the name that they provide
0423   ///\param[in] parent - Pointer to the scope/class for which the constructors
0424   ///           are being looked up
0425   ///           to be retrieved
0426   ///\param[out] funcs - vector of handles to all constructors found under the
0427   ///            given scope
0428   CPPINTEROP_API void LookupConstructors(const std::string& name,
0429                                          TCppScope_t parent,
0430                                          std::vector<TCppFunction_t>& funcs);
0431 
0432   /// Sets a list of all the Templated Methods that are in the Class that is
0433   /// supplied as a parameter.
0434   ///\returns true if the lookup succeeded, and false if there are no candidates
0435   ///\param[in] name - method name
0436   ///\param[in] parent - Pointer to the scope/class under which the methods have
0437   ///           to be retrieved
0438   ///\param[out] funcs - vector of function pointers matching the name
0439   CPPINTEROP_API bool
0440   GetClassTemplatedMethods(const std::string& name, TCppScope_t parent,
0441                            std::vector<TCppFunction_t>& funcs);
0442 
0443   /// Checks if the provided parameter is a method.
0444   CPPINTEROP_API bool IsMethod(TCppConstFunction_t method);
0445 
0446   /// Checks if the provided parameter is a 'Public' method.
0447   CPPINTEROP_API bool IsPublicMethod(TCppFunction_t method);
0448 
0449   /// Checks if the provided parameter is a 'Protected' method.
0450   CPPINTEROP_API bool IsProtectedMethod(TCppFunction_t method);
0451 
0452   /// Checks if the provided parameter is a 'Private' method.
0453   CPPINTEROP_API bool IsPrivateMethod(TCppFunction_t method);
0454 
0455   /// Checks if the provided parameter is a Constructor.
0456   CPPINTEROP_API bool IsConstructor(TCppConstFunction_t method);
0457 
0458   /// Checks if the provided parameter is a Destructor.
0459   CPPINTEROP_API bool IsDestructor(TCppConstFunction_t method);
0460 
0461   /// Checks if the provided parameter is a 'Static' method.
0462   CPPINTEROP_API bool IsStaticMethod(TCppConstFunction_t method);
0463 
0464   ///\returns the address of the function given its potentially mangled name.
0465   CPPINTEROP_API TCppFuncAddr_t GetFunctionAddress(const char* mangled_name);
0466 
0467   ///\returns the address of the function given its function declaration.
0468   CPPINTEROP_API TCppFuncAddr_t GetFunctionAddress(TCppFunction_t method);
0469 
0470   /// Checks if the provided parameter is a 'Virtual' method.
0471   CPPINTEROP_API bool IsVirtualMethod(TCppFunction_t method);
0472 
0473   /// Gets all the Fields/Data Members of a Class
0474   CPPINTEROP_API void GetDatamembers(TCppScope_t scope,
0475                                      std::vector<TCppScope_t>& datamembers);
0476 
0477   /// Gets all the Static Fields/Data Members of a Class
0478   ///\param[in] scope - class
0479   ///\param[out] funcs - vector of static data members
0480   CPPINTEROP_API void
0481   GetStaticDatamembers(TCppScope_t scope,
0482                        std::vector<TCppScope_t>& datamembers);
0483 
0484   /// Gets all the Enum Constants declared in a Class
0485   ///\param[in] scope - class
0486   ///\param[out] funcs - vector of static data members
0487   ///\param[in] include_enum_class - include enum constants from enum class
0488   CPPINTEROP_API
0489   void GetEnumConstantDatamembers(TCppScope_t scope,
0490                                   std::vector<TCppScope_t>& datamembers,
0491                                   bool include_enum_class = true);
0492 
0493   /// This is a Lookup function to be used specifically for data members.
0494   CPPINTEROP_API TCppScope_t LookupDatamember(const std::string& name,
0495                                               TCppScope_t parent);
0496 
0497   /// Gets the type of the variable that is passed as a parameter.
0498   CPPINTEROP_API TCppType_t GetVariableType(TCppScope_t var);
0499 
0500   /// Gets the address of the variable, you can use it to get the
0501   /// value stored in the variable.
0502   CPPINTEROP_API intptr_t GetVariableOffset(TCppScope_t var,
0503                                             TCppScope_t parent = nullptr);
0504 
0505   /// Checks if the provided variable is a 'Public' variable.
0506   CPPINTEROP_API bool IsPublicVariable(TCppScope_t var);
0507 
0508   /// Checks if the provided variable is a 'Protected' variable.
0509   CPPINTEROP_API bool IsProtectedVariable(TCppScope_t var);
0510 
0511   /// Checks if the provided variable is a 'Private' variable.
0512   CPPINTEROP_API bool IsPrivateVariable(TCppScope_t var);
0513 
0514   /// Checks if the provided variable is a 'Static' variable.
0515   CPPINTEROP_API bool IsStaticVariable(TCppScope_t var);
0516 
0517   /// Checks if the provided variable is a 'Constant' variable.
0518   CPPINTEROP_API bool IsConstVariable(TCppScope_t var);
0519 
0520   /// Checks if the provided parameter is a Record (struct).
0521   CPPINTEROP_API bool IsRecordType(TCppType_t type);
0522 
0523   /// Checks if the provided parameter is a Plain Old Data Type (POD).
0524   CPPINTEROP_API bool IsPODType(TCppType_t type);
0525 
0526   /// Checks if type is a pointer
0527   CPPINTEROP_API bool IsPointerType(TCppType_t type);
0528 
0529   /// Get the underlying pointee type
0530   CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
0531 
0532   /// Checks if type is a reference
0533   CPPINTEROP_API bool IsReferenceType(TCppType_t type);
0534 
0535   /// Get the type that the reference refers to
0536   CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type);
0537 
0538   /// Gets the pure, Underlying Type (as opposed to the Using Type).
0539   CPPINTEROP_API TCppType_t GetUnderlyingType(TCppType_t type);
0540 
0541   /// Gets the Type (passed as a parameter) as a String value.
0542   CPPINTEROP_API std::string GetTypeAsString(TCppType_t type);
0543 
0544   /// Gets the Canonical Type string from the std string. A canonical type
0545   /// is the type with any typedef names, syntactic sugars or modifiers stripped
0546   /// out of it.
0547   CPPINTEROP_API TCppType_t GetCanonicalType(TCppType_t type);
0548 
0549   /// Used to either get the built-in type of the provided string, or
0550   /// use the name to lookup the actual type.
0551   CPPINTEROP_API TCppType_t GetType(const std::string& type);
0552 
0553   ///\returns the complex of the provided type.
0554   CPPINTEROP_API TCppType_t GetComplexType(TCppType_t element_type);
0555 
0556   /// This will convert a class into its type, so for example, you can
0557   /// use it to declare variables in it.
0558   CPPINTEROP_API TCppType_t GetTypeFromScope(TCppScope_t klass);
0559 
0560   /// Checks if a C++ type derives from another.
0561   CPPINTEROP_API bool IsTypeDerivedFrom(TCppType_t derived, TCppType_t base);
0562 
0563   /// Creates a trampoline function by using the interpreter and returns a
0564   /// uniform interface to call it from compiled code.
0565   CPPINTEROP_API JitCall MakeFunctionCallable(TCppConstFunction_t func);
0566 
0567   CPPINTEROP_API JitCall MakeFunctionCallable(TInterp_t I,
0568                                               TCppConstFunction_t func);
0569 
0570   /// Checks if a function declared is of const type or not.
0571   CPPINTEROP_API bool IsConstMethod(TCppFunction_t method);
0572 
0573   ///\returns the default argument value as string.
0574   CPPINTEROP_API std::string GetFunctionArgDefault(TCppFunction_t func,
0575                                                    TCppIndex_t param_index);
0576 
0577   ///\returns the argument name of function as string.
0578   CPPINTEROP_API std::string GetFunctionArgName(TCppFunction_t func,
0579                                                 TCppIndex_t param_index);
0580 
0581   ///\returns arity of the operator or kNone
0582   CPPINTEROP_API OperatorArity GetOperatorArity(TCppFunction_t op);
0583 
0584   ///\returns list of operator overloads
0585   CPPINTEROP_API void GetOperator(TCppScope_t scope, Operator op,
0586                                   std::vector<TCppFunction_t>& operators,
0587                                   OperatorArity kind = kBoth);
0588 
0589   /// Creates an instance of the interpreter we need for the various interop
0590   /// services.
0591   ///\param[in] Args - the list of arguments for interpreter constructor.
0592   ///\param[in] CPPINTEROP_EXTRA_INTERPRETER_ARGS - an env variable, if defined,
0593   ///           adds additional arguments to the interpreter.
0594   CPPINTEROP_API TInterp_t
0595   CreateInterpreter(const std::vector<const char*>& Args = {},
0596                     const std::vector<const char*>& GpuArgs = {});
0597 
0598   /// Checks which Interpreter backend was CppInterOp library built with (Cling,
0599   /// Clang-REPL, etcetera). In practice, the selected interpreter should not
0600   /// matter, since the library will function in the same way.
0601   ///\returns the current interpreter instance, if any.
0602   CPPINTEROP_API TInterp_t GetInterpreter();
0603 
0604   /// Sets the Interpreter instance with an external interpreter, meant to
0605   /// be called by an external library that manages it's own interpreter.
0606   /// Sets a flag signifying CppInterOp does not have ownership of the
0607   /// sInterpreter.
0608   ///\param[in] Args - the pointer to an external interpreter
0609   CPPINTEROP_API void UseExternalInterpreter(TInterp_t I);
0610 
0611   /// Adds a Search Path for the Interpreter to get the libraries.
0612   CPPINTEROP_API void AddSearchPath(const char* dir, bool isUser = true,
0613                                     bool prepend = false);
0614 
0615   /// Returns the resource-dir path (for headers).
0616   CPPINTEROP_API const char* GetResourceDir();
0617 
0618   /// Uses the underlying clang compiler to detect the resource directory.
0619   /// In essence calling clang -print-resource-dir and checks if it ends with
0620   /// a compatible to CppInterOp version.
0621   ///\param[in] ClangBinaryName - the name (or the full path) of the compiler
0622   ///                             to ask.
0623   CPPINTEROP_API std::string
0624   DetectResourceDir(const char* ClangBinaryName = "clang");
0625 
0626   /// Asks the system compiler for its default include paths.
0627   ///\param[out] Paths - the list of include paths returned by eg.
0628   ///                     `c++ -xc++ -E -v /dev/null 2>&1`
0629   ///\param[in] CompilerName - the name (or the full path) of the compiler
0630   ///                          binary file.
0631   CPPINTEROP_API void
0632   DetectSystemCompilerIncludePaths(std::vector<std::string>& Paths,
0633                                    const char* CompilerName = "c++");
0634 
0635   /// Secondary search path for headers, if not found using the
0636   /// GetResourceDir() function.
0637   CPPINTEROP_API void AddIncludePath(const char* dir);
0638 
0639   // Gets the currently used include paths
0640   ///\param[out] IncludePaths - the list of include paths
0641   ///
0642   CPPINTEROP_API void GetIncludePaths(std::vector<std::string>& IncludePaths,
0643                                       bool withSystem = false,
0644                                       bool withFlags = false);
0645 
0646   /// Only Declares a code snippet in \c code and does not execute it.
0647   ///\returns 0 on success
0648   CPPINTEROP_API int Declare(const char* code, bool silent = false);
0649 
0650   /// Declares and executes a code snippet in \c code.
0651   ///\returns 0 on success
0652   CPPINTEROP_API int Process(const char* code);
0653 
0654   /// Declares, executes and returns the execution result as a intptr_t.
0655   ///\returns the expression results as a intptr_t.
0656   CPPINTEROP_API intptr_t Evaluate(const char* code, bool* HadError = nullptr);
0657 
0658   /// Looks up the library if access is enabled.
0659   ///\returns the path to the library.
0660   CPPINTEROP_API std::string LookupLibrary(const char* lib_name);
0661 
0662   /// Finds \c lib_stem considering the list of search paths and loads it by
0663   /// calling dlopen.
0664   /// \returns true on success.
0665   CPPINTEROP_API bool LoadLibrary(const char* lib_stem, bool lookup = true);
0666 
0667   /// Finds \c lib_stem considering the list of search paths and unloads it by
0668   /// calling dlclose.
0669   /// function.
0670   CPPINTEROP_API void UnloadLibrary(const char* lib_stem);
0671 
0672   /// Scans all libraries on the library search path for a given potentially
0673   /// mangled symbol name.
0674   ///\returns the path to the first library that contains the symbol definition.
0675   CPPINTEROP_API std::string
0676   SearchLibrariesForSymbol(const char* mangled_name,
0677                            bool search_system /*true*/);
0678 
0679   /// Inserts or replaces a symbol in the JIT with the one provided. This is
0680   /// useful for providing our own implementations of facilities such as printf.
0681   ///
0682   ///\param[in] linker_mangled_name - the name of the symbol to be inserted or
0683   ///           replaced.
0684   ///\param[in] address - the new address of the symbol.
0685   ///
0686   ///\returns true on failure.
0687   CPPINTEROP_API bool InsertOrReplaceJitSymbol(const char* linker_mangled_name,
0688                                                uint64_t address);
0689 
0690   /// Tries to load provided objects in a string format (prettyprint).
0691   CPPINTEROP_API std::string ObjToString(const char* type, void* obj);
0692 
0693   struct TemplateArgInfo {
0694     TCppType_t m_Type;
0695     const char* m_IntegralValue;
0696     TemplateArgInfo(TCppScope_t type, const char* integral_value = nullptr)
0697       : m_Type(type), m_IntegralValue(integral_value) {}
0698   };
0699   /// Builds a template instantiation for a given templated declaration.
0700   /// Offers a single interface for instantiation of class, function and
0701   /// variable templates
0702   ///
0703   ///\param[in] tmpl - Uninstantiated template class/function
0704   ///\param[in] template_args - Pointer to vector of template arguments stored
0705   ///           in the \c TemplateArgInfo struct
0706   ///\param[in] template_args_size - Size of the vector of template arguments
0707   ///           passed as \c template_args
0708   ///
0709   ///\returns Instantiated templated class/function/variable pointer
0710   CPPINTEROP_API TCppScope_t
0711   InstantiateTemplate(TCppScope_t tmpl, const TemplateArgInfo* template_args,
0712                       size_t template_args_size);
0713 
0714   /// Sets the class template instantiation arguments of \c templ_instance.
0715   ///
0716   ///\param[in] templ_instance - Pointer to the template instance
0717   ///\param[out] args - Vector of instantiation arguments
0718   CPPINTEROP_API void
0719   GetClassTemplateInstantiationArgs(TCppScope_t templ_instance,
0720                                     std::vector<TemplateArgInfo>& args);
0721 
0722   /// Instantiates a function template from a given string representation. This
0723   /// function also does overload resolution.
0724   ///\returns the instantiated function template declaration.
0725   CPPINTEROP_API TCppFunction_t
0726   InstantiateTemplateFunctionFromString(const char* function_template);
0727 
0728   /// Finds best overload match based on explicit template parameters (if any)
0729   /// and argument types.
0730   ///
0731   ///\param[in] candidates - vector of overloads that come under the
0732   ///           parent scope and have the same name
0733   ///\param[in] explicit_types - set of expicitly instantiated template types
0734   ///\param[in] arg_types - set of argument types
0735   ///\returns Instantiated function pointer
0736   CPPINTEROP_API TCppFunction_t
0737   BestOverloadFunctionMatch(const std::vector<TCppFunction_t>& candidates,
0738                             const std::vector<TemplateArgInfo>& explicit_types,
0739                             const std::vector<TemplateArgInfo>& arg_types);
0740 
0741   CPPINTEROP_API void GetAllCppNames(TCppScope_t scope,
0742                                      std::set<std::string>& names);
0743 
0744   CPPINTEROP_API void DumpScope(TCppScope_t scope);
0745 
0746   namespace DimensionValue {
0747     enum : long int {
0748       UNKNOWN_SIZE = -1,
0749     };
0750   }
0751 
0752   /// Gets the size/dimensions of a multi-dimension array.
0753   CPPINTEROP_API std::vector<long int> GetDimensions(TCppType_t type);
0754 
0755   /// Allocates memory for a given class.
0756   CPPINTEROP_API TCppObject_t Allocate(TCppScope_t scope);
0757 
0758   /// Deallocates memory for a given class.
0759   CPPINTEROP_API void Deallocate(TCppScope_t scope, TCppObject_t address);
0760 
0761   /// Creates an object of class \c scope and calls its default constructor. If
0762   /// \c arena is set it uses placement new.
0763   CPPINTEROP_API TCppObject_t Construct(TCppScope_t scope,
0764                                         void* arena = nullptr);
0765 
0766   /// Calls the destructor of object of type \c type. When withFree is true it
0767   /// calls operator delete/free.
0768   CPPINTEROP_API void Destruct(TCppObject_t This, TCppScope_t type,
0769                                bool withFree = true);
0770 
0771   /// @name Stream Redirection
0772   ///
0773   ///@{
0774 
0775   enum CaptureStreamKind : char {
0776     kStdOut = 1, ///< stdout
0777     kStdErr,     ///< stderr
0778     // kStdBoth,    ///< stdout and stderr
0779     // kSTDSTRM  // "&1" or "&2" is not a filename
0780   };
0781 
0782   /// Begins recording the given standard stream.
0783   ///\param[fd_kind] - The stream to be captured
0784   CPPINTEROP_API void BeginStdStreamCapture(CaptureStreamKind fd_kind);
0785 
0786   /// Ends recording the standard stream and returns the result as a string.
0787   CPPINTEROP_API std::string EndStdStreamCapture();
0788 
0789   ///@}
0790 
0791   /// Append all Code completion suggestions to Results.
0792   ///\param[out] Results - CC suggestions for code fragment. Suggestions are
0793   /// appended.
0794   ///\param[in] code - code fragmet to complete
0795   ///\param[in] complete_line - position (line) in code for suggestion
0796   ///\param[in] complete_column - position (column) in code for suggestion
0797   CPPINTEROP_API void CodeComplete(std::vector<std::string>& Results,
0798                                    const char* code,
0799                                    unsigned complete_line = 1U,
0800                                    unsigned complete_column = 1U);
0801 
0802   /// Reverts the last N operations performed by the interpreter.
0803   ///\param[in] N The number of operations to undo. Defaults to 1.
0804   ///\returns 0 on success, non-zero on failure.
0805   CPPINTEROP_API int Undo(unsigned N = 1);
0806 
0807 } // end namespace Cpp
0808 
0809 #endif // CPPINTEROP_CPPINTEROP_H