Skip to content

Commit 55af9d8

Browse files
committed
8366837: Clean up gensrc by spp.Spp
Reviewed-by: erikj
1 parent 323b020 commit 55af9d8

File tree

9 files changed

+759
-798
lines changed

9 files changed

+759
-798
lines changed

make/common/Utils.gmk

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,42 @@ uppercase = \
5555
$(uppercase_result) \
5656
)
5757

58+
lowercase_table := A,a B,b C,c D,d E,e F,f G,g H,h I,i J,j K,k L,l M,m N,n O,o \
59+
P,p Q,q R,r S,s T,t U,u V,v W,w X,x Y,y Z,z
60+
61+
lowercase_internal = \
62+
$(if $(strip $1), $$(subst $(firstword $1), $(call lowercase_internal, \
63+
$(wordlist 2, $(words $1), $1), $2)), $2)
64+
65+
# Convert a string to lower case. Works only on a-z.
66+
# $1 - The string to convert
67+
lowercase = \
68+
$(strip \
69+
$(eval lowercase_result := $(call lowercase_internal, $(lowercase_table), $1)) \
70+
$(lowercase_result) \
71+
)
72+
73+
lowercase_letters := a b c d e f g h i j k l m n o p q r s t u v w x y z
74+
uppercase_letters := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
75+
76+
titlecase_internal = \
77+
$(strip $(or \
78+
$(strip $(foreach l, $(lowercase_letters) $(uppercase_letters), \
79+
$(if $(filter $l%, $1), \
80+
$(call uppercase, $l)$(call lowercase, $(patsubst $l%,%,$1))))), \
81+
$1))
82+
83+
# Convert a string to Title Case. Works only on a-z.
84+
# $1 - The string to convert
85+
titlecase = \
86+
$(strip $(foreach w, $1, $(call titlecase_internal, $w)))
87+
88+
# Returns the first character of a string. Works only on a-z.
89+
# $1 - The string to extract the first character from
90+
firstchar = \
91+
$(strip $(foreach l, $(lowercase_letters) $(uppercase_letters), \
92+
$(if $(filter $l%, $(firstword $1)), $l)))
93+
5894
################################################################################
5995
# Creates a sequence of increasing numbers (inclusive).
6096
# Param 1 - starting number
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
#
2+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
#
5+
# This code is free software; you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License version 2 only, as
7+
# published by the Free Software Foundation. Oracle designates this
8+
# particular file as subject to the "Classpath" exception as provided
9+
# by Oracle in the LICENSE file that accompanied this code.
10+
#
11+
# This code is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
# version 2 for more details (a copy is included in the LICENSE file that
15+
# accompanied this code).
16+
#
17+
# You should have received a copy of the GNU General Public License version
18+
# 2 along with this work; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
#
21+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
# or visit www.oracle.com if you need additional information or have any
23+
# questions.
24+
#
25+
26+
include MakeIncludeStart.gmk
27+
ifeq ($(INCLUDE), true)
28+
29+
################################################################################
30+
# This file defines macros that sets up rules for running the spp.Spp build tool
31+
################################################################################
32+
33+
include Execute.gmk
34+
include $(TOPDIR)/make/ToolsJdk.gmk
35+
36+
NON_BYTE_NUMBER_TYPES := char short int long float double
37+
NUMBER_TYPES := byte $(NON_BYTE_NUMBER_TYPES)
38+
PRIMITIVE_TYPES := boolean $(NUMBER_TYPES)
39+
40+
################################################################################
41+
# The Conv function converts a type given as first argument (as a normal Java
42+
# native type name), into one of several corresponding strings, depending on
43+
# the aspect given in the second argument
44+
#
45+
# The implementation dispatches the call to one of several Conv_<aspect> macros.
46+
#
47+
# arg $1: the type to convert
48+
# arg $2: the aspect to convert for
49+
# arg $3: byte order (only needed for certain aspects)
50+
#
51+
Conv = \
52+
$(strip $(call Conv_$(strip $2),$(strip $1),$(strip $3)))
53+
54+
################################################################################
55+
# Conv_<aspect> implementations
56+
57+
# Return a single letter representing the type (lowercase first letter)
58+
Conv_x = \
59+
$(call firstchar, $1)
60+
61+
# Return capitalized type name
62+
Conv_Type = \
63+
$(call titlecase, $1)
64+
65+
# Return the full descriptive name of the type, e.g. int -> integer
66+
Conv_fulltype = \
67+
$(if $(filter char, $1), \
68+
character, \
69+
$(if $(filter int, $1), \
70+
integer, \
71+
$1 \
72+
) \
73+
)
74+
75+
# Return the capitalized full descriptive name of the type, e.g. int -> Integer
76+
Conv_Fulltype = \
77+
$(call titlecase, $(call Conv_fulltype, $1))
78+
79+
# Return log2 bits per value (0-3)
80+
Conv_LBPV = \
81+
$(if $(filter byte, $1), \
82+
0, \
83+
$(if $(filter char short, $1), \
84+
1, \
85+
$(if $(filter int float, $1), \
86+
2, \
87+
$(if $(filter long double, $1), \
88+
3))))
89+
90+
# Return float or int category
91+
Conv_category = \
92+
$(if $(filter float double, $1), \
93+
floatingPointType, \
94+
integralType \
95+
)
96+
97+
# Return stream information for char
98+
Conv_streams = \
99+
$(if $(filter char, $1), streamableType)
100+
101+
# Return stream type information for char
102+
Conv_streamtype = \
103+
$(if $(filter char, $1), int)
104+
105+
# Return capitalized stream type information for char
106+
Conv_Streamtype = \
107+
$(if $(filter char, $1), Int)
108+
109+
# Return article to use for type in English text
110+
Conv_a = \
111+
$(if $(filter int, $1), an, a)
112+
113+
# Return capitalized article to use for type in English text
114+
Conv_A = \
115+
$(if $(filter int, $1), An, A)
116+
117+
# Return integer type with same size as the type
118+
Conv_memtype = \
119+
$(if $(filter float, $1), int, $(if $(filter double, $1), long, $1))
120+
121+
# Return capitalized integer type with same size as the type
122+
Conv_Memtype = \
123+
$(call titlecase, $(call Conv, $1, memtype))
124+
125+
# Return capitalized full descriptive name for integer type with same size as the type
126+
Conv_FullMemtype = \
127+
$(call Conv, $(call Conv, $1, memtype), Fulltype)
128+
129+
# Return Type or Memtype depending on byte order
130+
# arg $2: BYTE_ORDER
131+
Conv_Swaptype = \
132+
$(if $(filter U, $2), \
133+
$(call Conv, $1, Type), \
134+
$(call Conv, $1, Memtype))
135+
136+
# Return fromBits method name for floating types, depending on byte order
137+
# arg $2: BYTE_ORDER
138+
Conv_fromBits = \
139+
$(if $(filter float double, $1), \
140+
$(if $(filter U, $2), , \
141+
$(call Conv, $1, Type).$(call Conv, $1, memtype)BitsTo$(call Conv, $1, Type)))
142+
143+
# Return toBits method name for floating types, depending on byte order
144+
# arg $2: BYTE_ORDER
145+
Conv_toBits = \
146+
$(if $(filter float double, $1), \
147+
$(if $(filter U, $2), , \
148+
$(call Conv, $1, Type).$1ToRaw$(call Conv, $(call Conv, $1, memtype), Type)Bits))
149+
150+
# Return swap method name, depending on byte order
151+
# arg $2: BYTE_ORDER
152+
Conv_swap = \
153+
$(if $(filter S, $2), Bits.swap)
154+
155+
# Return word describing the number of bytes required by type
156+
Conv_nbytes = \
157+
$(if $(filter 0, $(call Conv, $1, LBPV)), one, \
158+
$(if $(filter 1, $(call Conv, $1, LBPV)), two, \
159+
$(if $(filter 2, $(call Conv, $1, LBPV)), four, \
160+
$(if $(filter 3, $(call Conv, $1, LBPV)), eight))))
161+
162+
# Return word describing the number of bytes required by type, minus one
163+
Conv_nbytesButOne = \
164+
$(if $(filter 0, $(call Conv, $1, LBPV)), zero, \
165+
$(if $(filter 1, $(call Conv, $1, LBPV)), one, \
166+
$(if $(filter 2, $(call Conv, $1, LBPV)), three, \
167+
$(if $(filter 3, $(call Conv, $1, LBPV)), seven))))
168+
169+
################################################################################
170+
# Setup make rules that runs the spp.Spp build tool on an input file.
171+
#
172+
# Parameter 1 is the name of the rule. This name is used as variable prefix,
173+
# and the targets generated are listed in a variable by that name.
174+
#
175+
# Remaining parameters are named arguments. These include:
176+
# BEGIN_END Set to true to exclude everything outside #begin/#end (default: false)
177+
# SUBST_EMPTY_LINES Set to false to not generate empty lines for removed lines (default: true)
178+
# SOURCE_FILE The input file to process (required)
179+
# OUTPUT_FILE The output file (required)
180+
# INFO Override default message to print (optional)
181+
# KEYS One or more keys to control the generation (optional)
182+
# REPLACEMENTS one or more text replacement patterns, using the syntax:
183+
# VAR=VALUE [VAR=VALUE] ...
184+
#
185+
SetupStreamPreProcessing = $(NamedParamsMacroTemplate)
186+
define SetupStreamPreProcessingBody
187+
# Verify arguments
188+
ifeq ($$($1_SOURCE_FILE), )
189+
$$(error Must specify SOURCE_FILE (in $1))
190+
endif
191+
ifeq ($$($1_OUTPUT_FILE), )
192+
$$(error Must specify OUTPUT_FILE (in $1))
193+
endif
194+
195+
$1_COMMAND_LINE :=
196+
ifeq ($$($1_BEGIN_END), true)
197+
$1_COMMAND_LINE += -be
198+
endif
199+
200+
ifeq ($$($1_SUBST_EMPTY_LINES), false)
201+
$1_COMMAND_LINE += -nel
202+
endif
203+
204+
$1_COMMAND_LINE += $$(foreach k, $$($1_KEYS), -K$$k)
205+
$1_COMMAND_LINE += $$(subst $$$$(SPACE), ,$$(foreach d, $$($1_REPLACEMENTS), -D$$d))
206+
207+
$1_COMMAND_LINE += -i$$($1_SOURCE_FILE) -o$$($1_OUTPUT_FILE).tmp
208+
209+
ifeq ($$($1_INFO), )
210+
$1_INFO := Preprocessing $$(notdir $$($1_SOURCE_FILE)) for $(MODULE)
211+
endif
212+
213+
$$(eval $$(call SetupExecute, RUN_SPP_$1, \
214+
INFO := $$($1_INFO), \
215+
DEPS := $$($1_SOURCE_FILE) $$(BUILD_TOOLS_JDK), \
216+
OUTPUT_FILE := $$($1_OUTPUT_FILE), \
217+
COMMAND := $$(TOOL_SPP) $$($1_COMMAND_LINE), \
218+
PRE_COMMAND := $$(RM) $$($1_OUTPUT_FILE).tmp $$($1_OUTPUT_FILE), \
219+
POST_COMMAND := $$(MV) $$($1_OUTPUT_FILE).tmp $$($1_OUTPUT_FILE), \
220+
))
221+
222+
$1 += $$(RUN_SPP_$1)
223+
endef
224+
225+
################################################################################
226+
227+
endif # include guard
228+
include MakeIncludeEnd.gmk

make/modules/java.base/Gensrc.gmk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
################################################################################
2727

2828
include GensrcCommon.gmk
29+
include GensrcProperties.gmk
30+
include GensrcStreamPreProcessing.gmk
2931

3032
include gensrc/GensrcBuffer.gmk
3133
include gensrc/GensrcCharacterData.gmk
@@ -71,8 +73,6 @@ TARGETS += $(CLDR_GEN_DONE)
7173

7274
################################################################################
7375

74-
include GensrcProperties.gmk
75-
7676
$(eval $(call SetupCompileProperties, LIST_RESOURCE_BUNDLE, \
7777
SRC_DIRS := $(MODULE_SRC)/share/classes/sun/launcher/resources, \
7878
CLASS := ListResourceBundle, \

0 commit comments

Comments
 (0)