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

Add retain to type export #109

Merged
merged 8 commits into from
May 13, 2024
Merged
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import org.eclipse.fordiac.ide.model.libraryElement.FBType
import org.eclipse.fordiac.ide.model.libraryElement.INamedElement
import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration
import org.eclipse.fordiac.ide.model.libraryElement.With
import org.eclipse.fordiac.ide.model.LibraryElementTags
import org.eclipse.fordiac.ide.model.datatype.helper.RetainHelper.RetainTag;

import static extension org.eclipse.fordiac.ide.export.forte_ng.util.ForteNgExportUtil.*

Expand Down Expand Up @@ -377,20 +379,38 @@ abstract class ForteFBTemplate<T extends FBType> extends ForteLibraryElementTemp

def protected generateSetInitialValuesDeclaration(Iterable<VarDeclaration> variables) '''
«IF !variables.empty»
void setInitialValues() override;
void setInitialValues(bool cold) override;
«ENDIF»
'''

def protected generateSetInitialValuesDefinition(Iterable<VarDeclaration> variables) '''
«IF !variables.empty»
void «className»::setInitialValues() {
«FOR variable : variables»
«variable.generateName» = «variable.generateVariableDefaultValue»;
«ENDFOR»
void «className»::setInitialValues(bool cold) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that yesterday but can you please move the cold) { part into the if and else, and in the else only add ){

Because if there are no retain variables the cold param is not needed.

And as we are at it: In 4diac FORTE we have the coding guideline that function parameters stat with pa. So please change cold to paCold.

«IF variables.exists[ it.getAttributeValue(LibraryElementTags.RETAIN_ATTRIBUTE) !== null ]»
«generateRetainedInitialValuesDefinition(variables)»
«ELSE»
«generateVariableDefaultAssignment(variables)»
«ENDIF»
}

azoitl marked this conversation as resolved.
Show resolved Hide resolved
«ENDIF»
'''
def private generateRetainedInitialValuesDefinition(Iterable<VarDeclaration> variables) '''
if (cold) {
«generateVariableDefaultAssignment(variables.filter[isRetainedVariable(it)])»
}
«generateVariableDefaultAssignment(variables.filter[!isRetainedVariable(it)])»
'''

def private boolean isRetainedVariable(VarDeclaration variable) {
return variable.getAttributeValue(LibraryElementTags.RETAIN_ATTRIBUTE) !== null && variable.getAttributeValue(LibraryElementTags.RETAIN_ATTRIBUTE).equals(RetainTag.RETAIN.string);
}

def private generateVariableDefaultAssignment(Iterable<VarDeclaration> variables)'''
«FOR variable : variables»
«variable.generateName» = «variable.generateVariableDefaultValue»;
«ENDFOR»
'''

def protected generateConnectionVariableDeclarations(List<VarDeclaration> variables) '''
«FOR variable : variables AFTER '\n'»
Expand Down
Loading