Skip to content

Commit

Permalink
Let targetProperty classes specifies their behavior on updating from
Browse files Browse the repository at this point in the history
imported file
  • Loading branch information
byeonggiljun committed Mar 5, 2024
1 parent 5997ca5 commit fea23a1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void update(
.map(Objects::toString)
.toList();
fileListProperty.update(config, files);
} else {
} else if (property.loadFromFederate()) {
p.get().update(this, pair, err);
}
}
Expand Down
25 changes: 20 additions & 5 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.lflang.ast.ASTUtils.allPorts;
import static org.lflang.ast.ASTUtils.allReactions;
import static org.lflang.ast.ASTUtils.allStateVars;
import static org.lflang.ast.ASTUtils.convertToEmptyListIfNull;
import static org.lflang.ast.ASTUtils.getInferredType;
import static org.lflang.ast.ASTUtils.isInitialized;
import static org.lflang.ast.ASTUtils.toDefinition;
Expand Down Expand Up @@ -727,11 +728,25 @@ private void inspectReactorEResource(ReactorDecl reactor) {
if (lfResource != null) {
// Copy the user files and cmake-includes to the src-gen path of the main .lf file
copyUserFiles(lfResource.getTargetConfig(), lfResource.getFileConfig());
// Merge the CMake includes from the imported file into the target config
if (lfResource.getTargetConfig().isSet(CmakeIncludeProperty.INSTANCE)) {
CmakeIncludeProperty.INSTANCE.update(
this.targetConfig, lfResource.getTargetConfig().get(CmakeIncludeProperty.INSTANCE));
}

var config = lfResource.getTargetConfig();
var pairs = convertToEmptyListIfNull(config.extractTargetDecl().getConfig().getPairs());
pairs.forEach(
pair -> {
var p = config.forName((pair.getName()));
if (p.isPresent()) {
var property = p.get();
if (property.loadFromImport()) {
property.update(this.targetConfig, pair, messageReporter);
}
}
}
);
// // Merge the CMake includes from the imported file into the target config
// if (lfResource.getTargetConfig().isSet(CmakeIncludeProperty.INSTANCE)) {
// CmakeIncludeProperty.INSTANCE.update(
// this.targetConfig, lfResource.getTargetConfig().get(CmakeIncludeProperty.INSTANCE));
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public Element toAstElement(List<String> value) {
public String name() {
return "cmake-include";
}

@Override
public Boolean loadFromImport() {
return true;
}

@Override
public Boolean loadFromFederate() {
return true;
}
}
15 changes: 15 additions & 0 deletions core/src/main/java/org/lflang/target/property/TargetProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ public Optional<Element> astElementFromConfig(TargetConfig config) {
/** Return the name of this target property (in kebab case). */
public abstract String name();

/** Return the policy of loading from imported file */
public Boolean loadFromImport() {
return false;
}

/** Return the policy of loading from imported file */
public Boolean loadFromFederation() {
return true;
}

/** Return the policy of loading from imported file */
public Boolean loadFromFederate() {
return false;
}

/**
* Replace the value assigned to this target property in the given config with the given value.
*
Expand Down

0 comments on commit fea23a1

Please sign in to comment.