Doxygen
Loading...
Searching...
No Matches
defargs.l
Go to the documentation of this file.
1/******************************************************************************
2 *
3 *
4 *
5 * Copyright (C) 1997-2015 by Dimitri van Heesch.
6 *
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation under the terms of the GNU General Public License is hereby
9 * granted. No representations are made about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
11 * See the GNU General Public License for more details.
12 *
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
15 *
16 */
17
18/*! \file
19 * This scanner is used to convert a string into a list of function or
20 * template arguments. Each parsed argument results in a Argument struct,
21 * that is put into an ArgumentList in declaration order.
22 * Comment blocks for arguments can also be included in the string.
23 * The argument string does not contain new-lines (except inside any
24 * comment blocks).
25 * An Argument consists of the string fields:
26 * type,name,default value, and documentation
27 * The Argument list as a whole can be pure, constant or volatile.
28 *
29 * Examples of input strings are:
30 * \verbatim
31 * "(int a,int b) const"
32 * "(const char *s="hello world",int=5) = 0"
33 * "<class T,class N>"
34 * "(char c,const char)"
35 * \endverbatim
36 *
37 * Note: It is not always possible to distinguish between the name and
38 * type of an argument. In case of doubt the name is added to the
39 * type, and the matchArgumentList in util.cpp is be used to
40 * further determine the correct separation.
41 */
42%option never-interactive
43%option prefix="defargsYY"
44%option reentrant
45%option extra-type="struct defargsYY_state *"
46%top{
47#include <stdint.h>
48// forward declare yyscan_t to improve type safety
49#define YY_TYPEDEF_YY_SCANNER_T
50struct yyguts_t;
51typedef yyguts_t *yyscan_t;
yyguts_t * yyscan_t
Definition code.l:24
52}
53
54%{
55
56/*
57 * includes
58 */
59#include <stdio.h>
60//#include <iostream.h>
61#include <assert.h>
62#include <ctype.h>
63
64#include "defargs.h"
65#include "entry.h"
66#include "util.h"
67#include "arguments.h"
68#include "message.h"
69#include "debug.h"
70
71#define YY_NO_INPUT 1
72#define YY_NO_UNISTD_H 1
73
74/* -----------------------------------------------------------------
75 * state variables
76 */
104
105[[maybe_unused]] static const char *stateToString(int state);
106
107static int yyread(yyscan_t yyscanner,char *buf,int max_size);
108static bool nameIsActuallyPartOfType(DString &name);
109
110/* -----------------------------------------------------------------
111 */
112#undef YY_INPUT
113#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
114
115// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
116static inline const char *getLexerFILE() {return __FILE__;}
117#define LEX_NO_INPUT_FILENAME
118#include "doxygen_lex.h"
119
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
static bool nameIsActuallyPartOfType(DString &name)
Definition defargs.l:816
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition defargs.l:639
static const char * stateToString(int state)
static const char * getLexerFILE()
Definition defargs.l:116
DString curArgDefValue
Definition defargs.l:87
const char * inputString
Definition defargs.l:81
std::unique_ptr< ArgumentList > & argList
Definition defargs.l:82
int argSquareCount
Definition defargs.l:95
DString curArgArray
Definition defargs.l:91
DString curArgDocs
Definition defargs.l:89
DString curArgName
Definition defargs.l:88
SrcLangExt lang
Definition defargs.l:83
defargsYY_state(const char *inStr, std::unique_ptr< ArgumentList > &al, SrcLangExt l)
Definition defargs.l:79
DString curArgAttrib
Definition defargs.l:90
DString * copyArgValue
Definition defargs.l:85
DString delimiter
Definition defargs.l:102
int lastExtendsContext
Definition defargs.l:101
DString extraTypeChars
Definition defargs.l:93
int argCurlyCount
Definition defargs.l:97
int readArgContext
Definition defargs.l:98
int argSharpCount
Definition defargs.l:96
DString curTypeConstraint
Definition defargs.l:92
int argRoundCount
Definition defargs.l:94
int inputPosition
Definition defargs.l:84
int lastDocContext
Definition defargs.l:99
DString curArgTypeName
Definition defargs.l:86
SrcLangExt
Definition types.h:207
A bunch of utility functions.
120%}
121
122B [ \t]
123Bopt {B}*
124ID [$a-z_A-Z\x80-\xFF][$a-z_A-Z0-9\x80-\xFF]*
125RAWBEGIN (u|U|L|u8)?R\"[^ \t\‍(\‍)\\‍]{0,16}"("
126RAWEND ")"[^ \t\‍(\‍)\\‍]{0,16}\"
127
128 // C start comment
129CCS "/\*"
130 // C end comment
131CCE "*\/"
132 // Cpp comment
133CPPC "/\/"
134
135%option noyywrap
136
137%x Start
138%x CopyArgString
139%x CopyRawString
140%x CopyArgRound
141%x CopyArgRound2
142%x CopyArgSquare
143%x CopyArgSharp
144%x CopyArgCurly
145%x ReadFuncArgType
146%x ReadFuncArgDef
147%x ReadFuncArgPtr
148%x FuncQual
149%x ReadDocBlock
150%x ReadDocLine
151%x ReadTypeConstraint
152%x TrailingReturn
153
154
156
157<Start>[<(] { BEGIN(ReadFuncArgType); }
158
159<ReadFuncArgType>{B}* {
160 yyextra->curArgTypeName+=" ";
161 }
162<ReadFuncArgType,ReadFuncArgPtr>"["[^\‍]]*"]" {
163 if (YY_START==ReadFuncArgPtr)
164 {
165 yyextra->curArgTypeName+=yytext;
166 }
167 else if (yyextra->curArgTypeName.stripWhiteSpace().empty())
168 {
169 yyextra->curArgAttrib=yytext; // for M$-IDL
170 }
171 else // array type
172 {
173 yyextra->curArgArray+=yytext;
174 }
175 }
176<ReadFuncArgDef>"'"\\‍[0-7]{1,3}"'" { yyextra->curArgDefValue+=yytext; }
177<ReadFuncArgDef>"'"\\."'" { yyextra->curArgDefValue+=yytext; }
178<ReadFuncArgDef>"'"."'" { yyextra->curArgDefValue+=yytext; }
179<ReadFuncArgDef>{RAWBEGIN} { yyextra->curArgDefValue+=yytext;
180 yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
181 BEGIN( CopyRawString );
182 }
DString extractBeginRawStringDelimiter(const char *rawStart)
Definition util.cpp:5341
183<ReadFuncArgDef>\" {
184 yyextra->curArgDefValue+=*yytext;
185 BEGIN( CopyArgString );
186 }
187<ReadFuncArgType>"("([^:)]+{B}*"::")*{B}*[&*\^]+{Bopt}/{ID} {
188 // function pointer as argument
189 yyextra->curArgTypeName+=yytext;
190 //yyextra->curArgTypeName=yyextra->curArgTypeName.simplifyWhiteSpace();
191 BEGIN( ReadFuncArgPtr );
192 }
193<ReadFuncArgPtr>{ID} {
194 yyextra->curArgName=yytext;
195 }
196<ReadFuncArgPtr>")"{B}*"(" { // function pointer
197 yyextra->curArgTypeName+=yytext;
198 //yyextra->curArgTypeName=yyextra->curArgTypeName.simplifyWhiteSpace();
199 yyextra->readArgContext = ReadFuncArgType;
200 yyextra->copyArgValue=&yyextra->curArgTypeName;
201 yyextra->argRoundCount=0;
202 BEGIN( CopyArgRound2 );
203 }
204<ReadFuncArgPtr>")"/{B}*"[" { // pointer to fixed size array
205 yyextra->curArgTypeName+=yytext;
206 yyextra->curArgTypeName+=yyextra->curArgName;
207 //yyextra->curArgTypeName=yyextra->curArgTypeName.simplifyWhiteSpace();
208 BEGIN( ReadFuncArgType );
209 }
210<ReadFuncArgPtr>")" { // redundant braces detected / remove them
211 size_t i=yyextra->curArgTypeName.rfind('(');
212 size_t l=yyextra->curArgTypeName.length();
213 if (i!=DString::npos)
214 {
215 yyextra->curArgTypeName=yyextra->curArgTypeName.left(i)+
216 yyextra->curArgTypeName.right(l-i-1);
217 }
218 yyextra->curArgTypeName+=yyextra->curArgName;
219 BEGIN( ReadFuncArgType );
220 }
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:182
221<ReadFuncArgType>"<="|">="|"->"|">>"|"<<" { // handle operators in defargs
222 yyextra->curArgTypeName+=yytext;
223 }
224<ReadFuncArgType,ReadFuncArgDef>[({<\‍[] {
225 if (YY_START==ReadFuncArgType)
226 {
227 yyextra->curArgTypeName+=*yytext;
228 yyextra->copyArgValue=&yyextra->curArgTypeName;
229 }
230 else // YY_START==ReadFuncArgDef
231 {
232 yyextra->curArgDefValue+=*yytext;
233 yyextra->copyArgValue=&yyextra->curArgDefValue;
234 }
235 yyextra->readArgContext = YY_START;
236 if (*yytext=='(')
237 {
238 yyextra->argRoundCount=0;
239 BEGIN( CopyArgRound );
240 }
241 else if (*yytext=='[')
242 {
243 yyextra->argSquareCount=0;
244 BEGIN( CopyArgSquare );
245 }
246 else if (*yytext=='{')
247 {
248 yyextra->argCurlyCount=0;
249 BEGIN( CopyArgCurly );
250 }
251 else // yytext=='<'
252 {
253 yyextra->argSharpCount=0;
254 yyextra->argRoundCount=0;
255 BEGIN( CopyArgSharp );
256 }
257 }
258<CopyArgRound,CopyArgRound2>"(" {
259 yyextra->argRoundCount++;
260 *yyextra->copyArgValue += *yytext;
261 }
262<CopyArgRound,CopyArgRound2>")"({B}*{ID})* {
263 *yyextra->copyArgValue += yytext;
264 if (yyextra->argRoundCount>0)
265 {
266 yyextra->argRoundCount--;
267 }
268 else
269 {
270 if (YY_START==CopyArgRound2)
271 {
272 *yyextra->copyArgValue+=" "+yyextra->curArgName;
273 }
274 BEGIN( yyextra->readArgContext );
275 }
276 }
277<CopyArgRound>")"/{B}* {
278 *yyextra->copyArgValue += *yytext;
279 if (yyextra->argRoundCount>0) yyextra->argRoundCount--;
280 else BEGIN( yyextra->readArgContext );
281 }
282<CopyArgSquare>"[" {
283 yyextra->argSquareCount++;
284 *yyextra->copyArgValue += *yytext;
285 }
286<CopyArgSquare>"]"({B}*{ID})* {
287 *yyextra->copyArgValue += yytext;
288 if (yyextra->argSquareCount>0)
289 {
290 yyextra->argRoundCount--;
291 }
292 else
293 {
294 BEGIN( yyextra->readArgContext );
295 }
296 }
297<CopyArgSquare>"]"/{B}* {
298 *yyextra->copyArgValue += *yytext;
299 if (yyextra->argSquareCount>0) yyextra->argSquareCount--;
300 else BEGIN( yyextra->readArgContext );
301 }
302<CopyArgSharp>"<<" {
303 if (yyextra->argRoundCount>0)
304 {
305 // for e.g. < typename A = (i<<3) >
306 *yyextra->copyArgValue += yytext;
307 }
308 else
309 {
310 REJECT;
311 }
312 }
313<CopyArgSharp>">>" {
314 if (yyextra->argRoundCount>0)
315 {
316 // for e.g. < typename A = (i>>3) >
317 *yyextra->copyArgValue += yytext;
318 }
319 else
320 {
321 REJECT;
322 }
323 }
324<CopyArgSharp>"<" {
325 // don't count < inside (, e.g. for things like: < typename A=(i<6) >
326 if (yyextra->argRoundCount==0) yyextra->argSharpCount++;
327 *yyextra->copyArgValue += *yytext;
328 }
329<CopyArgSharp>">" {
330 *yyextra->copyArgValue += *yytext;
331 if (yyextra->argRoundCount>0 && yyextra->argSharpCount==0)
332 {
333 // don't count > inside )
334 }
335 else
336 {
337 if (yyextra->argSharpCount>0)
338 {
339 yyextra->argSharpCount--;
340 }
341 else
342 {
343 BEGIN( yyextra->readArgContext );
344 }
345 }
346 }
347<CopyArgSharp>"(" {
348 yyextra->argRoundCount++;
349 *yyextra->copyArgValue += *yytext;
350 }
351<CopyArgSharp>")" {
352 yyextra->argRoundCount--;
353 *yyextra->copyArgValue += *yytext;
354 }
355<CopyArgCurly>"{" {
356 yyextra->argCurlyCount++;
357 *yyextra->copyArgValue += *yytext;
358 }
359<CopyArgCurly>"}" {
360 *yyextra->copyArgValue += *yytext;
361 if (yyextra->argCurlyCount>0) yyextra->argCurlyCount--;
362 else BEGIN( yyextra->readArgContext );
363 }
364<CopyArgString>\\. {
365 yyextra->curArgDefValue+=yytext;
366 }
367<CopyRawString>{RAWEND} {
368 yyextra->curArgDefValue+=yytext;
369 if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
370 {
371 BEGIN( ReadFuncArgDef );
372 }
373 }
DString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:5349
374<CopyArgString>\" {
375 yyextra->curArgDefValue+=*yytext;
376 BEGIN( ReadFuncArgDef );
377 }
378<ReadFuncArgType>"=" {
379 BEGIN( ReadFuncArgDef );
380 }
381<ReadFuncArgType,ReadFuncArgDef>[,)>]{B}*({CCS}[*!]|{CPPC}[/!])"<" {
382 yyextra->lastDocContext=YY_START;
383 yyextra->lastDocChar=*yytext;
384 DString text(yytext);
385 if (text.find("//")!=DString::npos)
386 BEGIN( ReadDocLine );
387 else
388 BEGIN( ReadDocBlock );
389 }
390<ReadFuncArgType,ReadFuncArgDef>[,)>] {
391 if (*yytext==')' && yyextra->curArgTypeName.stripWhiteSpace().empty())
392 {
393 yyextra->curArgTypeName+=*yytext;
394 BEGIN(FuncQual);
395 }
396 else
397 {
398 yyextra->curArgTypeName=removeRedundantWhiteSpace(yyextra->curArgTypeName);
399 yyextra->curArgDefValue=yyextra->curArgDefValue.stripWhiteSpace();
400 //printf("curArgType='%s' curArgDefVal='%s'\n",qPrint(yyextra->curArgTypeName),qPrint(yyextra->curArgDefValue));
401 int l = static_cast<int>(yyextra->curArgTypeName.length());
402 if (l>0)
403 {
404 int i=l-1;
405 while (i>=0 && (isspace((uint8_t)yyextra->curArgTypeName.at(i)) || yyextra->curArgTypeName.at(i)=='.')) i--;
406 while (i>=0 && (isId(yyextra->curArgTypeName.at(i)) || yyextra->curArgTypeName.at(i)=='$')) i--;
407 Argument a;
408 a.attrib = yyextra->curArgAttrib;
409 a.typeConstraint = yyextra->curTypeConstraint.stripWhiteSpace();
410 //printf("a->type=%s a->name=%s i=%d l=%d\n",
411 // qPrint(a->type),qPrint(a->name),i,l);
412 a.array.clear();
413 if (i==l-1 && yyextra->curArgTypeName.at(i)==')') // function argument
414 {
415 size_t bis=yyextra->curArgTypeName.find('(');
416 int bi = bis!=DString::npos ? static_cast<int>(bis) : -1;
417 int fi = bi-1;
418 //printf("func arg fi=%d\n",fi);
419 while (fi>=0 && (isId(yyextra->curArgTypeName.at(fi)) || yyextra->curArgTypeName.at(fi)==':')) fi--;
420 if (fi>=0)
421 {
422 a.type = yyextra->curArgTypeName.left(fi+1);
423 a.name = yyextra->curArgTypeName.mid(fi+1,bi-fi-1).stripWhiteSpace();
424 a.array = yyextra->curArgTypeName.right(l-bi);
425 }
426 else
427 {
428 a.type = yyextra->curArgTypeName;
429 }
430 }
431 else if (i>=0 && yyextra->curArgTypeName.at(i)!=':')
432 { // type contains a name
433 a.type = removeRedundantWhiteSpace(yyextra->curArgTypeName.left(i+1)).stripWhiteSpace();
434 a.name = yyextra->curArgTypeName.right(l-i-1).stripWhiteSpace();
435
436 // if the type becomes a type specifier only then we make a mistake
437 // and need to correct it to avoid seeing a nameless parameter
438 // "struct A" as a parameter with type "struct" and name "A".
439 int sv=0;
440 if (a.type.startsWith("const ")) sv=6;
441 else if (a.type.startsWith("volatile ")) sv=9;
442
443 if (a.type.mid(sv)=="struct" ||
444 a.type.mid(sv)=="union" ||
445 a.type.mid(sv)=="class" ||
446 a.type.mid(sv)=="typename" ||
447 a.type=="const" ||
448 a.type=="volatile" ||
450 )
451 {
452 a.type = a.type + " " + a.name;
453 a.name.clear();
454 }
455 //printf(" --> a->type='%s' a->name='%s'\n",qPrint(a->type),qPrint(a->name));
456 }
457 else // assume only the type was specified, try to determine name later
458 {
459 a.type = removeRedundantWhiteSpace(yyextra->curArgTypeName);
460 }
461 if (!a.type.empty() && a.type.at(0)=='$') // typeless PHP name?
462 {
463 a.name = a.type;
464 a.type = "";
465 }
466 a.array += removeRedundantWhiteSpace(yyextra->curArgArray);
467 //printf("array=%s\n",qPrint(a->array));
468 size_t alen = a.array.length();
469 if (alen>2 && a.array.at(0)=='(' &&
470 a.array.at(alen-1)==')') // fix-up for int *(a[10])
471 {
472 size_t pi=a.array.find('[');
473 i = pi!=DString::npos ? static_cast<int>(pi-1) : -1;
474 a.array = a.array.mid(1,alen-2);
475 if (i>0 && a.name.empty())
476 {
477 a.name = a.array.left(i).stripWhiteSpace();
478 a.array = a.array.mid(i);
479 }
480 }
481 a.defval = yyextra->curArgDefValue;
482 //printf("a->type=%s a->name=%s a->defval=\"%s\"\n",qPrint(a->type),qPrint(a->name),qPrint(a->defval));
483 a.docs = yyextra->curArgDocs.stripWhiteSpace();
484 //printf("Argument '%s' '%s' adding docs='%s'\n",qPrint(a->type),qPrint(a->name),qPrint(a->docs));
485 yyextra->argList->push_back(a);
486 }
487 yyextra->curArgAttrib.clear();
488 yyextra->curArgTypeName.clear();
489 yyextra->curArgDefValue.clear();
490 yyextra->curArgArray.clear();
491 yyextra->curArgDocs.clear();
492 yyextra->curTypeConstraint.clear();
493 if (*yytext==')')
494 {
495 BEGIN(FuncQual);
496 //printf(">>> end of argument list\n");
497 }
498 else
499 {
500 BEGIN( ReadFuncArgType );
501 }
502 }
503 }
This class contains the information about the argument of a function or template.
Definition arguments.h:27
DString docs
Definition arguments.h:48
DString typeConstraint
Definition arguments.h:49
DString attrib
Definition arguments.h:42
DString defval
Definition arguments.h:47
DString array
Definition arguments.h:46
DString name
Definition arguments.h:45
DString type
Definition arguments.h:43
void clear()
Definition dstring.h:218
void push_back(char c)
Definition dstring.h:206
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:322
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:690
DString right(size_t len) const
Definition dstring.h:315
size_t find(char c, size_t pos=0) const
Definition dstring.h:243
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:341
DString left(size_t len) const
Definition dstring.h:310
bool startsWith(const char *s) const
Definition dstring.h:604
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:155
bool isId(int c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:899
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:428
504<ReadFuncArgType,ReadFuncArgPtr>"extends" {
505 if (yyextra->lang!=SrcLangExt::Java)
506 {
507 REJECT;
508 }
509 else
510 {
511 yyextra->argSharpCount=0;
512 yyextra->curTypeConstraint.clear();
513 yyextra->lastExtendsContext=YY_START;
514 BEGIN(ReadTypeConstraint);
515 }
516 }
517<ReadFuncArgType,ReadFuncArgPtr>"$"?{ID} {
518 DString name(yytext);
519 if (YY_START==ReadFuncArgType && yyextra->curArgArray=="[]") // Java style array
520 {
521 yyextra->curArgTypeName+=" []";
522 yyextra->curArgArray.clear();
523 }
524 //printf("resolveName '%s'->'%s'\n",yytext,qPrint(name));
525 yyextra->curArgTypeName+=name;
526 }
527<ReadFuncArgType,ReadFuncArgPtr>. {
528 yyextra->curArgTypeName+=*yytext;
529 }
530
531<ReadFuncArgDef,CopyArgString>"<="|"->"|">="|">>"|"<<" {
532 yyextra->curArgDefValue+=yytext;
533 }
534<ReadFuncArgDef,CopyArgString,CopyRawString>. {
535 yyextra->curArgDefValue+=*yytext;
536 }
537<CopyArgRound,CopyArgRound2,CopyArgSquare,CopyArgSharp,CopyArgCurly>{ID} {
538 *yyextra->copyArgValue+=yytext;
539 }
540<CopyArgRound,CopyArgRound2,CopyArgSquare,CopyArgSharp,CopyArgCurly>. {
541 *yyextra->copyArgValue += *yytext;
542 }
543<ReadTypeConstraint>[,)>] {
544 if (yytext[0]!='>' || yyextra->argSharpCount==0)
545 {
546 unput(*yytext);
547 BEGIN(yyextra->lastExtendsContext);
548 }
549 else
550 {
551 yyextra->curTypeConstraint+=yytext;
552 yyextra->argSharpCount--;
553 }
554 }
555<ReadTypeConstraint>"<" {
556 yyextra->curTypeConstraint+=yytext;
557 yyextra->argSharpCount++;
558 }
559<ReadTypeConstraint>. {
560 yyextra->curTypeConstraint+=yytext;
561 }
562<ReadTypeConstraint>\n {
563 yyextra->curTypeConstraint+=' ';
564 }
565<FuncQual>"const" {
566 yyextra->argList->setConstSpecifier(true);
567 }
568<FuncQual>"volatile" {
569 yyextra->argList->setVolatileSpecifier(true);
570 }
571<FuncQual>"override" {
572 }
573<FuncQual>"&" {
574 yyextra->argList->setRefQualifier(RefQualifierType::LValue);
575 }
576<FuncQual>"&&" {
577 yyextra->argList->setRefQualifier(RefQualifierType::RValue);
578 }
579<FuncQual,TrailingReturn>"="{B}*"0" {
580 yyextra->argList->setPureSpecifier(true);
581 BEGIN(FuncQual);
582 }
583<FuncQual>"->" { // C++11 trailing return type
584 yyextra->argList->setTrailingReturnType(DString(" -> "));
585 BEGIN(TrailingReturn);
586 }
587<TrailingReturn>{B}/("final"|"override"){B}* {
588 unput(*yytext);
589 BEGIN(FuncQual);
590 }
591<TrailingReturn>. {
592 yyextra->argList->setTrailingReturnType(yyextra->argList->trailingReturnType()+yytext);
593 }
594<TrailingReturn>\n {
595 yyextra->argList->setTrailingReturnType(yyextra->argList->trailingReturnType()+yytext);
596 }
597<FuncQual>")"{B}*"["[^]]*"]" { // for functions returning a pointer to an array,
598 // i.e. ")[]" in "int (*f(int))[4]" with argsString="(int))[4]"
599 yyextra->extraTypeChars=yytext;
600 }
601<ReadDocBlock>[^\*\n]+ {
602 yyextra->curArgDocs+=yytext;
603 }
604<ReadDocLine>[^\n]+ {
605 yyextra->curArgDocs+=yytext;
606 }
607<ReadDocBlock>{CCE} {
608 if (yyextra->lastDocChar!=0)
609 unput(yyextra->lastDocChar);
610 BEGIN(yyextra->lastDocContext);
611 }
612<ReadDocLine>\n {
613 if (yyextra->lastDocChar!=0)
614 unput(yyextra->lastDocChar);
615 BEGIN(yyextra->lastDocContext);
616 }
617<ReadDocBlock>\n {
618 yyextra->curArgDocs+=*yytext;
619 }
620<ReadDocBlock>. {
621 yyextra->curArgDocs+=*yytext;
622 }
623<*>({CCS}[*!]|{CPPC}[/!])("<"?) {
624 yyextra->lastDocContext=YY_START;
625 yyextra->lastDocChar=0;
626 if (yytext[1]=='/')
627 BEGIN( ReadDocLine );
628 else
629 BEGIN( ReadDocBlock );
630 }
631<*>\n
632<*>.
633
634%%
635
636/* ----------------------------------------------------------------------------
637 */
638
639static int yyread(yyscan_t yyscanner,char *buf,int max_size)
640{
641 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
642 int c=0;
643 while( c < max_size && yyextra->inputString[yyextra->inputPosition] )
644 {
645 *buf = yyextra->inputString[yyextra->inputPosition++] ;
646 c++; buf++;
647 }
648 return c;
649}
650
651/*
652The following code is generated using 'gperf keywords.txt'
653where keywords.txt has the following content
654
655---------------------------------
656%define class-name KeywordHash
657%define lookup-function-name find
658%readonly-tables
659%language=C++
660%%
661unsigned
662signed
663bool
664char
665char8_t
666char16_t
667char32_t
668wchar_t
669int
670short
671long
672float
673double
674int8_t
675int16_t
676int32_t
677int64_t
678intmax_t
679intptr_t
680uint8_t
681uint16_t
682uint32_t
683uint64_t
684uintmax_t
685uintptr_t
686const
687volatile
688void
689%%
690---------------------------------
691*/
692//--- begin gperf generated code ----------------------------------------------------------
693
694#define TOTAL_KEYWORDS 28
695#define MIN_WORD_LENGTH 3
696#define MAX_WORD_LENGTH 9
697#define MIN_HASH_VALUE 3
698#define MAX_HASH_VALUE 48
699/* maximum key range = 46, duplicates = 0 */
700
702{
703 private:
704 static inline size_t hash (const char *str, size_t len);
705 public:
706 static const char *find (const char *str, size_t len);
707};
708
709inline size_t KeywordHash::hash (const char *str, size_t len)
710{
711 static const unsigned char asso_values[] =
712 {
713 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
714 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
715 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
716 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
717 49, 49, 49, 49, 49, 49, 49, 49, 49, 5,
718 5, 30, 0, 49, 25, 49, 10, 49, 49, 49,
719 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
720 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
721 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
722 49, 49, 49, 49, 49, 0, 49, 0, 5, 49,
723 15, 0, 49, 10, 49, 30, 49, 49, 0, 20,
724 0, 49, 15, 49, 5, 10, 0, 49, 49, 49,
725 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
726 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
727 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
728 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
729 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
730 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
731 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
732 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
733 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
734 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
735 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
736 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
737 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
738 49, 49, 49, 49, 49, 49
739 };
740 size_t hval = len;
741
742 switch (hval)
743 {
744 default:
745 hval += asso_values[static_cast<unsigned char>(str[4])];
746 /*FALLTHROUGH*/
747 case 4:
748 hval += asso_values[static_cast<unsigned char>(str[3])];
749 /*FALLTHROUGH*/
750 case 3:
751 break;
752 }
753 return hval;
754}
755
756const char * KeywordHash::find (const char *str, size_t len)
757{
758 static const char * const wordlist[] =
759 {
760 "", "", "",
761 "int",
762 "bool",
763 "float",
764 "signed",
765 "",
766 "volatile",
767 "char",
768 "short",
769 "double",
770 "wchar_t",
771 "uint16_t",
772 "long",
773 "const",
774 "int8_t",
775 "uint8_t",
776 "char16_t",
777 "void",
778 "", "",
779 "char8_t",
780 "intptr_t",
781 "uintptr_t",
782 "", "", "",
783 "intmax_t",
784 "uintmax_t",
785 "", "",
786 "int64_t",
787 "uint64_t",
788 "", "", "",
789 "int16_t",
790 "uint32_t",
791 "", "", "",
792 "int32_t",
793 "char32_t",
794 "", "", "", "",
795 "unsigned"
796 };
797
798 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
799 {
800 size_t key = hash (str, len);
801
802 if (key <= MAX_HASH_VALUE)
803 {
804 const char *s = wordlist[key];
805
806 if (*str == *s && !dstrcmp (str + 1, s + 1))
807 return s;
808 }
809 }
810 return nullptr;
811}
812
813//--- end gperf generated code ----------------------------------------------------------
814
815/* bug_520975 */
817{
818 return KeywordHash::find(name.data(),name.length())!=nullptr;
819}
820
821/*! Converts an argument string into an ArgumentList.
822 * \param[in] lang language of the current argument list
823 * \param[in] argsString the list of Arguments.
824 * \param[out] extraTypeChars point to string to which trailing characters
825 * for complex types are written to
826 */
827
828std::unique_ptr<ArgumentList> stringToArgumentList(SrcLangExt lang, const DString &argsString,DString *extraTypeChars)
829{
830 std::unique_ptr<ArgumentList> al = std::make_unique<ArgumentList>();
831 if (argsString.empty()) return al;
832
833 yyscan_t yyscanner;
834 defargsYY_state extra(argsString.data(),al,lang);
835 defargsYYlex_init_extra(&extra,&yyscanner);
836#ifdef FLEX_DEBUG
837 defargsYYset_debug(Debug::isFlagSet(Debug::Lex_defargs)?1:0,yyscanner);
838#endif
839 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
840 DebugLex debugLex(Debug::Lex_defargs, __FILE__, nullptr);
841
842 defargsYYrestart( nullptr, yyscanner );
843 BEGIN( Start );
844 defargsYYlex(yyscanner);
845 if (yyextra->argList->empty())
846 {
847 yyextra->argList->setNoParameters(true);
848 }
849 if (extraTypeChars) *extraTypeChars=yyextra->extraTypeChars;
850 //printf("stringToArgumentList(%s) result=%s\n",argsString,qPrint(argListToString(*al)));
851 defargsYYlex_destroy(yyscanner);
852 return al;
853}
854
855#include "defargs.l.h"
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:161
@ Lex_defargs
Definition debug.h:60
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:133
static size_t hash(const char *str, size_t len)
Definition defargs.l:709
static const char * find(const char *str, size_t len)
Definition defargs.l:756
std::unique_ptr< ArgumentList > stringToArgumentList(SrcLangExt lang, const DString &argsString, DString *extraTypeChars)
Definition defargs.l:828
#define MIN_WORD_LENGTH
Definition defargs.l:695
#define MAX_HASH_VALUE
Definition defargs.l:698
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:54
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition xml.l:230