Skip to content

Commit

Permalink
Bunch of formatting.
Browse files Browse the repository at this point in the history
Add in a ClassFileParseOption for StaticImport so we can start cutting down on the ifdefs.
  • Loading branch information
wasabii committed Jan 18, 2025
1 parent 2c0baab commit 8d420f8
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 216 deletions.
14 changes: 4 additions & 10 deletions src/IKVM.Runtime/ClassFile.BootstrapMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,18 @@ sealed partial class ClassFile
internal struct BootstrapMethod
{

private MethodHandleConstantHandle method;
private ConstantHandle[] args;
MethodHandleConstantHandle method;
ConstantHandle[] args;

internal BootstrapMethod(MethodHandleConstantHandle method, ConstantHandle[] args)
{
this.method = method;
this.args = args;
}

internal MethodHandleConstantHandle BootstrapMethodIndex
{
get { return method; }
}
internal MethodHandleConstantHandle BootstrapMethodIndex => method;

internal int ArgumentCount
{
get { return args.Length; }
}
internal int ArgumentCount => args.Length;

internal ConstantHandle GetArgument(int index)
{
Expand Down
51 changes: 0 additions & 51 deletions src/IKVM.Runtime/ClassFile.Constant.cs

This file was deleted.

55 changes: 20 additions & 35 deletions src/IKVM.Runtime/ClassFile.ConstantPoolItemClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,33 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
#if !IMPORTER
if (classFile.MajorVersion < 49 && (options & ClassFileParseOptions.RelaxedClassNameValidation) == 0)
{
char prev = name[0];
if (Char.IsLetter(prev) || prev == '$' || prev == '_' || prev == '[' || prev == '/')
var prev = name[0];
if (char.IsLetter(prev) || prev == '$' || prev == '_' || prev == '[' || prev == '/')
{
int skip = 1;
int end = name.Length;
if (prev == '[')
{
if (!IsValidFieldSig(name))
{
goto barf;
}
throw new ClassFormatError("Invalid class name \"{0}\"", name);

while (name[skip] == '[')
{
skip++;
}

if (name.EndsWith(";"))
{
end--;
}
}

for (int i = skip; i < end; i++)
{
char c = name[i];
if (!Char.IsLetterOrDigit(c) && c != '$' && c != '_' && (c != '/' || prev == '/'))
{
goto barf;
}
var c = name[i];
if (!char.IsLetterOrDigit(c) && c != '$' && c != '_' && (c != '/' || prev == '/'))
throw new ClassFormatError("Invalid class name \"{0}\"", name);

prev = c;
}
name = String.Intern(name.Replace('/', '.'));

name = string.Intern(name.Replace('/', '.'));
return;
}
}
Expand All @@ -123,34 +120,26 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
if (name[0] == '[')
{
if (!IsValidFieldSig(name))
{
goto barf;
}
throw new ClassFormatError("Invalid class name \"{0}\"", name);

// the semicolon is only allowed at the end and IsValidFieldSig enforces this,
// but since invalidJava15Characters contains the semicolon, we decrement end
// to make the following check against invalidJava15Characters ignore the
// trailing semicolon.
if (name[end - 1] == ';')
{
end--;
}

while (name[start] == '[')
{
start++;
}
}

if (name.IndexOfAny(invalidJava15Characters, start, end - start) >= 0)
{
goto barf;
}
throw new ClassFormatError("Invalid class name \"{0}\"", name);

name = string.Intern(name.Replace('/', '.'));
return;
}
}
barf:
throw new ClassFormatError("Invalid class name \"{0}\"", name);
}

internal override void MarkLinkRequired()
Expand All @@ -168,7 +157,8 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
if (typeWrapper == Context.VerifierJavaTypeFactory.Null)
{
var tw = thisType.ClassLoader.LoadClass(name, mode | LoadMode.WarnClassNotFound);
#if !IMPORTER && !FIRST_PASS

#if IMPORTER == false && FIRST_PASS == false
if (!tw.IsUnloadable)
{
try
Expand All @@ -181,17 +171,12 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
}
}
#endif

typeWrapper = tw;
}
}

internal string Name
{
get
{
return name;
}
}
internal string Name => name;

internal RuntimeJavaType GetClassType()
{
Expand Down
1 change: 1 addition & 0 deletions src/IKVM.Runtime/ClassFile.ConstantPoolItemDouble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Jeroen Frijters

using System;

using IKVM.ByteCode;
using IKVM.ByteCode.Decoding;

namespace IKVM.Runtime
Expand Down
32 changes: 7 additions & 25 deletions src/IKVM.Runtime/ClassFile.ConstantPoolItemFMI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
clazz = (ConstantPoolItemClass)classFile.GetConstantPoolItem(clazzHandle);
// if the constant pool items referred to were strings, GetConstantPoolItem returns null
if (name_and_type == null || clazz == null)
{
throw new ClassFormatError("Bad index in constant pool");
}

name = String.Intern(classFile.GetConstantPoolUtf8String(utf8_cp, name_and_type.NameHandle));
name = string.Intern(classFile.GetConstantPoolUtf8String(utf8_cp, name_and_type.NameHandle));
descriptor = classFile.GetConstantPoolUtf8String(utf8_cp, name_and_type.DescriptorHandle);
Validate(name, descriptor, classFile.MajorVersion);
descriptor = String.Intern(descriptor.Replace('/', '.'));
descriptor = string.Intern(descriptor.Replace('/', '.'));
}

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

internal string Name
{
get
{
return name;
}
}
internal string Name => name;

internal string Signature
{
get
{
return descriptor;
}
}
internal string Signature => descriptor;

internal string Class
{
get
{
return clazz.Name;
}
}
internal string Class => clazz.Name;

internal RuntimeJavaType GetClassType()
{
return clazz.GetClassType();
}

internal abstract RuntimeJavaMember GetMember();

}

}

}
16 changes: 7 additions & 9 deletions src/IKVM.Runtime/ClassFile.ConstantPoolItemFieldref.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
{
base.Link(thisType, mode);
lock (this)
{
if (fieldTypeWrapper != null)
{
return;
}
}

RuntimeJavaField fw = null;
RuntimeJavaType wrapper = GetClassType();
var wrapper = GetClassType();
if (wrapper == null)
{
return;
}

if (!wrapper.IsUnloadable)
{
fw = wrapper.GetFieldWrapper(Name, Signature);
Expand All @@ -87,8 +83,10 @@ internal override void Link(RuntimeJavaType thisType, LoadMode mode)
fw.Link(mode);
}
}
RuntimeClassLoader classLoader = thisType.ClassLoader;
RuntimeJavaType fld = classLoader.FieldTypeWrapperFromSig(this.Signature, mode);

var classLoader = thisType.ClassLoader;
var fld = classLoader.FieldTypeWrapperFromSig(this.Signature, mode);

lock (this)
{
if (fieldTypeWrapper == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,21 @@ internal ConstantPoolItemInterfaceMethodref(RuntimeContext context, InterfaceMet
internal override void Link(RuntimeJavaType thisType, LoadMode mode)
{
base.Link(thisType, mode);
RuntimeJavaType wrapper = GetClassType();

var wrapper = GetClassType();
if (wrapper != null)
{
if (!wrapper.IsUnloadable)
{
method = wrapper.GetInterfaceMethod(Name, Signature);
}

if (method == null)
{
// NOTE vmspec 5.4.3.4 clearly states that an interfacemethod may also refer to a method in Object
method = thisType.Context.JavaBase.TypeOfJavaLangObject.GetMethodWrapper(Name, Signature, false);
}

if (method != null)
{
method.Link(mode);
}
}
}

Expand Down
22 changes: 4 additions & 18 deletions src/IKVM.Runtime/ClassFile.ConstantPoolItemInvokeDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Jeroen Frijters
[email protected]
*/
using System;

using IKVM.ByteCode;
using IKVM.ByteCode.Decoding;

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

sealed partial class ClassFile
{

internal sealed class ConstantPoolItemInvokeDynamic : ConstantPoolItem
{

Expand Down Expand Up @@ -67,12 +66,8 @@ internal override void Resolve(ClassFile classFile, string[] utf8_cp, ClassFileP
internal override void Link(RuntimeJavaType thisType, LoadMode mode)
{
lock (this)
{
if (argTypeWrappers != null)
{
return;
}
}

var classLoader = thisType.ClassLoader;
var args = classLoader.ArgJavaTypeListFromSig(descriptor, mode);
Expand All @@ -98,20 +93,11 @@ internal RuntimeJavaType GetRetType()
return retTypeWrapper;
}

internal string Name
{
get { return name; }
}
internal string Name => name;

internal string Signature
{
get { return descriptor; }
}
internal string Signature => descriptor;

internal ushort BootstrapMethod
{
get { return bootstrapMethodAttributeIndex; }
}
internal ushort BootstrapMethod => bootstrapMethodAttributeIndex;

}

Expand Down
1 change: 1 addition & 0 deletions src/IKVM.Runtime/ClassFile.ConstantPoolItemLiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ internal override ConstantType GetConstantType()
{
return ConstantType.LiveObject;
}

}

}
Expand Down
Loading

0 comments on commit 8d420f8

Please sign in to comment.