From 8c470f31582f918e3c4eef3ce81fe826676da01b Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 7 Jul 2021 22:08:33 -0700 Subject: [PATCH] Sporadic work done in an airport - Initial ErrorBuilder class - Random documentation --- .../flywheel/backend/pipeline/SourceFile.java | 4 +-- .../backend/pipeline/error/ErrorBuilder.java | 30 +++++++++++++++++++ .../{parse => error}/ErrorReporter.java | 4 ++- .../pipeline/parse/AbstractShaderElement.java | 1 + .../backend/pipeline/parse/Include.java | 1 + .../pipeline/parse/ShaderFunction.java | 1 + .../backend/pipeline/parse/ShaderStruct.java | 5 +--- .../backend/pipeline/parse/StructField.java | 3 +- .../backend/pipeline/parse/Variable.java | 1 + .../backend/pipeline/span/CharPos.java | 5 ++-- .../backend/pipeline/span/ErrorSpan.java | 3 ++ .../flywheel/backend/pipeline/span/Span.java | 24 +++++++++++++-- 12 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorBuilder.java rename src/main/java/com/jozufozu/flywheel/backend/pipeline/{parse => error}/ErrorReporter.java (82%) diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/SourceFile.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/SourceFile.java index 8ea1fb28b..4c6ad0c42 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/SourceFile.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/SourceFile.java @@ -113,9 +113,9 @@ public class SourceFile { int lastEnd = 0; for (Span elision : elisions) { - out.append(source, lastEnd, elision.getStart()); + out.append(source, lastEnd, elision.getStartPos()); - lastEnd = elision.getEnd(); + lastEnd = elision.getEndPos(); } out.append(source, lastEnd, source.length()); diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorBuilder.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorBuilder.java new file mode 100644 index 000000000..5f706a962 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorBuilder.java @@ -0,0 +1,30 @@ +package com.jozufozu.flywheel.backend.pipeline.error; + +import com.jozufozu.flywheel.backend.pipeline.SourceFile; + +public class ErrorBuilder { + + private StringBuilder internal; + + public ErrorBuilder header(CharSequence msg) { + internal.append("error: ") + .append(msg); + return endLine(); + } + + public ErrorBuilder errorIn(SourceFile file) { + internal.append("--> ") + .append(file.name); + return endLine(); + } + + public ErrorBuilder line(int no, CharSequence content) { + + return endLine(); + } + + public ErrorBuilder endLine() { + internal.append('\n'); + return this; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ErrorReporter.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorReporter.java similarity index 82% rename from src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ErrorReporter.java rename to src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorReporter.java index a41afd9e2..cdbda6169 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ErrorReporter.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/error/ErrorReporter.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.pipeline.parse; +package com.jozufozu.flywheel.backend.pipeline.error; import com.jozufozu.flywheel.backend.pipeline.SourceFile; import com.jozufozu.flywheel.backend.pipeline.span.Span; @@ -9,6 +9,8 @@ public class ErrorReporter { public String generateSpanError(Span span, String message) { SourceFile file = span.getSourceFile(); + + return ""; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/AbstractShaderElement.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/AbstractShaderElement.java index c88c0be3a..6f73370f5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/AbstractShaderElement.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/AbstractShaderElement.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend.pipeline.parse; +import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter; import com.jozufozu.flywheel.backend.pipeline.span.Span; public abstract class AbstractShaderElement { diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Include.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Include.java index 703435654..9d1f38504 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Include.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Include.java @@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.pipeline.parse; import java.util.Optional; import com.jozufozu.flywheel.backend.ShaderSources; +import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter; import com.jozufozu.flywheel.backend.pipeline.SourceFile; import com.jozufozu.flywheel.backend.pipeline.span.Span; diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderFunction.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderFunction.java index 83503a09e..ab2a8176a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderFunction.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderFunction.java @@ -6,6 +6,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter; import com.jozufozu.flywheel.backend.pipeline.span.Span; public class ShaderFunction extends AbstractShaderElement { diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderStruct.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderStruct.java index 2f3709356..01820d8b2 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderStruct.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/ShaderStruct.java @@ -1,9 +1,5 @@ package com.jozufozu.flywheel.backend.pipeline.parse; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -11,6 +7,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.jozufozu.flywheel.backend.loading.Program; import com.jozufozu.flywheel.backend.loading.TypeHelper; +import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter; import com.jozufozu.flywheel.backend.pipeline.span.Span; public class ShaderStruct extends AbstractShaderElement { diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/StructField.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/StructField.java index 07c93720b..bf61c8eb1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/StructField.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/StructField.java @@ -1,9 +1,8 @@ package com.jozufozu.flywheel.backend.pipeline.parse; -import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.jozufozu.flywheel.backend.loading.LayoutTag; +import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter; import com.jozufozu.flywheel.backend.pipeline.span.Span; public class StructField extends AbstractShaderElement { diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Variable.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Variable.java index 6576ddd9f..1b0c5226f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Variable.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/parse/Variable.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend.pipeline.parse; +import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter; import com.jozufozu.flywheel.backend.pipeline.span.Span; public class Variable extends AbstractShaderElement { diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/CharPos.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/CharPos.java index 7dfea1301..ab2b2de87 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/CharPos.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/CharPos.java @@ -1,7 +1,8 @@ package com.jozufozu.flywheel.backend.pipeline.span; -import com.jozufozu.flywheel.backend.pipeline.SourceFile; - +/** + * A position in a file. + */ public class CharPos { private final int idx; diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/ErrorSpan.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/ErrorSpan.java index cccb10720..8afdcb7bd 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/ErrorSpan.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/ErrorSpan.java @@ -2,6 +2,9 @@ package com.jozufozu.flywheel.backend.pipeline.span; import com.jozufozu.flywheel.backend.pipeline.SourceFile; +/** + * Represents a (syntactically) malformed segment of code. + */ public class ErrorSpan extends Span { public ErrorSpan(SourceFile in, int loc) { super(in, loc, loc); diff --git a/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/Span.java b/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/Span.java index 49285ae69..e635b1c98 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/Span.java +++ b/src/main/java/com/jozufozu/flywheel/backend/pipeline/span/Span.java @@ -23,31 +23,49 @@ public abstract class Span implements CharSequence { this.end = end; } + /** + * @return The file that contains this code segment. + */ public SourceFile getSourceFile() { return in; } - public int getStart() { + /** + * @return the string index at the (inclusive) beginning of this code segment. + */ + public int getStartPos() { return start.getPos(); } - public int getEnd() { + /** + * @return the string index at the (exclusive) end of this code segment. + */ + public int getEndPos() { return end.getPos(); } + /** + * @return true if this span has no width. + */ public boolean isEmpty() { return start == end; } + /** + * Get a span referring to a code segment inside this code segment. + */ public abstract Span subSpan(int from, int to); + /** + * @return the portion of code represented by this span. + */ public abstract String get(); public abstract boolean isErr(); @Override public int length() { - return end.getPos() - start.getPos(); + return getEndPos() - getStartPos(); } @Override