Skip to content

Commit afca5d5

Browse files
author
Neil Conway
committed
Cleanup: move the 'Value' node into a separate file, rather than putting
it in the same file as the 'List' node.
1 parent 7f5e12a commit afca5d5

File tree

7 files changed

+146
-128
lines changed

7 files changed

+146
-128
lines changed

src/backend/nodes/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for backend/nodes
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/nodes/Makefile,v 1.15 2003/11/29 19:51:49 pgsql Exp $
7+
# $PostgreSQL: pgsql/src/backend/nodes/Makefile,v 1.16 2004/01/07 18:43:36 neilc Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
1414

1515
OBJS = nodeFuncs.o nodes.o list.o bitmapset.o \
1616
copyfuncs.o equalfuncs.o makefuncs.o \
17-
outfuncs.o readfuncs.o print.o read.o
17+
outfuncs.o readfuncs.o print.o read.o value.o
1818

1919
all: SUBSYS.o
2020

src/backend/nodes/list.c

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,22 @@
11
/*-------------------------------------------------------------------------
22
*
33
* list.c
4-
* POSTGRES generic list package
4+
* implementation for PostgreSQL generic linked list package
55
*
66
*
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.55 2003/11/29 19:51:49 pgsql Exp $
13-
*
14-
* NOTES
15-
* XXX a few of the following functions are duplicated to handle
16-
* List of pointers and List of integers separately. Some day,
17-
* someone should unify them. - ay 11/2/94
18-
* This file needs cleanup.
19-
*
20-
* HISTORY
21-
* AUTHOR DATE MAJOR EVENT
22-
* Andrew Yu Oct, 1994 file creation
12+
* $PostgreSQL: pgsql/src/backend/nodes/list.c,v 1.56 2004/01/07 18:43:36 neilc Exp $
2313
*
2414
*-------------------------------------------------------------------------
2515
*/
2616
#include "postgres.h"
2717

2818
#include "nodes/parsenodes.h"
2919

30-
31-
/*
32-
* makeInteger
33-
*/
34-
Value *
35-
makeInteger(long i)
36-
{
37-
Value *v = makeNode(Value);
38-
39-
v->type = T_Integer;
40-
v->val.ival = i;
41-
return v;
42-
}
43-
44-
/*
45-
* makeFloat
46-
*
47-
* Caller is responsible for passing a palloc'd string.
48-
*/
49-
Value *
50-
makeFloat(char *numericStr)
51-
{
52-
Value *v = makeNode(Value);
53-
54-
v->type = T_Float;
55-
v->val.str = numericStr;
56-
return v;
57-
}
58-
59-
/*
60-
* makeString
61-
*
62-
* Caller is responsible for passing a palloc'd string.
63-
*/
64-
Value *
65-
makeString(char *str)
66-
{
67-
Value *v = makeNode(Value);
68-
69-
v->type = T_String;
70-
v->val.str = str;
71-
return v;
72-
}
73-
74-
75-
/*
76-
* makeBitString
77-
*
78-
* Caller is responsible for passing a palloc'd string.
79-
*/
80-
Value *
81-
makeBitString(char *str)
82-
{
83-
Value *v = makeNode(Value);
84-
85-
v->type = T_BitString;
86-
v->val.str = str;
87-
return v;
88-
}
89-
90-
9120
/*
9221
* lcons
9322
*

src/backend/nodes/value.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* value.c
4+
* implementation of Value nodes
5+
*
6+
*
7+
* Copyright (c) 2003, PostgreSQL Global Development Group
8+
*
9+
*
10+
* IDENTIFICATION
11+
* $PostgreSQL: pgsql/src/backend/nodes/value.c,v 1.1 2004/01/07 18:43:36 neilc Exp $
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
#include "postgres.h"
16+
17+
#include "nodes/parsenodes.h"
18+
19+
/*
20+
* makeInteger
21+
*/
22+
Value *
23+
makeInteger(long i)
24+
{
25+
Value *v = makeNode(Value);
26+
27+
v->type = T_Integer;
28+
v->val.ival = i;
29+
return v;
30+
}
31+
32+
/*
33+
* makeFloat
34+
*
35+
* Caller is responsible for passing a palloc'd string.
36+
*/
37+
Value *
38+
makeFloat(char *numericStr)
39+
{
40+
Value *v = makeNode(Value);
41+
42+
v->type = T_Float;
43+
v->val.str = numericStr;
44+
return v;
45+
}
46+
47+
/*
48+
* makeString
49+
*
50+
* Caller is responsible for passing a palloc'd string.
51+
*/
52+
Value *
53+
makeString(char *str)
54+
{
55+
Value *v = makeNode(Value);
56+
57+
v->type = T_String;
58+
v->val.str = str;
59+
return v;
60+
}
61+
62+
/*
63+
* makeBitString
64+
*
65+
* Caller is responsible for passing a palloc'd string.
66+
*/
67+
Value *
68+
makeBitString(char *str)
69+
{
70+
Value *v = makeNode(Value);
71+
72+
v->type = T_BitString;
73+
v->val.str = str;
74+
return v;
75+
}

src/include/nodes/nodes.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.149 2004/01/06 23:55:19 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.150 2004/01/07 18:43:36 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -175,16 +175,20 @@ typedef enum NodeTag
175175
T_AllocSetContext,
176176

177177
/*
178-
* TAGS FOR VALUE NODES (pg_list.h)
178+
* TAGS FOR VALUE NODES (value.h)
179179
*/
180180
T_Value = 650,
181-
T_List,
182181
T_Integer,
183182
T_Float,
184183
T_String,
185184
T_BitString,
186185
T_Null,
187186

187+
/*
188+
* TAGS FOR LIST NODES (pg_list.h)
189+
*/
190+
T_List,
191+
188192
/*
189193
* TAGS FOR PARSE TREE NODES (parsenodes.h)
190194
*/

src/include/nodes/pg_list.h

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*-------------------------------------------------------------------------
22
*
33
* pg_list.h
4-
* POSTGRES generic list package
4+
* interface for PostgreSQL generic linked list package
55
*
66
*
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.42 2003/11/29 22:41:06 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.43 2004/01/07 18:43:36 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -21,44 +21,6 @@
2121
* ----------------------------------------------------------------
2222
*/
2323

24-
/*----------------------
25-
* Value node
26-
*
27-
* The same Value struct is used for five node types: T_Integer,
28-
* T_Float, T_String, T_BitString, T_Null.
29-
*
30-
* Integral values are actually represented by a machine integer,
31-
* but both floats and strings are represented as strings.
32-
* Using T_Float as the node type simply indicates that
33-
* the contents of the string look like a valid numeric literal.
34-
*
35-
* (Before Postgres 7.0, we used a double to represent T_Float,
36-
* but that creates loss-of-precision problems when the value is
37-
* ultimately destined to be converted to NUMERIC. Since Value nodes
38-
* are only used in the parsing process, not for runtime data, it's
39-
* better to use the more general representation.)
40-
*
41-
* Note that an integer-looking string will get lexed as T_Float if
42-
* the value is too large to fit in a 'long'.
43-
*
44-
* Nulls, of course, don't need the value part at all.
45-
*----------------------
46-
*/
47-
typedef struct Value
48-
{
49-
NodeTag type; /* tag appropriately (eg. T_String) */
50-
union ValUnion
51-
{
52-
long ival; /* machine integer */
53-
char *str; /* string */
54-
} val;
55-
} Value;
56-
57-
#define intVal(v) (((Value *)(v))->val.ival)
58-
#define floatVal(v) atof(((Value *)(v))->val.str)
59-
#define strVal(v) (((Value *)(v))->val.str)
60-
61-
6224
/*----------------------
6325
* List node
6426
*
@@ -150,15 +112,6 @@ typedef struct FastList
150112
#define makeFastList1(fl, x1) \
151113
( (fl)->head = (fl)->tail = makeList1(x1) )
152114

153-
154-
/*
155-
* function prototypes in nodes/list.c
156-
*/
157-
extern Value *makeInteger(long i);
158-
extern Value *makeFloat(char *numericStr);
159-
extern Value *makeString(char *str);
160-
extern Value *makeBitString(char *str);
161-
162115
extern List *lcons(void *datum, List *list);
163116
extern List *lconsi(int datum, List *list);
164117
extern List *lconso(Oid datum, List *list);

src/include/nodes/primnodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.93 2003/11/29 22:41:06 pgsql Exp $
13+
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.94 2004/01/07 18:43:36 neilc Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -19,6 +19,7 @@
1919

2020
#include "access/attnum.h"
2121
#include "nodes/pg_list.h"
22+
#include "nodes/value.h"
2223

2324

2425
/* ----------------------------------------------------------------

src/include/nodes/value.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* value.h
4+
* interface for Value nodes
5+
*
6+
*
7+
* Copyright (c) 2003, PostgreSQL Global Development Group
8+
*
9+
* $PostgreSQL: pgsql/src/include/nodes/value.h,v 1.1 2004/01/07 18:43:36 neilc Exp $
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
#include "nodes/nodes.h"
15+
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+
49+
#define intVal(v) (((Value *)(v))->val.ival)
50+
#define floatVal(v) atof(((Value *)(v))->val.str)
51+
#define strVal(v) (((Value *)(v))->val.str)
52+
53+
extern Value *makeInteger(long i);
54+
extern Value *makeFloat(char *numericStr);
55+
extern Value *makeString(char *str);
56+
extern Value *makeBitString(char *str);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy