This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch eolian/improvements
in repository efl.
View the commit online.
commit 53403eb2ec6a6b54243b2978f877408d66178342
Author: [email protected] <[email protected]>
AuthorDate: Thu Oct 29 21:22:32 2026 -0600
eolian: constructors can be construction only
A constructor in a class's constructors {} block says "this property
is set while the object is built", but nothing said it must not be set
afterwards. A new @construct_only qualifier does, and it combines with
@optional:
constructors {
.win_name @construct_only;
.title @optional @construct_only;
}
eolian_gen turns it into a guarded EOAPI function: the generated body
refuses the call once the object is finalized, and the header's doc
comment says so. The reflection setter returns EPERM after finalize. A
refused call returns the .eo default value for the function. The
guard itself is the Eo side of this change, in the previous commit.
The API is eolian_constructor_is_construct_only(ctor) and
eolian_function_is_construct_only(fid, ftype). The second is per
function, not per class like eolian_function_is_constructor, because
the check lives in the one C function and every caller goes through
it. Both are exposed by pyolian and the Lua bindings.
Validation rejects what cannot work: the function must belong to the
class's own constructors (not an inherited one), a property must have
a setter, and the function can be neither static nor const. The parser
now also rejects a qualifier given twice, which @optional previously
let through.
Tests cover parsing, each validation error, the generated output
for a class and its child, and the pyolian accessors. No library .eo
uses the qualifier yet; that follows.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
doc/eolian/grammar.md | 24 +++
src/bin/eolian/docs.c | 20 ++-
src/bin/eolian/sources.c | 21 ++-
src/bindings/lua/eolian.lua | 10 ++
src/lib/eolian/Eolian.h | 43 ++++++
src/lib/eolian/database_constructor_api.c | 7 +
src/lib/eolian/database_function_api.c | 14 ++
src/lib/eolian/database_validate.c | 33 ++++
src/lib/eolian/eo_lexer.h | 2 +-
src/lib/eolian/eo_parser.c | 41 +++--
src/lib/eolian/eolian_database.h | 2 +
src/scripts/pyolian/eolian.py | 10 +-
src/scripts/pyolian/eolian_lib.py | 8 +
src/scripts/pyolian/test_eolian.py | 2 +
src/tests/eolian/data/construct_only.eo | 54 +++++++
src/tests/eolian/data/construct_only_child.eo | 19 +++
src/tests/eolian/data/construct_only_child_ref.c | 78 ++++++++++
src/tests/eolian/data/construct_only_const.eo | 11 ++
src/tests/eolian/data/construct_only_double.eo | 17 +++
src/tests/eolian/data/construct_only_double_opt.eo | 17 +++
src/tests/eolian/data/construct_only_foreign.eo | 6 +
src/tests/eolian/data/construct_only_noset.eo | 15 ++
src/tests/eolian/data/construct_only_ref.c | 170 +++++++++++++++++++++
src/tests/eolian/data/construct_only_ref.h | 140 +++++++++++++++++
src/tests/eolian/data/construct_only_static.eo | 17 +++
src/tests/eolian/eolian_generation.c | 23 +++
src/tests/eolian/eolian_parsing.c | 114 ++++++++++++++
27 files changed, 892 insertions(+), 26 deletions(-)
diff --git a/doc/eolian/grammar.md b/doc/eolian/grammar.md
index 37fad42c07..65cfd3ccac 100644
--- a/doc/eolian/grammar.md
+++ b/doc/eolian/grammar.md
@@ -256,6 +256,30 @@ class Efl.Ui.Button extends Efl.Ui.Layout_Base implements Efl.Ui.Clickable,
`data: null` says the class carries no private data. It is required, not optional — a
class that stores nothing must say so.
+Each entry of a `constructors` block names a function and may carry qualifiers, in any
+order:
+
+```eo
+constructors {
+ .win_name @construct_only;
+ .win_type @optional @construct_only;
+}
+```
+
+`@optional` lets `efl_add` callers omit the call. `@construct_only` makes the function
+legal only during construction, inside `efl_add` and before the object is finalized: the
+generated C function logs an error and does nothing when called on a finalized object.
+An object is only marked finalized once every `finalize` implementation, the class's own
+and its parents', and the `efl_add` construction block have run, so all of those may
+call construct-only functions. The restriction applies to a property's setter (the getter
+is always callable) or a method, and only to a function the class declares itself.
+Each qualifier may be given once.
+
+A refused call returns the default declared in the `.eo` file (`return: bool (false)`),
+exactly as a call that cannot be resolved does, so give a construct-only function a
+default that reads as failure. Setting the property through reflection returns
+`EPERM` instead.
+
## 5. Methods and properties
### Methods
diff --git a/src/bin/eolian/docs.c b/src/bin/eolian/docs.c
index 19fb96e040..dbfb7761b9 100644
--- a/src/bin/eolian/docs.c
+++ b/src/bin/eolian/docs.c
@@ -527,6 +527,8 @@ eo_gen_docs_func_gen(const Eolian_State *state, const Eolian_Function *fid,
rdoc = eolian_function_return_documentation_get(fid, ftype);
+ Eina_Bool construct_only = eolian_function_is_construct_only(fid, ftype);
+
if (doc)
{
sum = eolian_documentation_summary_get(doc);
@@ -597,7 +599,8 @@ eo_gen_docs_func_gen(const Eolian_State *state, const Eolian_Function *fid,
}
/* only summary, nothing else; generate standard brief doc */
- if (!desc && !par && !vpar && !rdoc && (ftype == EOLIAN_METHOD || !pdoc))
+ if (!desc && !par && !vpar && !rdoc && !construct_only &&
+ (ftype == EOLIAN_METHOD || !pdoc))
{
_gen_doc_brief(state, SUMMARY_OR_DEFAULT(sum), since, group,
NULL, indent, buf);
@@ -614,7 +617,7 @@ eo_gen_docs_func_gen(const Eolian_State *state, const Eolian_Function *fid,
indent, curl, buf, wbuf);
eina_strbuf_append_char(buf, '\n');
- if (desc || since || par || rdoc || pdoc)
+ if (desc || since || par || rdoc || pdoc || construct_only)
{
_indent_line(buf, indent);
eina_strbuf_append(buf, " *\n");
@@ -626,7 +629,7 @@ eo_gen_docs_func_gen(const Eolian_State *state, const Eolian_Function *fid,
eina_strbuf_append(buf, " * ");
_append_section(state, desc, indent, curl + 3, buf, wbuf);
eina_strbuf_append_char(buf, '\n');
- if (par || rdoc || pdoc || since)
+ if (par || rdoc || pdoc || since || construct_only)
{
_indent_line(buf, indent);
eina_strbuf_append(buf, " *\n");
@@ -651,13 +654,22 @@ eo_gen_docs_func_gen(const Eolian_State *state, const Eolian_Function *fid,
_append_section(state, pdesc, indent, curl + 3, buf, wbuf);
eina_strbuf_append_char(buf, '\n');
}
- if (par || rdoc || since)
+ if (par || rdoc || since || construct_only)
{
_indent_line(buf, indent);
eina_strbuf_append(buf, " *\n");
}
}
+ if (construct_only)
+ {
+ _indent_line(buf, indent);
+ eina_strbuf_append(buf, " * @note This function is only allowed during construction, "
+ "inside efl_add and before the object is finalized.\n");
+ _indent_line(buf, indent);
+ eina_strbuf_append(buf, " *\n");
+ }
+
if (!eolian_function_is_static(fid))
{
_indent_line(buf, indent);
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index 0b7e71513a..8d9f480f67 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -476,10 +476,19 @@ _gen_reflect_set(Eina_Strbuf *buf, const char *cnamel,
eina_strbuf_append_printf(buf, " %s%scval;\n", ct, starsp);
if (is_enum)
+ eina_strbuf_append(buf, " int64_t ecval;\n");
+ /* the setter refuses a finalized object, so say so rather than report
+ * success for a write that did nothing */
+ if (eolian_function_is_construct_only(fid, EOLIAN_PROP_SET))
{
- eina_strbuf_append(buf, " int64_t ecval;\n");
- eina_strbuf_append(buf, " if (!eina_value_int64_convert(&val, &ecval))\n");
+ eina_strbuf_append(buf, " if (efl_finalized_get(obj))\n");
+ eina_strbuf_append(buf, " {\n");
+ eina_strbuf_append(buf, " r = EPERM;\n");
+ eina_strbuf_append(buf, " goto end;\n");
+ eina_strbuf_append(buf, " }\n");
}
+ if (is_enum)
+ eina_strbuf_append(buf, " if (!eina_value_int64_convert(&val, &ecval))\n");
else
eina_strbuf_append_printf(buf, " if (!eina_value_%s_convert(&val, &cval))\n", initf);
eina_strbuf_append(buf, " {\n");
@@ -933,8 +942,12 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
eina_strbuf_append(buf, "FUNC_BODY");
if (has_params)
eina_strbuf_append_char(buf, 'V');
- if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
- || eolian_function_is_static(fid))
+ /* only a setter or a method can be construct only, and validation
+ * refuses const and static ones, so this never meets _CONST */
+ if (eolian_function_is_construct_only(fid, ftype))
+ eina_strbuf_append(buf, "_CONSTRUCT_ONLY");
+ else if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
+ || eolian_function_is_static(fid))
{
eina_strbuf_append(buf, "_CONST");
}
diff --git a/src/bindings/lua/eolian.lua b/src/bindings/lua/eolian.lua
index d55d7cc17c..cd11d7c3a6 100644
--- a/src/bindings/lua/eolian.lua
+++ b/src/bindings/lua/eolian.lua
@@ -357,6 +357,7 @@ ffi.cdef [[
const Eolian_Implement *eolian_function_implement_get(const Eolian_Function *function_id);
Eina_Bool eolian_function_is_static(const Eolian_Function *function_id);
Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass);
+ Eina_Bool eolian_function_is_construct_only(const Eolian_Function *function_id, Eolian_Function_Type ftype);
Eina_Bool eolian_function_is_function_pointer(const Eolian_Function *function_id);
Eina_Iterator *eolian_property_keys_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
Eina_Iterator *eolian_property_values_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
@@ -389,6 +390,7 @@ ffi.cdef [[
const Eolian_Class *eolian_constructor_class_get(const Eolian_Constructor *ctor);
const Eolian_Function *eolian_constructor_function_get(const Eolian_Constructor *ctor);
Eina_Bool eolian_constructor_is_optional(const Eolian_Constructor *ctor);
+ Eina_Bool eolian_constructor_is_construct_only(const Eolian_Constructor *ctor);
Eina_Iterator *eolian_class_constructors_get(const Eolian_Class *klass);
Eina_Iterator *eolian_class_events_get(const Eolian_Class *klass);
const Eolian_Type *eolian_event_type_get(const Eolian_Event *event);
@@ -1191,6 +1193,10 @@ M.Function = ffi.metatype("Eolian_Function", {
return eolian.eolian_function_is_constructor(self, klass) ~= 0
end,
+ is_construct_only = function(self, ftype)
+ return eolian.eolian_function_is_construct_only(self, ftype) ~= 0
+ end,
+
is_function_pointer = function(self)
return eolian.eolian_function_is_function_pointer(self) ~= 0
end,
@@ -1363,6 +1369,10 @@ ffi.metatype("Eolian_Constructor", {
is_optional = function(self)
return eolian.eolian_constructor_is_optional(self) ~= 0
+ end,
+
+ is_construct_only = function(self)
+ return eolian.eolian_constructor_is_construct_only(self) ~= 0
end
}
})
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 4583480906..1512ccdda1 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -1717,6 +1717,33 @@ eolian_function_is_beta(const Eolian_Function *function_id)
*/
EOLIAN_API Eina_Bool eolian_function_is_constructor(const Eolian_Function *function_id, const Eolian_Class *klass);
+/*
+ * @brief Indicates if a function may only be called during construction.
+ *
+ * This is a property of the function itself: only the class declaring it can
+ * mark it @construct_only in its constructors block, the generated C function
+ * carries the check, and it applies to every object that can call it. That
+ * differs from eolian_function_is_constructor, which is per class because a
+ * constructors list is that class's efl_add signature.
+ *
+ * It is true for EOLIAN_PROP_SET, EOLIAN_PROPERTY and EOLIAN_METHOD when the
+ * function is marked, and always false for EOLIAN_PROP_GET: the getter of a
+ * property stays callable at any time.
+ *
+ * A refused call to the generated C function returns the default value the
+ * .eo declares for the function (as a call that cannot be resolved does), so
+ * pick a default that reads as failure; the reflection setter returns EPERM.
+ *
+ * @param[in] function_id Id of the function
+ * @param[in] ftype which half of a property, or EOLIAN_METHOD
+ * @return EINA_TRUE and EINA_FALSE respectively (EINA_FALSE if function_id is NULL)
+ *
+ * @since 1.30
+ *
+ * @ingroup Eolian
+ */
+EOLIAN_API Eina_Bool eolian_function_is_construct_only(const Eolian_Function *function_id, Eolian_Function_Type ftype);
+
/*
* @brief Returns an iterator to the parameter handles for a method/ctor/dtor.
*
@@ -2205,6 +2232,22 @@ EOLIAN_API const Eolian_Function *eolian_constructor_function_get(const Eolian_C
*/
EOLIAN_API Eina_Bool eolian_constructor_is_optional(const Eolian_Constructor *ctor);
+/*
+ * @brief Checks if a constructor is tagged @construct_only.
+ *
+ * A construct only function may only be called while the object is being
+ * constructed, inside efl_add and before the object is finalized: the
+ * generated C function refuses the call afterwards.
+ *
+ * @param[in] ctor the handle of the constructor
+ * @return EINA_TRUE if construct only, EINA_FALSE if not (or if input is NULL).
+ *
+ * @since 1.30
+ *
+ * @ingroup Eolian
+ */
+EOLIAN_API Eina_Bool eolian_constructor_is_construct_only(const Eolian_Constructor *ctor);
+
/*
* @brief Get an iterator to the constructing functions defined in a class.
*
diff --git a/src/lib/eolian/database_constructor_api.c b/src/lib/eolian/database_constructor_api.c
index f1794df409..a576bec5e3 100644
--- a/src/lib/eolian/database_constructor_api.c
+++ b/src/lib/eolian/database_constructor_api.c
@@ -29,3 +29,10 @@ eolian_constructor_is_optional(const Eolian_Constructor *ctor)
EINA_SAFETY_ON_NULL_RETURN_VAL(ctor, EINA_FALSE);
return ctor->is_optional;
}
+
+EOLIAN_API Eina_Bool
+eolian_constructor_is_construct_only(const Eolian_Constructor *ctor)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ctor, EINA_FALSE);
+ return ctor->is_construct_only;
+}
diff --git a/src/lib/eolian/database_function_api.c b/src/lib/eolian/database_function_api.c
index 0d7e5d60c9..34dec13596 100644
--- a/src/lib/eolian/database_function_api.c
+++ b/src/lib/eolian/database_function_api.c
@@ -141,6 +141,20 @@ eolian_function_is_constructor(const Eolian_Function *fid, const Eolian_Class *k
return r;
}
+EOLIAN_API Eina_Bool
+eolian_function_is_construct_only(const Eolian_Function *fid, Eolian_Function_Type ftype)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE);
+ /* only the declaring class can make a function construct only, and it
+ * never applies to the getter of a property */
+ if ((ftype != EOLIAN_PROP_SET) && (ftype != EOLIAN_PROPERTY) &&
+ (ftype != EOLIAN_METHOD))
+ return EINA_FALSE;
+ if (!database_function_is_type((Eolian_Function *)fid, ftype))
+ return EINA_FALSE;
+ return fid->is_construct_only;
+}
+
static Eina_List *
_get_prop_keys(const Eolian_Function *fid, Eolian_Function_Type ftype)
{
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index 1ceff3749e..472ab1eed0 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -1259,6 +1259,39 @@ _db_fill_ctors(Eolian_Class *cl)
ret = EINA_FALSE;
goto end;
}
+ if (ctor->is_construct_only)
+ {
+ /* the check is generated in the declaring class's .eo.c, so
+ * a class can only restrict the functions it declares itself
+ */
+ if (tcl != cl)
+ {
+ _eo_parser_log(&ctor->base, "'%s' cannot be @construct_only: "
+ "it is declared by '%s', not by '%s'",
+ ctor->base.name, tcl->base.name, cl->base.name);
+ ret = EINA_FALSE;
+ goto end;
+ }
+ Eolian_Function_Type cft = eolian_function_type_get(cfunc);
+ if ((cft != EOLIAN_METHOD) && (cft != EOLIAN_PROPERTY) &&
+ (cft != EOLIAN_PROP_SET))
+ {
+ _eo_parser_log(&ctor->base, "'%s' cannot be @construct_only: "
+ "it has no setter", ctor->base.name);
+ ret = EINA_FALSE;
+ goto end;
+ }
+ if (eolian_function_is_static(cfunc) ||
+ ((cft == EOLIAN_METHOD) && eolian_function_object_is_const(cfunc)))
+ {
+ _eo_parser_log(&ctor->base, "'%s' cannot be @construct_only: "
+ "it is static or const, so it has no object "
+ "state to protect", ctor->base.name);
+ ret = EINA_FALSE;
+ goto end;
+ }
+ ((Eolian_Function *)cfunc)->is_construct_only = EINA_TRUE;
+ }
database_function_constructor_add((Eolian_Function *)cfunc, tcl);
eina_hash_add(th, ctor->base.name, ctor->base.name);
}
diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h
index eb91a542ab..cbcca174d1 100644
--- a/src/lib/eolian/eo_lexer.h
+++ b/src/lib/eolian/eo_lexer.h
@@ -31,7 +31,7 @@ enum Tokens
KW(keys), KW(legacy), KW(methods), KW(mixin), KW(params), \
KW(parse), KW(parts), KW(styles), KW(ptr), KW(set), KW(type), KW(values), KW(requires), \
\
- KWAT(auto), KWAT(beta), KWAT(by_ref), KWAT(c_name), KWAT(const), \
+ KWAT(auto), KWAT(beta), KWAT(by_ref), KWAT(c_name), KWAT(const), KWAT(construct_only), \
KWAT(deprecated), KWAT(empty), KWAT(extern), KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), \
KWAT(move), KWAT(no_unused), KWAT(nullable), KWAT(optional), KWAT(out), \
KWAT(private), KWAT(property), KWAT(protected), KWAT(restart), \
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 3a165cad42..79eae658da 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -1833,6 +1833,29 @@ propend:
}
}
+/* @optional and @construct_only, in any order, each at most once */
+static void
+parse_constructor_qualifiers(Eo_Lexer *ls, Eolian_Constructor *ctor)
+{
+ Eina_Bool has_optional = EINA_FALSE, has_construct_only = EINA_FALSE;
+ for (;;)
+ {
+ if (ls->t.kw == KW_at_optional)
+ {
+ CASE_LOCK(ls, optional, "optional qualifier");
+ ctor->is_optional = EINA_TRUE;
+ }
+ else if (ls->t.kw == KW_at_construct_only)
+ {
+ CASE_LOCK(ls, construct_only, "construct_only qualifier");
+ ctor->is_construct_only = EINA_TRUE;
+ }
+ else
+ break;
+ eo_lexer_get(ls);
+ }
+}
+
static void
parse_constructor(Eo_Lexer *ls)
{
@@ -1851,14 +1874,7 @@ parse_constructor(Eo_Lexer *ls)
ls->klass->base.name,
ls->t.value.s);
eo_lexer_get(ls);
- while (ls->t.kw == KW_at_optional)
- {
- if (ls->t.kw == KW_at_optional)
- {
- ctor->is_optional = EINA_TRUE;
- }
- eo_lexer_get(ls);
- }
+ parse_constructor_qualifiers(ls, ctor);
check_next(ls, ';');
return;
}
@@ -1878,14 +1894,7 @@ parse_constructor(Eo_Lexer *ls)
if (ls->t.token != '.') break;
eo_lexer_get(ls);
}
- while (ls->t.kw == KW_at_optional)
- {
- if (ls->t.kw == KW_at_optional)
- {
- ctor->is_optional = EINA_TRUE;
- }
- eo_lexer_get(ls);
- }
+ parse_constructor_qualifiers(ls, ctor);
check_next(ls, ';');
ctor->base.name = eina_stringshare_add(eina_strbuf_string_get(buf));
eo_lexer_dtor_pop(ls);
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 4bdc918b71..63b283d20a 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -239,6 +239,7 @@ struct _Eolian_Function
Eina_Bool set_return_by_ref :1;
Eina_Bool is_static :1;
Eina_Bool is_deprecated :1; /* kept for compatibility; bindings leave it out */
+ Eina_Bool is_construct_only :1; /* set by validation from the class's own constructors block */
};
struct _Eolian_Style
@@ -337,6 +338,7 @@ struct _Eolian_Constructor
Eolian_Object base;
const Eolian_Class *klass;
Eina_Bool is_optional: 1;
+ Eina_Bool is_construct_only: 1;
};
struct _Eolian_Event
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index eccfee076b..b4d2370ad2 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -869,7 +869,8 @@ class Part(Object):
class Constructor(Object):
def __repr__(self):
- return "<eolian.Constructor '{0.name}', optional={0.is_optional}>".format(self)
+ return "<eolian.Constructor '{0.name}', optional={0.is_optional}," \
+ " construct_only={0.is_construct_only}>".format(self)
@cached_property
def function(self):
@@ -879,6 +880,10 @@ class Constructor(Object):
def is_optional(self):
return bool(lib.eolian_constructor_is_optional(self))
+ @cached_property
+ def is_construct_only(self):
+ return bool(lib.eolian_constructor_is_construct_only(self))
+
@cached_property
def class_(self):
return Class(lib.eolian_constructor_class_get(self))
@@ -980,6 +985,9 @@ class Function(Object):
def is_constructor(self, klass):
return bool(lib.eolian_function_is_constructor(self, klass._obj))
+ def is_construct_only(self, ftype):
+ return bool(lib.eolian_function_is_construct_only(self, int(ftype)))
+
# @cached_property
# def is_function_pointer(self):
# return bool(lib.eolian_function_is_function_pointer(self))
diff --git a/src/scripts/pyolian/eolian_lib.py b/src/scripts/pyolian/eolian_lib.py
index 4ea7714e88..8dba57cbab 100644
--- a/src/scripts/pyolian/eolian_lib.py
+++ b/src/scripts/pyolian/eolian_lib.py
@@ -354,6 +354,10 @@ lib.eolian_function_is_static.restype = c_bool
lib.eolian_function_is_constructor.argtypes = (c_void_p, c_void_p)
lib.eolian_function_is_constructor.restype = c_bool
+# EAPI Eina_Bool eolian_function_is_construct_only(const Eolian_Function *function_id, Eolian_Function_Type ftype);
+lib.eolian_function_is_construct_only.argtypes = (c_void_p, c_int)
+lib.eolian_function_is_construct_only.restype = c_bool
+
# EAPI Eina_Bool eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param_desc);
lib.eolian_parameter_is_by_ref.argtypes = (c_void_p,)
lib.eolian_parameter_is_by_ref.restype = c_bool
@@ -496,6 +500,10 @@ lib.eolian_constructor_function_get.restype = c_void_p
lib.eolian_constructor_is_optional.argtypes = (c_void_p,)
lib.eolian_constructor_is_optional.restype = c_bool
+# EAPI Eina_Bool eolian_constructor_is_construct_only(const Eolian_Constructor *ctor);
+lib.eolian_constructor_is_construct_only.argtypes = (c_void_p,)
+lib.eolian_constructor_is_construct_only.restype = c_bool
+
# Eolian_Event ##############################################################
diff --git a/src/scripts/pyolian/test_eolian.py b/src/scripts/pyolian/test_eolian.py
old mode 100644
new mode 100755
index 657ec4a5c0..62e1cc8538
--- a/src/scripts/pyolian/test_eolian.py
+++ b/src/scripts/pyolian/test_eolian.py
@@ -419,6 +419,7 @@ class TestEolianFunction(object):
assert f.is_static is False
assert f.is_beta is False
assert f.is_constructor(cls) is False
+ assert f.is_construct_only(eolian.Eolian_Function_Type.PROP_SET) is False
# # #assert f.is_function_pointer == False # TODO broken somehow
assert len(list(f.getter_values)) == 1
assert len(list(f.getter_values)) == 1
@@ -514,6 +515,7 @@ class TestEolianConstructor(object):
assert isinstance(ctor, eolian.Constructor)
assert ctor.name == 'Efl.Ui.Win.win_name'
assert ctor.is_optional is False
+ assert ctor.is_construct_only is False
assert isinstance(ctor.class_, eolian.Class)
assert ctor.class_.name == 'Efl.Ui.Win'
assert isinstance(ctor.function, eolian.Function)
diff --git a/src/tests/eolian/data/construct_only.eo b/src/tests/eolian/data/construct_only.eo
new file mode 100644
index 0000000000..efee89cb61
--- /dev/null
+++ b/src/tests/eolian/data/construct_only.eo
@@ -0,0 +1,54 @@
+class @beta Construct_Only {
+ [[A class whose setup is only allowed during construction. @since 1.66]]
+ data: Construct_Only_Data;
+ methods {
+ @property name {
+ [[The name, fixed at construction.]]
+ set {
+ }
+ get {
+ }
+ values {
+ name: string; [[The name.]]
+ }
+ }
+ @property size {
+ [[The size, fixed at construction.]]
+ set {
+ return: bool (false); [[$true on success.]]
+ }
+ get {
+ }
+ values {
+ size: int; [[The size.]]
+ }
+ }
+ @property level {
+ [[A property that stays settable at any time.]]
+ set {
+ }
+ get {
+ }
+ values {
+ level: int; [[The level.]]
+ }
+ }
+ configure {
+ [[A method that is only allowed during construction.]]
+ params {
+ @in mode: int; [[The mode.]]
+ @in label: list<string> @move; [[The labels.]]
+ }
+ }
+ reset {
+ [[A parameterless method that is only allowed during construction.]]
+ }
+ }
+ constructors {
+ .name @construct_only;
+ .size @optional @construct_only;
+ .configure @construct_only @optional;
+ .reset @construct_only @optional;
+ Construct_Only.level @optional;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_child.eo b/src/tests/eolian/data/construct_only_child.eo
new file mode 100644
index 0000000000..25b141ac6d
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_child.eo
@@ -0,0 +1,19 @@
+class @beta Construct_Only_Child extends Construct_Only {
+ [[Inherits the restrictions of its parent. @since 1.66]]
+ methods {
+ @property own_size {
+ [[Restricted by this class itself.]]
+ set {
+ }
+ get {
+ }
+ values {
+ size: int; [[The size.]]
+ }
+ }
+ }
+ constructors {
+ Construct_Only.name;
+ .own_size @construct_only;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_child_ref.c b/src/tests/eolian/data/construct_only_child_ref.c
new file mode 100644
index 0000000000..a0892bd107
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_child_ref.c
@@ -0,0 +1,78 @@
+
+void _construct_only_child_own_size_set(Eo *obj, Construct_Only_Child_Data *pd, int size);
+
+
+static Eina_Error
+__eolian_construct_only_child_own_size_set_reflect(Eo *obj, Eina_Value val)
+{
+ Eina_Error r = 0; int cval;
+ if (efl_finalized_get(obj))
+ {
+ r = EPERM;
+ goto end;
+ }
+ if (!eina_value_int_convert(&val, &cval))
+ {
+ r = EINA_ERROR_VALUE_FAILED;
+ goto end;
+ }
+ construct_only_child_own_size_set(obj, cval);
+ end:
+ eina_value_flush(&val);
+ return r;
+}
+
+EAPI EAPI_WEAK EFL_VOID_FUNC_BODYV_CONSTRUCT_ONLY(construct_only_child_own_size_set, EFL_FUNC_CALL(size), int size);
+
+int _construct_only_child_own_size_get(const Eo *obj, Construct_Only_Child_Data *pd);
+
+
+static Eina_Value
+__eolian_construct_only_child_own_size_get_reflect(const Eo *obj)
+{
+ int val = construct_only_child_own_size_get(obj);
+ return eina_value_int_init(val);
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONST(construct_only_child_own_size_get, int, 0);
+
+static Eina_Bool
+_construct_only_child_class_initializer(Efl_Class *klass)
+{
+ const Efl_Object_Ops *opsp = NULL;
+
+ const Efl_Object_Property_Reflection_Ops *ropsp = NULL;
+
+#ifndef CONSTRUCT_ONLY_CHILD_EXTRA_OPS
+#define CONSTRUCT_ONLY_CHILD_EXTRA_OPS
+#endif
+
+ EFL_OPS_DEFINE(ops,
+ EFL_OBJECT_OP_FUNC(construct_only_child_own_size_set, _construct_only_child_own_size_set),
+ EFL_OBJECT_OP_FUNC(construct_only_child_own_size_get, _construct_only_child_own_size_get),
+ CONSTRUCT_ONLY_CHILD_EXTRA_OPS
+ );
+ opsp = &ops;
+
+ static const Efl_Object_Property_Reflection refl_table[] = {
+ {"own_size", __eolian_construct_only_child_own_size_set_reflect, __eolian_construct_only_child_own_size_get_reflect},
+ };
+ static const Efl_Object_Property_Reflection_Ops rops = {
+ refl_table, EINA_C_ARRAY_LENGTH(refl_table)
+ };
+ ropsp = &rops;
+
+ return efl_class_functions_set(klass, opsp, ropsp);
+}
+
+static const Efl_Class_Description _construct_only_child_class_desc = {
+ EO_VERSION,
+ "Construct_Only_Child",
+ EFL_CLASS_TYPE_REGULAR,
+ sizeof(Construct_Only_Child_Data),
+ _construct_only_child_class_initializer,
+ NULL,
+ NULL
+};
+
+EFL_DEFINE_CLASS(construct_only_child_class_get, &_construct_only_child_class_desc, CONSTRUCT_ONLY_CLASS, NULL);
diff --git a/src/tests/eolian/data/construct_only_const.eo b/src/tests/eolian/data/construct_only_const.eo
new file mode 100644
index 0000000000..48058c0c34
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_const.eo
@@ -0,0 +1,11 @@
+class @beta Construct_Only_Const {
+ [[A const method cannot be construct only. @since 1.66]]
+ methods {
+ peek @const {
+ [[Does not modify the object.]]
+ }
+ }
+ constructors {
+ .peek @construct_only;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_double.eo b/src/tests/eolian/data/construct_only_double.eo
new file mode 100644
index 0000000000..e6dc3eb16b
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_double.eo
@@ -0,0 +1,17 @@
+class @beta Construct_Only_Double {
+ [[The same qualifier twice is refused. @since 1.66]]
+ methods {
+ @property name {
+ set {
+ }
+ get {
+ }
+ values {
+ name: string; [[The name.]]
+ }
+ }
+ }
+ constructors {
+ .name @construct_only @construct_only;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_double_opt.eo b/src/tests/eolian/data/construct_only_double_opt.eo
new file mode 100644
index 0000000000..0fde58a20e
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_double_opt.eo
@@ -0,0 +1,17 @@
+class @beta Construct_Only_Double_Opt {
+ [[The same qualifier twice is refused. @since 1.66]]
+ methods {
+ @property name {
+ set {
+ }
+ get {
+ }
+ values {
+ name: string; [[The name.]]
+ }
+ }
+ }
+ constructors {
+ .name @optional @construct_only @optional;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_foreign.eo b/src/tests/eolian/data/construct_only_foreign.eo
new file mode 100644
index 0000000000..9f18ed537d
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_foreign.eo
@@ -0,0 +1,6 @@
+class @beta Construct_Only_Foreign extends Construct_Only {
+ [[Cannot restrict what its parent declares. @since 1.66]]
+ constructors {
+ Construct_Only.level @construct_only;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_noset.eo b/src/tests/eolian/data/construct_only_noset.eo
new file mode 100644
index 0000000000..8048422515
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_noset.eo
@@ -0,0 +1,15 @@
+class @beta Construct_Only_Noset {
+ [[A getter only property cannot be construct only. @since 1.66]]
+ methods {
+ @property ro {
+ get {
+ }
+ values {
+ v: int; [[A value.]]
+ }
+ }
+ }
+ constructors {
+ .ro @construct_only;
+ }
+}
diff --git a/src/tests/eolian/data/construct_only_ref.c b/src/tests/eolian/data/construct_only_ref.c
new file mode 100644
index 0000000000..3de00f6a3e
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_ref.c
@@ -0,0 +1,170 @@
+
+void _construct_only_name_set(Eo *obj, Construct_Only_Data *pd, const char *name);
+
+
+static Eina_Error
+__eolian_construct_only_name_set_reflect(Eo *obj, Eina_Value val)
+{
+ Eina_Error r = 0; const char *cval;
+ if (efl_finalized_get(obj))
+ {
+ r = EPERM;
+ goto end;
+ }
+ if (!eina_value_string_convert(&val, &cval))
+ {
+ r = EINA_ERROR_VALUE_FAILED;
+ goto end;
+ }
+ construct_only_name_set(obj, cval);
+ end:
+ eina_value_flush(&val);
+ return r;
+}
+
+EAPI EAPI_WEAK EFL_VOID_FUNC_BODYV_CONSTRUCT_ONLY(construct_only_name_set, EFL_FUNC_CALL(name), const char *name);
+
+const char *_construct_only_name_get(const Eo *obj, Construct_Only_Data *pd);
+
+
+static Eina_Value
+__eolian_construct_only_name_get_reflect(const Eo *obj)
+{
+ const char *val = construct_only_name_get(obj);
+ return eina_value_string_init(val);
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONST(construct_only_name_get, const char *, NULL);
+
+Eina_Bool _construct_only_size_set(Eo *obj, Construct_Only_Data *pd, int size);
+
+
+static Eina_Error
+__eolian_construct_only_size_set_reflect(Eo *obj, Eina_Value val)
+{
+ Eina_Error r = 0; int cval;
+ if (efl_finalized_get(obj))
+ {
+ r = EPERM;
+ goto end;
+ }
+ if (!eina_value_int_convert(&val, &cval))
+ {
+ r = EINA_ERROR_VALUE_FAILED;
+ goto end;
+ }
+ construct_only_size_set(obj, cval);
+ end:
+ eina_value_flush(&val);
+ return r;
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODYV_CONSTRUCT_ONLY(construct_only_size_set, Eina_Bool, EINA_FALSE /* false */, EFL_FUNC_CALL(size), int size);
+
+int _construct_only_size_get(const Eo *obj, Construct_Only_Data *pd);
+
+
+static Eina_Value
+__eolian_construct_only_size_get_reflect(const Eo *obj)
+{
+ int val = construct_only_size_get(obj);
+ return eina_value_int_init(val);
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONST(construct_only_size_get, int, 0);
+
+void _construct_only_level_set(Eo *obj, Construct_Only_Data *pd, int level);
+
+
+static Eina_Error
+__eolian_construct_only_level_set_reflect(Eo *obj, Eina_Value val)
+{
+ Eina_Error r = 0; int cval;
+ if (!eina_value_int_convert(&val, &cval))
+ {
+ r = EINA_ERROR_VALUE_FAILED;
+ goto end;
+ }
+ construct_only_level_set(obj, cval);
+ end:
+ eina_value_flush(&val);
+ return r;
+}
+
+EAPI EAPI_WEAK EFL_VOID_FUNC_BODYV(construct_only_level_set, EFL_FUNC_CALL(level), int level);
+
+int _construct_only_level_get(const Eo *obj, Construct_Only_Data *pd);
+
+
+static Eina_Value
+__eolian_construct_only_level_get_reflect(const Eo *obj)
+{
+ int val = construct_only_level_get(obj);
+ return eina_value_int_init(val);
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONST(construct_only_level_get, int, 0);
+
+void _construct_only_configure(Eo *obj, Construct_Only_Data *pd, int mode, Eina_List *label);
+
+static void
+_construct_only_configure_ownership_fallback(int mode, Eina_List *label)
+{
+ (void)mode;
+ eina_list_free(label);
+}
+
+EAPI EAPI_WEAK EFL_VOID_FUNC_BODYV_CONSTRUCT_ONLY_FALLBACK(construct_only_configure, _construct_only_configure_ownership_fallback(mode, label);, EFL_FUNC_CALL(mode, label), int mode, Eina_List *label);
+
+void _construct_only_reset(Eo *obj, Construct_Only_Data *pd);
+
+EAPI EAPI_WEAK EFL_VOID_FUNC_BODY_CONSTRUCT_ONLY(construct_only_reset);
+
+static Eina_Bool
+_construct_only_class_initializer(Efl_Class *klass)
+{
+ const Efl_Object_Ops *opsp = NULL;
+
+ const Efl_Object_Property_Reflection_Ops *ropsp = NULL;
+
+#ifndef CONSTRUCT_ONLY_EXTRA_OPS
+#define CONSTRUCT_ONLY_EXTRA_OPS
+#endif
+
+ EFL_OPS_DEFINE(ops,
+ EFL_OBJECT_OP_FUNC(construct_only_name_set, _construct_only_name_set),
+ EFL_OBJECT_OP_FUNC(construct_only_name_get, _construct_only_name_get),
+ EFL_OBJECT_OP_FUNC(construct_only_size_set, _construct_only_size_set),
+ EFL_OBJECT_OP_FUNC(construct_only_size_get, _construct_only_size_get),
+ EFL_OBJECT_OP_FUNC(construct_only_level_set, _construct_only_level_set),
+ EFL_OBJECT_OP_FUNC(construct_only_level_get, _construct_only_level_get),
+ EFL_OBJECT_OP_FUNC(construct_only_configure, _construct_only_configure),
+ EFL_OBJECT_OP_FUNC(construct_only_reset, _construct_only_reset),
+ CONSTRUCT_ONLY_EXTRA_OPS
+ );
+ opsp = &ops;
+
+ static const Efl_Object_Property_Reflection refl_table[] = {
+ {"name", __eolian_construct_only_name_set_reflect, __eolian_construct_only_name_get_reflect},
+ {"size", __eolian_construct_only_size_set_reflect, __eolian_construct_only_size_get_reflect},
+ {"level", __eolian_construct_only_level_set_reflect, __eolian_construct_only_level_get_reflect},
+ };
+ static const Efl_Object_Property_Reflection_Ops rops = {
+ refl_table, EINA_C_ARRAY_LENGTH(refl_table)
+ };
+ ropsp = &rops;
+
+ return efl_class_functions_set(klass, opsp, ropsp);
+}
+
+static const Efl_Class_Description _construct_only_class_desc = {
+ EO_VERSION,
+ "Construct_Only",
+ EFL_CLASS_TYPE_REGULAR,
+ sizeof(Construct_Only_Data),
+ _construct_only_class_initializer,
+ NULL,
+ NULL
+};
+
+EFL_DEFINE_CLASS(construct_only_class_get, &_construct_only_class_desc, NULL, NULL);
diff --git a/src/tests/eolian/data/construct_only_ref.h b/src/tests/eolian/data/construct_only_ref.h
new file mode 100644
index 0000000000..1cf9f78024
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_ref.h
@@ -0,0 +1,140 @@
+#ifndef _EOLIAN_CONSTRUCT_ONLY_EO_H_
+#define _EOLIAN_CONSTRUCT_ONLY_EO_H_
+
+#ifndef _CONSTRUCT_ONLY_EO_CLASS_TYPE
+#define _CONSTRUCT_ONLY_EO_CLASS_TYPE
+
+#ifndef _CONSTRUCT_ONLY_EO_CLASS_TYPE_FWD
+#define _CONSTRUCT_ONLY_EO_CLASS_TYPE_FWD
+typedef Eo Construct_Only;
+#endif
+
+#endif
+
+#ifndef _CONSTRUCT_ONLY_EO_TYPES
+#define _CONSTRUCT_ONLY_EO_TYPES
+
+
+#endif
+#ifdef EFL_BETA_API_SUPPORT
+/** A class whose setup is only allowed during construction.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+#define CONSTRUCT_ONLY_CLASS construct_only_class_get()
+
+EAPI EAPI_WEAK const Efl_Class *construct_only_class_get(void) EINA_CONST;
+
+/**
+ * @brief The name, fixed at construction.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ * @param[in] name The name.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK void construct_only_name_set(Eo *obj, const char *name);
+
+/**
+ * @brief The name, fixed at construction.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The name.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK const char *construct_only_name_get(const Eo *obj);
+
+/**
+ * @brief The size, fixed at construction.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ * @param[in] size The size.
+ *
+ * @return @c true on success.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK Eina_Bool construct_only_size_set(Eo *obj, int size);
+
+/**
+ * @brief The size, fixed at construction.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The size.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK int construct_only_size_get(const Eo *obj);
+
+/**
+ * @brief A property that stays settable at any time.
+ *
+ * @param[in] obj The object.
+ * @param[in] level The level.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK void construct_only_level_set(Eo *obj, int level);
+
+/**
+ * @brief A property that stays settable at any time.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The level.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK int construct_only_level_get(const Eo *obj);
+
+/**
+ * @brief A method that is only allowed during construction.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ * @param[in] mode The mode.
+ * @param[in] label The labels.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK void construct_only_configure(Eo *obj, int mode, Eina_List *label EFL_TRANSFER_OWNERSHIP);
+
+/**
+ * @brief A parameterless method that is only allowed during construction.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only
+ */
+EAPI EAPI_WEAK void construct_only_reset(Eo *obj);
+#endif /* EFL_BETA_API_SUPPORT */
+
+#endif
diff --git a/src/tests/eolian/data/construct_only_static.eo b/src/tests/eolian/data/construct_only_static.eo
new file mode 100644
index 0000000000..8f143bc98c
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_static.eo
@@ -0,0 +1,17 @@
+class @beta Construct_Only_Static {
+ [[A static function cannot be construct only. @since 1.66]]
+ methods {
+ @property sprop @static {
+ set {
+ }
+ get {
+ }
+ values {
+ v: int; [[A value.]]
+ }
+ }
+ }
+ constructors {
+ .sprop @construct_only;
+ }
+}
diff --git a/src/tests/eolian/eolian_generation.c b/src/tests/eolian/eolian_generation.c
index 4ed1ab48ff..73f557d327 100644
--- a/src/tests/eolian/eolian_generation.c
+++ b/src/tests/eolian/eolian_generation.c
@@ -156,6 +156,28 @@ EFL_START_TEST(eolian_deprecated_source_generation)
}
EFL_END_TEST
+/* A construct only function is guarded in the .eo.c and says so in the .eo.h */
+EFL_START_TEST(eolian_construct_only_generation)
+{
+ char output_filepath[PATH_MAX + 128] = "";
+ snprintf(output_filepath, PATH_MAX, "%s/eolian_construct_only",
+ eina_environment_tmp_get());
+ _remove_ref(output_filepath, "eo.c");
+ _remove_ref(output_filepath, "eo.h");
+ fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/construct_only.eo", "-gc", output_filepath));
+ fail_if(!_files_compare(TESTS_SRC_DIR"/data/construct_only_ref.c", output_filepath, "eo.c"));
+ fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/construct_only.eo", "-gh", output_filepath));
+ fail_if(!_files_compare(TESTS_SRC_DIR"/data/construct_only_ref.h", output_filepath, "eo.h"));
+
+ /* inherited restriction is the parent's own, only the new one is guarded */
+ snprintf(output_filepath, PATH_MAX, "%s/eolian_construct_only_child",
+ eina_environment_tmp_get());
+ _remove_ref(output_filepath, "eo.c");
+ fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/construct_only_child.eo", "-gc", output_filepath));
+ fail_if(!_files_compare(TESTS_SRC_DIR"/data/construct_only_child_ref.c", output_filepath, "eo.c"));
+}
+EFL_END_TEST
+
EFL_START_TEST(eolian_default_values_generation)
{
char output_filepath[PATH_MAX + 128] = "";
@@ -279,4 +301,5 @@ void eolian_generation_test(TCase *tc)
tcase_add_test(tc, owning);
tcase_add_test(tc, eolian_styles_generation);
tcase_add_test(tc, eolian_deprecated_source_generation);
+ tcase_add_test(tc, eolian_construct_only_generation);
}
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index db6e5a98e1..12d5ce4e59 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -1581,6 +1581,118 @@ EFL_START_TEST(eolian_deprecated)
}
EFL_END_TEST
+/* @construct_only is a constructor qualifier, in any order next to
+ @optional. The function is restricted for the class declaring it and the
+ classes inheriting from it, but only the setter of a property. */
+EFL_START_TEST(eolian_construct_only)
+{
+ const Eolian_Unit *unit;
+ const Eolian_Class *cls, *child;
+ const Eolian_Constructor *ctor;
+ const Eolian_Function *fid;
+ Eina_Iterator *iter;
+ Eina_Bool expected_opt[] = { EINA_FALSE, EINA_TRUE, EINA_TRUE, EINA_TRUE, EINA_TRUE };
+ Eina_Bool expected_co[] = { EINA_TRUE, EINA_TRUE, EINA_TRUE, EINA_TRUE, EINA_FALSE };
+ int i = 0;
+
+ Eolian_State *eos = eolian_state_new();
+
+ fail_if(!eolian_state_directory_add(eos, TESTS_SRC_DIR"/data"));
+ fail_if(!(unit = eolian_state_file_parse(eos, "construct_only_child.eo")));
+ fail_if(!(cls = eolian_unit_class_by_name_get(unit, "Construct_Only")));
+ fail_if(!(child = eolian_unit_class_by_name_get(unit, "Construct_Only_Child")));
+
+ /* both qualifier orders, and the full name form without the qualifier */
+ fail_if(!(iter = eolian_class_constructors_get(cls)));
+ EINA_ITERATOR_FOREACH(iter, ctor)
+ {
+ ck_assert_int_lt(i, 5);
+ ck_assert_int_eq(eolian_constructor_is_optional(ctor), expected_opt[i]);
+ ck_assert_int_eq(eolian_constructor_is_construct_only(ctor), expected_co[i]);
+ i++;
+ }
+ eina_iterator_free(iter);
+ ck_assert_int_eq(i, 5);
+
+ /* a property is restricted through its setter only */
+ fail_if(!(fid = eolian_class_function_by_name_get(cls, "name", EOLIAN_PROP_SET)));
+ fail_if(!eolian_function_is_construct_only(fid, EOLIAN_PROP_SET));
+ fail_if(!eolian_function_is_construct_only(fid, EOLIAN_PROPERTY));
+ fail_if(eolian_function_is_construct_only(fid, EOLIAN_PROP_GET));
+ fail_if(eolian_function_is_construct_only(fid, EOLIAN_UNRESOLVED));
+ fail_if(!(fid = eolian_class_function_by_name_get(cls, "size", EOLIAN_PROPERTY)));
+ fail_if(!eolian_function_is_construct_only(fid, EOLIAN_PROP_SET));
+ fail_if(!(fid = eolian_class_function_by_name_get(cls, "configure", EOLIAN_METHOD)));
+ fail_if(!eolian_function_is_construct_only(fid, EOLIAN_METHOD));
+ fail_if(!(fid = eolian_class_function_by_name_get(cls, "reset", EOLIAN_METHOD)));
+ fail_if(!eolian_function_is_construct_only(fid, EOLIAN_METHOD));
+ fail_if(!(fid = eolian_class_function_by_name_get(cls, "level", EOLIAN_PROPERTY)));
+ fail_if(eolian_function_is_construct_only(fid, EOLIAN_PROP_SET));
+ fail_if(eolian_function_is_construct_only(fid, EOLIAN_PROPERTY));
+
+ /* a property of the function: it is the same one the child inherits,
+ and the child's own is marked by the child */
+ fail_if(!(fid = eolian_class_function_by_name_get(child, "own_size", EOLIAN_PROP_SET)));
+ fail_if(!eolian_function_is_construct_only(fid, EOLIAN_PROP_SET));
+ fail_if(eolian_function_is_construct_only(fid, EOLIAN_PROP_GET));
+
+ /* the child lists an inherited function without the qualifier, which
+ does not lift the restriction its parent declared */
+ fail_if(!(iter = eolian_class_constructors_get(child)));
+ fail_if(!eina_iterator_next(iter, (void **)&ctor));
+ fail_if(eolian_constructor_is_construct_only(ctor));
+ fail_if(!eina_iterator_next(iter, (void **)&ctor));
+ fail_if(!eolian_constructor_is_construct_only(ctor));
+ eina_iterator_free(iter);
+
+ /* NULL inputs */
+ fail_if(eolian_function_is_construct_only(NULL, EOLIAN_PROP_SET));
+ fail_if(eolian_constructor_is_construct_only(NULL));
+
+ eolian_state_free(eos);
+}
+EFL_END_TEST
+
+static void
+_construct_only_error_cb(const Eolian_Object *obj EINA_UNUSED, const char *msg, void *data)
+{
+ Eina_Strbuf *sb = data;
+ eina_strbuf_append(sb, msg);
+ eina_strbuf_append_char(sb, '\n');
+}
+
+/* Each file is valid but for its @construct_only, and is refused for that
+ reason only: the message is checked. */
+EFL_START_TEST(eolian_construct_only_invalid)
+{
+ static const struct { const char *file, *msg; } bad[] = {
+ { "construct_only_foreign.eo", "is declared by 'Construct_Only', not by 'Construct_Only_Foreign'" },
+ { "construct_only_noset.eo", "it has no setter" },
+ { "construct_only_static.eo", "it is static or const" },
+ { "construct_only_const.eo", "it is static or const" },
+ { "construct_only_double.eo", "double construct_only qualifier" },
+ { "construct_only_double_opt.eo", "double optional qualifier" },
+ };
+ unsigned int i;
+
+ for (i = 0; i < EINA_C_ARRAY_LENGTH(bad); i++)
+ {
+ Eina_Strbuf *sb = eina_strbuf_new();
+ Eolian_State *eos = eolian_state_new();
+
+ eolian_state_error_cb_set(eos, _construct_only_error_cb);
+ eolian_state_error_data_set(eos, sb);
+ fail_if(!eolian_state_directory_add(eos, TESTS_SRC_DIR"/data"));
+ fail_if(eolian_state_file_parse(eos, bad[i].file));
+ ck_assert_msg(!!strstr(eina_strbuf_string_get(sb), bad[i].msg),
+ "%s: unexpected error '%s'", bad[i].file, eina_strbuf_string_get(sb));
+
+ eolian_state_free(eos);
+ eina_strbuf_free(sb);
+ }
+}
+EFL_END_TEST
+
EFL_START_TEST(eolian_mixins_require)
{
const Eolian_Unit *unit;
@@ -1838,6 +1950,8 @@ void eolian_parsing_test(TCase *tc)
tcase_add_test(tc, eolian_parts);
tcase_add_test(tc, eolian_styles);
tcase_add_test(tc, eolian_deprecated);
+ tcase_add_test(tc, eolian_construct_only);
+ tcase_add_test(tc, eolian_construct_only_invalid);
tcase_add_test(tc, eolian_mixins_require);
tcase_add_test(tc, eolian_class_requires_classes);
tcase_add_test(tc, eolian_class_unimpl);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.