Skip to content

Commit

Permalink
Add retain to type export (#109)
Browse files Browse the repository at this point in the history
* add retain flag to type exporter

* restructure generation

* replace hardcoded strings

* replace hardcoded strings

* move filter argument into seperate method

* remove boolean variable from setInitialValues

as discussed the setInitialValues() will only effect the values of variables during a warm restart. therefore it should only contain variables not tagged with RETAIN

* remove comments

* move empty line
  • Loading branch information
MandKastner committed May 13, 2024
1 parent 0d857b2 commit 12a7940
Showing 1 changed file with 22 additions and 8 deletions.
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 @@ -374,22 +376,34 @@ abstract class ForteFBTemplate<T extends FBType> extends ForteLibraryElementTemp
«type.interfaceList.outMappedInOutVars.generateConnectionAccessorsDefinition("getDIOOutConUnchecked", "CInOutDataConnection *"
«ENDIF»
'''
def protected generateSetInitialValuesDeclaration(Iterable<VarDeclaration> variables) '''
«IF !variables.empty»
«IF containsNonRetainedVariable(variables)»
void setInitialValues() override;
«ENDIF»
'''
def protected generateSetInitialValuesDefinition(Iterable<VarDeclaration> variables) '''
«IF !variables.empty»
«IF(containsNonRetainedVariable(variables))»
void «className»::setInitialValues() {
«FOR variable : variables»
«variable.generateName» = «variable.generateVariableDefaultValue»;
«ENDFOR»
«generateVariableDefaultAssignment(variables.filter[!isRetainedVariable(it)])»
}

«ENDIF»
«ENDIF»
'''
def private boolean isRetainedVariable(VarDeclaration variable) {
return variable.getAttributeValue(LibraryElementTags.RETAIN_ATTRIBUTE) !== null && variable.getAttributeValue(LibraryElementTags.RETAIN_ATTRIBUTE).equals(RetainTag.RETAIN.string);
}
def private boolean containsNonRetainedVariable(Iterable<VarDeclaration> variables) {
return variables.exists[!isRetainedVariable(it)];
}
def private generateVariableDefaultAssignment(Iterable<VarDeclaration> variables)'''
«FOR variable : variables»
«variable.generateName» = «variable.generateVariableDefaultValue»;
«ENDFOR»
'''
def protected generateConnectionVariableDeclarations(List<VarDeclaration> variables) '''
Expand Down

0 comments on commit 12a7940

Please sign in to comment.