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

Port CGenerator.xtend to Java #1049

Merged
merged 12 commits into from
Mar 17, 2022
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
@@ -793,7 +793,7 @@ public boolean isFederatedAndCentralized() {
* @param The name of the docker file.
* @param The name of the federate.
*/
public void writeDockerFile(File dockerComposeDir, String dockerFileName, String federateName) {
public void writeDockerFile(File dockerComposeDir, String dockerFileName, String federateName) throws IOException {
throw new UnsupportedOperationException("This target does not support docker file generation.");
}

35 changes: 35 additions & 0 deletions org.lflang/src/org/lflang/generator/c/CConstructorGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.lflang.generator.c;

import org.lflang.federated.FederateInstance;
import org.lflang.generator.CodeBuilder;
import org.lflang.lf.ReactorDecl;

/**
* Generates C constructor code for a reactor.
*
*/
public class CConstructorGenerator {
/**
* Generate a constructor for the specified reactor in the specified federate.
* @param reactor The parsed reactor data structure.
* @param federate A federate name, or null to unconditionally generate.
* @param constructorCode Lines of code previously generated that need to
* go into the constructor.
*/
public static String generateConstructor(
ReactorDecl reactor,
FederateInstance federate,
String constructorCode
) {
var structType = CUtil.selfType(reactor);
var code = new CodeBuilder();
code.pr(structType+"* new_"+reactor.getName()+"() {");
code.indent();
code.pr(structType+"* self = ("+structType+"*)_lf_new_reactor(sizeof("+structType+"));");
code.pr(constructorCode);
code.pr("return self;");
code.unindent();
code.pr("}");
return code.toString();
}
}
Loading