Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding cli option to remove interfaces constraints on records. #156

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ verify the build and binary from the command line.
- Local flags with `@flag` directive
- DataView for copy free data passing
- DateRef for copy free data passing with ownership
- Allows for not null interfaces references in records
- Generating string names for C++ enums
- Bug fixes

Expand Down Expand Up @@ -301,9 +302,9 @@ Notable differences when comparing to the Java/ObjC support:
easily add extension methods (by add functions to prototype) without having to
derive from a base class.

The command to run Wasm/TypeScript unit tests is `bazel run
//test-suite:server-ts`. You will need the `tsc` compiler and the `browserify`
tool to run these tests.
Use `bazel run //test-suite:server-ts` to run the Wasm/TypeScript unit tests.
You will need `npm` and run `npm install` in the `test-suite` folder.
You need as well the `tsc` compiler and the `browserify` tool to run these tests.

## Async interface support

Expand Down
6 changes: 5 additions & 1 deletion src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ object Main {
var inFileListPath: Option[File] = None
var outFileListPath: Option[File] = None
var skipGeneration: Boolean = false
var allowInterfacesInRecords: Boolean = false
var yamlOutFolder: Option[File] = None
var yamlOutFile: Option[String] = None
var yamlPrefix: String = ""
Expand Down Expand Up @@ -265,6 +266,8 @@ object Main {
.text("Optional file in which to write the list of output files produced.")
opt[Boolean]("skip-generation").valueName("<true/false>").foreach(x => skipGeneration = x)
.text("Way of specifying if file generation should be skipped (default: false)")
opt[Boolean]("allow-interfaces-in-records").valueName("<true/false>").foreach(x => allowInterfacesInRecords = x)
.text("Allows for records to contain interfaces.")

note("\nIdentifier styles (ex: \"FooBar\", \"fooBar\", \"foo_bar\", \"FOO_BAR\", \"m_fooBar\")\nUse an exclamation mark to apply stricty, even on ALL_CAPS identifiers (ex: \"FooBar!\")\n")
identStyle("ident-java-enum", c => { javaIdentStyle = javaIdentStyle.copy(enum = c) })
Expand Down Expand Up @@ -341,7 +344,7 @@ object Main {

// Resolve names in IDL file, check types.
System.out.println("Resolving...")
resolver.resolve(meta.defaults, idl) match {
resolver.resolve(meta.defaults, idl, allowInterfacesInRecords) match {
case Some(err) =>
System.err.println(err)
System.exit(1); return
Expand Down Expand Up @@ -435,6 +438,7 @@ object Main {
jsIdentStyle,
tsOutFolder,
tsModule,
allowInterfacesInRecords,
outFileListWriter,
skipGeneration,
yamlOutFolder,
Expand Down
1 change: 1 addition & 0 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ package object generatorTools {
jsIdentStyle: JsIdentStyle,
tsOutFolder: Option[File],
tsModule: String,
allowInterfacesInRecords: Boolean,
outFileListWriter: Option[Writer],
skipGeneration: Boolean,
yamlOutFolder: Option[File],
Expand Down
18 changes: 11 additions & 7 deletions src/source/resolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package object resolver {

type Scope = immutable.Map[String,Meta]

def resolve(metas: Scope, idl: Seq[TypeDecl]): Option[Error] = {
def resolve(metas: Scope, idl: Seq[TypeDecl], allowInterfacesInRecords: Boolean): Option[Error] = {

try {
var topScope = metas
Expand Down Expand Up @@ -74,7 +74,7 @@ def resolve(metas: Scope, idl: Seq[TypeDecl]): Option[Error] = {
scope = scope.updated(typeParam.ident.name, MParam(typeParam.ident.name))
}

resolve(scope, typeDecl.body)
resolve(scope, typeDecl.body, allowInterfacesInRecords)
}

for (typeDecl <- idl) {
Expand All @@ -88,10 +88,10 @@ def resolve(metas: Scope, idl: Seq[TypeDecl]): Option[Error] = {
None
}

private def resolve(scope: Scope, typeDef: TypeDef) {
private def resolve(scope: Scope, typeDef: TypeDef, allowInterfacesInRecords: Boolean) {
typeDef match {
case e: Enum => resolveEnum(scope, e)
case r: Record => resolveRecord(scope, r)
case r: Record => resolveRecord(scope, r, allowInterfacesInRecords)
case i: Interface => resolveInterface(scope, i)
case p: ProtobufMessage=>
}
Expand Down Expand Up @@ -214,7 +214,7 @@ private def constTypeCheck(ty: MExpr, value: Any, resolvedConsts: Seq[Const]) {
}
}

private def resolveRecord(scope: Scope, r: Record) {
private def resolveRecord(scope: Scope, r: Record, allowInterfacesInRecords: Boolean) {
val dupeChecker = new DupeChecker("record field")
for (f <- r.fields) {
dupeChecker.check(f.ident)
Expand Down Expand Up @@ -243,7 +243,9 @@ private def resolveRecord(scope: Scope, r: Record) {
}
case df: MDef => df.defType match {
case DInterface =>
throw new Error(f.ident.loc, "Interface reference cannot live in a record").toException
if (!allowInterfacesInRecords) {
throw new Error(f.ident.loc, "Interface reference cannot live in a record").toException
}
case DRecord =>
val record = df.body.asInstanceOf[Record]
if (!r.derivingTypes.subsetOf(record.derivingTypes))
Expand All @@ -252,7 +254,9 @@ private def resolveRecord(scope: Scope, r: Record) {
}
case e: MExtern => e.defType match {
case DInterface =>
throw new Error(f.ident.loc, "Interface reference cannot live in a record").toException
if (!allowInterfacesInRecords) {
throw new Error(f.ident.loc, "Interface reference cannot live in a record").toException
}
case DRecord =>
val record = e.body.asInstanceOf[Record]
if (!r.derivingTypes.subsetOf(record.derivingTypes))
Expand Down
Loading