Skip to content

Commit

Permalink
interface generator: allow comments inside classes
Browse files Browse the repository at this point in the history
although the Pascal generator merging field type declarations, messes the comments up by putting them all at the beginning
  • Loading branch information
benibela committed Nov 15, 2023
1 parent 141a366 commit fbf6a7c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ object ImportExportFlag {
}



//nativePtr is a very large object which must be destroyed with a call to VLImportAccounts

open class ImportExportData(
@JvmField var accountsToImport: Array<String> = emptyArray(),
@JvmField var flags: Int = 0,
//nativePtr is a very large object which must be destroyed with a call to VLImportAccounts,
@JvmField var nativePtr: Long = 0
) {
override fun equals(other: Any?): Boolean =
Expand Down
1 change: 1 addition & 0 deletions commoninterface.pas
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ TOptionsShared = class
type

TImportExportData = record
//nativePtr is a very large object which must be destroyed with a call to VLImportAccounts
flags: int32;
nativePtr: int64;
accountsToImport: array of string;
Expand Down
7 changes: 4 additions & 3 deletions interface-generator-pretty-to-xml.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ declare function igp:make-class($annotations, $nameAndParent, $children){
case "@KotlinDataClass" return attribute kotlin-class {"data"}
case "@PascalClass" return attribute pascal-type {"class"}
default return igp:annotation-to-attribute($a),
for $x in $children!translate(., " ", "")
for $w in $children
let $x := $w!translate(., " ", "")
let $split := extract($x, "([^:]+):([^=]+)(=\s*(.*))?", (1,2,4) )
let $name := $split[1]!normalize-space()
let $type := $split[2]!normalize-space()
let $default := $split[3]
let $default := $default!(if ($type = "String") then replace(., '^"|"$', '') else .)
return
igp:make-type($type, (attribute name { $name }, $default[.] ! attribute default { . } ) )
return if (starts-with($x, "//")) then <comment>{$w!replace(., "^//", "")}</comment>
else igp:make-type($type, (attribute name { $name }, $default[.] ! attribute default { . } ) )
}
</class>
};
Expand Down
18 changes: 13 additions & 5 deletions interface-generator.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare function ig:error($e, $at){
};

declare function ig:properties($e){
$e/*
$e/*[not(self::comment)]
};

declare function ig:parent($e){
Expand Down Expand Up @@ -79,6 +79,7 @@ declare function ig:pascal-make-fields-of-type($s, $type){
};

declare function ig:pascal-make-fields($s, $prefix){
$s/comment/x"//{.}",
ig:pascal-make-fields-of-type($s/string, $prefix || "string"),
ig:pascal-make-fields-of-type($s/int, $prefix || "int32"),
ig:pascal-make-fields-of-type($s/long, $prefix || "int64"),
Expand Down Expand Up @@ -430,7 +431,8 @@ begin
case element(array) return x" temp[{$i}].l := arrayToJArrayCI(self.{$p/@name});&#x0A;"
case element(classref) return x" temp[{$i}].l := self.{$p/@name}.toJava;&#x0A;"
case element(intenumref) return x" temp[{$i}].i := ord(self.{$p/@name});&#x0A;"
default return ig:error("unknown property type")
case element(comment) return ()
default return ig:error("unknown property type (toJava)")
}
result := newObject({@id}Class, {@id}ClassInit, @temp[0]);
{for $p at $i in $allprops where $p[self::array or self::string or self::classref] return x" deleteLocalRef(temp[{$i - 1}].l);&#x0A;"}
Expand All @@ -449,7 +451,8 @@ begin
case element(array) return x" fromJavaArrayAndDelete({@name}, getObjectField( jvm, {@name}{ig:jni-pascal-suffix(.)} ));&#x0A;"
case element(classref) return x" {@name} := T{@ref}.fromJavaAndDelete(getObjectField( jvm, {@name}{ig:jni-pascal-suffix(.)} ));&#x0A;"
case element(intenumref) return x" {@name} := T{@ref}(getIntField( jvm, {@name}I ));&#x0A;"
default return ig:error("unknown property type.")
case element(comment) return ()
default return ig:error("unknown property type. (fromJava)")
)}
end;
end;
Expand Down Expand Up @@ -542,7 +545,10 @@ declare function ig:kotlin-make-class($s){
{(@kotlin-class, "open")[1]} class {@id}(
{ join ((
$aprops!ig:kotlin-make-prop(., $addDefault),
*/ig:kotlin-make-prop(., $addDefault)!concat($fieldtype,.)
*/(
if (self::comment) then x"//{.}"
else ig:kotlin-make-prop(., $addDefault)!concat($fieldtype,.)
)
), ",&#x0A; ")
}
) {ig:parent(.)!x": {.}({join($aprops!@name, ", ")})"} {{
Expand All @@ -551,13 +557,15 @@ declare function ig:kotlin-make-class($s){
typeswitch (.)
case element(string)|element(int)|element(long)|element(double)|element(boolean)|element(classref)|element(intenumref) return concat(@name, " == other.", @name)
case element(array) return concat(@name, ".contentEquals(other.", @name,")")
case element(comment) return ()
default return ig:error("Unknown field type", .)
)), " &amp;&amp; ")}
override fun hashCode(): Int =
super.hashCode() { */concat("xor ",
super.hashCode() { ig:properties(.)/concat("xor ",
typeswitch (.)
case element(string)|element(int)|element(long)|element(double)|element(boolean)|element(classref)|element(intenumref) return @name || ".hashCode()"
case element(array) return concat(@name, ".contentHashCode()")
case element(comment) return ()
default return ig:error("Unknown field type", .)
, ".rotateLeft(",position(),")" ) }
}}")
Expand Down
2 changes: 1 addition & 1 deletion interface.pretty
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ enum ImportExportFlag {
}


//nativePtr is a very large object which must be destroyed with a call to VLImportAccounts
@Pascal<->Kotlin
@KotlinVar
class ImportExportData {
accountsToImport: String[]
flags: Int
//nativePtr is a very large object which must be destroyed with a call to VLImportAccounts
nativePtr: Long
}

Expand Down
2 changes: 1 addition & 1 deletion interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
<value name="Config" value="4"/>
<value name="Password" value="8"/>
</intenum>
<comment>nativePtr is a very large object which must be destroyed with a call to VLImportAccounts</comment>
<class id="ImportExportData" jvm-pascal="" pascal-jvm="" kotlin-var="var">
<array name="accountsToImport">
<string/>
</array>
<int name="flags"/>
<comment>nativePtr is a very large object which must be destroyed with a call to VLImportAccounts</comment>
<long name="nativePtr"/>
</class>
<comment>Classes to represent metadata of a library</comment>
Expand Down

0 comments on commit fbf6a7c

Please sign in to comment.