Skip to content

Commit

Permalink
7902688: Asmtools support for JEP 360: changing the name from SealedT…
Browse files Browse the repository at this point in the history
…ypes to SealedClasses
  • Loading branch information
lkuskov committed Jun 4, 2020
1 parent 656d105 commit 176446e
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/org/openjdk/asmtools/jasm/ClassArrayAttr.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
* }
* <p>
* JEP 360 (Sealed types): class file 59.65535
* PermittedSubtypes_attribute {
* PermittedSubclasses_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 permitted_subtypes_count;
* u2 classes[permitted_subtypes_count];
* u2 number_of_classes;
* u2 classes[number_of_classes];
* }
*/
public class ClassArrayAttr extends AttrData {
Expand Down
16 changes: 8 additions & 8 deletions src/org/openjdk/asmtools/jasm/ClassData.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class ClassData extends MemberData {
// JEP 359 - Record attribute since class file 58.65535
private RecordData recordData;

// JEP 360 - PermittedSubtypes attribute since class file 59.65535
private PermittedTypesAttr permittedTypesAttr;
// JEP 360 - PermittedSubclasses attribute since class file 59.65535
private PermittedSubclassesAttr permittedSubclassesAttr;

ModuleAttr moduleAttribute = null;
Environment env;
Expand Down Expand Up @@ -311,9 +311,9 @@ public void addNestMembers(List<ConstantPool.ConstCell> classes) {
nestMembersAttr = new NestMembersAttr(this, classes);
}

public void addPermittedSubtypes(List<ConstantPool.ConstCell> classes) {
env.traceln("addPermittedSubtypes");
permittedTypesAttr = new PermittedTypesAttr(this, classes);
public void addPermittedSubclasses(List<ConstantPool.ConstCell> classes) {
env.traceln("addPermittedSubclasses");
permittedSubclassesAttr = new PermittedSubclassesAttr(this, classes);
}


Expand Down Expand Up @@ -459,8 +459,8 @@ protected DataVector getAttrVector() {
if(nestMembersAttributesExist())
attrs.add(nestMembersAttr);
// since class version 59.65535 (JEP 360)
if ( permittedSubtypesAttributesExist() )
attrs.add(permittedTypesAttr);
if ( permittedSubclassesAttributesExist() )
attrs.add(permittedSubclassesAttr);
}
return attrs;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ public boolean nestHostAttributeExists() {

public boolean nestMembersAttributesExist() { return nestMembersAttr != null; }

public boolean permittedSubtypesAttributesExist() { return permittedTypesAttr != null; }
public boolean permittedSubclassesAttributesExist() { return permittedSubclassesAttr != null; }

public boolean recordAttributeExists() { return recordData != null; }

Expand Down
2 changes: 1 addition & 1 deletion src/org/openjdk/asmtools/jasm/JasmTokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public enum Token {
RECORD (175, "RECORD", "Record", EnumSet.of(TokenType.DECLARATION, TokenType.JASM_IDENT, TokenType.MODULE_NAME ), KeywordType.KEYWORD),
COMPONENT (176, "COMPONENT", "Component", EnumSet.of(TokenType.DECLARATION, TokenType.JASM_IDENT, TokenType.MODULE_NAME ), KeywordType.KEYWORD),
//
PERMITTEDSUBTYPES (177, "PERMITTEDSUBTYPES", "PermittedSubtypes", EnumSet.of(TokenType.DECLARATION, TokenType.JASM_IDENT, TokenType.MODULE_NAME ), KeywordType.KEYWORD),
PERMITTEDSUBCLASSES (177, "PERMITTEDSUBCLASSES", "PermittedSubclasses", EnumSet.of(TokenType.DECLARATION, TokenType.JASM_IDENT, TokenType.MODULE_NAME ), KeywordType.KEYWORD),

//Module statements
REQUIRES (180, "REQUIRES", "requires", EnumSet.of(TokenType.DECLARATION, TokenType.JASM_IDENT, TokenType.MODULE_NAME ), KeywordType.KEYWORD),
Expand Down
14 changes: 7 additions & 7 deletions src/org/openjdk/asmtools/jasm/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ ConstCell parseName() throws Scanner.SyntaxError, IOException {
case INNER_TYPE_TYPEPATH:
case WILDCARD_TYPEPATH:
case TYPE_ARGUMENT_TYPEPATH:
case PERMITTEDSUBTYPES:
case PERMITTEDSUBCLASSES:
case INF:
case NAN:
case COMPONENT:
Expand Down Expand Up @@ -466,7 +466,7 @@ ConstCell parseClassName(boolean uncond) throws Scanner.SyntaxError, IOException
case INNER_TYPE_TYPEPATH:
case WILDCARD_TYPEPATH:
case TYPE_ARGUMENT_TYPEPATH:
case PERMITTEDSUBTYPES:
case PERMITTEDSUBCLASSES:
case INF:
case NAN:
case COMPONENT:
Expand Down Expand Up @@ -965,13 +965,13 @@ private void parseNestHost() throws Scanner.SyntaxError, IOException {
}

/**
* Parse a list of classes belonging to the [NestMembers | PermittedSubtypes] entry
* Parse a list of classes belonging to the [NestMembers | PermittedSubclasses] entry
*/
private void parseClasses(Consumer<ArrayList<ConstCell>> classesConsumer)
throws Scanner.SyntaxError, IOException {
ArrayList<ConstCell> classes = new ArrayList<>();
// Parses in the form:
// (NESTMEMBERS|PERMITTEDSUBTYPES)? IDENT(, IDENT)*;
// (NESTMEMBERS|PERMITTEDSUBCLASSES)? IDENT(, IDENT)*;
debugStr(" [Parser.parseClasses]: <<<Begin>>>");
while (true) {
String className = prependPackage(parseIdent(), true);
Expand Down Expand Up @@ -1757,13 +1757,13 @@ private void parseClassMembers() throws IOException {
scanner.scan();
parseClasses(list -> cd.addNestMembers(list));
break;
case PERMITTEDSUBTYPES: // JEP 360
case PERMITTEDSUBCLASSES: // JEP 360
if (cd.nestMembersAttributesExist()) {
env.error(scanner.pos, "extra.permittedsubtypes.attribute");
env.error(scanner.pos, "extra.permittedsubclasses.attribute");
throw new Scanner.SyntaxError();
}
scanner.scan();
parseClasses(list -> cd.addPermittedSubtypes(list));
parseClasses(list -> cd.addPermittedSubclasses(list));
break;
case RECORD: // JEP 359
if (cd.recordAttributeExists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
/**
* The "classes[]" data of attributes
* JEP 360 (Sealed types): class file 59.65535
* PermittedSubtypes_attribute {
* PermittedSubclasses_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 permitted_subtypes_count;
* u2 classes[permitted_subtypes_count];
* u2 number_of_classes;
* u2 classes[number_of_classes];
* }
*/
public class PermittedTypesAttr extends ClassArrayAttr {
public PermittedTypesAttr(ClassData cdata, List<ConstantPool.ConstCell> classes) {
super(Tables.AttrTag.ATT_PermittedSubtypes.parsekey(), cdata, classes);
public class PermittedSubclassesAttr extends ClassArrayAttr {
public PermittedSubclassesAttr(ClassData cdata, List<ConstantPool.ConstCell> classes) {
super(Tables.AttrTag.ATT_PermittedSubclasses.parsekey(), cdata, classes);
}
}
8 changes: 4 additions & 4 deletions src/org/openjdk/asmtools/jasm/Tables.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ static public enum AttrTag {
// }
ATT_Record (34, "ATT_Record", "Record"),
// JEP 360 (Sealed types): class file 59.65535
// PermittedSubtypes_attribute {
// PermittedSubclasses_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
// u2 permitted_subtypes_count;
// u2 classes[permitted_subtypes_count];
// u2 number_of_classes;
// u2 classes[number_of_classes];
// }
ATT_PermittedSubtypes (35, "ATT_PermittedSubtypes", "PermittedSubtypes");
ATT_PermittedSubclasses (35, "ATT_PermittedSubclasses", "PermittedSubclasses");

private final Integer value;
private final String printval;
Expand Down
2 changes: 1 addition & 1 deletion src/org/openjdk/asmtools/jasm/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ err.token.expected={0} expected.
err.identifier.expected=Identifier expected.
err.extra.nesthost.attribute=There may be at most one NestHost attribute.
err.extra.nestmembers.attribute=There may be at most one NestMembers attribute.
err.extra.permittedsubtypes.attribute=There may be at most one PermittedSubtypes attribute.
err.extra.permittedsubclasses.attribute=There may be at most one PermittedSubclasses attribute.
err.extra.record.attribute=There may be at most one Record attribute.
err.grouped.component.expected=Either an annotation or a record component expected.
warn.no.components.in.record.attribute=Record should have at least one component.
Expand Down
8 changes: 4 additions & 4 deletions src/org/openjdk/asmtools/jdec/ClassData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1008,13 +1008,13 @@ private void decodeAttr(DataInputStream in, PrintWriter out) throws IOException
// }
case ATT_NestMembers:
// JEP 360 (Sealed types): class file 59.65535
// PermittedSubtypes_attribute {
// PermittedSubclasses_attribute {
// u2 attribute_name_index;
// u4 attribute_length;
// u2 permitted_subtypes_count;
// u2 classes[permitted_subtypes_count];
// u2 number_of_classes;
// u2 classes[number_of_classes];
// }
case ATT_PermittedSubtypes:
case ATT_PermittedSubclasses:
int nsubtypes = in.readUnsignedShort();
startArrayCmt(nsubtypes, "classes");
try {
Expand Down
10 changes: 5 additions & 5 deletions src/org/openjdk/asmtools/jdis/ClassArrayData.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
* }
* <p>
* JEP 360 (Sealed types): class file 59.65535
* PermittedSubtypes_attribute {
* PermittedSubclasses_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 permitted_subtypes_count;
* u2 classes[permitted_subtypes_count];
* u2 number_of_classes;
* u2 classes[number_of_classes];
* }
* </p>
*/
public class ClassArrayData {
public class ClassArrayData extends Indenter {
String name;
ClassData cls;
int[] classes;
Expand All @@ -72,7 +72,7 @@ public void print() {
String indexes = "";
String names = "";
boolean pr_cpx = options.contains(Options.PR.CPX);
cls.out.print(name + " ");
cls.out.print(getIndentString() + name + " ");
for (int i = 0; i < classes.length; i++) {
if (pr_cpx) {
indexes += (indexes.isEmpty() ? "" : ", ") + "#" + classes[i];
Expand Down
16 changes: 8 additions & 8 deletions src/org/openjdk/asmtools/jdis/ClassData.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public class ClassData extends MemberData {
// The NestMembers of this class (since class file: 55.0)
protected NestMembersData nestMembers;

// The PermittedSubtypes of this class (JEP 360 (Sealed types): class file 59.65535)
protected PermittedSubtypesData permittedSubtypes;
// The PermittedSubclasses of this class (JEP 360 (Sealed types): class file 59.65535)
protected PermittedSubclassesData permittedSubclassesData;

// other parsing fields
protected PrintWriter out;
Expand Down Expand Up @@ -228,9 +228,9 @@ protected boolean handleAttributes(DataInputStream in, AttrTag attrtag, int attr
case ATT_Record:
record = new RecordData(this).read(in);
break;
case ATT_PermittedSubtypes:
// Read PermittedSubtypes Attribute (JEP 360 (Sealed types): class file 59.65535)
permittedSubtypes = new PermittedSubtypesData(this).read(in, attrlen);
case ATT_PermittedSubclasses:
// Read PermittedSubclasses Attribute (JEP 360 (Sealed types): class file 59.65535)
permittedSubclassesData = new PermittedSubclassesData(this).read(in, attrlen);
break;
default:
handled = false;
Expand Down Expand Up @@ -448,9 +448,9 @@ public void print() throws IOException {
record.print();
}

// Print PermittedSubtypes Attribute (JEP 360 (Sealed types): class file 59.65535)
if( permittedSubtypes != null) {
permittedSubtypes.print();
// Print PermittedSubclasses Attribute (JEP 360 (Sealed types): class file 59.65535)
if( permittedSubclassesData != null) {
permittedSubclassesData.print();
}
// Print the NestHost (since class file: 55.0)
if(nestHost != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
import java.io.IOException;

/**
* The NestMembers attribute data
* The PermittedSubclasses attribute data
* <p>
* JEP 360 (Sealed types): class file 59.65535
* PermittedSubtypes_attribute {
* PermittedSubclasses_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 permitted_subtypes_count;
* u2 classes[permitted_subtypes_count];
* u2 number_of_classes;
* u2 classes[number_of_classes];
* }
*/
public class PermittedSubtypesData extends ClassArrayData {
public PermittedSubtypesData(ClassData cls) {
super(cls, JasmTokens.Token.PERMITTEDSUBTYPES.parseKey());
public class PermittedSubclassesData extends ClassArrayData {
public PermittedSubclassesData(ClassData cls) {
super(cls, JasmTokens.Token.PERMITTEDSUBCLASSES.parseKey());
}

public PermittedSubtypesData read(DataInputStream in, int attribute_length) throws IOException, ClassFormatError {
return (PermittedSubtypesData) super.read(in, attribute_length);
public PermittedSubclassesData read(DataInputStream in, int attribute_length) throws IOException, ClassFormatError {
return (PermittedSubclassesData) super.read(in, attribute_length);
}
}

0 comments on commit 176446e

Please sign in to comment.