source: trunk/idl-compiler/parser_c/override_parser.c

Last change on this file was 326, checked in by cinc, 17 years ago

Portability patches for Windows, Linux, Darwin by Bird.

File size: 8.2 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) 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#ifdef __OS2__
35# include <os2.h>
36#endif /* __OS2__ */
37
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41
42#include <glib.h>
43#include <glib/gprintf.h>
44#include "parser.h"
45
46
47extern GScanner *gScanner;
48//extern PINTERFACE pCurInterface;
49extern PPARSEINFO pParseInfo;
50
51PINTERFACE findInterfaceForMethod(PINTERFACE pStartInterface, gchar* chrMethodName)
52{
53 int a;
54
55 while(pStartInterface)
56 {
57 for(a=0;a<pStartInterface->pMethodArray->len;a++)
58 {
59 PMETHOD pm=(PMETHOD)g_ptr_array_index(pStartInterface->pMethodArray, a);
60 if(!strcmp(pm->chrName, chrMethodName))
61 return pStartInterface;
62 }
63 if(pStartInterface->chrParent)
64 pStartInterface=findInterfaceFromName(pStartInterface->chrParent);
65 else
66 pStartInterface=NULL;
67 }
68
69 return NULL;
70}
71
72/*
73 Parse override. Note that 'NOMOVERRIDE' is the current symbol..
74
75 OM:= IDL_SYMBOL_OVERRIDE '(' IDENT ')' ';'
76 */
77void parseOverrideMethod(void)
78{
79 GTokenValue value;
80 POVERMETHOD pOMethod=g_malloc0(sizeof(OVERMETHOD));
81 PINTERFACE pif;
82
83 if(!matchNext('('))
84 {
85 getNextToken(); /* Make sure error references the correct token */
86 g_scanner_unexp_token(gScanner,
87 '(',
88 NULL,
89 NULL,
90 NULL,
91 "Error in NOMOVERRIDE()",
92 TRUE); /* is_error */
93 exit(1);
94 }
95
96 /* This is the method we actually try to override */
97 if(!matchNext(G_TOKEN_IDENTIFIER))
98 {
99 getNextToken(); /* Make sure error references the correct token */
100 g_scanner_unexp_token(gScanner,
101 G_TOKEN_IDENTIFIER,
102 NULL,
103 NULL,
104 NULL,
105 "Error in NOMOVERRIDE(). Identifier expected.",
106 TRUE); /* is_error */
107 exit(1);
108 }
109 value=gScanner->value;
110 pOMethod->chrName=g_strdup(value.v_identifier);
111
112 /* Now check if the method was introduced by some parent */
113 if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pOMethod->chrName))==NULL)
114 {
115 g_printf("%s:%d: error: Method '%s' was not introduced by some parent interface.\n",
116 pParseInfo->chrCurrentSourceFile, g_scanner_cur_line(gScanner)-pParseInfo->uiLineCorrection,
117 pOMethod->chrName);
118 exit(1);
119 }
120 pOMethod->chrIntroducingIFace=pif->chrName; /* No copy of string here. Nobody should free the
121 interface info under our feet. */
122
123 if(!matchNext(')'))
124 {
125 getNextToken(); /* Make sure error references the correct token */
126 g_scanner_unexp_token(gScanner,
127 ')',
128 NULL,
129 NULL,
130 NULL,
131 "Error in NOMOVERRIDE(). Closing ')' is missing.",
132 TRUE); /* is_error */
133 exit(1);
134 }
135 if(!matchNext(';'))
136 {
137 getNextToken(); /* Make sure error references the correct token */
138 g_scanner_unexp_token(gScanner,
139 ';',
140 NULL,
141 NULL,
142 NULL,
143 "Error in NOMOVERRIDE(). Missing ';' at end of statement.",
144 TRUE); /* is_error */
145 exit(1);
146 }
147 g_ptr_array_add(pParseInfo->pCurInterface->pOverrideArray, (gpointer) pOMethod);
148}
149
150
151/*
152 Parse override. Note that the identifier is the current symbol.
153
154 OM:= IDENT ':' IDL_SYMBOL_OVERRIDE2 ';'
155 */
156void parseOverrideMethodFromIdentifier(void)
157{
158 GTokenValue value;
159 POVERMETHOD pOMethod=g_malloc0(sizeof(OVERMETHOD));
160 PINTERFACE pif;
161
162 /* Keep the current identifier. We need to check for existance later if we find
163 we are in an override statement. */
164 value=gScanner->value;
165 pOMethod->chrName=g_strdup(value.v_identifier);
166
167 if(!matchNext(':'))
168 {
169 getNextToken(); /* Make sure error references the correct token */
170 g_scanner_unexp_token(gScanner,
171 ':',
172 NULL,
173 NULL,
174 NULL,
175 "",
176 TRUE); /* is_error */
177 exit(1);
178 }
179
180 /* Check for 'override' */
181 if(!matchNext(G_TOKEN_SYMBOL))
182 {
183 getNextToken(); /* Make sure error references the correct token */
184 g_scanner_unexp_token(gScanner,
185 G_TOKEN_SYMBOL,
186 NULL,
187 NULL,
188 NULL,
189 "'override' keyword expected.",
190 TRUE); /* is_error */
191 exit(1);
192 }
193 else
194 {
195 /* Check if symbol is 'override' */
196 PSYMBOL pCurSymbol;
197
198 value=gScanner->value;
199 pCurSymbol=value.v_symbol;
200
201 if(pCurSymbol->uiSymbolToken != IDL_SYMBOL_OVERRIDE2)
202 {
203 g_scanner_unexp_token(gScanner,
204 G_TOKEN_SYMBOL,
205 NULL,
206 NULL,
207 NULL,
208 "'override' keyword expected after ':'.",
209 TRUE); /* is_error */
210 exit(1);
211 }
212 }
213
214 /* Now check if the method was introduced by some parent */
215 if((pif=findInterfaceForMethod(pParseInfo->pCurInterface, pOMethod->chrName))==NULL)
216 {
217 g_printf("%s:%d: error: Method '%s' was not introduced by some parent interface.\n",
218 pParseInfo->chrCurrentSourceFile, g_scanner_cur_line(gScanner)-pParseInfo->uiLineCorrection,
219 pOMethod->chrName);
220 exit(1);
221 }
222
223
224 pOMethod->chrIntroducingIFace=pif->chrName; /* No copy of string here. Nobody should free the
225 interface info under our feet. */
226
227 /* Check for trailing ';' */
228 if(!matchNext(';'))
229 {
230 getNextToken(); /* Make sure error references the correct token */
231 g_scanner_unexp_token(gScanner,
232 ';',
233 NULL,
234 NULL,
235 NULL,
236 "Error in override statement. Trailing ';' is missing.",
237 TRUE); /* is_error */
238 exit(1);
239 }
240 g_ptr_array_add(pParseInfo->pCurInterface->pOverrideArray, (gpointer) pOMethod);
241}
Note: See TracBrowser for help on using the repository browser.