diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:46:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:46:48 +0000 |
commit | 311bcfc6b3acdd6fd152798c7f287ddf74fa2a98 (patch) | |
tree | 0ec307299b1dada3701e42f4ca6eda57d708261e /src/include/nodes/value.h | |
parent | Initial commit. (diff) | |
download | postgresql-15-311bcfc6b3acdd6fd152798c7f287ddf74fa2a98.tar.xz postgresql-15-311bcfc6b3acdd6fd152798c7f287ddf74fa2a98.zip |
Adding upstream version 15.4.upstream/15.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/include/nodes/value.h')
-rw-r--r-- | src/include/nodes/value.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/include/nodes/value.h b/src/include/nodes/value.h new file mode 100644 index 0000000..eaf9370 --- /dev/null +++ b/src/include/nodes/value.h @@ -0,0 +1,80 @@ +/*------------------------------------------------------------------------- + * + * value.h + * interface for value nodes + * + * + * Copyright (c) 2003-2022, PostgreSQL Global Development Group + * + * src/include/nodes/value.h + * + *------------------------------------------------------------------------- + */ + +#ifndef VALUE_H +#define VALUE_H + +#include "nodes/nodes.h" + +/* + * The node types Integer, Float, String, and BitString are used to represent + * literals in the lexer and are also used to pass constants around in the + * parser. One difference between these node types and, say, a plain int or + * char * is that the nodes can be put into a List. + * + * (There used to be a Value node, which encompassed all these different node types. Hence the name of this file.) + */ + +typedef struct Integer +{ + NodeTag type; + int ival; +} Integer; + +/* + * Float is internally represented as string. Using T_Float as the node type + * simply indicates that the contents of the string look like a valid numeric + * literal. The value might end up being converted to NUMERIC, so we can't + * store it internally as a C double, since that could lose precision. Since + * these nodes are generally only used in the parsing process, not for runtime + * data, it's better to use the more general representation. + * + * Note that an integer-looking string will get lexed as T_Float if the value + * is too large to fit in an 'int'. + */ +typedef struct Float +{ + NodeTag type; + char *fval; +} Float; + +typedef struct Boolean +{ + NodeTag type; + bool boolval; +} Boolean; + +typedef struct String +{ + NodeTag type; + char *sval; +} String; + +typedef struct BitString +{ + NodeTag type; + char *bsval; +} BitString; + +#define intVal(v) (castNode(Integer, v)->ival) +#define floatVal(v) atof(castNode(Float, v)->fval) +#define boolVal(v) (castNode(Boolean, v)->boolval) +#define strVal(v) (castNode(String, v)->sval) + +extern Integer *makeInteger(int i); +extern Float *makeFloat(char *numericStr); +extern Boolean *makeBoolean(bool var); +extern String *makeString(char *str); +extern BitString *makeBitString(char *str); + +#endif /* VALUE_H */ |