Browse Source

Comment & doxygen documentation enhancement

Yann Weber 1 year ago
parent
commit
077821fc3f
19 changed files with 665 additions and 158 deletions
  1. 7
    13
      Doxyfile.mk
  2. 13
    4
      config.h
  3. 22
    1
      python_const.c
  4. 35
    3
      python_const.h
  5. 33
    3
      python_if.c
  6. 100
    25
      python_if.h
  7. 2
    0
      python_pyrpn.c
  8. 22
    15
      python_pyrpn.h
  9. 23
    1
      python_rpnexpr.c
  10. 75
    30
      python_rpnexpr.h
  11. 20
    1
      python_rpntoken.c
  12. 142
    12
      python_rpntoken.h
  13. 22
    5
      rpn_if.h
  14. 53
    20
      rpn_if_default.h
  15. 6
    0
      rpn_ifs.h
  16. 9
    8
      rpn_jit.h
  17. 5
    1
      rpn_lib.h
  18. 64
    12
      rpn_mutate.h
  19. 12
    4
      rpn_parse.h

+ 7
- 13
Doxyfile.mk View File

@@ -46,13 +46,13 @@ INLINE_GROUPED_CLASSES = NO
46 46
 INLINE_SIMPLE_STRUCTS  = NO
47 47
 TYPEDEF_HIDES_STRUCT   = NO
48 48
 LOOKUP_CACHE_SIZE      = 0
49
-EXTRACT_ALL            = YES
50
-EXTRACT_PRIVATE        = NO
51
-EXTRACT_PACKAGE        = NO
52
-EXTRACT_STATIC         = NO
49
+EXTRACT_ALL            = NO
50
+EXTRACT_PRIVATE        = YES
51
+EXTRACT_PACKAGE        = YES
52
+EXTRACT_STATIC         = YES
53 53
 EXTRACT_LOCAL_CLASSES  = YES
54
-EXTRACT_LOCAL_METHODS  = NO
55
-EXTRACT_ANON_NSPACES   = NO
54
+EXTRACT_LOCAL_METHODS  = YES
55
+EXTRACT_ANON_NSPACES   = YES
56 56
 HIDE_UNDOC_MEMBERS     = NO
57 57
 HIDE_UNDOC_CLASSES     = NO
58 58
 HIDE_FRIEND_COMPOUNDS  = NO
@@ -83,7 +83,7 @@ QUIET                  = NO
83 83
 WARNINGS               = YES
84 84
 WARN_IF_UNDOCUMENTED   = YES
85 85
 WARN_IF_DOC_ERROR      = YES
86
-WARN_NO_PARAMDOC       = NO
86
+WARN_NO_PARAMDOC       = YES
87 87
 WARN_AS_ERROR          = NO
88 88
 WARN_FORMAT            = "$file:$line: $text"
89 89
 INPUT                  = ./
@@ -151,7 +151,6 @@ USE_HTAGS              = NO
151 151
 VERBATIM_HEADERS       = YES
152 152
 CLANG_ASSISTED_PARSING = NO
153 153
 ALPHABETICAL_INDEX     = YES
154
-COLS_IN_ALPHA_INDEX    = 5
155 154
 GENERATE_HTML          = YES
156 155
 HTML_OUTPUT            = html
157 156
 HTML_FILE_EXTENSION    = .html
@@ -199,14 +198,12 @@ PDF_HYPERLINKS         = YES
199 198
 USE_PDFLATEX           = YES
200 199
 LATEX_BATCHMODE        = NO
201 200
 LATEX_HIDE_INDICES     = NO
202
-LATEX_SOURCE_CODE      = NO
203 201
 LATEX_BIB_STYLE        = plain
204 202
 LATEX_TIMESTAMP        = NO
205 203
 GENERATE_RTF           = NO
206 204
 RTF_OUTPUT             = rtf
207 205
 COMPACT_RTF            = NO
208 206
 RTF_HYPERLINKS         = NO
209
-RTF_SOURCE_CODE        = NO
210 207
 GENERATE_MAN           = YES
211 208
 MAN_OUTPUT             = man
212 209
 MAN_EXTENSION          = .3
@@ -216,7 +213,6 @@ XML_OUTPUT             = xml
216 213
 XML_PROGRAMLISTING     = YES
217 214
 GENERATE_DOCBOOK       = NO
218 215
 DOCBOOK_OUTPUT         = docbook
219
-DOCBOOK_PROGRAMLISTING = NO
220 216
 GENERATE_AUTOGEN_DEF   = NO
221 217
 GENERATE_PERLMOD       = NO
222 218
 PERLMOD_LATEX          = NO
@@ -229,8 +225,6 @@ SKIP_FUNCTION_MACROS   = YES
229 225
 ALLEXTERNALS           = NO
230 226
 EXTERNAL_GROUPS        = YES
231 227
 EXTERNAL_PAGES         = YES
232
-PERL_PATH              = /usr/bin/perl
233
-CLASS_DIAGRAMS         = YES
234 228
 HIDE_UNDOC_RELATIONS   = YES
235 229
 HAVE_DOT               = YES
236 230
 DOT_NUM_THREADS        = 0

+ 13
- 4
config.h View File

@@ -19,12 +19,21 @@
19 19
 #ifndef __RPN_CONFIG__
20 20
 #define __RPN_CONFIG__
21 21
 
22
-#define _GNU_SOURCE
23
-
22
+/**@file config.h
23
+ * @brief Global definition for all C files
24
+ */
24 25
 
25
-#define PYRPN_doc_meth(NAME, header, docstring) PyDoc_STRVAR(NAME ## _doc,\
26
-		header "\n--\n\n" docstring);
26
+/**@brief The programms is under GPL */
27
+#define _GNU_SOURCE
27 28
 
29
+/**@brief Allow fancy method declaration by indicating arguments list
30
+ * explicitly
31
+ * @param name char* The method name
32
+ * @param callback The C function to call
33
+ * @param flags int Python flags for method call options
34
+ * @param header char* List of arguments
35
+ * @param docstring char* The method documentation
36
+ */
28 37
 #define PYRPN_method(name, callback, flags, header, docstring) \
29 38
 {name, (PyCFunction)callback, flags, \
30 39
 	PyDoc_STR(name "("header ")\n--\n\n" docstring)}

+ 22
- 1
python_const.c View File

@@ -1,4 +1,11 @@
1 1
 #include "python_const.h"
2
+/**@file python_const.c
3
+ * @brief pyrpn.const code
4
+ * @ingroup python_ext
5
+ * @ingroup pymod_pyrpn_RPNIterParams
6
+ * @ingroup pymod_pyrpn_RPNTokenTypes
7
+ * @ingroup pymod_pyrpn_RPNMutationParams
8
+ */
2 9
 
3 10
 /** @todo implement GC with m_clear */
4 11
 PyModuleDef rpnconstmodule = {
@@ -13,6 +20,8 @@ PyModuleDef rpnconstmodule = {
13 20
 };
14 21
 
15 22
 /* Various named tuple definition, instanciated in python_rpnexpr module init */
23
+/**@brief @ref pymod_pyrpn_RPNIterParams fields definition
24
+ * @ingroup pymod_pyrpn_RPNIterParams */
16 25
 static PyStructSequence_Field params_fields[] = {
17 26
 	{
18 27
 		.name = "argc",
@@ -43,6 +52,8 @@ PyStructSequence_Desc rpnif_params_desc = {
43 52
 };
44 53
 PyTypeObject rpnif_params_SeqDesc;
45 54
 
55
+/**@brief @ref pymod_pyrpn_RPNTokenTypes field definition
56
+ * @ingroup pymod_pyrpn_RPNTokenTypes */
46 57
 static PyStructSequence_Field token_types_fields[] = {
47 58
 	{	.name = "op",
48 59
 		.doc = "Operation",
@@ -62,6 +73,8 @@ PyStructSequence_Desc rpn_token_types_desc = {
62 73
 };
63 74
 PyTypeObject rpn_token_types_SeqDesc;
64 75
 
76
+/**@brief @ref pymod_pyrpn_RPNMutationParams field definition
77
+ * @ingroup pymod_pyrpn_RPNMutationParams */
65 78
 static PyStructSequence_Field mutation_params_fields[] = {
66 79
 	{	.name = "minimum_length",
67 80
 		.doc = "Expression minimum length",
@@ -106,6 +119,12 @@ rpn_mutation_params_t rpn_mutation_params_default = {
106 119
 	.w_mut_elt = {1.0,1.0,1.0},
107 120
 };
108 121
 
122
+/**@brief Adds a constant to @ref pymod_pyrpn_const module
123
+ * @param mod The @ref pymod_pyrpn_const module
124
+ * @param name The constant's name
125
+ * @param value The constant's value
126
+ * @return 0 or -1 on error
127
+ */
109 128
 int Py_rpnconst_add(PyObject* mod, const char* name, int value)
110 129
 {
111 130
 	PyObject *val;
@@ -119,7 +138,9 @@ int Py_rpnconst_add(PyObject* mod, const char* name, int value)
119 138
 	return 0;
120 139
 }
121 140
 
122
-/** @todo rename this function ! (bad prefix) */
141
+/**@todo rename this function ! (bad prefix)
142
+ * @brief Module initialisation function
143
+ * @return The initialized module */
123 144
 PyObject *Py_rpnconst_init(void)
124 145
 {
125 146
 	PyObject *mod;

+ 35
- 3
python_const.h View File

@@ -30,24 +30,56 @@
30 30
 #include "rpn_mutate.h"
31 31
 #include "rpn_if_default.h"
32 32
 
33
+/**@file python_const.h
34
+ * @brief Python pyrpn.const module headers
35
+ * @ingroup python_ext
36
+ * @ingroup pymod_pyrpn_const
37
+ */
38
+
39
+/**@defgroup pymod_pyrpn_const module pyrpn.const
40
+ * @brief A module containing constant values
41
+ *
42
+ * Constants values are @ref ifs_if_default_posflag
43
+ * and @ref ifs_if_default_resflag
44
+ * @ingroup pymod_pyrpn
45
+ */
46
+
33 47
 /**@brief pyrpn.const module specs
34
- * @ingroup python_module */
48
+ * @ingroup pymod_pyrpn */
35 49
 extern PyModuleDef rpnconstmodule;
36 50
 
37
-/**@brief A single instance of this object is used for parameters representation */
51
+/**@defgroup pymod_pyrpn_RPNIterParams pyrpn.RPNIterParams
52
+ * @brief namedtuple representing @ref pymod_pyrpn_RPNExprIter parameters 
53
+ * @ingroup pymod_pyrpn */
54
+/**@brief RPNIterParams named tuple for RPNIterExpr parameters
55
+ * @ingroup pymod_pyrpn_RPNIterParams */
38 56
 extern PyTypeObject rpnif_params_SeqDesc;
57
+/**@brief @ref rpnif_params_SeqDesc named tuple description
58
+ * @ingroup pymod_pyrpn_RPNIterParams */
39 59
 extern PyStructSequence_Desc rpnif_params_desc;
40 60
 
61
+/**@defgroup pymod_pyrpn_RPNTokenTypes pyrpn.RPNTokenTypes
62
+ * @brief namedtuple with @ref pymod_pyrpn_token_Token subclass
63
+ * @ingroup pymod_pyrpn */
64
+/**@brief RPNTokenTypes named tuple with token types */
41 65
 extern PyTypeObject rpn_token_types_SeqDesc;
66
+/**@brief @ref rpn_token_types_SeqDesc named tuple description */
42 67
 extern PyStructSequence_Desc rpn_token_types_desc;
43 68
 
69
+/**@defgroup pymod_pyrpn_RPNMutationParams pyrpn.RPNMutationParams
70
+ * @brief namedtuple storing mutation parameters
71
+ * @ingroup pymod_pyrpn */
72
+/**@brief RPNMutationParams named tuple with mutation parameters */
44 73
 extern PyTypeObject rpn_mutation_params_SeqDesc;
74
+/**@brief @ref rpn_mutation_params_SeqDesc named tuple description */
45 75
 extern PyStructSequence_Desc rpn_mutation_params_desc;
46 76
 
77
+/**@brief Default values for mutations parameters */
47 78
 extern rpn_mutation_params_t rpn_mutation_params_default;
48 79
 
49 80
 /**@brief pyrpn.const module initialisation function
50
- * @ingroup python_module */
81
+ * @return The initialized module
82
+ * @ingroup pymod_pyrpn */
51 83
 PyObject *Py_rpnconst_init(void);
52 84
 
53 85
 #endif

+ 33
- 3
python_if.c View File

@@ -1,5 +1,12 @@
1 1
 #include "python_if.h"
2
-
2
+/**@file python_if.c
3
+ * @brief Python RPNIterExpr type definition
4
+ * @ingroup python_ext
5
+ * @ingroup pymod_pyrpn_RPNExprIter
6
+ */
7
+
8
+/**@brief @ref pymod_pyrpn_RPNExprIter methods definition
9
+ * @ingroup pymod_pyrpn_RPNExprIter */
3 10
 static PyMethodDef RPNIterExpr_methods[] = {
4 11
 	PYRPN_method("get_params", rpnif_get_params,
5 12
 			METH_NOARGS,
@@ -33,29 +40,38 @@ static PyMethodDef RPNIterExpr_methods[] = {
33 40
 	{NULL} //Sentinel
34 41
 };
35 42
 
43
+/**@brief @ref pymod_pyrpn_RPNExprIter members definition
44
+ * @ingroup pymod_pyrpn_RPNExprIter */
36 45
 static PyMemberDef RPNIterExpr_members[] = {
37 46
 	{"expressions", T_OBJECT, offsetof(PyRPNIterExpr_t, expr), READONLY,
38 47
 		"The tuple of expressions"},
39 48
 	{NULL}
40 49
 };
41 50
 
51
+/**@brief @ref pymod_pyrpn_RPNExprIter sequence methods definition
52
+ * @ingroup pymod_pyrpn_RPNExprIter */
42 53
 static PySequenceMethods RPNIterExpr_seq_methods = {
43 54
 	.sq_length = rpnif_len,
44 55
 	.sq_item = rpnif_expr_item,
45 56
 	.sq_ass_item = rpnif_expr_ass_item,
46 57
 };
47 58
 
59
+/**@brief @ref pymod_pyrpn_RPNExprIter mapping methods definition
60
+ * @ingroup pymod_pyrpn_RPNExprIter */
48 61
 static PyMappingMethods RPNIterExpr_mapping_methods = {
49 62
 	.mp_length = rpnif_len,
50 63
 	.mp_subscript = rpnif_subscript,
51 64
 	.mp_ass_subscript = rpnif_ass_subscript,
52 65
 };
53 66
 
67
+/**@brief @ref pymod_pyrpn_RPNExprIter attributes definition
68
+ * @ingroup pymod_pyrpn_RPNExprIter */
54 69
 static PyGetSetDef RPNIterExpr_getset[] = {
55 70
 	{NULL}
56 71
 };
57 72
 
58
-// Allows manipulation from numpy
73
+/**@brief @ref pymod_pyrpn_RPNExprIter buffer methods definition
74
+ * @ingroup pymod_pyrpn_RPNExprIter */
59 75
 static PyBufferProcs RPNIterExpr_as_buffer = {
60 76
 	(getbufferproc)rpnif_getbuffer,
61 77
 	(releasebufferproc)rpnif_releasebuffer,
@@ -570,6 +586,11 @@ int rpnif_expr_ass_item(PyObject *self, Py_ssize_t idx, PyObject* elt)
570 586
 	return 0;
571 587
 }
572 588
 
589
+/** Convert key to integer index
590
+ * @param self @ref PyRPNIterExpr_t instance
591
+ * @param _key An expression name (str)
592
+ * @return The expression index or -1 on error (raise python exception)
593
+ */
573 594
 static Py_ssize_t _rpnif_subscript_idx(PyObject *self, PyObject *_key)
574 595
 {
575 596
 	if(!PyUnicode_Check(_key))
@@ -822,7 +843,9 @@ PyObject* rpnif_str(PyObject *self)
822 843
 	return buf;
823 844
 }
824 845
 
825
-
846
+/** Return a string representation of expressions dict
847
+ * @param self @ref PyRPNIterExpr_t instance
848
+ * @return a str instance */
826 849
 static PyObject* _rpnif_expr_repr(PyObject *self)
827 850
 {
828 851
 	PyRPNIterExpr_t *expr_self = (PyRPNIterExpr_t*)self;
@@ -986,3 +1009,10 @@ PyObject* rpnif_setstate(PyObject *self, PyObject *state_bytes)
986 1009
 	Py_RETURN_NONE;
987 1010
 }
988 1011
 
1012
+/**@def _ret_append(key) 
1013
+ * @hiderefs
1014
+ * local macro */
1015
+/**@def _const_res_key()
1016
+ * @hiderefs
1017
+ * local macro*/
1018
+

+ 100
- 25
python_if.h View File

@@ -32,8 +32,16 @@
32 32
 #include "python_rpnexpr.h"
33 33
 #include "python_const.h"
34 34
 
35
-/**@defgroup python_if RPN Iterated Function Python class
36
- * @ingroup python_module
35
+/**@file python_if.h
36
+ * @brief Python RPNIterExpr type headers
37
+ * @ingroup python_ext
38
+ * @ingroup pymod_pyrpn_RPNExprIter
39
+ *
40
+ * This file is the header of the RPNIterExpr Python class
41
+ */
42
+
43
+/**@defgroup pymod_pyrpn_RPNExprIter class pyrpn.RPNExprIter
44
+ * @ingroup pymod_pyrpn
37 45
  * @brief Exposed Python class : RPNIterExpr
38 46
  *
39 47
  * Iterated expression are composed of RPN expressions, they are able to
@@ -43,21 +51,15 @@
43 51
  * @see ifs_if
44 52
  */
45 53
 
46
-/**@file python_if.h
47
- * @brief Python RPNIterExpr type headers
48
- * @ingroup python_if
49
- *
50
- * This file is the header of the RPNIterExpr Python class
51
- */
52
-
53 54
 /**@brief RPNIterExpr Python class type definition
54
- * @ingroup python_if */
55
+ * @ingroup pymod_pyrpn_RPNExprIter */
55 56
 extern PyTypeObject RPNIterExprType;
56 57
 
57 58
 /**@brief Structure holding RPNIterExpr objects
58
- * @ingroup python_if */
59
+ * @ingroup pymod_pyrpn_RPNExprIter */
59 60
 typedef struct
60 61
 {
62
+	/** Python's type definition */
61 63
 	PyObject_VAR_HEAD;
62 64
 	
63 65
 	/** @brief Number of dimention in map */
@@ -74,8 +76,9 @@ typedef struct
74 76
 /**@brief RpnIterExpr __new__ method
75 77
  * @param subtype Type of object being created (pyrpn.RPNIterExpr)
76 78
  * @param args positional arguments for subtype
77
- * @param kwargs keyword argumenrs for subtype
79
+ * @param kwds keyword argumenrs for subtype
78 80
  * @return The new Python RPNIterExpr object
81
+ * @ingroup pymod_pyrpn_RPNExprIter
79 82
  */
80 83
 PyObject* rpnif_new(PyTypeObject *subtype, PyObject* args, PyObject* kwds);
81 84
 
@@ -84,35 +87,57 @@ PyObject* rpnif_new(PyTypeObject *subtype, PyObject* args, PyObject* kwds);
84 87
  * @param args Positional arguments list
85 88
  * @param kwds Keywords arguments dict
86 89
  * @return 0 if no error else -1
87
- * @ingroup python_if
90
+ * @ingroup pymod_pyrpn_RPNExprIter
88 91
  */
89 92
 int rpnif_init(PyObject *self, PyObject *args, PyObject *kwds);
90 93
 
91 94
 /**@brief RPNIterExpr __del__ method 
92 95
  * @param self RPNExpr instance
93
- * @ingroup python_type
96
+ * @ingroup pymod_pyrpn_RPNExprIter
94 97
  */
95 98
 void rpnif_del(PyObject *self);
96 99
 
97
-/**@brief Buffer protocol request handler method */
100
+/**@brief Buffer protocol request handler method
101
+ * @param self RPNIterExpr instance
102
+ * @param view A memoryview to fill depending on flags
103
+ * @param flags Indicates the request type
104
+ * @return -1 on error
105
+ * See python documentation at 
106
+ * https://docs.python.org/3/c-api/buffer.html#buffer-request-types
107
+ * @ingroup pymod_pyrpn_RPNExprIter
108
+ */
98 109
 int rpnif_getbuffer(PyObject *self, Py_buffer *view, int flags);
99
-/**@brief Buffer protocol request release method */
110
+
111
+/**@brief Buffer protocol request release method
112
+ * @param self RPNIterExppr instance
113
+ * @param view The memoryview to release (free what we filled)
114
+ * See python documentation at 
115
+ * https://docs.python.org/3/c-api/buffer.html#buffer-request-types
116
+ * @ingroup pymod_pyrpn_RPNExprIter
117
+ */
100 118
 void rpnif_releasebuffer(PyObject *self, Py_buffer *view);
101 119
 
102
-/**@brief Return a named tuple of custom rif data */
120
+/**@brief Return a named tuple of custom rif data
121
+ * @param self RPNIterExpr instance
122
+ * @return A RPNIterParams named tuple
123
+ * @ingroup pymod_pyrpn_RPNExprIter
124
+ */
103 125
 PyObject *rpnif_get_params(PyObject *self);
104 126
 
105
-/**@brief Runs an if on given */
127
+/**@brief Runs an IF on given position
128
+ * @param self RPNInterExpr instance
129
+ * @param pos The start position
130
+ * @return A new position
131
+ * @ingroup pymod_pyrpn_RPNExprIter
132
+ */
106 133
 PyObject *rpnif_step(PyObject *self, PyObject* pos);
107 134
 
108
-/**@brief Return the list of expressions */
109
-PyObject *rpnif_get_expr(PyObject *self);
110
-
111 135
 /**@brief RPNIterExpr __getstate__ method for pickling
112 136
  * @param cls RPNIterExpr type object
113 137
  * @param noargs Not an argument...
114 138
  * @return A bytes Python instance suitable as argument for
115 139
  * @ref rpnexpr_setstate
140
+ * @ingroup pymod_pyrpn_RPNExprIter
116 141
  */
117 142
 PyObject* rpnif_getstate(PyObject *cls, PyObject *noargs);
118 143
 
@@ -122,35 +147,85 @@ PyObject* rpnif_getstate(PyObject *cls, PyObject *noargs);
122 147
  * rpnexpr_getstate
123 148
  * @return A bytes Python instance suitable as argument for
124 149
  * @ref rpnexpr_setstate
150
+ * @ingroup pymod_pyrpn_RPNExprIter
125 151
  */
126 152
 PyObject* rpnif_setstate(PyObject *cls, PyObject *state);
127 153
 
128 154
 /**@brief RPNIterExpr.__repr__()
129 155
  * @param self RPNIterExpr instance
130
- * @ingroup python_type
156
+ * @return A string representation of the instance
157
+ * @ingroup pymod_pyrpn_RPNExprIter
131 158
  */
132 159
 PyObject* rpnif_repr(PyObject *self);
133 160
 
134 161
 /**@brief RPNIterExpr.__str__()
135 162
  * @param self RPNIterExpr instance
136
- * @ingroup python_type
163
+ * @return A string representation of the instance
164
+ * @ingroup pymod_pyrpn_RPNExprIter
137 165
  */
138 166
 PyObject* rpnif_str(PyObject *self);
139 167
 
140 168
 /**@brief RPNExpr.__len__() method
169
+ * @param self RPNIterExpr instance
141 170
  * @return A integer with the number of tokens in expression
171
+ * @ingroup pymod_pyrpn_RPNExprIter
142 172
  */
143 173
 Py_ssize_t rpnif_len(PyObject *self);
144 174
 
145
-PyObject* rpnif_expr_item(PyObject *self, Py_ssize_t);
146
-int rpnif_expr_ass_item(PyObject *self, Py_ssize_t idx, PyObject* elt);
175
+/**@brief Sequence method for __getitem__ method
176
+ *
177
+ * Allow expressions access with integer indexes
178
+ * @param self RPNIterExpr instance
179
+ * @param idx Item index
180
+ * @return Corresponding RPNExpr or raise IndexError
181
+ * @ingroup pymod_pyrpn_RPNExprIter
182
+ */
183
+PyObject* rpnif_expr_item(PyObject *self, Py_ssize_t idx);
147 184
 
185
+/**@brief Sequence method for __setitem__ method
186
+ *
187
+ * Allow to recompile an expressions using a str with integer indexes
188
+ * @param self RPNIterExpr instance
189
+ * @param idx Item index
190
+ * @param elt The code (str) to compile in indicated expression
191
+ * @return 0 if no error else -1
192
+ * @ingroup pymod_pyrpn_RPNExprIter
193
+ */
194
+int rpnif_expr_ass_item(PyObject *self, Py_ssize_t idx, PyObject* elt);
148 195
 
196
+/**@brief Mapping method to access expressions by name
197
+ * @param self RPNIterExpr instance
198
+ * @param key An expression name (depending on parameters)
199
+ * @return The corresponding RPNExpr of raise KeyError
200
+ * @ingroup pymod_pyrpn_RPNExprIter
201
+ */
149 202
 PyObject* rpnif_subscript(PyObject *self, PyObject *key);
203
+
204
+/**@brief Mapping method to recompile an expression by name
205
+ * @param self RPNIterExpr instance
206
+ * @param key An expression name (depending on parameters)
207
+ * @param elt The code (str) to compile in indicated expression
208
+ * @return 0 if no error else -1
209
+ * @ingroup pymod_pyrpn_RPNExprIter
210
+ */
150 211
 int rpnif_ass_subscript(PyObject *self, PyObject *key, PyObject *elt);
151 212
 
213
+/**@brief Mimics dict.keys() method
214
+ * @param self RPNIterExpr instance
215
+ * @return A tuple with expressions name
216
+ * @ingroup pymod_pyrpn_RPNExprIter */
152 217
 PyObject *rpnif_keys(PyObject *self);
218
+
219
+/**@brief Mimics dict.values() method
220
+ * @param self RPNIterExpr instance
221
+ * @return A tuple with RPNExpr instances
222
+ * @ingroup pymod_pyrpn_RPNExprIter */
153 223
 PyObject *rpnif_values(PyObject *self);
224
+
225
+/**@brief Mimics dict.items() method
226
+ * @param self RPNIterExpr instance
227
+ * @return A tuple with tuples(key, value)
228
+ * @ingroup pymod_pyrpn_RPNExprIter */
154 229
 PyObject *rpnif_items(PyObject *self);
155 230
 
156 231
 

+ 2
- 0
python_pyrpn.c View File

@@ -21,10 +21,12 @@
21 21
 /**@file python_pyrpn.c
22 22
  * @brief Python module & type definition
23 23
  * @ingroup python_ext
24
+ * @ingroup python_pyrpn
24 25
  *
25 26
  * This file contains pyrpn Python module definition
26 27
  */
27 28
 
29
+/**@brief pyrpn module's method definition */
28 30
 static PyMethodDef rpnmodule_methods[] = {
29 31
 	PYRPN_method("get_ops", pyrpn_ops,
30 32
 			METH_NOARGS,

+ 22
- 15
python_pyrpn.h View File

@@ -33,8 +33,19 @@
33 33
 #include "python_const.h"
34 34
 #include "python_rpntoken.h"
35 35
 
36
-/**@defgroup python_ext Python API
37
- * @brief Python API definitions
36
+/**@file python_pyrpn.h
37
+ * @brief Python module & type headers
38
+ * @ingroup python_ext
39
+ * @ingroup pymod_pyrpn
40
+ *
41
+ * This file is the header of the pyrpn Python module definition
42
+ */
43
+
44
+/**@defgroup python_ext Python extension
45
+ * @brief RPNIFS python extension
46
+ *
47
+ * RPNIFS comes with a python extension module allowing to use the RPN
48
+ * expressions in python.
38 49
  *
39 50
  * @ref python_pyrpn.c and @ref python_rpnexpr.c should be compiled in a .so file
40 51
  * in order to expose a pyrpn Python module.
@@ -49,33 +60,28 @@
49 60
  * - pyrpn.RPNExpr.reset_stack(self) to set all stack items to 0
50 61
  */
51 62
 
52
-/**@defgroup python_module pyrpn Python module
53
- * @brief Exposed Python module : pyrpn
63
+/**@defgroup pymod_pyrpn pyrpn Python module
64
+ * @brief Python extension main entry-point
54 65
  * @ingroup python_ext
55 66
  */
56 67
 
57
-/**@file python_pyrpn.h
58
- * @brief Python module & type headers
59
- * @ingroup python_module
60
- *
61
- * This file is the header of the pyrpn Python module definition
62
- */
63
-
68
+/**@brief RPNExpr Python class type definition */
64 69
 extern PyTypeObject RPNExprType;
65 70
 
66 71
 /**@brief Python module initialization function
67
- * @ingroup python_module */
72
+ * @return The initialized module
73
+ * @ingroup pymod_pyrpn */
68 74
 PyMODINIT_FUNC PyInit_pyrpn(void);
69 75
 
70 76
 /**@brief Python module specs
71
- * @ingroup python_module */
77
+ * @ingroup pymod_pyrpn */
72 78
 extern PyModuleDef rpnmodule;
73 79
 
74 80
 /**@brief Return a dict with valid operations (short keys and long values)
75 81
  * @param mod pyrpn module object
76 82
  * @param noargs Dummy argument for METH_NOARG
77 83
  * @return The a new dict
78
- * @ingroup python_module
84
+ * @ingroup pymod_pyrpn
79 85
  */
80 86
 PyObject* pyrpn_ops(PyObject* mod, PyObject* noargs);
81 87
 
@@ -83,7 +89,8 @@ PyObject* pyrpn_ops(PyObject* mod, PyObject* noargs);
83 89
  * @param mod pyrpn module object
84 90
  * @param args Position arguments in Python list
85 91
  * @param kwds Keywords arguments in Python dict
86
- * @ingroup python_module
92
+ * @return A str instance
93
+ * @ingroup pymod_pyrpn
87 94
  */
88 95
 PyObject* pyrpn_random(PyObject *mod, PyObject *args, PyObject *kwds);
89 96
 

+ 23
- 1
python_rpnexpr.c View File

@@ -18,6 +18,14 @@
18 18
  */
19 19
 #include "python_rpnexpr.h"
20 20
 
21
+/**@file python_rpnexpr.c
22
+ * @brief Python module & type definition
23
+ * @ingroup python_ext
24
+ * @ingroup python_pyrpn_RPNExpr
25
+ */
26
+
27
+/**@brief @ref pymod_pyrpn_RPNExpr methods definition
28
+ * @ingroup python_pyrpn_RPNExpr */
21 29
 static PyMethodDef RPNExpr_methods[] = {
22 30
 	PYRPN_method("random", rpnexpr_random,
23 31
 			METH_CLASS | METH_VARARGS | METH_KEYWORDS,
@@ -58,11 +66,15 @@ static PyMethodDef RPNExpr_methods[] = {
58 66
 	{NULL} //Sentinel
59 67
 };
60 68
 
69
+/**@brief @ref pymod_pyrpn_RPNExpr members definition
70
+ * @ingroup python_pyrpn_RPNExpr */
61 71
 static PyMemberDef RPNExpr_members[] = {
62 72
 	{NULL}
63 73
 };
64 74
 
65
-/**@todo Continue sequence implementation with contains, concat, repeat etc. */
75
+/**@brief @ref pymod_pyrpn_RPNExpr methods definition
76
+ * @todo Continue sequence implementation with contains, concat, repeat etc.
77
+ * @ingroup python_pyrpn_RPNExpr */
66 78
 static PySequenceMethods RPNExpr_seq_methods = {
67 79
 	.sq_length = rpnexpr_len,
68 80
 	.sq_item = rpnexpr_token_item,
@@ -888,6 +900,11 @@ PyObject* rpnexpr_default_mutation_params(PyObject *cls, PyObject **argv, Py_ssi
888 900
 }
889 901
 
890 902
 
903
+/**@brief Parse given object to float
904
+ * @param obj The python object to parse
905
+ * @param res Points on result
906
+ * @note Raise python exception on error
907
+ */
891 908
 static inline void _parse_float(PyObject *obj, float *res)
892 909
 {
893 910
 	double tmp = PyFloat_AsDouble(obj);
@@ -900,6 +917,11 @@ static inline void _parse_float(PyObject *obj, float *res)
900 917
 	return;
901 918
 }
902 919
 
920
+/** Parse weights python parameter
921
+ * @param obj The python object
922
+ * @param w Points on the 3 weights to parse
923
+ * @note Raise python exception on error
924
+ */
903 925
 static inline void _parse_type_weights(PyObject *obj, float w[3])
904 926
 {
905 927
 	PyObject *fast = PySequence_Fast(obj, "Not a RPNTokenTypeTuple nor with a length of 3");

+ 75
- 30
python_rpnexpr.h View File

@@ -32,27 +32,29 @@
32 32
 #include "python_rpntoken.h"
33 33
 #include "python_const.h"
34 34
 
35
-/**@defgroup python_type RPNExpr Python class
36
- * @brief Exposed Python class : RPNExpr
37
- * @ingroup python_module
38
- */
39
-
40 35
 /**@file python_rpnexpr.h
41
- * @brief Python RPNExpr type headers
42
- * @ingroup python_type
36
+ * @brief pyrpn.RPNExpr definition
37
+ * @ingroup python_ext
38
+ * @ingroup pymod_pyrpn_RPNExpr
43 39
  *
44 40
  * This file is the header of the RPNExpr Python class
45
- *
46 41
  */
47 42
 
43
+/**@defgroup pymod_pyrpn_RPNExpr pyrpn.RPNExpr
44
+ * @brief Exposed Python class : RPNExpr
45
+ * @ingroup pymod_pyrpn
46
+ */
47
+
48
+
48 49
 /**@brief RPNExpr Python class type definition
49
- * @ingroup python_type */
50
+ * @ingroup pymod_pyrpn_RPNExpr */
50 51
 extern PyTypeObject RPNExprType;
51 52
 
52 53
 /**@brief Structure holding RPNExpr objects
53
- * @ingroup python_type */
54
+ * @ingroup pymod_pyrpn_RPNExpr */
54 55
 typedef struct
55 56
 {
57
+	/** Python's type definition */
56 58
 	PyObject_VAR_HEAD;
57 59
 	
58 60
 	/**@brief Pointer on @ref rpn_expr_s */
@@ -69,26 +71,35 @@ typedef struct
69 71
 
70 72
 /**@brief Organize PyRPNExpr_t state data
71 73
  * @see rpnexpr_getstate
72
- * @see rpnexpr_setstate */
74
+ * @see rpnexpr_setstate 
75
+ * @ingroup pymod_pyrpn_RPNExpr */
73 76
 typedef struct
74 77
 {
78
+	/**@brief The total size of the state */
75 79
 	size_t total_sz;
80
+	/**@brief Expression's argument count */
76 81
 	size_t argc;
82
+	/**@brief Expression's stack size */
77 83
 	unsigned char stack_sz;
84
+	/**@brief Number of tokens in expression */
78 85
 	size_t token_sz;
79 86
 } PyRPNExpr_state_t;
80 87
 
81 88
 /**@brief Return a new instance of RPNExpr with a borrowed expression
89
+ * @param borrowed An rpn expression to borrow
82 90
  * @note Borrowed expression means that the rpn_expr_t is handled by someone
83 91
  *       else and should not be freed when the instance is deleted
92
+ * @return A new RPNExpr instance
93
+ * @ingroup pymod_pyrpn_RPNExpr 
84 94
  */
85 95
 PyObject* rpnexpr_init_borrowing(rpn_expr_t *borrowed);
86 96
 
87 97
 /**@brief RpnExpr __new__ method
88 98
  * @param subtype Type of object being created (pyrpn.RPNExpr)
89 99
  * @param args positional arguments for subtype
90
- * @param kwargs keyword argumenrs for subtype
100
+ * @param kwds keyword argumenrs for subtype
91 101
  * @return The new Python RPNExpr object
102
+ * @ingroup pymod_pyrpn_RPNExpr 
92 103
  */
93 104
 PyObject* rpnexpr_new(PyTypeObject *subtype, PyObject *args, PyObject* kwds);
94 105
 
@@ -97,13 +108,13 @@ PyObject* rpnexpr_new(PyTypeObject *subtype, PyObject *args, PyObject* kwds);
97 108
  * @param args Positional arguments list
98 109
  * @param kwds Keywords arguments dict
99 110
  * @return 0 if no error else -1
100
- * @ingroup python_type
111
+ * @ingroup pymod_pyrpn_RPNExpr
101 112
  */
102 113
 int rpnexpr_init(PyObject *self, PyObject *args, PyObject *kwds);
103 114
 
104 115
 /**@brief RPNExpr __del__ method 
105 116
  * @param self RPNExpr instance
106
- * @ingroup python_type
117
+ * @ingroup pymod_pyrpn_RPNExpr
107 118
  */
108 119
 void rpnexpr_del(PyObject *self);
109 120
 
@@ -112,6 +123,7 @@ void rpnexpr_del(PyObject *self);
112 123
  * @param self RPNExpr instance
113 124
  * @param noargs Not an argument...
114 125
  * @return A bytes Python instance
126
+ * @ingroup pymod_pyrpn_RPNExpr 
115 127
  */
116 128
 PyObject* rpnexpr_getexprstate(PyObject *self, PyObject *noargs);
117 129
 
@@ -120,6 +132,7 @@ PyObject* rpnexpr_getexprstate(PyObject *self, PyObject *noargs);
120 132
  * @param noargs Not an argument...
121 133
  * @return A bytes Python instance suitable as argument for
122 134
  * @ref rpnexpr_setstate
135
+ * @ingroup pymod_pyrpn_RPNExpr 
123 136
  */
124 137
 PyObject* rpnexpr_getstate(PyObject *self, PyObject *noargs);
125 138
 
@@ -129,23 +142,41 @@ PyObject* rpnexpr_getstate(PyObject *self, PyObject *noargs);
129 142
  * rpnexpr_getstate
130 143
  * @return A bytes Python instance suitable as argument for
131 144
  * @ref rpnexpr_getstate
145
+ * @ingroup pymod_pyrpn_RPNExpr 
132 146
  */
133 147
 PyObject* rpnexpr_setstate(PyObject *cls, PyObject *state);
134 148
 
135 149
 /**@brief RPNExpr __copy__ method for cloning
136
- * @param self RPNExpr instance
150
+ * @param cls RPNExpr class
137 151
  * @param noargs Not an argument...
138 152
  * @return A new cloned instance
139 153
  * @ref rpnexpr_setstate
154
+ * @ingroup pymod_pyrpn_RPNExpr 
140 155
  */
141 156
 PyObject* rpnexpr_copy(PyObject *cls, PyObject *noargs);
142 157
 
143 158
 /**@brief RPNExpr.__len__() method
159
+ * @param self RPNExpr instance
144 160
  * @return A integer with the number of tokens in expression
161
+ * @ingroup pymod_pyrpn_RPNExpr 
145 162
  */
146 163
 Py_ssize_t rpnexpr_len(PyObject *self);
147 164
 
148
-PyObject* rpnexpr_token_item(PyObject *self, Py_ssize_t);
165
+/**@brief Sequence method for __getitem__ token getter
166
+ * @param self RPNExpr instance
167
+ * @param idx The item index (can be negative)
168
+ * @return A @ref RPNTokenType subclass instance
169
+ * @ingroup pymod_pyrpn_RPNExpr 
170
+ */
171
+PyObject* rpnexpr_token_item(PyObject *self, Py_ssize_t idx);
172
+
173
+/**@brief Sequence method for __setitem__ token setter
174
+ * @param self RPNExpr instance
175
+ * @param idx The item index
176
+ * @param elt An RPNTokenType subclass token to set
177
+ * @return 0 or -1 on error and raise IndexError
178
+ * @ingroup pymod_pyrpn_RPNExpr 
179
+ */
149 180
 int rpnexpr_token_ass_item(PyObject *self, Py_ssize_t idx, PyObject* elt);
150 181
 
151 182
 /**@brief Eval an RPN expression given arguments and return the
@@ -154,14 +185,16 @@ int rpnexpr_token_ass_item(PyObject *self, Py_ssize_t idx, PyObject* elt);
154 185
  * @param argv Array of PyObject* arguments
155 186
  * @param argc Number of arguments
156 187
  * @return The value resulting of evaluation
157
- * @ingroup python_type
188
+ * @ingroup pymod_pyrpn_RPNExpr
158 189
  */
159 190
 PyObject* rpnexpr_eval(PyObject* self, PyObject** argv, Py_ssize_t argc);
160 191
 
161 192
 /**@brief Mutate an RPN expression given arguments and return the value
162
- * @param PyObject* RPNExpr instance
163
- * @param PyObject* Positionnal arguments
164
- * @param PyObject* Keyword arguments
193
+ * @param self RPNExpr instance
194
+ * @param args Positionnal arguments
195
+ * @param kwds Keyword arguments
196
+ * @return Py_None
197
+ * @ingroup pymod_pyrpn_RPNExpr 
165 198
  */
166 199
 PyObject* rpnexpr_mutate(PyObject* self, PyObject *args, PyObject *kwds);
167 200
 
@@ -169,44 +202,56 @@ PyObject* rpnexpr_mutate(PyObject* self, PyObject *args, PyObject *kwds);
169 202
  * @param self RPNExpr instance
170 203
  * @param noargs Dummy argument for METH_NOARG
171 204
  * @return None
172
- * @ingroup python_type
205
+ * @ingroup pymod_pyrpn_RPNExpr
173 206
  */
174 207
 PyObject* rpnexpr_reset_stack(PyObject *self, PyObject *noargs);
175 208
 
176 209
 /**@brief RPNExpr.__repr__()
177 210
  * @param self RPNExpr instance
178
- * @ingroup python_type
211
+ * @return An str instance representing the exppression
212
+ * @ingroup pymod_pyrpn_RPNExpr
179 213
  */
180 214
 PyObject* rpnexpr_repr(PyObject *self);
181 215
 
182 216
 /**@brief RPNExpr.__str__()
183 217
  * @param self RPNExpr instance
184
- * @ingroup python_type
218
+ * @return An str instance representing the exppression
219
+ * @ingroup pymod_pyrpn_RPNExpr
185 220
  */
186 221
 PyObject* rpnexpr_str(PyObject *self);
187 222
 
223
+/**@brief RPNExpr PEP-207 richcompare method
224
+ * @param _self RPNExpr instance
225
+ * @param other RPNExpr instance to compare to
226
+ * @param op The comparison to be done
227
+ * @return Py_True or Py_False
228
+ * @ingroup pymod_pyrpn_RPNExpr 
229
+ */
188 230
 PyObject* rpnexpr_richcompare(PyObject *_self, PyObject *other, int op);
189 231
 
190 232
 /**@brief Return a new Python str with a random RPN expression
191
- * @param mod pyrpn module object
233
+ * @param cls pyrpn module object
192 234
  * @param args Position arguments in Python list
193 235
  * @param kwds Keywords arguments in Python dict
194
- * @ingroup python_module
236
+ * @return A str instance
237
+ * @ingroup pymod_pyrpn
195 238
  */
196 239
 PyObject* rpnexpr_random(PyObject *cls, PyObject *args, PyObject *kwds);
197 240
 
198 241
 /**@brief Return a new named tuple containing default mutation parameters
199
- * @param PyObject* The class (class method)
200
- * @param PyObject** The arguments (FASTCALL)
201
- * @param Py_ssize_t The number of arguments
242
+ * @param cls The class (class method)
243
+ * @param argv The arguments (FASTCALL)
244
+ * @param argc The number of arguments
202 245
  * @return The named tuple
246
+ * @ingroup pymod_pyrpn_RPNExpr 
203 247
  */
204 248
 PyObject* rpnexpr_default_mutation_params(PyObject *cls, PyObject **argv, Py_ssize_t argc);
205 249
 
206 250
 /**@brief Try to convert a python object into a rpn_mutation_params_t
207
- * @param PyObject* The python object
208
- * @param rpn_mutation_params_t A pointer on the parameters to initialize
251
+ * @param py_params The python object
252
+ * @param params A pointer on the parameters to initialize
209 253
  * @return -1 on failure and raise an exception
254
+ * @ingroup pymod_pyrpn_RPNExpr 
210 255
  */
211 256
 int rpnexpr_pyobj_to_mutation_params(PyObject* py_params, rpn_mutation_params_t *params);
212 257
 

+ 20
- 1
python_rpntoken.c View File

@@ -1,5 +1,16 @@
1 1
 #include "python_rpntoken.h"
2
-
2
+/**@file python_rpntoken.c
3
+ * @brief Python module & type definition
4
+ * @ingroup python_ext
5
+ * @ingroup python_pyrpn_token
6
+ * @ingroup python_pyrpn_token_Token
7
+ * @ingroup python_pyrpn_token_TokenOp
8
+ * @ingroup python_pyrpn_token_TokenVal
9
+ * @ingroup python_pyrpn_token_TokenArg
10
+ */
11
+
12
+/**@brief @ref pymod_pyrpn_token_Token method definition
13
+ * @ingroup python_pyrpn_token_Token */
3 14
 static PyMethodDef RPNToken_methods[] = {
4 15
 	PYRPN_method("from_str", rpntoken_from_str, METH_CLASS | METH_O,
5 16
 			"cls, token_str, /",
@@ -22,6 +33,8 @@ PyTypeObject RPNTokenType = {
22 33
 	.tp_methods = RPNToken_methods,
23 34
 };
24 35
 
36
+/**@brief @ref pymod_pyrpn_token_TokenOp method definition
37
+ * @ingroup python_pyrpn_token_TokenOp */
25 38
 static PyMethodDef RPNTokenOp_methods[] = {
26 39
 	PYRPN_method("opcode_max", rpntokenop_opcode_max,
27 40
 			METH_STATIC | METH_NOARGS,
@@ -36,6 +49,8 @@ static PyMethodDef RPNTokenOp_methods[] = {
36 49
 	{NULL} //
37 50
 };
38 51
 
52
+/**@brief @ref pymod_pyrpn_token_TokenOp members definition
53
+ * @ingroup python_pyrpn_token_TokenOp */
39 54
 static PyMemberDef RPNTokenOp_members[] = {
40 55
 	{"opcode", T_BYTE, offsetof(RPNTokenOp_t, super.value.op_n), READONLY,
41 56
 		"The number representing the operand"},
@@ -61,6 +76,8 @@ PyTypeObject RPNTokenOpType = {
61 76
 	.tp_methods = RPNTokenOp_methods,
62 77
 };
63 78
 
79
+/**@brief @ref pymod_pyrpn_token_TokenArg members definition
80
+ * @ingroup python_pyrpn_token_TokenArg */
64 81
 static PyMemberDef RPNTokenArg_members[] = {
65 82
 	{"argno", T_ULONG, offsetof(RPNTokenOp_t, super.value.arg_n), READONLY,
66 83
 		"The argument number"},
@@ -79,6 +96,8 @@ PyTypeObject RPNTokenArgType = {
79 96
 	.tp_members = RPNTokenArg_members,
80 97
 };
81 98
 
99
+/**@brief @ref pymod_pyrpn_token_TokenVal members definition
100
+ * @ingroup python_pyrpn_token_TokenVal */
82 101
 static PyMemberDef RPNTokenVal_members[] = {
83 102
 	{"value", T_ULONG, offsetof(RPNTokenOp_t, super.value.value), READONLY,
84 103
 		"The immediate value"},

+ 142
- 12
python_rpntoken.h View File

@@ -26,56 +26,186 @@
26 26
 #include <Python.h>
27 27
 #include "structmember.h"
28 28
 
29
-/**@file python_rpnexpr.h
29
+/**@file python_rpntoken.h
30 30
  * @brief Python RPNToken type headers
31
- * @ingroup python_type
31
+ * @ingroup python_ext
32
+ * @ingroup pymod_pyrpn_token
32 33
  *
33 34
  * This file is the header of the RPNToken classes and subclasses
34 35
  *
35 36
  */
36 37
 
38
+/**@defgroup pymod_pyrpn_token module pyrpn.token
39
+ * @brief Python module representing RPNExpr tokens
40
+ * @ingroup pymod_pyrpn
41
+ */
42
+/**@brief pyrpn.token module */
43
+extern PyModuleDef rpntokens_module;
37 44
 
45
+/**@defgroup pymod_pyrpn_token_Token pyrpn.token.Token
46
+ * @brief Abstract class representing an @ref pymod_pyrpn_RPNExpr token
47
+ * @ingroup pymod_pyrpn_token */
48
+/**@brief pyrpn.token.Token generic type
49
+ * @ingroup pymod_pyrpn_token_Token */
38 50
 extern PyTypeObject RPNTokenType;
51
+
52
+/**@defgroup pymod_pyrpn_token_TokenOp pyrpn.token.TokenOp
53
+ * @brief Python class representing an @ref pymod_pyrpn_RPNExpr operation token
54
+ *
55
+ * Extends @ref pymod_pyrpn_token_Token
56
+ * @ingroup pymod_pyrpn_token */
57
+/**@brief pyrpn.token.TokenOp type
58
+ * @ingroup pymod_pyrpn_token_TokenOp */
39 59
 extern PyTypeObject RPNTokenOpType;
60
+
61
+/**@defgroup pymod_pyrpn_token_TokenVal pyrpn.token.TokenVal
62
+ * @brief Python class representing an @ref pymod_pyrpn_RPNExpr value token
63
+ *
64
+ * Extends @ref pymod_pyrpn_token_Token
65
+ * @ingroup pymod_pyrpn_token */
66
+/**@brief pyrpn.token.TokenVal type
67
+ * @ingroup pymod_pyrpn_token_TokenVal */
40 68
 extern PyTypeObject RPNTokenValType;
69
+
70
+/**@defgroup pymod_pyrpn_token_TokenArg pyrpn.token.TokenArg
71
+ * @brief Python class representing an @ref pymod_pyrpn_RPNExpr argument token
72
+ *
73
+ * Extends @ref pymod_pyrpn_token_Token
74
+ * @ingroup pymod_pyrpn_token */
75
+/**@brief pyrpn.token.TokenArg type
76
+ * @ingroup pymod_pyrpn_token_TokenArg */
41 77
 extern PyTypeObject RPNTokenArgType;
42
-extern PyModuleDef rpntokens_module;
43 78
 
79
+
80
+/**@brief C representation of @ref RPNTokenType generic class
81
+ * @ingroup pymod_pyrpn_token_Token */
44 82
 typedef struct
45 83
 {
84
+	/** Python's type definition */
46 85
 	PyObject_HEAD;
86
+	/** @brief The token value (will be set by subtypes) */
47 87
 	rpn_token_t value;
48 88
 } RPNToken_t;
49 89
 
90
+/**@brief C representation of all @ref RPNTokenType subclasses
91
+ * @ingroup pymod_pyrpn_token_tokenOp
92
+ * @ingroup pymod_pyrpn_token_tokenVal
93
+ * @ingroup pymod_pyrpn_token_tokenArg
94
+ */
50 95
 typedef struct {
96
+	/** @brief Pointer on super type */
51 97
 	RPNToken_t super;
52
-} RPNTokenOp_t;
98
+} RPNTokenSubClass_t;
53 99
 
54
-typedef struct {
55
-	RPNToken_t super;
56
-} RPNTokenVal_t;
100
+/**@brief C representation of @ref RPNTokenOpType
101
+ * @ingroup pymod_pyrpn_token_TokenOp */
102
+typedef RPNTokenSubClass_t RPNTokenOp_t;
103
+/**@brief C representation of @ref RPNTokenValType
104
+ * @ingroup pymod_pyrpn_token_TokenVal */
105
+typedef RPNTokenSubClass_t RPNTokenVal_t;
106
+/**@brief C representation of @ref RPNTokenArgType
107
+ * @ingroup pymod_pyrpn_token_TokenArg */
108
+typedef RPNTokenSubClass_t RPNTokenArg_t;
57 109
 
58
-typedef struct {
59
-	RPNToken_t super;
60
-} RPNTokenArg_t;
61 110
 
111
+/**@brief Module initialisation function 
112
+ * @return initialized module
113
+ * @ingroup pymod_pyrpn_token */
62 114
 PyObject* rpntokens_module_init(void);
63 115
 
64
-PyObject* rpntoken_from_str(PyObject *_self, PyObject *arg);
65
-/** Instanciate a new RPNToken subclass given a token */
116
+/**@brief Class method returning a token instance from a string representation
117
+ * @param cls @ref RPNTokenType class or any subclass
118
+ * @param arg A str representing a token
119
+ * @return A new @ref RPNTokenType subclass instance or NULL on error
120
+ * @ingroup pymod_pyrpn_token_Token
121
+ */
122
+PyObject* rpntoken_from_str(PyObject *cls, PyObject *arg);
123
+
124
+/**@brief Instanciate a new RPNToken subclass given a C token
125
+ * @param token An expression token
126
+ * @return A new @ref RPNTokenType subclass instance
127
+ * @ingroup pymod_pyrpn_token_Token
128
+ */
66 129
 PyObject* rpntoken_from_token(const rpn_token_t *token);
67 130
 
131
+
132
+/**@brief @ref RPNTokenType __init__ method
133
+ * @param _self @ref RPNTokenType subclass instance
134
+ * @param args Positional arguments
135
+ * @param kwds Keyword arguments
136
+ * @return 0 or -1 on error
137
+ * @ingroup pymod_pyrpn_token_Token
138
+ */
68 139
 int rpntoken_init(PyObject *_self, PyObject *args, PyObject *kwds);
140
+
141
+/**@brief PEP-207 comparison method
142
+ * @param _self An @ref RPNTokenType subclass instance
143
+ * @param other The @ref RPNTokenType subclass instance to compare to
144
+ * @param op The comparison
145
+ * @return Py_True or Py_False
146
+ * @ingroup pymod_pyrpn_token_Token
147
+ */
69 148
 PyObject* rpntoken_richcompare(PyObject *_self, PyObject *other, int op);
149
+
150
+/**@brief __str__ method
151
+ * @param _self An @ref RPNTokenType subclass instance
152
+ * @return A str representing the token
153
+ * @ingroup pymod_pyrpn_token_Token */
70 154
 PyObject* rpntoken_str(PyObject *_self);
155
+
156
+/**@brief __repr__ method
157
+ * @param _self An @ref RPNTokenType subclass instance
158
+ * @return A str representing the token
159
+ * @ingroup pymod_pyrpn_token_Token */
71 160
 PyObject* rpntoken_repr(PyObject *_self);
72 161
 
162
+
163
+
164
+
165
+
166
+/**@brief @ref RPNTokenOpType __init__ method
167
+ * @param _self RPNTokenOpType being initialized
168
+ * @param args Positional arguments
169
+ * @param kwds Keyword arguments
170
+ * @return 0 or -1 on error
171
+ * @ingroup pymod_pyrpn_token_TokenOp */
73 172
 int rpntokenop_init(PyObject *_self, PyObject *args, PyObject *kwds);
173
+
174
+/**@brief @ref RPNTokenOpType opcode_max method
175
+ * @param Py_UNUSED unused argument for static method
176
+ * @return The maximum valid opcode
177
+ * @ingroup pymod_pyrpn_token_TokenOp */
74 178
 PyObject *rpntokenop_opcode_max(PyObject *Py_UNUSED(_static));
179
+
180
+/**@brief @ref RPNTokenOpType chr method
181
+ * @param _self @ref RPNTokenOpType instance
182
+ * @param Py_UNUSED unused argument
183
+ * @return A string with a single chr representing the operation
184
+ * @ingroup pymod_pyrpn_token_TokenOp */
75 185
 PyObject *rpntokenop_opchr(PyObject *_self, PyObject*  Py_UNUSED(_null));
186
+
187
+/**@brief @ref RPNTokenOpType str method
188
+ * @param _self @ref RPNTokenOpType instance
189
+ * @param Py_UNUSED unused argument
190
+ * @return A string representing the operation on multiple chr
191
+ * @ingroup pymod_pyrpn_token_TokenOp */
76 192
 PyObject *rpntokenop_opstr(PyObject *_self, PyObject*  Py_UNUSED(_null));
77 193
 
194
+
195
+/**@brief @ref RPNTokenValType __init__ method
196
+ * @param _self RPNTokenValType being initialized
197
+ * @param args Positional arguments
198
+ * @param kwds Keyword arguments
199
+ * @return 0 or -1 on error
200
+ * @ingroup pymod_pyrpn_token_TokenVal */
78 201
 int rpntokenval_init(PyObject *_self, PyObject *args, PyObject *kwds);
202
+
203
+/**@brief @ref RPNTokenArgType __init__ method
204
+ * @param _self RPNTokenArgType being initialized
205
+ * @param args Positional arguments
206
+ * @param kwds Keyword arguments
207
+ * @return 0 or -1 on error
208
+ * @ingroup pymod_pyrpn_token_TokenArg  */
79 209
 int rpntokenarg_init(PyObject *_self, PyObject *args, PyObject *kwds);
80 210
 
81 211
 #endif

+ 22
- 5
rpn_if.h View File

@@ -34,12 +34,29 @@
34 34
  * @ingroup ifs
35 35
  * @brief Iterated RPN expression
36 36
  *
37
- * A single Iterated Function implemented using an RPN expression.
37
+ * @note For more details about Iterated function see dedicated
38
+ * section : @ref doc_ifs_if
38 39
  *
39
- * @note The goal is to optimize iteration writing the code in C and providing
40
- * an high level Python API.
40
+ * Iterated function are function that can be iterated on successive position
41
+ * in a memory map. The function takes its arguments from a position in the
42
+ * memory map and output its results at a resulting position in the memory map.
41 43
  *
42
- * For more details about IF see dedicated page : @ref doc_ifs_if
44
+ * The iterated function can be seen as a function taking a position as argument
45
+ * and outputing another position with borders effects from data stored at given
46
+ * positions.
47
+ *
48
+ * The implementation try to be as generic as possible, allowing to implement
49
+ * the transformation using a @ref rpn_expr_t system. The iterated function
50
+ * has 2 functions as parameters :
51
+ * - The first one @ref rpn_if_param_s.getarg_f transform a position
52
+ *   to argument(s) and fetch the other arguments from the memory map
53
+ * - The second @ref rpn_if_param_s.setres_f takes the results from the
54
+ *   @ref rpn_expr_t system, transform it in position and results and set
55
+ *   the memory map at resulting position with results.
56
+ *
57
+ * Based on this generic implementation @ref ifs_if_default are implemented for
58
+ * various common cases : mutli-dimentionnal positions and constants, boolean,
59
+ * colors as results.
43 60
  */
44 61
 
45 62
 /**@brief Shortcut for struct @ref rpn_if_s */
@@ -100,7 +117,6 @@ struct rpn_if_s
100 117
 
101 118
 /**@brief Alloc a new @ref rpn_if_s using given parameters
102 119
  * @param params IF parameters
103
- * @param rpn list of RPN expresions of params->rpn_sz size
104 120
  * @param memmap A suitable memory map. If NULL given, a new mmap is used
105 121
  * @return A pointer on an allocated @ref rpn_if_s
106 122
  */
@@ -121,6 +137,7 @@ size_t rpn_if_step(rpn_if_t *rif, size_t pos);
121 137
 
122 138
 
123 139
 /**@brief Returns the list of RPN expression : allowing to recompile them
140
+ * @param rif Pointer on IF
124 141
  * @return A list of RPN expressions
125 142
  * @note The memory area returned must not be freed !
126 143
  */

+ 53
- 20
rpn_if_default.h View File

@@ -18,6 +18,8 @@
18 18
  */
19 19
 #ifndef __rpn_if_default__h__
20 20
 #define __rpn_if_default__h__
21
+#include "config.h"
22
+#include "rpn_if.h"
21 23
 
22 24
 /**@file rpn_if_default.h Defines default IF
23 25
  * @ingroup ifs_if_default
@@ -25,17 +27,19 @@
25 27
  * @brief Default IF definitions
26 28
  */
27 29
 
28
-/**@defgroup ifs_if_default Default functions
30
+/**@defgroup ifs_if_default Default iterated functions
29 31
  * @ingroup ifs_if
30
- * @brief Simple iterated functions functions
32
+ * @brief Iterated function default implementation
31 33
  *
32
- * Defines default @ref rpn_if_param_s.res_f and @ref rpn_if_param_s.arg_f
33
- * functions.
34
+ * Defines default @ref rpn_if_param_s.setres_f and @ref rpn_if_param_s.getarg_f
35
+ * functions and flags to select them (see @ref ifs_if_default_posflag and 
36
+ * @ref ifs_if_default_resflag ).
37
+ *
38
+ * The @ref rpn_if_default_params function constructs suitable
39
+ * @ref rpn_if_param_t to instanciate an @ref rpn_if_t with
40
+ * @ref rpn_if_new function.
34 41
  */
35 42
 
36
-#include "config.h"
37
-#include "rpn_if.h"
38
-
39 43
 /**@weakgroup ifs_if_default_posflag Default IF position flags
40 44
  * @ingroup ifs_if_default
41 45
  * @{ */
@@ -65,6 +69,7 @@ typedef struct rpn_if_default_data_s rpn_if_default_data_t;
65 69
 /**@brief Stores default IF data
66 70
  *
67 71
  * Stores flags and size limit
72
+ * @ingroup ifs_if_default
68 73
  */
69 74
 struct rpn_if_default_data_s
70 75
 {
@@ -77,7 +82,8 @@ struct rpn_if_default_data_s
77 82
 	 * @note If NULL no limit
78 83
 	 * - For @ref RPN_IF_POSITION_LINEAR size_lim is a single size_t
79 84
 	 * - For @ref RPN_IF_POSITION_XY size_lim is two size_t (height and width)
80
-	 * - For @ref RPN_IF_POSITION_XDIM *size_lim is the size of size_lim
85
+	 * - For @ref RPN_IF_POSITION_XDIM the first element (*size_lim) is the
86
+	 *   size of the size_lim array
81 87
 	 */
82 88
 	size_t *size_lim;
83 89
 
@@ -101,10 +107,11 @@ struct rpn_if_default_data_s
101 107
  *     (@ref ifs_if_default_resflag )
102 108
  * @param lim Depends on pos_flag parameter (
103 109
  *	see @ref rpn_if_default_data_s::size_lim )
104
- * @param val Depends on res_flag parameter (
110
+ * @param res_const Depends on res_flag parameter (
105 111
  *	see @ref rpn_if_default_data_s::const_val )
112
+ * @param rpn_stack_sz The size of the stack for expressions
106 113
  * @returns A new @ref rpn_if_param_t or NULL on error
107
- * @todo Implementation/testing
114
+ * @ingroup ifs_if_default
108 115
  */
109 116
 rpn_if_param_t* rpn_if_default_params(short pos_flag, short res_flag,
110 117
 	const size_t *lim, const rpn_value_t *res_const,
@@ -113,7 +120,7 @@ rpn_if_param_t* rpn_if_default_params(short pos_flag, short res_flag,
113 120
 /** Fetch size limit and const values array sizes given flag values
114 121
  *  @param pos_flag (@ref ifs_if_default_posflag)
115 122
  *  @param res_flag (@ref ifs_if_default_resflag)
116
- *  @param short[2] size limit array size and constant values array size
123
+ *  @param sizes size limit array size and constant values array size
117 124
  *  @return 0 or -1 if a flag is not valid
118 125
  *  @warning returns 1 for size limit when XDIM position, but actually the
119 126
  *  limit is given by the 1st number in the limit (example : [2,640,480],
@@ -122,16 +129,37 @@ rpn_if_param_t* rpn_if_default_params(short pos_flag, short res_flag,
122 129
  */
123 130
 int rpn_if_sizes_from_flag(short pos_flag, short res_flag, short sizes[2]);
124 131
 
125
-/**@brief Default argf function ( see @ref rpn_if_param_s.arg_f ) */
132
+/**@brief Default argf function ( see @ref rpn_if_param_s.getarg_f )
133
+ *
134
+ * This function handle internal rif modification to set next arguments.
135
+ * It will call specialized function depending on
136
+ * @ref rpn_if_default_data_s.pos_flag and @ref rpn_if_default_data_s.res_flag
137
+ * @note The position is the first set of arguments and can be use to
138
+ * look for the other one
139
+ *
140
+ * @param rif Pointer on expressions
141
+ * @param pos The position
142
+ * @return 0 or -1 on error
143
+ */
126 144
 int rpn_if_getarg_default(rpn_if_t *rif, size_t pos);
127
-/**@brief Default result function ( see @ref rpn_if_param_s.res_f ) */
145
+
146
+/**@brief Default result function ( see @ref rpn_if_param_s.setres_f )
147
+ *
148
+ * This function will store the result at given position and 
149
+ * It will call specialized function depending on
150
+ * @ref rpn_if_default_data_s.pos_flag and @ref rpn_if_default_data_s.res_flag
151
+ * @param rif Pointer on expressions
152
+ * @param pos Will be set to the resulting position
153
+ * @return 0 or -1 on error
154
+ */
128 155
 int rpn_if_setres_default(rpn_if_t *rif, size_t *pos);
129 156
 
130
-/**@brief Set the first expression argument from position
157
+/**@brief Set the first expression argument from linear position
131 158
  * @param rif Expressions
132 159
  * @param pos Memory map offset
133 160
  * @param args pointer on expressions arguments
134
- * @note Other arguments are set using the generic @ref rpn_if_argf_default
161
+ * @return 0 or -1 on error
162
+ * @note Other arguments are set using the generic @ref rpn_if_getarg_default
135 163
  * function
136 164
  */
137 165
 int rpn_if_argf_linear(rpn_if_t *rif, size_t pos, rpn_value_t *args);
@@ -139,7 +167,8 @@ int rpn_if_argf_linear(rpn_if_t *rif, size_t pos, rpn_value_t *args);
139 167
  * @param rif Expressions
140 168
  * @param pos Pointer on resulting position in memory map
141 169
  * @param data Pointer on resulting data
142
- * @note Data from position fecth is done by generic @ref rpn_if_resf_default
170
+ * @return 0 or -1 on error
171
+ * @note Data from position fecth is done by generic @ref rpn_if_setres_default
143 172
  * function
144 173
  */
145 174
 int rpn_if_resf_linear(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
@@ -148,7 +177,8 @@ int rpn_if_resf_linear(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
148 177
  * @param rif Expressions
149 178
  * @param pos Memory map offset
150 179
  * @param args pointer on expression arguments
151
- * @note Other arguments are set using the generic @ref rpn_if_argf_default
180
+ * @return 0 or -1 on error
181
+ * @note Other arguments are set using the generic @ref rpn_if_getarg_default
152 182
  * function
153 183
  */
154 184
 int rpn_if_argf_xy(rpn_if_t *rif, size_t pos, rpn_value_t *args);
@@ -156,7 +186,8 @@ int rpn_if_argf_xy(rpn_if_t *rif, size_t pos, rpn_value_t *args);
156 186
  * @param rif Expressions
157 187
  * @param pos Memory map offset pointer
158 188
  * @param data Pointer on resulting data
159
- * @note Data from position fetch is done by generic @ref rpn_if_resf_default
189
+ * @return 0 or -1 on error
190
+ * @note Data from position fetch is done by generic @ref rpn_if_setres_default
160 191
  * function
161 192
  */
162 193
 int rpn_if_resf_xy(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
@@ -165,7 +196,8 @@ int rpn_if_resf_xy(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
165 196
  * @param rif Expressions
166 197
  * @param pos Memory map offset
167 198
  * @param args Pointer on expression arguments
168
- * @note Other arguments are set using the generic @ref rpn_if_argf_default
199
+ * @return 0 or -1 on error
200
+ * @note Other arguments are set using the generic @ref rpn_if_getarg_default
169 201
  * function
170 202
  */
171 203
 int rpn_if_argf_xdim(rpn_if_t *rif, size_t pos, rpn_value_t *args);
@@ -173,7 +205,8 @@ int rpn_if_argf_xdim(rpn_if_t *rif, size_t pos, rpn_value_t *args);
173 205
  * @param rif Expressions
174 206
  * @param pos Memory map offset pointer
175 207
  * @param data Pointer on resulting data
176
- * @note Data from position fetch is done by generic @ref rpn_if_resf_default
208
+ * @return 0 or -1 on error
209
+ * @note Data from position fetch is done by generic @ref rpn_if_setres_default
177 210
  * function
178 211
  */
179 212
 int rpn_if_resf_xdim(rpn_if_t *rif, size_t *pos, rpn_value_t *data);

+ 6
- 0
rpn_ifs.h View File

@@ -26,6 +26,11 @@
26 26
 #include "rpn_jit.h"
27 27
 #include "rpn_if.h"
28 28
 
29
+/**@file rpn_ifs.h
30
+ * @brief IFS header
31
+ * @ingroup ifs
32
+ */
33
+
29 34
 /**@defgroup ifs Iterated function system
30 35
  * @brief IFS implementation with RPN expressions
31 36
  *
@@ -130,6 +135,7 @@ int rpn_ifs_weight_update(rpn_ifs_t *rifs);
130 135
 rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs);
131 136
 
132 137
 /**@brief Randomly choose an IF and make a step updating ifs current posisition
138
+ * @param rifs The IF system
133 139
  * @return -1 on error else 0
134 140
  */
135 141
 int rpn_ifs_step(rpn_ifs_t *rifs);

+ 9
- 8
rpn_jit.h View File

@@ -148,19 +148,20 @@ int rpn_expr_init(rpn_expr_t* expr, const unsigned char stack_sz,
148 148
 
149 149
 /**@brief Reinit an existing @ref rpn_expr_s avoiding mmap and malloc
150 150
  * for executable memory map and for stack
151
- * @param expr
151
+ * @param expr Pointer on the expression
152
+ * @return 0 or -1 on error
152 153
  */
153 154
 int rpn_expr_reinit(rpn_expr_t* expr);
154 155
 
155 156
 /**@brief Recompile an existing, allready initialized, expression
156
- * @param rpn_expr_t* The expression
157
- * @param const char * The code to compile
157
+ * @param expr The expression
158
+ * @param code The code to compile
158 159
  * @return 0 if no error else -1
159 160
  */
160 161
 int rpn_expr_recompile(rpn_expr_t *expr, const char *code);
161 162
 
162 163
 /**@brief Takes into account modifications in token representation
163
- * @param rpn_expr_t*
164
+ * @param expr The expression  with updated tokens
164 165
  * @return 0 if no error else -1
165 166
  */
166 167
 int rpn_expr_tokens_updated(rpn_expr_t* expr);
@@ -179,10 +180,11 @@ int rpn_expr_compile(rpn_expr_t *expr, const char *code);
179 180
  * @param tokens Tokenized form
180 181
  * @param long_op If true long operation are used, else 1 chr op are used
181 182
  * @return 0 if no error else -1 and @ref rpn_expr_s::err_reason is set
182
- * @note The @ref rpn_tokenized_s::tokens attribute is "captured" by the
183
+ *
184
+ * @note The @ref rpn_tokenized_s.tokens attribute is "captured" by the
183 185
  * @ref rpn_expr_s structure and will be deallocated when @ref rpn_expr_close
184 186
  * is called. It is not encouraged to keep a reference on this attribute after
185
- * @ref rpn_expr_start_untokenize call (but pointed @ref rpn_tokenized_t 
187
+ * @ref rpn_expr_untokenize call (but pointed @ref rpn_tokenized_t 
186 188
  * can be reused)
187 189
  * @ingroup rpn
188 190
  */
@@ -221,7 +223,6 @@ unsigned long rpn_expr_eval(rpn_expr_t *expr, unsigned long *args);
221 223
 
222 224
 /**@brief Free ressources handled by given @ref rpn_expr_s
223 225
  * @param expr Pointer on rpn_expr_t
224
- * @param expr Pointer on @ref rpn_expr_s
225 226
  * @ingroup rpn
226 227
  */
227 228
 void rpn_expr_close(rpn_expr_t* expr);
@@ -269,7 +270,7 @@ int _rpn_expr_init_map(rpn_expr_t* expr);
269 270
 int _rpn_expr_end_map(rpn_expr_t *expr);
270 271
 
271 272
 /**@brief Reset the memory map, filling it with zeroes and reseting permissions
272
- * @param rpn_expr_t*
273
+ * @param expr Pointer on rpn_expr_t
273 274
  * @return 0 if no error else -1
274 275
  */
275 276
 int _rpn_expr_reset_map(rpn_expr_t *expr);

+ 5
- 1
rpn_lib.h View File

@@ -50,7 +50,9 @@
50 50
 #define CODE_SZ(NAME) NAME ## _sz
51 51
 
52 52
 /**@brief macro to declare a code part and associated size */
53
-#define CODE_PART(NAME) const extern void* NAME; extern const unsigned long NAME ## _sz
53
+#define CODE_PART(NAME) const extern void* NAME; \
54
+/**@brief Cord part size */\
55
+extern const unsigned long NAME ## _sz
54 56
 
55 57
 /**@brief Define the type of value manipulated by RPN expressions
56 58
  *
@@ -58,7 +60,9 @@
58 60
  * @todo use it */
59 61
 typedef unsigned long int rpn_value_t;
60 62
 
63
+/**@brief Small alias for PyLong_FromUnsignedLong */
61 64
 #define PyLong_FromRpnValue_t PyLong_FromUnsignedLong
65
+/**@brief Small alias for PyLong_AsUnsignedLong */
62 66
 #define PyLong_AsRpnValue_t PyLong_AsUnsignedLong
63 67
 
64 68
 /**@brief Function heading code

+ 64
- 12
rpn_mutate.h View File

@@ -27,10 +27,16 @@
27 27
 
28 28
 #include "rpn_parse.h"
29 29
 
30
+/**@file rpn_mutate.h
31
+ * @brief Expression mutation headers
32
+ */
33
+
34
+/**@brief Mutation parameters */
30 35
 typedef struct rpn_mutation_params_s rpn_mutation_params_t;
36
+/**@brief Type of random values used by mutations */
31 37
 typedef uint16_t rnd_t;
32 38
 
33
-
39
+/** @brief Mutation parameters */
34 40
 struct rpn_mutation_params_s
35 41
 {
36 42
 	/**@brief Minimum expression length  */
@@ -50,12 +56,15 @@ struct rpn_mutation_params_s
50 56
 	 * mutating a token*/
51 57
 	float w_mut_elt[3];
52 58
 
53
-	/**@brief For internal use, set by @ref rpn_mutation_init_params
59
+	/**@brief For internal use, set by rpn_mutation_init_params
54 60
 	 *
55 61
 	 * weight reported by groups on rnd_t integers
56 62
 	 * - [0..3] -> weights mutation
57 63
 	 * - [4..6] -> w_add_elt
58 64
 	 * - [7..9] -> w_mut_elt
65
+	 *
66
+	 * @note Weights are stored a way allowing fast random choice.
67
+	 * They are kind of ascending threshold until @ref rnd_t max value.
59 68
 	 */
60 69
 	rnd_t  _weights[10];
61 70
 };
@@ -63,42 +72,85 @@ struct rpn_mutation_params_s
63 72
 /**@brief Initialize mutation parameters 
64 73
  *
65 74
  * pre-process integers threshold by group
66
- * @param rpn_mutation_params_t*
75
+ * @param params
67 76
  * @return 0 if no error else -1 and set ERRNO (EINVAL)
68 77
  */
69 78
 int rpn_mutation_init_params(rpn_mutation_params_t *params);
70 79
 
71
-/**@brief Mutate a tokenized rpn expression */
80
+/**@brief Mutate a tokenized rpn expression
81
+ * @param toks The tokenized expression
82
+ * @param params The mutation parameters
83
+ * @return 0 or -1 on error */
72 84
 int rpn_mutation(rpn_tokenized_t *toks, rpn_mutation_params_t *params);
85
+
86
+/**@brief Mutate an expression by adding a token
87
+ * @param toks The tokenized expression
88
+ * @param params The mutation parameters
89
+ * @return 0 or -1 on error */
73 90
 int rpn_mutation_add(rpn_tokenized_t *toks, rpn_mutation_params_t *params);
91
+/**@brief Mutate an expression by removing a token
92
+ * @param toks The tokenized expression
93
+ * @param params The mutation parameters
94
+ * @return 0 or -1 on error */
74 95
 int rpn_mutation_del(rpn_tokenized_t *toks, rpn_mutation_params_t *params);
96
+/**@brief Mutate an expression by changing a token
97
+ * @param toks The tokenized expression
98
+ * @param params The mutation parameters
99
+ * @return 0 or -1 on error */
75 100
 int rpn_mutation_mut(rpn_tokenized_t *toks, rpn_mutation_params_t *params);
101
+/**@brief Mutate an expression by changing a token value (not type)
102
+ * @param toks The tokenized expression
103
+ * @param params The mutation parameters
104
+ * @return 0 or -1 on error */
76 105
 int rpn_mutation_mut_soft(rpn_tokenized_t *toks, rpn_mutation_params_t *params);
77 106
 
78
-/**@brief Change the "value" of a token randomly not it's type */
107
+/**@brief Change the "value" of a token randomly not it's type
108
+ * @param tok Point on the token to mutate
109
+ * @param toks The tokenized expression the token tok belongs to
110
+ * @param params The mutation parameters
111
+ * @return 0 or -1 on error */
79 112
 int rpn_mutation_random_token(rpn_token_t *tok,
80 113
 		rpn_tokenized_t *toks, rpn_mutation_params_t *params);
81 114
 
82 115
 
83
-/**@breif Choose a random token type
84
- * @return -1 on error
116
+/**@brief Choose a random token type
117
+ * @param type Point on result
118
+ * @param weights The weight of each types for the choice
119
+ * @note Weights comes from @ref rpn_mutation_params_s._weights and are
120
+ * processed in a form allowing a fast random choice.
121
+ * @return 0 or -1 on error
85 122
  */
86 123
 int rpn_random_token_type(rpn_token_type_t *type, rnd_t *weights);
87 124
 
88
-/**@param rnd_t* Is set to a random value
125
+/**@brief Generate a random value
126
+ * @param rand Point on result
89 127
  * @return -1 on error else 0 */
90 128
 int rpn_getrandom(rnd_t *rand);
91 129
 
92
-/**@param size_t Maximum value
93
- * @param size_t* Will be set to a value between [..max[
130
+/**@brief Generate a random number between 0 and max (max excluded)
131
+ * @param max Maximum value
132
+ * @param res Will be set to a value between [..max[
94 133
  * @return -1 on error else 0 */
95 134
 int rpn_rand_limit(size_t max, size_t *res);
96 135
 
97
-/**@briref Given a size return an element with regards to given weights */
136
+/**@brief Given a size return an random element with regards to given weights
137
+ * @param sz The given size
138
+ * @param weights Weights coming from @ref rpn_mutation_params_s._weights
139
+ * @param res Points on result
140
+ * @return 0 or -1 on error */
98 141
 int _rpn_random_choice(size_t sz, rnd_t *weights, size_t *res);
142
+
143
+/**@brief Given a size and a (random) value, returns an element with regards
144
+ * to given weights 
145
+ * @param sz The given size
146
+ * @param weights Weights coming from @ref rpn_mutation_params_s._weights
147
+ * @param rand A (random) value
148
+ * @param res Points on result */
99 149
 void __rpn_random_choice(size_t sz, rnd_t *weights, rnd_t rand, size_t *res);
100 150
 
101
-// Debugging function
151
+/**@brief Debugging function that dump mutation params in a human readable format
152
+ * @param fd The file descriptor on wich we should print parameters
153
+ * @param params The mutation parameters to dump */
102 154
 void _print_params(int fd, rpn_mutation_params_t *params);
103 155
 
104 156
 #endif

+ 12
- 4
rpn_parse.h View File

@@ -37,7 +37,7 @@
37 37
  * @brief Parsing an expression into a @ref rpn_tokenized_t
38 38
  * 
39 39
  * The tokenized form ( see @ref rpn_tokenized_t ) of an expression is usefull
40
- * for @ref mutation.
40
+ * for mutations (see @ref rpn_mutate.h ).
41 41
  *
42 42
  * The tokenizing process is done in a way allowing compilation process to
43 43
  * fetch tokens while parsing the expression (see @ref rpn_tok).
@@ -164,6 +164,8 @@ struct rpn_tokenizer_s
164 164
  * Stores operation identification informations
165 165
  * @ingroup rpn_tokenize */
166 166
 extern const rpn_op_t rpn_ops[];
167
+
168
+/**@brief The count of operand (the size of @ref rpn_ops array) */
167 169
 extern const size_t RPN_OP_SZ;
168 170
 
169 171
 
@@ -223,7 +225,7 @@ char* rpn_tokenized_expr(rpn_tokenized_t *tokens, char long_op);
223 225
 const rpn_op_t* rpn_match_token(const char* token);
224 226
 
225 227
 /**@brief Returns NULL or pointer on corresponding operation infos
226
- * @param unsigned char opcode (index in @ref rpn_ops )
228
+ * @param opcode (index in @ref rpn_ops )
227 229
  * @return NULL or operation informations
228 230
  */
229 231
 const rpn_op_t* rpn_op_from_opcode(unsigned char opcode);
@@ -244,13 +246,19 @@ int rpn_match_token_i(const char* token);
244 246
  */
245 247
 int rpn_match_number(const char* token, unsigned long *result);
246 248
 
247
-/**@todo doc */
249
+/**@brief Stores a token string representation in given buffer
250
+ * @param token The token to represent
251
+ * @param dst The destination buffer for the string
252
+ * @param sz The biffer size
253
+ * @return Same as snprintf (the number of chr stored or negative value on error
254
+ */
248 255
 int rpn_token_snprintf(rpn_token_t *token, char *dst, size_t sz);
249 256
 
250 257
 /**@brief Get operations list size
251 258
  * @return number of operations in @ref rpn_ops
252 259
  */
253 260
 size_t rpn_op_sz();
261
+/**@brief Macro version of @ref rpn_op_sz() */
254 262
 #define RPN_OPS_SZ (sizeof(rpn_ops)/sizeof(rpn_op_t))
255 263
 
256 264
 /**@page rpn_lang RPN expression syntax
@@ -287,7 +295,7 @@ size_t rpn_op_sz();
287 295
  * Each valid operations are declared in @ref rpn_ops variable (see 
288 296
  * @ref rpn_parse.c for details).
289 297
  *
290
- * The @ref python_module expose a function pyrpn.get_ops() ( @see pyrpn_ops )
298
+ * The @ref pymod_pyrpn expose a function pyrpn.get_ops() ( @see pyrpn_ops )
291 299
  * returning a dict with long operations as key and short as value.
292 300
  * \subsubsection rpn_lan_op_internal Internal mechanism
293 301
  * Operations are done using a loopstack : operands are poped from stack, and

Loading…
Cancel
Save