File: fncall.h

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (112 lines) | stat: -rw-r--r-- 3,472 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
  Copyright 2024 Northern.tech AS

  This file is part of CFEngine 3 - written and maintained by Northern.tech AS.

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; version 3.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

  To the extent this program is licensed as part of the Enterprise
  versions of CFEngine, the applicable Commercial Open Source License
  (COSL) may apply to this file if you as a licensee so wish it. See
  included file COSL.txt.
*/

#ifndef CFENGINE_FNCALL_H
#define CFENGINE_FNCALL_H

#include <cf3.defs.h>

struct FnCall_
{
    char *name;
    Rlist *args;

    const Promise *caller;
};

typedef enum FnCallStatus
{
    FNCALL_SUCCESS,
    FNCALL_FAILURE
} FnCallStatus;

typedef struct
{
    FnCallStatus status;
    Rval rval;
} FnCallResult;

typedef struct
{
    const char *pattern;
    DataType dtype;
    const char *description;
} FnCallArg;

typedef enum
{
    FNCALL_OPTION_NONE = 0,
    // Functions with variable arguments don't require a fixed number
    // of arguments.
    FNCALL_OPTION_VARARG = 1 << 0,
    // Cached functions are evaluated once per run (memoized). The
    // hash key is the function name and all the arguments.
    FNCALL_OPTION_CACHED = 1 << 1,
    // Collecting functions take a variable reference OR can accept a
    // nested function call. Either way, those parameters are
    // collected into a data container.
    FNCALL_OPTION_COLLECTING = 1 << 2,
    // Delayed-evaluation functions will evaluate their arguments directly,
    // so they can do things like maplist(canonify($(this)), mylist)
    FNCALL_OPTION_DELAYED_EVALUATION = 1 << 3,
    // Unsafe functions (with side effects) that should not be evaluated in
    // simulate mode(s).
    FNCALL_OPTION_UNSAFE = 1 << 4,
} FnCallOption;

typedef struct
{
    const char *name;
    DataType dtype;
    const FnCallArg *args;
    FnCallResult (*impl)(EvalContext *, const Policy *, const FnCall *, const Rlist *);
    const char *description;
    FnCallOption options;
    FnCallCategory category;
    SyntaxStatus status;
} FnCallType;

extern const FnCallType CF_FNCALL_TYPES[];

bool FnCallIsBuiltIn(Rval rval);

FnCall *FnCallNew(const char *name, Rlist *args);
FnCall *FnCallCopy(const FnCall *f);
FnCall *FnCallCopyRewriter(const FnCall *f, JsonElement *map);
void FnCallDestroy(FnCall *fp);
unsigned FnCallHash(const FnCall *fp, unsigned seed);
void FnCallWrite(Writer *writer, const FnCall *call);


FnCallResult FnCallEvaluate(EvalContext *ctx, const Policy *policy, FnCall *fp, const Promise *caller);

const FnCallType *FnCallTypeGet(const char *name);

FnCall *ExpandFnCall(const EvalContext *ctx, const char *ns, const char *scope, const FnCall *f);
Rlist *NewExpArgs(EvalContext *ctx, const Policy *policy, const FnCall *fp, const FnCallType *fp_type);

// TODO: should probably demolish this eventually
void FnCallShow(FILE *fout, const char *prefix, const FnCall *fp, const Rlist *args);

#endif