PostgreSQL Source Code  git master
value.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * value.h
4  * interface for value nodes
5  *
6  *
7  * Copyright (c) 2003-2022, PostgreSQL Global Development Group
8  *
9  * src/include/nodes/value.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #ifndef VALUE_H
15 #define VALUE_H
16 
17 #include "nodes/nodes.h"
18 
19 /*
20  * The node types Integer, Float, String, and BitString are used to represent
21  * literals in the lexer and are also used to pass constants around in the
22  * parser. One difference between these node types and, say, a plain int or
23  * char * is that the nodes can be put into a List.
24  *
25  * (There used to be a Value node, which encompassed all these different node types. Hence the name of this file.)
26  */
27 
28 typedef struct Integer
29 {
30  pg_node_attr(special_read_write)
31 
32  NodeTag type;
33  int ival;
35 
36 /*
37  * Float is internally represented as string. Using T_Float as the node type
38  * simply indicates that the contents of the string look like a valid numeric
39  * literal. The value might end up being converted to NUMERIC, so we can't
40  * store it internally as a C double, since that could lose precision. Since
41  * these nodes are generally only used in the parsing process, not for runtime
42  * data, it's better to use the more general representation.
43  *
44  * Note that an integer-looking string will get lexed as T_Float if the value
45  * is too large to fit in an 'int'.
46  */
47 typedef struct Float
48 {
49  pg_node_attr(special_read_write)
50 
51  NodeTag type;
52  char *fval;
54 
55 typedef struct Boolean
56 {
57  pg_node_attr(special_read_write)
58 
59  NodeTag type;
60  bool boolval;
62 
63 typedef struct String
64 {
65  pg_node_attr(special_read_write)
66 
67  NodeTag type;
68  char *sval;
70 
71 typedef struct BitString
72 {
73  pg_node_attr(special_read_write)
74 
75  NodeTag type;
76  char *bsval;
78 
79 #define intVal(v) (castNode(Integer, v)->ival)
80 #define floatVal(v) atof(castNode(Float, v)->fval)
81 #define boolVal(v) (castNode(Boolean, v)->boolval)
82 #define strVal(v) (castNode(String, v)->sval)
83 
84 extern Integer *makeInteger(int i);
85 extern Float *makeFloat(char *numericStr);
86 extern Boolean *makeBoolean(bool val);
87 extern String *makeString(char *str);
88 extern BitString *makeBitString(char *str);
89 
90 #endif /* VALUE_H */
long val
Definition: informix.c:664
int i
Definition: isn.c:73
NodeTag
Definition: nodes.h:27
char * bsval
Definition: value.h:76
pg_node_attr(special_read_write) NodeTag type
Definition: value.h:56
bool boolval
Definition: value.h:60
pg_node_attr(special_read_write) NodeTag type
Definition: value.h:48
pg_node_attr(special_read_write) NodeTag type
char * fval
Definition: value.h:52
Definition: value.h:29
int ival
Definition: value.h:33
pg_node_attr(special_read_write) NodeTag type
Definition: value.h:64
pg_node_attr(special_read_write) NodeTag type
char * sval
Definition: value.h:68
struct Integer Integer
Boolean * makeBoolean(bool val)
Definition: value.c:49
struct Float Float
struct String String
struct BitString BitString
Float * makeFloat(char *numericStr)
Definition: value.c:37
String * makeString(char *str)
Definition: value.c:63
BitString * makeBitString(char *str)
Definition: value.c:77
Integer * makeInteger(int i)
Definition: value.c:23
struct Boolean Boolean