summaryrefslogtreecommitdiffstats
path: root/thirdparties/wince/include/smc/statemap.h
blob: 2fe7b85ad5151a0172ddb9fc27041019badffe8a (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef _H_STATEMAP
#define _H_STATEMAP

/*
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Original Code is State Machine Compiler (SMC).
 * 
 * The Initial Developer of the Original Code is Charles W. Rapp.
 * 
 * Port to C by Francois Perrad, francois.perrad@gadz.org
 * Copyright 2004, Francois Perrad.
 * All Rights Reserved.
 *
 * Contributor(s): 
 *
 * Description
 *
 * RCS ID
 * $Id: statemap.h,v 1.4 2009/03/01 18:20:40 cwrapp Exp $
 *
 * Change Log
 * $Log: statemap.h,v $
 * Revision 1.4  2009/03/01 18:20:40  cwrapp
 * Preliminary v. 6.0.0 commit.
 *
 * Revision 1.3  2008/05/30 21:14:48  fperrad
 * - define TRACE only when undefined
 *
 * Revision 1.2  2007/08/05 12:58:11  cwrapp
 * Version 5.0.1 check-in. See net/sf/smc/CODE_README.txt for more information.
 *
 * Revision 1.1  2005/06/16 18:08:17  fperrad
 * Added C, Perl & Ruby.
 *
 */

#include <stdio.h>
#include <string.h>

#ifndef TRACE
#define TRACE printf
#endif

#define STATE_MEMBERS \
    const char *_name; \
    int _id;

struct State
{
    STATE_MEMBERS
};

#define getName(state) \
    (state)->_name
#define getId(state) \
    (state)->_id

#define State_Default(fsm) \
    assert(0)

#define FSM_MEMBERS(app) \
    const struct app##State * _state; \
    const struct app##State * _previous_state; \
    const struct app##State ** _stack_start; \
    const struct app##State ** _stack_curr; \
    const struct app##State ** _stack_max; \
    const char * _transition; \
    int _debug_flag;

struct FSMContext
{
    FSM_MEMBERS(_)
};

#define FSM_INIT(fsm, state)    \
    (fsm)->_state = (state); \
    (fsm)->_previous_state = NULL; \
    (fsm)->_stack_start = NULL; \
    (fsm)->_stack_curr = NULL; \
    (fsm)->_stack_max = NULL; \
    (fsm)->_transition = NULL; \
    (fsm)->_debug_flag = 0

#define FSM_STACK(fsm, stack) \
    (fsm)->_stack_start = &(stack)[0]; \
    (fsm)->_stack_curr = &(stack)[0]; \
    (fsm)->_stack_max = &(stack)[0] + (sizeof(stack) / sizeof(void*))


#define getState(fsm) \
    (fsm)->_state
#define clearState(fsm) \
    (fsm)->_previous_state = (fsm)->_state; \
    (fsm)->_state = NULL
#define setState(fsm, state) \
    (fsm)->_state = (state); \
    if ((fsm)->_debug_flag != 0) { \
        TRACE("NEW STATE    : %s\n", getName(state)); \
    }
#define pushState(fsm, state) \
    if ((fsm)->_stack_curr >= (fsm)->_stack_max) { \
        assert(0 == "STACK OVERFLOW"); \
    } \
    *((fsm)->_stack_curr) = (fsm)->_state; \
    (fsm)->_stack_curr ++; \
    (fsm)->_state = state; \
    if ((fsm)->_debug_flag != 0) { \
        TRACE("PUSH TO STATE: %s\n", getName(state)); \
    }
#define popState(fsm) \
    (fsm)->_stack_curr --; \
    (fsm)->_state = *((fsm)->_stack_curr); \
    if ((fsm)->_debug_flag != 0) { \
        TRACE("POP TO STATE : %s\n", getName((fsm)->_state)); \
    }
#define emptyStateStack(fsm) \
    (fsm)->_stack_curr = (fsm)->_stack_start
#define setTransition(fsm, transition) \
    (fsm)->_transition = (transition)
#define getTransition(fsm) \
    (fsm)->_transition
#define getDebugFlag(fsm) \
    (fsm)->_debug_flag
#define setDebugFlag(fsm, flag) \
    (fsm)->_debug_flag = (flag)

#endif
OpenPOWER on IntegriCloud