Skip to content

Commit

Permalink
Remove unused parameters from condRepeatEosHeader and document `con…
Browse files Browse the repository at this point in the history
…dRepeatEosHeader` and `condRepeatEosFooter`
  • Loading branch information
Mingun committed Sep 15, 2024
1 parent 53fa661 commit 3c21915
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class CSharpCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts(s"${privateMemberName(id)} = new ${kaitaiType2NativeType(ArrayTypeInStream(dataType))}();")
}

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("{")
out.inc
out.puts("var i = 0;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class CppCompiler(
outSrc.puts(s"${privateMemberName(id)} = ${newVector(dataType)};")
}

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
outSrc.puts("{")
outSrc.inc
outSrc.puts("int i = 0;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class GoCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
// function works even on `nil` slices (https://go.dev/tour/moretypes/15)
}

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts(s"for i := 0;; i++ {")
out.inc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
override def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit =
out.puts(s"${privateMemberName(id)} = new ${kaitaiType2JavaType(ArrayTypeInStream(dataType))}();")

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("{")
out.inc
out.puts("int i = 0;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
override def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit =
out.puts(s"${privateMemberName(id)} = [];")

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("var i = 0;")
out.puts(s"while (!$io.isEof()) {")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class LuaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts(s"${privateMemberName(id)} = {}")
}

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("local i = 0")
out.puts(s"while not $io:is_eof() do")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
// empty sequences (see https://narimiran.github.io/nim-basics/#_result_variable)
}

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("block:")
out.inc
out.puts("var i: int")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class PHPCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
override def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit =
out.puts(s"${privateMemberName(id)} = [];")

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("$i = 0;")
out.puts(s"while (!$io->isEof()) {")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
override def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit =
out.puts(s"${privateMemberName(id)} = [];")

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
// Perl allows shadowing of variables, no need a scope to isolate them
out.puts("my $i = 0;")
out.puts(s"while (!$io->is_eof()) {")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
override def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit =
out.puts(s"${privateMemberName(id)} = []")

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("i = 0")
out.puts(s"while not $io.is_eof():")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
override def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit =
out.puts(s"${privateMemberName(id)} = []")

override def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit = {
override def condRepeatEosHeader(io: String): Unit = {
out.puts("i = 0")
out.puts(s"while not $io.eof?")
out.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,8 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts(s"*${RustCompiler.privateMemberName(id, writeAccess = true)} = Vec::new();")
}

override def condRepeatEosHeader(id: Identifier,
io: String,
dataType: DataType): Unit = {
out.puts("{")
out.inc
override def condRepeatEosHeader(io: String): Unit = {
// Rust allows shadowing of variables, no need a scope to isolate them
out.puts(s"let mut _i = 0;")
out.puts(s"while !$io.is_eof() {")
out.inc
Expand All @@ -295,8 +292,6 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
out.puts("_i += 1;")
out.dec
out.puts("}")
out.dec
out.puts("}")
}

override def condRepeatExprHeader(countExpr: Ast.expr): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ trait CommonReads extends LanguageCompiler {
(ExtraAttrs.forAttr(attr, this) ++ List(attr)).foreach(a => condRepeatInitAttr(a.id, a.dataType))
attr.cond.repeat match {
case RepeatEos =>
condRepeatEosHeader(id, io, attr.dataType)
condRepeatEosHeader(io)
case RepeatExpr(countExpr: Ast.expr) =>
condRepeatExprHeader(countExpr)
case RepeatUntil(_) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ abstract class LanguageCompiler(

def condRepeatInitAttr(id: Identifier, dataType: DataType): Unit

def condRepeatEosHeader(id: Identifier, io: String, dataType: DataType): Unit
/**
* Generates start of loop until end-of-stream is reached.
*
* @param io rendered expression that evaluates to reference of a stream which
* should be checked
*/
def condRepeatEosHeader(io: String): Unit
/**
* Generates end of loop until end-of-stream is reached.
*/
def condRepeatEosFooter: Unit

/**
Expand Down

0 comments on commit 3c21915

Please sign in to comment.