From 128e1790bf0f37d310959ecc4c9cdb31a06e21dd Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 7 Apr 2024 14:25:08 +0200 Subject: [PATCH] Rename methods by replacing "opaque" with "external" This is to reflect the new meaning of these methods since b2ec9e54d78b1485f27d1b74be8eaf8b868b8ed6, when they were updated to process all external types from the perspective of the current type, not only opaque types. --- .../scala/io/kaitai/struct/ClassCompiler.scala | 8 ++++---- .../scala/io/kaitai/struct/NimClassCompiler.scala | 2 +- .../scala/io/kaitai/struct/TypeProcessor.scala | 14 +++++++------- .../io/kaitai/struct/languages/CppCompiler.scala | 2 +- .../struct/languages/JavaScriptCompiler.scala | 2 +- .../io/kaitai/struct/languages/LuaCompiler.scala | 2 +- .../io/kaitai/struct/languages/NimCompiler.scala | 2 +- .../io/kaitai/struct/languages/PerlCompiler.scala | 2 +- .../kaitai/struct/languages/PythonCompiler.scala | 2 +- .../io/kaitai/struct/languages/RustCompiler.scala | 2 +- .../languages/components/LanguageCompiler.scala | 6 +++--- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala b/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala index feb7d3043..4bb652216 100644 --- a/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala @@ -19,7 +19,7 @@ class ClassCompiler( override def compile: CompileLog.SpecSuccess = { lang.fileHeader(topClassName.head) - compileOpaqueClasses(topClass) + compileExternalClasses(topClass) compileClass(topClass) lang.fileFooter(topClassName.head) @@ -29,9 +29,9 @@ class ClassCompiler( ) } - def compileOpaqueClasses(topClass: ClassSpec) = { - TypeProcessor.getOpaqueClasses(topClass).foreach((classSpec) => - lang.opaqueClassDeclaration(classSpec) + def compileExternalClasses(topClass: ClassSpec) = { + TypeProcessor.getExternalClasses(topClass).foreach((classSpec) => + lang.externalClassDeclaration(classSpec) ) } diff --git a/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala b/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala index 5100a2bae..ef9afeca4 100644 --- a/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/NimClassCompiler.scala @@ -21,7 +21,7 @@ class NimClassCompiler( override def compile: CompileLog.SpecSuccess = { lang.fileHeader(classNameFlattened(topClass)) - compileOpaqueClasses(topClass) + compileExternalClasses(topClass) // if there are any enums at all maybe we can detect it and not generate this template // nimlang.enumTemplate diff --git a/shared/src/main/scala/io/kaitai/struct/TypeProcessor.scala b/shared/src/main/scala/io/kaitai/struct/TypeProcessor.scala index 51c2c0050..d5fc7ceb1 100644 --- a/shared/src/main/scala/io/kaitai/struct/TypeProcessor.scala +++ b/shared/src/main/scala/io/kaitai/struct/TypeProcessor.scala @@ -7,28 +7,28 @@ import io.kaitai.struct.format._ import scala.collection.mutable object TypeProcessor { - def getOpaqueClasses(curClass: ClassSpec): Iterable[ClassSpec] = { + def getExternalClasses(curClass: ClassSpec): Iterable[ClassSpec] = { val res = mutable.Set[ClassSpec]() curClass.seq.map((attr) => - res ++= getOpaqueDataTypes(attr.dataType, curClass) + res ++= getExternalDataTypes(attr.dataType, curClass) ) curClass.instances.foreach { case (_, inst) => inst match { case pis: ParseInstanceSpec => - res ++= getOpaqueDataTypes(pis.dataType, curClass) + res ++= getExternalDataTypes(pis.dataType, curClass) case _ => None } } // Traverse all nested types recursively curClass.types.foreach { case (_, nestedType) => - res ++= getOpaqueClasses(nestedType) + res ++= getExternalClasses(nestedType) } res } - def getOpaqueDataTypes(dataType: DataType, curClass: ClassSpec): Iterable[ClassSpec] = { + def getExternalDataTypes(dataType: DataType, curClass: ClassSpec): Iterable[ClassSpec] = { dataType match { case ut: UserType => if (ut.isExternal(curClass)) { @@ -38,10 +38,10 @@ object TypeProcessor { } case st: SwitchType => st.cases.flatMap { case (_, ut) => - getOpaqueDataTypes(ut, curClass) + getExternalDataTypes(ut, curClass) } case _ => - // all other types are not opaque external user types + // all other types are not external user types List() } } diff --git a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala index 05ef8e7c3..286552a3c 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala @@ -108,7 +108,7 @@ class CppCompiler( } } - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = { + override def externalClassDeclaration(classSpec: ClassSpec): Unit = { classForwardDeclaration(classSpec.name) importListHdr.addLocal(outFileNameHeader(classSpec.name.head)) } diff --git a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala index ae2408b46..22447bcb1 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/JavaScriptCompiler.scala @@ -58,7 +58,7 @@ class JavaScriptCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts("});") } - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = { + override def externalClassDeclaration(classSpec: ClassSpec): Unit = { val className = type2class(classSpec.name.head) importList.add(s"./$className") } diff --git a/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala index aaace9974..d8533b2ae 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala @@ -32,7 +32,7 @@ class LuaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) override def outImports(topClass: ClassSpec) = importList.toList.mkString("", "\n", "\n") - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = + override def externalClassDeclaration(classSpec: ClassSpec): Unit = importList.add("require(\"" + classSpec.name.head + "\")") override def fileHeader(topClassName: String): Unit = { diff --git a/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala index ecece1861..0faf9796c 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/NimCompiler.scala @@ -54,7 +54,7 @@ class NimCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts } - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = + override def externalClassDeclaration(classSpec: ClassSpec): Unit = importList.add(classSpec.name.head) override def innerEnums = false override val translator: NimTranslator = new NimTranslator(typeProvider, importList) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala index a38d5a93d..b3b13ac6a 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PerlCompiler.scala @@ -50,7 +50,7 @@ class PerlCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts("1;") } - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = + override def externalClassDeclaration(classSpec: ClassSpec): Unit = importList.add(type2class(classSpec.name.head)) override def classHeader(name: List[String]): Unit = { diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala index bc74dc1a6..a6b25b7e2 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala @@ -77,7 +77,7 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts } - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = { + override def externalClassDeclaration(classSpec: ClassSpec): Unit = { val name = classSpec.name.head importList.add( if (config.pythonPackage.nonEmpty) { diff --git a/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala index e52a0adfe..f2bb16b62 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/RustCompiler.scala @@ -54,7 +54,7 @@ class RustCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts } - override def opaqueClassDeclaration(classSpec: ClassSpec): Unit = { + override def externalClassDeclaration(classSpec: ClassSpec): Unit = { val name = type2class(classSpec.name.last) val pkg = type2classAbs(classSpec.name) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala index 068ec13a6..985bbdfa1 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/components/LanguageCompiler.scala @@ -75,12 +75,12 @@ abstract class LanguageCompiler( def fileFooter(topClassName: String): Unit = {} /** - * Outputs declaration of "opaque class", i.e. class that will be referred to in this file, but + * Outputs declaration of "external class", i.e. class that will be referred to in this file, but * not declared here. Some languages require either a "forward declaration" in this case, or a - * statement to import that class, or something similar. Called once per each opaque class. + * statement to import that class, or something similar. Called once per each external class. * @param classSpec */ - def opaqueClassDeclaration(classSpec: ClassSpec): Unit = {} + def externalClassDeclaration(classSpec: ClassSpec): Unit = {} def classDoc(name: List[String], doc: DocSpec): Unit = {} def classHeader(name: List[String]): Unit