Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5bde0cde3e60590b67f0ccf5ed9f121cf773281e (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
/*******************************************************************************
 * Copyright (c) 2011 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:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.generator.c.gen

import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*

@Singleton
class StateMachineGen extends GenericStateMachineGenerator {
	
	@Inject extension RoomExtensions
	
	def genHeaderConstants(ExpandedActorClass xpac) {
		val ac = xpac.actorClass
		/* TODO: can save one entry if NO_STATE=-1 but influences Java */
		val historySize = ac.allBaseStates.size - ac.allLeafStates.size + 2
		'''
			/* constant for state machine data */
			#define ac.name.toUpperCase_HISTORY_SIZE historySize
		'''
	}
	
	def genDataMembers(ExpandedActorClass xpac) {
		val ac = xpac.actorClass
		'''
			/* state machine variables */
			etInt16 state;
			etInt16 history[ac.name.toUpperCase_HISTORY_SIZE];
		'''
	}
	
	def genInitialization(ExpandedActorClass xpac) {
		val ac = xpac.actorClass
		'''
			self->state = STATE_TOP;
			{
				int i;
				for (i=0; i<ac.name.toUpperCase_HISTORY_SIZE; ++i)
					self->history[i] = NO_STATE;
			}
			langExt.operationScope(ac.name, false)executeInitTransition(self);
		'''
	}
	
	override protected genExtra(ExpandedActorClass xpac) {
		val ac = xpac.actorClass
		'''
			
			langExt.accessLevelPrivatevoid setState(ac.name* self, int new_state) {
				self->state = new_state;
			}
			
			langExt.accessLevelPrivateint getState(ac.name* self) {
				return self->state;
			}
		'''
	}
	
	override protected stateType() {
		"etInt16"
	}
	
	override protected unreachableReturn() {
		"/* return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) */"
	}
	
}

Back to the top