Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e3cd5a23e50bfcfc6796cd08cf96899039093fa4 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
 * 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:
 * 		Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

/*
	collection of convenience functions for code generation
*/

import room;
import etricegen;

extension org::eclipse::etrice::generator::extensions::Extensions;
extension org::eclipse::xtend::util::stdlib::naming;

///////////////////////////////////////////////////////////////////////////////
// general

///////////////////////////////////////////////////////////////////////////////
// types

// type names for Type class (distinguish Primitive and DataClass)
String toJavaType(PrimitiveType prim):
switch(prim.toString()) {
	case 'uint8': 'undefined_type'
	case 'uint16': 'undefined_type'
	case 'uint32': 'undefined_type'
	case 'int8': 'byte'
	case 'int16': 'short'
	case 'int32': 'int'
	case 'float32': 'float'
	case 'float64': 'double'
	case 'string' : 'String'
	default: prim.toString()};
String toJavaObjectType(PrimitiveType prim):
switch(prim.toString()) {
	case 'uint8': 'undefined_type'
	case 'uint16': 'undefined_type'
	case 'uint32': 'undefined_type'
	case 'int8': 'Byte'
	case 'int16': 'Short'
	case 'int32': 'Integer'
	case 'float32': 'Float'
	case 'float64': 'Double'
	case 'string': 'String'
	default: prim.toString()};
String typeName(Type type): type.type!=null? type.type.name : type.prim.toJavaType();
String freeTypeName(FreeType type): type.type!=null? type.type : type.prim.toJavaType();
String typeObjectName(Type type): type.type!=null? type.type.name : type.prim.toJavaObjectType();

// default values for data
String defaultValue(PrimitiveType prim):
switch(prim.toString()) {
	case 'uint8': '0'
	case 'uint16': '0'
	case 'uint32': '0'
	case 'int8': '0'
	case 'int16': '0'
	case 'int32': '0'
	case 'float32': '0.0'
	case 'float64': '0.0'
	case 'string': '""'
	default: prim.toString()};
String defaultValue(TypedID a): a.type.type!=null? "new "+a.type.type.name+"()" : a.type.prim.defaultValue();

///////////////////////////////////////////////////////////////////////////////
// protocol and messages

///////////////////////////////////////////////////////////////////////////////
// actor

private String getDataTypeCast(TriggeredTransition tt): tt.triggers.msgFromIfPairs.message.select(e|e.data!=null).first().data.type.typeObjectName();
private String getDataType(TriggeredTransition tt): tt.triggers.msgFromIfPairs.message.select(e|e.data!=null).first().data.type.typeName();
String getArgumentList(ExpandedActorClass xpac, Transition t): JAVA org.eclipse.etrice.generator.java.gen.JavaGenerator.getArgumentList(org.eclipse.etrice.generator.etricegen.ExpandedActorClass, org.eclipse.etrice.core.room.Transition);
String getTypedDataDefinition(Message m): JAVA org.eclipse.etrice.generator.java.gen.JavaGenerator.getTypedData(org.eclipse.etrice.core.room.Message);

String getExecuteChainCode(ExpandedActorClass ac, TransitionChain tc): JAVA org.eclipse.etrice.generator.java.gen.JavaGenerator.getExecuteChain(org.eclipse.etrice.generator.etricegen.ExpandedActorClass, org.eclipse.etrice.generator.etricegen.TransitionChain);

Back to the top