Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadliaJerad committed Dec 2, 2024
1 parent 4f33efb commit 78f7815
Showing 1 changed file with 67 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@
public class CExtensionUtils {

// Regular expression pattern for shared_ptr types.
static final Pattern sharedPointerVariable = Pattern
.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?<type>((/\\*.*?\\*/)?(\\S+))+)>$");
static final Pattern sharedPointerVariable =
Pattern.compile("^(/\\*.*?\\*/)?std::shared_ptr<(?<type>((/\\*.*?\\*/)?(\\S+))+)>$");

/**
* Generate C code that initializes network actions.
*
* <p>
* These network actions will be triggered by federate.c whenever a message is
* received from
* <p>These network actions will be triggered by federate.c whenever a message is received from
* the network.
*
* @param federate The federate.
* @param main The main reactor that contains the federate (used to lookup
* references).
* @param main The main reactor that contains the federate (used to lookup references).
*/
public static String initializeTriggersForNetworkActions(
FederateInstance federate, ReactorInstance main) {
Expand Down Expand Up @@ -101,11 +98,8 @@ public static String initializeTriggersForNetworkActions(
/**
* Generate C code that holds a sorted list of STAA structs by time.
*
* <p>
* For decentralized execution, on every logical timestep, a thread will iterate
* through each
* staa struct, wait for the designated offset time, and set the associated port
* status to absent
* <p>For decentralized execution, on every logical timestep, a thread will iterate through each
* staa struct, wait for the designated offset time, and set the associated port status to absent
* if it isn't known.
*
* @param federate The federate.
Expand All @@ -121,7 +115,8 @@ public static String stpStructs(FederateInstance federate) {
// main reactor for each Action.
for (int i = 0; i < federate.staaOffsets.size(); ++i) {
// Find the corresponding ActionInstance.
List<Action> networkActions = federate.staToNetworkActionMap.get(federate.staaOffsets.get(i));
List<Action> networkActions =
federate.staToNetworkActionMap.get(federate.staaOffsets.get(i));

code.pr("staa_lst[" + i + "] = (staa_t*) malloc(sizeof(staa_t));");
code.pr(
Expand Down Expand Up @@ -154,8 +149,7 @@ public static String stpStructs(FederateInstance federate) {
}

/**
* Create a port status field variable for a network input port "input" in the
* self struct of a
* Create a port status field variable for a network input port "input" in the self struct of a
* reactor.
*
* @param input The network input port
Expand All @@ -176,23 +170,15 @@ public static String createPortStatusFieldForInput(Input input) {
}

/**
* Given a connection 'delay' expression, return a string that represents the
* interval_t value of
* Given a connection 'delay' expression, return a string that represents the interval_t value of
* the additional delay that needs to be applied to the outgoing message.
*
* <p>
* The returned additional delay in absence of after on network connection
* (i.e., if delay is
* passed as a null) is NEVER. This has a special meaning in C library functions
* that send network
* messages that carry timestamps (@see lf_send_tagged_message and
* lf_send_port_absent_to_federate
* in lib/core/federate.c). In this case, the sender will send its current tag
* as the timestamp of
* the outgoing message without adding a microstep delay. If the user has
* assigned an after delay
* to the network connection (that can be zero) either as a time value (e.g.,
* 200 msec) or as a
* <p>The returned additional delay in absence of after on network connection (i.e., if delay is
* passed as a null) is NEVER. This has a special meaning in C library functions that send network
* messages that carry timestamps (@see lf_send_tagged_message and lf_send_port_absent_to_federate
* in lib/core/federate.c). In this case, the sender will send its current tag as the timestamp of
* the outgoing message without adding a microstep delay. If the user has assigned an after delay
* to the network connection (that can be zero) either as a time value (e.g., 200 msec) or as a
* literal (e.g., a parameter), that delay in nsec will be returned.
*
* @param delay The delay associated with a connection.
Expand Down Expand Up @@ -236,9 +222,11 @@ public static void handleCompileDefinitions(
}

private static void handleAdvanceMessageInterval(FederateInstance federate) {
var advanceMessageInterval = federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval;
var advanceMessageInterval =
federate.targetConfig.get(CoordinationOptionsProperty.INSTANCE).advanceMessageInterval;
if (advanceMessageInterval != null) {
federate.targetConfig
federate
.targetConfig
.get(CompileDefinitionsProperty.INSTANCE)
.put("ADVANCE_MESSAGE_INTERVAL", String.valueOf(advanceMessageInterval.toNanoSeconds()));
}
Expand All @@ -251,14 +239,12 @@ static boolean clockSyncIsOn(FederateInstance federate, RtiConfig rtiConfig) {
}

/**
* Initialize clock synchronization (if enabled) and its related options for a
* given federate.
* Initialize clock synchronization (if enabled) and its related options for a given federate.
*
* <p>
* Clock synchronization can be enabled using the clock-sync target property.
* <p>Clock synchronization can be enabled using the clock-sync target property.
*
* @see <a href=
* "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation</a>
* "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation</a>
*/
public static void initializeClockSynchronization(
FederateInstance federate, RtiConfig rtiConfig, MessageReporter messageReporter) {
Expand All @@ -285,14 +271,12 @@ public static void initializeClockSynchronization(
}

/**
* Initialize clock synchronization (if enabled) and its related options for a
* given federate.
* Initialize clock synchronization (if enabled) and its related options for a given federate.
*
* <p>
* Clock synchronization can be enabled using the clock-sync target property.
* <p>Clock synchronization can be enabled using the clock-sync target property.
*
* @see <a href=
* "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation</a>
* "https://github.com/icyphy/lingua-franca/wiki/Distributed-Execution#clock-synchronization">Documentation</a>
*/
public static void addClockSyncCompileDefinitions(FederateInstance federate) {

Expand Down Expand Up @@ -323,9 +307,10 @@ public static void generateCMakeInclude(
FederateInstance federate, FederationFileConfig fileConfig) throws IOException {
Files.createDirectories(fileConfig.getSrcPath().resolve("include"));

Path cmakeIncludePath = fileConfig
.getSrcPath()
.resolve("include" + File.separator + federate.name + "_extension.cmake");
Path cmakeIncludePath =
fileConfig
.getSrcPath()
.resolve("include" + File.separator + federate.name + "_extension.cmake");

CodeBuilder cmakeIncludeCode = new CodeBuilder();

Expand All @@ -347,8 +332,7 @@ public static void generateCMakeInclude(
}

/**
* Generate code that sends the neighbor structure message to the RTI. See
* {@code
* Generate code that sends the neighbor structure message to the RTI. See {@code
* MSG_TYPE_NEIGHBOR_STRUCTURE} in {@code federated/net_common.h}.
*
* @param federate The federate that is sending its neighbor structure
Expand Down Expand Up @@ -421,13 +405,14 @@ public static String generateFederateNeighborStructure(FederateInstance federate
// Use NEVER to encode no delay at all.
code.pr("candidate_tmp = NEVER;");
} else {
var delayTime = delay instanceof ParameterReference
// In that case use the default value.
? CTypes.getInstance()
.getTargetTimeExpr(
ASTUtils.getDefaultAsTimeValue(
((ParameterReference) delay).getParameter()))
: CTypes.getInstance().getTargetExpr(delay, InferredType.time());
var delayTime =
delay instanceof ParameterReference
// In that case use the default value.
? CTypes.getInstance()
.getTargetTimeExpr(
ASTUtils.getDefaultAsTimeValue(
((ParameterReference) delay).getParameter()))
: CTypes.getInstance().getTargetExpr(delay, InferredType.time());

code.pr(
String.join(
Expand Down Expand Up @@ -484,27 +469,26 @@ public static String surroundWithIfElseFederated(String insideIf, String insideE
return surroundWithIfFederated(insideIf);
} else {
return """
#ifdef FEDERATED
%s
#else
%s
#endif // FEDERATED
"""
#ifdef FEDERATED
%s
#else
%s
#endif // FEDERATED
"""
.formatted(insideIf, insideElse);
}
}

/**
* Surround {@code code} with blocks to ensure that code only executes if the
* program is
* Surround {@code code} with blocks to ensure that code only executes if the program is
* federated.
*/
public static String surroundWithIfFederated(String code) {
return """
#ifdef FEDERATED
%s
#endif // FEDERATED
"""
#ifdef FEDERATED
%s
#endif // FEDERATED
"""
.formatted(code);
}

Expand All @@ -513,41 +497,39 @@ public static String surroundWithIfElseFederatedCentralized(String insideIf, Str
return surroundWithIfFederatedCentralized(insideIf);
} else {
return """
#ifdef FEDERATED_CENTRALIZED
%s
#else
%s
#endif // FEDERATED_CENTRALIZED
"""
#ifdef FEDERATED_CENTRALIZED
%s
#else
%s
#endif // FEDERATED_CENTRALIZED
"""
.formatted(insideIf, insideElse);
}
}

/**
* Surround {@code code} with blocks to ensure that code only executes if the
* program is federated
* Surround {@code code} with blocks to ensure that code only executes if the program is federated
* and has a centralized coordination.
*/
public static String surroundWithIfFederatedCentralized(String code) {
return """
#ifdef FEDERATED_CENTRALIZED
%s
#endif // FEDERATED_CENTRALIZED
"""
#ifdef FEDERATED_CENTRALIZED
%s
#endif // FEDERATED_CENTRALIZED
"""
.formatted(code);
}

/**
* Surround {@code code} with blocks to ensure that code only executes if the
* program is federated
* Surround {@code code} with blocks to ensure that code only executes if the program is federated
* and has a decentralized coordination.
*/
public static String surroundWithIfFederatedDecentralized(String code) {
return """
#ifdef FEDERATED_DECENTRALIZED
%s
#endif // FEDERATED_DECENTRALIZED
"""
#ifdef FEDERATED_DECENTRALIZED
%s
#endif // FEDERATED_DECENTRALIZED
"""
.formatted(code);
}

Expand All @@ -568,9 +550,7 @@ public static String generateSerializationIncludes(FederateInstance federate) {
return code.getCode();
}

/**
* Generate cmake-include code needed for enabled serializers of the federate.
*/
/** Generate cmake-include code needed for enabled serializers of the federate. */
public static String generateSerializationCMakeExtension(FederateInstance federate) {
CodeBuilder code = new CodeBuilder();
for (SupportedSerializers serializer : federate.enabledSerializers) {
Expand Down

0 comments on commit 78f7815

Please sign in to comment.