1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: CDDL 1.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
---|
6 | * this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at http://www.sun.com/cddl/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is "NOM" Netlabs Object Model
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2005-2007
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | *
|
---|
23 | * Alternatively, the contents of this file may be used under the terms of
|
---|
24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
---|
25 | * case the provisions of the LGPL are applicable instead of those above. If
|
---|
26 | * you wish to allow use of your version of this file only under the terms of
|
---|
27 | * the LGPL, and not to allow others to use your version of this file under
|
---|
28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
---|
29 | * above and replace them with the notice and other provisions required by the
|
---|
30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
---|
31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
---|
32 | *
|
---|
33 | * ***** END LICENSE BLOCK ***** */
|
---|
34 |
|
---|
35 | #ifdef __OS2__
|
---|
36 | # include <os2.h>
|
---|
37 | #endif /* __OS2__ */
|
---|
38 |
|
---|
39 | #include <stdio.h>
|
---|
40 | #include "nom.h"
|
---|
41 |
|
---|
42 | #include "parser.h"
|
---|
43 |
|
---|
44 | extern GScanner *gScanner;
|
---|
45 | extern PPARSEINFO pParseInfo;
|
---|
46 |
|
---|
47 | /*
|
---|
48 | We need this information during parsing to decide if an identifier
|
---|
49 | is e.g. a typespec or just a var name.
|
---|
50 | */
|
---|
51 | void setCurSymbolInfo(void)
|
---|
52 | {
|
---|
53 | switch(gScanner->token)
|
---|
54 | {
|
---|
55 | case G_TOKEN_IDENTIFIER:
|
---|
56 | /* Here we have to check identifiers if they are for example types, e.g. int */
|
---|
57 | break;
|
---|
58 | default:
|
---|
59 | pParseInfo->uiCurSymbolKind=KIND_UNKNOWN;
|
---|
60 | break;
|
---|
61 | }
|
---|
62 | if(gScanner->token==G_TOKEN_SYMBOL)
|
---|
63 | {
|
---|
64 | GTokenValue value;
|
---|
65 | PSYMBOL pCurSymbol;
|
---|
66 |
|
---|
67 | value=gScanner->value;
|
---|
68 | pCurSymbol=value.v_symbol;
|
---|
69 |
|
---|
70 | pParseInfo->uiCurSymbolKind=pCurSymbol->uiKind;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | guint queryCurTokensKind(void)
|
---|
75 | {
|
---|
76 | return pParseInfo->uiCurSymbolKind;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /* This token is not necessarily the current token! */
|
---|
80 | static guint getKindOfNextToken()
|
---|
81 | {
|
---|
82 | /* Load info into gScanner */
|
---|
83 | g_scanner_peek_next_token(gScanner);
|
---|
84 |
|
---|
85 | if(gScanner->next_token==G_TOKEN_SYMBOL)
|
---|
86 | {
|
---|
87 | GTokenValue value;
|
---|
88 | PSYMBOL pCurSymbol;
|
---|
89 |
|
---|
90 | value=gScanner->next_value;
|
---|
91 | pCurSymbol=value.v_symbol;
|
---|
92 |
|
---|
93 | return pCurSymbol->uiKind;
|
---|
94 | }
|
---|
95 | switch(gScanner->next_token)
|
---|
96 | {
|
---|
97 | case G_TOKEN_IDENTIFIER:
|
---|
98 | {
|
---|
99 | /* Compare strings here. Yes, that's slow... */
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | default:
|
---|
103 | break;
|
---|
104 | }
|
---|
105 |
|
---|
106 | return KIND_UNKNOWN;
|
---|
107 | }
|
---|
108 |
|
---|
109 | #if 0
|
---|
110 | guint queryNextTokensKind(void)
|
---|
111 | {
|
---|
112 | return getKindFromTokenType(gScanner->next_token);
|
---|
113 | }
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /* Well, the name says all... */
|
---|
117 | void getNextToken(void)
|
---|
118 | {
|
---|
119 | g_scanner_get_next_token(gScanner);
|
---|
120 | setCurSymbolInfo();
|
---|
121 | }
|
---|
122 |
|
---|
123 | gboolean matchNextKind(guint uiKind)
|
---|
124 | {
|
---|
125 | if(uiKind==getKindOfNextToken())
|
---|
126 | {
|
---|
127 | getNextToken();
|
---|
128 | return TRUE;
|
---|
129 | }
|
---|
130 | return FALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | /* Well, the name says all... */
|
---|
134 | gboolean matchCur(GTokenType token)
|
---|
135 | {
|
---|
136 | if(token==gScanner->token)
|
---|
137 | {
|
---|
138 | return TRUE;
|
---|
139 | }
|
---|
140 | return FALSE;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* Well, the name says all...
|
---|
144 |
|
---|
145 | Note that this function advances to the next token if the
|
---|
146 | tokens match.
|
---|
147 | */
|
---|
148 | gboolean matchNext(GTokenType token)
|
---|
149 | {
|
---|
150 | if(token==g_scanner_peek_next_token(gScanner))
|
---|
151 | {
|
---|
152 | getNextToken();
|
---|
153 | return TRUE;
|
---|
154 | }
|
---|
155 | return FALSE;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /*
|
---|
159 | Print current token info.
|
---|
160 | */
|
---|
161 | void printToken(GTokenType token)
|
---|
162 | {
|
---|
163 | GTokenValue value=gScanner->value;
|
---|
164 |
|
---|
165 | switch(token)
|
---|
166 | {
|
---|
167 | case G_TOKEN_SYMBOL:
|
---|
168 | {
|
---|
169 | PSYMBOL pCurSymbol=value.v_symbol;
|
---|
170 |
|
---|
171 | switch(pCurSymbol->uiSymbolToken)
|
---|
172 | {
|
---|
173 | case IDL_SYMBOL_INTERFACE:
|
---|
174 | g_message("Token: %d (IDL_SYMBOL_INTERFACE)\t\t\t (LINE %d)",
|
---|
175 | pCurSymbol->uiSymbolToken, g_scanner_cur_line(gScanner));
|
---|
176 | break;
|
---|
177 | case IDL_SYMBOL_DEFINE:
|
---|
178 | g_message("Token: %d (IDL_SYMBOL_DEFINE)\t\t\t", pCurSymbol->uiSymbolToken);
|
---|
179 | break;
|
---|
180 | case IDL_SYMBOL_IFDEF:
|
---|
181 | g_message("Token: %d (IDL_SYMBOL_IFDEF)\t\t\t", pCurSymbol->uiSymbolToken);
|
---|
182 | break;
|
---|
183 | case IDL_SYMBOL_ENDIF:
|
---|
184 | g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", pCurSymbol->uiSymbolToken);
|
---|
185 | break;
|
---|
186 | default:
|
---|
187 | {
|
---|
188 | g_message("Token: %d (%s)\t\t\t (LINE %d)", pCurSymbol->uiSymbolToken,
|
---|
189 | pCurSymbol->chrSymbolName, g_scanner_cur_line(gScanner));
|
---|
190 |
|
---|
191 | break;
|
---|
192 | }
|
---|
193 | }/* switch */
|
---|
194 | break;
|
---|
195 | }
|
---|
196 | case G_TOKEN_IDENTIFIER:
|
---|
197 | g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s (LINE %d)",
|
---|
198 | token, value.v_identifier, g_scanner_cur_line(gScanner));
|
---|
199 | break;
|
---|
200 | case G_TOKEN_STRING:
|
---|
201 | g_message("Token: %d (G_TOKEN_STRING)\t\t\t%s", token, value.v_string);
|
---|
202 | break;
|
---|
203 | case G_TOKEN_LEFT_PAREN:
|
---|
204 | g_message("Token: %d (G_TOKEN_LEFT_PAREN)\t\t\t( (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
205 | break;
|
---|
206 | case G_TOKEN_RIGHT_PAREN:
|
---|
207 | g_message("Token: %d (G_TOKEN_RIGHT_PAREN)\t\t\t) (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
208 | break;
|
---|
209 | case G_TOKEN_LEFT_CURLY:
|
---|
210 | g_message("Token: %d (G_TOKEN_LEFT_CURLY)\t\t\t{ (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
211 | break;
|
---|
212 | case G_TOKEN_RIGHT_CURLY:
|
---|
213 | g_message("Token: %d (G_TOKEN_RIGHT_CURLY)\t\t\t} (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
214 | break;
|
---|
215 | case ':':
|
---|
216 | g_message("Token: %d (colon)\t\t:", token);
|
---|
217 | break;
|
---|
218 | case ';':
|
---|
219 | g_message("Token: %d (semicolon)\t\t\t; (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
220 | break;
|
---|
221 | case '#':
|
---|
222 | g_message("Token: %d (hash)\t\t\t#", token);
|
---|
223 | break;
|
---|
224 | case '/':
|
---|
225 | g_message("Token: %d (slash)\t\t\t/ %s", token, value.v_comment);
|
---|
226 | break;
|
---|
227 | case G_TOKEN_COMMA:
|
---|
228 | g_message("Token: %d (G_TOKEN_COMMA)\t\t\t,", token);
|
---|
229 | break;
|
---|
230 | case G_TOKEN_INT:
|
---|
231 | g_message("Token: %d (G_TOKEN_INT)\t\t\t%ld", token, value.v_int);
|
---|
232 | break;
|
---|
233 | default:
|
---|
234 | {
|
---|
235 | g_message("Token: %d (---)\t\t\t (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
236 | break;
|
---|
237 | } /* default */
|
---|
238 | } /* switch */
|
---|
239 | }
|
---|