47
45
// preprocess __if_exists and __if_not_exists statements
48
46
advice execution ("% Puma::PreprocessorParser::next()") : around () {
51
49
JoinPoint::That *preparser;
53
preparser = tjp->that ();
51
preparser = tjp->that ();
54
52
tjp->proceed (); // get the next token
55
53
token = *tjp->result ();
57
55
type = token->type ();
58
56
// __if_exists (...) { ... }
59
if (type == TOK_IF_EXISTS) {
60
preparser->skip_up_to (TOK_CLOSE_CURLY);
61
*(Token**)thisJoinPoint->result () = preparser->next ();
57
if (type == Puma::TOK_IF_EXISTS) {
58
preparser->skip_up_to (Puma::TOK_CLOSE_CURLY);
59
*(Puma::Token**)thisJoinPoint->result () = preparser->next ();
63
61
// __if_not_exists (...) { ... }
64
} else if (type == TOK_IF_NOT_EXISTS) {
65
preparser->skip_up_to (TOK_OPEN_CURLY);
62
} else if (type == Puma::TOK_IF_NOT_EXISTS) {
63
preparser->skip_up_to (Puma::TOK_OPEN_CURLY);
66
64
preparser->_depth.push (1);
67
*(Token**)thisJoinPoint->result () = preparser->next ();
65
*(Puma::Token**)thisJoinPoint->result () = preparser->next ();
70
68
// skip closing `}' of __if_not_exists
71
69
if (preparser->_depth.length ()) {
72
if (type == TOK_OPEN_CURLY)
70
if (type == Puma::TOK_OPEN_CURLY)
73
71
preparser->_depth.top () = preparser->_depth.top () + 1;
74
else if (type == TOK_CLOSE_CURLY) {
72
else if (type == Puma::TOK_CLOSE_CURLY) {
75
73
preparser->_depth.top () = preparser->_depth.top () - 1;
76
if (preparser->_depth.top () == 0) {
77
preparser->_depth.pop ();
78
*(Token**)thisJoinPoint->result () = preparser->next ();
74
if (preparser->_depth.top () == 0) {
75
preparser->_depth.pop ();
76
*(Puma::Token**)thisJoinPoint->result () = preparser->next ();
99
97
// skip __if_exists resp. __if_not_exists statement
100
98
slice void WinIfExistsCpp::skip_up_to (int end_token) {
101
99
unsigned parenthesis = 0, curlies = 0;
105
103
// skip up to the first non-nested `{'
106
104
while ((token = parseToken ())) {
107
105
type = token->type ();
108
if (type == TOK_OPEN_CURLY) {
106
if (type == Puma::TOK_OPEN_CURLY) {
109
107
if (parenthesis == 0 && curlies == 0)
112
} else if (type == TOK_CLOSE_CURLY)
110
} else if (type == Puma::TOK_CLOSE_CURLY)
114
else if (type == TOK_OPEN_ROUND)
112
else if (type == Puma::TOK_OPEN_ROUND)
116
else if (type == TOK_CLOSE_ROUND)
114
else if (type == Puma::TOK_CLOSE_ROUND)
120
118
// skip up to the first non-nested `}'
121
if (end_token == TOK_CLOSE_CURLY) {
119
if (end_token == Puma::TOK_CLOSE_CURLY) {
122
120
parenthesis = curlies = 0;
123
121
while ((token = parseToken ())) {
124
122
type = token->type ();
125
if (type == TOK_OPEN_CURLY)
123
if (type == Puma::TOK_OPEN_CURLY)
127
else if (type == TOK_CLOSE_CURLY) {
125
else if (type == Puma::TOK_CLOSE_CURLY) {
128
126
if (parenthesis == 0 && curlies == 0)
131
} else if (type == TOK_OPEN_ROUND)
129
} else if (type == Puma::TOK_OPEN_ROUND)
133
else if (type == TOK_CLOSE_ROUND)
131
else if (type == Puma::TOK_CLOSE_ROUND)