Skip to content

Commit 8d420f8

Browse files
committedJan 18, 2025·
Bunch of formatting.
Add in a ClassFileParseOption for StaticImport so we can start cutting down on the ifdefs.
1 parent 2c0baab commit 8d420f8

20 files changed

+80
-216
lines changed
 

‎src/IKVM.Runtime/ClassFile.BootstrapMethod.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,18 @@ sealed partial class ClassFile
3333
internal struct BootstrapMethod
3434
{
3535

36-
private MethodHandleConstantHandle method;
37-
private ConstantHandle[] args;
36+
MethodHandleConstantHandle method;
37+
ConstantHandle[] args;
3838

3939
internal BootstrapMethod(MethodHandleConstantHandle method, ConstantHandle[] args)
4040
{
4141
this.method = method;
4242
this.args = args;
4343
}
4444

45-
internal MethodHandleConstantHandle BootstrapMethodIndex
46-
{
47-
get { return method; }
48-
}
45+
internal MethodHandleConstantHandle BootstrapMethodIndex => method;
4946

50-
internal int ArgumentCount
51-
{
52-
get { return args.Length; }
53-
}
47+
internal int ArgumentCount => args.Length;
5448

5549
internal ConstantHandle GetArgument(int index)
5650
{

‎src/IKVM.Runtime/ClassFile.Constant.cs

-51
This file was deleted.

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemClass.cs

+20-35
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,33 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
8181
#if !IMPORTER
8282
if (classFile.MajorVersion < 49 && (options & ClassFileParseOptions.RelaxedClassNameValidation) == 0)
8383
{
84-
char prev = name[0];
85-
if (Char.IsLetter(prev) || prev == '$' || prev == '_' || prev == '[' || prev == '/')
84+
var prev = name[0];
85+
if (char.IsLetter(prev) || prev == '$' || prev == '_' || prev == '[' || prev == '/')
8686
{
8787
int skip = 1;
8888
int end = name.Length;
8989
if (prev == '[')
9090
{
9191
if (!IsValidFieldSig(name))
92-
{
93-
goto barf;
94-
}
92+
throw new ClassFormatError("Invalid class name \"{0}\"", name);
93+
9594
while (name[skip] == '[')
96-
{
9795
skip++;
98-
}
96+
9997
if (name.EndsWith(";"))
100-
{
10198
end--;
102-
}
10399
}
100+
104101
for (int i = skip; i < end; i++)
105102
{
106-
char c = name[i];
107-
if (!Char.IsLetterOrDigit(c) && c != '$' && c != '_' && (c != '/' || prev == '/'))
108-
{
109-
goto barf;
110-
}
103+
var c = name[i];
104+
if (!char.IsLetterOrDigit(c) && c != '$' && c != '_' && (c != '/' || prev == '/'))
105+
throw new ClassFormatError("Invalid class name \"{0}\"", name);
106+
111107
prev = c;
112108
}
113-
name = String.Intern(name.Replace('/', '.'));
109+
110+
name = string.Intern(name.Replace('/', '.'));
114111
return;
115112
}
116113
}
@@ -123,34 +120,26 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
123120
if (name[0] == '[')
124121
{
125122
if (!IsValidFieldSig(name))
126-
{
127-
goto barf;
128-
}
123+
throw new ClassFormatError("Invalid class name \"{0}\"", name);
124+
129125
// the semicolon is only allowed at the end and IsValidFieldSig enforces this,
130126
// but since invalidJava15Characters contains the semicolon, we decrement end
131127
// to make the following check against invalidJava15Characters ignore the
132128
// trailing semicolon.
133129
if (name[end - 1] == ';')
134-
{
135130
end--;
136-
}
131+
137132
while (name[start] == '[')
138-
{
139133
start++;
140-
}
141134
}
142135

143136
if (name.IndexOfAny(invalidJava15Characters, start, end - start) >= 0)
144-
{
145-
goto barf;
146-
}
137+
throw new ClassFormatError("Invalid class name \"{0}\"", name);
147138

148139
name = string.Intern(name.Replace('/', '.'));
149140
return;
150141
}
151142
}
152-
barf:
153-
throw new ClassFormatError("Invalid class name \"{0}\"", name);
154143
}
155144

156145
internal override void MarkLinkRequired()
@@ -168,7 +157,8 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
168157
if (typeWrapper == Context.VerifierJavaTypeFactory.Null)
169158
{
170159
var tw = thisType.ClassLoader.LoadClass(name, mode | LoadMode.WarnClassNotFound);
171-
#if !IMPORTER && !FIRST_PASS
160+
161+
#if IMPORTER == false && FIRST_PASS == false
172162
if (!tw.IsUnloadable)
173163
{
174164
try
@@ -181,17 +171,12 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
181171
}
182172
}
183173
#endif
174+
184175
typeWrapper = tw;
185176
}
186177
}
187178

188-
internal string Name
189-
{
190-
get
191-
{
192-
return name;
193-
}
194-
}
179+
internal string Name => name;
195180

196181
internal RuntimeJavaType GetClassType()
197182
{

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemDouble.cs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Jeroen Frijters
2424

2525
using System;
2626

27+
using IKVM.ByteCode;
2728
using IKVM.ByteCode.Decoding;
2829

2930
namespace IKVM.Runtime

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemFMI.cs

+7-25
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
6161
clazz = (ConstantPoolItemClass)classFile.GetConstantPoolItem(clazzHandle);
6262
// if the constant pool items referred to were strings, GetConstantPoolItem returns null
6363
if (name_and_type == null || clazz == null)
64-
{
6564
throw new ClassFormatError("Bad index in constant pool");
66-
}
6765

68-
name = String.Intern(classFile.GetConstantPoolUtf8String(utf8_cp, name_and_type.NameHandle));
66+
name = string.Intern(classFile.GetConstantPoolUtf8String(utf8_cp, name_and_type.NameHandle));
6967
descriptor = classFile.GetConstantPoolUtf8String(utf8_cp, name_and_type.DescriptorHandle);
7068
Validate(name, descriptor, classFile.MajorVersion);
71-
descriptor = String.Intern(descriptor.Replace('/', '.'));
69+
descriptor = string.Intern(descriptor.Replace('/', '.'));
7270
}
7371

7472
protected abstract void Validate(string name, string descriptor, int majorVersion);
@@ -83,37 +81,21 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
8381
clazz.Link(thisType, mode);
8482
}
8583

86-
internal string Name
87-
{
88-
get
89-
{
90-
return name;
91-
}
92-
}
84+
internal string Name => name;
9385

94-
internal string Signature
95-
{
96-
get
97-
{
98-
return descriptor;
99-
}
100-
}
86+
internal string Signature => descriptor;
10187

102-
internal string Class
103-
{
104-
get
105-
{
106-
return clazz.Name;
107-
}
108-
}
88+
internal string Class => clazz.Name;
10989

11090
internal RuntimeJavaType GetClassType()
11191
{
11292
return clazz.GetClassType();
11393
}
11494

11595
internal abstract RuntimeJavaMember GetMember();
96+
11697
}
98+
11799
}
118100

119101
}

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemFieldref.cs

+7-9
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
6767
{
6868
base.Link(thisType, mode);
6969
lock (this)
70-
{
7170
if (fieldTypeWrapper != null)
72-
{
7371
return;
74-
}
75-
}
72+
7673
RuntimeJavaField fw = null;
77-
RuntimeJavaType wrapper = GetClassType();
74+
var wrapper = GetClassType();
7875
if (wrapper == null)
79-
{
8076
return;
81-
}
77+
8278
if (!wrapper.IsUnloadable)
8379
{
8480
fw = wrapper.GetFieldWrapper(Name, Signature);
@@ -87,8 +83,10 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
8783
fw.Link(mode);
8884
}
8985
}
90-
RuntimeClassLoader classLoader = thisType.ClassLoader;
91-
RuntimeJavaType fld = classLoader.FieldTypeWrapperFromSig(this.Signature, mode);
86+
87+
var classLoader = thisType.ClassLoader;
88+
var fld = classLoader.FieldTypeWrapperFromSig(this.Signature, mode);
89+
9290
lock (this)
9391
{
9492
if (fieldTypeWrapper == null)

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemInterfaceMethodref.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,21 @@ internal ConstantPoolItemInterfaceMethodref(RuntimeContext context, InterfaceMet
4747
internal override void Link(RuntimeJavaType thisType, LoadMode mode)
4848
{
4949
base.Link(thisType, mode);
50-
RuntimeJavaType wrapper = GetClassType();
50+
51+
var wrapper = GetClassType();
5152
if (wrapper != null)
5253
{
5354
if (!wrapper.IsUnloadable)
54-
{
5555
method = wrapper.GetInterfaceMethod(Name, Signature);
56-
}
56+
5757
if (method == null)
5858
{
5959
// NOTE vmspec 5.4.3.4 clearly states that an interfacemethod may also refer to a method in Object
6060
method = thisType.Context.JavaBase.TypeOfJavaLangObject.GetMethodWrapper(Name, Signature, false);
6161
}
62+
6263
if (method != null)
63-
{
6464
method.Link(mode);
65-
}
6665
}
6766
}
6867

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemInvokeDynamic.cs

+4-18
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ Jeroen Frijters
2121
jeroen@frijters.net
2222
2323
*/
24-
using System;
25-
2624
using IKVM.ByteCode;
2725
using IKVM.ByteCode.Decoding;
2826

@@ -31,6 +29,7 @@ namespace IKVM.Runtime
3129

3230
sealed partial class ClassFile
3331
{
32+
3433
internal sealed class ConstantPoolItemInvokeDynamic : ConstantPoolItem
3534
{
3635

@@ -67,12 +66,8 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
6766
internal override void Link(RuntimeJavaType thisType, LoadMode mode)
6867
{
6968
lock (this)
70-
{
7169
if (argTypeWrappers != null)
72-
{
7370
return;
74-
}
75-
}
7671

7772
var classLoader = thisType.ClassLoader;
7873
var args = classLoader.ArgJavaTypeListFromSig(descriptor, mode);
@@ -98,20 +93,11 @@ internal RuntimeJavaType GetRetType()
9893
return retTypeWrapper;
9994
}
10095

101-
internal string Name
102-
{
103-
get { return name; }
104-
}
96+
internal string Name => name;
10597

106-
internal string Signature
107-
{
108-
get { return descriptor; }
109-
}
98+
internal string Signature => descriptor;
11099

111-
internal ushort BootstrapMethod
112-
{
113-
get { return bootstrapMethodAttributeIndex; }
114-
}
100+
internal ushort BootstrapMethod => bootstrapMethodAttributeIndex;
115101

116102
}
117103

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemLiveObject.cs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ internal override ConstantType GetConstantType()
4545
{
4646
return ConstantType.LiveObject;
4747
}
48+
4849
}
4950

5051
}

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemMI.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ internal ConstantPoolItemMI(RuntimeContext context, ClassConstantHandle clazz, N
5353
protected override void Validate(string name, string descriptor, int majorVersion)
5454
{
5555
if (!IsValidMethodSig(descriptor))
56-
{
5756
throw new ClassFormatError("Method {0} has invalid signature {1}", name, descriptor);
58-
}
57+
5958
if (!IsValidMethodName(name, new ClassFormatVersion((ushort)majorVersion, 0)))
6059
{
6160
if (!ReferenceEquals(name, StringConstants.INIT))
62-
{
6361
throw new ClassFormatError("Invalid method name \"{0}\"", name);
64-
}
62+
6563
if (!descriptor.EndsWith("V"))
66-
{
6764
throw new ClassFormatError("Method {0} has invalid signature {1}", name, descriptor);
68-
}
6965
}
7066
}
7167

@@ -79,9 +75,10 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
7975
return;
8076
}
8177
}
82-
RuntimeClassLoader classLoader = thisType.ClassLoader;
83-
RuntimeJavaType[] args = classLoader.ArgJavaTypeListFromSig(this.Signature, mode);
84-
RuntimeJavaType ret = classLoader.RetTypeWrapperFromSig(this.Signature, mode);
78+
79+
var classLoader = thisType.ClassLoader;
80+
var args = classLoader.ArgJavaTypeListFromSig(this.Signature, mode);
81+
var ret = classLoader.RetTypeWrapperFromSig(this.Signature, mode);
8582
lock (this)
8683
{
8784
if (argTypeWrappers == null)
@@ -116,7 +113,9 @@ internal override RuntimeJavaMember GetMember()
116113
{
117114
return method;
118115
}
116+
119117
}
118+
120119
}
121120

122121
}

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemMethodHandle.cs

+7-28
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,17 @@ internal override void MarkLinkRequired()
8585
cpi.MarkLinkRequired();
8686
}
8787

88-
internal string Class
89-
{
90-
get { return cpi.Class; }
91-
}
88+
internal string Class => cpi.Class;
9289

93-
internal string Name
94-
{
95-
get { return cpi.Name; }
96-
}
90+
internal string Name => cpi.Name;
9791

98-
internal string Signature
99-
{
100-
get { return cpi.Signature; }
101-
}
92+
internal string Signature => cpi.Signature;
10293

103-
internal ConstantPoolItemFMI MemberConstantPoolItem
104-
{
105-
get { return cpi; }
106-
}
94+
internal ConstantPoolItemFMI MemberConstantPoolItem => cpi;
10795

108-
internal MethodHandleKind Kind
109-
{
110-
get { return data.Kind; }
111-
}
96+
internal MethodHandleKind Kind => data.Kind;
11297

113-
internal RuntimeJavaMember Member
114-
{
115-
get { return cpi.GetMember(); }
116-
}
98+
internal RuntimeJavaMember Member => cpi.GetMember();
11799

118100
internal RuntimeJavaType GetClassType()
119101
{
@@ -125,10 +107,7 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
125107
cpi.Link(thisType, mode);
126108
}
127109

128-
internal override ConstantType GetConstantType()
129-
{
130-
return ConstantType.MethodHandle;
131-
}
110+
internal override ConstantType GetConstantType() => ConstantType.MethodHandle;
132111

133112
}
134113

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemMethodType.cs

+4-20
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
6262
internal override void Link(RuntimeJavaType thisType, LoadMode mode)
6363
{
6464
lock (this)
65-
{
6665
if (argTypeWrappers != null)
67-
{
6866
return;
69-
}
70-
}
7167

7268
var classLoader = thisType.ClassLoader;
7369
var args = classLoader.ArgJavaTypeListFromSig(descriptor, mode);
@@ -83,25 +79,13 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
8379
}
8480
}
8581

86-
internal string Signature
87-
{
88-
get { return descriptor; }
89-
}
82+
internal string Signature => descriptor;
9083

91-
internal RuntimeJavaType[] GetArgTypes()
92-
{
93-
return argTypeWrappers;
94-
}
84+
internal RuntimeJavaType[] GetArgTypes() => argTypeWrappers;
9585

96-
internal RuntimeJavaType GetRetType()
97-
{
98-
return retTypeWrapper;
99-
}
86+
internal RuntimeJavaType GetRetType() => retTypeWrapper;
10087

101-
internal override ConstantType GetConstantType()
102-
{
103-
return ConstantType.MethodType;
104-
}
88+
internal override ConstantType GetConstantType() => ConstantType.MethodType;
10589

10690
}
10791

‎src/IKVM.Runtime/ClassFile.ConstantPoolItemUtf8.cs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ internal override object GetRuntimeValue()
4545
{
4646
return str;
4747
}
48+
4849
}
4950

5051
}

‎src/IKVM.Runtime/ClassFile.ConstantType.cs

+4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ namespace IKVM.Runtime
2727

2828
sealed partial class ClassFile
2929
{
30+
3031
internal enum ConstantType
3132
{
33+
3234
Integer,
3335
Long,
3436
Float,
@@ -38,7 +40,9 @@ internal enum ConstantType
3840
MethodHandle,
3941
MethodType,
4042
LiveObject, // used by anonymous class constant pool patching
43+
4144
}
45+
4246
}
4347

4448
}

‎src/IKVM.Runtime/ClassFile.InnerClass.cs

+2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ sealed partial class ClassFile
3232

3333
internal struct InnerClass
3434
{
35+
3536
internal ClassConstantHandle innerClass; // ConstantPoolItemClass
3637
internal ClassConstantHandle outerClass; // ConstantPoolItemClass
3738
internal Utf8ConstantHandle name; // ConstantPoolItemUtf8
3839
internal Modifiers accessFlags;
40+
3941
}
4042

4143
}

‎src/IKVM.Runtime/ClassFile.Method.cs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Jeroen Frijters
2626
using IKVM.ByteCode.Decoding;
2727
using IKVM.CoreLib.Diagnostics;
2828

29-
3029
#if IMPORTER
3130
using IKVM.Tools.Importer;
3231
#endif

‎src/IKVM.Runtime/ClassFileParseOptions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum ClassFileParseOptions
3636
RelaxedClassNameValidation = 4,
3737
TrustedAnnotations = 8,
3838
RemoveAssertions = 16,
39+
StaticImport = 32,
3940

4041
}
4142

‎src/IKVM.Runtime/RuntimeClassLoader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ internal ClassFileParseOptions ClassFileParseOptions
949949
get
950950
{
951951
#if IMPORTER
952-
var cfp = ClassFileParseOptions.LocalVariableTable;
952+
var cfp = ClassFileParseOptions.LocalVariableTable | ClassFileParseOptions.StaticImport;
953953
if (EmitStackTraceInfo)
954954
cfp |= ClassFileParseOptions.LineNumberTable;
955955
if (context.ClassLoaderFactory.bootstrapClassLoader is ImportClassLoader)

‎src/IKVM.Tools.Importer/ImportClassLoader.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,7 @@ static int CreateCompiler(RuntimeContext context, StaticCompiler compiler, IDiag
26592659
{
26602660
try
26612661
{
2662-
using var f = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(assemblyType.GetData()), null, ClassFileParseOptions.None, null);
2662+
using var f = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(assemblyType.GetData()), null, ClassFileParseOptions.StaticImport, null);
26632663

26642664
// NOTE the "assembly" type in the unnamed package is a magic type
26652665
// that acts as the placeholder for assembly attributes
@@ -2690,7 +2690,7 @@ static int CreateCompiler(RuntimeContext context, StaticCompiler compiler, IDiag
26902690
{
26912691
try
26922692
{
2693-
using var f = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(h[className].GetData()), null, ClassFileParseOptions.None, null);
2693+
using var f = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(h[className].GetData()), null, ClassFileParseOptions.StaticImport, null);
26942694
if (f.Name == className)
26952695
{
26962696
foreach (var m in f.Methods)

‎src/IKVM.Tools.Importer/ImportContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ static bool EmitStubWarning(RuntimeContext context, StaticCompiler compiler, Imp
946946
{
947947
try
948948
{
949-
cf = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(buf), "<unknown>", ClassFileParseOptions.None, null);
949+
cf = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(buf), "<unknown>", ClassFileParseOptions.StaticImport, null);
950950
}
951951
catch (ClassFormatError)
952952
{
@@ -1205,7 +1205,7 @@ static void ProcessAttributeAnnotationsClass(RuntimeContext context, IDiagnostic
12051205
try
12061206
{
12071207
using var file = File.OpenRead(filename);
1208-
var cf = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(file), null, ClassFileParseOptions.None, null);
1208+
var cf = new IKVM.Runtime.ClassFile(context, diagnostics, IKVM.ByteCode.Decoding.ClassFile.Read(file), null, ClassFileParseOptions.StaticImport, null);
12091209
ArrayAppend(ref annotations, cf.Annotations);
12101210
}
12111211
catch (Exception x)

0 commit comments

Comments
 (0)
Please sign in to comment.