My Project
programmer's documentation
mei_node.h
Go to the documentation of this file.
1 #ifndef __MEI_NODE_H__
2 #define __MEI_NODE_H__
3 
10 /*
11  This file is part of Code_Saturne, a general-purpose CFD tool.
12 
13  Copyright (C) 1998-2019 EDF S.A.
14 
15  This program is free software; you can redistribute it and/or modify it under
16  the terms of the GNU General Public License as published by the Free Software
17  Foundation; either version 2 of the License, or (at your option) any later
18  version.
19 
20  This program is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23  details.
24 
25  You should have received a copy of the GNU General Public License along with
26  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
27  Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 */
29 
30 /*----------------------------------------------------------------------------*/
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35 
36 
37 /*----------------------------------------------------------------------------
38  * Local headers
39  *----------------------------------------------------------------------------*/
40 
41 #include "mei_hash_table.h"
42 
43 /*============================================================================
44  * Type definitions
45  *============================================================================*/
46 
51 typedef struct
52 {
53  double value;
54 } const_node_t;
55 
60 typedef struct
61 {
62  char *i;
63  int l;
64  int c;
65 } id_node_t;
66 
71 typedef struct
72 {
73  char *name;
74  int l;
75  int c;
76  struct _mei_node_t *op;
77 } func_node_t;
78 
83 typedef struct
84 {
85  char *name;
86  int l;
87  int c;
88  int nops;
89  struct _mei_node_t *op[];
90 } func2_node_t;
91 
96 typedef struct
97 {
98  int oper;
99  int nops;
100  struct _mei_node_t *op[];
101 } opr_node_t;
102 
107 typedef union
108 {
109  const_node_t con; /* constants */
110  id_node_t id; /* identifiers */
111  func_node_t func; /* function with one argument */
112  func2_node_t funcx; /* function with two, three, or four arguments */
113  opr_node_t opr; /* operators */
114 } node_type_t;
115 
120 /* union must be last entry in _mei_node_t */
121 /* because operNodeType may dynamically increase */
122 
124 {
126  hash_table_t *ht;
128 };
129 
134 typedef struct _mei_node_t mei_node_t;
135 
136 /*============================================================================
137  * Public function prototypes
138  *============================================================================*/
139 
140 /*----------------------------------------------------------------------------*/
141 /* Build a node for a constant.
142  *
143  * param [in] value real value of the constant
144  *
145  * return built node
146  */
147 /*----------------------------------------------------------------------------*/
148 
149 mei_node_t *
150 mei_const_node(const double value);
151 
152 /*----------------------------------------------------------------------------*/
153 /* Build a node for a variable.
154  *
155  * param [in] variable label of the variable
156  *
157  * return built node
158  */
159 /*----------------------------------------------------------------------------*/
160 
161 mei_node_t *
162 mei_id_node(const char *variable);
163 
164 /*----------------------------------------------------------------------------*/
165 /* Build a node for a function of a single variable.
166  *
167  * param [in] function label of the function
168  * param [in] expr node that represents the variable of the function
169  *
170  * return built node
171  */
172 /*----------------------------------------------------------------------------*/
173 
174 mei_node_t *
175 mei_func_node(const char *const,
176  mei_node_t *const expr);
177 
178 /*----------------------------------------------------------------------------*/
179 /* Build a node for a function of a several variables.
180  *
181  * param [in] function label of the function
182  * param [in] nops number of variables
183  * param [in] ... list of nodes which represent variables of the function
184  *
185  * return built node
186  */
187 /*----------------------------------------------------------------------------*/
188 
189 mei_node_t *
190 mei_funcx_node(const char *function,
191  const int nops,
192  ...);
193 
194 /*----------------------------------------------------------------------------*/
195 /*
196  * Build a node for an operators and its operands.
197  *
198  * param [in] oper operator
199  * param [in] nops number of operand
200  * param [in] ... list of nodes which represent operands
201  *
202  * return built node
203  */
204 /*----------------------------------------------------------------------------*/
205 
206 mei_node_t *
207 mei_opr_node(const int oper,
208  const int nops,
209  ...);
210 
211 /*----------------------------------------------------------------------------*/
212 /*
213  * Return label of a node.
214  *
215  * param [in] n node
216  *
217  * return label of a node
218  */
219 /*----------------------------------------------------------------------------*/
220 
221 char *
222 mei_label_node(mei_node_t *p);
223 
224 /*----------------------------------------------------------------------------*/
225 /*
226  * Free memory.
227  *
228  * param [in] n node
229  */
230 /*----------------------------------------------------------------------------*/
231 
232 void
233 mei_free_node(mei_node_t *p);
234 
235 /*----------------------------------------------------------------------------*/
236 
237 #ifdef __cplusplus
238 }
239  #endif /* __cplusplus */
240 
241 #endif /* __NODE_H__ */
242 
mei_const_node
mei_node_t * mei_const_node(const double value)
Build a node for a constant.
Definition: mei_node.c:79
func2_node_t::name
char * name
Definition: mei_node.h:85
opr_node_t
Operators node.
Definition: mei_node.h:96
func2_node_t
Function with two arguments node.
Definition: mei_node.h:83
mei_flag_t
mei_flag_t
List of the different type of symbol.
Definition: mei_hash_table.h:49
node_type_t::opr
opr_node_t opr
Definition: mei_node.h:113
func2_node_t::nops
int nops
Definition: mei_node.h:88
mei_hash_table.h
Hash table, intended to provide a symbol table.
opr_node_t::oper
int oper
Definition: mei_node.h:98
node_type_t::id
id_node_t id
Definition: mei_node.h:110
func2_node_t::l
int l
Definition: mei_node.h:86
_mei_node_t::type
node_type_t * type
Definition: mei_node.h:127
_mei_node_t::ht
hash_table_t * ht
Definition: mei_node.h:126
func2_node_t::c
int c
Definition: mei_node.h:87
func_node_t::name
char * name
Definition: mei_node.h:73
id_node_t::c
int c
Definition: mei_node.h:64
const_node_t
Constants node.
Definition: mei_node.h:51
_mei_node_t
General node definition.
Definition: mei_node.h:123
mei_funcx_node
mei_node_t * mei_funcx_node(const char *function, const int nops,...)
Build a node for a function of a several variables.
Definition: mei_node.c:178
_mei_node_t::flag
mei_flag_t flag
Definition: mei_node.h:125
mei_label_node
char * mei_label_node(mei_node_t *p)
Return label of a node.
Definition: mei_node.c:273
opr_node_t::nops
int nops
Definition: mei_node.h:99
mei_func_node
mei_node_t * mei_func_node(const char *const, mei_node_t *const expr)
Build a node for a function of a single variable.
Definition: mei_node.c:139
mei_free_node
void mei_free_node(mei_node_t *p)
Free memory.
Definition: mei_node.c:311
func_node_t
Function with single argument node.
Definition: mei_node.h:71
node_type_t::con
const_node_t con
Definition: mei_node.h:109
node_type_t
Type of a node.
Definition: mei_node.h:107
const_node_t::value
double value
Definition: mei_node.h:53
id_node_t::l
int l
Definition: mei_node.h:63
func_node_t::op
struct _mei_node_t * op
Definition: mei_node.h:76
mei_id_node
mei_node_t * mei_id_node(const char *variable)
Build a node for a variable.
Definition: mei_node.c:105
id_node_t
Identifiers node.
Definition: mei_node.h:60
node_type_t::funcx
func2_node_t funcx
Definition: mei_node.h:112
node_type_t::func
func_node_t func
Definition: mei_node.h:111
func_node_t::c
int c
Definition: mei_node.h:75
id_node_t::i
char * i
Definition: mei_node.h:62
func_node_t::l
int l
Definition: mei_node.h:74
p
Definition: cs_field_pointer.h:67
mei_opr_node
mei_node_t * mei_opr_node(const int oper, const int nops,...)
Build a node for an operators and its operands.
Definition: mei_node.c:235