blob: cab5ec1d85b6402c17c6873d71050e58f8fa9742 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2015 CEA LIST.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* CEA LIST - initial API and implementation
*******************************************************************************/
package org.eclipse.papyrus.designer.languages.c.codegen.module
import org.eclipse.papyrus.designer.languages.c.codegen.lib.TransformationUtil
import org.eclipse.uml2.uml.CallEvent
import org.eclipse.uml2.uml.Class
import org.eclipse.uml2.uml.FinalState
import org.eclipse.uml2.uml.SignalEvent
import org.eclipse.uml2.uml.State
import org.eclipse.uml2.uml.StateMachine
import org.eclipse.uml2.uml.VisibilityKind
import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.classScript.*
import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.commonScript.*
import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.functionScript.*
import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.importScript.*
import static extension org.eclipse.papyrus.designer.languages.c.codegen.lib.variableScript.*
import static extension org.eclipse.papyrus.designer.languages.c.codegen.services.UmlCommentServices.*
class classModuleScript {
def static classModuleScript(Class clazz) '''
««« This template is called by the main module file
«clazz.genHeading()»
«clazz.genBodyIncludes»
«clazz.genModuleDeclarationBody()»
«clazz.genModuleImplementationBody()»
'''
def static genModuleDeclarationBody(Class clazz) '''
«IF (clazz.visibility != VisibilityKind.PUBLIC_LITERAL)»
«clazz.partComment('Private Class Description')»
// Structure
«clazz.genClassStructDeclarations()»
// Constructor and destructor declarations
«clazz.genDynamicInstanciationOperationPrototypes()»
// Property initialization declarations
«clazz.genDefaultInitialisationProtoype()»
// Class methods declarations
«clazz.genNonStaticFunctionDeclarations()»
«ENDIF»
// ----------------------------------Private and Protected Global VariableDescription----------------------------------
«IF (clazz.ownedAttributes.filter[isStatic && visibility != VisibilityKind.PUBLIC_LITERAL && type !== null].size > 0)»
«clazz.partComment('Private/Protected Global Variable Declarations')»
«ENDIF»
«FOR attribute : clazz.ownedAttributes»
«IF (attribute.isStatic && attribute.visibility != VisibilityKind.PUBLIC_LITERAL && attribute.type !== null)»
// global variable declaration
«attribute.genVariableDeclaration()»
«ENDIF»
«ENDFOR»
// ----------------------------------Private and Protected Class Functions----------------------------------
«IF (clazz.ownedOperations.filter[!isStatic && namespace.visibility == VisibilityKind.PUBLIC_LITERAL && visibility == VisibilityKind.PUBLIC_LITERAL].size > 0)»
«clazz.partComment('Private/Protected Function Declarations')»
«ENDIF»
«FOR operation : clazz.ownedOperations»
«IF (!operation.isStatic && operation.namespace.visibility == VisibilityKind.PUBLIC_LITERAL && operation.visibility != VisibilityKind.PUBLIC_LITERAL)»
«operation.genFunctionPrototype()»
«ENDIF»
«ENDFOR»
// ----------------------------------Private and Protected Global Functions----------------------------------
«IF (clazz.getAllOperations.filter[isStatic && visibility == VisibilityKind.PUBLIC_LITERAL].size > 0)»
«clazz.partComment('Private/Protected Global Function Declarations')»
«ENDIF»
«FOR operation : clazz.getAllOperations»
«IF (operation.isStatic && operation.visibility != VisibilityKind.PUBLIC_LITERAL)»
«operation.genFunctionPrototype()»
«ENDIF»
«ENDFOR»
'''
def static genModuleImplementationBody(Class clazz) '''
// ----------------------------------Implementation of the class constructor and destructor----------
«clazz.genDynamicInstanciationOperations()»
// ----------------------------------Initialization functions implementation----------------------------------
«clazz.genDefaultIntialisationOperation()»
// ----------------------------------Functions Implementation----------------------------------
«FOR operation : clazz.getAllOperations»
«operation.genFunctionImplementation()»
«ENDFOR»
// ----------------------------------Receptions Implementation----------------------------------
«FOR reception : clazz.ownedReceptions»
«IF reception.signal != null»«reception.genFunctionImplementation()»«ENDIF»
«ENDFOR»
// ----------------------------------Signal Event Process Functions Implementations--------------------------------
«IF (clazz.classifierBehavior !== null)»
«FOR signalEvent : clazz.model.allOwnedElements.filter(SignalEvent)»
«signalEvent.genSignalEventProcessFunctionImplementation(clazz)»
«ENDFOR»
«ENDIF»
// ----------------------------------Call Event Process Functions Implementations----------------------------------
«IF (clazz.classifierBehavior !== null)»
«FOR callevent : clazz.model.allOwnedElements.filter(CallEvent)»
«IF (callevent.operation !== null && clazz.operations.contains(callevent.operation))»
«callevent.genCallEventProcessFunctionImplementation(clazz)»
«ENDIF»
«ENDFOR»
«ENDIF»
«IF (clazz.classifierBehavior != null && !clazz.ownedBehaviors.filter(StateMachine).isEmpty)»
«var sm = clazz.ownedBehaviors.filter(StateMachine).head»
// ----------------------------------Entry Exit and DoActivity Implementations for each state ----------------------------------
«IF !sm.regions.head.subvertices.filter(State).filter[!(it instanceof FinalState)].isEmpty»
«var states = clazz.ownedBehaviors.filter(StateMachine).head.regions.head.subvertices.filter(State).filter[!(it instanceof FinalState)]»
«FOR state : states»
«IF (TransformationUtil.isBehaviorExist(state.entry))»
«state.genEntryImplementation»
«ENDIF»
«IF (TransformationUtil.isBehaviorExist(state.exit))»
«state.genExitImplementation»
«ENDIF»
«IF (TransformationUtil.isBehaviorExist(state.doActivity))»
«state.genDoActivityImplementation»
«ENDIF»
«ENDFOR»
«ENDIF»
«IF(TransformationUtil.hasTriggerlessTransition(sm))»
//--------------------process Completion Event for completion transition-------------------//
«clazz.genProcessCompletionEventFunctionImplementation»
«ENDIF»
«ENDIF»
'''
}