Skip to content

Commit

Permalink
mutation gone
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Jan 1, 2025
1 parent 0db9e90 commit 4e927bb
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 326 deletions.
14 changes: 14 additions & 0 deletions include/libfyaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -9901,6 +9901,20 @@ struct fy_document *
fy_type_info_get_yaml_annotation(const struct fy_type_info *ti)
FY_EXPORT;

/**
* fy_type_info_get_yaml_comment() - Get the yaml annotation of this type as string
*
* Retrieve a document containing the yaml keyword annotations of this type as a string
*
* @ti: The type info
*
* Returns:
* The yaml comment or NULL
*/
const char *
fy_type_info_get_yaml_comment(const struct fy_type_info *ti)
FY_EXPORT;

const char *
fy_type_info_get_yaml_name(const struct fy_type_info *ti)
FY_EXPORT;
Expand Down
1 change: 1 addition & 0 deletions src/reflection/fy-reflection-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ struct fy_decl {
struct fy_document *fyd_yaml; /* the YAML keyworded */
bool fyd_yaml_parsed;
char *yaml_comment;
bool yaml_comment_generated;

union {
struct {
Expand Down
36 changes: 24 additions & 12 deletions src/reflection/fy-reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,25 +1312,20 @@ struct fy_document *fy_decl_get_yaml_annotation(struct fy_decl *decl)
const char *fy_decl_get_yaml_comment(struct fy_decl *decl)
{
struct fy_document *fyd;
char *s, *e;

if (!decl)
return NULL;

if (decl->yaml_comment_generated)
return decl->yaml_comment;

if (!decl->yaml_comment) {
fyd = fy_decl_get_yaml_annotation(decl);
if (fyd) {
decl->yaml_comment = fy_emit_document_to_string(fyd, FYECF_MODE_FLOW_ONELINE);
if (decl->yaml_comment) {
/* trim newlines at the end */
s = decl->yaml_comment;
e = s + strlen(s);
while (s < e && e[-1] == '\n')
*--e = '\0';
}
}
if (fyd)
decl->yaml_comment = fy_emit_document_to_string(fyd,
FYECF_MODE_FLOW_ONELINE | FYECF_WIDTH_INF | FYECF_NO_ENDING_NEWLINE);
}

decl->yaml_comment_generated = true;
return decl->yaml_comment;
}

Expand Down Expand Up @@ -3323,6 +3318,23 @@ struct fy_document *fy_type_info_get_yaml_annotation(const struct fy_type_info *
return fy_decl_get_yaml_annotation(decl);
}

const char *fy_type_info_get_yaml_comment(const struct fy_type_info *ti)
{
struct fy_type_info_wrapper *tiw;
struct fy_decl *decl;

tiw = fy_type_info_wrapper_from_info(ti);
if (!tiw)
return NULL;

decl = tiw->decl;
if (!decl)
return NULL;

return fy_decl_get_yaml_comment(decl);
}


struct fy_document *fy_field_info_get_yaml_annotation(const struct fy_field_info *fi)
{
return fy_decl_get_yaml_annotation(fy_decl_from_field_info(fi));
Expand Down
Loading

0 comments on commit 4e927bb

Please sign in to comment.