value.h 1.8 KB

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