Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 160265df9b8945a6fd2bda6e1cf49ebf082b03b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 * Copyright (c) 2014 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.cpp.codegen.xtend

import org.eclipse.uml2.uml.Operation
import org.eclipse.uml2.uml.Parameter
import org.eclipse.papyrus.cpp.codegen.utils.Modifier
import org.eclipse.papyrus.cpp.codegen.utils.CppGenUtils
import org.eclipse.uml2.uml.ParameterDirectionKind
import org.eclipse.uml2.uml.Behavior
import org.eclipse.papyrus.C_Cpp.Array
import org.eclipse.uml2.uml.util.UMLUtil

/**
 * @author Önder GÜRCAN (onder.gurcan@cea.fr)
 */
class CppParameter {
	
	static def CppOperationParameters(Operation operation, boolean showDefault) '''
		«FOR ownedParameter : operation.ownedParameters.filter[it.direction != ParameterDirectionKind.RETURN_LITERAL] SEPARATOR ', '»«CppParameter(ownedParameter, showDefault)»«ENDFOR»'''
	
	/**  
	 * comment signature for a given behavior (e.g. effect within state machine)
	 */ 
	static def CppBehaviorParameters(Behavior behavior, boolean showDefault) '''
		«FOR ownedParameter : behavior.ownedParameters.filter[it.direction != ParameterDirectionKind.RETURN_LITERAL] SEPARATOR ', '»«CppParameter(ownedParameter, showDefault)»«ENDFOR»
	'''
	
	/**
	 * C++ parameter. Default values are added, if parameter showDefault is true (implementation signature
	 */ 
	static def CppParameter(Parameter parameter, boolean showDefault) {
		Modifier.modCVQualifier(parameter) + Modifier.modSCQualifier(parameter) + CppGenUtils.cppQualifiedName(parameter.type) +
			Modifier.modPtr(parameter) + Modifier.modRef(parameter) + Modifier.dirInfo(parameter) + " " + parameter.name +
			Modifier.modArray(parameter) + {if (showDefault) defaultValue(parameter) else ""}
	}
	
	/**
	 * CppParameterCalculation for CDT
	 */
	static def CppParameterForCDT(Parameter parameter) {
		var paramStr = Modifier.modCVQualifier(parameter) + Modifier.modSCQualifier(parameter) + CppGenUtils.cppQualifiedName(parameter.type) +
			Modifier.modPtr(parameter) + Modifier.modRef(parameter)
		if (UMLUtil.getStereotypeApplication(parameter, Array) != null) {
			paramStr += "[]"
		}
		return paramStr
	}	
	 
	static def defaultValue(Parameter parameter) {
		if (parameter.defaultValue != null)  " = " + parameter.defaultValue.stringValue() else ""
	}
}

Back to the top