Skip to content

Commit

Permalink
A million warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
a4z committed Nov 11, 2023
1 parent f741119 commit ee45fd1
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 133 deletions.
30 changes: 26 additions & 4 deletions src/main/scala/djinni/CWrapperGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
}
}

def getDefArgs(m: Interface.Method, self: String, forHeader: Boolean): String = {
def getDefArgs(
m: Interface.Method,
self: String,
forHeader: Boolean
): String = {
if (m.static || self == "") {
marshal.cArgDecl(
m.params.map(p =>
Expand All @@ -65,7 +69,11 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
}
}

def getCArgTypes(m: Interface.Method, self: String, forHeader: Boolean): String = {
def getCArgTypes(
m: Interface.Method,
self: String,
forHeader: Boolean
): String = {
marshal.cArgDecl(
Seq(self) ++ m.params.map(p => marshal.cParamType(p.ty, forHeader))
)
Expand Down Expand Up @@ -239,6 +247,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
classAsMethodName: String,
w: IndentWriter
): Unit = {
val _ = retType // unused, TODO, check remove
val elTyRef = getContainerElTypeRef(tm, 0, ident)
val addToList = marshal.callback(idCpp.method(classAsMethodName + "__add"))
declareObjectUniquePointerHandle(tm, classAsMethodName, w)
Expand Down Expand Up @@ -325,6 +334,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
classAsMethodName: String,
w: IndentWriter
): Unit = {
val _ = retType // unused, TODO, check remove
val addToMap = marshal.callback(idCpp.method(classAsMethodName + "__add"))
val keyTyRef = getContainerElTypeRef(tm, 0, ident)
val valTyRef = getContainerElTypeRef(tm, 1, ident)
Expand Down Expand Up @@ -396,6 +406,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
classAsMethodName: String,
w: IndentWriter
): Unit = {
val _ = retType // unused, TODO, check remove
marshal.callback(idCpp.method(classAsMethodName + "__create"))
val addToMap = marshal.callback(idCpp.method(classAsMethodName + "__add"))
val keyTyRef = getContainerElTypeRef(tm, 0, ident)
Expand Down Expand Up @@ -426,8 +437,8 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
getReturnType: String,
addCArgs: String
): Unit = {
val _ = (tm, ident, retType) // unused, TODO, check remove
val handle = "DjinniObjectHandle *"

var ret = ""
var cArgs = ""
if (getName != "") {
Expand Down Expand Up @@ -460,8 +471,8 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
getReturnType: String,
addCArgs: String
): Unit = {
val _ = (tm, ident, retType) // unused, TODO, check remove
val handle = "struct DjinniObjectHandle *"

var ret = ""
var cArgs = ""
if (getName != "") {
Expand Down Expand Up @@ -548,6 +559,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
deleteMethod: String,
w: IndentWriter
): Unit = {
val _ = handle // unused, TODO, check remove
w.wl(
"djinni::Handle" + t(optHandle) + " " + djinniWrapper + "::fromCpp" + p(
spec.cppOptionalTemplate + t(retType) + " dc"
Expand Down Expand Up @@ -577,6 +589,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
deleteMethod: String,
w: IndentWriter
): Unit = {
val _ = reinterpret // unused, TODO, check remove
w.wl(
spec.cppOptionalTemplate + t(retTypeStr) + djinniWrapper + "::toCpp" + p(
"djinni::Handle" + t(optHandle) + " dh"
Expand Down Expand Up @@ -607,6 +620,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
retType: String,
w: IndentWriter
): Unit = {
val _ = (handle, optHandle) // unused, TODO, check remove
w.wl(
"static " + "djinni::Handle" + t(cppHandle) + " fromCpp" + p(
cppMarshal.fqParamType(tm) + " dc"
Expand Down Expand Up @@ -639,6 +653,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
h: mutable.TreeSet[String],
hpp: mutable.TreeSet[String]
): Unit = {
val _ = className // unused, TODO, check remove
// className is the composed idl named of the container type
val handle = "DjinniObjectHandle"
val handlePtr = handle + " *"
Expand Down Expand Up @@ -761,6 +776,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
h: mutable.TreeSet[String],
hpp: mutable.TreeSet[String]
): Unit = {
val _ = className // unused, TODO, check remove
// className is the composed idl named of the container type
val handle = "DjinniObjectHandle"
val handlePtr = "DjinniObjectHandle *"
Expand Down Expand Up @@ -932,6 +948,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
h: mutable.TreeSet[String],
hpp: mutable.TreeSet[String]
): Unit = {
val _ = className // unused, TODO, check remove
// className is the composed idl named of the container type
val handle = "DjinniObjectHandle"
val handlePtr = "DjinniObjectHandle *"
Expand Down Expand Up @@ -1107,6 +1124,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
methods: Seq[Interface.Method],
w: IndentWriter
): Unit = {
val _ = cClassWrapper // unused, TODO, check remove
for (m <- methods) {
val ret = marshal.cReturnType(m.ret, false)
val cArgs = getCArgTypes(m, marshal.djinniObjectHandle + " * ", false)
Expand Down Expand Up @@ -1262,6 +1280,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
number: Int,
w: IndentWriter
): IndentWriter = {
val _ = (prefix, number) // unused, TODO, check remove
val recordAsMethodName = idCpp.method(ident.name)

for (f <- r.fields) {
Expand Down Expand Up @@ -1361,6 +1380,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
create: Boolean,
f: IndentWriter => Unit
): Unit = {
val _ = cppClass // unused, TODO, check remove
if (create)
createFile(
spec.cWrapperHeaderOutFolder.get,
Expand Down Expand Up @@ -1398,6 +1418,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
create: Boolean,
f: IndentWriter => Unit
): Unit = {
val _ = cppClass // unused, TODO, check remove
// hpp file contains definition of DjinniStruct wrapper over cpp shared_ptr
// meant to facilitate interuse of interfaces across files
if (create)
Expand Down Expand Up @@ -1544,6 +1565,7 @@ class CWrapperGenerator(spec: Spec) extends Generator(spec) {
w: IndentWriter,
className: String
): Unit = {
val _ = ident // unused, TODO, check remove
w.wl("struct " + marshal.wrappedName(className) + " final {").nested {
w.wl(
marshal.wrappedName(className) + p(
Expand Down
69 changes: 36 additions & 33 deletions src/main/scala/djinni/CWrapperMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,40 +56,44 @@ class CWrapperMarshal(spec: Spec) extends Marshal(spec) { // modeled(pretty much
override def fqReturnType(ret: Option[TypeRef]): String =
throw new NotImplementedError()

def cFieldType(tm: MExpr, forHeader: Boolean): String = ctypename(tm, forHeader)
def cFieldType(tm: MExpr, forHeader: Boolean): String =
ctypename(tm, forHeader)
override def fieldType(tm: MExpr): String = ctypename(tm, false)
override def fqFieldType(tm: MExpr): String = throw new NotImplementedError()

// override def toCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion")
// override def fromCpp(tm: MExpr, expr: String): String = throw new AssertionError("cpp to cpp conversion")

def references(m: Meta, exclude: String): Seq[SymbolReference] = m match {
case p: MPrimitive =>
p.idlName match {
case "i8" | "i16" | "i32" | "i64" =>
List(ImportRef("<stdint.h>" + pythonCdefIgnore))
case "bool" => List(ImportRef("<stdbool.h>" + pythonCdefIgnore))
case _ => List()
}
case MDate => List(ImportRef("<chrono>" + pythonSetSourceIgnore))
case MBinary =>
List(
ImportRef("<vector>" + pythonSetSourceIgnore),
ImportRef("<stdint.h>" + pythonCdefIgnore)
)
case MOptional => List(ImportRef(spec.cppOptionalHeader))
case d: MDef =>
d.defType match {
case DInterface => List(ImportRef(q(cw + d.name + ".hpp")))
case DRecord => List(ImportRef(q(dh + d.name + ".hpp")))
case DEnum =>
List(
ImportRef(q(d.name + ".hpp")),
ImportRef(q(dh + d.name + ".hpp"))
)
}
case _: MExtern => throw new NotImplementedError()
case _ => List()
def references(m: Meta, exclude: String): Seq[SymbolReference] = {
val _ = exclude // unused, TODO: remove
m match {
case p: MPrimitive =>
p.idlName match {
case "i8" | "i16" | "i32" | "i64" =>
List(ImportRef("<stdint.h>" + pythonCdefIgnore))
case "bool" => List(ImportRef("<stdbool.h>" + pythonCdefIgnore))
case _ => List()
}
case MDate => List(ImportRef("<chrono>" + pythonSetSourceIgnore))
case MBinary =>
List(
ImportRef("<vector>" + pythonSetSourceIgnore),
ImportRef("<stdint.h>" + pythonCdefIgnore)
)
case MOptional => List(ImportRef(spec.cppOptionalHeader))
case d: MDef =>
d.defType match {
case DInterface => List(ImportRef(q(cw + d.name + ".hpp")))
case DRecord => List(ImportRef(q(dh + d.name + ".hpp")))
case DEnum =>
List(
ImportRef(q(d.name + ".hpp")),
ImportRef(q(dh + d.name + ".hpp"))
)
}
case _: MExtern => throw new NotImplementedError()
case _ => List()
}
}

// Types that need RAII will be placed in unique pointers at acquisition time, and released when the language
Expand All @@ -107,8 +111,8 @@ class CWrapperMarshal(spec: Spec) extends Marshal(spec) { // modeled(pretty much
case MOptional =>
tm.args.head.base match {
case _: MPrimitive => true
case MDate => true
case _ => needsRAII(tm.args.head)
case MDate => true
case _ => needsRAII(tm.args.head)
}
case _: MExtern => throw new NotImplementedError()
case _ => false
Expand All @@ -118,7 +122,7 @@ class CWrapperMarshal(spec: Spec) extends Marshal(spec) { // modeled(pretty much
case MString | MBinary => true
case MOptional =>
tm.args.head.base match {
case _: MPrimitive => true
case _: MPrimitive => true
case MString | MBinary => true
case MDate => true
case _ => false
Expand Down Expand Up @@ -202,7 +206,6 @@ class CWrapperMarshal(spec: Spec) extends Marshal(spec) { // modeled(pretty much
case _ => throw new NotImplementedError()
}


private def toCIdlType(tm: MExpr): String = {
def baseToIdl(m: Meta): String = m match {
case p: MPrimitive => p.cName
Expand All @@ -217,7 +220,7 @@ class CWrapperMarshal(spec: Spec) extends Marshal(spec) { // modeled(pretty much
case MOptional =>
tm.args.head.base match {
case _: MPrimitive => "boxed"
case _ => "optional"
case _ => "optional"
}
case _ => m.asInstanceOf[MOpaque].idlName
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/djinni/CffiGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class CffiGenerator(spec: Spec) extends Generator(spec) {
val marshal = new PythonMarshal(spec)
val cffi: String = spec.pycffiPackageName + "_cffi"

def writeCffiFile(ident: String, origin: String, f: IndentWriter => Unit): Unit = {
def writeCffiFile(
ident: String,
origin: String,
f: IndentWriter => Unit
): Unit = {
val _ = (ident, origin) // unused, TODO: remove
createFileOnce(
spec.pycffiOutFolder.get,
"pycffi_lib_build" + ".py",
Expand Down
21 changes: 14 additions & 7 deletions src/main/scala/djinni/CppCliGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ class CppCliGenerator(spec: Spec) extends Generator(spec) {
def withCppCliNs(namespace: String, t: String): String =
withNs(Some(namespace), t)

val writeCppCliCppFile: (String, String, Iterable[String], IndentWriter => Unit) => Unit = writeCppFileGeneric(
spec.cppCliOutFolder.get,
spec.cppCliNamespace,
spec.cppCliIdentStyle.file,
""
) _
val writeCppCliCppFile
: (String, String, Iterable[String], IndentWriter => Unit) => Unit =
writeCppFileGeneric(
spec.cppCliOutFolder.get,
spec.cppCliNamespace,
spec.cppCliIdentStyle.file,
""
) _

def writeCppCliHppFile(
name: String,
Expand Down Expand Up @@ -164,7 +166,12 @@ class CppCliGenerator(spec: Spec) extends Generator(spec) {
}
}

override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum): Unit = {
override def generateEnum(
origin: String,
ident: Ident,
doc: Doc,
e: Enum
): Unit = {
val refs = new CppCliRefs(ident.name)

writeCppCliHppFile(
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/djinni/CppCliMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class CppCliMarshal(spec: Spec) extends Marshal(spec) {
toCppCliType(tm, None, Seq(), needsHandle = true)
def typename(ty: TypeRef, needsHandle: Boolean): String =
toCppCliType(ty, None, Seq(), needsHandle)
def typename(name: String, ty: TypeDef): String = idCs.ty(name)
def typename(name: String, ty: TypeDef): String = {
val _ = ty // unused, TODO: remove
idCs.ty(name)
}

override def fqTypename(tm: meta.MExpr): String =
toCppCliType(tm, Some(spec.cppCliNamespace), Seq(), needsHandle = true)
Expand Down Expand Up @@ -67,6 +70,7 @@ class CppCliMarshal(spec: Spec) extends Marshal(spec) {
}

def include(ident: String, isExtendedRecord: Boolean = false): String = {
val _ = isExtendedRecord // unused, TODO: remove
q(spec.cppCliIdentStyle.file(ident) + "." + spec.cppHeaderExt)
}

Expand Down
23 changes: 15 additions & 8 deletions src/main/scala/djinni/CppGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class CppGenerator(spec: Spec) extends Generator(spec) {

val marshal = new CppMarshal(spec)

val writeCppFile: (String, String, Iterable[String], IndentWriter => Unit) => Unit = writeCppFileGeneric(
spec.cppOutFolder.get,
spec.cppNamespace,
spec.cppFileIdentStyle,
spec.cppIncludePrefix
) _
val writeCppFile
: (String, String, Iterable[String], IndentWriter => Unit) => Unit =
writeCppFileGeneric(
spec.cppOutFolder.get,
spec.cppNamespace,
spec.cppFileIdentStyle,
spec.cppIncludePrefix
) _
def writeHppFile(
name: String,
origin: String,
Expand Down Expand Up @@ -127,7 +129,12 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
}
}

override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum): Unit = {
override def generateEnum(
origin: String,
ident: Ident,
doc: Doc,
e: Enum
): Unit = {
val refs = new CppRefs(ident.name)
val self = marshal.typename(ident, e)

Expand Down Expand Up @@ -315,7 +322,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
def generateHppConstants(w: IndentWriter, consts: Seq[Const]): Unit = {
for (c <- consts) {
// set value in header if can constexpr (only primitives)
var constexpr = shouldConstexpr(c)
val constexpr = shouldConstexpr(c)
var constValue = ";"
if (constexpr) {
constValue = c.value match {
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/djinni/CppMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
ty: TypeRef,
namespace: Option[String] = None,
scopeSymbols: Seq[String] = Seq()
): String =
): String = {
toCppType(ty.resolved, namespace, scopeSymbols)
}

private def toCppType(
tm: MExpr,
Expand Down
Loading

0 comments on commit ee45fd1

Please sign in to comment.