structure-check: gate counts code lines, docs and comments in English

Gate ignores blank and full-line comment lines so the 250-line limit
measures code bulk, not documentation weight; docs/README.md synced.
Translate code comments to English in classfile, core config, namegen,
rename assign, constants forms. Expand Plausible word bank with
client-ecosystem terms (Module, Setting, Mixin, ...). cargo fmt clean,
check.sh green.
This commit is contained in:
Loki 2026-10-09 10:31:02 +02:00
parent ec28ec82e3
commit 39178420e4
Signed by: boba
GPG key ID: 253067914055423B
42 changed files with 532 additions and 437 deletions

View file

@ -1,8 +1,8 @@
//! Сборка классов «с нуля»: junk-классы, рантайм-декодеры, аннотации-шум.
//! Building classes "from scratch": junk classes, runtime decoders, noise annotations.
use crate::model::{Attribute, ClassFile, Code, Field, Method, Version};
/// Строитель класса без бинарного представления на входе.
/// A class builder with no binary representation on input.
#[derive(Debug, Clone)]
pub struct ClassBuilder {
version: Version,
@ -16,8 +16,8 @@ pub struct ClassBuilder {
}
impl ClassBuilder {
/// Новый класс `public` с указанным суперклассом (`None` = `java/lang/Object`,
/// кроме самого `java/lang/Object` — у него суперкласса нет).
/// A new `public` class with the given superclass (`None` = `java/lang/Object`,
/// except for `java/lang/Object` itself — it has no superclass).
pub fn new(this_class: impl Into<String>, super_class: Option<&str>) -> Self {
let this_class = this_class.into();
let super_class = match super_class {
@ -37,25 +37,25 @@ impl ClassBuilder {
}
}
/// Задать версию классового файла.
/// Set the class-file version.
pub fn version(mut self, version: Version) -> Self {
self.version = version;
self
}
/// Задать флаги доступа (перезаписывает `ACC_PUBLIC|ACC_SUPER`).
/// Set access flags (overwrites `ACC_PUBLIC|ACC_SUPER`).
pub fn access_flags(mut self, flags: u16) -> Self {
self.access_flags = flags;
self
}
/// Добавить интерфейс.
/// Add an interface.
pub fn interface(mut self, name: impl Into<String>) -> Self {
self.interfaces.push(name.into());
self
}
/// Добавить поле.
/// Add a field.
pub fn field(mut self, name: impl Into<String>, descriptor: impl Into<String>) -> Self {
self.fields.push(Field {
access_flags: 0x0001, // ACC_PUBLIC
@ -66,7 +66,7 @@ impl ClassBuilder {
self
}
/// Добавить метод без тела (`abstract`/`native` должны выставить флаги сами).
/// Add a method without a body (`abstract`/`native` must set their own flags).
pub fn method(
mut self,
access_flags: u16,
@ -83,7 +83,7 @@ impl ClassBuilder {
self
}
/// Добавить метод с телом.
/// Add a method with a body.
pub fn method_with_code(
mut self,
access_flags: u16,
@ -101,13 +101,13 @@ impl ClassBuilder {
self
}
/// Добавить атрибут уровня класса.
/// Add a class-level attribute.
pub fn attribute(mut self, attribute: Attribute) -> Self {
self.attributes.push(attribute);
self
}
/// Собрать класс.
/// Build the class.
pub fn build(self) -> ClassFile {
ClassFile {
version: self.version,
@ -122,7 +122,7 @@ impl ClassBuilder {
}
}
/// Пустое тело метода (`return`), для junk-методов.
/// An empty method body (`return`), for junk methods.
pub fn empty_code(max_locals: u16) -> Code {
Code {
max_stack: 0,

View file

@ -1,4 +1,4 @@
//! Структура «программы» — единица работы пайплайна.
//! The "program" structure — the unit of work for the pipeline.
pub mod builder;
pub mod version;
@ -8,7 +8,7 @@ pub use version::Version;
use crate::format::StackMapFrame;
use crate::insn::{Const, Insn, Label};
/// Неизвестные/специфичные атрибуты хранятся байтами — round-trip без потерь.
/// Unknown/specific attributes are stored as bytes — lossless round-trip.
#[derive(Debug, Clone, PartialEq)]
pub enum Attribute {
SourceFile(String),
@ -19,26 +19,26 @@ pub enum Attribute {
Deprecated,
Synthetic,
InnerClasses(Vec<InnerClass>),
/// `NestHost`: класс, служащий nest-хостом (JVMS §4.7.28).
/// `NestHost`: the class acting as nest host (JVMS §4.7.28).
NestHost(String),
/// `NestMembers`: классы-члены этого nest-хоста (JVMS §4.7.29).
/// `NestMembers`: the member classes of this nest host (JVMS §4.7.29).
NestMembers(Vec<String>),
/// `ConstantValue` поля (`static final`): значение из пула.
/// A field's `ConstantValue` (`static final`): a value from the pool.
ConstantValue(Const),
/// `BootstrapMethods` для `invokedynamic` (лямбды): метод + аргументы.
/// `BootstrapMethods` for `invokedynamic` (lambdas): method + arguments.
BootstrapMethods(Vec<BootstrapMethod>),
/// `EnclosingMethod`: класс и опциональный метод, содержащие локальный класс.
/// `EnclosingMethod`: the class and optional method enclosing a local class.
EnclosingMethod {
class: String,
method: Option<(String, String)>,
},
/// `MethodParameters`: имена формальных параметров (`None` — безымянный).
/// `MethodParameters`: formal parameter names (`None` — unnamed).
MethodParameters(Vec<MethodParameter>),
/// `Record`: компоненты record-класса.
/// `Record`: the record class's components.
Record(Vec<RecordComponent>),
/// `LocalVariableTypeTable`: сигнатуры generic-локальных (как LVT).
/// `LocalVariableTypeTable`: generic local signatures (like LVT).
LocalVariableTypeTable(Vec<LocalVariableType>),
/// Всё остальное: имя + сырые байты `info` (осторожно с индексами пула).
/// Everything else: name + raw `info` bytes (careful with pool indices).
Raw {
name: String,
data: Vec<u8>,
@ -47,14 +47,14 @@ pub enum Attribute {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LineNumber {
/// Метка начала (байты вычисляет writer — переживает вставки пассов).
/// Start label (the writer computes bytes — survives pass insertions).
pub start: Label,
pub line: u16,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalVariable {
/// Метки диапазона видимости (writer пересчитает в байты).
/// Visibility-range labels (the writer recomputes them into bytes).
pub start: Label,
pub end: Label,
pub name: String,
@ -70,10 +70,10 @@ pub struct InnerClass {
pub access_flags: u16,
}
/// Один `bootstrap`-метод: ссылка вида `MethodHandle` + аргументы-константы.
/// One `bootstrap` method: a `MethodHandle`-style reference + const arguments.
#[derive(Debug, Clone, PartialEq)]
pub struct BootstrapMethod {
/// Номер `reference_kind` (JVMS §5.4.3.5).
/// The `reference_kind` number (JVMS §5.4.3.5).
pub kind: u8,
pub owner: String,
pub name: String,
@ -82,14 +82,14 @@ pub struct BootstrapMethod {
pub args: Vec<Const>,
}
/// Формальный параметр метода (`MethodParameters`).
/// A method's formal parameter (`MethodParameters`).
#[derive(Debug, Clone, PartialEq)]
pub struct MethodParameter {
pub name: Option<String>,
pub access_flags: u16,
}
/// Компонент `Record`: поле record-класса с атрибутами.
/// A `Record` component: a record class field with attributes.
#[derive(Debug, Clone, PartialEq)]
pub struct RecordComponent {
pub name: String,
@ -97,10 +97,10 @@ pub struct RecordComponent {
pub attributes: Vec<Attribute>,
}
/// Строка `LocalVariableTypeTable` (как `LocalVariable`, но с сигнатурой).
/// A `LocalVariableTypeTable` entry (like `LocalVariable`, but with a signature).
#[derive(Debug, Clone, PartialEq)]
pub struct LocalVariableType {
/// Метки диапазона видимости (writer пересчитает в байты).
/// Visibility-range labels (the writer recomputes them into bytes).
pub start: Label,
pub end: Label,
pub name: String,
@ -126,18 +126,18 @@ pub struct Method {
}
impl Method {
/// `native`/`abstract` тела не имеют.
/// `native`/`abstract` methods have no body.
pub fn has_code(&self) -> bool {
self.code.is_some()
}
}
/// Тело метода.
/// A method body.
#[derive(Debug, Clone, PartialEq)]
pub struct Code {
pub max_stack: u16,
pub max_locals: u16,
/// Маркеры меток + инструкции; ветвления указывают на [`Label`].
/// Label markers + instructions; branches point at a [`Label`].
pub insns: Vec<Insn>,
pub exception_table: Vec<ExceptionHandler>,
pub frames: Vec<StackMapFrame>,
@ -145,7 +145,7 @@ pub struct Code {
}
impl Code {
/// Все метки, объявленные в теле метода.
/// All labels declared in the method body.
pub fn labels(&self) -> Vec<Label> {
self.insns
.iter()
@ -163,11 +163,11 @@ pub struct ExceptionHandler {
pub start: Label,
pub end: Label,
pub handler: Label,
/// Внутреннее имя класса или `None` для `any`.
/// The class's internal name, or `None` for `any`.
pub catch_type: Option<String>,
}
/// Один `.class` в нормализованном виде.
/// One `.class` in normalized form.
#[derive(Debug, Clone, PartialEq)]
pub struct ClassFile {
pub version: Version,
@ -181,34 +181,34 @@ pub struct ClassFile {
}
impl ClassFile {
/// Ищет метод по имени и дескриптору.
/// Finds a method by name and descriptor.
pub fn method(&self, name: &str, descriptor: &str) -> Option<&Method> {
self.methods
.iter()
.find(|m| m.name == name && m.descriptor == descriptor)
}
/// Ищет метод по имени и дескриптору (мутирующий доступ).
/// Finds a method by name and descriptor (mutating access).
pub fn method_mut(&mut self, name: &str, descriptor: &str) -> Option<&mut Method> {
self.methods
.iter_mut()
.find(|m| m.name == name && m.descriptor == descriptor)
}
/// Признак `ACC_INTERFACE`.
/// The `ACC_INTERFACE` flag.
pub fn is_interface(&self) -> bool {
self.access_flags & 0x0200 != 0
}
}
/// Ресурс внутри архива (JSON, properties, картинки, ...).
/// A resource inside the archive (JSON, properties, images, ...).
#[derive(Debug, Clone, PartialEq)]
pub struct Resource {
pub path: String,
pub data: Vec<u8>,
}
/// Вся входная программа: классы + ресурсы.
/// The whole input program: classes + resources.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Program {
pub classes: Vec<ClassFile>,
@ -216,24 +216,24 @@ pub struct Program {
}
impl Program {
/// Класс по внутреннему имени (`pkg/Class`).
/// A class by internal name (`pkg/Class`).
pub fn class(&self, internal_name: &str) -> Option<&ClassFile> {
self.classes.iter().find(|c| c.this_class == internal_name)
}
/// Класс по внутреннему имени (мутирующий доступ).
/// A class by internal name (mutating access).
pub fn class_mut(&mut self, internal_name: &str) -> Option<&mut ClassFile> {
self.classes
.iter_mut()
.find(|c| c.this_class == internal_name)
}
/// Ресурс по пути внутри архива.
/// A resource by its path inside the archive.
pub fn resource(&self, path: &str) -> Option<&Resource> {
self.resources.iter().find(|r| r.path == path)
}
/// Пустая ли программа.
/// Whether the program is empty.
pub fn is_empty(&self) -> bool {
self.classes.is_empty() && self.resources.is_empty()
}

View file

@ -1,6 +1,6 @@
//! Версия классового файла (major/minor).
//! Class-file version (major/minor).
/// Версия классового файла.
/// The class-file version.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Version {
pub minor: u16,