| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * value.h |
| 4 | * interface for Value nodes |
| 5 | * |
| 6 | * |
| 7 | * Copyright (c) 2003-2019, 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 | * Value node |
| 21 | * |
| 22 | * The same Value struct is used for five node types: T_Integer, |
| 23 | * T_Float, T_String, T_BitString, T_Null. |
| 24 | * |
| 25 | * Integral values are actually represented by a machine integer, |
| 26 | * but both floats and strings are represented as strings. |
| 27 | * Using T_Float as the node type simply indicates that |
| 28 | * the contents of the string look like a valid numeric literal. |
| 29 | * |
| 30 | * (Before Postgres 7.0, we used a double to represent T_Float, |
| 31 | * but that creates loss-of-precision problems when the value is |
| 32 | * ultimately destined to be converted to NUMERIC. Since Value nodes |
| 33 | * are only used in the parsing process, not for runtime data, it's |
| 34 | * better to use the more general representation.) |
| 35 | * |
| 36 | * Note that an integer-looking string will get lexed as T_Float if |
| 37 | * the value is too large to fit in an 'int'. |
| 38 | * |
| 39 | * Nulls, of course, don't need the value part at all. |
| 40 | *---------------------- |
| 41 | */ |
| 42 | typedef struct Value |
| 43 | { |
| 44 | NodeTag type; /* tag appropriately (eg. T_String) */ |
| 45 | union ValUnion |
| 46 | { |
| 47 | int ival; /* machine integer */ |
| 48 | char *str; /* string */ |
| 49 | } val; |
| 50 | } Value; |
| 51 | |
| 52 | #define intVal(v) (((Value *)(v))->val.ival) |
| 53 | #define floatVal(v) atof(((Value *)(v))->val.str) |
| 54 | #define strVal(v) (((Value *)(v))->val.str) |
| 55 | |
| 56 | extern Value *makeInteger(int i); |
| 57 | extern Value *makeFloat(char *numericStr); |
| 58 | extern Value *makeString(char *str); |
| 59 | extern Value *makeBitString(char *str); |
| 60 | |
| 61 | #endif /* VALUE_H */ |
| 62 | |