source: trunk/idl-compiler/c/token.c@ 321

Last change on this file since 321 was 321, checked in by cinc, 18 years ago

Removed GTK includes

File size: 6.7 KB
Line 
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 <stdio.h>
37#include "nom.h"
38
39#include "parser.h"
40
41extern GScanner *gScanner;
42extern PPARSEINFO pParseInfo;
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 */
48void setCurSymbolInfo(void)
49{
50 switch(gScanner->token)
51 {
52 case G_TOKEN_IDENTIFIER:
53 /* Here we have to check identifiers if they are for example types, e.g. int */
54 break;
55 default:
56 pParseInfo->uiCurSymbolKind=KIND_UNKNOWN;
57 break;
58 }
59 if(gScanner->token==G_TOKEN_SYMBOL)
60 {
61 GTokenValue value;
62 PSYMBOL pCurSymbol;
63
64 value=gScanner->value;
65 pCurSymbol=value.v_symbol;
66
67 pParseInfo->uiCurSymbolKind=pCurSymbol->uiKind;
68 }
69}
70
71guint queryCurTokensKind(void)
72{
73 return pParseInfo->uiCurSymbolKind;
74}
75
76/* This token is not necessarily the current token! */
77static guint getKindOfNextToken()
78{
79 /* Load info into gScanner */
80 g_scanner_peek_next_token(gScanner);
81
82 if(gScanner->next_token==G_TOKEN_SYMBOL)
83 {
84 GTokenValue value;
85 PSYMBOL pCurSymbol;
86
87 value=gScanner->next_value;
88 pCurSymbol=value.v_symbol;
89
90 return pCurSymbol->uiKind;
91 }
92 switch(gScanner->next_token)
93 {
94 case G_TOKEN_IDENTIFIER:
95 {
96 /* Compare strings here. Yes, that's slow... */
97 break;
98 }
99 default:
100 break;
101 }
102
103 return KIND_UNKNOWN;
104}
105
106#if 0
107guint queryNextTokensKind(void)
108{
109 return getKindFromTokenType(gScanner->next_token);
110}
111#endif
112
113/* Well, the name says all... */
114void getNextToken(void)
115{
116 g_scanner_get_next_token(gScanner);
117 setCurSymbolInfo();
118}
119
120gboolean matchNextKind(guint uiKind)
121{
122 if(uiKind==getKindOfNextToken())
123 {
124 getNextToken();
125 return TRUE;
126 }
127 return FALSE;
128}
129
130/* Well, the name says all... */
131gboolean matchCur(GTokenType token)
132{
133 if(token==gScanner->token)
134 {
135 return TRUE;
136 }
137 return FALSE;
138}
139
140/* Well, the name says all...
141
142 Note that this function advances to the next token if the
143 tokens match.
144*/
145gboolean matchNext(GTokenType token)
146{
147 if(token==g_scanner_peek_next_token(gScanner))
148 {
149 getNextToken();
150 return TRUE;
151 }
152 return FALSE;
153}
154
155/*
156 Print current token info.
157 */
158void printToken(GTokenType token)
159{
160 GTokenValue value=gScanner->value;
161
162 switch(token)
163 {
164 case G_TOKEN_SYMBOL:
165 {
166 PSYMBOL pCurSymbol=value.v_symbol;
167
168 switch(pCurSymbol->uiSymbolToken)
169 {
170 case IDL_SYMBOL_INTERFACE:
171 g_message("Token: %d (IDL_SYMBOL_INTERFACE)\t\t\t (LINE %d)",
172 pCurSymbol->uiSymbolToken, g_scanner_cur_line(gScanner));
173 break;
174 case IDL_SYMBOL_DEFINE:
175 g_message("Token: %d (IDL_SYMBOL_DEFINE)\t\t\t", pCurSymbol->uiSymbolToken);
176 break;
177 case IDL_SYMBOL_IFDEF:
178 g_message("Token: %d (IDL_SYMBOL_IFDEF)\t\t\t", pCurSymbol->uiSymbolToken);
179 break;
180 case IDL_SYMBOL_ENDIF:
181 g_message("Token: %d (IDL_SYMBOL_ENDIF)\t\t\t", pCurSymbol->uiSymbolToken);
182 break;
183 default:
184 {
185 g_message("Token: %d (%s)\t\t\t (LINE %d)", pCurSymbol->uiSymbolToken,
186 pCurSymbol->chrSymbolName, g_scanner_cur_line(gScanner));
187
188 break;
189 }
190 }/* switch */
191 break;
192 }
193 case G_TOKEN_IDENTIFIER:
194 g_message("Token: %d (G_TOKEN_IDENTIFIER)\t\t%s (LINE %d)",
195 token, value.v_identifier, g_scanner_cur_line(gScanner));
196 break;
197 case G_TOKEN_STRING:
198 g_message("Token: %d (G_TOKEN_STRING)\t\t\t%s", token, value.v_string);
199 break;
200 case G_TOKEN_LEFT_PAREN:
201 g_message("Token: %d (G_TOKEN_LEFT_PAREN)\t\t\t( (LINE %d)", token, g_scanner_cur_line(gScanner));
202 break;
203 case G_TOKEN_RIGHT_PAREN:
204 g_message("Token: %d (G_TOKEN_RIGHT_PAREN)\t\t\t) (LINE %d)", token, g_scanner_cur_line(gScanner));
205 break;
206 case G_TOKEN_LEFT_CURLY:
207 g_message("Token: %d (G_TOKEN_LEFT_CURLY)\t\t\t{ (LINE %d)", token, g_scanner_cur_line(gScanner));
208 break;
209 case G_TOKEN_RIGHT_CURLY:
210 g_message("Token: %d (G_TOKEN_RIGHT_CURLY)\t\t\t} (LINE %d)", token, g_scanner_cur_line(gScanner));
211 break;
212 case ':':
213 g_message("Token: %d (colon)\t\t:", token);
214 break;
215 case ';':
216 g_message("Token: %d (semicolon)\t\t\t; (LINE %d)", token, g_scanner_cur_line(gScanner));
217 break;
218 case '#':
219 g_message("Token: %d (hash)\t\t\t#", token);
220 break;
221 case '/':
222 g_message("Token: %d (slash)\t\t\t/ %s", token, value.v_comment);
223 break;
224 case G_TOKEN_COMMA:
225 g_message("Token: %d (G_TOKEN_COMMA)\t\t\t,", token);
226 break;
227 case G_TOKEN_INT:
228 g_message("Token: %d (G_TOKEN_INT)\t\t\t%ld", token, value.v_int);
229 break;
230 default:
231 {
232 g_message("Token: %d (---)\t\t\t (LINE %d)", token, g_scanner_cur_line(gScanner));
233 break;
234 } /* default */
235 } /* switch */
236}
Note: See TracBrowser for help on using the repository browser.