Skip to content

Commit

Permalink
clean up in TargetTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnrd committed Mar 7, 2024
1 parent 210a7e0 commit 2718a02
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
12 changes: 1 addition & 11 deletions core/src/main/java/org/lflang/generator/TargetTypes.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.lflang.generator;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.lflang.InferredType;
import org.lflang.TimeValue;
Expand All @@ -26,9 +25,6 @@
* and types to the target language. Each code generator is expected to use at least one
* language-specific instance of this interface.
*
* <p>TODO currently, {@link GeneratorBase} implements this interface, it should instead contain an
* instance.
*
* @author Clément Fournier - TU Dresden, INSA Rennes
*/
public interface TargetTypes {
Expand Down Expand Up @@ -88,12 +84,7 @@ default String escapeIdentifier(String ident) {
* Returns an expression in the target language that corresponds to the given time value ({@link
* #getTargetTimeType()}).
*/
default String getTargetTimeExpr(TimeValue timeValue) {
// todo make non-default when we reuse this for all generators,
// all targets should support this.
Objects.requireNonNull(timeValue);
throw new UnsupportedGeneratorFeatureException("Time expressions");
}
String getTargetTimeExpr(TimeValue timeValue);

/**
* Returns the expression that is used to replace a missing expression in the source language. The
Expand Down Expand Up @@ -182,7 +173,6 @@ default String getTargetInitializer(Initializer init, Type type) {
* Returns the representation of the given expression in target code. The given type, if non-null,
* may inform the code generation.
*/
// FIXME use visitor pattern???
default String getTargetExpr(Expression expr, InferredType type) {
if (ASTUtils.isZero(expr) && type != null && type.isTime) {
return getTargetTimeExpr(TimeValue.ZERO);
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/org/lflang/generator/c/CTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull

@Override
public String getTargetTimeExpr(TimeValue time) {
if (time != null) {
if (time.unit != null) {
return cMacroName(time.unit) + "(" + time.getMagnitude() + ")";
} else {
return Long.valueOf(time.getMagnitude()).toString();
}
}
return "0"; // FIXME: do this or throw exception?
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/lflang/generator/ts/TSTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public String getTargetUndefinedType() {
return "unknown";
}

@Override
public String getTargetTimeExpr(TimeValue value) {
if (value.unit != null) {
return "TimeValue.%s(%s)".formatted(value.unit.getCanonicalName(), value.time);
Expand Down

0 comments on commit 2718a02

Please sign in to comment.