eolian: consistent and cleaner error values from APIs

Now all error/unknown/etc values returned from APIs are zero,
previously it was a mix of zeroes and minus ones. Also, some
enums that had no error/invalid value before have one now, which
allows for better distinction between what is an error and what
is an intended result.
This commit is contained in:
Daniel Kolesa 2017-01-13 15:15:10 +01:00
parent 70ad68bfc7
commit a70645e154
9 changed files with 92 additions and 84 deletions

View File

@ -573,10 +573,6 @@ eo_gen_docs_func_gen(const Eolian_Function *fid, Eolian_Function_Type ftype,
switch (dir)
{
case EOLIAN_IN_PARAM:
eina_strbuf_append(buf, " * @param[in] ");
curl += sizeof(" * @param[in] ") - 1;
break;
case EOLIAN_OUT_PARAM:
eina_strbuf_append(buf, " * @param[out] ");
curl += sizeof(" * @param[out] ") - 1;
@ -585,6 +581,10 @@ eo_gen_docs_func_gen(const Eolian_Function *fid, Eolian_Function_Type ftype,
eina_strbuf_append(buf, " * @param[in,out] ");
curl += sizeof(" * @param[in,out] ") - 1;
break;
default:
eina_strbuf_append(buf, " * @param[in] ");
curl += sizeof(" * @param[in] ") - 1;
break;
}
const char *nm = eolian_parameter_name_get(par);

View File

@ -40,14 +40,15 @@ ffi.cdef [[
typedef enum
{
EOLIAN_IN_PARAM = 0,
EOLIAN_UNKNOWN_PARAM = 0,
EOLIAN_IN_PARAM,
EOLIAN_OUT_PARAM,
EOLIAN_INOUT_PARAM
} Eolian_Parameter_Dir;
typedef enum
{
EOLIAN_CLASS_UNKNOWN_TYPE = 0,
EOLIAN_CLASS_UNKNOWN_TYPE = 0,
EOLIAN_CLASS_REGULAR,
EOLIAN_CLASS_ABSTRACT,
EOLIAN_CLASS_MIXIN,
@ -56,7 +57,8 @@ ffi.cdef [[
typedef enum
{
EOLIAN_SCOPE_PUBLIC = 0,
EOLIAN_SCOPE_UNKNOWN = 0,
EOLIAN_SCOPE_PUBLIC,
EOLIAN_SCOPE_PRIVATE,
EOLIAN_SCOPE_PROTECTED
} Eolian_Object_Scope;
@ -142,7 +144,7 @@ ffi.cdef [[
} Eolian_Value_t;
typedef enum {
EOLIAN_BINOP_INVALID = -1,
EOLIAN_BINOP_INVALID = 0,
EOLIAN_BINOP_ADD, /* + int, float */
EOLIAN_BINOP_SUB, /* - int, float */
@ -168,7 +170,7 @@ ffi.cdef [[
} Eolian_Binary_Operator;
typedef enum {
EOLIAN_UNOP_INVALID = -1,
EOLIAN_UNOP_INVALID = 0,
EOLIAN_UNOP_UNM, /* - sint */
EOLIAN_UNOP_UNP, /* + sint */
@ -178,7 +180,7 @@ ffi.cdef [[
} Eolian_Unary_Operator;
typedef enum {
EOLIAN_DECL_UNKNOWN = -1,
EOLIAN_DECL_UNKNOWN = 0,
EOLIAN_DECL_CLASS,
EOLIAN_DECL_ALIAS,
EOLIAN_DECL_STRUCT,
@ -187,7 +189,7 @@ ffi.cdef [[
} Eolian_Declaration_Type;
typedef enum {
EOLIAN_DOC_TOKEN_UNKNOWN = -1,
EOLIAN_DOC_TOKEN_UNKNOWN = 0,
EOLIAN_DOC_TOKEN_TEXT,
EOLIAN_DOC_TOKEN_REF,
EOLIAN_DOC_TOKEN_MARK_NOTE,
@ -433,9 +435,10 @@ end
cutil.init_module(init, shutdown)
M.object_scope = {
PUBLIC = 0,
PRIVATE = 1,
PROTECTED = 2
UNKNOWN = 0,
PUBLIC = 1,
PRIVATE = 2,
PROTECTED = 3
}
M.directory_scan = function(dir)
@ -479,12 +482,12 @@ M.database_validate = function()
end
M.declaration_type = {
UNKNOWN = -1,
CLASS = 0,
ALIAS = 1,
STRUCT = 2,
ENUM = 3,
VAR = 4
UNKNOWN = 0,
CLASS = 0,
ALIAS = 1,
STRUCT = 2,
ENUM = 3,
VAR = 4
}
M.type_type = {
@ -849,9 +852,10 @@ M.Function = ffi.metatype("Eolian_Function", {
})
M.parameter_dir = {
IN = 0,
OUT = 1,
INOUT = 2
UNKNOWN = 0,
IN = 1,
OUT = 2,
INOUT = 3
}
ffi.metatype("Eolian_Function_Parameter", {
@ -1271,39 +1275,39 @@ M.Value = ffi.metatype("Eolian_Value", {
})
M.binary_operator = {
INVALID = -1,
INVALID = 0,
ADD = 0,
SUB = 1,
MUL = 2,
DIV = 3,
MOD = 4,
ADD = 1,
SUB = 2,
MUL = 3,
DIV = 4,
MOD = 5,
EQ = 5,
NQ = 6,
GT = 7,
LT = 8,
GE = 9,
LE = 10,
EQ = 6,
NQ = 7,
GT = 8,
LT = 9,
GE = 10,
LE = 11,
AND = 11,
OR = 12,
AND = 12,
OR = 13,
BAND = 13,
BOR = 14,
BXOR = 15,
LSH = 16,
RSH = 17
BAND = 14,
BOR = 15,
BXOR = 16,
LSH = 17,
RSH = 18
}
M.unary_operator = {
INVALID = -1,
INVALID = 0,
UNM = 0,
UNP = 1,
UNM = 1,
UNP = 2,
NOT = 2,
BNOT = 3
NOT = 3,
BNOT = 4
}
M.Expression = ffi.metatype("Eolian_Expression", {
@ -1523,14 +1527,14 @@ M.Documentation = ffi.metatype("Eolian_Documentation", {
})
M.doc_token_type = {
UNKNOWN = -1,
TEXT = 0,
REF = 1,
MARK_NOTE = 2,
MARK_WARNING = 3,
MARK_REMARK = 4,
MARK_TODO = 5,
MARKUP_MONOSPACE = 6
UNKNOWN = 0,
TEXT = 1,
REF = 2,
MARK_NOTE = 3,
MARK_WARNING = 4,
MARK_REMARK = 5,
MARK_TODO = 6,
MARKUP_MONOSPACE = 7
}
M.doc_ref_type = {

View File

@ -182,7 +182,8 @@ typedef enum
typedef enum
{
EOLIAN_IN_PARAM = 0,
EOLIAN_UNKNOWN_PARAM = 0,
EOLIAN_IN_PARAM,
EOLIAN_OUT_PARAM,
EOLIAN_INOUT_PARAM
} Eolian_Parameter_Dir;
@ -198,7 +199,8 @@ typedef enum
typedef enum
{
EOLIAN_SCOPE_PUBLIC = 0,
EOLIAN_SCOPE_UNKNOWN = 0,
EOLIAN_SCOPE_PUBLIC,
EOLIAN_SCOPE_PRIVATE,
EOLIAN_SCOPE_PROTECTED
} Eolian_Object_Scope;
@ -291,7 +293,7 @@ typedef struct _Eolian_Value
typedef enum
{
EOLIAN_BINOP_INVALID = -1,
EOLIAN_BINOP_INVALID = 0,
EOLIAN_BINOP_ADD, /* + int, float */
EOLIAN_BINOP_SUB, /* - int, float */
@ -318,7 +320,7 @@ typedef enum
typedef enum
{
EOLIAN_UNOP_INVALID = -1,
EOLIAN_UNOP_INVALID = 0,
EOLIAN_UNOP_UNM, /* - sint */
EOLIAN_UNOP_UNP, /* + sint */
@ -329,7 +331,7 @@ typedef enum
typedef enum
{
EOLIAN_DECL_UNKNOWN = -1,
EOLIAN_DECL_UNKNOWN = 0,
EOLIAN_DECL_CLASS,
EOLIAN_DECL_ALIAS,
EOLIAN_DECL_STRUCT,
@ -339,7 +341,7 @@ typedef enum
typedef enum
{
EOLIAN_DOC_TOKEN_UNKNOWN = -1,
EOLIAN_DOC_TOKEN_UNKNOWN = 0,
EOLIAN_DOC_TOKEN_TEXT,
EOLIAN_DOC_TOKEN_REF,
EOLIAN_DOC_TOKEN_MARK_NOTE,

View File

@ -29,7 +29,7 @@ eolian_event_documentation_get(const Eolian_Event *event)
EAPI Eolian_Object_Scope
eolian_event_scope_get(const Eolian_Event *event)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(event, EOLIAN_SCOPE_PUBLIC);
EINA_SAFETY_ON_NULL_RETURN_VAL(event, EOLIAN_SCOPE_UNKNOWN);
return event->scope;
}

View File

@ -8,25 +8,25 @@
EAPI Eolian_Object_Scope
eolian_function_scope_get(const Eolian_Function *fid, Eolian_Function_Type ftype)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_PUBLIC);
EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_UNRESOLVED, EOLIAN_SCOPE_PUBLIC);
EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_PROPERTY, EOLIAN_SCOPE_PUBLIC);
EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_UNKNOWN);
EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_UNRESOLVED, EOLIAN_SCOPE_UNKNOWN);
EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_PROPERTY, EOLIAN_SCOPE_UNKNOWN);
switch (ftype)
{
case EOLIAN_METHOD:
if (fid->type != EOLIAN_METHOD)
return EOLIAN_SCOPE_PUBLIC;
return EOLIAN_SCOPE_UNKNOWN;
return fid->get_scope;
case EOLIAN_PROP_GET:
if ((fid->type != EOLIAN_PROP_GET) && (fid->type != EOLIAN_PROPERTY))
return EOLIAN_SCOPE_PUBLIC;
return EOLIAN_SCOPE_UNKNOWN;
return fid->get_scope;
case EOLIAN_PROP_SET:
if ((fid->type != EOLIAN_PROP_SET) && (fid->type != EOLIAN_PROPERTY))
return EOLIAN_SCOPE_PUBLIC;
return EOLIAN_SCOPE_UNKNOWN;
return fid->set_scope;
default:
return EOLIAN_SCOPE_PUBLIC;
return EOLIAN_SCOPE_UNKNOWN;
}
}

View File

@ -8,7 +8,7 @@
EAPI Eolian_Parameter_Dir
eolian_parameter_direction_get(const Eolian_Function_Parameter *param)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(param, EOLIAN_IN_PARAM);
EINA_SAFETY_ON_NULL_RETURN_VAL(param, EOLIAN_UNKNOWN_PARAM);
return param->param_dir;
}

View File

@ -270,7 +270,7 @@ get_binop_id(int tok)
case TOK_LSH: return EOLIAN_BINOP_LSH;
case TOK_RSH: return EOLIAN_BINOP_RSH;
default: return -1;
default: return EOLIAN_BINOP_INVALID;
}
}
@ -284,11 +284,13 @@ get_unop_id(int tok)
case '!': return EOLIAN_UNOP_NOT;
case '~': return EOLIAN_UNOP_BNOT;
default: return -1;
default: return EOLIAN_UNOP_INVALID;
}
}
static const int binprec[] = {
-1, /* invalid */
8, /* + */
8, /* - */
9, /* * */
@ -314,13 +316,6 @@ static const int binprec[] = {
#define UNARY_PRECEDENCE 10
static int
get_binop_prec(Eolian_Binary_Operator id)
{
if (id < 0) return -1;
return binprec[id];
}
static Eolian_Expression *parse_expr_bin(Eo_Lexer *ls, int min_prec);
static Eolian_Expression *parse_expr(Eo_Lexer *ls);
@ -329,7 +324,7 @@ parse_expr_simple(Eo_Lexer *ls)
{
Eolian_Expression *expr;
Eolian_Unary_Operator unop = get_unop_id(ls->t.token);
if (unop >= 0)
if (unop != EOLIAN_UNOP_INVALID)
{
int line = ls->line_number, col = ls->column;
eo_lexer_get(ls);
@ -436,8 +431,8 @@ parse_expr_bin(Eo_Lexer *ls, int min_prec)
{
Eolian_Expression *rhs, *bin;
Eolian_Binary_Operator op = get_binop_id(ls->t.token);
int prec = get_binop_prec(op);
if ((op < 0) || (prec < 0) || (prec < min_prec))
int prec = binprec[op];
if ((op == EOLIAN_BINOP_INVALID) || (prec < 0) || (prec < min_prec))
break;
eo_lexer_get(ls);
rhs = parse_expr_bin(ls, prec + 1);
@ -1073,6 +1068,7 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
Eina_Bool has_nonull = EINA_FALSE, has_optional = EINA_FALSE,
has_nullable = EINA_FALSE;
Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter));
par->param_dir = EOLIAN_IN_PARAM;
FILL_BASE(par->base, ls, ls->line_number, ls->column);
*params = eina_list_append(*params, par);
if (allow_inout && ls->t.kw == KW_at_in)
@ -1321,6 +1317,7 @@ parse_property(Eo_Lexer *ls)
prop = calloc(1, sizeof(Eolian_Function));
prop->klass = ls->tmp.kls;
prop->type = EOLIAN_UNRESOLVED;
prop->get_scope = prop->set_scope = EOLIAN_SCOPE_PUBLIC;
FILL_BASE(prop->base, ls, ls->line_number, ls->column);
ls->tmp.kls->properties = eina_list_append(ls->tmp.kls->properties, prop);
check(ls, TOK_VALUE);
@ -1406,6 +1403,7 @@ parse_method(Eo_Lexer *ls)
meth = calloc(1, sizeof(Eolian_Function));
meth->klass = ls->tmp.kls;
meth->type = EOLIAN_METHOD;
meth->get_scope = meth->set_scope = EOLIAN_SCOPE_PUBLIC;
FILL_BASE(meth->base, ls, ls->line_number, ls->column);
ls->tmp.kls->methods = eina_list_append(ls->tmp.kls->methods, meth);
check(ls, TOK_VALUE);
@ -1692,6 +1690,7 @@ parse_event(Eo_Lexer *ls)
{
Eolian_Event *ev = calloc(1, sizeof(Eolian_Event));
FILL_BASE(ev->base, ls, ls->line_number, ls->column);
ev->scope = EOLIAN_SCOPE_PUBLIC;
Eina_Strbuf *buf = push_strbuf(ls);
ls->tmp.kls->events = eina_list_append(ls->tmp.kls->events, ev);
check(ls, TOK_VALUE);

View File

@ -226,7 +226,7 @@ struct _Eolian_Event
Eolian_Documentation *doc;
Eolian_Type *type;
Eolian_Class *klass;
int scope;
Eolian_Object_Scope scope;
Eina_Bool is_beta :1;
Eina_Bool is_hot :1;
Eina_Bool is_restart :1;

View File

@ -12,6 +12,7 @@ local M = {}
M.Node = util.Object:clone {
scope = {
UNKNOWN = eolian.object_scope.UNKNOWN,
PUBLIC = eolian.object_scope.PUBLIC,
PRIVATE = eolian.object_scope.PRIVATE,
PROTECTED = eolian.object_scope.PROTECTED
@ -408,6 +409,7 @@ M.Function = Node:clone {
}
M.Parameter = Node:clone {
UNKNOWN = eolian.param_dir.UNKNOWN,
IN = eolian.parameter_dir.IN,
OUT = eolian.parameter_dir.OUT,
INOUT = eolian.parameter_dir.INOUT,
@ -427,7 +429,8 @@ M.Parameter = Node:clone {
[self.OUT] = "out",
[self.INOUT] = "inout"
}
return dir_to_str[self:direction_get()]
return assert(dir_to_str[self:direction_get()],
"unknown parameter direction")
end,
type_get = function(self)