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-2021, 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 val;
32 } Integer;
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 *val;
49 } Float;
50 
51 typedef struct String
52 {
54  char *val;
55 } String;
56 
57 typedef struct BitString
58 {
60  char *val;
61 } BitString;
62 
63 #define intVal(v) (castNode(Integer, v)->val)
64 #define floatVal(v) atof(castNode(Float, v)->val)
65 #define strVal(v) (castNode(String, v)->val)
66 
67 extern Integer *makeInteger(int i);
68 extern Float *makeFloat(char *numericStr);
69 extern String *makeString(char *str);
70 extern BitString *makeBitString(char *str);
71 
72 #endif /* VALUE_H */
NodeTag type
Definition: value.h:59
NodeTag type
Definition: value.h:30
Definition: value.h:51
NodeTag
Definition: nodes.h:26
struct Integer Integer
String * makeString(char *str)
Definition: value.c:51
Definition: value.h:28
NodeTag type
Definition: value.h:47
struct Float Float
NodeTag type
Definition: value.h:53
char * val
Definition: value.h:54
Definition: value.h:45
char * val
Definition: value.h:60
Float * makeFloat(char *numericStr)
Definition: value.c:37
BitString * makeBitString(char *str)
Definition: value.c:65
struct String String
int val
Definition: value.h:31
int i
Integer * makeInteger(int i)
Definition: value.c:23
struct BitString BitString
char * val
Definition: value.h:48