📄 ucri.h
字号:
/// The underlying Function object
void* fun();
/// Evaluate this function.
/// \param args Pointer to an array of arguments
/// \param result Pointer to the result
/// \param obj Optional object pointer, if this is a method
/// \return OK if fine
int eval(void *args, void *result, void *obj=NULL);
/// Attach a trace object to the function
/// \param tr A trace object
/// \sa XTrace
void set_trace(XTrace* tr);
/// Get the current trace object, if any.
/// \return The trace object
XTrace* get_trace();
/// Get the function's pcode.
/// This is the underlying bytecode compiled by UnderC; accessing
/// it is useful if you are looking for specific references.
/// \return A pointer to the pcode
XInstruction* pcode();
/// Globally set whether we are tracing functions or not.
static void set_tracing(bool yesno);
/// Given a function block, find its function
static XFunction* from_fb(void* fb);
/// Look up a variable name in the function's context
/// \param Name of Variable (usually a formal parameter)
/// \return The corresponding entry
/// \sa XEntry
XEntry* lookup_local(char* name);
};
typedef listx<XFunction *> XFunctions;
typedef listx<XEntry *> XEntries;
/// XNTable wraps NamedTable, and is the base class for
/// XClass; You can look up symbols, or get a list of
/// all available symbols.
/// do note that get_functions() etc can be given optional
/// mask patterns (Not general regular expressions - just simple wildcards
/// either like '*_init' or like 'get_*')
class EXPORT XNTable {
protected:
NamedTable *m_table;
public:
XNTable(NamedTable *tbl);
/// Look up a name in this context
/// \param name Symbol name
/// \param in_parent True if you want to keep looking in the parent context
/// \return The symbol table entry, or NULL if not found.
/// \sa XEntry
virtual XEntry* lookup(char *name,bool in_parent=false);
/// Look up a class in this context
/// \return A pointer to the class object, NULL if not found or not a class
/// \sa XClass
XClass* lookup_class(char *name, bool in_parent=false);
/// Look up a template in this context
XTemplateFun* lookup_template(char *name, bool in_p=false);
/// The underlying NamedTable object
NamedTable* table();
/// Name of this symbol table
char* name();
/// The offset of a given pointer in this context's data space
int offset(void* p);
/// Create a new entry in this table
/// \param nm Name of new symbol
/// \param xt Type of entry
/// \sa XEntry
XEntry *create(char *nm = "", XType *xt = NULL);
/// A list of all functions in this context
/// \param flags Can control whether you want non-static, etc.
/// \return a function list
XFunctions& functions(int flags=0);
/// a list of all variables in this context
XEntries& variables(int flags=FIELDS);
/// \c get_functions() is the prefered way to get a list of functions in this context. \a flags can be:
/// \li \c NON_STATIC non-static member functions
/// \li \c VIRTUALS virtual member functions
/// \li \c BUILTINS UnderC builtin functions
/// \li \c CTORS Class constructors
/// \li \c DTORS Class destructors
/// \li \c IMPORTS Functions imported from a DLL
/// \li \c UNDEFINED Functions which have been declared but not defined yet.
///
/// You can combine this with \c DO_PARENT to extract entries from the parent
/// context, and so on.
///
/// \param fns A list to receive the functions
/// \param flags Controls type of functions required
/// \param pattern Can specify a wildcard
void get_functions(XFunctions& fns, int flags = 0,char *pattern=NULL);
/// \c get_variables() is the prefered way to get a list of variables.
/// It can be used to fetch \em any kind of entry,
/// depending on the flags used. For types, use these flag values:
/// \li \c TYPEDEFS any typedefs
/// \li \c NAMESPACES any namespaces
/// \li \c CLASSES any classes
///
/// For variables, you can combine FIELDS with one of the following flags:
/// \li \c TEMPS temporary variables
/// \li \c CONSTS constants (\em not macros)
/// \li \c NON_STATIC non-static members of a struct
///
/// Again, \a flags can contain DO_PARENT as before.
void get_variables(XEntries& vars, int flags=FIELDS,char *pattern=NULL);
static void dispose_of_entries(XEntries& vars);
};
class XTemplateFun ;
class EXPORT XClass: public XNTable {
public:
XClass(NamedTable *tbl);
/// underlying Class object.
Class* class_obj();
/// base class of this class.
/// \return Base class if defined; NULL otherwise
XClass* base_class();
/// Create an object of this type.
/// It is assumed that this class has a suitable default constructor.
void* create();
/// Does this class inherit from a given class?
/// \param xc Another class
/// \return A measure of inheritance depth; zero if not related.
int inherits_from(XClass *xc);
/// If we are a template class, the number of template parameters
/// \return Zero for ordinary classes
int no_template_parms();
/// The type parameters of a template class
/// \return A list of types; NULL if not a template
XType* template_parm(int idx);
XTemplateFun* get_template();
// *add 1.2.4 Accessing RTTI; setting and getting the class of an object
/// Has this class got a VMT (Virtual Method Table)? .
bool has_VMT();
/// Given an object, what is its dynamic class?.
static XClass* get_class_of(void* p);
/// Set the class of an object dynamically.
void set_class_of(void* p);
};
class XModule;
typedef listx<XModule *> XModules;
typedef listx<XClass *> XClasses;
/// XModule wraps Module, which is the UC representation
/// of a loaded source file (of any extension). Note that
/// the name lookup is exact. You can also use the module
/// id from XFunction::module() for access. The lists()
/// function will give you all currently loaded modules.
class EXPORT XModule {
private:
Module* m_mod;
public:
XModule(Module *pm);
/// This translates a module index into a module object
/// \param id Index
/// \return XModule object; NULL if the index is out of range
static XModule* from_id(int id);
/// Likewise, except using a filename (must be exact match).
static XModule* from_name(char* filename);
/// All available modules.
static XModules& lists();
/// What is the filename of this module?
char* filename();
/// List of functions defined in this module.
XFunctions& functions();
/// List of classes defined in this module.
XClasses& classes();
};
/// XTemplateFun wraps TemplateEntry. You can use
/// XNTable::lookup_template() to get a ptr to your template,
/// and then dynamically instantiate it. match_instantiate()
/// is passed argument types (which is the usual way it's
/// done in C++) and instantiate() is passed formal type
/// parameters (which is more convenient)
class EXPORT XTemplateFun {
private:
TemplateEntry* m_templ;
public:
XTemplateFun(TemplateEntry *te);
/// Instantiate this template function, given argument types
/// \param tl Formal argument types
void* match_instantiate(const XTList& tl);
/// Instantiate this template function, given type parameters
/// \param tl Formal template type parameters
void* instantiate(const XTList& tl);
/// Name of this template
char* name();
};
// Access to the important namespaces.
// Please remember to call uc_ucri_init() to make
// sure these are available!
/// The global symbol table.
EXPORT XNTable* uc_global();
/// The std standard namespace.
EXPORT XNTable* uc_std();
/// To be called before accessing any UCRI function.
EXPORT void uc_ucri_init();
// *add 1.2.4 Profiling support
EXPORT unsigned long* ucri_instruction_counter(bool do_profiling);
/// Evaluate a UnderC function ptr, optionally with object pointer.
#ifdef __UNDERC__
CEXPORT XAPI int uc_eval_method(void *sc, void *obj, void *arguments, void *result);
#else
CEXPORT int XAPI uc_eval_method(void *sc, void *obj, void *arguments, void *result);
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -