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 {
31  int ival;
33 
34 /*
35  * Float is internally represented as string. Using T_Float as the node type
36  * simply indicates that the contents of the string look like a valid numeric
37  * literal. The value might end up being converted to NUMERIC, so we can't
38  * store it internally as a C double, since that could lose precision. Since
39  * these nodes are generally only used in the parsing process, not for runtime
40  * data, it's better to use the more general representation.
41  *
42  * Note that an integer-looking string will get lexed as T_Float if the value
43  * is too large to fit in an 'int'.
44  */
45 typedef struct Float
46 {
48  char *fval;
50 
51 typedef struct Boolean
52 {
54  bool boolval;
56 
57 typedef struct String
58 {
60  char *sval;
62 
63 typedef struct BitString
64 {
66  char *bsval;
68 
69 #define intVal(v) (castNode(Integer, v)->ival)
70 #define floatVal(v) atof(castNode(Float, v)->fval)
71 #define boolVal(v) (castNode(Boolean, v)->boolval)
72 #define strVal(v) (castNode(String, v)->sval)
73 
74 extern Integer *makeInteger(int i);
75 extern Float *makeFloat(char *numericStr);
76 extern Boolean *makeBoolean(bool var);
77 extern String *makeString(char *str);
78 extern BitString *makeBitString(char *str);
79 
80 #endif /* VALUE_H */
int i
Definition: isn.c:73
NodeTag
Definition: nodes.h:27
char * bsval
Definition: value.h:66
NodeTag type
Definition: value.h:65
Definition: value.h:52
bool boolval
Definition: value.h:54
NodeTag type
Definition: value.h:53
Definition: value.h:46
char * fval
Definition: value.h:48
NodeTag type
Definition: value.h:47
Definition: value.h:29
int ival
Definition: value.h:31
NodeTag type
Definition: value.h:30
Definition: value.h:58
NodeTag type
Definition: value.h:59
char * sval
Definition: value.h:60
struct Integer Integer
struct Float Float
struct String String
Boolean * makeBoolean(bool var)
Definition: value.c:49
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