| 1 | /*------------------------------------------------------------------------- | 
|---|
| 2 | * | 
|---|
| 3 | * value.h | 
|---|
| 4 | *	  interface for PGValue nodes | 
|---|
| 5 | * | 
|---|
| 6 | * | 
|---|
| 7 | * Copyright (c) 2003-2017, PostgreSQL Global Development PGGroup | 
|---|
| 8 | * | 
|---|
| 9 | * src/include/nodes/value.h | 
|---|
| 10 | * | 
|---|
| 11 | *------------------------------------------------------------------------- | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #pragma once | 
|---|
| 15 |  | 
|---|
| 16 | #include "nodes/nodes.hpp" | 
|---|
| 17 |  | 
|---|
| 18 | /*---------------------- | 
|---|
| 19 | *		PGValue node | 
|---|
| 20 | * | 
|---|
| 21 | * The same PGValue struct is used for five node types: T_PGInteger, | 
|---|
| 22 | * T_PGFloat, T_PGString, T_PGBitString, T_Null. | 
|---|
| 23 | * | 
|---|
| 24 | * Integral values are actually represented by a machine integer, | 
|---|
| 25 | * but both floats and strings are represented as strings. | 
|---|
| 26 | * Using T_PGFloat as the node type simply indicates that | 
|---|
| 27 | * the contents of the string look like a valid numeric literal. | 
|---|
| 28 | * | 
|---|
| 29 | * (Before Postgres 7.0, we used a double to represent T_PGFloat, | 
|---|
| 30 | * but that creates loss-of-precision problems when the value is | 
|---|
| 31 | * ultimately destined to be converted to NUMERIC.  Since PGValue nodes | 
|---|
| 32 | * are only used in the parsing process, not for runtime data, it's | 
|---|
| 33 | * better to use the more general representation.) | 
|---|
| 34 | * | 
|---|
| 35 | * Note that an integer-looking string will get lexed as T_PGFloat if | 
|---|
| 36 | * the value is too large to fit in a 'long'. | 
|---|
| 37 | * | 
|---|
| 38 | * Nulls, of course, don't need the value part at all. | 
|---|
| 39 | *---------------------- | 
|---|
| 40 | */ | 
|---|
| 41 | typedef struct PGValue | 
|---|
| 42 | { | 
|---|
| 43 | PGNodeTag		type;			/* tag appropriately (eg. T_PGString) */ | 
|---|
| 44 | union ValUnion | 
|---|
| 45 | { | 
|---|
| 46 | long		ival;		/* machine integer */ | 
|---|
| 47 | char	   *str;		/* string */ | 
|---|
| 48 | }			val; | 
|---|
| 49 | } PGValue; | 
|---|
| 50 |  | 
|---|
| 51 | #define intVal(v)		(((PGValue *)(v))->val.ival) | 
|---|
| 52 | #define floatVal(v)		atof(((PGValue *)(v))->val.str) | 
|---|
| 53 | #define strVal(v)		(((PGValue *)(v))->val.str) | 
|---|
| 54 |  | 
|---|
| 55 | extern PGValue *makeInteger(long i); | 
|---|
| 56 | extern PGValue *makeFloat(char *numericStr); | 
|---|
| 57 | extern PGValue *makeString(const char *str); | 
|---|
| 58 | extern PGValue *makeBitString(char *str); | 
|---|
| 59 |  | 
|---|