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 | #include <os2.h>
|
---|
36 | #include <gtk/gtk.h>
|
---|
37 | #include "nom.h"
|
---|
38 |
|
---|
39 | #include "parser.h"
|
---|
40 |
|
---|
41 | extern GScanner *gScanner;
|
---|
42 | extern GTokenType curToken;
|
---|
43 |
|
---|
44 | /*
|
---|
45 | We need this information during parsing to decide if an identifier
|
---|
46 | is e.g. a typespec or just a var name.
|
---|
47 | */
|
---|
48 | void setSymbolInfo(GTokenType token)
|
---|
49 | {
|
---|
50 | PSYMBOLINFO psi;
|
---|
51 |
|
---|
52 | psi=(PSYMBOLINFO)gScanner->user_data;
|
---|
53 |
|
---|
54 | switch(token)
|
---|
55 | {
|
---|
56 | case G_TOKEN_IDENTIFIER:
|
---|
57 | /* Here we have to check identifiers if they are for example types, e.g. int */
|
---|
58 | break;
|
---|
59 | default:
|
---|
60 | psi->uiCurSymbolKind=KIND_UNKNOWN;
|
---|
61 | break;
|
---|
62 | }
|
---|
63 | if(token>G_TOKEN_LAST)
|
---|
64 | {
|
---|
65 | psi->uiCurSymbolKind=psi->pSymbols[token-G_TOKEN_LAST-1].uiKind;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | guint queryCurTokensKind(void)
|
---|
70 | {
|
---|
71 | PSYMBOLINFO psi;
|
---|
72 |
|
---|
73 | psi=(PSYMBOLINFO)gScanner->user_data;
|
---|
74 | return psi->uiCurSymbolKind;
|
---|
75 | }
|
---|
76 |
|
---|
77 | static guint getKindFromTokenType(GTokenType token)
|
---|
78 | {
|
---|
79 | if(token>G_TOKEN_LAST)
|
---|
80 | {
|
---|
81 | PSYMBOLINFO psi;
|
---|
82 |
|
---|
83 | psi=(PSYMBOLINFO)gScanner->user_data;
|
---|
84 | return psi->pSymbols[token-G_TOKEN_LAST-1].uiKind;
|
---|
85 | }
|
---|
86 | switch(token)
|
---|
87 | {
|
---|
88 | case G_TOKEN_IDENTIFIER:
|
---|
89 | {
|
---|
90 | /* Compare strings here. Yes, that's slow... */
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | default:
|
---|
94 | break;
|
---|
95 | }
|
---|
96 |
|
---|
97 | return KIND_UNKNOWN;
|
---|
98 | }
|
---|
99 |
|
---|
100 | guint queryNextTokensKind(void)
|
---|
101 | {
|
---|
102 | return getKindFromTokenType(gScanner->next_token);
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | /* Well, the name says all... */
|
---|
107 | void getNextToken(void)
|
---|
108 | {
|
---|
109 | curToken = g_scanner_get_next_token(gScanner);
|
---|
110 | setSymbolInfo(curToken);
|
---|
111 | }
|
---|
112 |
|
---|
113 | gboolean matchNextKind(guint uiKind)
|
---|
114 | {
|
---|
115 | GTokenType token;
|
---|
116 |
|
---|
117 | token=g_scanner_peek_next_token(gScanner);
|
---|
118 | if(uiKind==getKindFromTokenType(token))
|
---|
119 | {
|
---|
120 | getNextToken();
|
---|
121 | return TRUE;
|
---|
122 | }
|
---|
123 | return FALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /* Well, the name says all... */
|
---|
127 | gboolean matchCur(GTokenType token)
|
---|
128 | {
|
---|
129 | if(token==curToken)
|
---|
130 | {
|
---|
131 | return TRUE;
|
---|
132 | }
|
---|
133 | return FALSE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* Well, the name says all...
|
---|
137 |
|
---|
138 | Note that this function advances to the next token if the
|
---|
139 | tokens match.
|
---|
140 | */
|
---|
141 | gboolean matchNext(GTokenType token)
|
---|
142 | {
|
---|
143 | if(token==g_scanner_peek_next_token(gScanner))
|
---|
144 | {
|
---|
145 | getNextToken();
|
---|
146 | return TRUE;
|
---|
147 | }
|
---|
148 | return FALSE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /*
|
---|
152 | Print current token info.
|
---|
153 | */
|
---|
154 | void printToken(GTokenType token)
|
---|
155 | {
|
---|
156 | GTokenValue value=gScanner->value;
|
---|
157 |
|
---|
158 | switch(token)
|
---|
159 | {
|
---|
160 | case IDL_SYMBOL_INTERFACE:
|
---|
161 | g_message("Token: %d (IDL_SYMBOL_INTERFACE)\t\t\t (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
162 | break;
|
---|
163 | case G_TOKEN_IDENTIFIER:
|
---|
164 | g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s (LINE %d)",
|
---|
165 | token, value.v_identifier, g_scanner_cur_line(gScanner));
|
---|
166 | break;
|
---|
167 | case G_TOKEN_STRING:
|
---|
168 | g_message("Token: %d (G_TOKEN_STRING)\t\t\t%s", token, value.v_string);
|
---|
169 | break;
|
---|
170 | case G_TOKEN_LEFT_PAREN:
|
---|
171 | g_message("Token: %d (G_TOKEN_LEFT_PAREN)\t\t\t( (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
172 | break;
|
---|
173 | case G_TOKEN_RIGHT_PAREN:
|
---|
174 | g_message("Token: %d (G_TOKEN_RIGHT_PAREN)\t\t\t) (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
175 | break;
|
---|
176 | case G_TOKEN_LEFT_CURLY:
|
---|
177 | g_message("Token: %d (G_TOKEN_LEFT_CURLY)\t\t\t{ (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
178 | break;
|
---|
179 | case G_TOKEN_RIGHT_CURLY:
|
---|
180 | g_message("Token: %d (G_TOKEN_RIGHT_CURLY)\t\t\t} (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
181 | break;
|
---|
182 | case ':':
|
---|
183 | g_message("Token: %d (colon)\t\t:", token);
|
---|
184 | break;
|
---|
185 | case ';':
|
---|
186 | g_message("Token: %d (semicolon)\t\t\t; (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
187 | break;
|
---|
188 | case '#':
|
---|
189 | g_message("Token: %d (hash)\t\t\t#", token);
|
---|
190 | break;
|
---|
191 | case '/':
|
---|
192 | g_message("Token: %d (slash)\t\t\t/ %s", token, value.v_comment);
|
---|
193 | break;
|
---|
194 | case G_TOKEN_COMMA:
|
---|
195 | g_message("Token: %d (G_TOKEN_COMMA)\t\t\t,", token);
|
---|
196 | break;
|
---|
197 | case G_TOKEN_INT:
|
---|
198 | g_message("Token: %d (G_TOKEN_INT)\t\t\t%ld", token, value.v_int);
|
---|
199 | break;
|
---|
200 | case IDL_SYMBOL_DEFINE:
|
---|
201 | g_message("Token: %d (IDL_SYMBOL_DEFINE)\t\t\t", token);
|
---|
202 | break;
|
---|
203 | case IDL_SYMBOL_IFDEF:
|
---|
204 | g_message("Token: %d (IDL_SYMBOL_IFDEF)\t\t\t", token);
|
---|
205 | break;
|
---|
206 | case IDL_SYMBOL_ENDIF:
|
---|
207 | g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", token);
|
---|
208 | break;
|
---|
209 | default:
|
---|
210 | {
|
---|
211 | PSYMBOLINFO psi;
|
---|
212 | psi=(PSYMBOLINFO)gScanner->user_data;
|
---|
213 |
|
---|
214 | if(token>G_TOKEN_LAST)
|
---|
215 | g_message("Token: %d (%s)\t\t\t (LINE %d)", token,
|
---|
216 | psi->pSymbols[token-G_TOKEN_LAST-1].chrSymbolName, g_scanner_cur_line(gScanner));
|
---|
217 | else
|
---|
218 | g_message("Token: %d (---)\t\t\t (LINE %d)", token, g_scanner_cur_line(gScanner));
|
---|
219 | break;
|
---|
220 | } /* default */
|
---|
221 | } /* switch */
|
---|
222 | }
|
---|