Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
10 : * Licensed to the Apache Software Foundation (ASF) under one or more
11 : * contributor license agreements. See the NOTICE file distributed
12 : * with this work for additional information regarding copyright
13 : * ownership. The ASF licenses this file to you under the Apache
14 : * License, Version 2.0 (the "License"); you may not use this file
15 : * except in compliance with the License. You may obtain a copy of
16 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 : */
18 :
19 : %option yylineno
20 :
21 : %{
22 : /*
23 : * scanner.ll - Lexical scanner for IDLC 1.0
24 : */
25 :
26 : #include <ctype.h>
27 : #include <stdlib.h>
28 : #include <string.h>
29 :
30 : #ifndef _IDLC_IDLC_HXX_
31 : #include <idlc/idlc.hxx>
32 : #endif
33 : #ifndef _IDLC_ERRORHANDLER_HXX_
34 : #include <idlc/errorhandler.hxx>
35 : #endif
36 : #ifndef _IDLC_FEHELPER_HXX_
37 : #include <idlc/fehelper.hxx>
38 : #endif
39 :
40 : #include "attributeexceptions.hxx"
41 :
42 :
43 : class AstExpression;
44 : class AstArray;
45 : class AstMember;
46 :
47 : #include <parser.hxx>
48 :
49 : /* handle locations */
50 : int yycolumn = 1;
51 :
52 : #define YY_USER_ACTION idlc()->setOffset(yycolumn, yycolumn+yyleng-1); \
53 : yycolumn += yyleng;
54 :
55 : sal_Int32 beginLine = 0;
56 0 : ::rtl::OString docu;
57 :
58 0 : static int asciiToInteger(char const * s, sal_Int64 * sval, sal_uInt64 * uval) {
59 0 : bool neg = false;
60 0 : if (*s == '-') {
61 0 : neg = true;
62 0 : ++s;
63 : }
64 0 : unsigned int base = 10;
65 0 : if (*s == '0') {
66 0 : base = 8;
67 0 : ++s;
68 0 : if (*s == 'X' || *s == 'x') {
69 0 : base = 16;
70 0 : ++s;
71 : }
72 : }
73 0 : sal_uInt64 val = 0;
74 0 : for (; *s != 0; ++s) {
75 : unsigned int n;
76 0 : if (*s >= '0' && *s <= '9') {
77 0 : n = *s - '0';
78 : } else {
79 0 : switch (*s) {
80 : case 'A':
81 : case 'a':
82 0 : n = 10;
83 0 : break;
84 : case 'B':
85 : case 'b':
86 0 : n = 11;
87 0 : break;
88 : case 'C':
89 : case 'c':
90 0 : n = 12;
91 0 : break;
92 : case 'D':
93 : case 'd':
94 0 : n = 13;
95 0 : break;
96 : case 'E':
97 : case 'e':
98 0 : n = 14;
99 0 : break;
100 : case 'F':
101 : case 'f':
102 0 : n = 15;
103 0 : break;
104 : default:
105 0 : goto done;
106 : }
107 : }
108 : // The following guarantees the invariant val <= SAL_MAX_UINT64 (because
109 : // base and n are sufficiently small), *if*
110 : // std::numeric_limits<sal_uInt64>::max() == SAL_MAX_UINT64:
111 0 : sal_uInt64 nval = val * base + n;
112 0 : if (nval < val) {
113 : idlc()->error()->syntaxError(
114 0 : PS_NoState, idlc()->getLineNumber(),
115 0 : "integral constant too large");
116 0 : val = 0;
117 0 : break;
118 : }
119 0 : val = nval;
120 : }
121 : done:
122 0 : if (neg) {
123 0 : if (val < SAL_CONST_UINT64(0x8000000000000000)) {
124 0 : *sval = -static_cast< sal_Int64 >(val);
125 0 : } else if (val == SAL_CONST_UINT64(0x8000000000000000)) {
126 0 : *sval = SAL_MIN_INT64;
127 : } else {
128 : idlc()->error()->syntaxError(
129 0 : PS_NoState, idlc()->getLineNumber(),
130 0 : "negative integral constant too large");
131 0 : *sval = 0;
132 : }
133 0 : return IDL_INTEGER_LITERAL;
134 0 : } else if (val <= static_cast< sal_uInt64 >(SAL_MAX_INT64)) {
135 0 : *sval = static_cast< sal_Int64 >(val);
136 0 : return IDL_INTEGER_LITERAL;
137 : } else {
138 0 : *uval = val;
139 0 : return IDL_INTEGER_ULITERAL;
140 : }
141 : }
142 :
143 0 : static double asciiToFloat(const sal_Char *s)
144 : {
145 0 : double d = 0.0;
146 : double e, k;
147 0 : sal_Int32 neg = 0, negexp = 0;
148 :
149 0 : if (*s == '-')
150 : {
151 0 : neg = 1;
152 0 : s++;
153 : }
154 0 : while (*s >= '0' && *s <= '9')
155 : {
156 0 : d = (d * 10) + *s - '0';
157 0 : s++;
158 : }
159 0 : if (*s == '.')
160 : {
161 0 : s++;
162 0 : e = 10;
163 0 : while (*s >= '0' && *s <= '9')
164 : {
165 0 : d += (*s - '0') / (e * 1.0);
166 0 : e *= 10;
167 0 : s++;
168 : }
169 : }
170 0 : if (*s == 'e' || *s == 'E')
171 : {
172 0 : s++;
173 0 : if (*s == '-')
174 : {
175 0 : negexp = 1;
176 0 : s++;
177 : } else
178 : {
179 0 : if (*s == '+')
180 0 : s++;
181 0 : e = 0;
182 0 : while (*s >= '0' && *s <= '9')
183 : {
184 0 : e = (e * 10) + *s - '0';
185 0 : s++;
186 : }
187 0 : if (e > 0)
188 : {
189 0 : for (k = 1; e > 0; k *= 10, e--)
190 : ;
191 0 : if (negexp)
192 0 : d /= k;
193 : else
194 0 : d *= k;
195 : }
196 : }
197 : }
198 0 : if (neg) d *= -1.0;
199 0 : return d;
200 : }
201 :
202 0 : static void idlParsePragma(sal_Char* pPragma)
203 : {
204 0 : ::rtl::OString pragma(pPragma);
205 0 : sal_Int32 index = pragma.indexOf("include");
206 0 : sal_Char* begin = pPragma + index + 8;
207 0 : sal_Char* offset = begin;
208 0 : while (*offset != ',') offset++;
209 : //::rtl::OString include = pragma.copy(index + 8, offset - begin);
210 : //unused// idlc()->insertInclude(pragma.copy(index + 8, (sal_Int32)(offset - begin)));
211 0 : }
212 :
213 0 : static void parseLineAndFile(sal_Char* pBuf)
214 : {
215 0 : sal_Char *r = pBuf;
216 : sal_Char *h;
217 0 : sal_Bool bIsInMain = sal_False;
218 :
219 : /* Skip initial '#' */
220 0 : if (*r != '#')
221 : return;
222 :
223 : /* Find line number */
224 0 : for (r++; *r == ' ' || *r == '\t' || isalpha(*r); r++) ;
225 0 : h = r;
226 0 : for (; *r != '\0' && *r != ' ' && *r != '\t'; r++) ;
227 0 : *r++ = 0;
228 0 : idlc()->setLineNumber((sal_uInt32)atol(h));
229 0 : yylineno = atol(h);
230 :
231 : /* Find file name, if present */
232 0 : for (; *r != '"'; r++)
233 : {
234 0 : if (*r == '\n' || *r == '\0')
235 : return;
236 : }
237 0 : h = ++r;
238 0 : for (; *r != '"'; r++) ;
239 0 : *r = 0;
240 0 : if (*h == '\0')
241 0 : idlc()->setFileName(::rtl::OString("standard input"));
242 : else
243 0 : idlc()->setFileName(::rtl::OString(h));
244 :
245 0 : bIsInMain = (idlc()->getFileName() == idlc()->getRealFileName()) ? sal_True : sal_False;
246 0 : idlc()->setInMainfile(bIsInMain);
247 : }
248 :
249 : // Suppress any warnings from generated code:
250 : #if defined __GNUC__
251 : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
252 : #pragma GCC diagnostic ignored "-Wunused-function"
253 : #pragma GCC diagnostic ignored "-Wunused-label"
254 : #endif
255 : #elif defined __SUNPRO_CC
256 : #pragma disable_warn
257 : #elif defined _MSC_VER
258 : #pragma warning(push, 1)
259 : /**/
260 : #ifdef yywrap
261 : #undef yywrap
262 : #define yywrap() 1
263 : #endif
264 : /**/
265 : #endif
266 : %}
267 :
268 : %option noyywrap
269 : %option never-interactive
270 :
271 : %x DOCU
272 : %x COMMENT
273 :
274 : DIGIT [0-9]
275 : OCT_DIGIT [0-7]
276 : HEX_DIGIT [a-fA-F0-9]
277 : CAPITAL [A-Z]
278 : ALPHA [a-zA-Z]
279 : INT_LITERAL [1-9][0-9]*
280 : OCT_LITERAL 0{OCT_DIGIT}*
281 : HEX_LITERAL (0x|0X){HEX_DIGIT}*
282 :
283 : IDENTIFIER_NEW ({ALPHA}({ALPHA}|{DIGIT})*)|({CAPITAL}("_"?({ALPHA}|{DIGIT})+)*)
284 : IDENTIFIER ("_"?({ALPHA}|{DIGIT})+)*
285 :
286 : %%
287 :
288 : [ \t\r]+ ; /* eat up whitespace */
289 0 : [\n] {
290 0 : idlc()->incLineNumber();
291 0 : yycolumn = 1;
292 0 : yylineno++;
293 : }
294 0 :
295 0 : attribute return IDL_ATTRIBUTE;
296 0 : bound return IDL_BOUND;
297 0 : case return IDL_CASE;
298 0 : const return IDL_CONST;
299 0 : constants return IDL_CONSTANTS;
300 0 : constrained return IDL_CONSTRAINED;
301 0 : default return IDL_DEFAULT;
302 0 : enum return IDL_ENUM;
303 0 : exception return IDL_EXCEPTION;
304 0 : interface return IDL_INTERFACE;
305 0 : maybeambiguous return IDL_MAYBEAMBIGUOUS;
306 0 : maybedefault return IDL_MAYBEDEFAULT;
307 0 : maybevoid return IDL_MAYBEVOID;
308 0 : module return IDL_MODULE;
309 0 : needs return IDL_NEEDS;
310 0 : observes return IDL_OBSERVES;
311 0 : optional return IDL_OPTIONAL;
312 0 : property return IDL_PROPERTY;
313 0 : raises return IDL_RAISES;
314 0 : readonly return IDL_READONLY;
315 0 : removable return IDL_REMOVEABLE;
316 0 : service return IDL_SERVICE;
317 0 : sequence return IDL_SEQUENCE;
318 0 : singleton return IDL_SINGLETON;
319 0 : struct return IDL_STRUCT;
320 0 : switch return IDL_SWITCH;
321 0 : transient return IDL_TRANSIENT;
322 0 : typedef return IDL_TYPEDEF;
323 0 : union return IDL_UNION;
324 0 :
325 0 : any return IDL_ANY;
326 0 : boolean return IDL_BOOLEAN;
327 0 : byte return IDL_BYTE;
328 0 : char return IDL_CHAR;
329 0 : double return IDL_DOUBLE;
330 0 : float return IDL_FLOAT;
331 0 : hyper return IDL_HYPER;
332 0 : long return IDL_LONG;
333 0 : short return IDL_SHORT;
334 0 : string return IDL_STRING;
335 0 : type return IDL_TYPE;
336 0 : unsigned return IDL_UNSIGNED;
337 0 : void return IDL_VOID;
338 0 :
339 0 : TRUE return IDL_TRUE;
340 0 : True return IDL_TRUE;
341 0 : FALSE return IDL_FALSE;
342 0 : False return IDL_FALSE;
343 0 :
344 0 : in return IDL_IN;
345 0 : out return IDL_OUT;
346 0 : inout return IDL_INOUT;
347 0 :
348 0 : get return IDL_GET;
349 0 : set return IDL_SET;
350 :
351 0 : published return IDL_PUBLISHED;
352 0 :
353 0 : "..." return IDL_ELLIPSIS;
354 0 :
355 : ("-")?{INT_LITERAL}+(l|L|u|U)? {
356 0 : return asciiToInteger(yytext, &yylval.ival, &yylval.uval);
357 : }
358 :
359 : ("-")?{OCT_LITERAL}+(l|L|u|U)? {
360 0 : return asciiToInteger(yytext, &yylval.ival, &yylval.uval);
361 : }
362 :
363 : ("-")?{HEX_LITERAL}+(l|L|u|U)? {
364 0 : return asciiToInteger(yytext, &yylval.ival, &yylval.uval);
365 : }
366 :
367 : ("-")?{DIGIT}+(e|E){1}(("+"|"-")?{DIGIT}+)+(f|F)? |
368 : ("-")?"."{DIGIT}+((e|E)("+"|"-")?{DIGIT}+)?(f|F)? |
369 : ("-")?{DIGIT}*"."{DIGIT}+((e|E)("+"|"-")?{DIGIT}+)?(f|F)? {
370 0 : yylval.dval = asciiToFloat( yytext );
371 0 : return IDL_FLOATING_PT_LITERAL;
372 : }
373 :
374 : {IDENTIFIER} {
375 0 : yylval.sval = new ::rtl::OString(yytext);
376 0 : return IDL_IDENTIFIER;
377 : }
378 :
379 : \<\< {
380 0 : yylval.strval = yytext;
381 0 : return IDL_LEFTSHIFT;
382 : }
383 : \>\> {
384 0 : yylval.strval = yytext;
385 0 : return IDL_RIGHTSHIFT;
386 : }
387 : \:\: {
388 0 : yylval.strval = yytext;
389 0 : return IDL_SCOPESEPARATOR;
390 : }
391 :
392 : "/*" {
393 0 : BEGIN( COMMENT );
394 0 : docu = ::rtl::OString();
395 0 : beginLine = idlc()->getLineNumber();
396 : }
397 0 :
398 : "/***" {
399 0 : BEGIN( COMMENT );
400 0 : docu = ::rtl::OString();
401 0 : beginLine = idlc()->getLineNumber();
402 : }
403 0 :
404 : <COMMENT>[^*]+ {
405 0 : docu += ::rtl::OString(yytext);
406 0 : }
407 0 :
408 : <COMMENT>"*"[^*/]+ {
409 0 : docu += ::rtl::OString(yytext);
410 0 : }
411 0 :
412 : <COMMENT>"**" {
413 0 : docu += ::rtl::OString(yytext);
414 : }
415 0 :
416 : <COMMENT>[*]+"/" {
417 0 : docu = docu.trim();
418 0 : sal_Int32 nIndex = 0;
419 0 : int count = 0;
420 0 : do { docu.getToken( 0, '\n', nIndex ); count++; } while( nIndex != -1 );
421 0 : idlc()->setLineNumber( beginLine + count - 1);
422 0 : BEGIN( INITIAL );
423 : }
424 0 :
425 : "/**" {
426 0 : BEGIN( DOCU );
427 0 : docu = ::rtl::OString();
428 0 : beginLine = idlc()->getLineNumber();
429 : }
430 0 :
431 : <DOCU>[^*\n]+ {
432 0 : docu += ::rtl::OString(yytext);
433 : }
434 0 :
435 : <DOCU>"\n"[ \t]*"*"{1} {
436 0 : idlc()->setLineNumber( idlc()->getLineNumber() + 1);
437 0 : docu += ::rtl::OString("\n");
438 : }
439 0 :
440 : <DOCU>"\n" {
441 0 : idlc()->setLineNumber( idlc()->getLineNumber() + 1);
442 0 : docu += ::rtl::OString(yytext);
443 : }
444 0 :
445 : <DOCU>"*"[^*^/\n]* {
446 0 : docu += ::rtl::OString(yytext);
447 : }
448 0 :
449 : <DOCU>"\n"[ \t]*"*/" {
450 0 : docu = docu.trim();
451 0 : sal_Int32 nIndex = 0;
452 0 : int count = 0;
453 0 : do { docu.getToken( 0, '\n', nIndex ); count++; } while( nIndex != -1 );
454 0 : idlc()->setLineNumber( beginLine + count - 1);
455 0 : if ( (nIndex = docu.indexOf("/*")) >= 0 || (nIndex = docu.indexOf("///")) >= 0 )
456 : {
457 0 : if ( 0 != nIndex &&
458 0 : (docu.getStr()[nIndex - 1] != '"' && docu.getStr()[nIndex - 1] != ':') )
459 0 : idlc()->error()->syntaxError(PS_NoState, idlc()->getLineNumber(),
460 0 : "nested documentation strings are not allowed!");
461 : }
462 0 : idlc()->setDocumentation(docu);
463 0 : BEGIN( INITIAL );
464 : }
465 0 :
466 : <DOCU>"*/" {
467 0 : docu = docu.trim();
468 0 : sal_Int32 nIndex = 0;
469 0 : int count = 0;
470 0 : do { docu.getToken( 0, '\n', nIndex ); count++; } while( nIndex != -1 );
471 0 : idlc()->setLineNumber( beginLine + count - 1);
472 0 : if ( docu.indexOf("/*") >= 0 || docu.indexOf("//") >= 0 )
473 : {
474 0 : if ( 0 != nIndex &&
475 0 : (docu.getStr()[nIndex - 1] != '"' && docu.getStr()[nIndex - 1] != ':') )
476 0 : idlc()->error()->syntaxError(PS_NoState, idlc()->getLineNumber(),
477 0 : "nested documentation strings are not allowed!");
478 : }
479 0 : idlc()->setDocumentation(docu);
480 0 : BEGIN( INITIAL );
481 : }
482 0 :
483 : "//"[^/]{1}.*"\n" {
484 : /* only a comment */
485 0 : ::rtl::OString docStr(yytext);
486 0 : docStr = docStr.copy( 0, docStr.lastIndexOf('\n') );
487 0 : docStr = docStr.copy( docStr.lastIndexOf('/')+1 );
488 0 : docStr = docStr.trim();
489 0 : idlc()->incLineNumber();
490 : }
491 0 :
492 : "///".*"\n" {
493 0 : ::rtl::OString docStr(yytext);
494 0 : docStr = docStr.copy( 0, docStr.lastIndexOf('\n') );
495 0 : docStr = docStr.copy( docStr.lastIndexOf('/')+1 );
496 0 : docStr = docStr.trim();
497 0 : idlc()->incLineNumber();
498 0 : idlc()->setDocumentation(docStr);
499 : }
500 0 :
501 0 : . return yytext[0];
502 0 :
503 : ^#[ \t]*line[ \t]*[0-9]*" ""\""[^\"]*"\""\n {
504 0 : parseLineAndFile(yytext);
505 0 : }
506 0 :
507 : ^#[ \t]*[0-9]*" ""\""[^\"]*"\""" "[0-9]*\n {
508 0 : parseLineAndFile(yytext);
509 0 : }
510 0 :
511 : ^#[ \t]*[0-9]*" ""\""[^\"]*"\""\n {
512 0 : parseLineAndFile(yytext);
513 0 : }
514 0 :
515 : ^#[ \t]*[0-9]*\n {
516 0 : parseLineAndFile(yytext);
517 0 : }
518 0 :
519 : ^#[ \t]*ident.*\n {
520 : /* ignore cpp ident */
521 0 : idlc()->incLineNumber();
522 : }
523 0 :
524 : ^#[ \t]*pragma[ \t].*\n { /* remember pragma */
525 0 : idlParsePragma(yytext);
526 0 : idlc()->incLineNumber();
527 : }
528 0 :
529 0 : %%
|