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

Unknown port types handled with unknown instead of Present #1857

Merged
merged 9 commits into from
Jul 2, 2023
Merged
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
1 change: 0 additions & 1 deletion core/src/main/java/org/lflang/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ public enum Target {
// underscores)
"TimeUnit",
"TimeValue",
"Present",
"Sched",
"Read",
"Write",
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/TargetTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ default String getTargetBracedListExpr(BracedListExpression expr, InferredType t
.collect(Collectors.joining(",", "{", "}"));
}

/** Return an "undefined" type which is used as a default when a type cannot be inferred. */
/** Return an "unknown" type which is used as a default when a type cannot be inferred. */
String getTargetUndefinedType();

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/ts/TSTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getTargetTagType() {

@Override
public String getTargetUndefinedType() {
return "Present";
return "unknown";
}

public String getTargetTimeExpr(TimeValue value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ object TSDelayBodyGenerator : DelayBodyGenerator {
/**
* Return a TS type for the specified action.
* If the type has not been specified, return
* "Present" which is the base type for Actions.
* `unknown`.
* @param action The action
* @return The TS type.
*/
private fun getActionType(action: Action): String {
return if (action.type != null) {
TSTypes.getInstance().getTargetType(action.type)
} else {
"Present"
"unknown"
}
}

Expand All @@ -30,7 +30,7 @@ object TSDelayBodyGenerator : DelayBodyGenerator {
}

override fun generateDelayGeneric(): String {
return "T extends Present"
return "T"
}

override fun generateAfterDelaysWithVariableWidth() = false
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/kotlin/org/lflang/generator/ts/TSExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ fun WidthSpec.toTSCode(): String = terms.joinToString(" + ") {
/**
* Return a TS type for the specified port.
* If the type has not been specified, return
* "Present" which is the base type for ports.
* `unknown`.
* @return The TS type.
*/
val Port.tsPortType: String
get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "Present"
get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "unknown"

/**
* Return a TS type for the specified action.
* If the type has not been specified, return
* "Present" which is the base type for Actions.
* `unknown` which is the base type for Actions.
* @return The TS type.
*/
val Action.tsActionType: String
get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "Present"
get() = type?.let { TSTypes.getInstance().getTargetType(it) } ?: "unknown"

fun Expression.toTsTime(): String = TSTypes.getInstance().getTargetTimeExpr(this)
fun TimeValue.toTsTime(): String = TSTypes.getInstance().getTargetTimeExpr(this)
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TSImportPreambleGenerator(
import {Reaction as __Reaction} from '@lf-lang/reactor-ts'
import {State as __State} from '@lf-lang/reactor-ts'
import {TimeUnit, TimeValue, Tag as __Tag, Origin as __Origin} from '@lf-lang/reactor-ts'
import {Args as __Args, Variable as __Variable, Triggers as __Triggers, Present, Read, Write, ReadWrite, MultiReadWrite, Sched} from '@lf-lang/reactor-ts'
import {Variable as __Variable, Read, Write, ReadWrite, MultiReadWrite, Sched} from '@lf-lang/reactor-ts'
import {Log} from '@lf-lang/reactor-ts'
import {ProcessedCommandLineArgs as __ProcessedCommandLineArgs, CommandLineOptionDefs as __CommandLineOptionDefs, CommandLineUsageDefs as __CommandLineUsageDefs, CommandLineOptionSpec as __CommandLineOptionSpec, unitBasedTimeValueCLAType as __unitBasedTimeValueCLAType, booleanCLAType as __booleanCLAType} from '@lf-lang/reactor-ts'
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class TSReactionGenerator(
"""
|
|this.add${if (reaction.isMutation) "Mutation" else "Reaction"}(
| new __Triggers($reactionTriggers),
| new __Args($reactFuncArgs),
| [$reactionTriggers],
| [$reactFuncArgs],
| function ($reactSignature) {
| // =============== START react prologue
${" | "..reactPrologue}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.lflang.generator.ts

import org.lflang.generator.getTargetTimeExpr
import org.lflang.generator.orZero
import org.lflang.lf.Expression
import org.lflang.lf.Timer
import java.util.*

Expand Down