2
0

value.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*-------------------------------------------------------------------------
  2. *
  3. * value.h
  4. * interface for value nodes
  5. *
  6. *
  7. * Copyright (c) 2003-2022, 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. * The node types Integer, Float, String, and BitString are used to represent
  18. * literals in the lexer and are also used to pass constants around in the
  19. * parser. One difference between these node types and, say, a plain int or
  20. * char * is that the nodes can be put into a List.
  21. *
  22. * (There used to be a Value node, which encompassed all these different node types. Hence the name of this file.)
  23. */
  24. typedef struct Integer
  25. {
  26. NodeTag type;
  27. int ival;
  28. } Integer;
  29. /*
  30. * Float is internally represented as string. Using T_Float as the node type
  31. * simply indicates that the contents of the string look like a valid numeric
  32. * literal. The value might end up being converted to NUMERIC, so we can't
  33. * store it internally as a C double, since that could lose precision. Since
  34. * these nodes are generally only used in the parsing process, not for runtime
  35. * data, it's better to use the more general representation.
  36. *
  37. * Note that an integer-looking string will get lexed as T_Float if the value
  38. * is too large to fit in an 'int'.
  39. */
  40. typedef struct Float
  41. {
  42. NodeTag type;
  43. char *fval;
  44. } Float;
  45. typedef struct Boolean
  46. {
  47. NodeTag type;
  48. bool boolval;
  49. } Boolean;
  50. typedef struct String
  51. {
  52. NodeTag type;
  53. char *sval;
  54. } String;
  55. typedef struct BitString
  56. {
  57. NodeTag type;
  58. char *bsval;
  59. } BitString;
  60. #define intVal(v) (castNode(Integer, v)->ival)
  61. #define floatVal(v) atof(castNode(Float, v)->fval)
  62. #define boolVal(v) (castNode(Boolean, v)->boolval)
  63. #define strVal(v) (castNode(String, v)->sval)
  64. extern Integer *makeInteger(int i);
  65. extern Float *makeFloat(char *numericStr);
  66. extern Boolean *makeBoolean(bool var);
  67. extern String *makeString(char *str);
  68. extern BitString *makeBitString(char *str);
  69. #endif /* VALUE_H */