-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8358772: Template-Framework Library: Primitive Types #25672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
eme64
wants to merge
16
commits into
openjdk:master
from
eme64:JDK-8358772-TemplateFramework-types-operations-expressions
Closed
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
98ba68d
JDK-8358772
eme64 4def43a
types
eme64 16527d0
add test, does not compile now
eme64 c377093
update tests
eme64 fe28093
size and boxing
eme64 4cf7a29
wip test
eme64 e32f0a5
improve test
eme64 e34301b
documentation
eme64 3971082
rm unnecessary file
eme64 ff76272
rm previous changes
eme64 08b9f67
parser refactor
eme64 2deca27
Apply suggestions from code review
eme64 4c8d631
Apply suggestions from code review
eme64 a1c84e8
review suggestions applied
eme64 c39d4d6
rm static final
eme64 b07f752
Merge branch 'master' into JDK-8358772-TemplateFramework-types-operat…
eme64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/hotspot/jtreg/compiler/lib/template_framework/TokenParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package compiler.lib.template_framework; | ||
|
||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Helper class for {@link Token}, to keep the parsing methods package private. | ||
* | ||
* <p> | ||
* The {@link Template#body} and {@link Hook#anchor} are given a list of tokens, which are either | ||
* {@link Token}s or {@link String}s or some permitted boxed primitives. These are then parsed | ||
* and all non-{@link Token}s are converted to {@link StringToken}s. The parsing also flattens | ||
* {@link List}s. | ||
*/ | ||
final class TokenParser { | ||
static List<Token> parse(Object[] objects) { | ||
if (objects == null) { | ||
throw new IllegalArgumentException("Unexpected tokens: null"); | ||
} | ||
List<Token> outputList = new ArrayList<>(); | ||
parseToken(Arrays.asList(objects), outputList); | ||
return outputList; | ||
} | ||
|
||
private static void parseList(List<?> inputList, List<Token> outputList) { | ||
for (Object o : inputList) { | ||
parseToken(o, outputList); | ||
} | ||
} | ||
|
||
private static void parseToken(Object o, List<Token> outputList) { | ||
if (o == null) { | ||
throw new IllegalArgumentException("Unexpected token: null"); | ||
} | ||
switch (o) { | ||
case Token t -> outputList.add(t); | ||
case String s -> outputList.add(new StringToken(Renderer.format(s))); | ||
case Integer s -> outputList.add(new StringToken(Renderer.format(s))); | ||
case Long s -> outputList.add(new StringToken(Renderer.format(s))); | ||
case Double s -> outputList.add(new StringToken(Renderer.format(s))); | ||
case Float s -> outputList.add(new StringToken(Renderer.format(s))); | ||
case Boolean s -> outputList.add(new StringToken(Renderer.format(s))); | ||
case List<?> l -> parseList(l, outputList); | ||
default -> throw new IllegalArgumentException("Unexpected token: " + o); | ||
} | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
test/hotspot/jtreg/compiler/lib/template_framework/library/CodeGenerationDataNameType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package compiler.lib.template_framework.library; | ||
|
||
import java.util.List; | ||
|
||
import compiler.lib.template_framework.DataName; | ||
import compiler.lib.template_framework.Template; | ||
|
||
/** | ||
* The {@link CodeGenerationDataNameType} extends the {@link DataName.Type} with | ||
* additional functionality for code generation. These types with their extended | ||
* functionality can be used with many other code generation facilities in the | ||
* lbrary, such as generating random {@code Expression}s. | ||
eme64 marked this conversation as resolved.
Show resolved
Hide resolved
eme64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public interface CodeGenerationDataNameType extends DataName.Type { | ||
|
||
/** | ||
* This method provides a random constant value for the type, which can | ||
* be used as a token inside a {@link Template}. | ||
* | ||
* @return A random constant value. | ||
*/ | ||
public Object con(); | ||
eme64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The byte {@link PrimitiveType}. | ||
* | ||
* @return The byte {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType bytes() { return PrimitiveType.BYTES; } | ||
|
||
/** | ||
* The short {@link PrimitiveType}. | ||
* | ||
* @return The short {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType shorts() { return PrimitiveType.SHORTS; } | ||
|
||
/** | ||
* The char {@link PrimitiveType}. | ||
* | ||
* @return The char {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType chars() { return PrimitiveType.CHARS; } | ||
|
||
/** | ||
* The int {@link PrimitiveType}. | ||
* | ||
* @return The int {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType ints() { return PrimitiveType.INTS; } | ||
|
||
/** | ||
* The long {@link PrimitiveType}. | ||
* | ||
* @return The long {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType longs() { return PrimitiveType.LONGS; } | ||
|
||
/** | ||
* The float {@link PrimitiveType}. | ||
* | ||
* @return The float {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType floats() { return PrimitiveType.FLOATS; } | ||
|
||
/** | ||
* The double {@link PrimitiveType}. | ||
* | ||
* @return The double {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType doubles() { return PrimitiveType.DOUBLES; } | ||
|
||
/** | ||
* The boolean {@link PrimitiveType}. | ||
* | ||
* @return The boolean {@link PrimitiveType}. | ||
*/ | ||
public static PrimitiveType booleans() { return PrimitiveType.BOOLEANS; } | ||
|
||
/** | ||
* List of all {@link PrimitiveType}s. | ||
*/ | ||
public static final List<PrimitiveType> PRIMITIVE_TYPES = List.of( | ||
eme64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bytes(), | ||
chars(), | ||
shorts(), | ||
ints(), | ||
longs(), | ||
floats(), | ||
doubles(), | ||
booleans() | ||
); | ||
|
||
/** | ||
* List of all integral {@link PrimitiveType}s (byte, char, short, int, long). | ||
*/ | ||
public static final List<PrimitiveType> INTEGRAL_TYPES = List.of( | ||
bytes(), | ||
chars(), | ||
shorts(), | ||
ints(), | ||
longs() | ||
); | ||
|
||
/** | ||
* List of all subword {@link PrimitiveType}s (byte, char, short). | ||
*/ | ||
public static final List<PrimitiveType> SUBWORD_TYPES = List.of( | ||
bytes(), | ||
chars(), | ||
shorts() | ||
); | ||
|
||
/** | ||
* List of all floating {@link PrimitiveType}s (float, double). | ||
*/ | ||
public static final List<PrimitiveType> FLOATING_TYPES = List.of( | ||
floats(), | ||
doubles() | ||
); | ||
|
||
/** | ||
* List of all integral and floating {@link PrimitiveType}s. | ||
*/ | ||
public static final List<PrimitiveType> INTEGRAL_AND_FLOATING_TYPES = List.of( | ||
bytes(), | ||
chars(), | ||
shorts(), | ||
ints(), | ||
longs(), | ||
floats(), | ||
doubles() | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.