eolian: return Eolian_Object_Type from ref resolver
This needs only one enum and allows for better interop.
This commit is contained in:
parent
edda05e4d0
commit
c7fd43ad4e
|
@ -276,19 +276,6 @@ ffi.cdef [[
|
|||
EOLIAN_DOC_TOKEN_MARKUP_MONOSPACE
|
||||
} Eolian_Doc_Token_Type;
|
||||
|
||||
typedef enum {
|
||||
EOLIAN_DOC_REF_INVALID = 0,
|
||||
EOLIAN_DOC_REF_CLASS,
|
||||
EOLIAN_DOC_REF_FUNC,
|
||||
EOLIAN_DOC_REF_EVENT,
|
||||
EOLIAN_DOC_REF_ALIAS,
|
||||
EOLIAN_DOC_REF_STRUCT,
|
||||
EOLIAN_DOC_REF_STRUCT_FIELD,
|
||||
EOLIAN_DOC_REF_ENUM,
|
||||
EOLIAN_DOC_REF_ENUM_FIELD,
|
||||
EOLIAN_DOC_REF_VAR
|
||||
} Eolian_Doc_Ref_Type;
|
||||
|
||||
typedef struct _Eolian_Doc_Token {
|
||||
Eolian_Doc_Token_Type type;
|
||||
const char *text, *text_end;
|
||||
|
@ -494,7 +481,7 @@ ffi.cdef [[
|
|||
void eolian_doc_token_init(Eolian_Doc_Token *tok);
|
||||
Eolian_Doc_Token_Type eolian_doc_token_type_get(const Eolian_Doc_Token *tok);
|
||||
char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
|
||||
Eolian_Doc_Ref_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
|
||||
Eolian_Object_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
|
||||
]]
|
||||
|
||||
local cutil = require("cutil")
|
||||
|
@ -1815,19 +1802,6 @@ M.doc_token_type = {
|
|||
MARKUP_MONOSPACE = 7
|
||||
}
|
||||
|
||||
M.doc_ref_type = {
|
||||
INVALID = 0,
|
||||
CLASS = 1,
|
||||
FUNC = 2,
|
||||
EVENT = 3,
|
||||
ALIAS = 4,
|
||||
STRUCT = 5,
|
||||
STRUCT_FIELD = 6,
|
||||
ENUM = 7,
|
||||
ENUM_FIELD = 8,
|
||||
VAR = 9
|
||||
}
|
||||
|
||||
M.documentation_string_split = function(str)
|
||||
if not str then
|
||||
return {}
|
||||
|
@ -1881,7 +1855,7 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", {
|
|||
ref_get = function(self, unit)
|
||||
local stor = ffi.new("const void *[2]")
|
||||
local tp = tonumber(eolian.eolian_doc_token_ref_get(unit, self, stor, stor + 1))
|
||||
local reft = M.doc_ref_type
|
||||
local reft = M.object_type
|
||||
if tp == reft.CLASS then
|
||||
return tp, ffi.cast("const Eolian_Class *", stor[0])
|
||||
elseif tp == reft.FUNC then
|
||||
|
@ -1905,7 +1879,7 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", {
|
|||
elseif tp == reft.VAR then
|
||||
return tp, ffi.cast("const Eolian_Variable *", stor[0])
|
||||
else
|
||||
return reft.INVALID
|
||||
return reft.UNKNOWN
|
||||
end
|
||||
end
|
||||
}
|
||||
|
|
|
@ -449,20 +449,6 @@ typedef enum
|
|||
EOLIAN_DOC_TOKEN_MARKUP_MONOSPACE
|
||||
} Eolian_Doc_Token_Type;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EOLIAN_DOC_REF_INVALID = 0,
|
||||
EOLIAN_DOC_REF_CLASS,
|
||||
EOLIAN_DOC_REF_FUNC,
|
||||
EOLIAN_DOC_REF_EVENT,
|
||||
EOLIAN_DOC_REF_ALIAS,
|
||||
EOLIAN_DOC_REF_STRUCT,
|
||||
EOLIAN_DOC_REF_STRUCT_FIELD,
|
||||
EOLIAN_DOC_REF_ENUM,
|
||||
EOLIAN_DOC_REF_ENUM_FIELD,
|
||||
EOLIAN_DOC_REF_VAR
|
||||
} Eolian_Doc_Ref_Type;
|
||||
|
||||
typedef struct _Eolian_Doc_Token
|
||||
{
|
||||
Eolian_Doc_Token_Type type;
|
||||
|
@ -2779,7 +2765,7 @@ EAPI char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
|
|||
/*
|
||||
* @brief Get the thing that a reference token references.
|
||||
*
|
||||
* Returns EOLIAN_DOC_REF_INVALID on failure (when not ref token or
|
||||
* Returns EOLIAN_OBJECT_UNKNOWN on failure (when not ref token or
|
||||
* invalid ref, but invalid refs don't happen when database is valid).
|
||||
*
|
||||
* When the reference is a class, alias, struct, enum or var, the first data arg
|
||||
|
@ -2794,7 +2780,7 @@ EAPI char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
|
|||
* @param[out] data2 the secondary data
|
||||
* @return the kind of reference this is
|
||||
*/
|
||||
EAPI Eolian_Doc_Ref_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
|
||||
EAPI Eolian_Object_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ _validate_docstr(const Eolian_Unit *src, Eina_Stringshare *str, const Eolian_Obj
|
|||
eolian_doc_token_init(&tok);
|
||||
while (ret && (doc = eolian_documentation_tokenize(doc, &tok)))
|
||||
if (eolian_doc_token_type_get(&tok) == EOLIAN_DOC_TOKEN_REF)
|
||||
if (eolian_doc_token_ref_get(src, &tok, NULL, NULL) == EOLIAN_DOC_REF_INVALID)
|
||||
if (eolian_doc_token_ref_get(src, &tok, NULL, NULL) == EOLIAN_OBJECT_UNKNOWN)
|
||||
{
|
||||
char *refn = eolian_doc_token_text_get(&tok);
|
||||
_eolian_log_line(info->file, info->line, info->column,
|
||||
|
|
|
@ -289,38 +289,38 @@ eolian_doc_token_text_get(const Eolian_Doc_Token *tok)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
static Eolian_Doc_Ref_Type
|
||||
static Eolian_Object_Type
|
||||
_resolve_event(const Eolian_Unit *src, char *name, const void **data,
|
||||
const void **data2)
|
||||
{
|
||||
/* never trust the user */
|
||||
if (name[0] == ',')
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
char *evname = strrchr(name, '.');
|
||||
if (!evname)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
*evname++ = '\0';
|
||||
const Eolian_Class *cl = eolian_unit_class_by_name_get(src, name);
|
||||
if (!cl)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
const Eolian_Event *ev = eolian_class_event_get_by_name(cl, evname);
|
||||
if (!ev)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
if (data) *data = cl;
|
||||
if (data2) *data2 = ev;
|
||||
return EOLIAN_DOC_REF_EVENT;
|
||||
return EOLIAN_OBJECT_EVENT;
|
||||
}
|
||||
|
||||
EAPI Eolian_Doc_Ref_Type
|
||||
EAPI Eolian_Object_Type
|
||||
eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
||||
const void **data, const void **data2)
|
||||
{
|
||||
if (tok->type != EOLIAN_DOC_TOKEN_REF)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
size_t nlen = tok->text_end - tok->text;
|
||||
|
||||
|
@ -343,27 +343,16 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
|||
if (decl)
|
||||
{
|
||||
if (data) *data = decl;
|
||||
switch (eolian_object_type_get(decl))
|
||||
Eolian_Object_Type tp = eolian_object_type_get(decl);
|
||||
switch (tp)
|
||||
{
|
||||
case EOLIAN_OBJECT_CLASS:
|
||||
return EOLIAN_DOC_REF_CLASS;
|
||||
case EOLIAN_OBJECT_TYPEDECL:
|
||||
switch (eolian_typedecl_type_get((Eolian_Typedecl *)decl))
|
||||
{
|
||||
case EOLIAN_TYPEDECL_ALIAS:
|
||||
return EOLIAN_DOC_REF_ALIAS;
|
||||
case EOLIAN_TYPEDECL_STRUCT:
|
||||
case EOLIAN_TYPEDECL_STRUCT_OPAQUE:
|
||||
return EOLIAN_DOC_REF_STRUCT;
|
||||
case EOLIAN_TYPEDECL_ENUM:
|
||||
return EOLIAN_DOC_REF_ENUM;
|
||||
default:
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
}
|
||||
case EOLIAN_OBJECT_VARIABLE:
|
||||
return EOLIAN_DOC_REF_VAR;
|
||||
/* we only allow certain types to be referenced */
|
||||
return tp;
|
||||
default:
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -372,7 +361,7 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
|||
char *suffix = strrchr(name, '.');
|
||||
/* no suffix, therefore invalid */
|
||||
if (!suffix)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
/* name will terminate before suffix, suffix will be standalone */
|
||||
*suffix++ = '\0';
|
||||
|
@ -384,10 +373,10 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
|||
const Eolian_Struct_Type_Field *fld = eolian_typedecl_struct_field_get(tpd, suffix);
|
||||
/* field itself is invalid */
|
||||
if (!fld)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
if (data) *data = tpd;
|
||||
if (data2) *data2 = fld;
|
||||
return EOLIAN_DOC_REF_STRUCT_FIELD;
|
||||
return EOLIAN_OBJECT_STRUCT_FIELD;
|
||||
}
|
||||
|
||||
/* try an enum field */
|
||||
|
@ -397,10 +386,10 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
|||
const Eolian_Enum_Type_Field *fld = eolian_typedecl_enum_field_get(tpd, suffix);
|
||||
/* field itself is invalid */
|
||||
if (!fld)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
if (data) *data = tpd;
|
||||
if (data2) *data2 = fld;
|
||||
return EOLIAN_DOC_REF_ENUM_FIELD;
|
||||
return EOLIAN_OBJECT_ENUM_FIELD;
|
||||
}
|
||||
|
||||
/* now it can only be a function or invalid */
|
||||
|
@ -416,23 +405,23 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
|||
suffix = strrchr(name, '.');
|
||||
/* wrong suffix, therefore invalid */
|
||||
if (!suffix)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
/* re-terminate */
|
||||
*suffix++ = '\0';
|
||||
}
|
||||
|
||||
const Eolian_Class *cl = eolian_unit_class_by_name_get(unit, name);
|
||||
if (!cl)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
const Eolian_Function *fid = eolian_class_function_get_by_name(cl, suffix, ftype);
|
||||
if (!fid)
|
||||
return EOLIAN_DOC_REF_INVALID;
|
||||
return EOLIAN_OBJECT_UNKNOWN;
|
||||
|
||||
/* got a func */
|
||||
if (data) *data = cl;
|
||||
if (data2) *data2 = fid;
|
||||
return EOLIAN_DOC_REF_FUNC;
|
||||
return EOLIAN_OBJECT_FUNCTION;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -234,18 +234,6 @@ class Eolian_Doc_Token_Type(IntEnum):
|
|||
MARK_TODO = 6
|
||||
MARKUP_MONOSPACE = 7
|
||||
|
||||
class Eolian_Doc_Ref_Type(IntEnum):
|
||||
INVALID = 0
|
||||
CLASS = 1
|
||||
FUNC = 2
|
||||
EVENT = 3
|
||||
ALIAS = 4
|
||||
STRUCT = 5
|
||||
STRUCT_FIELD = 6
|
||||
ENUM = 7
|
||||
ENUM_FIELD = 8
|
||||
VAR = 9
|
||||
|
||||
|
||||
### internal Classes ########################################################
|
||||
|
||||
|
|
|
@ -831,7 +831,7 @@ lib.eolian_doc_token_type_get.restype = c_int
|
|||
lib.eolian_doc_token_text_get.argtypes = [c_void_p,]
|
||||
lib.eolian_doc_token_text_get.restype = c_void_p # char* TO BE FREED
|
||||
|
||||
# EAPI Eolian_Doc_Ref_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
|
||||
# EAPI Eolian_Object_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
|
||||
# lib.eolian_doc_token_ref_get.argtypes = [c_void_p, c_void_p, ???, ???]
|
||||
# lib.eolian_doc_token_ref_get.restype = c_int
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ class Template(pyratemp.Template):
|
|||
'Documentation': eolian.Documentation,
|
||||
'Documentation_Token': eolian.Documentation_Token,
|
||||
# Eolian Enums
|
||||
'Eolian_Object_Type': eolian.Eolian_Object_Type,
|
||||
'Eolian_Function_Type': eolian.Eolian_Function_Type,
|
||||
'Eolian_Parameter_Dir': eolian.Eolian_Parameter_Dir,
|
||||
'Eolian_Class_Type': eolian.Eolian_Class_Type,
|
||||
|
@ -142,9 +143,7 @@ class Template(pyratemp.Template):
|
|||
'Eolian_Variable_Type': eolian.Eolian_Variable_Type,
|
||||
'Eolian_Binary_Operator': eolian.Eolian_Binary_Operator,
|
||||
'Eolian_Unary_Operator': eolian.Eolian_Unary_Operator,
|
||||
'Eolian_Declaration_Type': eolian.Eolian_Declaration_Type,
|
||||
'Eolian_Doc_Token_Type': eolian.Eolian_Doc_Token_Type,
|
||||
'Eolian_Doc_Ref_Type': eolian.Eolian_Doc_Ref_Type,
|
||||
})
|
||||
|
||||
# Call the parent __init__ func
|
||||
|
|
|
@ -1256,7 +1256,7 @@ START_TEST(eolian_docs)
|
|||
fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_REF);
|
||||
txt = eolian_doc_token_text_get(&tok);
|
||||
fail_if(strcmp(txt, "pants"));
|
||||
fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_DOC_REF_VAR);
|
||||
fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_OBJECT_VARIABLE);
|
||||
free(txt);
|
||||
tdoc = eolian_documentation_tokenize(tdoc, &tok);
|
||||
fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_TEXT);
|
||||
|
@ -1267,7 +1267,7 @@ START_TEST(eolian_docs)
|
|||
fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_REF);
|
||||
txt = eolian_doc_token_text_get(&tok);
|
||||
fail_if(strcmp(txt, "Docs.meth"));
|
||||
fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_DOC_REF_FUNC);
|
||||
fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_OBJECT_FUNCTION);
|
||||
free(txt);
|
||||
tdoc = eolian_documentation_tokenize(tdoc, &tok);
|
||||
fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_TEXT);
|
||||
|
|
Loading…
Reference in New Issue