diff options
Diffstat (limited to 'src/main/java')
5 files changed, 43 insertions, 12 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java index 1d9244a..6db480e 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java @@ -348,6 +348,10 @@ public class RustWriter implements AutoCloseable { case RustPathIdentSegmentIdentifier pathIdentSegmentIdentifier -> { this.writeIdentifier(pathIdentSegmentIdentifier.name()); } + + case RustPathIdentSegmentSelfType _ -> { + this.writer.write("Self"); + } } } diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java index f6686bf..bc25612 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegment.java @@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment imports // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment imports -public sealed interface RustPathIdentSegment permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentIdentifier { +public sealed interface RustPathIdentSegment permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentCrate, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentGlobal, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentIdentifier, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType { public interface Builder { public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment build(); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentSelfType.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentSelfType.java new file mode 100644 index 0000000..186fc42 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustPathIdentSegmentSelfType.java @@ -0,0 +1,24 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType imports + +public record RustPathIdentSegmentSelfType() implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType.Builder(); + } + + public record Builder() implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegment.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType build() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType(); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPathIdentSegmentSelfType body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java index 8b0adf0..797f770 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java @@ -66,21 +66,20 @@ public record RustTypePath(java.util.List<org.zwobble.hobgoblin.compiler.output. } public static RustType crate(String... names) { - var segments = Stream.concat( - Stream.of(RustTypePathSegment.crate()), - Arrays.stream(names) - .map(name -> new RustTypePathSegment( - new RustPathIdentSegmentIdentifier(new RustIdentifier(name)), - Optional.empty() - )) - ) - .toList(); - return new RustTypePath(segments); + return qualified(RustTypePathSegment.crate(), names); } public static RustTypePath global(String... names) { + return qualified(RustTypePathSegment.global(), names); + } + + public static RustTypePath selfType(String... names) { + return qualified(RustTypePathSegment.selfType(), names); + } + + private static RustTypePath qualified(RustTypePathSegment qualifier, String... names) { var segments = Stream.concat( - Stream.of(RustTypePathSegment.global()), + Stream.of(qualifier), Arrays.stream(names) .map(name -> new RustTypePathSegment( new RustPathIdentSegmentIdentifier(new RustIdentifier(name)), diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java index cffef8d..6531925 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePathSegment.java @@ -50,6 +50,10 @@ public record RustTypePathSegment(org.zwobble.hobgoblin.compiler.output.lang.rus return new RustTypePathSegment(new RustPathIdentSegmentGlobal(), Optional.empty()); } + public static RustTypePathSegment selfType() { + return new RustTypePathSegment(new RustPathIdentSegmentSelfType(), Optional.empty()); + } + public RustTypePathSegment withArgs(List<RustType> args) { if (this.args.isPresent()) { throw new IllegalArgumentException("Type path segment already has args"); |
